Skip to main content
Quick Reference for AI Agents & Developers
Required: Moderation enabled in Dashboard → Moderation → Advanced Settings

Overview

Flagging messages allows users to report inappropriate content to moderators or administrators. When a message is flagged, it appears in the CometChat Dashboard under Moderation > Flagged Messages for review.
Available via: SDK | REST API | UI Kits
For a complete understanding of how flagged messages are reviewed and managed, see the Flagged Messages documentation.

Prerequisites

Before using the flag message feature:
  1. Moderation must be enabled for your app in the CometChat Dashboard
  2. Flag reasons should be configured under Moderation > Advanced Settings

How It Works

Get Flag Reasons

Before flagging a message, retrieve the list of available flag reasons configured in your Dashboard:
On SuccessgetFlagReasons() returns an array of flag reason objects:Flag Reason Array (per item):

Flag a Message

To flag a message, use the flagMessage() method with the message ID and a payload containing the reason:
On SuccessflagMessage() returns a success response:Response Object:

Parameters

Complete Example

Here’s a complete implementation showing how to build a report message flow:
  • Cache flag reasons: Call getFlagReasons() once at app initialization or when the report dialog is first opened, then reuse the cached list. Avoid fetching reasons on every report action.
  • Require a reason: Always require users to select a reason before submitting a flag. This improves the quality of moderation data and helps moderators prioritize reviews.
  • Provide a remark field: Allow users to add optional context via the remark parameter. Additional details help moderators make faster, more informed decisions.
  • Confirm before submitting: Show a confirmation dialog before calling flagMessage() to prevent accidental reports.
  • Show feedback after flagging: Display a success message or toast after a message is flagged so the user knows their report was submitted.
  • getFlagReasons() returns an empty array: Ensure that flag reasons are configured in the CometChat Dashboard under Moderation > Advanced Settings. Moderation must also be enabled for your app.
  • flagMessage() fails with an error: Verify that the reasonId matches one of the IDs returned by getFlagReasons(). Also confirm that the messageId is valid and belongs to a conversation the logged-in user has access to.
  • Flagged messages not appearing in Dashboard: Check that moderation is enabled in your Dashboard settings. Flagged messages appear under Moderation > Flagged Messages.
  • Permission errors: The logged-in user must be a participant in the conversation containing the message they want to flag. Users cannot flag messages from conversations they are not part of.

Next Steps

Edit Message

Edit sent messages in one-on-one and group conversations

Delete Message

Delete messages for yourself or for all participants

Receive Messages

Listen for incoming messages in real time

Delivery & Read Receipts

Track message delivery and read status