Send @mention messages
Send @mention messages in a group channel to notify specific users or all members.
Send an @mention message
Set mentionedInfo in the message content to mark this as a mention message:
TypeScript
import { GroupChannel, SendTextMessageParams, MentionedType } from '@nexconn/chat';
const channel = new GroupChannel('<group-id>');
// Put mention info inside the message content
const params = new SendTextMessageParams({
text: '@user1 Check this out!',
mentionedInfo: {
type: MentionedType.USERS, // Mention specific users
userIdList: ['user1'],
},
});
const { code, data } = await channel.sendMessage(params);
if (code === 0) {
console.log('@mention message sent:', data);
}
Handle @mention messages
Incoming messages can be identified as mention messages via the isMentioned property:
TypeScript
import { NCEngine, MessageHandler, Message } from '@nexconn/chat';
NCEngine.addMessageHandler('mention-handler', new MessageHandler({
onMessageReceived({ messages }): void {
messages.forEach((msg) => {
if (msg.isMentioned) {
console.log('Mentioned!', msg);
}
});
},
}));
tip
@mention messages interact with do-not-disturb settings. When DND is set to "mentions only", only @mention messages trigger push notifications.