View as Markdown
Open in
快速入門(API)
透過 REST API 讓你的第一通來電由人工智慧語音智慧體接聽:取得 API 金鑰、建立智慧體、佈建電話號碼,並撥打即時測試通話。
本指南將帶你完成接聽第一通由人工智慧智慧體處理的電話所需的四個 REST 呼叫。
步驟 1:取得 API 金鑰
- 登入
- 前往金鑰
在控制台中前往 組織 → 金鑰。
- 建立金鑰
點擊 建立金鑰,為金鑰命名,然後複製
sk_live_...值。原始金鑰只會顯示一次——請立即將其儲存至 你的密鑰管理工具。
在本指南中,請將 sk_live_YOUR_API_KEY 替換為你剛複製的值。
金鑰會自動識別你的組織,因此你無需在 URL 中加入組織 ID。
步驟 2:建立智慧體
智慧體會定義人工智慧如何處理對話——提示詞、語音、 產品層級、工具,以及 Widget 使用資格。
curl -X POST https://api.thunderphone.com/v1/agents \
-H "Authorization: Bearer sk_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Customer Support",
"prompt": "You are a friendly support agent for Acme Corp. Help with orders, returns, and product info. Be concise and helpful.",
"voice": "john",
"product": "spark"
}'import os, requests
agent = requests.post(
"https://api.thunderphone.com/v1/agents",
headers={"Authorization": f"Bearer {os.environ['THUNDERPHONE_API_KEY']}"},
json={
"name": "Customer Support",
"prompt": "You are a friendly support agent for Acme Corp. Help with orders, returns, and product info. Be concise and helpful.",
"voice": "john",
"product": "spark",
},
).json()
print("Agent id:", agent["id"])const agent = await fetch("https://api.thunderphone.com/v1/agents", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.THUNDERPHONE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "Customer Support",
prompt: "You are a friendly support agent for Acme Corp. Help with orders, returns, and product info. Be concise and helpful.",
voice: "john",
product: "spark",
}),
}).then((r) => r.json());
console.log("Agent id:", agent.id);步驟 3:佈建電話號碼
此呼叫會向 ThunderPhone 要求一組號碼,並將你新建立的 智慧體指派為來電處理程式。(若要從 VoIP 供應商自備號碼,請改參閱 VoIP 連線。)
# First provision
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"}'
# Then assign the agent you created in Step 2
curl -X PATCH https://api.thunderphone.com/v1/phone-numbers/<id-from-previous> \
-H "Authorization: Bearer sk_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"inbound_agent_id": 12}'number = requests.post(
"https://api.thunderphone.com/v1/phone-numbers",
headers={"Authorization": f"Bearer {os.environ['THUNDERPHONE_API_KEY']}"},
json={"area_code": "415"},
).json()
requests.patch(
f"https://api.thunderphone.com/v1/phone-numbers/{number['id']}",
headers={"Authorization": f"Bearer {os.environ['THUNDERPHONE_API_KEY']}"},
json={"inbound_agent_id": agent["id"]},
)
print("Your ThunderPhone number:", number["number"])你的新號碼初始狀態為 status="provisioning",並會在幾秒內轉為
active;當你關閉瀏覽器時,該號碼便已可接聽來電。
步驟 4(選用):設定 webhook
如需即時事件(動態通話路由、通話後處理),請新增 webhook 端點。只訂閱你需要的事件。
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": "Prod webhook",
"url": "https://your-server.com/thunderphone-webhook",
"events": ["telephony.incoming", "telephony.complete"]
}'回應包含一次性的 secret ——將它複製到你的密鑰管理工具。使用該密鑰驗證傳入請求中的 X-ThunderPhone-Signature-V2
標頭(請參閱
Webhook 概覽)。
步驟 5:測試你的智慧體
撥打你剛佈建的號碼。智慧體會接聽、自我介紹, 並依照你的提示執行。
通話結束後檢查通話內容:
curl https://api.thunderphone.com/v1/calls \
-H "Authorization: Bearer sk_live_YOUR_API_KEY"深入查看特定通話,以取得逐字稿和錄音 URL:
curl https://api.thunderphone.com/v1/calls/{call_id}/transcript \
-H "Authorization: Bearer sk_live_YOUR_API_KEY"
curl https://api.thunderphone.com/v1/calls/{call_id}/audio \
-H "Authorization: Bearer sk_live_YOUR_API_KEY"