Skip to content

Commit 05ffa45

Browse files
Merge branch 'main' into fern-cli-version-upgrade
2 parents 7afb8c6 + 984d9aa commit 05ffa45

File tree

3 files changed

+501
-256
lines changed

3 files changed

+501
-256
lines changed

fern/assistants/assistant-hooks.mdx

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,103 @@ Handle customer speech interruptions in a similar way:
157157
}
158158
```
159159

160+
<Note>
161+
Use `"oneOf": ["pipeline-error"]` as a catch-all filter for any pipeline-related error reason.
162+
</Note>
163+
160164
## Common use cases
161165

162166
- Transfer to a human agent on errors
163167
- Route to a fallback system if the assistant fails
164168
- Handle customer or assistant interruptions gracefully
165169
- Log errors or events for monitoring
166170

171+
## Slack Webhook on Call Failure
172+
173+
You can set up automatic Slack notifications when calls fail by combining assistant hooks with Slack webhooks. This is useful for monitoring call quality and getting immediate alerts when issues occur.
174+
175+
### Step 1: Generate a Slack webhook
176+
177+
Follow the [Slack webhook documentation](https://api.slack.com/messaging/webhooks) to create an incoming webhook:
178+
179+
1. Create a Slack app (if you don't have one already)
180+
2. Enable incoming webhooks in your app settings
181+
3. Create an incoming webhook for your desired channel
182+
4. Copy the webhook URL (it will look like `https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX`)
183+
184+
### Step 2: Create a serverless function
185+
186+
Set up a serverless function (using a service like [val.town](https://val.town)) to convert Vapi tool call requests into Slack messages:
187+
188+
```javascript
189+
export default async function(req: Request): Promise<Response> {
190+
try {
191+
const json = await req.json();
192+
console.log(json);
193+
194+
const callId = json.message.call.id;
195+
const reason = json.message.toolCalls[0].function.arguments.properties.callEndedReason.value;
196+
197+
fetch("<your-slack-webhook-url>", {
198+
"method": "POST",
199+
"headers": {
200+
"Content-Type": "application/json",
201+
},
202+
body: JSON.stringify({
203+
text: `🚨 Call Failed\nCall ID: ${callId}\nReason: ${reason}`
204+
}),
205+
});
206+
207+
return Response.json({
208+
results: [{
209+
"result": "success",
210+
"toolCallId": "hook-function-call"
211+
}],
212+
});
213+
} catch (err) {
214+
console.error("JSON parsing error:", err);
215+
return new Response("Invalid JSON", { status: 400 });
216+
}
217+
}
218+
```
219+
220+
### Step 3: Configure the assistant hook
221+
222+
Add this hook configuration to your assistant to trigger Slack notifications on call failures:
223+
224+
```json
225+
{
226+
"hooks": [{
227+
"on": "call.ending",
228+
"filters": [{
229+
"type": "oneOf",
230+
"key": "call.endedReason",
231+
"oneOf": ["pipeline-error"]
232+
}],
233+
"do": [{
234+
"type": "function",
235+
"function": {
236+
"name": "report_error",
237+
"parameters": {
238+
"type": "object",
239+
"properties": {
240+
"text": {
241+
"type": "string",
242+
"value": "A call error occurred."
243+
}
244+
}
245+
},
246+
"description": "Reports a call error to Slack."
247+
},
248+
"async": false,
249+
"server": {
250+
"url": "<your-serverless-function-url>"
251+
}
252+
}]
253+
}]
254+
}
255+
```
256+
167257
<Note>
168-
Use `"oneOf": ["pipeline-error"]` as a catch-all filter for any pipeline-related error reason.
258+
Replace `<your-slack-webhook-url>` with your actual Slack webhook URL and `<your-serverless-function-url>` with your serverless function endpoint.
169259
</Note>

0 commit comments

Comments
 (0)