Skip to main content

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.

tip
  • 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

ParameterTypeDescription
messageMessageThe 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.
userIdsString[]List of users who should receive the message.
pushContentStringModify 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.
  • To use RC's default push notification content, enter null. Note that custom message types have no default value.
  • To specify personalized offline push notifications for this message, you must provide pushContent in either location.
  • If your custom message type requires offline push service, you must provide pushContent in either location; otherwise, users won't receive offline push notifications.
pushDataStringAdditional information for remote push notifications. When the recipient receives the remote push message, they can access this field via:

io.rong.push.notification.PushNotificationMessage#getPushData()

. You can also configure this in the push attributes (MessagePushConfig) of Message, which will override this setting. See Custom Message Push Notifications for details.
callbackISendMessageCallbackCallback 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

ParameterTypeDescription
messageMessageThe 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.
userIdsString[]List of users who should receive the message.
pushContentStringModify 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.
  • To use RC's default push notification content, set this to null. Note that custom message types have no default value.
  • To specify personalized offline push notifications for this message, you must provide the pushContent field content to RC in either location.
  • If your custom message type requires offline push services, you must provide the pushContent field content to RC in either location, otherwise users won't receive offline push notifications.
pushDataStringAdditional information for remote push notifications. When the recipient receives the remote push message, they can access this field content via:

io.rong.push.notification.PushNotificationMessage#getPushData()

. You can also configure this in the push attributes (MessagePushConfig) of the Message, which will override this setting. See Custom Push Notifications.
callbackISendMediaMessageCallbackCallback 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) {

}
});