Skip to content

Commit e8f79f1

Browse files
committed
add docs on Slack notifications for call failures
1 parent 0df1844 commit e8f79f1

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

fern/assistants/assistant-hooks.mdx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,92 @@ Handle customer speech interruptions in a similar way:
164164
- Handle customer or assistant interruptions gracefully
165165
- Log errors or events for monitoring
166166

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

0 commit comments

Comments
 (0)