处理呼入电话(API)
端到端流程:配置智能体,将其分配给电话号码,接听来电并查看转录文本。
从您的终端完成标准的“让 AI 接听电话”流程。 您将:
- 使用提示词和语音创建智能体。
- 配置(或自带)电话号码,并将该智能体指定为其 呼入处理程序。
- 拨打该号码。查看通话日志、转录文本和录音。
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"}'响应包含一个 id 和采用 E.164 格式的 number。演示号码
初始状态为 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_reason、duration_seconds、billable_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。