Browse SDKs · React Native
SDKsReact Native

Send a message

OpenIM React Native SDK guide for send a message.

Copy

Call sendMessage() to send the MessageItem returned by a message-creation API. For a direct chat, set recvID; for a group chat, set groupID.

When messages are created from local image, audio, video, or file paths, the SDK uploads the resources during sending. For media messages created with remote URLs, use Send an uploaded media message.

const sentMessage = await OpenIMSDK.sendMessage({
  recvID: receiverUserID,
  groupID: '',
  message,
});

Parameters

ParameterTypeRequiredDescription
recvIDstringConditionalRecipient user ID for a direct chat; pass an empty string for a group chat.
groupIDstringConditionalTarget group ID for a group chat; pass an empty string for a direct chat.
messageMessageItemYesMessage to send.
offlinePushInfoOfflinePushNoOffline push configuration.
isOnlineOnlybooleanNoWhether to deliver only to online clients.

The call returns the sent MessageItem.

When sending progress is available, SendMessageProgress is emitted with progress and message:

function handleSendMessageProgress(info) {
  // ...
}

// Set the listener
OpenIMSDK.on(OpenIMEvent.SendMessageProgress, handleSendMessageProgress);

// Remove the listener
OpenIMSDK.off(OpenIMEvent.SendMessageProgress, handleSendMessageProgress);

Remove the listener when the component is destroyed, the account signs out, or the account changes.