ThunderPhone v3 已正式上线。全程自助,低至2美分/分钟。查看发布公告

Webhooks

telephony.complete / web.complete

通话结束时发送的非阻塞 Webhook,包含转录文本、录音 URL 和指标。

每次通话结束后都会触发完成事件——包括呼入电话、 呼出电话、网页通话或测试通话(构建器麦克风会话)。该事件为 非阻塞:请返回任意 2xx 响应。

事件会通过以下两种路径发送:

请求负载(端点投递)

{
  "data": {
    "billable_minutes": 1.25,
    "billing_total_cents": 8,
    "call_id": 987654321,
    "direction": "inbound",
    "duration_seconds": 54,
    "end_reason": "user_hangup",
    "end_time": "2026-04-20T18:25:04.822Z",
    "extracted_data": {
      "status": "completed",
      "fields": {
        "customer_name": "Alex Morgan",
        "appointment_date": "2026-04-23"
      },
      "evidence": {
        "customer_name": {
          "quote": "My name is Alex Morgan",
          "speaker_role": "caller",
          "turn_index": 4
        },
        "appointment_date": {
          "quote": "April 23 works for me",
          "speaker_role": "caller",
          "turn_index": 7
        }
      },
      "verification": "verified",
      "field_reasons": {},
      "schema_version": "92850758e231a3c95a..."
    },
    "from_number": "+14155550199",
    "product": "bolt",
    "recording_stopped_at": null,
    "recording_stopped_reason": null,
    "recording_url": "https://storage.example.com/…",
    "start_time": "2026-04-20T18:24:10.113Z",
    "status": "completed",
    "summary": "Alex Morgan called to book a follow-up visit and confirmed Thursday, April 23. The agent read the appointment back and Alex asked for a reminder text the day before.",
    "to_number": "+15551234567",
    "transcripts": [ /* see Transcript format */ ],
    "transfer_number": null,
    "unresolved_variables": ["campaign_owner"],
    "variables": {"campaign_name": "Spring renewals"},
    "voice": "john"
  },
  "event_id": "6a7b8c9d-0e1f-4a2b-8c3d-4e5f6a7b8c9d",
  "type": "telephony.complete"
}
字段类型描述
call_idinteger在此通话的所有事件中保持不变
agent_idinteger | null处理通话的智能体(如果已分配)
agent_namestring | null处理通话的智能体(如果已分配)
directionstringinbound、outbound、web、test。历史载荷可能包含旧版值 mic 或 widget
from_number, to_numberstringE.164。对于网页通话和测试通话,from_number 为字面值 "web"
origin_domainstring仅限网页通话和测试通话——承载组件的页面源(麦克风会话中为空)
start_time, end_timetimestampISO 8601 UTC
duration_secondsinteger | null根据开始和结束时间计算
statusstringcompleted 或 failed
end_reasonstring参见下表
answered_bystring | null仅限电话外呼,包括您的拨号器标记为外呼的 SIP 通话(其他情况下不包含此字段):接听方,取值为 human、voicemail、screener(呼叫筛选系统)、ivr(电话菜单)或 unknown。无人接听时为 null;对于由您迁出平台处理的外呼,在 migration.call.complete 事件中始终为 null。取值与通话对象相同
product, voicestring通话时生效的智能体配置
variablesobject通话开始时保存的输入变量快照
unresolved_variablesarray通话配置中引用但未在通话开始时提供的变量名
transfer_numberstring | null通话转接时设置
scheduled_send_idstring仅存在于由定时发送发起的通话中:该次发送的 ID。其他通话中均不包含此字段
recording_urlstring | null通话录音的短期有效签名链接;请及时下载,也可随时从 GET /v1/calls/{call_id}/audio 获取新链接。每次重试和重新发送都会附带新签名的链接。首次投递可能在录音上传完成前几秒到达,因此如果链接返回 404,请稍后重试。如果通话录音已关闭、通话没有录音或未能及时生成链接,则为 null
recording_stopped_attimestamp | null录音在通话结束前停止的时间;此时刻之后的内容不会出现在录音中。如果录音持续到通话结束或通话未录音,则为 null
recording_stopped_reasonstring | null录音提前停止的原因。warm_transfer:录音在暖转接呼叫目标方之前停止,即使转接失败且来电者返回智能体,录音也不会恢复。其他值仅供参考;后续可能新增更多值。当 recording_stopped_at 为 null 时,此字段为 null
billable_minutesnumber计费分钟数,四舍五入到最接近的 0.25 分钟(以 15 秒为增量,最少 0.25 分钟)。直接进入语音信箱的通话仍在此报告实际计量分钟数,但费用上限为按套餐费率计算的 1 分钟费用。
billing_total_centsinteger | null单位为美分。当 billing_pending 为 true 时为 null
billing_pendingboolean仅在按量计费通话的费用尚未结算时出现,值为 true:按量计费通话在结束几分钟后、用量数据到齐时计费,因此此处的 billable_minutes 和 billing_total_cents 为 null,费用随后在 call.billed 中提供。其他通话中均不包含此字段
transcriptsarray按轮次划分的转录条目;转录不可用时可能为空
summarystring | null当智能体在设置中启用了通话摘要(智能体上的 call_summary_enabled)且摘要生成成功时,提供通话后的自然语言摘要(2 至 4 句话,最多 2,000 个字符,使用智能体的 summary_language;否则使用组织的摘要语言;再否则使用通话语言,即智能体的主要语言,除非通话覆盖了该语言)。其他情况下为 null,包括通话过短无法生成摘要、通话没有转录,以及智能体关闭了录音或通话审查的情况。摘要与数据提取在同一个通话后步骤中生成,因此发送通话结束 Webhook 前等待提取数据设置(extraction_blocks_completion)决定此事件是否等待摘要:在等待模式下,摘要在事件发送前准备就绪(在该步骤 75 秒的时间预算内,摘要本身最多可用 30 秒);当事件不等待时(never,或在 except_transfers 下发生转接或返回您的联络中心),此字段为 null,且摘要不会在 call.data_extracted 中重新发送,因此请稍后从通话对象的 summary 中读取。控制台的通话页面也提供摘要
extracted_dataobject | null包含 status、fields、evidence、verification、field_reasons 和 schema_version 的结构化提取结果。每个非空字段都包含经过结构检查的原文引述(最多 1,000 个字符),以及说话方角色和轮次索引;模型返回的较长引述会被拒绝,而不是截断。字段为 null 时,证据也为 null。verified 表示每个候选值都恰好获得了一个有效的独立判定。unavailable 也涵盖格式错误或不完整的验证器输出;有效的部分判定仍会生效,而没有一个有效判定的候选值会被置为 null。status 的值为 completed、failed、exhausted、skipped 或 skipped_recording_disabled;智能体没有提取字段时为 null
steps_tracearray仅存在于智能体具有步骤或交接的通话中。记录通话经过这些步骤或交接的顺序:每个条目包含 t_ms(自通话开始以来的毫秒数)、agent(智能体的键,由 a 加其 ID 组成)、step(步骤 ID;交接给没有步骤的智能体时为 null)和 via(start、model、condition、on_enter 或 handoff)。仅包含 ID 和时间,因此即使录音关闭也会保留
collected_valuesobject仅存在于智能体具有步骤或交接的通话中。包含智能体在步骤中收集的值,以收集字段名为键;还包含每个步骤的 on_enter_tool 结果,以 <tool>_result 为键。通话内容未保留时(录音已关闭)省略此字段

结束原因

值含义
user_hangup对方先挂断了电话
ai_hangupAI 主动结束了通话
ai_transferAI 转接了通话;已设置 transfer_number
ai_warm_transferAI 完成了咨询式转接
returned_to_platformAI 将通话返回至您的联络中心:AI 挂断了通话,如果返回条目包含标头,则将其附加在 SIP BYE 中
voicemail_hangup检测到语音信箱,并根据您的 voicemail_action 结束了通话
max_duration通话达到最大时长限制:智能体或通话自身的限制,或者平台的 6 小时限制。在时长限制警告后由 AI 或呼叫方结束的通话,仍使用 ai_hangup 或 user_hangup
superseded会话被更新的会话取代
inbound_config_webhook_failed呼入处于 webhook 模式的号码时,配置 webhook 未返回可用配置,因此通话在智能体接听前结束。status 为 failed,且通话不计费
outbound_queue_timeout排队中的通话等待了 10 分钟,仍无可用拨号容量。status 为 failed,未发起拨号,且通话不计费
outbound_queue_canceled您在排队中的通话拨出前取消了该通话。status 为 failed,且通话不计费
outbound_no_answer外呼无人接听。对于您的拨号器使用 pickup may_ring 标记为外呼的 SIP 通话:通话连接后 60 秒内无人接听,或您的拨号器先挂断了通话。answered_by 为 null
unknown无法确定结束原因

转录格式

transcripts 中的每个条目代表一个对话轮次。角色包括 user(来电者语音)、model(智能体语音以及工具调用)、 tool(工具结果)和 system(通话事件,例如语言切换)。

[
  {
    "role": "user",
    "content_type": "text/plain",
    "content": "Hi, I'm calling about my appointment.",
    "start_ms": 1200,
    "end_ms":   4100,
    "audio_url": "https://storage.example.com/…"
  },
  {
    "role": "model",
    "content_type": "text/plain",
    "content": "Sure, what date works best?",
    "start_ms": 4200,
    "end_ms":   6100
  },
  {
    "role": "model",
    "content_type": "application/json",
    "content": {
      "tool_call": "search_appointments",
      "arguments": { "date": "2026-04-21" }
    }
  },
  {
    "role": "tool",
    "content_type": "application/json",
    "content": {
      "tool_name": "search_appointments",
      "response": { "available_slots": ["9:00 AM", "2:00 PM"] }
    }
  }
]
字段类型说明
rolestringuser、model、tool 或 system
content_typestring语音使用 text/plain;工具调用、工具结果和系统事件使用 application/json
contentstring | object语音文本,或上方所示的结构化对象。工具调用:{"tool_call": name, "arguments": {…}}。工具结果:{"tool_name": name, "response": {…}}
start_ms, end_msinteger相对于通话开始的偏移量,单位为毫秒。已知音频时间时提供
ttfa_msinteger测量到时,model 轮次的首段音频响应时间
audio_url, audio_urlsstring / array按轮次录制音频时,该轮次音频的会过期签名 URL

如需获取完整的结构化轮次历史记录(包含打断标记、 确认提示和原始位置),请使用 GET /v1/calls/{call_id}/history。

旧版负载差异

旧版单 URL webhook 信封为 {"type": "telephony.complete" | "web.complete", "data": {…}},且 不包含 event_id,其 data 与端点负载不同:

旧版完成负载还包含 agent_id 和 agent_name。

  • 轮次数组位于 history 中,而非 transcripts(轮次架构与上方相同)。
  • 字段集为原始的通话结束报告,可能包含超出上表范围的其他内部字段——请将未知字段视为参考信息。
  • Web 通话(direction: "web")不包含 from_number / to_number, 并会添加 origin_domain。
  • Builder 麦克风测试通话会在旧版路径中报告为 telephony.complete (端点系统会将其映射为 web.complete)。
  • 转接协调:当通话在转接过程中结束时, 旧版 webhook 会被同步调用,并可能返回 {"transfer_ready": false},以表示转接目标尚未准备就绪。任何其他响应 (或未配置旧版 webhook)都会让转接继续进行。端点投递绝不会为此被查询。

示例处理程序

Python (FastAPI)
import hashlib
import hmac
import json
import os
 
from fastapi import FastAPI, HTTPException, Request
 
app = FastAPI()
SECRET = os.environ["THUNDERPHONE_WEBHOOK_SECRET"]
 
def verify(body: bytes, signature: str) -> bool:
    expected = hmac.new(SECRET.encode(), body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature or "")
 
@app.post("/thunderphone-webhook")
async def webhook(request: Request):
    body = await request.body()
    if not verify(body, request.headers.get("X-ThunderPhone-Signature", "")):
        raise HTTPException(status_code=401)
 
    event = json.loads(body)
    if event["type"] in ("telephony.complete", "web.complete"):
        data = event["data"]
        # Endpoint deliveries use "transcripts"; the legacy webhook uses "history".
        turns = data.get("transcripts") or data.get("history") or []
        await persist_call_record(
            call_id=data["call_id"],
            turns=turns,
            recording_url=data.get("recording_url"),
        )
        if data["end_reason"] in ("ai_transfer", "ai_warm_transfer"):
            await notify_team(data.get("transfer_number"), data["call_id"])
    return {"ok": True}
Node.js (Express)
import crypto from "node:crypto";
import express from "express";
 
const app = express();
const SECRET = process.env.THUNDERPHONE_WEBHOOK_SECRET;
 
function verify(body, signature) {
  const expected = crypto.createHmac("sha256", SECRET).update(body).digest("hex");
  return signature &&
    crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
}
 
app.post(
  "/thunderphone-webhook",
  express.raw({ type: "application/json" }),
  async (req, res) => {
    if (!verify(req.body, req.header("X-ThunderPhone-Signature"))) {
      return res.sendStatus(401);
    }
    const event = JSON.parse(req.body.toString("utf8"));
    if (["telephony.complete", "web.complete"].includes(event.type)) {
      const data = event.data;
      // Endpoint deliveries use "transcripts"; the legacy webhook uses "history".
      const turns = data.transcripts ?? data.history ?? [];
      await persistCallRecord({ ...data, turns });
      if (["ai_transfer", "ai_warm_transfer"].includes(data.end_reason)) {
        await notifyTeam(data.transfer_number, data.call_id);
      }
    }
    res.json({ ok: true });
  },
);

常见用例

CRM 集成

将每次通话的转录文本和录音 URL 与您的客户记录一并保存。

分析

将转录文本流式传输至管道,用于主题建模、CSAT 信号提取或转接率监控。

质量审查

在 QA 工具中打开通话以供人工审查,或通过您自己的评估模型进行处理。

通知

在转接或失败时通知人工团队成员。


相关内容