Skip to main content

Development Guide

The SDK supports the Message Block Notification Callback feature starting from version 5.1.4.

By default, message senders cannot be notified when their messages are blocked by the sensitive word filtering mechanism. If your app needs to notify senders when messages are blocked due to triggering sensitive words, you can enable the Message Block Notification Callback service.

RC's content moderation services (including message sensitive words and message callback service) may block messages in the following scenarios:

  • Text message content triggers RC's built-in sensitive word filters, preventing message delivery to recipients.
  • Text message content triggers your custom sensitive word filters (blocked words), preventing message delivery to recipients.
  • Messages trigger moderation rules set by Message Callback Service, preventing message delivery to recipients.

Enabling the Service

You can enable this feature in the RC Console under Chat > Chat settings > Security & Moderation > Blocked Message Status Callback to Sender.

Setting Up the Message Block Listener

Use the setMessageBlockListener method to set up a message block listener that monitors blocked messages and their blocking reasons.

RongCoreClient.getInstance().setMessageBlockListener(listener);

Message Block Listener Details

When an outgoing message is blocked, the SDK triggers the following method in MessageBlockListener:

void onMessageBlock(BlockedMessageInfo info)

BlockedMessageInfo contains details about the blocked message, accessible through the methods listed below:

Parameter Description

Method NameDescription
getConversationType()Gets the conversation type of the blocked message's conversation
getTargetId()Gets the conversation ID where the blocked message was sent
getChannelId()Gets the ultra group channel ID where the blocked message was sent. Requires Android SDK version ≧ 5.2.4.
getBlockMsgUId()Gets the unique ID of the blocked message
getType()Gets the reason for message blocking. See MessageBlockType Description below.
getExtra()Gets additional information about the blocked message. Requires Android SDK version ≧ 5.2.5 (exception: due to historical reasons, this is also available in maintenance versions 5.2.3.2 and later in the 5.2.3.x series).
getSourceType()Gets the source type of the blocked ultra group message. 0: Original message triggered the block (default). 1: Message extension triggered the block. 2: Modified message content triggered the block. Supported in Android SDK 5.2.5 and later (ultra group only).
getSourceContent()Gets the JSON string of the blocked ultra group message or extension content. When sourceType is 1, it represents extension content. When sourceType is 2, it represents modified message content. See sourceContent Description below. Supported in Android SDK 5.2.5 and later (ultra group only).
  • MessageBlockType Description

    public enum MessageBlockType {

    /**
    * Unknown type
    */
    UNKNOWN(0),

    /**
    * Global sensitive word: Triggered RC's built-in global sensitive word filter
    */
    BLOCK_GLOBAL(1),

    /**
    * Custom sensitive word block: Triggered a custom sensitive word filter set by the client
    */
    BLOCK_CUSTOM(2),

    /**
    * Third-party moderation block: Triggered a third-party (e.g., Shumei) or message callback service (original template routing service) decision to block delivery
    */
    BLOCK_THIRD_PATY(3);
    }
  • sourceContent Description

    • When sourceType is 0, sourceContent is empty.
    • When sourceType is 1, sourceContent contains message extension content, e.g., {"mid":"xxx-xxx-xxx-xxx","put":{"key":"sensitive word"}}. mid is the notification message ID.
    • When sourceType is 2, sourceContent contains modified message content, e.g., {"content":"text containing sensitive information"}. For built-in message types, refer to Message Type Overview.

Retrieving Original Message Content and Setting Message Status After Blocking


// blockedMessageInfo contains details about the blocked message returned by setMessageBlockListener.

// Retrieve message details using the message's unique ID.
RongCoreClient.getInstance().getMessageByUid(blockedMessageInfo.getBlockMsgUId(), new IRongCoreCallback.ResultCallback<Message>() {
@Override
public void onSuccess(Message message) {
//Successfully retrieved local message
message.setSentStatus(Message.SentStatus.FAILED);//
//For IMKit, use IMCenter's setMessageSentStatus method to automatically refresh the UI.
//For IMLib, handle UI updates manually.

// Set message status
RongCoreClient.getInstance().setMessageSentStatus(message, new IRongCoreCallback.ResultCallback<Boolean>() {
@Override
public void onSuccess(Boolean aBoolean) {
//Successfully set message status
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
//Failed to set message status
}
});
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
//Failed to retrieve local message
}
});