Browse SDKs · WASM
SDKsWASM

Message overview

Understand how MessageItem is created, sent, received, queried, and synchronized.

Copy

The WASM SDK represents each message as a MessageItem. Sending a message has two stages: first create a pending message object for the desired content, then send that object to an individual user or a group. A creation method does not send the message, and a successful send Promise does not mean that other clients have already received it.

Receiving new messages, loading history, searching, and managing messages are all scoped to a conversation. Store both conversationID and clientMsgID in a message list: the former identifies the conversation, while the latter locates and merges a specific message.

Message processing flow

StagePrimary operationDescription
CreateCall the corresponding create*Message() methodReturns a pending MessageItem; it does not write to the server or trigger a new-message event.
SendCall sendMessage() or sendMessageNotOss()For a one-to-one chat, set recvID; for a group chat, set groupID. Pass an empty string for the other target field.
ReceiveListen for new-message eventsDetermine the target conversation from the message routing fields, then merge idempotently by clientMsgID.
QueryLoad history, search, or locate messages by IDQueries return a snapshot at call time and do not trigger new-message events.
UpdateDelete, revoke, modify, pin, or report message read statusHandle Promise results, related events, and any necessary re-query separately.

For image, audio, video, and file messages created from a browser File, sendMessage() uses the SDK's built-in upload and send flow. If your application has already obtained a media URL from its upload service, create the message with the corresponding create*MessageByURL() method and send it with sendMessageNotOss() to avoid uploading the resource again.

MessageItem structure

Whether a message is created, sent, received, or queried, the message object in data is a MessageItem. Common fields include:

FieldTypeDescription
clientMsgIDstringStable client-side message ID used for list deduplication, state updates, queries, and history pagination cursors.
serverMsgIDstringServer-side message ID. A pending or failed message may not yet have a valid value.
sessionTypeSessionTypeConversation type to which the message belongs, such as one-to-one or group chat.
sendIDstringSender's user ID.
recvIDstringRecipient's user ID for a one-to-one message; usually empty for a group message.
groupIDstringGroup ID for a group message; usually empty for a one-to-one message.
contentTypeMessageTypeMessage content type, which determines which content field to read.
createTimenumberTime when the message object was created.
sendTimenumberTime when the message was sent, used for message ordering.
seqnumberServer-side message sequence number. A message that has not been sent successfully may not have a usable sequence number.
senderPlatformIDPlatformClient platform from which the message was sent.
senderNicknamestringSnapshot of the sender's nickname.
senderFaceUrlstringSnapshot of the sender's avatar URL.
statusMessageStatusCurrent send state: sending, succeeded, or failed.
isReadbooleanSnapshot of the message's current read state.
offlinePushOfflinePush (optional)Offline push configuration used when sending.
exstring (optional)Extension string synchronized with the message.
localExstring (optional)Extension string stored only on the current device.

The message body is stored in the content field corresponding to contentType. Do not infer the message type from its array position or rendered text:

Message contentCorresponding field
Text and MarkdowntextElem, markdownTextElem
Image, audio, video, and filepictureElem, soundElem, videoElem, fileElem
@ mention and replyatTextElem, quoteElem
Merged forward and custom messagemergeElem, customElem
Contact card, location, and emojicardElem, locationElem, faceElem
Advanced text and typing statusadvancedTextElem, typingElem
Notification and attached statenotificationElem, attachedInfoElem

conversationID identifies the conversation to which a message belongs, but it is not a field of MessageItem. Obtain it from the active conversation, history query criteria, search result, or event context. Message state is generally merged by conversationID:clientMsgID.

Create messages with different content types

ContentEntry pointImportant details
Text and MarkdownCreate a text message, Create a Markdown messageRender Markdown safely on the receiving client.
Group @ mentionsCreate an @ messageAvailable only in group chats. Conversation data maintains the @ alert state.
Image, audio, video, and fileCreate an image message from a file, Create an image message from a URLOther media types use the same local-file or uploaded-URL paths.
Contact card, location, and emojiCreate a contact card message, Create a location message, Create an emoji messageCreation stores a content snapshot; it does not update automatically when the source data changes.
Reply, forward, and merged forwardCreate a reply message, Create a forwarded message, Create a merged messageThe created object must still be sent explicitly.
Custom business contentCreate a custom messageSuitable for structured application data that must be synchronized to conversation members.

Store state that affects only the current client's presentation in localEx; do not place business content that must be synchronized to other users there. See Set a local message extension.

Find a page by task

TaskPage
Send an ordinary message or media that has already been uploadedSend a message, Send an uploaded media message
Receive online, offline, and online-only messagesReceive messages
Load history, load in reverse, or retrieve message contextLoad message history, Load message history in reverse, Load message context
Locate messages by ID or search local messagesFind messages by ID, Search messages
Delete, revoke, modify, or pin messagesDelete messages in a batch, Revoke a message, Modify a message, Pin or unpin a message
Clear a conversation's unread count or manage member-level group read statusMark a conversation as read, Report group messages as read, Get members who read a group message
Report typing status or transcribe audioReport typing status, Transcribe audio
Insert, delete, or extend messages visible only on the current deviceInsert a local one-to-one message, Delete a local message, Set a local message extension

State synchronization boundaries

The complete listener implementation for each message event is maintained only on its canonical page:

ChangeCanonical event pageMerge strategy
New, offline, and online-only messagesReceive messagesDetermine the target conversation, then merge by clientMsgID.
Message deletionDelete messages in a batchRemove by target conversation and clientMsgID.
Message revocationRevoke a messageUpdate the message to the revoked state by clientMsgID.
Message modificationModify a messageReplace message content by clientMsgID.
Message pinningPin or unpin a messageUpdate the pinned set by conversationID.
Group read receiptReport group messages as readMerge by conversationID and clientMsgID.
Typing statusReport typing statusUpdate by conversationID:userID.

Conversation unread counts, total unread count, and group @ alerts are conversation state. Their event handlers are maintained on Mark a conversation as read, Maintain the total unread count, and Get the conversation list, respectively.

Creating a message object and performing a read-only query use the Promise result only to establish a snapshot; they do not trigger shared message events. For state-changing operations, treat Promise completion, event arrival, and re-query reconciliation as separate stages.