Browse SDKs · React Native
SDKsReact Native

Message overview

OpenIM React Native SDK guide for message overview.

Copy

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

StageRelated capabilityDescription
Createcreate*Message()Creates a MessageItem ready to send.
SendsendMessage() and sendMessageNotOss()Sends a message to a one-to-one chat or group chat.
ReceiveNew-message eventsReceives real-time, offline, and online-only messages.
QueryMessage history, lookup by ID, and searchReads or locates saved messages by conversation.
State changesRevocation, deletion, modification, and read receiptsUpdates 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:

FieldTypeDescription
clientMsgIDstringClient message ID, used to deduplicate, update, and locate messages.
serverMsgIDstringServer message ID.
sessionTypeSessionTypeConversation type, used to distinguish one-to-one chats from group chats.
sendIDstringSender user ID.
recvIDstringRecipient user ID for a one-to-one message.
groupIDstringGroup ID for a group message.
contentTypeMessageTypeMessage content type, which determines the content field to render.
createTimenumberMessage-object creation time.
sendTimenumberMessage send time.
seqnumberServer message sequence number.
senderPlatformIDPlatformClient platform that sent the message.
statusMessageStatusMessage send status.
isReadbooleanRead state.
senderNicknamestringSender nickname.
senderFaceUrlstringSender avatar URL.
offlinePushOfflinePushOffline push configuration.
contentstringSDK-serialized message content. For rendering, read the content field that corresponds to contentType.
exstringMessage extension field.
localExstringMessage extension field used only on the current device.

Message content is stored in the MessageItem field that corresponds to contentType:

ContentField
Text, rich text, and MarkdowntextElem, advancedTextElem, markdownTextElem
Images, audio, video, and filespictureElem, soundElem, videoElem, fileElem
@ messagesatTextElem
Reply messagesquoteElem
Merged forwardsmergeElem
Contact cards, locations, and emojicardElem, locationElem, faceElem
Custom messagescustomElem
Notifications, typing status, and attached statusnotificationElem, 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.

Browse by task

TaskPage
Receive real-time, offline, and online-only messagesReceive messages
Receive custom business messagesReceive custom business messages
Load message history or message contextLoad message history, Load message context
Find or search messages by IDFind messages by ID, Search messages
Delete, revoke, or modify messagesDelete messages in a batch, Revoke a message, Modify a message
Manage message data used only on the current deviceDelete a local message, Set a local message extension
Report or query group message read statusReport group messages as read, Get members who read a group message
Report or query typing statusReport typing status, Get typing status
Transcribe audioCheck audio transcription availability, Transcribe audio

Event handling

Complete event-listener examples for message events are available on the following pages: