Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app xIncludes Enterprise features

Message overview

Understand message creation, transmission, reception, querying, and lifecycle synchronization workflows.

Copy

The OpenIM UniApp SDK represents each message record using the OpenIMMessageItem interface. Message transmission operates in two distinct phases: first, construct an outgoing message data object using the appropriate creation method, and then transmit that object to a target user or group. Message creation methods do not send data over the network; likewise, Promise resolution from a send invocation does not guarantee that other devices have rendered the incoming message.

In message lists, locate individual messages using their owning conversation and clientMsgID. The conversationID is derived from the active conversation context, query filter, search result, or event payload, rather than being an intrinsic property of OpenIMMessageItem.

Message processing phases

PhaseCore operationsDescription
CreateInvoke the corresponding message creation methodReturns an OpenIMMessageItem or null. Generates the local message data structure without transmitting data or triggering new message events.
SendInvoke Send a message or Send a non-OSS messageSupply recvID for single chats, or groupID for group chats; pass an empty string "" for the unneeded target field.
ReceiveListen for incoming message eventsIdentify the destination conversation and merge items by clientMsgID; ignore duplicate event deliveries.
QueryLoad message history, search, or look up by IDRetrieves messages stored locally at the time of invocation without emitting message events.
UpdateDelete, revoke, edit, pin, or report read receiptsManage Promise resolution, incoming update events, and state re-queries independently.

For local image, audio, video, and file media, Send a message handles automated upload to storage before message transmission. If assets are already uploaded to your business server and possess public remote URLs, create URL-based message items and transmit them via Send a non-OSS message to bypass duplicate file uploads.

Common message fields

FieldTypeDescription
clientMsgIDstring | nullClient-generated message ID used for list deduplication and state tracking; verify existence in created objects.
serverMsgIDstring | nullServer-assigned message ID; null or empty while pending or if sending failed.
sessionTypeOpenIMSessionTypeChat session type, such as single chat or group chat.
sendIDstring | nullUser ID of the message sender.
recvIDstring | nullRecipient user ID for single chats; empty string in group chats.
groupIDstring | nullTarget group ID for group chats; empty string in single chats.
msgFromnumberMessage origin indicator.
contentTypeOpenIMMessageTypeMessage content type enum, determining which element field contains the payload.
createTimenumberTimestamp when the message object was created locally, in Unix milliseconds.
sendTimenumberTimestamp when the message was sent, in Unix milliseconds.
seqnumberAuthoritative sequence number assigned by OpenIMServer; absent before transmission succeeds.
senderPlatformIDOpenIMPlatformOperating platform constant of the sender device.
senderNicknamestring | nullSender nickname recorded in the message snapshot.
senderFaceUrlstring | nullSender avatar URL recorded in the message snapshot.
statusOpenIMMessageStatusMessage dispatch status (sending, success, or failed).
isReadbooleanRead receipt status at the time of receipt or query.
offlinePushOpenIMOfflinePush | nullOffline push notification configuration applied to this message.
contentstring | nullSerialized message body preserved by the SDK; prefer rendering the dedicated element property.
attachedInfostring | nullSDK internal auxiliary string; parse only according to confirmed business protocols.
exstring | nullCustom extension string synchronized with other participants across all clients.
localExstring | nullExtension string preserved exclusively in the local database of the current device.

The message body resides in the dedicated element property matching contentType:

Content payloadDedicated property
TexttextElem
Image, audio, video, filepictureElem, soundElem, videoElem, fileElem
@ mentions, quote repliesatTextElem, quoteElem
Merged forward, custommergeElem, customElem
Contact card, location, facecardElem, locationElem, faceElem
Advanced text, typing statusadvancedTextElem, typingElem
System notifications, auxiliary statenotificationElem, attachedInfoElem

The constants OpenIMMessageTypeUserCommandAdded, OpenIMMessageTypeUserCommandDeleted, and OpenIMMessageTypeUserCommandUpdated are OpenIMMessageType values used to recognize UserCommand business notifications. They are identified by evaluating contentType, not through separate event names.

Never evaluate message identity using display strings, array indices, or paginated list offsets. Always merge message states using conversationID:clientMsgID. Write device-specific display flags to localEx, while using ex or message payloads for business data that must synchronize across participants.

Message operation guides

Message creation and read-only query operations return the snapshot result of that single call without triggering shared message events. For state-modifying actions, Promise resolution, event notification, and re-querying current data represent three distinct and decoupled execution phases.