Skip to content

Commit 77af68e

Browse files
authored
add assistant-hooks (#251)
1 parent a58b937 commit 77af68e

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Assistant Hooks
2+
3+
Assistant hooks allow you to configure actions that will be performed when specific events occur during a call. Currently, hooks support the `call.ending` event, which triggers when a call is ending.
4+
5+
## Usage
6+
7+
Hooks are defined in the `hooks` array of an assistant. Each hook consists of:
8+
9+
- `on`: The event that triggers the hook (currently only supports `call.ending`)
10+
- `do`: The actions to perform when the hook triggers (currently only supports `transfer`)
11+
- `filters`: Optional conditions that must be met for the hook to trigger
12+
13+
The `call.endedReason` field in filters can be set to any of the [call ended reasons](https://docs.vapi.ai/api-reference/calls/get#response.body.endedReason). The transfer destination type follows the same schema as the [transfer call tool destinations](https://docs.vapi.ai/api-reference/tools/create#request.body.transferCall.destinations).
14+
15+
Note: Using `"oneOf": ["pipeline-error"]` acts as a catch-all filter that matches any pipeline-related error reason. This is useful when you want to handle all types of pipeline failures with the same transfer action.
16+
17+
## Example: Transfer on Pipeline Error
18+
19+
This example shows how to transfer a call to a fallback number when a pipeline error occurs. The hook will trigger when the call is ending due to a pipeline error, and transfer the call to a specified phone number:
20+
21+
```bash
22+
curl -X PATCH "https://api.vapi.ai/assistant/<id>" \
23+
-H "Authorization: Bearer <auth>" \
24+
-H "Content-Type: application/json" \
25+
-d '{
26+
"hooks": [{
27+
"on": "call.ending",
28+
"filters": [{
29+
"type": "oneOf",
30+
"key": "call.endedReason",
31+
"oneOf": ["pipeline-error"]
32+
}],
33+
"do": [{
34+
"type": "transfer",
35+
"destination": {
36+
"type": "number",
37+
"number": "+1234567890",
38+
"callerId": "+1987654321"
39+
}
40+
}]
41+
}]
42+
}'
43+
```
44+
45+
You can also transfer to a SIP destination:
46+
47+
```bash
48+
curl -X PATCH "https://api.vapi.ai/assistant/<id>" \
49+
-H "Authorization: Bearer <auth>" \
50+
-H "Content-Type: application/json" \
51+
-d '{
52+
"hooks": [{
53+
"on": "call.ending",
54+
"filters": [{
55+
"type": "oneOf",
56+
"key": "call.endedReason",
57+
"oneOf": ["pipeline-error"]
58+
}],
59+
"do": [{
60+
"type": "transfer",
61+
"destination": {
62+
"type": "sip",
63+
"sipUri": "sip:[email protected]"
64+
}
65+
}]
66+
}]
67+
}'
68+
```
69+
70+
Common use cases for hooks include:
71+
- Transferring to a human agent on errors
72+
- Routing to a fallback system if the assistant fails
73+
- Ensuring calls are handled gracefully in edge cases

fern/docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ navigation:
132132
path: assistants/dynamic-variables.mdx
133133
- page: Call Analysis
134134
path: assistants/call-analysis.mdx
135+
- page: Assistant Hooks
136+
path: assistants/assistant-hooks.mdx
135137
- page: Background Messages
136138
path: assistants/background-messages.mdx
137139
- page: Voice Formatting Plan

0 commit comments

Comments
 (0)