Message overview
OpenIM React Native SDK guide for message overview.
OpenIM React Native SDK represents each message with MessageItem. Creating a message only creates a MessageItem ready to send; to send it to a one-to-one user or group, call a sending API. Receiving, querying, and state changes such as deletion, revocation, and modification are handled through their respective APIs or events.
Message lists use clientMsgID to identify, deduplicate, and update individual messages. MessageItem does not contain conversationID; obtain the message's conversation from the current conversation, history-query parameters, or event context.
Message workflow
| Stage | Related capability | Description |
|---|---|---|
| Create | create*Message() | Creates a MessageItem ready to send. |
| Send | sendMessage() and sendMessageNotOss() | Sends a message to a one-to-one chat or group chat. |
| Receive | New-message events | Receives real-time, offline, and online-only messages. |
| Query | Message history, lookup by ID, and search | Reads or locates saved messages by conversation. |
| State changes | Revocation, deletion, modification, and read receipts | Updates the message list from call results and the corresponding events. |
MessageItem type
The message objects returned when creating, sending, receiving, or querying messages are MessageItem. Common public fields include:
| Field | Type | Description |
|---|---|---|
clientMsgID | string | Client message ID, used to deduplicate, update, and locate messages. |
serverMsgID | string | Server message ID. |
sessionType | SessionType | Conversation type, used to distinguish one-to-one chats from group chats. |
sendID | string | Sender user ID. |
recvID | string | Recipient user ID for a one-to-one message. |
groupID | string | Group ID for a group message. |
contentType | MessageType | Message content type, which determines the content field to render. |
createTime | number | Message-object creation time. |
sendTime | number | Message send time. |
seq | number | Server message sequence number. |
senderPlatformID | Platform | Client platform that sent the message. |
status | MessageStatus | Message send status. |
isRead | boolean | Read state. |
senderNickname | string | Sender nickname. |
senderFaceUrl | string | Sender avatar URL. |
offlinePush | OfflinePush | Offline push configuration. |
content | string | SDK-serialized message content. For rendering, read the content field that corresponds to contentType. |
ex | string | Message extension field. |
localEx | string | Message extension field used only on the current device. |
Message content is stored in the MessageItem field that corresponds to contentType:
| Content | Field |
|---|---|
| Text, rich text, and Markdown | textElem, advancedTextElem, markdownTextElem |
| Images, audio, video, and files | pictureElem, soundElem, videoElem, fileElem |
| @ messages | atTextElem |
| Reply messages | quoteElem |
| Merged forwards | mergeElem |
| Contact cards, locations, and emoji | cardElem, locationElem, faceElem |
| Custom messages | customElem |
| Notifications, typing status, and attached status | notificationElem, typingElem, attachedInfoElem |
All content fields are optional. A message usually uses only the content field that corresponds to its contentType; determine contentType before reading that field for rendering.
Create and send messages
First call the applicable creation API to obtain a MessageItem, then call a sending API. Use Send a message when the SDK uploads a local media file; use Send an uploaded media message when the media file already has a remote URL.
| Content | Page |
|---|---|
| Text and rich text | Create a text message, Create a rich-text message |
| @ messages | Create an @ message |
| Images, audio, video, and files | Create an image message from a file, Create an audio message from a file, Create a video message from files, Create a file message from a file |
| Contact cards, locations, and emoji | Create a contact card message, Create a location message, Create an emoji message |
| Replies, forwards, and merged forwards | Create a reply message, Create a forwarded message, Create a merged forward message |
| Custom messages | Create a custom message |
Browse by task
| Task | Page |
|---|---|
| Receive real-time, offline, and online-only messages | Receive messages |
| Receive custom business messages | Receive custom business messages |
| Load message history or message context | Load message history, Load message context |
| Find or search messages by ID | Find messages by ID, Search messages |
| Delete, revoke, or modify messages | Delete messages in a batch, Revoke a message, Modify a message |
| Manage message data used only on the current device | Delete a local message, Set a local message extension |
| Report or query group message read status | Report group messages as read, Get members who read a group message |
| Report or query typing status | Report typing status, Get typing status |
| Transcribe audio | Check audio transcription availability, Transcribe audio |
Event handling
Complete event-listener examples for message events are available on the following pages:
- New, offline, and online-only messages:
OnRecvNewMessage,OnRecvOfflineNewMessage, andOnRecvOnlineOnlyMessage. See Receive messages. - Custom business messages:
OnRecvCustomBusinessMessage. See Receive custom business messages. - Message deletion:
OnMsgDeleted. See Delete messages in a batch. - Message revocation:
OnNewRecvMessageRevoked. See Revoke a message. - Message modification:
OnMessageModified. See Modify a message. - Group-message read status:
OnRecvGroupReadReceipt. See Report group messages as read. - Typing-status changes:
OnInputStatusChanged. See Update input states.
Was this page helpful?