Quick Reference for AI Agents & Developers
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 values:
| Status | Enum Value | Description |
|---|---|---|
| Pending | ModerationStatus.PENDING | Message is being processed by moderation |
| Approved | ModerationStatus.APPROVED | Message passed moderation and is visible |
| Disapproved | ModerationStatus.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:- Kotlin
- Java
Step 2: Listen for Moderation Results
Register a message listener to receive moderation results in real-time:- Kotlin
- Java
Step 3: Handle Disapproved Messages
When a message is disapproved, handle it appropriately in your UI:- Kotlin
- Java
Next Steps
Moderation Overview
Configure moderation rules and manage flagged messages
Flag Message
Allow users to report inappropriate messages
Send Message
Send text, image, and video messages with automatic moderation
Dashboard
Enable and configure AI moderation in the CometChat Dashboard
Best Practices
Show Pending Status in UI
Show Pending Status in UI
Display a visual indicator (e.g., clock icon, “Pending review” label) for messages with
PENDING moderation status. This informs users that their message is being reviewed.Handle Disapproved Messages Gracefully
Handle Disapproved Messages Gracefully
When a message is disapproved, show a user-friendly message explaining why it was blocked. Avoid technical jargon and provide guidance on acceptable content.
Configure Moderation Rules in Dashboard
Configure Moderation Rules in Dashboard
Set up moderation rules in the CometChat Dashboard under Moderation > Rules. Define what content should be flagged or blocked based on your app’s policies.
Test Moderation Before Production
Test Moderation Before Production
Test moderation with various content types (text, images, videos) in a development environment to ensure rules work as expected before deploying to production.