Send a message
Send a pending message object with the WASM SDK.
sendMessage() sends a MessageItem returned by a message creation API. For a one-to-one chat, set only recvID; for a group chat, set only groupID.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
recvID | string | Conditional | Recipient's user ID for a one-to-one chat. Pass an empty string for a group chat. |
groupID | string | Conditional | Target group ID for a group chat. Pass an empty string for a one-to-one chat. |
message | MessageItem | Yes | Pending message object to send. |
offlinePushInfo | OfflinePush | No | Offline push configuration. |
isOnlineOnly | boolean | No | Whether to deliver only to online clients. Online-only messages are not stored in local history. |
const { data: sentMessage } = await openimsdk.sendMessage({
recvID: receiverUserID,
groupID: '',
message,
});When the Promise resolves, data is the server-confirmed MessageItem. On the sending client, replace the local pending item by clientMsgID with the returned object. For common and content-specific fields, see Message overview.
Other clients receive the message through new-message events. Completion of the send Promise, arrival of the event on another client, and any later history query are separate stages.
If your application has already uploaded the resource and stored it in a URL-based message, use sendMessageNotOss() instead; see Send an uploaded media message for the complete flow.
Was this page helpful?