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

# SiteSpeakAI webhooks

> SiteSpeakAI incoming webhooks in Corsair: the event paths to subscribe to, the payload each event carries, and the response data.

The SiteSpeakAI plugin handles incoming webhooks. Point your provider’s subscription URL at your Corsair HTTP handler (see [Overview](https://docs.corsair.dev/plugins/sitespeakai/overview.md) for setup context and the exact URL shape).

> [!NOTE]
>
> **New to Corsair?** See [webhooks](https://docs.corsair.dev/concepts/webhooks.md) and [hooks](https://docs.corsair.dev/concepts/hooks.md).

## Webhook map

* `clients`
  * `creditsExhausted` (`clients.creditsExhausted`)
* `escalations`
  * `created` (`escalations.created`)
* `leads`
  * `captured` (`leads.captured`)
* `ping`
  * `received` (`ping.received`)

## HTTP handler setup

```ts app/api/webhook/route.ts theme={null}
import { processWebhook } from "corsair";
import { corsair } from "@/server/corsair";

export async function POST(request: Request) {
    const headers = Object.fromEntries(request.headers);
    // With multiTenancy, give each tenant its own URL (/api/webhook?tenantId=acme):
    // the query says whose account, secret and hooks handle the delivery.
    const query = Object.fromEntries(new URL(request.url).searchParams);
    // The raw text, not request.json(): signatures are checked over the exact bytes sent.
    const body = await request.text();
    const result = await processWebhook(corsair, headers, body, query);
    if (!result.plugin) {
        return Response.json({ success: false }, { status: 404 });
    }
    // A refusal (bad signature) carries no status and answers 400; a handler
    // that threw comes back with 500, so the sender retries it.
    const status =
        result.response?.success === false ? (result.response.statusCode ?? 400) : 200;
    return Response.json(result.response ?? { success: true }, {
        status,
        headers: result.responseHeaders,
    });
}
```

## Events

## Clients

### Credits Exhausted

`clients.creditsExhausted`

A client workspace ran out of its own message credits (client.credits\_exhausted)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `timestamp` | `string \| null` | No | — |
| `team_id` | `string \| null` | No | — |
| `external_reference` | `string \| null` | No | — |
| `chatbot_id` | `string \| null` | No | — |
| `event` | `client.credits_exhausted` | Yes | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   message_limit?: number | null,
>   messages_used?: number | null,
>   topup_credits_remaining?: number | null
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   timestamp?: string | null,
>   team_id?: string | null,
>   external_reference?: string | null,
>   chatbot_id?: string | null,
>   event: client.credits_exhausted,
>   data: {
>     message_limit?: number | null,
>     messages_used?: number | null,
>     topup_credits_remaining?: number | null
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
sitespeakai({
    webhookHooks: {
        clients: {
            creditsExhausted: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Escalations

### Created

`escalations.created`

A visitor asked to talk to a human; carries the last message and inbox URL (escalation.created)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `timestamp` | `string \| null` | No | — |
| `team_id` | `string \| null` | No | — |
| `external_reference` | `string \| null` | No | — |
| `chatbot_id` | `string \| null` | No | — |
| `event` | `escalation.created` | Yes | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   visitor?: {
>     id?: string | null,
>     visitor_id?: string | null,
>     email?: string | null,
>     first_name?: string | null,
>     last_name?: string | null,
>     phone?: string | null,
>     custom_data?: Record<string, any> | null
>   } | null,
>   chatbot_name?: string | null,
>   last_message?: string | null,
>   inbox_url?: string | null
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   timestamp?: string | null,
>   team_id?: string | null,
>   external_reference?: string | null,
>   chatbot_id?: string | null,
>   event: escalation.created,
>   data: {
>     visitor?: {
>       id?: string | null,
>       visitor_id?: string | null,
>       email?: string | null,
>       first_name?: string | null,
>       last_name?: string | null,
>       phone?: string | null,
>       custom_data?: Record<string, any> | null
>     } | null,
>     chatbot_name?: string | null,
>     last_message?: string | null,
>     inbox_url?: string | null
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
sitespeakai({
    webhookHooks: {
        escalations: {
            created: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Leads

### Captured

`leads.captured`

A visitor left contact details in a client workspace agent for the first time (lead.captured)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `timestamp` | `string \| null` | No | — |
| `team_id` | `string \| null` | No | — |
| `external_reference` | `string \| null` | No | — |
| `chatbot_id` | `string \| null` | No | — |
| `event` | `lead.captured` | Yes | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   visitor?: {
>     id?: string | null,
>     visitor_id?: string | null,
>     email?: string | null,
>     first_name?: string | null,
>     last_name?: string | null,
>     phone?: string | null,
>     custom_data?: Record<string, any> | null
>   } | null,
>   chatbot_name?: string | null
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   timestamp?: string | null,
>   team_id?: string | null,
>   external_reference?: string | null,
>   chatbot_id?: string | null,
>   event: lead.captured,
>   data: {
>     visitor?: {
>       id?: string | null,
>       visitor_id?: string | null,
>       email?: string | null,
>       first_name?: string | null,
>       last_name?: string | null,
>       phone?: string | null,
>       custom_data?: Record<string, any> | null
>     } | null,
>     chatbot_name?: string | null
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
sitespeakai({
    webhookHooks: {
        leads: {
            captured: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Ping

### Received

`ping.received`

A test delivery sent from the dashboard or agency.webhooks.test (ping)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `timestamp` | `string \| null` | No | — |
| `team_id` | `string \| null` | No | — |
| `external_reference` | `string \| null` | No | — |
| `chatbot_id` | `string \| null` | No | — |
| `event` | `ping` | Yes | — |
| `data` | `Record<string, any> \| null` | No | — |

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   timestamp?: string | null,
>   team_id?: string | null,
>   external_reference?: string | null,
>   chatbot_id?: string | null,
>   event: ping,
>   data?: Record<string, any> | null
> }
> ```

**`webhookHooks` example**

```ts theme={null}
sitespeakai({
    webhookHooks: {
        ping: {
            received: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***


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