---
source_url: https://www.pubnub.com/docs/chat/chat-sdk/build/features/messages/moderation
title: Report offensive messages
updated_at: 2026-06-12T11:22:32.516Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# 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](https://www.pubnub.com/docs/chat/chat-sdk/build/features/custom-events#chat-events).

Add custom logic using [emitted events](#listen-to-report-events) to handle reported messages (e.g., [delete them](https://www.pubnub.com/docs/chat/chat-sdk/build/features/messages/delete)).

:::note Message Persistence
Enable Message Persistence in the [Admin Portal](https://admin.pubnub.com/).
:::

##### Under the hood

All moderation-related methods call PubNub Pub/Sub API and the JavaScript SDK [publish()](https://www.pubnub.com/docs/sdks/javascript/api-reference/publish-and-subscribe#publish) method.

## 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:

```ts
message.report(reason: string): Promise<any>
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| reason | string | Yes |  | Reason for reporting/flagging a given message. |

#### Output

| Type | Description |
| --- | --- |
| `Promise<any>` | Returned object with a value of any type. |

### Sample code

Report the last message on the `support` channel as offensive.

```ts
// 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 lastMessage.report("This message contains profane words. Can you remove it?")
```

## Get historical reported messages

`getMessageReportsHistory()` fetches reported message events for a channel with optional time and count filters.

### Method signature

This method takes the following parameters:

```ts
channel.getMessageReportsHistory(params?: {
    startTimetoken?: string;
    endTimetoken?: string;
    count?: number;
}): Promise<{
    events: Event<"report">[];
    isMore: boolean;
}>
```

#### Input

| Parameter | Description |
| --- | --- |
| `startTimetoken`Type: `string`Default: n/a | The start timetoken for fetching the history of reported messages, which allows specifying the point in time where the history retrieval should begin. |
| `endTimetoken`Type: `string`Default: n/a | The end time token for fetching the history of reported messages, which allows specifying the point in time where the history retrieval should end. |
| `count`Type: `number`Default: `undefined` | The number of reported message events to fetch from the history. |

#### Output

| Parameter | Description |
| --- | --- |
| `Promise<>`Type: `object` | Returned object containing these fields: `events` and `isMore`. |
| `> events`Type: `Event<"report">[]` | An array of events where each event is of the type `"report"`. These events represent the reported messages in the specified channel. |
| `> isMore`Type: `boolean` | A boolean flag indicating whether there are more reported message events available apart from the ones fetched in the current operation. |

### Sample code

Fetch historical messages reported on the `support` channel between the `1725100800000` (July 1, 2024, 00:00:00 UTC) and `1726780799000` (July 21, 2024, 23:59:59 UTC) timetokens.

```ts
// Example start and end timetokens
const startTimetoken = "1725100800000"; // July 1, 2024, 00:00:00 UTC in milliseconds
const endTimetoken = "1726780799000";   // July 21, 2024, 23:59:59 UTC in milliseconds

// asynchronously fetch the channel object and then get the reported messages history
async function fetchReportedMessagesHistory() {
    try {
        // reference the "chat" object and invoke the "getChannel()" method
        const channel = await chat.getChannel("support");

        // fetch the reported message history
        const { events, isMore } = await channel.getMessageReportsHistory({
            startTimetoken,
            endTimetoken
        });

        console.log("Reported Events:", events);
        console.log("Is there more data?:", isMore);
    } catch (error) {
        console.error("Error fetching message reports history:", error);
    }
}

// call the function to fetch reported messages history
fetchReportedMessagesHistory();
```

## Listen to report events

`channel.onMessageReported()` monitors report events for moderation dashboards.

### Method signature

```ts
channel.onMessageReported(callback: (report: MessageReport) => void): () => void
```

The `MessageReport` object contains:

| Property | Description |
| --- | --- |
| `reason`Type: `string` | Reason the message was reported. |
| `text`Type: `string?` | Text content of the reported message, if available. |
| `messageTimetoken`Type: `string?` | Timetoken of the reported message. |
| `reportedMessageChannelId`Type: `string?` | ID of the channel where the reported message was posted. |
| `reportedUserId`Type: `string?` | ID of the user who sent the reported message. |
| `autoModerationId`Type: `string?` | ID assigned by auto-moderation, if applicable. |

### Sample code

```ts
const channel = await chat.getChannel("support")
const stopListening = channel.onMessageReported((report) => {
    console.log(`Message reported: reason=${report.reason}, by user=${report.reportedUserId}`)
})
```

## Flag/Report messages (deprecated)

`DEPRECATED_report()` lets you flag and report an inappropriate message to the admin. All reported messages (events of type `report`) are sent to one dedicated `INTERNAL_ADMIN_CHANNEL` channel (one "bucket" for all reported messages).

### Method signature

This method takes the following parameters:

```ts
message.DEPRECATED_report(reason: string): Promise<any>
```

#### Input

| Parameter | Description |
| --- | --- |
| `reason` *Type: `string`Default: n/a | Reason for reporting/flagging a given message. |

#### Output

| Type | Description |
| --- | --- |
| `Promise<any>` | Returned object with a value of any type. |

### Sample code

Report the last message on the `support` channel as offensive.

```ts
// 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 lastMessage.DEPRECATED_report("This message contains profane words. Can you remove it?")
```