Skip to main content

Send Targeted Group Messages

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

Enable Services

No service activation is required to use the Send Targeted Group Messages feature. However, if you need to store targeted group messages in the server-side historical message records, the following services must be activated:

  • Cloud Storage for One-to-One and Group Messages service. You can enable this service for the App Key you are using by visiting the Chat pricing plans page in the Console. This service can be activated for Chat Premium Plan or Chat Ultimate Plan. For specific features and pricing, refer to the Billing Documentation.
  • Cloud Storage for Group Targeted Message service. You can enable this service via the RC Console by navigating to Configuration > Chat settings > Basic features > One-to-One and Group Chat, and then activating 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 the group targeted messages sent or received by the current user.

Send Targeted Regular Messages

Send regular messages to specified single or multiple users within a group.

To send a text message, you need to construct an RCMessage and then call sendDirectionalMessage:toUserIdList:pushContent:pushData:attached:successBlock:errorBlock: to send the message. Note that the RCMessage only stores the group ID (Target ID) and does not store the list of recipient user IDs.

RCTextMessage *text = [RCTextMessage messageWithContent:@"Hello"];
RCMessage *message = [[RCMessage alloc] initWithType:ConversationType_GROUP targetId:@"Group1" direction:MessageDirection_SEND messageId:-1 content:text];

[[RCCoreClient sharedCoreClient] sendDirectionalMessage:message
toUserIdList:@[@"user1",@"user2"]
pushContent:nil
pushData:nil
successBlock:^(RCMessage *successMessage) {

} errorBlock:^(RCErrorCode nErrorCode, RCMessage *errorMessage) {

}];
ParameterTypeDescription
messageRCMessageThe message object
userIdListNSArrayThe list of users to send the message to
pushContentNSStringCustom push notification content
pushDataNSStringAdditional information for remote push notifications
successBlockBlockCallback for successful message delivery
errorBlockBlockCallback for failed message delivery, including the error code RCErrorCode and the failed message

Send Targeted Media Messages

tip

The SDK supports sending targeted media messages in group chats starting from version 5.2.5.

Send multimedia messages to specified single or multiple users within a group chat.

To send an image message, you need to construct an RCMessage and then call sendDirectionalMediaMessage:toUserIdList:pushContent:pushData:attached:progress:successBlock:errorBlock:cancel: to send the message. Note that the RCMessage only stores the group ID (Target ID) and does not store the list of recipient user IDs.

RCImageMessage *imageMessage = [RCImageMessage messageWithImageURI:@"https://test.png"];
RCMessage *message = [[RCMessage alloc] initWithType:ConversationType_GROUP targetId:@"Group1" direction:MessageDirection_SEND messageId:-1 content:imageMessage];

[[RCCoreClient sharedCoreClient] sendDirectionalMediaMessage:message toUserIdList:@[@"user1",@"user2"] pushContent:nil pushData:nil progress:^(int progress, RCMessage * _Nonnull progressMessage) {
// Callback for media upload progress
} successBlock:^(RCMessage * _Nonnull successMessage) {
// Callback for successful message delivery
} errorBlock:^(RCErrorCode nErrorCode, RCMessage * _Nonnull errorMessage) {
// Callback for failed message delivery
} cancel:^(RCMessage * _Nonnull cancelMessage) {
// Callback for user cancellation of message sending
}];
ParameterTypeDescription
messageRCMessageThe message object
userIdListNSArrayThe list of users to send the message to
pushContentNSStringCustom push notification content
pushDataNSStringAdditional information for remote push notifications
progressBlockCallback for message upload progress
successBlockBlockCallback for successful message delivery
errorBlockBlockCallback for failed message delivery, including the error code RCErrorCode and the failed message
cancelBlockCallback for user cancellation of message sending