SDKsHarmonyOSEnterprise
Insert local single chat message
Insert a local-only message into the single chat history on the current device.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
msg | IMMessage | Yes | Message object to insert into the local database. |
recvID | string | Yes | Recipient user ID in the single chat. |
sendID | string | Yes | Sender user ID. |
Return value
Returns a Promise resolving to InsertSingleMessageToLocalResp:
| Property | Type | Description |
|---|---|---|
msg | IMMessage | The 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.
Was this page helpful?