Development guide
By default, the message sender cannot tell whether their message has been intercepted by the moderation service. If the app wants to notify the sender when a message is blocked due to a moderation rule, enable the sensitive content interception callback service.
Messages may be intercepted in the following situations:
- A text message matches a built-in global sensitive word and is not delivered to the recipient.
- A text message matches a custom profanity word (blocked sensitive word) you defined and is not delivered to the recipient.
- A message is blocked by a pre-messaging webhook rule and is not delivered to the recipient.
Set up the sensitive content interception listener
Use NCEngine.addChannelHandler to set a channel handler and listen for message interception events. When a sent message is intercepted, the SDK triggers the onMessageBlocked callback on ChannelHandler.
- Kotlin (Recommended)
- Java
kotlin
NCEngine.addChannelHandler("BLOCK_HANDLER", object : ChannelHandler {
override fun onMessageBlocked(info: BlockedMessageInfo) {
println("Message intercepted: ${info.blockedMessageUId}")
println("Channel: ${info.channelId}, type: ${info.channelType}")
println("Interception reason: ${info.blockType}")
}
})
Java
NCEngine.addChannelHandler("BLOCK_HANDLER", new ChannelHandler() {
@Override
public void onMessageBlocked(@NonNull BlockedMessageInfo info) {
Log.d("Block", "Message intercepted: " + info.getBlockedMessageUId());
Log.d("Block", "Channel: " + info.getChannelId() + ", type: " + info.getChannelType());
Log.d("Block", "Interception reason: " + info.getBlockType());
}
});
BlockedMessageInfo property reference
BlockedMessageInfo contains information about the intercepted message:
| Property | Type | Description |
|---|---|---|
| channelType | ChannelType | The Channel type of the intercepted message |
| channelId | String | The Channel ID of the intercepted message |
| blockedMessageUId | String | The unique ID of the intercepted message |
| blockType | BlockType | The reason the message was intercepted. See BlockType Description below |
| extra | String? | Additional information about the intercepted message |
| sourceType | Int | The source type of the intercepted message. 0: the original message triggered interception (default). 1: a message extension triggered interception. 2: edited message content triggered interception. |
| sourceContent | String? | The content JSON string of the intercepted message or extension. When sourceType is 1, this is the extension content. When sourceType is 2, this is the edited message content. See sourceContent Description below. |
- BlockType Description
| Enum Value | Description |
|---|---|
| UNKNOWN | Unknown type |
| GLOBAL | Global sensitive word: matched a built-in global sensitive word |
| CUSTOM | Custom sensitive word: matched a user-defined sensitive word |
| THIRD_PARTY | Blocked by a pre-messaging webhook rule |
-
sourceContent Description
- When
sourceTypeis0,sourceContentis empty. - When
sourceTypeis1,sourceContentis the message extension content, for example{"mid":"xxx-xxx-xxx-xxx","put":{"key":"sensitive word"}}.midis the notification ID. - When
sourceTypeis2,sourceContentis the edited message content, for example{"content":"text containing sensitive content"}.
- When
Retrieve the original message after interception
After a message is intercepted, use BaseChannel.getMessageById to retrieve the original message and update its send status:
- Kotlin (Recommended)
- Java
kotlin
NCEngine.addChannelHandler("BLOCK_HANDLER", object : ChannelHandler {
override fun onMessageBlocked(info: BlockedMessageInfo) {
BaseChannel.getMessageById(info.blockedMessageUId) { message, error ->
if (error == null && message != null) {
message.sentStatus = SendingStatus.FAILED
// Update the UI to show send failed status
}
}
}
})
Java
NCEngine.addChannelHandler("BLOCK_HANDLER", new ChannelHandler() {
@Override
public void onMessageBlocked(@NonNull BlockedMessageInfo info) {
BaseChannel.getMessageById(info.getBlockedMessageUId(), (message, error) -> {
if (error == null && message != null) {
message.setSentStatus(SendingStatus.FAILED);
// Update the UI to show send failed status
}
return null;
});
}
});