Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Insert local single chat message

Insert a local-only message into the single chat history on the current device.

Copy

Local insertion is intended for device-local system prompts, notices, or migration data that should not be transmitted to the peer.

Code example

import sdk, {
  InsertSingleMessageToLocalReq,
  InsertSingleMessageToLocalResp,
} from '@openimsdk/imsdk';

const request: InsertSingleMessageToLocalReq = {
  msg: message,
  recvID: targetUserID,
  sendID: currentUserID,
};
const response: InsertSingleMessageToLocalResp = await sdk.insertSingleMessageToLocal(request);
insertMessage(response.msg);

Parameters

ParameterTypeRequiredDescription
msgIMMessageYesMessage object to insert into the local database.
recvIDstringYesRecipient user ID in the single chat.
sendIDstringYesSender user ID.

Return value

Returns a Promise resolving to InsertSingleMessageToLocalResp:

PropertyTypeDescription
msgIMMessageThe inserted message object.

State changes after the call

sendID and recvID must match the destination single chat conversation. Clients merge inserted records into local feeds using clientMsgID (qualified by conversationID as needed). Resolving the Promise affects only the current device without sending network messages, triggering offline push notifications, or firing new message events. To insert local messages in group chats, see Insert local group message.