ThunderPhone 2.0 đã chính thức ra mắt.Tự thiết lập, từ 2 xu/phút.Xem thông báo ra mắt

Getting Started

Bắt đầu nhanh (API)

Trả lời cuộc gọi điện thoại đầu tiên bằng tác nhân AI: lấy khóa API, tạo tác nhân, cấp số điện thoại và thực hiện cuộc gọi thử trực tiếp — tất cả thông qua REST API.

Hướng dẫn này đưa bạn qua bốn lệnh gọi REST cần thiết để trả lời cuộc gọi điện đầu tiên bằng tác nhân AI.

Bước 1: Lấy khóa API

  1. Đăng nhập
  2. Đi đến Khóa

    Vào Tổ chức → Khóa trên dashboard.

  3. Tạo khóa

    Nhấp vào Tạo khóa, đặt tên cho khóa rồi sao chép giá trị sk_live_.... Khóa thô chỉ hiển thị một lần duy nhất — hãy lưu ngay vào trình quản lý bí mật của bạn.

Trong suốt hướng dẫn này, hãy thay sk_live_YOUR_API_KEY bằng giá trị bạn vừa sao chép. Khóa tự động xác định tổ chức của bạn, vì vậy bạn không cần đưa mã tổ chức vào URL.

Bước 2: Tạo tác nhân

Tác nhân xác định cách AI xử lý cuộc hội thoại — prompt, giọng nói, gói sản phẩm, công cụ và điều kiện đủ để dùng widget.

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);

Bước 3: Cấp một số điện thoại

Lệnh gọi này yêu cầu nhóm số demo của ThunderPhone cấp một số và gán tác nhân AI mới của bạn làm bộ xử lý cuộc gọi đến. (Để dùng số điện thoại riêng của bạn từ nhà cung cấp VoIP, hãy xem kết nối VoIP thay vào đó.)

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"])

Số mới của bạn bắt đầu với status="provisioning" và chuyển sang active trong vài giây; khi bạn đóng trình duyệt, số đã sẵn sàng nhận cuộc gọi.

Bước 4 (tùy chọn): Thiết lập webhook

Để nhận sự kiện theo thời gian thực (định tuyến cuộc gọi động, xử lý sau cuộc gọi), hãy thêm một endpoint webhook. Chỉ đăng ký các sự kiện bạn cần.

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"]
  }'

Phản hồi chứa secret dùng một lần — hãy sao chép nó vào trình quản lý bí mật của bạn. Dùng bí mật đó để xác minh header X-ThunderPhone-Signature trên các yêu cầu đến (xem tổng quan về webhook).

Bước 5: Kiểm thử tác nhân AI

Gọi đến số bạn vừa cấp. Tác nhân AI sẽ bắt máy, tự giới thiệu và làm theo prompt của bạn.

Kiểm tra cuộc gọi sau khi kết thúc:

curl https://api.thunderphone.com/v1/calls \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

Xem chi tiết một cuộc gọi cụ thể để lấy bản chép lời và URL bản ghi âm:

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"

Bước tiếp theo