Browse SDKs · uni-app / uni-app x
SDKsuni-app

Send a message

Send a pending message object with the uni-app / uni-app x SDK.

Copy

sendMessage() sends an OpenIMMessageItem 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.
messageOpenIMMessageItemYesPending message object to send.
offlinePushInfoOpenIMOfflinePushNoOffline push configuration.
isOnlineOnlybooleanNoWhether to deliver only to online clients. Online-only messages are not stored in local history.
import { sendMessage } from '@/uni_modules/unix-openim-sdk'

const sentMessage = await sendMessage({
  recvID: receiverUserID,
  groupID: '',
  message,
  isOnlineOnly: false,
})

When the Promise resolves, the returned value is the server-confirmed OpenIMMessageItem; the native UTS API does not wrap it in { data }. 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. Keep a failed pending message under the same clientMsgID when offering a retry unless the product deliberately creates a new send.

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