AI Integration Quick Reference
AI Integration Quick Reference
PENDING → APPROVED or DISAPPROVED
Supported Types: Text, Image, Video messagesOverview
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 |
TextMessage and MediaMessage types.
| Custom Messages | ❌ | Not subject to AI moderation |
| Action Messages | ❌ | Not subject to AI moderation |
Moderation Status
ThemoderationStatus property returns one of the following enum values:
| Status | Enum Value | Description |
|---|---|---|
| Pending | ModerationStatusEnum.PENDING | Message is being processed by moderation |
| Approved | ModerationStatusEnum.APPROVED | Message passed moderation and is visible |
| Disapproved | ModerationStatusEnum.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:- Dart
Response
Response
On Success — A
TextMessage object containing all details of the sent message, including the initial moderation status:TextMessage Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
id | number | Unique message ID | 501 |
metadata | object | Custom metadata attached to the message | {} |
receiver | object | Receiver user object | See below ↓ |
editedBy | string | UID of the user who edited the message | null |
conversationId | string | Unique conversation identifier | "cometchat-uid-1_user_cometchat-uid-2" |
sentAt | number | Epoch timestamp when the message was sent | 1745554729 |
receiverUid | string | UID of the receiver | "cometchat-uid-2" |
type | string | Type of the message | "text" |
readAt | number | Epoch timestamp when the message was read | 0 |
deletedBy | string | UID of the user who deleted the message | null |
deliveredAt | number | Epoch timestamp when the message was delivered | 0 |
deletedAt | number | Epoch timestamp when the message was deleted | 0 |
replyCount | number | Number of replies to this message | 0 |
sender | object | Sender user object | See below ↓ |
receiverType | string | Type of the receiver | "user" |
editedAt | number | Epoch timestamp when the message was edited | 0 |
parentMessageId | number | ID of the parent message (for threads) | -1 |
readByMeAt | number | Epoch timestamp when read by the current user | 0 |
category | string | Message category | "message" |
deliveredToMeAt | number | Epoch timestamp when delivered to the current user | 0 |
updatedAt | number | Epoch timestamp when the message was last updated | 1745554729 |
text | string | The text content of the message | "Hello, how are you?" |
tags | array | List of tags associated with the message | [] |
unreadRepliesCount | number | Count of unread replies | 0 |
mentionedUsers | array | List of mentioned users | [] |
hasMentionedMe | boolean | Whether the current user is mentioned | false |
reactions | array | List of reactions on the message | [] |
moderationStatus | string | Moderation status of the message | "pending" |
quotedMessageId | number | ID of the quoted message | null |
sender Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
uid | string | Unique identifier of the sender | "cometchat-uid-1" |
name | string | Display name of the sender | "Andrew Joseph" |
link | string | Profile link | null |
avatar | string | Avatar URL | "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp" |
metadata | object | Custom metadata | {} |
status | string | Online status | "online" |
role | string | User role | "default" |
statusMessage | string | Status message | null |
tags | array | User tags | [] |
hasBlockedMe | boolean | Whether this user has blocked the current user | false |
blockedByMe | boolean | Whether the current user has blocked this user | false |
lastActiveAt | number | Epoch timestamp of last activity | 1745554700 |
receiver Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
uid | string | Unique identifier of the receiver | "cometchat-uid-2" |
name | string | Display name of the receiver | "George Alan" |
link | string | Profile link | null |
avatar | string | Avatar URL | "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp" |
metadata | object | Custom metadata | {} |
status | string | Online status | "offline" |
role | string | User role | "default" |
statusMessage | string | Status message | null |
tags | array | User tags | [] |
hasBlockedMe | boolean | Whether this user has blocked the current user | false |
blockedByMe | boolean | Whether the current user has blocked this user | false |
lastActiveAt | number | Epoch timestamp of last activity | 1745550000 |
Error
Error
| Parameter | Type | Description | Sample Value |
|---|---|---|---|
code | string | Error code identifier | "ERR_BLOCKED_BY_EXTENSION" |
message | string | Human-readable error message | "Message blocked by moderation." |
details | string | Additional technical details | "The message was flagged and blocked by the AI moderation extension." |
Step 2: Listen for Moderation Results
Implement theMessageListener to receive moderation results in real-time:
- Dart
Step 3: Handle Disapproved Messages
When a message is disapproved, handle it appropriately in your UI:- Dart
Next Steps
After implementing AI Moderation, explore these related features:AI Agents
Build intelligent AI-powered agents for automated conversations
Flag Message
Allow users to manually report inappropriate messages
AI Chatbots
Create automated chatbot experiences for your users
Receive Messages
Handle incoming messages and moderation events