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

Webhooks

telephony.incoming / web.incoming

着信通話の設定をリアルタイムで構成するブロッキングWebhook。

着信電話がエージェントに割り当てられていない番号に到達した場合、または mode="webhook" の公開可能キーでウェブウィジェットセッションが開始された場合、ThunderPhone は レガシー webhook URLブロッキング telephony.incoming / web.incoming リクエストを送信し、設定レスポンスを最大 10 秒間待機します。この やり取りを使用して、通話ごとにプロンプト、音声、ツールを動的に選択します。エンドツーエンドのパターンについては、 動的通話設定ガイドを参照してください。

このブロッキング交換にはフォールバックがありません。ハンドラーが 2xx 以外のステータスを返す、タイムアウトする、または検証に失敗する設定を返した場合、 通話は拒否されます(電話は接続されず、ウィジェットセッションリクエストは 502/422 で失敗します)。迅速に応答してください。判断中、発信者には呼び出し音が聞こえています。

リクエストペイロード

電話(telephony.incoming)の場合:

{
  "type": "telephony.incoming",
  "data": {
    "call_id":     987654321,
    "from_number": "+14155550199",
    "to_number":   "+15551234567"
  }
}
フィールド説明
call_idinteger通話 ID。この通話のすべてのイベントで一貫している
from_numberstringE.164 発信者番号
to_numberstringE.164 宛先番号(ThunderPhone 番号のいずれか)

ウェブウィジェットセッション(web.incoming)では、data は電話番号ではなく 埋め込みページを識別します。

{
  "type": "web.incoming",
  "data": {
    "call_id": 987654322,
    "origin_domain": "https://example.com",
    "publishable_key_prefix": "pk_live_a1b2"
  }
}
フィールド説明
call_idinteger通話 ID
origin_domainstringウィジェットをホストするページのオリジン
publishable_key_prefixstringセッションを開始した公開可能キーの先頭文字列
language, primary_languagestringウィジェットセッションで言語オーバーライドが指定された場合に含まれる
voicestringウィジェットセッションで音声オーバーライドが指定された場合に含まれる
website_contextstringウィジェットがセッションごとのページコンテキストを渡した場合に含まれる

レスポンススキーマ

この通話のエージェント設定を記述する JSON オブジェクトを返します。 promptvoice は必須で、それ以外はすべて任意です。

{
  "prompt":  "You are a helpful booking assistant for Acme Restaurant.",
  "voice":   "john",
  "product": "spark",
  "background_track": null,
  "tools":   []
}
フィールド必須説明
promptstringはいエージェントを動作させるシステムプロンプト
voicestringはいGET /v1/voices の音声 ID。例: johnvoice_name はエイリアスとして使用できます。不明な音声はバリデーションに失敗し、通話は拒否されます
productstringいいえデフォルトは spark。使用可能: sparkboltstorm-basestorm-base-with-ackstorm-extrastorm-extra-with-ack
thinking_levelstringいいえminimalbase(デフォルト)、または extra。Storm 製品では上書きされます。storm-extra*extra を強制し、その他の storm-*base を強制します
audio_context_modestringいいえfull(デフォルト)または reduced
watchdog_enabledbooleanいいえこの通話の監視を有効にします。デフォルトは false
additional_audio_contextboolean | nullいいえ最新ターンのみではなく、直近数ターン分の発信者音声を含めます。わずかなレイテンシーとコストの増加で、修正やスペル・数字の多いデータ収集を改善します。着信セッションではデフォルトでオン、発信通話ではオフです。null はデフォルトを維持します
storm_feedback_modestringいいえnoneacknowledgement(デフォルト)、または tick
languagestringいいえprimary_language の省略形
primary_languagestringいいえ正規化された言語コード(デフォルトは en)。解決できないコードは通話を拒否します
has_additional_languagesbooleanいいえデフォルトは false
additional_languagesarray of stringいいえエージェントが切り替え可能な追加言語
native_voice_switchingbooleanいいえデフォルトは false。通話が別の言語に切り替わった際、設定済みの音声を維持するのではなく、その言語のネイティブ音声に切り替えます(性別を一致させます)
background_trackstring | nullいいえ環境音オーディオ ID または null
acknowledgement_prompt_modestringいいえauto(デフォルト)または manual(Storm-with-ack 製品)
acknowledgement_promptstringいいえacknowledgement_prompt_mode="manual" の場合に使用します
silence_interval_secondsinteger | nullいいえ5~120。確認を行うまでの発信者の無音時間(秒)
silence_max_checkinsinteger | nullいいえ1~10
silence_checkins_enabledbooleanいいえデフォルトは true
connect_tone_enabledbooleanいいえデフォルトは false
voicemail_actionstringいいえprompt(デフォルト)、hangup、または message
voicemail_messagestringいいえvoicemail_action="message" の場合に使用します
agent_namestringいいえダッシュボードとウィジェットに表示される表示名
org_namestringいいえエージェントのペルソナに使用する組織の表示名
toolsarrayいいえインライン関数ツールスキーマ(関数ツールを参照)
call_idintegerいいえリクエストの通話 ID を任意でエコーします。無視されます

promptvoice は必須のため、{} またはバリデーションに失敗する レスポンスを返すと、通話は 422 で拒否されます。このパスでは静的エージェントへの フォールバックはありません(webhook モードの番号またはキーには、エージェントが 割り当てられていません)。


レスポンスサイズの上限


ハンドラーの例

Python (FastAPI)
import hashlib
import hmac
import json
import os
 
from fastapi import FastAPI, HTTPException, Request
 
app = FastAPI()
WEBHOOK_SECRET = os.environ["THUNDERPHONE_WEBHOOK_SECRET"]
 
def verify(body: bytes, signature: str) -> bool:
    expected = hmac.new(WEBHOOK_SECRET.encode(), body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature or "")
 
@app.post("/thunderphone-webhook")
async def webhook(request: Request):
    body = await request.body()
    if not verify(body, request.headers.get("X-ThunderPhone-Signature", "")):
        raise HTTPException(status_code=401)
 
    event = json.loads(body)
    if event["type"] == "telephony.incoming":
        caller = event["data"]["from_number"]
        prompt = (
            "Greet the caller as a San Francisco local…"
            if caller.startswith("+1415")
            else "You are a friendly customer support agent…"
        )
        return {
            "prompt": prompt,
            "voice": "john",
            "product": "spark",
        }
    if event["type"] == "web.incoming":
        return {
            "prompt": "You are the website's helpful voice assistant…",
            "voice": "john",
            "product": "spark",
        }
    return {}
Node.js (Express)
import crypto from "node:crypto";
import express from "express";
 
const app = express();
const SECRET = process.env.THUNDERPHONE_WEBHOOK_SECRET;
 
function verify(body, signature) {
  const expected = crypto
    .createHmac("sha256", SECRET)
    .update(body)
    .digest("hex");
  return signature &&
    crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
}
 
app.post(
  "/thunderphone-webhook",
  express.raw({ type: "application/json" }),
  (req, res) => {
    if (!verify(req.body, req.header("X-ThunderPhone-Signature"))) {
      return res.sendStatus(401);
    }
    const event = JSON.parse(req.body.toString("utf8"));
 
    if (event.type === "telephony.incoming" || event.type === "web.incoming") {
      const caller = event.data.from_number || "web";
      const prompt = caller.startsWith("+1415")
        ? "Greet the caller as a San Francisco local…"
        : "You are a friendly customer support agent…";
      return res.json({
        prompt,
        voice: "john",
        product: "spark",
      });
    }
    res.json({});
  },
);

関数ツールを含むレスポンス

AI が会話中に API を呼び出せるよう、ツールを追加します。

{
  "prompt":  "You are a booking assistant. Use the available tools to help customers schedule appointments.",
  "voice":   "john",
  "product": "spark",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "search_appointments",
        "description": "Find available appointment slots",
        "parameters": {
          "type": "object",
          "properties": {
            "date": { "type": "string", "description": "YYYY-MM-DD" },
            "service": { "type": "string" }
          },
          "required": ["date"]
        }
      },
      "endpoint": {
        "url": "https://api.example.com/appointments/search",
        "method": "POST",
        "headers": {
          "X-Api-Key": "your-key"
        }
      }
    }
  ]
}

製品ティア早見表

製品レイテンシ推論応答
spark最小基本
bolt改善済み
storm-base高度
storm-base-with-ack高度推論中に自動フィラー
storm-extra深い
storm-extra-with-ack深い推論中に自動フィラー

関連