เริ่มต้นอย่างรวดเร็ว (API)
คู่มือนี้จะแนะนำ 4 REST call ที่จำเป็นสำหรับการรับสายโทรศัพท์สายแรกของคุณด้วย AI เอเจนต์
ขั้นตอนที่ 1: รับคีย์ API
- เข้าสู่ระบบ
- ไปที่คีย์
ไปที่ องค์กร → คีย์ ในแดชบอร์ด
- สร้างคีย์
คลิก สร้างคีย์ ตั้งชื่อ แล้วคัดลอกค่า
sk_live_...คีย์แบบเต็มจะแสดง เพียงครั้งเดียว — จัดเก็บไว้ ในตัวจัดการข้อมูลลับของคุณทันที
ตลอดคู่มือนี้ ให้แทนที่ sk_live_YOUR_API_KEY ด้วยค่าที่คุณ
เพิ่งคัดลอก คีย์จะระบุองค์กรของคุณโดยอัตโนมัติ ดังนั้น
คุณจึงไม่จำเป็นต้องใส่รหัสองค์กรใน URL
ขั้นตอนที่ 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
ในคำขอขาเข้า (ดู
ภาพรวม Webhooks)
ขั้นตอนที่ 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"