Create @ mention message
Create an @ mention text message for group chats.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Body text containing @ mention strings. |
usersInfo | AtInfo[] | Yes | List of mentioned users (up to 10), each specifying atUserID and groupNickname. |
quoteMessage | IMMessage | Yes | A quoted source message from the same group conversation. |
Return value
Returns a Promise resolving to CreateTextAtMessageResp:
| Property | Type | Description |
|---|---|---|
message | IMMessage | Locally 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.
Was this page helpful?