Webhook 端點

基於端點的 webhook 系統讓你可為每個組織登記多個 目的地,每個目的地均可擁有獨立的密鑰、狀態,以及訂閱的部分 事件類型。這是所有新整合建議採用的模式。

可與舊版單一 URL webhook比較, 後者為向後兼容而保留,但每個組織只支援一個 URL。

端點

方法路徑所需角色說明
GET/v1/developer/webhook-endpointsadmin+列出端點
POST/v1/developer/webhook-endpointsadmin+建立端點
PATCH/v1/developer/webhook-endpoints/{endpoint_id}admin+更新標籤/URL/事件/狀態
DELETE/v1/developer/webhook-endpoints/{endpoint_id}admin+刪除端點
POST/v1/developer/webhook-endpoints/{endpoint_id}/testadmin+傳送已簽署的測試遞送

端點物件

{
  "id": "c4d5e6f7-...",
  "label": "Production — Call events",
  "url": "https://example.com/thunderphone/hook",
  "events": ["telephony.incoming", "telephony.complete"],
  "status": "active",
  "secret_hint": "a1b2…9f0e",
  "created_at": "2026-04-20T18:24:10.113Z",
  "updated_at": "2026-04-20T18:24:10.113Z"
}
欄位類型說明
idUUID端點 id
labelstring顯示名稱,1–120 個字元
urlstringHTTPS URL;開發環境可使用 http://localhost
eventsstring 陣列已訂閱的事件類型(請參閱有效值)。空陣列會訂閱所有事件
statusstringactivedisabled(手動暫停),或 failing(遞送在 24 小時重試排程內未曾取得任何 2xx 而自動設定)
secret_hintstring簽署密鑰的首 4 個及末 4 個字元,中間以省略號分隔(a1b2…9f0e)——足以讓你對照本機儲存的密鑰,同時不會公開完整值
created_at, updated_attimestamp

有效事件類型

events 會按照以下精確集合驗證——不在清單內的值 會回傳 400。請參閱事件目錄以了解各類型的 payload 格式。

端點狀態


列出端點

curl https://api.thunderphone.com/v1/developer/webhook-endpoints \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

回傳一個端點物件陣列。


建立端點

curl -X POST https://api.thunderphone.com/v1/developer/webhook-endpoints \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "label":  "Production — Call events",
    "url":    "https://example.com/thunderphone/hook",
    "events": ["telephony.incoming", "telephony.complete"]
  }'
result = requests.post(
    "https://api.thunderphone.com/v1/developer/webhook-endpoints",
    headers={"Authorization": "Bearer sk_live_YOUR_API_KEY"},
    json={
        "label":  "Production — Call events",
        "url":    "https://example.com/thunderphone/hook",
        "events": ["telephony.incoming", "telephony.complete"],
    },
).json()
secret = result["secret"]
endpoint_id = result["id"]

請求欄位

欄位類型必填說明
label字串1–120 個字元
url字串HTTPS URL(僅 localhost / 127.0.0.1 可使用 http
events陣列留空或省略即訂閱所有事件。必須使用有效事件類型所列的值;重複項目將被移除

回傳 201 Created,包括端點物件及額外的頂層 secret 欄位,當中包含原始簽署金鑰——一個 48 字元的十六進位字串:

{
  "id": "c4d5e6f7-…",
  "label": "Production — Call events",
  "url": "https://example.com/thunderphone/hook",
  "events": ["telephony.incoming", "telephony.complete"],
  "status": "active",
  "secret_hint": "a1b2…9f0e",
  "created_at": "2026-04-20T18:24:10.113Z",
  "updated_at": "2026-04-20T18:24:10.113Z",
  "secret": "a1b2c37e08d94f5b16a2c8d90e7f3a4b5c6d7e8f90a19f0e"
}

更新端點

curl -X PATCH https://api.thunderphone.com/v1/developer/webhook-endpoints/c4d5e6f7-... \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "label":  "Production — Call + Grade events",
    "events": ["telephony.incoming", "telephony.complete", "call.graded"]
  }'
欄位類型說明
label字串
url字串
events陣列
status字串activedisabled。如要重新啟用被伺服器標記為 failing 的端點,請設定為 active

回傳 200 OK,包括已更新的端點物件


傳送測試傳遞

透過一般傳遞流程向一個端點傳送模擬 webhook.test 事件,包括標準 JSON 序列化、X-ThunderPhone-Signature、傳遞記錄及重試管理。 無論所選端點的 events 篩選條件為何,測試均會傳送至該端點。

curl -X POST https://api.thunderphone.com/v1/developer/webhook-endpoints/c4d5e6f7-.../test \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

端點會收到以下封裝資料:

{
  "data": {
    "message": "ThunderPhone webhook test",
    "sent_at": "2026-07-17T20:12:34.567890+00:00"
  },
  "event_id": "2ad6507c-7d19-4498-9b2d-7e8f944ab5a1",
  "type": "webhook.test"
}

首次嘗試後,API 會回傳 200 OK,即使目標端回傳錯誤亦然。請檢查 successstatusresponse_codeerror 以確認傳遞結果:

{
  "success": true,
  "event_id": "2ad6507c-7d19-4498-9b2d-7e8f944ab5a1",
  "event_type": "webhook.test",
  "status": "delivered",
  "response_code": 204,
  "error": ""
}

webhook.test 為模擬事件,不能加入端點的 events 訂閱。如首次嘗試失敗,傳遞會按照一般事件傳遞相同的重試排程進行。


刪除端點

curl -X DELETE https://api.thunderphone.com/v1/developer/webhook-endpoints/c4d5e6f7-... \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

回傳 204 No Content。系統會立即停止傳送至該 URL; 進行中的重試將會中止。


相關內容