Quick Reference for AI Agents & Developers
- Get flag reasons:
CometChat.getFlagReasons(onSuccess:onError:) - Flag message:
CometChat.flagMessage(messageId:detail:onSuccess:onError:) - Review flagged: CometChat Dashboard → Moderation → Flagged Messages
- Related: Moderation · AI Moderation · Messaging Overview
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:| Requirement | Location |
|---|---|
| Enable Moderation | CometChat Dashboard > App Settings |
| Configure Flag Reasons | Dashboard > Moderation > Advanced Settings |
How It Works
Get Flag Reasons
Before flagging a message, retrieve the list of available flag reasons configured in your Dashboard:- Swift
Sample Payloads - Get Flag Reasons
Sample Payloads - Get Flag Reasons
- Request
- Success Response
- Error Response
Method:
CometChat.getFlagReasons(onSuccess:onError:)No parameters required.Flag a Message
To flag a message, use theflagMessage() method with the message ID and a FlagDetail object:
- Swift
Sample Payloads - Flag Message
Sample Payloads - Flag Message
- Request
- Success Response
- Error Response
Method:
FlagDetail Object:
CometChat.flagMessage(messageId:detail:onSuccess:onError:)| Parameter | Type | Value |
|---|---|---|
| messageId | Int | 12345 |
| reasonId | String | "spam" |
| remark | String | "This message contains promotional content" |
| Parameter | Type | Required | Description |
|---|---|---|---|
| messageId | Int | YES | ID of message to flag |
| reasonId | String | YES | ID from getFlagReasons() |
| remark | String | NO | Additional context |
More Sample Payloads
More Sample Payloads
- Flag for Harassment
- Flag for Hate Speech
Request:
Swift Code:
| Parameter | Type | Value |
|---|---|---|
| messageId | Int | 12345 |
| reasonId | String | "harassment" |
| remark | String | "Inappropriate behavior towards other users" |
Implementation Flow
| Step | Action | Method |
|---|---|---|
| 1 | Load flag reasons on app init | CometChat.getFlagReasons() |
| 2 | Cache reasons for UI | Store in array/state |
| 3 | Show reason picker to user | Display cached reasons |
| 4 | User selects reason + remark | Capture selection |
| 5 | Submit flag | CometChat.flagMessage() |
| 6 | Review in Dashboard | Moderation > Flagged |
Complete Example
- Swift
Common Error Codes
| Error Code | Description | Resolution |
|---|---|---|
ERR_NOT_LOGGED_IN | User is not logged in | Login first |
ERR_MESSAGE_NOT_FOUND | Message doesn’t exist | Verify message ID |
ERR_INVALID_REASON_ID | Invalid flag reason ID | Use ID from getFlagReasons() |
ERR_FEATURE_NOT_ACCESSIBLE | Moderation not enabled | Enable in Dashboard or upgrade plan |