Report offensive messages
Chat SDK provides a mechanism for users to report offensive content in messages directly from their applications.
In each case, a user must provide a reason for flagging a given message. As a result of flagging, a reported message gets published on the dedicated administrative channel (with the PUBNUB_INTERNAL_ADMIN_CHANNEL
ID) and an event of the report
type gets created.
As a developer, you can add custom logic that uses the emitted events and defines what an admin can later do with such reported messages. For example, an admin can delete an inappropriate message.
Message Persistence
To work with stored message data, you must enable Message Persistence for your app's keyset in the Admin Portal.
Flag/Report messages
report()
lets you flag and report an inappropriate message to the admin.
Method signature
This method takes the following parameters:
message.report(reason: string): Promise<any>
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
reason | string | Yes | n/a | Reason for reporting/flagging a given message. |
Output
Type | Description |
---|---|
Promise<any> | Returned object with a value of any type. |
Basic usage
Report the last message on the support
channel as offensive.
// reference the "incident-management" channel
const channel = await chat.getChannel("support")
// get the last message on the channel
const lastMessage = (await channel.getHistory({count: 1})).messages[0]
// report the message to the admin and provide the reason
await message.report("This message contains profane words. Can you remove it?")
Listen to report
events
As an admin of your chat app, you can monitor all events emitted when someone reports an offensive message using the listenForEvents()
method. You can use this method to create moderation dashboard alerts.
Events documentation
To read more about the events of type report
, refer to the Chat events documentation.
Method signature
This method has the following parameters:
chat.listenForEvents({
channel: string;
type?: "report";
callback: (event: "report") => unknown;
}): () => void
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | string | Yes | n/a | Channel to listen for new report events. Set this value to a dedicated PUBNUB_INTERNAL_ADMIN_CHANNEL where all report events are sent. |
type | string | No | n/a | Type of events. report is the type defined for all events emitted when an offensive message is flagged/reported. |
callback | n/a | Yes | n/a | Callback function passed as a parameter. It defines the custom behavior to be executed whenever a report event type is detected on the specified channel. |
method | string | This parameter is deprecated. You no longer have to provide a method used to send this event type as the method is now passed automatically. publish for all events related to reporting. |
Output
Type | Description |
---|---|
() => void | Function you can call to disconnect (unsubscribe) from the channel and stop receiving report events. |
Basic usage
Print a notification for an offensive message reported on the support
channel.
const chat = {
listenForEvents: async (config) => {
const simulateEvent = () => {
const event = "report";
const eventData = {
channel: "support",
user: "Alice",
message: "That's a complete $5#$%#&$!",
};
if (event === config.type) {
config.callback(eventData);
}
};
// simulate a single event when listening starts
show all 28 lines