Report offensive messages

Unity 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 ID of PUBNUB_INTERNAL_MODERATION_{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.

All messages (events of type report) reported on a given channel are sent to a PUBNUB_INTERNAL_MODERATION_{channel_id} channel which is a child channel for the main one where a reported message was published. For example, an event on a message reported on the support channel will be sent to the PUBNUB_INTERNAL_MODERATION_support channel.

Method signature

This method takes the following parameters:

message.Report(string reason)

Input

ParameterTypeRequiredDefaultDescription
reasonstringYesn/aReason for reporting/flagging a given message.

Output

This method doesn't return any data.

Basic usage

Report the last message on the support channel as offensive.

// get the "supportt" channel
if (chat.TryGetChannel("support", out var channel))
{
Console.WriteLine($"Found channel with name {channel.Name}");

// retrieve the message history with the desired count
var messageHistory = channel.GetMessageHistory(null, null, 1);

// get the last message from the returned list
var lastMessage = messageHistory.Messages.FirstOrDefault();

// report the last message if it exists
if (lastMessage != null)
{
lastMessage.Report("This is insulting!");
show all 26 lines

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 StartListeningForReportEvents() 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:

// start listening
channel.StartListeningForReportEvents(string channelId)

// triggered report event
public event Action<ReportEvent> OnReportEvent;
// needs a corresponding event handler
void EventHandler(ReportEvent event)
Input
ParameterTypeRequiredDefaultDescription
channelIdstringNo (events are sent by default to the PUBNUB_INTERNAL_MODERATION_{channel_id} channel)n/aChannel to listen for new report events.
Output

This method doesn't return any data.

Basic usage

Print a notification for an offensive message reported on the support channel.

chat.StartListeningForReportEvents("support");
chat.OnReportEvent += reportEvent =>
{
Console.WriteLine("Message reported on the support channel!")
}
Last updated on