diff --git a/docs.json b/docs.json index 45abb3f3..f012e7ed 100644 --- a/docs.json +++ b/docs.json @@ -2563,6 +2563,7 @@ "sdk/javascript/threaded-messages", "sdk/javascript/edit-message", "sdk/javascript/delete-message", + "sdk/javascript/flag-message", "sdk/javascript/delete-conversation", "sdk/javascript/typing-indicators", "sdk/javascript/interactive-messages", diff --git a/sdk/javascript/flag-message.mdx b/sdk/javascript/flag-message.mdx new file mode 100644 index 00000000..a411e1fd --- /dev/null +++ b/sdk/javascript/flag-message.mdx @@ -0,0 +1,103 @@ +--- +title: "Flag A Message" +--- + +Flagging messages allows users to report inappropriate content to moderators or administrators. CometChat provides methods to flag messages with specific reasons and retrieve available flag reasons configured in your dashboard. + +## Flag a Message + +*In other words, as a user, how do I report a message?* + +To flag a message, you can use the `flagMessage()` method. This method takes the message ID and a payload containing an optional reason ID and remark. + + + +```javascript +let messageId = "ID_OF_THE_MESSAGE_YOU_WANT_TO_FLAG"; +let payload = { + reasonId: "spam", // Required: ID of the flag reason + remark: "This message contains promotional content" // Optional: Additional context +}; + +CometChat.flagMessage(messageId, payload).then( + response => { + console.log("Message flagged successfully", response); + }, error => { + console.log("Message flagging failed with error:", error); + } +); +``` + + + +```typescript +let messageId: string = "ID_OF_THE_MESSAGE_YOU_WANT_TO_FLAG"; +let payload: { reasonId: string; remark?: string } = { + reasonId: "spam", + remark: "This message contains promotional content" +}; + +CometChat.flagMessage(messageId, payload).then( + (response: CometChat.FlagMessageResponse) => { + console.log("Message flagged successfully", response); + }, (error: CometChat.CometChatException) => { + console.log("Message flagging failed with error:", error); + } +); +``` + + + +### Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| messageId | string | Yes | The ID of the message to be flagged | +| payload | object | Yes | Contains flagging details | +| payload.reasonId | string | Yes | ID of the flag reason (from getFlagReasons) | +| payload.remark | string | No | Additional context or explanation | + +### Response + +On successful flagging, you'll receive a response object: + +```javascript +{ + "success": true, + "message": "Message with id {{messageId}} has been flagged successfully" +} +``` + +## Get Flag Reasons + +*In other words, what are the available reasons for flagging a message?* + +Before flagging a message, you can retrieve the list of available flag reasons using the `getFlagReasons()` method. These reasons are configured in the CometChat Dashboard. + + + +```javascript +CometChat.getFlagReasons().then( + reasons => { + console.log("Flag reasons retrieved", reasons); + // Use reasons to populate your UI + }, error => { + console.log("Failed to get flag reasons:", error); + } +); +``` + + + +```typescript +CometChat.getFlagReasons().then( + (reasons: CometChat.FlagReason[]) => { + console.log("Flag reasons retrieved", reasons); + // Use reasons to populate your UI + }, (error: CometChat.CometChatException) => { + console.log("Failed to get flag reasons:", error); + } +); +``` + +