Skip to content

Commit f03b352

Browse files
cursoragentsahil
andcommitted
feat: Add call.ending hook with filters
Co-authored-by: sahil <sahil@vapi.ai>
1 parent 524ba3d commit f03b352

1 file changed

Lines changed: 73 additions & 6 deletions

File tree

fern/phone-numbers/phone-number-hooks.mdx

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,66 @@ slug: phone-numbers/phone-number-hooks
55

66
## Overview
77

8-
Phone number hooks allow you to configure actions that will be performed when specific events occur during a call. Currently, hooks support the `call.ringing` event (which is triggered when a call is ringing).
8+
Phone number hooks allow you to configure actions that will be performed when specific events occur during a call.
9+
10+
Supported events:
11+
12+
- `call.ringing`: Triggered when a call is ringing
13+
- `call.ending`: Triggered when a call is ending (supports filters for assistant-request failures)
914

1015
## Usage
1116

1217
Hooks are defined in the `hooks` array of a phone number. Each hook consists of:
1318

14-
- `on`: The event that triggers the hook (supports `call.ringing`)
15-
- `do`: The actions to perform when the hook triggers (supports `transfer` and `say`)
19+
- `on`: The event that triggers the hook (supports `call.ringing`, `call.ending`)
20+
- `do`: The action(s) to perform when the hook triggers
21+
- `filters` (for `call.ending` only): Optional conditions for when the hook should trigger. Filters for phone numbers are restricted to assistant-request related ended reasons on `call.endedReason`.
22+
23+
<Note>
24+
For `call.ending` on phone numbers, the filter key is fixed to `call.endedReason` and the values are limited to assistant-request related reasons.
25+
</Note>
26+
27+
<Info>
28+
When `do` includes a transfer, the destination can be a phone `number` or a `sip` URI. See the API reference for destination options.
29+
</Info>
30+
31+
## Example: Transfer on Call Ending (assistant-request failures)
32+
33+
Transfer the call immediately to a fallback number if the assistant request fails or returns an error/invalid/no assistant:
34+
35+
```bash
36+
curl -X PATCH "https://api.vapi.ai/phone-number/<id>" \
37+
-H "Authorization: Bearer <auth>" \
38+
-H "Content-Type: application/json" \
39+
-d '{
40+
"hooks": [
41+
{
42+
"on": "call.ending",
43+
"filters": [
44+
{
45+
"type": "oneOf",
46+
"key": "call.endedReason",
47+
"oneOf": [
48+
"assistant-request-failed",
49+
"assistant-request-returned-error",
50+
"assistant-request-returned-invalid-assistant",
51+
"assistant-request-returned-no-assistant"
52+
]
53+
}
54+
],
55+
"do": {
56+
"type": "transfer",
57+
"destination": {
58+
"type": "number",
59+
"number": "+15xxxx3"
60+
}
61+
}
62+
}
63+
]
64+
}'
65+
```
1666

17-
## Example: Say Message on Call Ringing
67+
## Example: Say message on call ringing
1868

1969
This example shows how to play a message when a call is ringing:
2070

@@ -33,7 +83,7 @@ curl -X PATCH "https://api.vapi.ai/phone-number/<id>" \
3383
}'
3484
```
3585

36-
## Example: Transfer on Call Ringing
86+
## Example: Transfer on call ringing
3787

3888
This example shows how to transfer a call when it starts ringing:
3989

@@ -77,4 +127,21 @@ curl -X PATCH "https://api.vapi.ai/phone-number/<id>" \
77127
```
78128

79129
Common use cases for phone number hooks include:
80-
- Disabling inbound calling by playing a message or transferring
130+
- Disabling inbound calling by playing a message or transferring
131+
132+
## How to enable
133+
134+
Use the Phone Numbers Update API to add hooks to a phone number’s config.
135+
136+
```bash
137+
curl -X PATCH "https://api.vapi.ai/phone-number/<id>" \
138+
-H "Authorization: Bearer <auth>" \
139+
-H "Content-Type: application/json" \
140+
-d '{
141+
"hooks": [ /* your hook objects */ ]
142+
}'
143+
```
144+
145+
<Tip>
146+
Looking to add hooks at the assistant level instead? Use the Assistants Update API and see [Assistant hooks](mdc:docs/assistants/assistant-hooks).
147+
</Tip>

0 commit comments

Comments
 (0)