telephony.incoming / web.incoming
เมื่อสายโทรศัพท์ขาเข้ามาถึงหมายเลขที่ยังไม่ได้กำหนด
เอเจนต์ หรือเมื่อเซสชันวิดเจ็ตเว็บเริ่มต้นด้วย publishable key ใน
mode="webhook" ThunderPhone จะส่งคำขอ telephony.incoming /
web.incoming แบบบล็อกการทำงานไปยัง
URL webhook เดิม
ของคุณ และรอการตอบกลับการกำหนดค่าสูงสุด 10 วินาที ใช้การแลกเปลี่ยนนี้เพื่อเลือกพรอมป์ต์ เสียง และเครื่องมือแบบไดนามิกสำหรับแต่ละสาย —
ดูรูปแบบการทำงานแบบครบวงจรได้ที่
คู่มือการกำหนดค่าสายแบบไดนามิก
การแลกเปลี่ยนแบบบล็อกการทำงานไม่มีทางเลือกสำรอง: หากตัวจัดการของคุณส่งคืนสถานะ
ที่ไม่ใช่ 2xx หมดเวลา หรือส่งคืนการกำหนดค่าที่ไม่ผ่านการตรวจสอบ
สายจะถูกปฏิเสธ (สายโทรศัพท์จะไม่เชื่อมต่อ ส่วนคำขอเซสชันวิดเจ็ต
จะล้มเหลวด้วย 502/422) ตอบกลับให้รวดเร็ว — ผู้โทรจะได้ยินเสียงเรียกเข้าระหว่างที่คุณตัดสินใจ
เพย์โหลดคำขอ
สำหรับสายโทรศัพท์ (telephony.incoming):
{
"type": "telephony.incoming",
"data": {
"call_id": 987654321,
"from_number": "+14155550199",
"to_number": "+15551234567"
}
}
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
call_id | integer | รหัสสาย — คงที่ตลอดทุกเหตุการณ์ของสายนี้ |
from_number | string | หมายเลขผู้โทรรูปแบบ E.164 |
to_number | string | ปลายทางรูปแบบ E.164 (หนึ่งในหมายเลข ThunderPhone ของคุณ) |
สำหรับเซสชันวิดเจ็ตเว็บ (web.incoming) data จะระบุหน้าที่ฝังวิดเจ็ต
แทนหมายเลขโทรศัพท์:
{
"type": "web.incoming",
"data": {
"call_id": 987654322,
"origin_domain": "https://example.com",
"publishable_key_prefix": "pk_live_a1b2"
}
}
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
call_id | integer | รหัสสาย |
origin_domain | string | ต้นทางของหน้าที่โฮสต์วิดเจ็ต |
publishable_key_prefix | string | อักขระแรกของ publishable key ที่เปิดเซสชัน |
language, primary_language | string | มีอยู่เมื่อเซสชันวิดเจ็ตขอแทนที่ภาษาที่ใช้ |
voice | string | มีอยู่เมื่อเซสชันวิดเจ็ตขอแทนที่เสียงที่ใช้ |
website_context | string | มีอยู่เมื่อวิดเจ็ตส่งบริบทหน้าสำหรับแต่ละเซสชัน |
สคีมาการตอบกลับ
ส่งคืนออบเจ็กต์ JSON ที่อธิบายการกำหนดค่าเอเจนต์สำหรับสายนี้
ต้องระบุ prompt และ voice; ส่วนอื่นทั้งหมดเป็นตัวเลือก
{
"prompt": "You are a helpful booking assistant for Acme Restaurant.",
"voice": "john",
"product": "spark",
"background_track": null,
"tools": []
}
| ฟิลด์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
prompt | string | ใช่ | พรอมป์ตระบบที่ขับเคลื่อนเอเจนต์ |
voice | string | ใช่ | รหัสเสียงจาก GET /v1/voices เช่น john ยอมรับ voice_name เป็นชื่อแทน เสียงที่ไม่รู้จักจะไม่ผ่านการตรวจสอบและปฏิเสธสาย |
product | string | ไม่ | ค่าเริ่มต้นคือ spark อนุญาต: spark, bolt, storm-base, storm-base-with-ack, storm-extra, storm-extra-with-ack |
thinking_level | string | ไม่ | minimal, base (ค่าเริ่มต้น) หรือ extra ถูกแทนที่สำหรับผลิตภัณฑ์ Storm: storm-extra* บังคับใช้ extra ส่วน storm-* อื่นบังคับใช้ base |
audio_context_mode | string | ไม่ | full (ค่าเริ่มต้น) หรือ reduced |
watchdog_enabled | boolean | ไม่ | เปิดใช้การกำกับดูแลสำหรับสายนี้ ค่าเริ่มต้นคือ false |
storm_feedback_mode | string | ไม่ | none, acknowledgement (ค่าเริ่มต้น) หรือ tick |
language | string | ไม่ | ชื่อย่อสำหรับ primary_language |
primary_language | string | ไม่ | รหัสภาษาแบบปรับมาตรฐานแล้ว (ค่าเริ่มต้น en) รหัสที่ไม่สามารถแก้ไขได้จะปฏิเสธสาย |
has_additional_languages | boolean | ไม่ | ค่าเริ่มต้นคือ false |
additional_languages | array of string | ไม่ | ภาษาเพิ่มเติมที่เอเจนต์สามารถสลับไปใช้ได้ |
background_track | string | null | ไม่ | รหัสเสียงบรรยากาศหรือ null |
acknowledgement_prompt_mode | string | ไม่ | auto (ค่าเริ่มต้น) หรือ manual (ผลิตภัณฑ์ Storm-with-ack) |
acknowledgement_prompt | string | ไม่ | ใช้เมื่อ acknowledgement_prompt_mode="manual" |
silence_interval_seconds | integer | null | ไม่ | 5–120 จำนวนวินาทีที่ผู้โทรเงียบก่อนการตรวจสอบสถานะ |
silence_max_checkins | integer | null | ไม่ | 1–10 |
silence_checkins_enabled | boolean | ไม่ | ค่าเริ่มต้นคือ true |
connect_tone_enabled | boolean | ไม่ | ค่าเริ่มต้นคือ false |
voicemail_action | string | ไม่ | prompt (ค่าเริ่มต้น), hangup หรือ message |
voicemail_message | string | ไม่ | ใช้เมื่อ voicemail_action="message" |
agent_name | string | ไม่ | ชื่อที่แสดงซึ่งรายงานไปยังแดชบอร์ดและวิดเจ็ต |
org_name | string | ไม่ | ชื่อที่แสดงขององค์กรสำหรับบุคลิกของเอเจนต์ |
tools | array | ไม่ | สคีมาเครื่องมือฟังก์ชันแบบอินไลน์ (ดู เครื่องมือฟังก์ชัน) |
call_id | integer | ไม่ | การส่งกลับรหัสสายจากคำขอแบบเลือกใช้ จะถูกละเว้น |
เนื่องจากต้องระบุ prompt และ voice การส่งคืน {} หรือการตอบกลับใดก็ตาม
ที่ไม่ผ่านการตรวจสอบจะปฏิเสธสายด้วย 422 — เส้นทางนี้ไม่มีเอเจนต์แบบคงที่เป็นทางเลือกสำรอง
(หมายเลขหรือคีย์ในโหมด webhook ไม่มีเอเจนต์ที่กำหนดไว้)
ขีดจำกัดขนาดการตอบกลับ
ตัวอย่างตัวจัดการ
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 {}
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 | สูงกว่า | เชิงลึก | เสียงเติมอัตโนมัติระหว่างคิด |