ഓരോ കോളിനും ഡൈനാമിക് കോൺഫിഗറേഷൻ

സ്ഥിരസ്ഥിതിയായി, ഓരോ ഫോൺ നമ്പറിനും പ്രസിദ്ധീകരിക്കാവുന്ന കീക്കും ഒരു സ്ഥിര ഏജന്റ് നിയോഗിച്ചിരിക്കും. ഓരോ കോളർക്കും അല്ലെങ്കിൽ ഓരോ സന്ദർശകർക്കും ഇഷ്ടാനുസൃതമാക്കൽ ആവശ്യമാകുമ്പോൾ — VIP റൂട്ടിംഗ്, ലോഗിൻ ചെയ്ത ഉപയോക്തൃ കോൺടെക്സ്റ്റ്, A/B prompt പരിശോധനകൾ — വെബ്ഹുക്ക് മോഡിലേക്ക് മാറി നിങ്ങളുടെ സെർവറിനെ തീരുമാനിക്കാൻ അനുവദിക്കുക.

ഇത് എങ്ങനെ പ്രവർത്തിക്കുന്നു

  1. നിങ്ങൾ telephony.incoming (ഫോൺ) അല്ലെങ്കിൽ web.incoming (വിജറ്റ്) ഇവന്റിലേക്ക് സബ്സ്ക്രൈബ് ചെയ്യുന്നു. രണ്ടും തടസ്സപ്പെടുത്തുന്ന വെബ്ഹുക്കുകളാണ്: കോൾ തുടരുന്നതിന് മുമ്പ് ThunderPhone നിങ്ങളുടെ പ്രതികരണത്തിനായി പരമാവധി 10 സെക്കൻഡ് കാത്തിരിക്കും.
  2. ThunderPhone നിങ്ങൾക്ക് {call_id, from_number, to_number} അയയ്ക്കുന്നു (വിജറ്റ് സെഷനുകളിൽ നമ്പറുകൾക്ക് പകരം വിജറ്റിന്-പ്രത്യേകമായ ഫീൽഡുകളാണ് ഉണ്ടാകുക — അഭ്യർത്ഥന സ്കീമ കാണുക).
  3. നിങ്ങളുടെ സെർവർ ഒരു ഏജന്റ് കോൺഫിഗറേഷനുമായി പ്രതികരിക്കുന്നു (prompt, ശബ്ദം, ഉൽപ്പന്നം, ടൂളുകൾ). ThunderPhone ആ കോൺഫിഗറേഷൻ കോളിനായി ഉപയോഗിക്കുന്നു.
  4. നിങ്ങൾ {} മടക്കിനൽകുകയോ, സമയപരിധി കവിയുകയോ, പിശക് സംഭവിക്കുകയോ ചെയ്താൽ, സ്ഥിരമായി നിയോഗിച്ച ഏജന്റിനെ ഒരു ഫാൾബാക്കായി ഉപയോഗിക്കും. സുരക്ഷിതമായ ഡിഫോൾട്ട്.

1. വെബ്ഹുക്ക് ലക്ഷ്യസ്ഥാനം കോൺഫിഗർ ചെയ്യുക

ഫോൺ കോളുകൾ

ഫോൺ നമ്പറുകൾക്കായി, നിങ്ങളുടെ എൻഡ്‌പോയിന്റിനെ telephony.incoming-ലേക്ക് സബ്സ്ക്രൈബ് ചെയ്യുക:

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 call-incoming",
    "url":    "https://example.com/thunderphone/incoming",
    "events": ["telephony.incoming"]
  }'

പ്രതികരണത്തിൽ ഒറ്റത്തവണ ഉപയോഗിക്കാവുന്ന secret ഉൾപ്പെടും — അത് സംരക്ഷിക്കുക; ഒപ്പ് സ്ഥിരീകരണത്തിനായി നിങ്ങൾ അത് ഉപയോഗിക്കും.

വെബ് വിജറ്റ്

വിജറ്റ് സെഷനുകൾക്കായി, നിങ്ങളുടെ എൻഡ്‌പോയിന്റ് URL ഉൾച്ചേർത്ത mode="webhook"-ൽ ഒരു പ്രസിദ്ധീകരിക്കാവുന്ന കീ സൃഷ്ടിക്കുക:

curl -X POST https://api.thunderphone.com/v1/publishable-key \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name":            "Dynamic widget",
    "mode":            "webhook",
    "webhook_url":     "https://example.com/thunderphone/widget-incoming",
    "allowed_domains": ["example.com"]
  }'

ഓരോ സെഷൻ ആരംഭത്തിലും വിജറ്റ് ഈ URL-ലേക്ക് POST ചെയ്യും.

2. ഹാൻഡ്‌ലർ നടപ്പിലാക്കുക

മൂന്ന് അടിസ്ഥാന നിയമങ്ങൾ:

import hashlib
import hmac
import json
import os

from fastapi import FastAPI, HTTPException, Request

app = FastAPI()
SECRET = os.environ["THUNDERPHONE_WEBHOOK_SECRET"]

def verify(body: bytes, sig: str) -> bool:
    expected = hmac.new(SECRET.encode(), body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, sig or "")

@app.post("/thunderphone/incoming")
async def incoming(request: Request):
    body = await request.body()
    if not verify(body, request.headers.get("X-ThunderPhone-Signature", "")):
        raise HTTPException(401)

    event = json.loads(body)
    if event["type"] not in ("telephony.incoming", "web.incoming"):
        return {}  # fall back to default

    caller = event["data"]["from_number"]
    # Cheap DB lookup: is this a known VIP?
    customer = lookup_customer(caller)
    if customer and customer.tier == "vip":
        return {
            "prompt":  f"You are a VIP concierge for {customer.name}. Be proactive…",
            "voice":   "john",
            "product": "storm-base",
        }
    return {}  # default agent handles non-VIPs

def lookup_customer(phone: str):
    # ... your CRM integration ...
    pass
import crypto from "node:crypto";
import express from "express";

const app = express();
const SECRET = process.env.THUNDERPHONE_WEBHOOK_SECRET;

function verify(body, sig) {
  const expected = crypto.createHmac("sha256", SECRET).update(body).digest("hex");
  return sig &&
    crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(sig));
}

app.post(
  "/thunderphone/incoming",
  express.raw({ type: "application/json" }),
  async (req, res) => {
    if (!verify(req.body, req.header("X-ThunderPhone-Signature"))) {
      return res.sendStatus(401);
    }
    const event = JSON.parse(req.body.toString("utf8"));

    const IMPORTANT_TYPES = new Set([
      "telephony.incoming",
      "web.incoming",
    ]);
    if (!IMPORTANT_TYPES.has(event.type)) return res.json({});

    const customer = await lookupCustomer(event.data.from_number);
    if (customer?.tier === "vip") {
      return res.json({
        prompt:  `You are a VIP concierge for ${customer.name}. Be proactive…`,
        voice:   "john",
        product: "storm-base",
      });
    }
    res.json({}); // fall back to default agent
  },
);

3. പ്രതികരണ സ്കീമ

പ്രതികരണ ബോഡി ഇൻകമിംഗ്-കോൾ പ്രതികരണ സ്കീമയുമായി കൃത്യമായി പൊരുത്തപ്പെടുന്നു. സാധാരണ ഉപയോഗിക്കുന്ന ഫീൽഡുകൾ:

ഫീൽഡ്തരംവിവരണം
promptസ്ട്രിംഗ് (നിർബന്ധം)ഏജന്റിനായുള്ള സിസ്റ്റം prompt
voiceസ്ട്രിംഗ് (നിർബന്ധം)GET /v1/voices-ൽ നിന്നുള്ള വോയ്‌സ് ഐഡി
productസ്ട്രിംഗ്ഡിഫോൾട്ടായി spark
background_trackസ്ട്രിംഗ് | nullആംബിയന്റ് ഓഡിയോ ഐഡി
acknowledgement_prompt_modeസ്ട്രിംഗ്auto അല്ലെങ്കിൽ manual (അംഗീകാരത്തോടെയുള്ള Storm-ന് മാത്രം)
acknowledgement_promptസ്ട്രിംഗ്മോഡ് manual ആയിരിക്കുമ്പോൾ നിർബന്ധം
toolsഅറേഇൻലൈൻ ഫംഗ്ഷൻ-ടൂൾ സ്കീമകൾ — ഫംഗ്ഷൻ ടൂളുകൾ കാണുക

പാറ്റേണുകൾ

ലോഗിൻ ചെയ്ത ഉപയോക്തൃ കോൺടെക്സ്റ്റ്

webhook-മോഡ് വിജറ്റുകളിൽ, സന്ദർശകന്റെ പേജിന് അവർ ആരാണെന്ന് ഇതിനകം അറിയാം. വിജറ്റ് SDK ഫോർവേഡ് ചെയ്യുന്ന ഒരു query string പാരാമീറ്ററോടെ (?customer_id=123) നിങ്ങളുടെ webhook വിളിച്ച്, സെർവർ-സൈഡിൽ ഉപഭോക്താവിനെ കണ്ടെത്തുക.

A/B prompt റോൾഔട്ട്

ഇത് സ്വയം നടപ്പാക്കുന്നതിന് മുമ്പ്, ThunderPhone-ൽ നേറ്റീവ് പരീക്ഷണങ്ങൾ ഫീച്ചർ (/dashboard/experiments, ഏജന്റ് ബിൽഡറിലെ A/B ടാബ്) ഉണ്ടെന്ന് ശ്രദ്ധിക്കുക. ഇത് വേരിയന്റുകൾ നിർവചിക്കുകയും, ട്രാഫിക് വിഭജിക്കുകയും, ഓരോ വേരിയന്റിന്റെയും ഫലങ്ങൾ താരതമ്യം ചെയ്യുകയും ചെയ്യുന്നു — webhook ആവശ്യമില്ല.

എന്നിരുന്നാലും webhook-സൈഡ് നിയന്ത്രണം ആവശ്യമാണെങ്കിൽ: call_id ഹാഷ് ചെയ്ത് → bucket; 0..49-ന് prompt A-യും 50..99-ന് prompt B-യും നൽകുക. നിങ്ങൾ തിരഞ്ഞെടുത്ത bucket നിങ്ങളുടെ സ്വന്തം DB-യിൽ രേഖപ്പെടുത്തി, പിന്നീട് പൂർത്തിയായ കോളിന്റെ ഗ്രേഡുമായി ബന്ധിപ്പിക്കുക.

സമയാധിഷ്ഠിത റൂട്ടിംഗ്

പ്രവർത്തന സമയം → "തത്സമയ പിന്തുണ" ഏജന്റ്; പ്രവർത്തന സമയത്തിന് ശേഷം → "സന്ദേശം എടുക്കുക" ഏജന്റ്. നിങ്ങളുടെ ഹാൻഡ്‌ലറിലെ new Date().getUTCHours() ഉപയോഗിച്ചുള്ള ലളിതമായ സ്വിച്ച് മാത്രം.


അടുത്ത ഘട്ടങ്ങൾ