> ## Documentation Index
> Fetch the complete documentation index at: https://docs.novu.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Platform events

> Receive provider events Novu does not handle, such as Slack link_shared, and call the provider's own API through Novu with the credentials it already holds.

Novu turns the common provider events into agent events: a Slack message becomes `onMessage`, a reaction becomes `onReaction`, a button click becomes `onAction`. Providers send many more events than that. Platform events let your agent receive any of the others and answer them with the provider's own API, without running a second webhook endpoint or storing provider tokens.

Use platform events when you need a provider feature Novu has no building block for yet:

* **Link unfurling:** show a rich preview when someone posts a link to your product.
* **Interactive unfurls and modals:** handle button clicks inside your own unfurl cards or modal views.
* **Slash commands:** answer `/your-command` from your agent.
* **Workspace and channel events:** welcome new members, react to new or renamed channels.

> [!NOTE]
>
> Platform events are available on Slack today, for agents connected with your own app. They are not available for managed agents or for the shared Novu demo app. If they aren't enabled for your organization yet, contact Novu support.

## How it works

```mermaid theme={null}
sequenceDiagram
    participant Provider as Chat provider
    participant Novu
    participant Bridge as Agent bridge

    Provider->>Novu: Event (for example link_shared)
    Novu->>Novu: Verify signature, check the integration's allowlist
    Novu-->>Provider: 200 OK
    Novu->>Bridge: onPlatformEvent(platform, event, ctx)
    Bridge->>Novu: ctx.platformApi.call('chat.unfurl', ...)
    Novu->>Provider: API call with the integration's credentials
    Provider-->>Novu: { ok: true }
    Novu-->>Bridge: { ok: true }
```

1. The provider sends the event to the same endpoint it already uses for your agent.
2. Novu verifies the request signature and checks the event type against the allowlist on the agent's integration. Events that aren't on the list keep the existing behavior.
3. Novu acknowledges the provider at once, looks up the subscriber linked to the user who caused the event, and delivers the event to `onPlatformEvent` in your bridge.
4. Your handler calls the provider's API through `ctx.platformApi`. Novu adds the integration's credentials, so your bridge never holds a provider token.

## Choose which events to forward

Forwarding is opt-in, per agent integration. Nothing is forwarded until you list the event types.

> [tab] Dashboard
>
> 1. Open the agent in the Novu Dashboard and select its Slack integration.
> 2. In **Platform events**, add the event types to forward, for example `link_shared`.
> 3. Click **Save**.

> [tab] API
>
> Set `platformEvents.forward` when you [update an agent integration](https://docs.novu.co/api-reference/agents/update-an-agent-integration.md):
>
> ```bash theme={null}
> curl -X PATCH "https://api.novu.co/v1/agents/<AGENT_IDENTIFIER>/integrations/<AGENT_INTEGRATION_ID>" \
>   -H "Authorization: ApiKey <NOVU_SECRET_KEY>" \
>   -H "Content-Type: application/json" \
>   -d '{ "platformEvents": { "forward": ["link_shared", "block_actions"] } }'
> ```
>
> Send `"forward": []` to stop forwarding.

Rules for the list:

* Use the provider's own event type names (`link_shared`, `team_join`, `view_submission`).
* Events Novu already handles, such as `message`, `app_mention` and `reaction_added`, can't be forwarded, so one event never runs two handlers.
* `*` forwards every event Novu doesn't handle. It must be the only entry.
* Up to 50 event types per integration.

You also have to subscribe your provider app to these events and grant the scopes they need. See [Slack platform events](https://docs.novu.co/agents/channels/slack.md#platform-events) for the Slack setup.

## Handle events

Add `onPlatformEvent` to your agent. It receives three arguments: the platform the event came from, the event, and a context. Declare `ctx` only when you call the provider's API: `(platform, event) => …` works too.

```typescript theme={null}
import { agent } from '@novu/framework';

export const supportAgent = agent('support-agent', {
  onMessage: async (message, ctx) => {
    // ...
  },
  onPlatformEvent: async (platform, event, ctx) => {
    if (platform === 'slack' && event.is('link_shared')) {
      // event.payload is typed as Slack's link_shared event
      for (const link of event.payload.links) {
        console.log('Shared:', link.url);
      }
    }
  },
});
```

Checking `platform` first tells TypeScript which provider's events you're handling. `event.is(type)` then narrows `event.payload` to the typed shape for that event. Novu ships types for Slack `link_shared`, `block_actions` and `slash_command`; any other event type arrives as a plain record.

### The event object

| Field | Type | Description |
| - | - | - |
| `id` | `string` | The provider's event ID (Slack `event_id`, or the interaction's `trigger_id`). |
| `type` | `string` | The provider's event type, as listed in the allowlist. |
| `payload` | `Record<string, unknown>` | The event exactly as the provider sent it. |
| `workspaceId` | `string \| undefined` | The workspace the event came from (Slack `team_id`). |
| `subscriberId` | `string \| null` | The Novu subscriber linked to the provider user who caused the event, such as the Slack user who shared the link or clicked the button. `null` when the event has no user or no subscriber is linked to them. |
| `integrationIdentifier` | `string` | The integration that received the event. |
| `receivedAt` | `string` | When Novu received the event (ISO 8601). |
| `is(type)` | `(type: string) => boolean` | Checks the type and narrows `payload`. |

### The context object

Platform events aren't part of a conversation, so the context has no `reply` or history. It has:

| Field | Description |
| - | - |
| `ctx.platform` | The platform the event came from, the same as the first argument. |
| `ctx.agentId` | The agent identifier. |
| `ctx.integrationIdentifier` | The integration that received the event. |
| `ctx.platformApi` | Calls the provider's API with the integration's credentials. See [Call the provider's API](#call-the-providers-api). |

## Call the provider's API

`ctx.platformApi` calls the provider's own API through Novu. You choose the method and arguments; Novu picks the host, adds the credentials and returns the provider's answer unchanged.

```typescript theme={null}
// Slack method style: posts the arguments to /chat.unfurl and returns Slack's response body
const result = await ctx.platformApi.call('chat.unfurl', { channel, ts, unfurls });

if (!result.ok) {
  console.warn('Slack refused the unfurl:', result.error);
}
```

`call()` doesn't throw when the provider answers with an error such as `{ ok: false }`: check the response the way you would with the provider's SDK. It throws a `PlatformApiError` only when Novu refuses the call itself, for example for a blocked method.

Use `request()` when you need the HTTP status or headers, such as `retry-after` on a rate limit:

```typescript theme={null}
const response = await ctx.platformApi.request({
  method: 'GET',
  path: '/users.info',
  query: { user: 'U0123ABCD' },
});

console.log(response.status, response.headers['retry-after'], response.body);
```

Inside `onPlatformEvent`, calls run in the workspace the event came from. Outside a handler, for example from a background job, create a client yourself and pass `workspaceId` when the app is installed in more than one workspace:

```typescript theme={null}
import { createPlatformApi } from '@novu/framework';

const slack = createPlatformApi({
  apiUrl: 'https://api.novu.co',
  secretKey: process.env.NOVU_SECRET_KEY!,
  agentId: 'support-agent',
  integrationIdentifier: 'slack',
  workspaceId: 'T0123ABCD',
});

await slack.call('chat.postMessage', { channel: 'C0123ABCD', text: 'Nightly report is ready' });
```

The same proxy is available over HTTP as `POST /v1/agents/{agentIdentifier}/integrations/{integrationIdentifier}/platform-api` with your secret key.

### Guardrails

* Calls are scoped to the environment of the secret key and to integrations connected to the agent.
* Methods that change the installation itself are blocked, such as Slack `oauth.*`, `admin.*`, `apps.uninstall` and `auth.revoke`.
* Requests are limited to 1 MB, responses to 5 MB, and each call to 10 seconds.
* Novu logs the method, path, status and latency of every call, never the bodies.

## Delivery

* Novu acknowledges the provider before it calls your bridge, so slow handlers never make the provider retry.
* Each event is delivered once. Provider retries of the same event are dropped for 10 minutes.
* Failed deliveries aren't retried, and events can arrive in any order.
* An error thrown in `onPlatformEvent` is logged by the bridge and doesn't affect other handlers.
* An agent without `onPlatformEvent` ignores forwarded events.

Some interactions need an answer in the same HTTP response, such as a Slack `view_submission` that returns validation errors. Novu has already answered the provider by the time your handler runs, so use the provider's API (for example `views.update`) or the interaction's `response_url` instead.

## Related

> [card] [Slack platform events](https://docs.novu.co/agents/channels/slack.md#platform-events)
>
> Setup, link unfurling and other Slack examples.

> [card] [Handlers and context](https://docs.novu.co/agents/custom-code-agent/building-blocks/handle-events.md)
>
> The handlers Novu runs for conversation events.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.