Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create @ mention message

Create an @ mention text message for group chats.

Copy

The HarmonyOS SDK method requires providing message body text, up to 10 mentioned group members, and a quoted source message. Mentioned members require stable user IDs and their current in-group nicknames.

Code example

import sdk, { AtInfo, CreateTextAtMessageReq, CreateTextAtMessageResp } from '@openimsdk/imsdk';

const mentionedUser: AtInfo = {
  atUserID: 'user_a',
  groupNickname: 'Alex',
};
const request: CreateTextAtMessageReq = {
  text: '@Alex Please confirm',
  usersInfo: [mentionedUser],
  quoteMessage: sourceMessage,
};
const response: CreateTextAtMessageResp = await sdk.createTextAtMessage(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
textstringYesBody text containing @ mention strings.
usersInfoAtInfo[]YesList of mentioned users (up to 10), each specifying atUserID and groupNickname.
quoteMessageIMMessageYesA quoted source message from the same group conversation.

Return value

Returns a Promise resolving to CreateTextAtMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated @ mention message object.

State changes after the call

sourceMessage must come from the same group chat via queries or events. Creating this message operates locally without altering conversation mention reminders or firing new message events. When sending the message via Send message, specify the destination groupID.

Mention all members

Do not hardcode mention-all tokens in application code. Retrieve the SDK-defined token first, then build the message:

import sdk, {
  AtInfo,
  CreateTextAtMessageReq,
  CreateTextAtMessageResp,
  GetAtAllTagResp,
} from '@openimsdk/imsdk';

const atAllResult: GetAtAllTagResp = await sdk.getAtAllTag();
const atAllUser: AtInfo = {
  atUserID: atAllResult.tag,
  groupNickname: 'Everyone',
};
const request: CreateTextAtMessageReq = {
  text: `${atAllResult.tag} Please check the group announcement`,
  usersInfo: [atAllUser],
  quoteMessage: sourceMessage,
};
const response: CreateTextAtMessageResp = await sdk.createTextAtMessage(request);
const message = response.message;

getAtAllTag() returns tag string identifying the internal mention-all symbol. It is a read-only query that does not create messages or emit events.