Skip to main content

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
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}")
}
})

BlockedMessageInfo property reference

BlockedMessageInfo contains information about the intercepted message:

PropertyTypeDescription
channelTypeChannelTypeThe Channel type of the intercepted message
channelIdStringThe Channel ID of the intercepted message
blockedMessageUIdStringThe unique ID of the intercepted message
blockTypeBlockTypeThe reason the message was intercepted. See BlockType Description below
extraString?Additional information about the intercepted message
sourceTypeIntThe 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.
sourceContentString?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 ValueDescription
UNKNOWNUnknown type
GLOBALGlobal sensitive word: matched a built-in global sensitive word
CUSTOMCustom sensitive word: matched a user-defined sensitive word
THIRD_PARTYBlocked by a pre-messaging webhook rule
  • sourceContent Description

    • When sourceType is 0, sourceContent is empty.
    • When sourceType is 1, sourceContent is the message extension content, for example {"mid":"xxx-xxx-xxx-xxx","put":{"key":"sensitive word"}}. mid is the notification ID.
    • When sourceType is 2, sourceContent is the edited message content, for example {"content":"text containing sensitive content"}.

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
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
}
}
}
})