Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Insert local group message

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

Copy

Inserts a synthetic or migrated message directly into the local device database for a group chat.

Code example

import sdk, { InsertGroupMessageToLocalReq, InsertGroupMessageToLocalResp } from '@openimsdk/imsdk';

const request: InsertGroupMessageToLocalReq = {
  msg: message,
  groupID: groupID,
  sendID: currentUserID,
};
const response: InsertGroupMessageToLocalResp = await sdk.insertGroupMessageToLocal(request);
insertMessage(response.msg);

Parameters

ParameterTypeRequiredDescription
msgIMMessageYesMessage object to insert into the local database.
groupIDstringYesTarget group identifier.
sendIDstringYesSender user ID shown on the message bubble.

Return value

Returns a Promise resolving to InsertGroupMessageToLocalResp:

PropertyTypeDescription
msgIMMessageThe inserted message object with initialized database state.

State changes after the call

groupID and sendID must match the message routing and display context. Merge the inserted item into UI feeds using clientMsgID (qualified by conversationID as needed). Resolving the Promise modifies only the local database of the current device; it does not dispatch messages to group members or trigger shared message arrival events. To insert a local message in single chat, see Insert local single message.