diff --git a/fern/assistants/assistant-hooks.mdx b/fern/assistants/assistant-hooks.mdx index 9cb7da4d2..f7b58e7d4 100644 --- a/fern/assistants/assistant-hooks.mdx +++ b/fern/assistants/assistant-hooks.mdx @@ -157,6 +157,10 @@ Handle customer speech interruptions in a similar way: } ``` + +Use `"oneOf": ["pipeline-error"]` as a catch-all filter for any pipeline-related error reason. + + ## Common use cases - Transfer to a human agent on errors @@ -164,6 +168,92 @@ Handle customer speech interruptions in a similar way: - Handle customer or assistant interruptions gracefully - Log errors or events for monitoring +## Slack Webhook on Call Failure + +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. + +### Step 1: Generate a Slack webhook + +Follow the [Slack webhook documentation](https://api.slack.com/messaging/webhooks) to create an incoming webhook: + +1. Create a Slack app (if you don't have one already) +2. Enable incoming webhooks in your app settings +3. Create an incoming webhook for your desired channel +4. Copy the webhook URL (it will look like `https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX`) + +### Step 2: Create a serverless function + +Set up a serverless function (using a service like [val.town](https://val.town)) to convert Vapi tool call requests into Slack messages: + +```javascript +export default async function(req: Request): Promise { + try { + const json = await req.json(); + console.log(json); + + const callId = json.message.call.id; + const reason = json.message.toolCalls[0].function.arguments.properties.callEndedReason.value; + + fetch("", { + "method": "POST", + "headers": { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + text: `🚨 Call Failed\nCall ID: ${callId}\nReason: ${reason}` + }), + }); + + return Response.json({ + results: [{ + "result": "success", + "toolCallId": "hook-function-call" + }], + }); + } catch (err) { + console.error("JSON parsing error:", err); + return new Response("Invalid JSON", { status: 400 }); + } +} +``` + +### Step 3: Configure the assistant hook + +Add this hook configuration to your assistant to trigger Slack notifications on call failures: + +```json +{ + "hooks": [{ + "on": "call.ending", + "filters": [{ + "type": "oneOf", + "key": "call.endedReason", + "oneOf": ["pipeline-error"] + }], + "do": [{ + "type": "function", + "function": { + "name": "report_error", + "parameters": { + "type": "object", + "properties": { + "text": { + "type": "string", + "value": "A call error occurred." + } + } + }, + "description": "Reports a call error to Slack." + }, + "async": false, + "server": { + "url": "" + } + }] + }] +} +``` + -Use `"oneOf": ["pipeline-error"]` as a catch-all filter for any pipeline-related error reason. +Replace `` with your actual Slack webhook URL and `` with your serverless function endpoint. \ No newline at end of file