Browse SDKs · WASM
SDKsWASM

Send a message

Send a pending message object with the WASM SDK.

Copy

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

ParameterTypeRequiredDescription
recvIDstringConditionalRecipient's user ID for a one-to-one chat. Pass an empty string for a group chat.
groupIDstringConditionalTarget group ID for a group chat. Pass an empty string for a one-to-one chat.
messageMessageItemYesPending message object to send.
offlinePushInfoOfflinePushNoOffline push configuration.
isOnlineOnlybooleanNoWhether 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. Promise completion, arrival of the receiving event, and reconciliation through a history query are separate stages.

If the resource has already been uploaded by your application and stored in a URL-based message, use sendMessageNotOss().