Sending Ultra Group Targeted Messages
You can send regular messages and multimedia messages to one or more specified members in an ultra group channel, while other members will not receive these messages.
- This capability is supported starting from version 5.6.9.
- The maximum number of recipients for a single targeted message is 300 users.
- If the targeted message is an @mention message, @all is not supported.
Sending Targeted Regular Messages
You can use sendDirectionalMessage:toUserIdList:pushContent:pushData:attached:successBlock:errorBlock: to send regular messages to specified users in a specific channel of an ultra group. Users not in the recipient list will not receive this message.
Set the ultra group conversation type, ultra group targetId, and channel channelId in the message object. When channelId is empty, messages are sent to the RCDefault channel by default. Note that the recipient userId list is not stored in the RCMessage object.
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;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| message | RCMessage | The message body to be sent. Required attributes include conversation type (conversationType), channel ID (channelId), conversation ID (targetId), and message content (content). |
| userIdList | NSArray | List of recipient users |
| pushContent | NSString | Modifies or specifies the content displayed in the remote push notification bar. You can also configure this in the push attributes (RCMessagePushConfig) of RCMessage, which will override this setting. See [Configuring Push Notification Attributes].
|
| pushData | String | Additional information for remote push notifications. You can also configure this in the push attributes (RCMessagePushConfig) of RCMessage, which will override this setting. See [Configuring Push Notification Attributes]. |
| attachedBlock | Block | Callback when the message is successfully inserted into the database |
| successBlock | Block | Callback when the message is successfully sent |
| errorBlock | Block | Callback when message sending fails, including the error code RCErrorCode and the failed message. |
Example Code
RCTextMessage *text = [RCTextMessage messageWithContent:@"Hello"];
RCMessage *message = [[RCMessage alloc] initWithType:ConversationType_ULTRAGROUP 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 *successMessage) {
} errorBlock:^(RCErrorCode nErrorCode, RCMessage *errorMessage) {
}];
Sending Targeted Multimedia Messages
You can use sendDirectionalMediaMessage:toUserIdList:pushContent:pushData:attached:progress:successBlock:errorBlock:cancel: to send multimedia messages to specified users in a specific channel of an ultra group. Users not in the recipient list will not receive this message.
Set the ultra group conversation type, ultra group targetId, and channel channelId in the message object. When channelId is empty, messages are sent to the RCDefault channel by default. Note that the recipient userId list is not stored in the RCMessage object.
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;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| message | RCMessage | The message body to be sent. Required attributes include conversation type (conversationType), channel ID (channelId), conversation ID (targetId), and message content (content). |
| userIdList | NSArray | List of recipient users |
| pushContent | NSString | Modifies or specifies the content displayed in the remote push notification bar. You can also configure this in the push attributes (RCMessagePushConfig) of RCMessage, which will override this setting. See [Configuring Push Notification Attributes].
|
| pushData | String | Additional information for remote push notifications. You can also configure this in the push attributes (RCMessagePushConfig) of RCMessage, which will override this setting. See [Configuring Push Notification Attributes]. |
| attachedBlock | Block | Callback when the message is successfully inserted into the database |
| progress | Block | Callback for message sending progress updates |
| successBlock | Block | Callback when the message is successfully sent |
| errorBlock | Block | Callback when message sending fails, including the error code RCErrorCode and the failed message. |
| cancel | Block | Callback when the user cancels message sending |
Example Code
RCImageMessage *imageMessage = [RCImageMessage messageWithImageURI:@"https://test.png"];
RCMessage *message = [[RCMessage alloc] initWithType:ConversationType_ULTRAGROUP 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) {
// Multimedia 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
}];