Skip to main content

Send Targeted Group Messages

The IMLib SDK supports sending targeted messages in group conversations. Targeted messages are only delivered to one or more specified members, while other users in the group conversation will not receive the message.

Enable Services

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

  • The Cloud Storage for One-to-One and Group Messages service is enabled by default. This service is available for Chat Starter Plan and Chat Pro Plan. Specific features and pricing are subject to the RC Official Pricing Page.

  • Cloud Storage for Group Targeted Message service. You can enable this service in the RC Console under Chat > Chat settings > Global Messages.

By default, both sent and received targeted group messages are not 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 targeted group messages sent or received by the current user.

Send Targeted Group Text Messages

Send text messages to specified single or multiple users in a group.

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

Method Signature



- (void)sendDirectionalMessage:(RCMessage *)message
toUserIdList:(NSArray<NSString *> *)userIdList
pushContent:(nullable NSString *)pushContent
pushData:(nullable NSString *)pushData
attached:(nullable void(^)(RCMessage *_Nullable message))attachedBlock
successBlock:(nullable void (^)(RCMessage *successMessage))successBlock
errorBlock:(nullable void (^)(RCErrorCode nErrorCode, RCMessage *errorMessage))errorBlock;

Parameters

ParameterTypeDescription
messageRCMessageThe message object.
userIdListNSArrayList of recipient users.
pushContentNSStringCustom push notification display content.
pushDataNSStringAdditional information for remote push notifications.
attachedBlockBlockCallback when the message is stored in the database, with message being the stored message object.
successBlockBlockCallback for successful message sending.
errorBlockBlockCallback for failed message sending, including the error code RCErrorCode and the failed message.

Example Code

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
attached:^(RCMessage * _Nullable message) {

} successBlock:^(RCMessage * _Nonnull successMessage) {

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

}];

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 in a group chat.

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

Method Signature



- (void)sendDirectionalMediaMessage:(RCMessage *)message
toUserIdList:(NSArray<NSString *> *)userIdList
pushContent:(nullable NSString *)pushContent
pushData:(nullable NSString *)pushData
attached:(nullable void(^)(RCMessage *_Nullable message))attachedBlock
progress:(nullable void (^)(int progress, RCMessage *progressMessage))progressBlock
successBlock:(nullable void (^)(RCMessage *successMessage))successBlock
errorBlock:(nullable void (^)(RCErrorCode nErrorCode, RCMessage *errorMessage))errorBlock
cancel:(nullable void (^)(RCMessage *cancelMessage))cancelBlock;

Parameters

ParameterTypeDescription
messageRCMessageThe message object.
userIdListNSArrayList of recipient users.
pushContentNSStringCustom push notification display content.
pushDataNSStringAdditional information for remote push notifications.
progressBlockCallback for message upload progress updates.
successBlockBlockCallback when the message is stored in the database, with message being the stored message object.
successBlockBlockCallback for successful message sending.
errorBlockBlockCallback for failed message sending, including the error code RCErrorCode and the failed message.
cancelBlockCallback when the user cancels message sending.

Example Code

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 attached:^(RCMessage * _Nullable message) {

}progress:^(int progress, RCMessage * _Nonnull progressMessage) {
// Media upload progress callback
} successBlock:^(RCMessage * _Nonnull successMessage) {
// Message sent successfully
} errorBlock:^(RCErrorCode nErrorCode, RCMessage * _Nonnull errorMessage) {
// Message sending failed
} cancel:^(RCMessage * _Nonnull cancelMessage) {
// User canceled sending
}];