ThunderPhone 2.0 متاح الآن.خدمة ذاتية، ابتداءً من 2 سنت/دقيقة.اقرأ الإعلان

Getting Started

البدء السريع (API)

أجب عن أول مكالمة هاتفية باستخدام وكيل صوتي بالذكاء الاصطناعي: احصل على مفتاح API، وأنشئ وكيلاً، وفّر رقم هاتف، وأجرِ مكالمة اختبار مباشرة — كل ذلك عبر واجهة REST API.

يرشدك هذا الدليل عبر استدعاءات REST الأربعة اللازمة للرد على أول مكالمة هاتفية لك باستخدام وكيل صوتي بالذكاء الاصطناعي.

الخطوة 1: احصل على مفتاح API

  1. تسجيل الدخول
  2. الانتقال إلى المفاتيح

    انتقل إلى المؤسسة → المفاتيح في لوحة التحكم.

  3. إنشاء مفتاح

    انقر على إنشاء مفتاح، وامنحه اسمًا، ثم انسخ قيمة sk_live_.... يُعرض المفتاح الخام مرة واحدة فقط — خزّنه فورًا في مدير الأسرار لديك.

طوال هذا الدليل، استبدل sk_live_YOUR_API_KEY بالقيمة التي نسختها للتو. يعرّف المفتاح مؤسستك تلقائيًا، لذا لا تحتاج مطلقًا إلى إضافة معرّف المؤسسة إلى عناوين URL.

الخطوة 2: أنشئ وكيلًا

يحدد الوكيل كيفية تعامل الذكاء الاصطناعي مع المحادثات — الموجّه، والصوت، ومستوى المنتج، والأدوات، وأهلية الأداة المصغّرة.

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

الخطوة 3: توفير رقم هاتف

يطلب هذا الاستدعاء من ThunderPhone رقمًا ويعيّن وكيلك الجديد لمعالجة المكالمات الواردة. (لإحضار رقمك الخاص من مزوّد VoIP، راجع اتصالات VoIP بدلًا من ذلك.)

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

يبدأ رقمك الجديد بالحالة status="provisioning" ثم ينتقل إلى active خلال بضع ثوانٍ؛ وبحلول وقت إغلاق المتصفح يكون الرقم جاهزًا لاستقبال المكالمات.

الخطوة 4 (اختيارية): إعداد خطاف ويب

لأحداث الوقت الفعلي (توجيه المكالمات الديناميكي، المعالجة بعد المكالمة)، أضف نقطة نهاية لخطاف ويب. اشترك فقط في الأحداث التي تحتاج إليها.

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-V2 في الطلبات الواردة (راجع نظرة عامة على Webhooks).

الخطوة 5: اختبار وكيلك

اتصل بالرقم الذي وفّرته للتو. يرد الوكيل، ويعرّف بنفسه، ويتبع موجّهك.

افحص المكالمة بعد انتهائها:

curl https://api.thunderphone.com/v1/calls \
  -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"
curl https://api.thunderphone.com/v1/calls/{call_id}/audio \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

الخطوات التالية