The chat manager class, responsible for sending and receiving messages, managing conversations (including loading and deleting conversations), and downloading attachments.

The sample code for sending a text message is as follows:

let msg = ChatMessage.createTextMessage(
'asteriskhx2',
Date.now().toString(),
ChatMessageChatType.PeerChat
);
let callback = new (class s implements ChatMessageStatusCallback {
onProgress(progress: number): void {
chatlog.log('ConnectScreen.sendMessage.onProgress ', progress);
}
onError(error: ChatError): void {
chatlog.log('ConnectScreen.sendMessage.onError ', error);
}
onSuccess(): void {
chatlog.log('ConnectScreen.sendMessage.onSuccess');
}
onReadAck(): void {
chatlog.log('ConnectScreen.sendMessage.onReadAck');
}
onDeliveryAck(): void {
chatlog.log('ConnectScreen.sendMessage.onDeliveryAck');
}
onStatusChanged(status: ChatMessageStatus): void {
chatlog.log('ConnectScreen.sendMessage.onStatusChanged ', status);
}
})();
ChatClient.getInstance()
.chatManager.sendMessage(msg, callback)
.then((nmsg: ChatMessage) => {
chatlog.log(`${msg}, ${nmsg}`);
})
.catch();

Hierarchy

  • BaseManager
    • ChatManager

Constructors

Properties

Methods

addMessageListener addReaction addRemoteAndLocalConversationsMark createChatThread deleteAllMessageAndConversation deleteConversation deleteConversationAllMessages deleteMessage deleteMessagesBeforeTimestamp deleteMessagesWithTimestamp deleteRemoteAndLocalConversationsMark destroyChatThread downloadAttachment downloadAttachmentInCombine downloadThumbnail downloadThumbnailInCombine fetchAllConversations fetchChatThreadFromServer fetchChatThreadWithParentFromServer fetchCombineMessageDetail fetchConversationsByOptions fetchConversationsFromServerWithCursor fetchConversationsFromServerWithPage fetchGroupAcks fetchHistoryMessages fetchHistoryMessagesByOptions fetchJoinedChatThreadFromServer fetchJoinedChatThreadWithParentFromServer fetchLastMessageWithChatThread fetchMembersWithChatThreadFromServer fetchPinnedConversationsFromServerWithCursor fetchPinnedMessages fetchReactionDetail fetchReactionList fetchSupportedLanguages getAllConversations getConversation getConversationMessageCount getConversationUnreadCount getConvMsgsWithKeyword getLatestMessage getLatestReceivedMessage getMessage getMessagePinInfo getMessages getMessagesWithKeyword getMessagesWithMsgType getMessageThread getMessageWithTimestamp getMsgs getMsgsWithKeyword getMsgsWithMsgType getMsgWithTimestamp getPinnedMessages getReactionList getThreadConversation getUnreadCount groupAckCount importMessages insertMessage joinChatThread leaveChatThread markAllConversationsAsRead markAllMessagesAsRead markMessageAsRead modifyMessageBody pinConversation pinMessage recallMessage removeAllMessageListener removeConversationFromServer removeMemberWithChatThread removeMessageListener removeMessagesFromServerWithMsgIds removeMessagesFromServerWithTimestamp removeReaction reportMessage resendMessage searchMsgFromDB sendConversationReadAck sendGroupMessageReadAck sendMessage sendMessageReadAck setConversationExtension setNativeListener translateMessage unpinMessage updateChatThreadName updateConversationMessage updateMessage _callMethod checkErrorFromResult handleGroupFileCallback handleMessageCallback

Constructors

Properties

_eventEmitter?: NativeEventEmitter
TAG: string = 'ChatManager'

Methods

  • Adds a message listener.

    Parameters

    Returns void

  • Adds a Reaction.

    Parameters

    • reaction: string

      The Reaction content.

    • msgId: string

      The ID of the message for which the Reaction is added.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Marks conversations.

    This method marks conversations both locally and on the server.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Creates a message thread.

    Each member of the group where the thread belongs can call this method.

    Upon the creation of a message thread, the following will occur:

    Parameters

    • name: string

      The name of the new message thread. It can contain a maximum of 64 characters.

    • msgId: string

      The ID of the parent message.

    • parentId: string

      The parent ID, which is the group ID.

    Returns Promise<ChatMessageThread>

    If success, the new message thread object is returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Clears all conversations and all messages in them.

    Parameters

    • clearServerData: boolean = false

      Whether to clear all conversations and all messages in them on the server.

      • true:Yes. All conversations and all messages in them will be cleared on the server side. The current user cannot retrieve messages and conversations from the server, while this has no impact on other users.
      • (Default) false:No. All local conversations and all messages in them will be cleared, while those on the server remain.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes a conversation and its local messages from the local database.

    Parameters

    • convId: string

      The conversation ID.

    • withMessage: boolean = true

      Whether to delete the historical messages with the conversation.

      • (Default) true: Yes.
      • false: No.

    Returns Promise<void>

    Whether the conversation is successfully deleted.

    • true: Yes.
    • false: No.

    A description of the exception. See ChatError.

  • Deletes all messages in the conversation from both the memory and local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes a message from the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • msgId: string

      The ID of the message to delete.

    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes local messages with timestamp that is before the specified one.

    Parameters

    • timestamp: number

      The specified Unix timestamp(milliseconds).

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes messages sent or received in a certain period from the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • params: {
          endTs: number;
          startTs: number;
      }
      • endTs: number
      • startTs: number
    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<void>

    params

    • startTs: The starting UNIX timestamp for message deletion. The unit is millisecond.
    • endTs: The end UNIX timestamp for message deletion. The unit is millisecond.

    A description of the exception. See ChatError.

  • Unmarks conversations.

    This method unmarks conversations both locally and on the server.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Downloads the message attachment.

    You can also call this method if the attachment fails to be downloaded automatically.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Downloads the message attachment.

    Note This method is only used to download messages attachment in combine type message or thread type.

    Note The bottom layer will not get the original message object and will use the json converted message object.

    You can also call this method if the attachment fails to be downloaded automatically.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Downloads the message thumbnail.

    Parameters

    • message: ChatMessage

      The ID of the message with the thumbnail to be downloaded. Only the image messages and video messages have a thumbnail.

    • Optionalcallback: ChatMessageStatusCallback

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Downloads the message thumbnail.

    Note This method is only used to download messages thumbnail in combine type message.

    Parameters

    • message: ChatMessage

      The ID of the message with the thumbnail to be downloaded. Only the image messages and video messages have a thumbnail.

    • Optionalcallback: ChatMessageStatusCallback

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Returns Promise<ChatConversation[]>

    The conversation list of the current user.

    2023-07-24

    Gets the conversation list from the server.

    Note

    • To use this function, you need to contact our business manager to activate it.
    • After this function is activated, users can pull 10 conversations within 7 days by default (each conversation contains the latest historical message).
    • If you want to adjust the number of conversations or time limit, contact our business manager.

    A description of the exception. See ChatError.

  • Gets the details of the message thread from the server.

    Parameters

    • chatThreadId: string

      The message thread ID.

    Returns Promise<undefined | ChatMessageThread>

    If success, the details of the message thread are returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Uses the pagination to get the list of message threads in the specified group.

    This method gets data from the server.

    Parameters

    • parentId: string

      The parent ID, which is the group ID.

    • cursor: string = ''

      The position from which to start getting data. At the first method call, if you set cursor to null or an empty string, the SDK will get data in the reverse chronological order of when message threads are created.

    • pageSize: number = 20

      The number of message threads that you expect to get on each page. The value range is [1,400].

    Returns Promise<ChatCursorResult<ChatMessageThread>>

    If success, a list of message threads is returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Gets the list of original messages included in a combined message.

    A combined message contains one or more multiple original messages.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of original messages in the message body.

    A description of the exception. See ChatError.

  • Gets the list of conversations from the server with pagination.

    The SDK retrieves the list of conversations in the reverse chronological order of their active time (generally the timestamp of the last message).

    If there is no message in the conversation, the SDK retrieves the list of conversations in the reverse chronological order of their creation time.

    Parameters

    • Optionalcursor: string
    • OptionalpageSize: number

    Returns Promise<ChatCursorResult<ChatConversation>>

    The list of retrieved conversations.

    A description of the exception. See ChatError.

  • Gets conversations from the server with pagination.

    Parameters

    • pageSize: number

      The number of conversations to retrieve on each page.

    • pageNum: number

      The current page number, starting from 1.

    Returns Promise<ChatConversation[]>

    If success, the list of conversations is returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Uses the pagination to get read receipts for group messages from the server.

    For how to send read receipts for group messages, see sendConversationReadAck.

    Parameters

    • msgId: string

      The message ID.

    • groupId: string
    • startAckId: string

      The starting read receipt ID for query. After this parameter is set, the SDK retrieves read receipts, from the specified one, in the reverse chronological order of when the server receives them. If this parameter is set as null or an empty string, the SDK retrieves read receipts, from the latest one, in the reverse chronological order of when the server receives them.

    • pageSize: number = 0

      The number of read receipts for the group message that you expect to get on each page. The value range is [1,400].

    Returns Promise<ChatCursorResult<ChatGroupMessageAck>>

    The list of retrieved read receipts (excluding the one with the starting ID) and the cursor for the next query.

    A description of the exception. See ChatError.

  • Uses the pagination to get messages in the specified conversation from the server.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<ChatCursorResult<ChatMessage>>

    The list of retrieved messages (excluding the one with the starting ID) and the cursor for the next query.

    params

    • pageSize: The number of messages that you expect to get on each page. The value range is [1,50].
    • startMsgId: The starting message ID for query. After this parameter is set, the SDK retrieves messages, starting from the specified one, in the reverse chronological order of when the server receives them. If this parameter is set an empty string, the SDK retrieves messages, starting from the latest one, in the reverse chronological order of when the server receives them.
    • direction: The message search direction. See ChatSearchDirection. - (Default) ChatSearchDirection.Up: Messages are retrieved in the descending order of the Unix timestamp included in them. - ChatSearchDirection.Down: Messages are retrieved in the ascending order of the Unix timestamp included in them.

    A description of the exception. See ChatError.

  • retrieve the history message for the specified session from the server.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • chatType: ChatConversationType

      The conversation type. See ChatConversationType.

    • Optionalparams: {
          cursor?: string;
          options?: ChatFetchMessageOptions;
          pageSize?: number;
      }

      options: The parameter configuration class for pulling historical messages from the server. See ChatFetchMessageOptions.

      • cursor: The cursor position from which to start querying data.
      • pageSize: The number of messages that you expect to get on each page. The value range is [1,50].

    Returns Promise<ChatCursorResult<ChatMessage>>

    The list of retrieved messages (excluding the one with the starting ID) and the cursor for the next query.

    A description of the exception. See ChatError.

  • Uses the pagination to get the list of message threads that the current user has joined.

    Parameters

    • cursor: string = ''

      The position from which to start getting data. At the first method call, if you set cursor to null or an empty string, the SDK will get data in the reverse chronological order of when the user joins the message threads.

    • pageSize: number = 20

      The number of message threads that you expect to get on each page. The value range is [1,400].

    Returns Promise<ChatCursorResult<ChatMessageThread>>

    If success, a list of message threads is returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Uses the pagination to get the list of message threads that the current user has joined in the specified group.

    This method gets data from the server.

    Parameters

    • parentId: string

      The parent ID, which is the group ID.

    • cursor: string = ''

      The position from which to start getting data. At the first method call, if you set cursor to null or an empty string, the SDK will get data in the reverse chronological order of when the user joins the message threads.

    • pageSize: number = 20

      The number of message threads that you expect to get on each page. The value range is [1,400].

    Returns Promise<ChatCursorResult<ChatMessageThread>>

    If success, a list of message threads is returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Gets the last reply in the specified message threads from the server.

    Parameters

    • chatThreadIds: string[]

      The list of message thread IDs to query. You can pass a maximum of 20 message thread IDs each time.

    Returns Promise<Map<string, ChatMessage>>

    If success, a list of last replies are returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Uses the pagination to get a list of members in the message thread.

    Each member of the group to which the message thread belongs can call this method.

    Parameters

    • chatThreadId: string

      The message thread ID.

    • cursor: string = ''

      The position from which to start getting data. At the first method call, if you set cursor to null or an empty string, the SDK will get data in the chronological order of when members join the message thread.

    • pageSize: number = 20

      The number of members that you expect to get on each page. The value range is [1,400].

    Returns Promise<ChatCursorResult<string>>

    If success, the list of members in a message thread is returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Get the list of pinned conversations from the server with pagination.

    The SDK returns the pinned conversations in the reverse chronological order of their pinning.

    Parameters

    • Optionalcursor: string
    • OptionalpageSize: number

    Returns Promise<ChatCursorResult<ChatConversation>>

    The list of retrieved conversations.

    A description of the exception. See ChatError.

  • Gets the list of pinned messages in the conversation from the server.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of pinned messages. If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Gets the Reaction details.

    Parameters

    • msgId: string

      The message ID.

    • reaction: string

      The Reaction content.

    • Optionalcursor: string

      The cursor position from which to start getting Reactions.

    • OptionalpageSize: number

      The number of Reactions you expect to get on each page.

    Returns Promise<ChatCursorResult<ChatMessageReaction>>

    If success, the SDK returns the Reaction details and the cursor for the next query. The SDK returns null if all the data is fetched. If a failure occurs, an exception is thrown.

    A description of the exception. See ChatError.

  • Gets the list of Reactions.

    Parameters

    • msgIds: string[]

      The message ID list.

    • groupId: string

      The group ID, which is invalid only when the chat type is group chat.

    • chatType: ChatMessageChatType

      The chat type.

    Returns Promise<Map<string, ChatMessageReaction[]>>

    If success, the Reaction list is returned; otherwise, an exception is thrown.

    A description of the exception. See ChatError.

  • Gets all languages supported by the translation service.

    Returns Promise<ChatTranslateLanguage[]>

    The list of languages supported for translation.

    A description of the exception. See ChatError.

  • Gets all conversations from the local database.

    Conversations will be first retrieved from the memory. If no conversation is found, the SDK retrieves from the local database.

    Returns Promise<ChatConversation[]>

    The retrieved conversations.

    A description of the exception. See ChatError.

  • Gets the conversation by conversation ID and conversation type.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • createIfNeed: boolean = true

      Whether to create a conversation if the specified conversation is not found:

      • (Default) true: Yes.
      • false: No.
    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

      • (Default) false: No.
      • true: Yes.

    Returns Promise<undefined | ChatConversation>

    The retrieved conversation object. The SDK returns null if the conversation is not found.

    A description of the exception. See ChatError.

  • Gets the message count of the conversation.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<number>

    The message count. getMessageCount

    A description of the exception. See ChatError.

  • Gets the unread message count of the conversation.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<number>

    The unread message count.

    A description of the exception. See ChatError.

  • Gets messages that the specified user sends in a conversation in a certain period.

    This method gets data from the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    • convId The conversation ID.
    • convType The conversation type. See ChatConversationType.
    • keywords The keywords for query.
    • direction The message search direction. See ChatSearchDirection.
    • (Default) ChatSearchDirection.UP: Messages are retrieved in the descending order of the Unix timestamp included in them.
    • ChatSearchDirection.DOWN: Messages are retrieved in the ascending order of the Unix timestamp included in them.
    • timestamp The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction.
    • searchScope The message search scope. See ChatMessageSearchScope. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them.
    • count The maximum number of messages to retrieve each time. The value range is [1,400].
    • sender The user ID or group ID for retrieval. Usually, it is the conversation ID.
    • isChatThread Whether the conversation is a thread conversation.

    A description of the exception. See ChatError.

  • Gets the latest message from the conversation.

    Note

    The operation does not change the unread message count. If the conversation object does not exist, this method will create it.

    The SDK gets the latest message from the memory first. If no message is found, the SDK loads the message from the local database and then puts it in the memory.

    Parameters

    Returns Promise<undefined | ChatMessage>

    The message instance. The SDK returns undefined if the message does not exist.

    A description of the exception. See ChatError.

  • Gets the latest received message from the conversation.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<undefined | ChatMessage>

    The message instance. The SDK returns undefined if the message does not exist.

    A description of the exception. See ChatError.

  • Gets a message from the local database by message ID.

    Parameters

    • msgId: string

      The message ID.

    Returns Promise<undefined | ChatMessage>

    The message.

    A description of the exception. See ChatError.

  • Gets the pinning information of a message.

    Parameters

    • messageId: string

      The message ID.

    Returns Promise<undefined | ChatMessagePinInfo>

    The message pinning information. If the message does not exit or is not pinned, undefined is returned.

    A description of the exception. See ChatError.

  • Retrieves messages of a specified quantity in a conversation from the local database.

    The retrieved messages will also be put in the conversation in the memory according to the timestamp included in them.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • startMsgId: string

      The starting message ID for query. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If this parameter is set an empty string, the SDK retrieves messages according to the message search direction while ignoring this parameter.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection.

      • (Default) ChatSearchDirection.UP: Messages are retrieved in the descending order of the Unix timestamp included in them.
      • ChatSearchDirection.DOWN: Messages are retrieved in the ascending order of the Unix timestamp included in them.
    • loadCount: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,50].

    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2023-07-24. Use getMsgs instead.

  • Gets messages that the specified user sends in a conversation in a certain period.

    This method gets data from the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • keywords: string

      The keywords for query.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection.

      • (Default) ChatSearchDirection.UP: Messages are retrieved in the descending order of the Unix timestamp included in them.
      • ChatSearchDirection.DOWN: Messages are retrieved in the ascending order of the Unix timestamp included in them.
    • timestamp: number = -1

      The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them.

    • count: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,400].

    • Optionalsender: string

      The user ID or group ID for retrieval. Usually, it is the conversation ID.

    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2023-07-24 This method is deprecated. Use getConvMsgsWithKeyword instead.

  • Retrieves messages of a certain type in the conversation from the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • msgType: ChatMessageType

      The message type. See ChatMessageType.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection.

      • (Default) ChatSearchDirection.UP: Messages are retrieved in the descending order of the Unix timestamp included in them.
      • ChatSearchDirection.DOWN: Messages are retrieved in the ascending order of the Unix timestamp included in them.
    • timestamp: number = -1

      The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them.

    • count: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,400].

    • Optionalsender: string

      The user ID or group ID for retrieval. Usually, it is the conversation ID.

    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2023-07-24. Use getMsgsWithMsgType instead.

  • Gets the details of the message thread from the memory.

    Parameters

    • msgId: string

      The message thread ID.

    Returns Promise<undefined | ChatMessageThread>

    If success, the details of the message thread are returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Retrieves messages that are sent and received in a certain period in a conversation in the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • startTime: number

      The starting Unix timestamp for query, in milliseconds.

    • endTime: number

      The ending Unix timestamp for query, in milliseconds.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection.

      • (Default) ChatSearchDirection.UP: Messages are retrieved in the descending order of the Unix timestamp included in them.
      • ChatSearchDirection.DOWN: Messages are retrieved in the ascending order of the Unix timestamp included in them.
    • count: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,400].

    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding with the ones with the starting or ending timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2023-07-24 This method is deprecated. Use getMsgWithTimestamp instead.

  • Retrieves messages of a specified quantity in a conversation from the local database.

    The retrieved messages will also be put in the conversation in the memory according to the timestamp included in them.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Retrieves messages with keywords from the local database.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Retrieves messages of a certain type in the conversation from the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Retrieves messages that are sent and received in a certain period in a conversation in the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • params: {
          convId: string;
          convType: ChatConversationType;
          count?: number;
          direction?: ChatSearchDirection;
          endTime: number;
          isChatThread?: boolean;
          startTime: number;
      }

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding with the ones with the starting or ending timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Gets the pinned messages in a local conversation.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of pinned messages. If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Gets the list of Reactions from a message.

    Parameters

    • msgId: string

      The message ID.

    Returns Promise<ChatMessageReaction[]>

    If success, the Reaction list is returned; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Gets the thread conversation by conversation ID.

    Parameters

    • convId: string

      The conversation ID.

    • createIfNeed: boolean = true

      Whether to create a conversation if the specified conversation is not found:

      • (Default) true: Yes.
      • false: No.

    Returns Promise<undefined | ChatConversation>

    The retrieved conversation object. The SDK returns null if the conversation is not found.

    A description of the exception. See ChatError.

  • Gets the count of the unread messages.

    Returns Promise<number>

    The count of the unread messages.

    A description of the exception. See ChatError.

  • Gets the number of members that have read the group message.

    Parameters

    • msgId: string

      The message ID.

    Returns Promise<undefined | number>

    If success, the SDK returns the number of members that have read the group message; otherwise, an exception will be thrown.

    A description of the exception. See ChatError.

  • Imports messages to the local database.

    You can only import messages that you sent or received.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Inserts a message to the conversation in the local database.

    For example, when a notification messages is received, a message can be constructed and written to the conversation. If the message to insert already exits (msgId or localMsgId is existed), the insertion fails.

    The message will be inserted based on the Unix timestamp included in it. Upon message insertion, the SDK will automatically update attributes of the conversation, including latestMessage.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Leaves a message thread.

    Each member in the message thread can call this method.

    In a multi-device login scenario, note the following:

    Parameters

    • chatThreadId: string

      The ID of the message thread that the current user wants to leave.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Marks all conversations as read.

    This method is for the local conversations only.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Marks all messages as read.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Marks a message as read.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • msgId: string

      The message ID.

    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Modifies a message.

    After this method is called to modify a message, both the local message and the message on the server are modified.

    This method can only modify a text message in one-to-one chats or group chats, but not in chat rooms.

    Parameters

    Returns Promise<ChatMessage>

    The modified message. See ChatMessageBody.

    A description of the exception. See ChatError.

  • Sets whether to pin a conversation.

    Parameters

    • convId: string

      The conversation ID.

    • isPinned: boolean

      Whether to pin a conversation:

      • true:Yes.
      • false: No. The conversation is unpinned.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Pins a message.

    Parameters

    • messageId: string

      The message ID.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Recalls the sent message.

    Parameters

    • msgId: string

      The message ID.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Removes all message listeners.

    Returns void

  • Deletes the specified conversation and its historical messages from the server.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • isDeleteMessage: boolean = true

      Whether to delete the historical messages with the conversation.

      • (Default) true: Yes.
      • false: No.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Removes a member from the message thread.

    Only the owner or admins of the group where the message thread belongs and the message thread creator can call this method.

    The removed member will receive the ChatMessageEventListener.onChatMessageThreadUserRemoved callback.

    You can listen for message thread events by setting ChatMessageEventListener.

    Parameters

    • chatThreadId: string

      The message thread ID.

    • memberId: string

      The user ID of the member to be removed from the message thread.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Removes the message listener.

    Parameters

    Returns void

  • Deletes messages from the conversation (from both local storage and server).

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation Type.

    • msgIds: string[]

      The IDs of messages to delete from the current conversation.

    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes messages from the conversation (from both local storage and server).

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation Type.

    • timestamp: number

      The message timestamp in millisecond. The messages with the timestamp smaller than the specified one will be deleted.

    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes a Reaction.

    Parameters

    • reaction: string

      The Reaction to delete.

    • msgId: string

      The message ID.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Reports an inappropriate message.

    Parameters

    • msgId: string

      The ID of the message to report.

    • tag: string

      The tag of the inappropriate message. You need to type a custom tag, like porn or ad.

    • reason: string

      The reporting reason. You need to type a specific reason.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Resends a message.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Retrieves messages with keywords in a conversation from the local database.

    Parameters

    • keywords: string

      The keywords for query.

    • timestamp: number = -1

      The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them.

    • maxCount: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,400].

    • from: string = ''

      The user ID or group ID for retrieval. Usually, it is the conversation ID.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection. - (Default) ChatSearchDirection.Up: Messages are retrieved in the descending order of the Unix timestamp included in them. - ChatSearchDirection.Down: Messages are retrieved in the ascending order of the Unix timestamp included in them.

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2024-04-22. Use getMsgsWithKeyword instead.

  • Sends the conversation read receipt to the server.

    Note

    • This method is valid only for one-to-one conversations.
    • After this method is called, the sever will set the message status from unread to read.
    • The SDK triggers the ChatMessageEventListener.onConversationRead callback on the client of the message sender, notifying that the messages are read. This also applies to multi-device scenarios.

    Parameters

    • convId: string

      The conversation ID.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Sends the group message receipt to the server.

    Note

    Parameters

    • msgId: string

      The message ID.

    • groupId: string

      The group ID.

    • Optionalopt: {
          content: string;
      }

      The extension information, which is a custom keyword that specifies a custom action or command.

      • content: string

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Sends a message.

    Note

    • For a voice or image message or a message with an attachment, the SDK will automatically upload the attachment.
    • You can determine whether to upload the attachment to the chat sever by setting ChatOptions.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Sends the read receipt to the server.

    This method applies to one-to-one chats only.

    Note

    This method takes effect only when you set ChatOptions.requireAck as true.

    To send a group message read receipt, you can call sendGroupMessageReadAck.

    We recommend that you call sendConversationReadAck when opening the chat page. In other cases, you can call this method to reduce the number of method calls.

    Parameters

    • message: ChatMessage

      The message for which the read receipt is to be sent.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Sets the extension information of the conversation.

    note If the conversation object does not exist, this method will create it.

    Parameters

    • convId: string

      The conversation ID.

    • convType: ChatConversationType

      The conversation type. See ChatConversationType.

    • ext: {
          [key: string]: string | number | boolean;
      }

      The extension information. This parameter must be key-value type.

      • [key: string]: string | number | boolean
    • isChatThread: boolean = false

      Whether the conversation is a thread conversation.

    Returns Promise<void>

  • Parameters

    • event: NativeEventEmitter

    Returns void

  • Translates a text message.

    Parameters

    • msg: ChatMessage

      The text message to translate.

    • languages: string[]

      The target languages.

    Returns Promise<ChatMessage>

    The translation.

    A description of the exception. See ChatError.

  • Unpins a message.

    Parameters

    • messageId: string

      The message ID.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Changes the name of the message thread.

    Only the owner or admins of the group where the message thread belongs and the message thread creator can call this method.

    Each member of the group to which the message thread belongs will receive the ChatMessageEventListener.onChatMessageThreadUpdated callback.

    You can listen for message thread events by setting ChatMessageEventListener.

    Parameters

    • chatThreadId: string

      The message thread ID.

    • newName: string

      The new message thread name. It can contain a maximum of 64 characters.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Updates a message in the local database.

    After you modify a message, the message ID remains unchanged and the SDK automatically updates properties of the conversation, like latestMessage.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Updates the local message.

    The message will be updated both in the memory and local database.

    Parameters

    Returns Promise<ChatMessage>

    The updated message.

    A description of the exception. See ChatError.

  • Type Parameters

    • T

    Parameters

    • method: string
    • Optionalargs: {}

      Returns Promise<T>

    • Parameters

      • result: any

      Returns void

    • Parameters

      Returns void

    • Parameters

      Returns void