AI Integration Quick Reference
AI Integration Quick Reference
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.For a complete understanding of how flagged messages are reviewed and managed, see the Flagged Messages documentation.
Prerequisites
Before using the flag message feature:- Moderation must be enabled for your app in the CometChat Dashboard
- 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:- JavaScript
- TypeScript
Response
The response is an array of flag reason objects:Flag a Message
To flag a message, use theflagMessage() method with the message ID and a payload containing the reason:
- JavaScript
- TypeScript
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| messageId | string | Yes | The ID of the message to flag |
| payload.reasonId | string | Yes | ID of the flag reason (from getFlagReasons()) |
| payload.remark | string | No | Additional context or explanation from the user |
Response
flagMessage() method flags a BaseMessage object for moderation. The flagged message can be identified using getter methods:
| Field | Getter | Return Type | Description |
|---|---|---|---|
| id | getId() | number | Unique message ID |
| sender | getSender() | User | The user who sent the message |
| type | getType() | string | Message type (text, image, custom, etc.) |
| sentAt | getSentAt() | number | Timestamp when the message was sent |
Complete Example
Here’s a complete implementation showing how to build a report message flow:Next Steps
AI Moderation
Automate content moderation with AI
Delete a Message
Remove messages from conversations
Receive Messages
Listen for incoming messages in real time
Send Messages
Send text, media, and custom messages