ThunderPhone 2.0、提供開始。セルフサービスで、1分あたり2¢から。発表内容を見る

Getting Started

クイックスタート(API)

AIエージェントで最初の電話に応答します。APIキーの取得、エージェントの作成、電話番号のプロビジョニング、ライブテスト通話の発信を、すべてREST APIで行えます。

このガイドでは、AIエージェントで最初の電話に応答するために必要な4つのREST呼び出しを説明します。

ステップ1: APIキーを取得する

  1. ログイン

    app.thunderphone.comを開きます。

  2. キーに移動

    ダッシュボードで組織 → キーに移動します。

  3. キーを作成

    キーを作成をクリックし、名前を付けて sk_live_...の値をコピーします。キーの生の値は一度だけ表示されるため、すぐに シークレットマネージャーに保存してください。

このガイド全体で、sk_live_YOUR_API_KEYを先ほどコピーした値に置き換えます。 キーによって組織が自動的に識別されるため、URLに組織IDを含める必要はありません。

ステップ2: エージェントを作成する

エージェントでは、AIが会話をどのように処理するかを定義します。プロンプト、音声、 製品ティア、ツール、ウィジェットの利用可否を設定します。

cURL
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"
  }'
Python
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"])
Node.js
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 接続 を参照してください。

cURL
# 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}'
Python
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 ヘッダーを検証します(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"

次のステップ