Automatically moderate chat messages using AI to detect and block inappropriate content in real-time.
AI Integration Quick Reference
let textMessage = new CometChat.TextMessage("UID", "Hello", CometChat.RECEIVER_TYPE.USER);// Send message — check moderation statusCometChat.sendMessage(textMessage).then(message => { const status = message.getModerationStatus(); // CometChat.ModerationStatus.PENDING | APPROVED | DISAPPROVED});// Listen for moderation resultsCometChat.addMessageListener("MOD_LISTENER", new CometChat.MessageListener({ onMessageModerated: (message) => { const status = message.getModerationStatus(); // Handle APPROVED or DISAPPROVED }}));
Supported types: Text, Image, Video messages only
Statuses:PENDING → APPROVED or DISAPPROVED
AI Moderation automatically reviews messages for inappropriate content in real-time. When a user sends a text, image, or video message, it’s held in a PENDING state while the moderation service analyzes it, then marked as APPROVED or DISAPPROVED via the onMessageModerated event.getModerationStatus() is available on TextMessage and MediaMessage objects. Custom messages are not subject to moderation.
For configuring moderation rules and managing flagged messages from the dashboard, see the Moderation Overview.
When you send a text, image, or video message, check the initial moderation status:
TypeScript
JavaScript
const textMessage = new CometChat.TextMessage( receiverUID, "Hello, how are you?", CometChat.RECEIVER_TYPE.USER);CometChat.sendMessage(textMessage).then( (message: CometChat.TextMessage) => { // Check moderation status const status: string = message.getModerationStatus(); if (status === CometChat.ModerationStatus.PENDING) { console.log("Message is under moderation review"); // Show pending indicator in UI } }, (error: CometChat.CometChatException) => { console.log("Message sending failed:", error); });
const textMessage = new CometChat.TextMessage( receiverUID, "Hello, how are you?", CometChat.RECEIVER_TYPE.USER);CometChat.sendMessage(textMessage).then( (message) => { // Check moderation status const status = message.getModerationStatus(); if (status === CometChat.ModerationStatus.PENDING) { console.log("Message is under moderation review"); // Show pending indicator in UI } }, (error) => { console.log("Message sending failed:", error); });
When a message is disapproved, you should handle it appropriately in your UI:
function handleDisapprovedMessage(message) { const messageId = message.getId(); // Option 1: Hide the message completely hideMessageFromUI(messageId); // Option 2: Show a placeholder message showBlockedPlaceholder(messageId, "This message was blocked by moderation"); // Option 3: Notify the sender (if it's their message) if (message.getSender().getUid() === currentUserUID) { showNotification("Your message was blocked due to policy violation"); }}
Always remove listeners when they’re no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.