Profanity filter callback
By default, the message sender cannot tell whether their message has been intercepted by the Nexconn 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 Nexconn built-in global sensitive word and is not delivered to the recipient.
- A text message matches a custom sensitive 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.
Listen for blocked messages
Register a MessageHandler and implement onMessageBlocked. The Swift-first example below matches the current iOS SDK event signature (MessageBlockedEvent).
- Swift
- Objective-C
swift
import NexconnChatSDK
final class BlockedMessageHandler: NSObject, MessageHandler {
func onMessageBlocked(_ event: MessageBlockedEvent) {
guard let info = event.info else { return }
print("Message blocked in channel: \(info.channelIdentifier.channelId)")
print("Block type: \(info.blockType.rawValue)")
print("Message ID: \(info.messageId)")
}
}
let blockedMessageHandler = BlockedMessageHandler()
NCEngine.addMessageHandler(identifier: "BLOCKED_MESSAGE_HANDLER", handler: blockedMessageHandler)
Objective C
[NCEngine addMessageHandlerWithIdentifier:@"BLOCKED_MESSAGE_HANDLER" handler:self];
Objective C
- (void)onMessageBlocked:(NCMessageBlockedEvent *)event {
NCBlockedMessageInfo *info = event.info;
if (info == nil) {
return;
}
NSLog(@"Message blocked in channel: %@", info.channelIdentifier.channelId);
NSLog(@"Block type: %ld", (long)info.blockType);
NSLog(@"Message ID: %@", info.messageId);
}
NCBlockedMessageInfo
| Property | Type | Description |
|---|---|---|
channelIdentifier | NCChannelIdentifier | Channel identifier of the intercepted message |
messageId | NSString | Unique ID of the intercepted message |
blockType | NCMessageBlockType | Reason the message was intercepted |
extra | NSString | Additional information |
sentTime | int64 | Send time (Unix timestamp, milliseconds) |
sourceType | NSInteger | Source type: 0 original message, 1 metadata update, 2 edited content |
sourceContent | NSString | Content JSON of the intercepted message or extension |
NCMessageBlockType
| Enum value | Numeric value | Description |
|---|---|---|
NCMessageBlockTypeGlobal | 1 | Matched a Nexconn built-in global sensitive word |
NCMessageBlockTypeCustom | 2 | Matched a custom sensitive word defined in Nexconn |
NCMessageBlockTypeThirdParty | 3 | Blocked by a pre-messaging webhook rule |