Skip to main content

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:
  1. Moderation is enabled for your app in the CometChat Dashboard
  2. Moderation rules are configured under Moderation > Rules
  3. You’re using CometChat SDK version that supports moderation

How It Works

Supported Message Types

Moderation is triggered only for the following message types:

Moderation Status

The moderationStatus property returns one of the following enum values:

Implementation

Step 1: Send a Message and Check Initial Status

When you send a text, image, or video message, check the initial moderation status:
Starting with v5.1.0, `sendMessage()` accepts a listener: parameter that takes a MessageSentListener. The listener: parameter requires cometchat_sdk 5.1.0 or later. With offline support off, the listener behaves exactly like the old callback: the sent message arrives in onMessageSent (the drop-in for onSuccess) and onError is unchanged. With offline support on, onMessagePending fires first — the message is persisted locally. A message sent without a connection stays pending and is sent when the connection returns: onError fires once with code ERR_CONNECTION (details ERROR_INTERNET_UNAVAILABLE) as a not-connected notice, and onMessageSent follows once the message is sent. In onError, code ERR_CONNECTION means the message is queued; a real failure also reaches OfflineMessageListener.onOutboxMessageFailed, with the message’s status set to failed. A send without a listener: is never queued. See Send While Offline.

Step 2: Listen for Moderation Results

Implement the MessageListener to receive moderation results in real-time:

Step 3: Handle Disapproved Messages

When a message is disapproved, handle it appropriately in your UI:

Next Steps

After implementing AI Moderation, consider adding a reporting feature to allow users to flag messages they find inappropriate. For more details, see the Flag Message documentation.