Send Group @ Message
In group conversations, IMLib supports sending group @ messages, which can be used to notify all members or specified members in the group.
Constructing @ Messages
The message content to be sent can be an instance of a built-in message type (such as RongIMLib.TextMessage) or a custom message type instance registered via RongIMLib.registerMessageType().
Constructing @ messages requires setting the mentionedInfo parameter
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| content | string | Yes | Text content |
| mentionedInfo | MentionedInfo | No | Construction parameter for @ messages |
- mentionedInfo Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| type | number | Yes | @ message type: 0: @ all, 1: @ specified users |
| userIdList | string[] | No | List of user IDs to @ |
| mentionedContent | string | No | Push notification content, e.g., 'Someone mentioned you'. The mentionedContent in @ messages has the highest priority and will override all default or custom pushContent data. |
Example Code
const details = {
content: 'I am a text message',
mentionedInfo: {
type: 1, //1: @ all 2: @ specified users
userIdList: ['user1'], //List of user IDs to @
mentionedContent: 'Someone mentioned you' //Extended information, e.g., 'Someone mentioned you'
}
}
const message = new RongIMLib.TextMessage(details)
## Sending @ Messages
Call [sendMessage](https://docs.rongcloud.cn/web-imlib/message/send) to send @ messages in a group. Ensure that `isMentioned` is set to true in the options, as this configuration only takes effect in group conversations (`ConversationType.GROUP`).
#### Parameter Description
| Parameter | Type | Required | Description |
|:--------|:-------|:-------|:------ |
| conversation | [IConversationOption](https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/interfaces/IConversationOption.html) | Yes | Target conversation |
| message | [BaseMessage](https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/classes/BaseMessage.html) | Yes | Message instance to be sent. Must be a subclass of BaseMessage, which can be a built-in IMLib message (e.g., RongIMLib.TextMessage) or a custom message instance registered via RongIMLib.registerMessageType(). |
| options | [ISendMessageOptions](https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/interfaces/ISendMessageOptions.html) | No | Sending configuration options. Defines optional behaviors during sending, such as extensibility and push notifications. |
#### Example Code
```js
const details = {
content: 'I am a text message',
mentionedInfo: {
type: 1,
userIdList: ['user1'],
mentionedContent: 'Someone mentioned you'
}
}
const message = new RongIMLib.TextMessage(details)
//Send @ message, only effective when conversationType is `ConversationType.GROUP`
const conversation = {
conversationType: RongIMLib.ConversationType.GROUP,
targetId: 'Target ID'
}
const options = {
isMentioned: true
}
RongIMLib.sendMessage(conversation, message, options).then(res => {
if(res.code === 0){
// Successfully sent group @ message
console.log(res.data)
} else {
console.log(res.code, res.msg);
}
})