技能 编程开发 Retell AI Webhook事件处理

Retell AI Webhook事件处理

v20260423
retellai-webhooks-events
本技能用于指导开发者如何为 Retell AI 构建和管理 webhook 端点。它支持捕获和处理关键的呼叫生命周期事件(如呼叫开始、结束、分析),并能接收和处理对话中触发的函数调用。适用于构建需要与 Retell AI 进行实时后端交互的复杂语音代理或呼叫自动化系统。
获取技能
148 次下载
概览

Retell AI Webhooks Events

Overview

Handle Retell AI webhook events for call lifecycle, transcripts, and function execution.

Prerequisites

  • HTTPS webhook endpoint
  • Agent configured with webhook URL

Instructions

Step 1: Configure Webhook URL

// Set webhook URL in agent configuration
await retell.agent.update(agentId, {
  webhook_url: 'https://your-app.com/webhooks/retell',
});

Step 2: Webhook Endpoint

import express from 'express';

const app = express();
app.post('/webhooks/retell', express.json(), async (req, res) => {
  const { event, call } = req.body;

  switch (event) {
    case 'call_started':
      console.log(`Call started: ${call.call_id} from ${call.from_number}`);
      break;

    case 'call_ended':
      console.log(`Call ended: ${call.call_id}`);
      console.log(`  Duration: ${call.duration_ms}ms`);
      console.log(`  Status: ${call.call_status}`);
      if (call.transcript) {
        await saveTranscript(call.call_id, call.transcript);
      }
      break;

    case 'call_analyzed':
      console.log(`Analysis ready: ${call.call_id}`);
      console.log(`  Summary: ${call.call_analysis?.call_summary}`);
      break;

    default:
      console.log(`Unhandled event: ${event}`);
  }

  res.status(200).json({ received: true });
});

Step 3: Handle Function Calls During Conversation

// When agent triggers a function, Retell calls your URL
app.post('/functions/book-appointment', express.json(), async (req, res) => {
  const { patient_name, phone, date, time } = req.body.args;

  // Process the booking
  const booking = await bookAppointment(patient_name, phone, date, time);

  // Return response for agent to speak
  res.json({
    result: `Appointment booked for ${patient_name} on ${date} at ${time}. Confirmation number: ${booking.id}`,
  });
});

Output

  • Webhook handling for call lifecycle events
  • Transcript storage on call completion
  • Function execution during live calls

Error Handling

Issue Cause Solution
No webhook events URL not configured Set webhook_url on agent
Function timeout Slow backend Respond within 5 seconds
Missing transcript Short call Transcript only for calls > 5 seconds

Resources

Next Steps

Common errors: retellai-common-errors

信息
Category 编程开发
Name retellai-webhooks-events
版本 v20260423
大小 2.94KB
更新时间 2026-04-28
语言