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

# AgentPhone webhooks

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

The AgentPhone plugin handles incoming webhooks. Point your provider’s subscription URL at your Corsair HTTP handler (see [Overview](https://docs.corsair.dev/plugins/agentphone/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

* `agents`
  * `callEnded` (`agents.callEnded`)
  * `callStarted` (`agents.callStarted`)
  * `contactShared` (`agents.contactShared`)
  * `message` (`agents.message`)
  * `reaction` (`agents.reaction`)
* `numbers`
  * `released` (`numbers.released`)

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

## Agents

### Call Ended

`agents.callEnded`

A voice call ended.

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `event` | `agent.call_ended` | Yes | — |
| `channel` | `string` | No | — |
| `timestamp` | `string` | Yes | — |
| `agentId` | `string \| null` | No | — |
| `test` | `boolean` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   callId: string,
>   endedAt?: string | null,
>   durationSeconds?: number | null,
>   transcript?: {
>     role: string,
>     content: string
>   }[] | null
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   event: agent.call_ended,
>   channel?: string,
>   timestamp: string,
>   agentId?: string | null,
>   test?: boolean,
>   data: {
>     callId: string,
>     endedAt?: string | null,
>     durationSeconds?: number | null,
>     transcript?: {
>       role: string,
>       content: string
>     }[] | null
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
agentphone({
    webhookHooks: {
        agents: {
            callEnded: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Call Started

`agents.callStarted`

A voice call was answered.

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `event` | `agent.call_started` | Yes | — |
| `channel` | `string` | No | — |
| `timestamp` | `string` | Yes | — |
| `agentId` | `string \| null` | No | — |
| `test` | `boolean` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   callId: string,
>   startedAt: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   event: agent.call_started,
>   channel?: string,
>   timestamp: string,
>   agentId?: string | null,
>   test?: boolean,
>   data: {
>     callId: string,
>     startedAt: string
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
agentphone({
    webhookHooks: {
        agents: {
            callStarted: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Contact Shared

`agents.contactShared`

An iMessage contact shared their name.

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `event` | `agent.contact_shared` | Yes | — |
| `channel` | `string` | No | — |
| `timestamp` | `string` | Yes | — |
| `agentId` | `string \| null` | No | — |
| `test` | `boolean` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   address: string,
>   numberId: string,
>   displayName?: string | null,
>   firstName?: string | null,
>   lastName?: string | null
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   event: agent.contact_shared,
>   channel?: string,
>   timestamp: string,
>   agentId?: string | null,
>   test?: boolean,
>   data: {
>     address: string,
>     numberId: string,
>     displayName?: string | null,
>     firstName?: string | null,
>     lastName?: string | null
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
agentphone({
    webhookHooks: {
        agents: {
            contactShared: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Message

`agents.message`

An inbound message or a live voice transcript arrived.

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `event` | `agent.message` | Yes | — |
| `channel` | `string` | No | — |
| `timestamp` | `string` | Yes | — |
| `agentId` | `string \| null` | No | — |
| `test` | `boolean` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   numberId?: string | null,
>   messageId?: string | null,
>   conversationId?: string | null,
>   message?: string | null,
>   transcript?: string | null,
>   from?: string | null,
>   to?: string | null
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   event: agent.message,
>   channel?: string,
>   timestamp: string,
>   agentId?: string | null,
>   test?: boolean,
>   data: {
>     numberId?: string | null,
>     messageId?: string | null,
>     conversationId?: string | null,
>     message?: string | null,
>     transcript?: string | null,
>     from?: string | null,
>     to?: string | null
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
agentphone({
    webhookHooks: {
        agents: {
            message: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Reaction

`agents.reaction`

A contact reacted to an iMessage or WhatsApp message.

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `event` | `agent.reaction` | Yes | — |
| `channel` | `string` | No | — |
| `timestamp` | `string` | Yes | — |
| `agentId` | `string \| null` | No | — |
| `test` | `boolean` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   messageId?: string | null,
>   reactionType: string,
>   conversationId: string,
>   numberId: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   event: agent.reaction,
>   channel?: string,
>   timestamp: string,
>   agentId?: string | null,
>   test?: boolean,
>   data: {
>     messageId?: string | null,
>     reactionType: string,
>     conversationId: string,
>     numberId: string
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
agentphone({
    webhookHooks: {
        agents: {
            reaction: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Numbers

### Released

`numbers.released`

A number reached its expiry date and was released.

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `event` | `number.released` | Yes | — |
| `channel` | `string` | No | — |
| `timestamp` | `string` | Yes | — |
| `agentId` | `string \| null` | No | — |
| `test` | `boolean` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
>   numberId: string,
>   phoneNumber: string,
>   reason: string,
>   expiresAt: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   event: number.released,
>   channel?: string,
>   timestamp: string,
>   agentId?: string | null,
>   test?: boolean,
>   data: {
>     numberId: string,
>     phoneNumber: string,
>     reason: string,
>     expiresAt: string
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
agentphone({
    webhookHooks: {
        numbers: {
            released: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***


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