Skip to main content

Moderation Integration

To maintain a safe, respectful, and engaging environment for your users, our platform offers a powerful Moderation Integration system. This system allows you to automatically review, filter, and take action on user-generated messages, images, and videos before they are delivered. With Moderation Integration, you can define flexible rules, receive real-time updates, and ensure your app meets community guidelines, legal standards, and brand values without manual intervention.

Choose Your Integration Method

UI Kit (Recommended)

Zero code required — Moderation is built into CometChat UI Kits. Simply configure rules in the Dashboard and the UI Kit handles everything automatically.

SDK Integration

Full control — Use the CometChat SDK to handle moderation programmatically in your custom UI implementation.

Integrate Moderation

Using UI Kit? You only need Step 1 - the UI Kit handles moderation automatically!
1

Setup Rules

Define content moderation rules for your app’s messaging system.
2

Integrate with SDK (Custom UI only)

If building a custom UI, implement moderation handling in your code. See SDK Integration below.
3

Configure Webhooks (Optional)

Set up webhooks to receive real-time moderation events on your server.

Setting Up Moderation Rules

Moderation rules act as filters to ensure that the messages exchanged within your app meet your safety and content guidelines.

How It Works

  • When a message, image, or video is submitted, it is automatically checked against the moderation rules you’ve configured.
  • These rules can detect offensive language, sensitive content, spam, scams, and more.
  • Based on your settings, content can be:
    • Approved: Delivered to the recipient.
    • Disapproved: Blocked and not delivered.
    • Flagged: Delivered to the recipient, but flagged for review.

Benefits

  • Safety first: Protect your users and brand from harmful or unwanted content.
  • Customizable: Fine-tune moderation rules to suit your app’s unique needs.
  • Seamless experience: Moderation happens in real time, keeping communication flowing smoothly.

Creating Moderation Rules

CometChat provides a set of default moderation rules designed to cover common use cases such as offensive language, spam, and inappropriate content. You can enable these rules to start moderating messages immediately, without any additional setup.
If you have specific requirements, you can create custom moderation rules tailored to your app’s needs:
  1. Using the CometChat Dashboard — A simple, no-code interface for visually creating and managing moderation rules.
  1. Using the CometChat API — Programmatically create and manage moderation rules for advanced or automated workflows. See the Rules Management documentation.

Configuring a Moderation Webhook

To automate your moderation flow and receive updates in real time, configure a moderation webhook. This allows your system to react instantly when a message or media is moderated.
Webhooks are optional if you’re using the SDK’s onMessageModerated listener for real-time updates.

How It Works

  • Every time content is moderated, a webhook event is triggered and sent to the URL you specify.
  • Your application can then take action based on the moderation result.

Handle Moderation Events

The key webhook events to handle include:
  • moderation_engine_approved — Triggered when the engine automatically approves content.
  • moderation_engine_blocked — Triggered when the engine automatically blocks content.
  • moderation_manual_approved — Triggered when a moderator manually approves previously blocked content.
To receive these events, enable the relevant webhooks in the CometChat Dashboard:
Application → Webhooks → Create Webhook → Triggers → Moderation

Integrating Moderation with SDK

Once your moderation rules are configured in the Dashboard, integrate moderation into your application using the CometChat SDK. The SDK automatically handles moderation for all messages sent through CometChat.
Using UI Kit? Skip this section - the UI Kit handles everything automatically!

Send a Message and Check Moderation Status

When you send a message, it’s automatically checked against your moderation rules. The message object contains a moderationStatus property:
const textMessage = new CometChat.TextMessage(
  receiverUID,
  "Hello, how are you?",
  CometChat.RECEIVER_TYPE.USER
);

CometChat.sendMessage(textMessage).then(
  (message) => {
    const status = message.getModerationStatus();
    
    switch (status) {
      case CometChat.ModerationStatus.PENDING:
        console.log("Message is under moderation review");
        break;
      case CometChat.ModerationStatus.APPROVED:
        console.log("Message approved and delivered");
        break;
      case CometChat.ModerationStatus.DISAPPROVED:
        console.log("Message blocked by moderation");
        break;
    }
  },
  (error) => {
    console.log("Message sending failed:", error);
  }
);

Listen for Moderation Results

Register a message listener to receive real-time moderation updates when the moderation engine finishes processing:
const listenerID = "MODERATION_LISTENER";

CometChat.addMessageListener(
  listenerID,
  new CometChat.MessageListener({
    onMessageModerated: (message) => {
      const status = message.getModerationStatus();
      const messageId = message.getId();

      if (status === CometChat.ModerationStatus.APPROVED) {
        console.log(`Message ${messageId} approved - show in UI`);
        // Update UI to display the message
      } else if (status === CometChat.ModerationStatus.DISAPPROVED) {
        console.log(`Message ${messageId} blocked`);
        // Hide message or show blocked placeholder
      }
    }
  })
);

// Remove listener when done
// CometChat.removeMessageListener(listenerID);

Handle Blocked Messages in UI

When a message is blocked (disapproved), handle it appropriately in your UI:
function handleBlockedMessage(message) {
  const messageId = message.getId();
  const senderUid = message.getSender().getUid();
  
  // Option 1: Hide the message completely
  removeMessageFromUI(messageId);
  
  // Option 2: Show a placeholder
  showPlaceholder(messageId, "This message was blocked by moderation");
  
  // Option 3: Notify the sender
  if (senderUid === currentUserUID) {
    showToast("Your message was blocked due to policy violation");
  }
}

Moderation Status Reference

StatusValueDescription
PendingPENDINGMessage is being processed by moderation engine
ApprovedAPPROVEDMessage passed moderation and is visible to recipients
DisapprovedDISAPPROVEDMessage violated rules and was blocked

Summary

By combining well-defined moderation rules with SDK integration, you can build a safe and user-friendly content moderation system:
  • UI Kit users: Just configure rules in the Dashboard - everything else is automatic
  • SDK users: Implement onMessageModerated listener to handle moderation results