View as Markdown
Open in
telephony.complete / web.complete
通話結束時傳送的非阻塞 Webhook,包含逐字稿、錄音 URL 及指標。
每次通話結束後,都會觸發完成事件——包括來電電話通話、外撥電話通話、網頁通話或測試通話(Builder 咪高峰工作階段)。這是非阻塞事件:以任何 2xx 回應即可。
事件會透過以下兩種途徑傳送:
- **Webhook 端點**會接收
telephony.complete(電話通話)或web.complete(網頁通話及 Builder 咪高峰測試通話),當中包括下文記錄的穩定 payload、每次傳送專屬的event_id、30 秒逾時設定,以及最長 24 小時的重試機制。 - **舊版單一 URL webhook**會進行一次同步嘗試(10 秒逾時,不設重試),其 payload 略有不同——請參閱舊版 payload 差異。
請求負載(端點傳送)
{
"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": "spark",
"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_id | integer | 此通話的所有事件中保持不變 |
agent_id | integer | null | 處理通話的智能體(如已指派) |
agent_name | string | null | 處理通話的智能體(如已指派) |
direction | string | inbound、outbound、web、test。歷史 payload 可能包含舊版 mic 或 widget 值 |
from_number, to_number | string | E.164。網頁通話及測試通話的 from_number 為字面值 "web" |
origin_domain | string | 僅限 Web/test——載入 widget 的頁面來源(mic 工作階段為空) |
start_time, end_time | timestamp | ISO 8601 UTC |
duration_seconds | integer | null | 根據開始/結束時間計算 |
status | string | completed 或 failed |
end_reason | string | 請參閱下表 |
answered_by | string | null | 僅限撥出電話(其他情況不提供):接聽者,human、voicemail、screener(來電篩選助理)、ivr(電話選單)或 unknown。無人接聽時為 null;對於由你正遷移離開的平台處理的撥出電話,在 migration.call.complete 事件中則一律為 null。與通話物件使用相同值 |
product, voice | string | 通話時生效的智能體設定 |
variables | object | 通話開始時建立快照的輸入變數 |
unresolved_variables | array | 通話設定所引用、但在通話開始時未提供的變數名稱 |
transfer_number | string | null | 通話已轉接時設定 |
scheduled_send_id | string | 僅適用於由排程發送撥出的通話:該發送的 ID。其他所有通話均不提供 |
recording_url | string | null | 會過期的簽署 URL;請及時下載。沒有可用錄音檔案時為 null |
recording_stopped_at | timestamp | null | 錄音在通話結束前停止的時間;此時間後的內容不會包含在錄音中。錄音持續至通話結束,或通話未錄音時為 null |
recording_stopped_reason | string | null | 錄音提早停止的原因。warm_transfer:在暖轉接撥打目的地前停止錄音;即使轉接失敗且來電者返回智能體,錄音仍會維持關閉。其他值僅供參考;日後可能新增更多值。recording_stopped_at 為 null 時,此值為 null |
billable_minutes | number | 計費分鐘,四捨五入至最接近的四分一分鐘(每 15 秒遞增,最低 0.25)。直接轉駁至留言信箱的通話仍會在此報告實際計量分鐘,但收費上限為按方案費率計算的一分鐘。 |
billing_total_cents | integer | null | 美元仙。billing_pending 為 true 時,此值為 null |
billing_pending | boolean | 僅會在尚未結算費用的按用量計費通話中以 true 提供:按用量計費通話會在結束數分鐘後、使用量資料送達後收費,因此此處的 billable_minutes 及 billing_total_cents 為 null,費用會在 call.billed 中送達。其他所有通話均不提供 |
transcripts | array | 每輪對話的逐字稿項目;逐字稿不可用時可為空 |
summary | string | null | 智能體建立工具中 收集資料 下的 產生通話摘要 已啟用(Agent 上的 call_summary_enabled),且產生成功時提供的淺白易懂通話後摘要(兩至四句文字,最多 2,000 個字元,以智能體的 summary_language 撰寫;否則使用組織的摘要語言;再否則使用通話語言:除非通話覆寫,否則為智能體的主要語言);其他情況為 null,包括通話過短而無法摘要、沒有逐字稿的通話,以及已關閉錄音的智能體。摘要與資料擷取在同一個通話後步驟中產生,因此 傳送通話完成 webhook 前等待擷取資料 設定(extraction_blocks_completion)決定此事件是否等待摘要:在等待模式下,摘要會在傳送此事件前準備完成(摘要本身在該步驟的 75 秒預算內最多可使用 30 秒);當事件不等待時(never,或在 except_transfers 下進行轉接或返回你的聯絡中心),此欄位為 null,而摘要不會在 call.data_extracted 中重新傳送,因此請稍後從通話物件的 summary 讀取。控制台的通話頁面亦提供此資料 |
extracted_data | object | null | 結構化擷取結果,包含 status、fields、evidence、verification、field_reasons 及 schema_version。每個非 null 欄位均包含經精確結構檢查的原文引述(最多 1,000 個字元)、其發言者角色及對話輪次索引;模型返回的較長引述會被拒絕,而非截斷。欄位為 null 時,證據為 null。verified 表示每個候選值均獲得剛好一個有效的獨立判定。unavailable 亦涵蓋格式錯誤或不完整的驗證器輸出;有效的不完整判定仍會套用,而沒有任何有效判定的候選值會設為 null。status 為 completed、failed、exhausted、skipped 或 skipped_recording_disabled;智能體沒有擷取欄位時為 null |
steps_trace | array | 僅適用於智能體設有步驟或交接的通話。通話經過這些項目的順序:每個項目包含 t_ms(通話開始後的毫秒數)、agent(智能體的索引鍵,即 a 加上其 ID)、step(步驟 ID;若交接至沒有步驟的智能體則為 null)及 via(start、model、condition、on_enter 或 handoff)。僅保留 ID 及時間,因此即使錄音已關閉亦會保留 |
collected_values | object | 僅適用於智能體設有步驟或交接的通話。智能體在其步驟中收集的值,以收集欄位名稱作為索引鍵,另加上每個步驟的 on_enter_tool 結果對應的 <tool>_result。通話內容未被保留時不提供(錄音已關閉) |
結束原因
| 值 | 含義 |
|---|---|
user_hangup | 遠端通話方先掛線 |
ai_hangup | AI 主動結束通話 |
ai_transfer | AI 轉駁通話;已設定 transfer_number |
ai_warm_transfer | AI 已完成暖轉駁(有人接聽的轉駁) |
returned_to_platform | 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,且通話不會收費 |
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 | 字串 | user、model、tool 或 system |
content_type | 字串 | 語音使用 text/plain;工具呼叫、工具結果及系統事件使用 application/json |
content | 字串 | 物件 | 語音文字,或上方所示的結構化物件。工具呼叫:{"tool_call": name, "arguments": {…}}。工具結果:{"tool_name": name, "response": {…}} |
start_ms、end_ms | 整數 | 相對通話開始時間的偏移量,單位為毫秒。已知音訊時間時提供 |
ttfa_ms | 整數 | 已量度時,model 回合的首段音訊時間 |
audio_url、audio_urls | 字串/陣列 | 如按回合錄音,則提供該回合音訊的有時限簽署網址 |
如需完整的結構化回合記錄(包括中斷標記、
確認提示及原始位置),請使用
GET /v1/calls/{call_id}/history。
舊版負載差異
舊版單一網址 webhook 封裝格式為
{"type": "telephony.complete" | "web.complete", "data": {…}},當中
不包含 event_id,而其 data 與端點負載不同:
舊版完成負載亦會包含 agent_id 及 agent_name。
- 回合陣列位於
history,而非transcripts(回合結構與上方相同)。 - 欄位集合為原始通話結束報告,可能包含上表以外的額外內部欄位——未知欄位應視為資訊用途。
- 網頁通話(
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 工具中開啟通話供人手審核,或使用你自己的評估模型處理。
通知
於轉接/失敗時通知團隊成員。