Quick Reference for AI Agents & Developers
- Enable: Configure AI Moderation in CometChat Dashboard → Extensions
- Behavior: Messages automatically reviewed before delivery
- Flagged messages: Access via
message.metadatafor moderation status - Related: Moderation Overview · Extensions Overview · Messaging Overview
Overview
AI Moderation in the CometChat SDK helps ensure that your chat application remains safe and compliant by automatically reviewing messages for inappropriate content. This feature leverages AI to moderate messages in real-time, reducing manual intervention and improving user experience.For a broader understanding of moderation features, configuring rules, and managing flagged messages, see the Moderation Overview.
Prerequisites
Before using AI Moderation, ensure the following:- Moderation is enabled for your app in the CometChat Dashboard
- Moderation rules are configured under Moderation > Rules
- You’re using CometChat SDK version that supports moderation
How It Works
| Step | Description |
|---|---|
| 1. Send Message | App sends a text, image, or video message |
| 2. Pending Status | Message is sent with pending moderation status |
| 3. AI Processing | Moderation service analyzes the content |
| 4. Result Event | onMessageModerated event fires with final status |
Supported Message Types
Moderation is triggered only for the following message types:| Message Type | Moderated | Notes |
|---|---|---|
| Text Messages | ✅ | Content analyzed for inappropriate text |
| Image Messages | ✅ | Images scanned for unsafe content |
| Video Messages | ✅ | Videos analyzed for prohibited content |
| Custom Messages | ❌ | Not subject to AI moderation |
| Action Messages | ❌ | Not subject to AI moderation |
Moderation Status
ThegetModerationStatus() method returns one of the following string values:
| Status | Value | Description |
|---|---|---|
| Pending | "pending" | Message is being processed by moderation |
| Approved | "approved" | Message passed moderation and is visible |
| Disapproved | "disapproved" | Message violated rules and was blocked |
Implementation
Step 1: Send a Message and Check Initial Status
When you send a text, image, or video message, check the initial moderation status:- Swift
- Objective-C
Sample Payload - Send Message with Moderation Check
Sample Payload - Send Message with Moderation Check
Request Parameters:
Success Response (TextMessage Object):
Moderation Status Values:
| Parameter | Type | Description |
|---|---|---|
| receiverUid | String | Unique identifier of the receiver. Example: "cometchat-uid-2" |
| text | String | Message content to send. Example: "Hello, this is a test message!" |
| receiverType | ReceiverType | Type of receiver. Example: .user |
| Parameter | Type | Description |
|---|---|---|
| id | Int | Unique message identifier. Example: 38254 |
| muid | String? | Message unique ID. Example: nil |
| senderUid | String? | UID of the sender. Example: "cometchat-uid-2" |
| receiverUid | String? | UID of the receiver. Example: "cometchat-uid-2" |
| getModerationStatus() | String | Current moderation status. Example: "pending" or "unmoderated" |
| Status | Description |
|---|---|
"pending" | Message is being processed by moderation service |
"approved" | Message passed moderation and is visible |
"disapproved" | Message violated rules and was blocked |
"unmoderated" | Moderation is not enabled for this app |
Step 2: Listen for Moderation Results
Implement theonMessageModerated delegate method to receive moderation results in real-time:
- Swift
- Objective-C
Sample Payload - onMessageModerated Event (Approved)
Sample Payload - onMessageModerated Event (Approved)
Event Trigger: Received via
UI Action:
CometChatMessageDelegate.onMessageModerated(moderatedMessage:)moderatedMessage (TextMessage Object):| Parameter | Type | Description |
|---|---|---|
| id | Int | Unique message identifier. Example: 12345 |
| text | String | Original message content. Example: "Hello, how are you?" |
| senderUid | String? | UID of the message sender. Example: "cometchat-uid-1" |
| receiverUid | String? | UID of the receiver. Example: "cometchat-uid-2" |
| getModerationStatus() | String | Final moderation status. Example: "approved" |
| Action | Description |
|---|---|
| Show message | Display message normally in the chat UI |
| Remove pending indicator | Clear any “under review” status |
Sample Payload - onMessageModerated Event (Disapproved)
Sample Payload - onMessageModerated Event (Disapproved)
Event Trigger: Received via
Handling Options:
CometChatMessageDelegate.onMessageModerated(moderatedMessage:)moderatedMessage (TextMessage Object):| Parameter | Type | Description |
|---|---|---|
| id | Int | Unique message identifier. Example: 12346 |
| text | String | Original message content. Example: "[inappropriate content]" |
| senderUid | String? | UID of the message sender. Example: "cometchat-uid-1" |
| receiverUid | String? | UID of the receiver. Example: "cometchat-uid-2" |
| getModerationStatus() | String | Final moderation status. Example: "disapproved" |
| Option | Description |
|---|---|
| Hide completely | Remove message from UI entirely |
| Show placeholder | Display “Message blocked by moderation” |
| Notify sender | Show notification about policy violation |
Step 3: Handle Disapproved Messages
When a message is disapproved, handle it appropriately in your UI:- Swift
- Objective-C