Skip to main content

Send Targeted Group Message

You can send regular messages and media messages to one or more specified members in a group, while other members will not receive the message.

Enable Services

Using the Send Targeted Group Message feature does not require enabling any services. However, if you need to store targeted group messages in the server's historical message records, you must enable the following services:

  • Cloud Storage for One-to-One and Group Messages service. You can go to the Chat pricing plans page in the Console to enable this service for the current App Key. This service is available 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 in the RC Console by navigating to Configuration > Chat settings > Basic features > One-to-One and Group Chat, and then enabling Cloud Storage for Group Targeted Message.

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

Send Targeted Group Regular Message

Send a regular message to specified users in a group. Other users not in the recipient list will not receive this message. Note that the Message object only stores the group ID (Target ID) and not the list of recipient user IDs.

Conversation.ConversationType type = Conversation.ConversationType.GROUP;
String targetId = "123";
TextMessage content = TextMessage.obtain("Targeted message text content");
Message message = Message.obtain(targetId, conversationType, messageContent);

String[] userIds = new String[]{"id_01", "id_02"};

RongCoreClient.getInstance().sendDirectionalMessage(message, userIds, null, null, 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) {

}
});

The sendDirectionalMessage method directly provides parameters for controlling push notification content (pushContent) and push additional information (pushData). However, if you need finer control over offline push notifications, such as title, content, icon, or other third-party vendor-specific configurations, please use the message push attributes for configuration.

  • If the message being sent is of a built-in regular message type, such as TextMessage, these parameters can be set to null. When the message triggers an offline push notification, the RC server will use the default pushContent value for each built-in message type. For the default push notification content of each message type, refer to User Content Message Format.
  • If the message type is a custom message type and requires offline push notification support, you must provide the pushContent field to RC; otherwise, users will not receive offline push notifications.
  • If the message type is a custom message type but does not require remote push notification support (e.g., an App business layer operation command implemented via a custom message type), you can leave the pushContent field empty.
  • The MessagePushConfig push attribute configuration in Message will override the configuration here and provide more configuration capabilities, such as customizing the push notification title. For more details, refer to Custom Message Push Notification.
ParameterTypeDescription
messageMessageThe message body to be sent. Required attributes include conversation type (conversationType), conversation ID (targetId), and message content (content). Note that targeted group messages require the conversation type to be Conversation.ConversationType.GROUP.
userIdsString[]The list of users who need to receive the message.
pushContentStringModify or specify the content displayed in the remote message push notification bar. You can also configure this in the Message push attributes (MessagePushConfig), which will override the configuration here. For more details, refer to Custom Message Push Notification.
  • If you want to use RC's default push notification content, you can set this to null. Note that custom message types have no default value.
  • If you want to specify personalized offline push notifications for this message, you must provide the pushContent field content to RC in either of the above places.
  • If your custom message type requires offline push services, you must provide the pushContent field content to RC in either of the above places; otherwise, users will not receive offline push notifications.
pushDataStringAdditional information for remote push. When the recipient receives the remote push message, they can obtain this field content via the following method:

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

. You can also configure this in the Message push attributes (MessagePushConfig), which will override the configuration here. For more details, refer to Custom Message Push Notification.
callbackISendMessageCallbackCallback for sending the message.

Send Targeted Group Media Message

Send a media message to one or more specified users in a group chat. Note that the Message object only stores the group ID (Target ID) and not the list of recipient user IDs.

String targetId = "Target ID";
ConversationType conversationType = ConversationType.PRIVATE;
Uri localUri = Uri.parse("file://image path");//Local path of the image. The recipient can obtain the automatically generated thumbnail Uri via getThumUri
boolean mIsFull = true; //Whether to send the original image
ImageMessage mediaMessageContent = ImageMessage.obtain(localUri, mIsFull);

Message message = Message.obtain(targetId, conversationType, 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) {

}
});

The sendDirectionalMediaMessage method directly provides parameters for controlling push notification content (pushContent) and push additional information (pushData). However, if you need finer control over offline push notifications, such as title, content, icon, or other third-party vendor-specific configurations, please use the message push attributes for configuration. For more details, refer to Custom Message Push Notification.

  • If the message being sent is of a built-in media message type, such as ImageMessage, these parameters can be set to null. When the message triggers an offline push notification, the RC server will use the default pushContent value for each built-in message type. For the default push notification content of each message type, refer to User Content Message Format.
  • If the message type is a custom message type and requires offline push notification support, you must provide the pushContent field to RC; otherwise, users will not receive offline push notifications.
  • If the message type is a custom message type but does not require remote push notification support (e.g., an App business layer operation command implemented via a custom message type), you can leave the pushContent field empty.
  • The MessagePushConfig push attribute configuration in Message will override the configuration here and provide more configuration capabilities, such as customizing the push notification title. For more details, refer to Custom Message Push Notification.
ParameterTypeDescription
messageMessageThe message body to be sent. Required attributes include conversation type (conversationType), conversation ID (targetId), and message content (content). Note that targeted group messages require the conversation type to be Conversation.ConversationType.GROUP.
userIdsString[]The list of users who need to receive the message.
pushContentStringModify or specify the content displayed in the remote message push notification bar. You can also configure this in the Message push attributes (MessagePushConfig), which will override the configuration here. For more details, refer to Custom Message Push Notification.
  • If you want to use RC's default push notification content, you can set this to null. Note that custom message types have no default value.
  • If you want to specify personalized offline push notifications for this message, you must provide the pushContent field content to RC in either of the above places.
  • If your custom message type requires offline push services, you must provide the pushContent field content to RC in either of the above places; otherwise, users will not receive offline push notifications.
pushDataStringAdditional information for remote push. When the recipient receives the remote push message, they can obtain this field content via the following method:

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

. You can also configure this in the Message push attributes (MessagePushConfig), which will override the configuration here. For more details, refer to Custom Message Push Notification.
callbackISendMediaMessageCallbackCallback for sending the media message