Skip to main content

Send Group Targeted Message

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

Enable Services

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

  • Cloud Storage for Group Targeted Message service. You can enable this service in the RC Console.

By default, group targeted messages sent and received by clients are not stored in the historical message service. Therefore, when clients call the API to retrieve historical messages, the results returned from the RC server will not include group targeted messages sent or received by the current user.

Send Regular Group Targeted Message

Send regular messages 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 does not store the recipient user ID list.

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 the Message, which will override this setting. For details, see Customize Push Notifications.
  • 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 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 will not receive offline push notifications.
pushDataStringAdditional information for remote push notifications. When the recipient receives the remote push message, they can obtain 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. For details, see Customize Push Notifications.
callbackISendMessageCallbackCallback for sending messages.

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, 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 more granular control over offline push notifications, such as titles, content, icons, or other third-party vendor-specific configurations, please use the message push attributes for configuration.


}

@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 more granular control over offline push notifications, such as titles, content, icons, or other third-party vendor-specific configurations, please use the message push attributes for configuration.

<!-- ========== OVERLAP END ========== -->
<!-- New content starts below -->


- If the sent message belongs to SDK's built-in message types (e.g., [TextMessage]), these two parameters can be set to `null`. When the message triggers an offline push notification, the RC server will use the default `pushContent` values for each built-in message type. For default push notification content of each message type, see [User Content Message Formats].


- If the message type is a custom message 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 but does not require remote push notification support (e.g., app business layer operation commands implemented via custom message types), you can leave the `pushContent` field empty.


- The `pushContent` and `pushData` configurations in the `MessagePushConfig` of the `Message`'s push attributes will override the configurations here and provide more configuration capabilities, such as custom push notification titles. For details, see [Custom Message Push Notifications](../message/send.md#custom-message-push-notifications).


## Sending Targeted Group Media Messages

Send multimedia messages to specified individual or multiple users in a group chat. Note that the `Message` only stores the group ID (Target ID) and does not store the recipient user ID list.


#### Interface
```java
RongCoreClient.getInstance().sendDirectionalMediaMessage(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**: Targeted group messages require the conversation type to be `Conversation.ConversationType.GROUP`. |
| userIds | String[] | List of users who need to receive the message. |
| pushContent | String | Modify or specify the content displayed in the remote message push notification bar. You can also configure this in the `Message`'s push attributes (`MessagePushConfig`), which will override the configuration here. For details, see [Custom Message Push Notifications](../message/send.md#custom-message-push-notifications).<ul><li>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 values.</li><li>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.</li><li>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.</li></ul> |
| pushData | String | Additional information for remote push. When the recipient receives the remote push message, they can obtain this field content via the following method:<p>`io.rong.push.notification.PushNotificationMessage#getPushData()`</p>. You can also configure this in the `Message`'s push attributes (`MessagePushConfig`), which will override the configuration here. For details, see [Custom Message Push Notifications](../message/send.md#custom-message-push-notifications). |
| callback | [ISendMediaMessageCallback] | Callback for sending media messages |


#### Example Code
```java
String targetId = "Target ID";
ConversationType conversationType = ConversationType.PRIVATE;
Uri localUri = Uri.parse("file://path_to_image");//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). If you need more granular control over offline push notifications, such as titles, content, icons, or other third-party vendor-specific configurations, please use the message push attributes for configuration. For details, see Custom Message Push Notifications.

  • If the sent message belongs to an SDK 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 default push notification content of each message type, see User Content Message Format.

  • For custom message types that require offline push notifications, you must provide the pushContent field to RC; otherwise, users will not receive offline push notifications.

  • For custom message types that do not require offline push notifications (e.g., app business layer operation commands implemented via custom message types), the pushContent field can be left empty.

  • The pushContent and pushData configurations in MessagePushConfig of the Message object will override the settings here and provide more configuration capabilities, such as custom push notification titles. For details, see Custom Message Push Notifications.