Send Targeted Messages in Ultra Groups
You can send regular messages and media messages to one or more specified members in an ultra group channel, while other members won't receive these messages.
- This feature 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.
Send Targeted Regular Messages
You can use sendDirectionalMessage to send regular messages to specified users in a designated ultra group channel. Users not in the recipient list won't receive this message.
Set the ultra group conversation type, ultra group targetId, and channel channelId in the message object. When channelId is empty, messages will be sent to the RCDefault channel by default. Note that the recipient userId list won't be stored in the Message object.
Interface
RongCoreClient.getInstance().sendDirectionalMessage(message, userIds, pushContent, pushData,callback);
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| message | Message | The message body to be sent. Required attributes include conversation type (conversationType), conversation ID (targetId), and message content (content). Note: Group targeted messages require the conversation type to be Conversation.ConversationType.GROUP. |
| userIds | String[] | List of users who should receive the message. |
| pushContent | String | Modify or specify the content displayed in the remote push notification bar. You can also configure this in the push attributes (MessagePushConfig) of Message, which will override this setting. See Custom Message Push Notifications for details.
|
| pushData | String | Additional information for remote push notifications. When the recipient receives the remote push message, they can access this field via:
MessagePushConfig) of Message, which will override this setting. See Custom Message Push Notifications for details. |
| callback | ISendMessageCallback | Callback for message sending. |
Sample Code
Conversation.ConversationType type = Conversation.ConversationType.GROUP;
String targetId = "123";
TextMessage content = TextMessage.obtain("Targeted message text content");
Message message = Message.obtain(targetId, conversationType, channelId, messageContent);
String[] userIds = new String[]{"id_01", "id_02"};
RongCoreClient.getInstance().sendDirectionalMessage(message, userIds, pushContent, pushData, new IRongCoreCallback.ISendMessageCallback() {
@Override
public void onAttached(Message message) {
}
@Override
public void onSuccess(Message message) {
}
@Override
public void onError(final Message message, IRongCoreEnum.CoreErrorCode errorCode) {
}
});
Send Targeted Media Messages
You can use sendDirectionalMediaMessage to send media messages to specified users in a designated ultra group channel. Users not in the recipient list won't receive this message.
Set the ultra group conversation type, ultra group targetId, and channel channelId in the message object. When channelId is empty, messages will be sent to the RCDefault channel by default. Note that the recipient userId list won't be stored in the Message object.
Interface
RongCoreClient.getInstance().sendDirectionalMediaMessage(message, userIds, null, null, callback);
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| message | Message | The message body to be sent. Required attributes include conversation type (conversationType), conversation ID (targetId), and message content (content). Note: Ultra group targeted messages require the conversation type to be Conversation.ConversationType.GROUP. |
| userIds | String[] | List of users who should receive the message. |
| pushContent | String | Modify or specify the content displayed in the remote push notification bar. You can also configure this in the push attributes (MessagePushConfig) of the Message, which will override this setting. See Custom Push Notifications.
|
| pushData | String | Additional information for remote push notifications. When the recipient receives the remote push message, they can access this field content via:
MessagePushConfig) of the Message, which will override this setting. See Custom Push Notifications. |
| callback | ISendMediaMessageCallback | Callback for sending media messages |
Sample Code
String targetId = "Target ID";
ConversationType conversationType = ConversationType.ULTRA_GROUP;
Uri localUri = Uri.parse("file://image_path");//Local image path, recipients can get automatically generated thumbnail Uri via getThumUri
boolean mIsFull = true; //Whether to send original image
ImageMessage mediaMessageContent = ImageMessage.obtain(localUri, mIsFull);
Message message = Message.obtain(targetId, conversationType, channelId, mediaMessageContent);
String[] userIds = new String[]{"id_01", "id_02"};
RongCoreClient.getInstance().sendDirectionalMediaMessage(message, userIds, null, null, new IRongCoreCallback.ISendMediaMessageCallback() {
@Override
public void onProgress(Message message, int i) {
}
@Override
public void onCanceled(Message message) {
}
@Override
public void onAttached(Message message) {
}
@Override
public void onSuccess(Message message) {
}
@Override
public void onError(final Message message, final IRongCoreEnum.CoreErrorCode errorCode) {
}
});