Send Group @ Message
You can send group @ messages in a group.
Constructing @ Messages
The content of the message to be sent can be an instance of a built-in message like RongIMLib.TextMessage, or a custom message instance implemented through RongIMLib.registerMessageType().
const details = {
content: 'I am a text message',
mentionedInfo: {
type: 1, //1: @ all 2: @ specified users
userIdList: ['user1'], //List of user IDs to be @mentioned
mentionedContent: 'Someone mentioned you' //Carry extended information, such as 'Someone mentioned you'
}
}
const message = new RongIMLib.TextMessage(details)
| Parameter | Type | Required | Description |
|---|---|---|---|
| content | String | Yes | Text content |
| mentionedInfo | Object | No | Details of the @ information. |
| mentionedInfo.type | Number | No | Type of @ message 1: @ all 2: @ specified users |
| mentionedInfo.userIdList | String [] | No | List of user IDs to be @mentioned |
| mentionedInfo.mentionedContent | String | No | Push notification content, such as 'Someone mentioned you'. The mentionedContent in the @ message has the highest priority and will override all default or custom pushContent data. |
Sending @ Messages
Call sendMessage to send @ messages in a group. Make sure to set isMentioned to true.
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 valid when the conversationType value 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);
}
})
The sendMessage method has the following parameters:
-
conversation: - The target conversation for message delivery, API reference IConversationOption
-
message: The content of the message to be sent, which can be an instance of a built-in message like
RongIMLib.TextMessage, or a custom message instance implemented throughRongIMLib.registerMessageType(). -
options: Defines some optional behaviors in the sending process, such as whether it is extensible, push, etc.
Parameter Type Required Description isMentioned boolean No Whether it is an @ message, only valid when the conversationType value is ConversationType.GROUPdisableNotification boolean No When set to true, the server will not send Push notifications, and the mobile device will not pop up local notification reminders