Send message
Send a message to a one-to-one or group conversation with automatic media upload using the OpenIM React Native SDK.
Dispatch a MessageItem constructed by a message creation method to a designated one-to-one or group conversation:
When sending image, audio, video, or file messages created with local filesystem paths, the SDK automatically uploads the media files prior to dispatch. If media files are already hosted on your own server or object storage and created via URL, use Send uploaded media message.
const sentMessage = await OpenIMSDK.sendMessage({
recvID: receiverUserID,
groupID: '',
message,
});Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
recvID | string | Conditional | Recipient user ID for one-to-one chats; pass an empty string "" for group chats. |
groupID | string | Conditional | Target group ID for group chats; pass an empty string "" for one-to-one chats. |
message | MessageItem | Yes | Message object generated by a message creation method. |
offlinePushInfo | OfflinePush | No | Custom offline push notification title, content, and passthrough payload. |
isOnlineOnly | boolean | No | Whether to deliver solely to currently online clients without storing in server offline history. |
Return value
A resolved Promise returns the dispatched MessageItem containing server-assigned properties such as serverMsgID, sendTime, and updated status.
State changes and lifecycle phases
- Promise resolution: Indicates the message has been written to the local database and accepted by the OpenIM server dispatch queue. It does not signify that the counterparty has received or read the message.
- Event arrival: During media uploads, the SDK periodically emits
SendMessageProgressevents. When the counterparty receives or reads the message, corresponding delivery or read-receipt events are triggered. - Re-query reconciliation: If disconnected or encountering timeout errors, invoke Load older messages upon reconnecting to verify the final message status.
Always use clientMsgID as the unique key to transition message state from "sending" to "success" or "failed" in local UI state.
Listen for media upload progress
Track upload progress when dispatching large files, high-resolution videos, or audio:
interface SendMessageProgressPayload {
clientMsgID: string;
progress: number;
}
const handleSendMessageProgress = ({
clientMsgID,
progress,
}: SendMessageProgressPayload) => {
// Locate the pending message by clientMsgID and update UI upload percentage
};
// Register listener
OpenIMSDK.on(OpenIMEvent.SendMessageProgress, handleSendMessageProgress);
// Unregister listener on cleanup
OpenIMSDK.off(OpenIMEvent.SendMessageProgress, handleSendMessageProgress);Unregister the listener using the same function reference when unmounting screens or signing out.
Was this page helpful?