telephony.complete / web.complete
通话结束时发送的非阻塞 webhook,包含转录文本、录音 URL 和指标。
每次通话结束后都会触发完成事件——包括呼入电话、 呼出电话、网页通话或测试通话(构建器麦克风会话)。该事件为 非阻塞式:请返回任意 2xx 响应。
事件会通过以下两种路径发送:
- **Webhook 端点**会接收
telephony.complete(电话通话)或web.complete(网页通话和 构建器麦克风测试通话),其中包含下文记录的稳定载荷、 每次投递对应的event_id、30 秒超时,以及 最长 24 小时的重试。 - 旧版单 URL webhook 会收到一次同步尝试(10 秒超时,不重试),其载荷略有不同——请参阅 旧版载荷差异。
请求载荷(端点投递)
{
"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",
"from_number": "+14155550199",
"product": "spark",
"recording_url": "https://storage.example.com/…",
"start_time": "2026-04-20T18:24:10.113Z",
"status": "completed",
"to_number": "+15551234567",
"transcripts": [ /* see Transcript format */ ],
"transfer_number": null,
"voice": "john"
},
"event_id": "6a7b8c9d-0e1f-4a2b-8c3d-4e5f6a7b8c9d",
"type": "telephony.complete"
}| 字段 | 类型 | 说明 |
|---|---|---|
call_id | integer | 在该通话的所有事件中保持不变 |
direction | string | inbound、outbound、web、test。历史载荷可能包含旧版 mic 或 widget 值 |
from_number, to_number | string | E.164。对于网页通话和测试通话,from_number 的字面值为 "web" |
origin_domain | string | 仅网页/测试通话——托管小组件的页面来源(麦克风会话为空) |
start_time, end_time | timestamp | ISO 8601 UTC |
duration_seconds | integer | null | 根据开始时间和结束时间计算 |
status | string | completed 或 failed |
end_reason | string | 请参阅下表 |
product, voice | string | 通话时生效的智能体配置 |
transfer_number | string | null | 通话转接时设置 |
recording_url | string | null | 会过期的签名 URL;请及时下载。没有可用录音文件时为 null |
billable_minutes | number | 计费分钟数,按最接近的四分之一分钟取整(每 15 秒递增,最低 0.25)。直接转入语音信箱的通话仍会在此报告其实际计量分钟数,但费用将按套餐费率封顶为一分钟。 |
billing_total_cents | integer | 美元美分 |
transcripts | array | 每轮的转录条目;无法提供转录时可能为空 |
结束原因
| 值 | 含义 |
|---|---|
user_hangup | 对方先挂断了通话 |
ai_hangup | AI 主动结束了通话 |
ai_transfer | AI 转接了通话;已设置 transfer_number |
ai_warm_transfer | AI 完成了暖转接(咨询式转接) |
voicemail_hangup | 检测到语音信箱,并根据您的 voicemail_action 结束了通话 |
max_duration | 通话达到最大时长限制 |
superseded | 会话已被较新的会话替代 |
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"] }
}
}
]| 字段 | 类型 | 说明 |
|---|---|---|
role | string | user、model、tool 或 system |
content_type | string | 语音使用 text/plain;工具调用、工具结果和系统事件使用 application/json |
content | string | object | 语音文本,或上方所示的结构化对象。工具调用:{"tool_call": name, "arguments": {…}}。工具结果:{"tool_name": name, "response": {…}} |
start_ms、end_ms | integer | 相对于通话开始的偏移量,单位为毫秒。已知音频时间时提供 |
ttfa_ms | integer | 测得时,model 轮次的首段音频响应时间 |
audio_url、audio_urls | string / array | 按轮次录制时,该轮次音频的会过期签名 URL |
如需获取完整的结构化轮次历史记录(包括中断标记、
确认提示和原始位置),请使用
GET /v1/calls/{call_id}/history。
旧版载荷差异
旧版单 URL webhook 信封为
{"type": "telephony.complete" | "web.complete", "data": {…}},其中
不包含 event_id,其 data 与端点载荷不同:
- 轮次数组位于
history下,而非transcripts(轮次架构与上方相同)。 - 字段集合为原始通话结束报告,可能包含超出上表范围的额外内部字段——请将未知字段视为信息性内容。
- Web 通话(
direction: "web")省略from_number/to_number, 并添加origin_domain。 - Builder 麦克风测试通话在旧版路径中报告为
telephony.complete(端点系统会将其映射为web.complete)。 - 转接协调:当通话在转接中结束时,旧版 webhook 会被同步调用,并可能返回
{"transfer_ready": false},以表示交接目标尚未准备就绪。任何其他响应(或没有旧版 webhook)都会让转接继续进行。端点投递绝不会因此被查询。
示例处理程序
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}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 工具中打开通话以供人工审核,或通过您自己的评估模型运行评估。
通知
在转接或失败时通知人工团队成员。