ThunderPhone 2.0 正式上線。全程自助,每分鐘 2 美分起查看公告

Developer cookbook

處理來電(API)

端到端流程:設定智慧體、將其指派給電話號碼、接聽來電,並檢視逐字稿。

透過終端機完成標準的「使用 AI 接聽電話」流程。 你將會:

  1. 建立具備提示詞與語音的智慧體。
  2. 佈建(或自備)電話號碼,並將智慧體指派為其入站處理者。
  3. 撥打該號碼,查看通話紀錄、逐字稿與錄音。

API 呼叫總數:四次。總時間:不到五分鐘。

1. 建立智慧體

智慧體會整合用於處理通話的提示詞、語音與產品方案。請參閱 智慧體以了解所有設定欄位;最低需求如下:

curl -X POST https://api.thunderphone.com/v1/agents \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name":    "Acme Support",
    "prompt":  "You are a friendly support agent for Acme. Help callers with orders and returns. Keep answers short.",
    "voice":   "john",
    "product": "spark"
  }'

儲存回傳的 id——你會在步驟 2 用到它。

2. 取得電話號碼

若你只需要一個可供撥打的號碼,請從 ThunderPhone 的號碼池佈建示範號碼:

curl -X POST https://api.thunderphone.com/v1/phone-numbers \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"area_code": "415"}'

回應會包含 E.164 格式的 idnumber。示範號碼起始狀態為 status="provisioning",並會在幾秒內變為 active——如有需要,可輪詢 GET /v1/phone-numbers/{id} 查看狀態轉換。

3. 指派智慧體

將步驟 1 的智慧體與號碼的入站方向建立關聯:

curl -X PATCH https://api.thunderphone.com/v1/phone-numbers/{phone_id} \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"inbound_agent_id": 12}'

完成——該號碼已啟用。你也可以在同一個 PATCH 中設定 outbound_agent_id, 讓該號碼也能用於撥出電話。

4. 接聽來電

使用你的電話撥打該號碼。智慧體會接聽、依照你的提示詞自我介紹, 然後開始對話。

通話進行期間,會在 GET /v1/calls中顯示,狀態為 status="in_progress"。通話結束後,紀錄會更新 end_reasonduration_secondsbillable_minutes,以及(最終)錄音 URL 與 AI 評分。

5. 檢查結果

擷取最近通話清單:

curl 'https://api.thunderphone.com/v1/calls?limit=5' \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

取得逐字稿:

curl https://api.thunderphone.com/v1/calls/{call_id}/transcript \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

以及錄音 URL(短期有效,已簽署):

curl https://api.thunderphone.com/v1/calls/{call_id}/audio \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

若你已訂閱 telephony.complete webhook, 你會收到以 POST 傳送至伺服器的相同資料——請參閱 call.complete


後續步驟