Skip to main content

Send Group Targeted Message

The SDK supports sending targeted messages in group chats. Targeted messages are only sent to specified users, and other users in the group chat will not receive the message.

Enable Services

No service needs to be enabled to use the Send Group Targeted Message feature. However, if you need to store group targeted messages in the server-side historical message records, the following services must be enabled:

  • Cloud Storage for One-to-One and Group Messages: You can enable this service for the current App Key on the Chat pricing plans page in the Console. This service is available for Chat Premium Plan or Chat Ultimate Plan. For specific features and pricing, refer to Billing Instructions document.
  • Cloud Storage for Group Targeted Message: You can enable this service in the RC Console by navigating to Configuration > Chat settings > Basic features > One-to-One and Group Chat and enabling Cloud Storage for Group Targeted Message.

By default, group targeted messages sent and received by the client are not stored in the historical message service. Therefore, when the client calls the API to retrieve historical messages, the results returned from the RC server will not include group targeted messages sent or received by the current user.

Send Group Targeted Message

Call sendMessage to send a group targeted message.

// Send a group targeted message, only valid when the 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 the group targeted message
console.log(res.data)
}
})