Open in
クイックスタート(API)
AIエージェントで最初の電話に応答します。APIキーを取得し、エージェントを作成し、電話番号をプロビジョニングして、REST APIだけでライブテスト通話を発信します。
このガイドでは、AIエージェントで最初の電話に応答するまでに必要な4回のREST呼び出しを説明します。
ステップ1: APIキーを取得する
- ログイン
app.thunderphone.comを開きます。
- キーに移動
ダッシュボードで組織 → キーに移動します。
- キーを作成
キーを作成をクリックし、名前を付けて
sk_live_...の値をコピーします。生のキーが表示されるのは一度だけです。すぐに シークレットマネージャーに保存してください。
このガイド全体で、sk_live_YOUR_API_KEYをコピーした値に置き換えます。キーは組織を自動的に識別するため、URLに組織IDを指定する必要はありません。
ステップ2: エージェントを作成する
エージェントは、AIが会話を処理する方法を定義します。これにはプロンプト、音声、製品ティア、ツール、ウィジェットの利用可否が含まれます。
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"