Send Group Targeted Message
The SDK supports sending targeted messages in group chats. Targeted messages are only delivered to specified users, while other users in the group chat will not receive these messages.
Enabling Services
No service activation is required to use the Send Group Targeted Message feature. Note that if you need to store group targeted messages in server-side historical message records, the following services must be enabled:
-
The Cloud Storage for One-to-One and Group Messages service is enabled by default. If you are using an App Key in the production environment, this service is available for Chat Starter Plan or Chat Pro Plan. For specific features and pricing, refer to the Billing Guide document.
-
Cloud Storage for Group Targeted Message service. You can enable this service in the RC Console under Chat > Chat settings > Global Message.
By default, neither sent nor received group targeted messages are stored in the historical message service. Therefore, when clients call APIs to retrieve historical messages, the results returned from the RC server will not include group targeted messages that the current user has sent or received.
Sending Group Targeted Messages
You can specify a list of user IDs to receive targeted messages by setting the options.directionalUserIdList parameter, then call the sendMessage method to send group targeted messages.
The targeted message feature only takes effect when conversationType is set to ConversationType.GROUP.
Sample Code
//Send group targeted message (only effective when conversationType is `ConversationType.GROUP`)
const conversationType = RongIMLib.ConversationType.GROUP
const targetId = 'GroupID'
const message = new RongIMLib.TextMessage({
content: 'I am a text message'
})
RongIMLib.sendMessage({
conversationType,
targetId
}, message, {
directionalUserIdList: ['user1'], // User ID list
}).then(res => {
if(res.code === 0){
// Successfully sent group @ message
console.log(res.data)
}
})