Skip to main content
// Send message and check moderation status
CometChat.sendMessage(textMessage, onSuccess: (TextMessage message) {
  if (message.moderationStatus?.value == ModerationStatusEnum.PENDING.value) {
    // Message is under moderation review
  }
}, onError: (e) {});

// Listen for moderation results
CometChat.addMessageListener("MODERATION_LISTENER", MessageListener(
  onMessageModerated: (BaseMessage message) {
    // Handle APPROVED or DISAPPROVED status
  },
));

// Remove listener when done
CometChat.removeMessageListener("MODERATION_LISTENER");
Moderation Status: PENDINGAPPROVED or DISAPPROVED Supported Types: Text, Image, Video messages

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.
Available via: SDK | REST API | UI Kits | Dashboard
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

StepDescription
1. Send MessageApp sends a text, image, or video message
2. Pending StatusMessage is sent with PENDING moderation status
3. AI ProcessingModeration service analyzes the content
4. Result EventonMessageModerated event fires with final status

Supported Message Types

Moderation is triggered only for the following message types:
Message TypeModeratedNotes
Text MessagesContent analyzed for inappropriate text
Image MessagesImages scanned for unsafe content
Video MessagesVideos analyzed for prohibited content
Moderation applies to TextMessage and MediaMessage types. | Custom Messages | ❌ | Not subject to AI moderation | | Action Messages | ❌ | Not subject to AI moderation |

Moderation Status

The moderationStatus property returns one of the following enum values:
StatusEnum ValueDescription
PendingModerationStatusEnum.PENDINGMessage is being processed by moderation
ApprovedModerationStatusEnum.APPROVEDMessage passed moderation and is visible
DisapprovedModerationStatusEnum.DISAPPROVEDMessage 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:
TextMessage textMessage = TextMessage(
  text: "Hello, how are you?",
  receiverUid: receiverUID,
  receiverType: ReceiverTypeConstants.user,
);

CometChat.sendMessage(
  textMessage,
  onSuccess: (TextMessage message) {
    // Check moderation status
    if (message.moderationStatus?.value == ModerationStatusEnum.PENDING.value) {
      print("Message is under moderation review");
      // Show pending indicator in UI
    }
  },
  onError: (CometChatException e) {
    print("Message sending failed: ${e.message}");
  },
);
On Success — A TextMessage object containing all details of the sent message, including the initial moderation status:TextMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID501
metadataobjectCustom metadata attached to the message{}
receiverobjectReceiver user objectSee below ↓
editedBystringUID of the user who edited the messagenull
conversationIdstringUnique conversation identifier"cometchat-uid-1_user_cometchat-uid-2"
sentAtnumberEpoch timestamp when the message was sent1745554729
receiverUidstringUID of the receiver"cometchat-uid-2"
typestringType of the message"text"
readAtnumberEpoch timestamp when the message was read0
deletedBystringUID of the user who deleted the messagenull
deliveredAtnumberEpoch timestamp when the message was delivered0
deletedAtnumberEpoch timestamp when the message was deleted0
replyCountnumberNumber of replies to this message0
senderobjectSender user objectSee below ↓
receiverTypestringType of the receiver"user"
editedAtnumberEpoch timestamp when the message was edited0
parentMessageIdnumberID of the parent message (for threads)-1
readByMeAtnumberEpoch timestamp when read by the current user0
categorystringMessage category"message"
deliveredToMeAtnumberEpoch timestamp when delivered to the current user0
updatedAtnumberEpoch timestamp when the message was last updated1745554729
textstringThe text content of the message"Hello, how are you?"
tagsarrayList of tags associated with the message[]
unreadRepliesCountnumberCount of unread replies0
mentionedUsersarrayList of mentioned users[]
hasMentionedMebooleanWhether the current user is mentionedfalse
reactionsarrayList of reactions on the message[]
moderationStatusstringModeration status of the message"pending"
quotedMessageIdnumberID of the quoted messagenull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-1"
namestringDisplay name of the sender"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name of the receiver"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745550000
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_BLOCKED_BY_EXTENSION"
messagestringHuman-readable error message"Message blocked by moderation."
detailsstringAdditional technical details"The message was flagged and blocked by the AI moderation extension."

Step 2: Listen for Moderation Results

Implement the MessageListener to receive moderation results in real-time:
class ModerationListener with MessageListener {
  
  @override
  void onMessageModerated(BaseMessage message) {
    if (message is TextMessage) {
      switch (message.moderationStatus?.value) {
        case ModerationStatusEnum.APPROVED:
          print("Message ${message.id} approved");
          // Update UI to show message normally
          break;
          
        case ModerationStatusEnum.DISAPPROVED:
          print("Message ${message.id} blocked");
          // Handle blocked message (hide or show warning)
          handleDisapprovedMessage(message);
          break;
      }
    } else if (message is MediaMessage) {
      switch (message.moderationStatus?.value) {
        case ModerationStatusEnum.APPROVED:
          print("Media message ${message.id} approved");
          break;
          
        case ModerationStatusEnum.DISAPPROVED:
          print("Media message ${message.id} blocked");
          handleDisapprovedMessage(message);
          break;
      }
    }
  }
}

// Register the listener
CometChat.addMessageListener("MODERATION_LISTENER", ModerationListener());

// Don't forget to remove the listener when done
// CometChat.removeMessageListener("MODERATION_LISTENER");

Step 3: Handle Disapproved Messages

When a message is disapproved, handle it appropriately in your UI:
void handleDisapprovedMessage(BaseMessage message) {
  int messageId = message.id;
  
  // 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.sender?.uid == currentUserUID) {
    showNotification("Your message was blocked due to policy violation");
  }
}

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