telephony.complete / web.complete

每次通話結束後,都會觸發一個完成事件——包括來電電話、撥出電話、網頁通話或測試通話(Builder 咪高峰工作階段)。此事件為非阻塞:請以任何 2xx 回應。

事件會透過以下兩種途徑傳送:

請求 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",
    "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_idinteger此通話的所有事件均使用相同的穩定 ID
directionstringinboundoutboundwebtest。舊有 payload 可能包含舊版 micwidget
from_number, to_numberstringE.164。網頁通話及測試通話的 from_number 固定為 "web"
origin_domainstring僅限網頁/測試——承載 widget 的頁面來源(咪高峰工作階段為空白)
start_time, end_timetimestampISO 8601 UTC
duration_secondsinteger | null根據開始/結束時間計算
statusstringcompletedfailed
end_reasonstring請參閱下表
product, voicestring通話時生效的智能體設定
transfer_numberstring | null通話被轉接時設定
recording_urlstring | null會過期的簽署 URL;請盡快下載。沒有可用錄音檔案時為 null
billable_minutesnumber計費分鐘,四捨五入至最接近的四分一分鐘(每 15 秒為一個增量,最低 0.25)。直接轉入語音信箱的通話仍會在此報告實際計量分鐘,但按方案費率計算的收費上限為一分鐘。
billing_total_centsinteger美元美仙
transcriptsarray每輪對話的逐字稿項目;逐字稿不可用時可以為空

結束原因

含義
user_hangup遠端一方先掛線
ai_hangupAI 主動結束通話
ai_transferAI 轉接通話;已設定 transfer_number
ai_warm_transferAI 已完成暖轉接(有人接聽的轉接)
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"] }
    }
  }
]
欄位類型說明
rolestringusermodeltoolsystem
content_typestring語音使用 text/plain;工具呼叫、工具結果及系統事件使用 application/json
contentstring | object語音文字,或上述顯示的結構化物件。工具呼叫:{"tool_call": name, "arguments": {…}}。工具結果:{"tool_name": name, "response": {…}}
start_msend_msinteger相對於通話開始時間的偏移量,單位為 ms。已知音訊時間時會提供
ttfa_msinteger已量度時,model 輪次的首段音訊時間
audio_urlaudio_urlsstring / array如按輪次錄音,則為該輪次音訊的限時簽署 URL

如需完整結構化的輪次記錄(包括中斷標記、 確認提示及原始位置),請使用 GET /v1/calls/{call_id}/history

舊版負載差異

舊版單一 URL webhook 封裝為 {"type": "telephony.complete" | "web.complete", "data": {…}},且 不設 event_id;其 data 與端點負載有所不同:


範例處理程式

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 整合

將每通電話的逐字稿及錄音網址,連同你的客戶記錄一併儲存。

分析

將逐字稿串流至處理流程,以進行主題建模、擷取 CSAT 訊號或監察轉接率。

品質審核

在 QA 工具中開啟通話供人手審核,或透過你自訂的評估模型進行分析。

通知

於轉接/失敗時通知團隊成員。


相關內容