Report offensive messages

Users can report offensive messages directly from your app. Reported messages publish to PUBNUB_INTERNAL_MODERATION_{channel_id} and emit report events.

Add custom logic using emitted events to handle reported messages (e.g., delete them).

Message Persistence

Enable Message Persistence in the Admin Portal.

Flag/Report messages​

Report() flags a message for admin review. Reports publish to PUBNUB_INTERNAL_MODERATION_{channel_id} (e.g., reporting on support sends to PUBNUB_INTERNAL_MODERATION_support).

Method signature​

This method takes the following parameters:

1message.Report(string reason)

Input​

required
reason required#
Type: string
Default: no default
Reason for reporting/flagging a given message.

Output​

An awaitable Task<ChatOperationResult>.

Sample code​

Report the last message on the support channel as offensive.

1using System.Linq;
2using System.Threading.Tasks;
3using PubnubApi;
4using PubnubChatApi;
5using UnityEngine;
6
7// Configuration
8PubnubChatConfig chatConfig = new PubnubChatConfig();
9
10PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
11{
12 SubscribeKey = "demo",
13 PublishKey = "demo",
14 Secure = true
15};
show all 54 lines

Listen to Report events​

StreamReportEvents() monitors report events for moderation dashboards. Use OnMessageReported to handle report updates.

Events documentation

To read more about the events of type Report, refer to the Chat events documentation.

Method naming

Earlier versions used SetListeningForReportEvents() to enable streaming. This method has been superseded by StreamReportEvents(), though it remains available for backward compatibility.

Method signature​

These methods take the following parameters:

  • StreamReportEvents()

    1channel.StreamReportEvents(bool stream)
  • OnMessageReported - Event signature

    1// event on the Channel entity — enabled by StreamReportEvents()
    2public event Action<MessageReport> OnMessageReported;
    3// needs a corresponding event handler
    4void EventHandler(MessageReport report)

Input​

stream#
Type: bool
Default: no default
Whether to start (true) or stop (false) listening to report events on the channel. Events are sent to the PUBNUB_INTERNAL_MODERATION_{channel_id} channel.
Required in StreamReportEvents()
Yes
Required in OnMessageReported
n/a
report#
Type: MessageReport
Default: no default
Typed report data containing the flagged message text, reason, timetoken, channel ID, and reporter's user ID.
Required in StreamReportEvents()
No
Required in OnMessageReported
Yes

Output​

These methods don't return a value. Report event updates are delivered through the OnMessageReported event handler.

Sample code​

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

1using System.Linq;
2using System.Threading.Tasks;
3using PubnubApi;
4using PubnubChatApi;
5using UnityEngine;
6
7// Configuration
8PubnubChatConfig chatConfig = new PubnubChatConfig();
9
10PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
11{
12 SubscribeKey = "demo",
13 PublishKey = "demo",
14 Secure = true
15};
show all 33 lines

Was this page useful?

Last updated on