Dispatch Voice Kit Webhook Reference
Back to live board

Dispatch Voice Kit: Outbound Webhooks

Every state change made by the voice agent or the dispatch board is written atomically to an append-only events outbox in the same request as the domain mutation, then delivered asynchronously via HTTP POST.

Delivery Target #

  • If TENANT_WEBHOOK_URL is configured, events are sent to that URL.
  • If TENANT_WEBHOOK_URL is unset, events are delivered to this deployment's built-in echo receiver at POST <origin>/api/webhooks/echo. The echo receiver verifies the signature and stores a receipt so end-to-end delivery is visible on the board without external infrastructure.

Request Headers #

Every outbound webhook POST sends the following headers:

Header Description
content-type application/json
x-dispatch-event Event type name from EVENT_TYPES (for example order.created).
x-dispatch-delivery Unique event id (evt_<hex>), safe to use as an idempotency key.
x-dispatch-timestamp Unix timestamp in seconds when the delivery attempt was signed.
x-dispatch-signature sha256=<hex>, HMAC-SHA256 of <timestamp>.<raw_body> keyed by WEBHOOK_SIGNING_SECRET.

Envelope Structure #

Every webhook body uses the same top-level envelope:

JSON
{
  "id": "evt_7d3c5f4e90124a889a2c8a4b1f92e101",
  "type": "order.created",
  "created_at": "2026-12-07T15:30:58.000Z",
  "tenant": "stonebridge",
  "data": {}
}

Phone numbers inside data are masked as (NNN) ***-NNNN (or Private number when unavailable) with one intentional exception: escalation.callback_number carries the unmasked E.164 callback number so downstream dispatch workflows can return the call.

Signature Verification #

Verify signatures against the exact raw UTF-8 request body bytes (never re-serialized JSON). Reject requests whose x-dispatch-timestamp is more than 300 seconds from your clock, and always use a constant-time digest comparison.

Node.js (built-in node:crypto) #

JS
import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyDispatchWebhook(rawBody, headers, secret) {
  const ts = headers["x-dispatch-timestamp"];
  const sig = headers["x-dispatch-signature"];
  if (!ts || !sig || !sig.startsWith("sha256=")) return false;
  if (Math.abs(Math.floor(Date.now() / 1000) - Number(ts)) > 300) return false;
  const expected = "sha256=" + createHmac("sha256", secret).update(`${ts}.${rawBody}`, "utf8").digest("hex");
  const a = Buffer.from(sig, "utf8");
  const b = Buffer.from(expected, "utf8");
  return a.length === b.length && timingSafeEqual(a, b);
}

Python (standard library) #

PYTHON
import hashlib, hmac, time

def verify_dispatch_webhook(raw_body: bytes, headers: dict, secret: str) -> bool:
    ts = headers.get("x-dispatch-timestamp", "")
    sig = headers.get("x-dispatch-signature", "")
    if not ts.isdigit() or not sig.startswith("sha256="):
        return False
    if abs(int(time.time()) - int(ts)) > 300:
        return False
    expected = "sha256=" + hmac.new(secret.encode(), f"{ts}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(sig, expected)

Timeout, Retries and Idempotency #

  • Timeout: 3 seconds per attempt.
  • Success: Any HTTP 2xx status marks the outbox row delivered.
  • Retries: Up to 4 total attempts with backoff (5 seconds after attempt 1, 20 seconds after attempt 2, 60 seconds after attempt 3). After 4 failed attempts the row is marked failed.
  • Scheduling: Attempt 1 runs immediately after the originating HTTP response using @vercel/functions waitUntil (never delaying the voice tool or API response). Any pending rows whose retry time has arrived are flushed opportunistically on subsequent API requests (up to 5 rows per request, also non-blocking).
  • Missing signing secret: If WEBHOOK_SIGNING_SECRET is unset, delivery is marked skipped rather than sending unsigned payloads.
  • Idempotency: Deduplicate deliveries on x-dispatch-delivery (same value as payload.id).

Event Types and Sample Payloads #

1. call.started #

Emitted once when Retell reports call_started.

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a01",
  "type": "call.started",
  "created_at": "2026-12-07T15:30:11.000Z",
  "tenant": "stonebridge",
  "data": {
    "call": {
      "call_id": "call_7f3a91c2",
      "status": "live",
      "answered": true,
      "started_at": "2026-12-07T15:30:11.000Z",
      "ended_at": null,
      "duration_seconds": 0,
      "caller": {
        "display": "Tester One",
        "type": "tester",
        "company": "Harlow Site Works (demo)",
        "number_masked": "(240) ***-0142"
      },
      "language": "en",
      "call_type": "other",
      "outcome": "in_progress",
      "summary": "",
      "actions": [],
      "transcript": null,
      "recording_url": null
    }
  }
}

2. call.completed #

Emitted once when a call finishes (call_ended, or call_analyzed if call_ended was missed).

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a02",
  "type": "call.completed",
  "created_at": "2026-12-07T15:31:45.000Z",
  "tenant": "stonebridge",
  "data": {
    "call": {
      "call_id": "call_7f3a91c2",
      "status": "ended",
      "answered": true,
      "started_at": "2026-12-07T15:30:11.000Z",
      "ended_at": "2026-12-07T15:31:45.000Z",
      "duration_seconds": 94,
      "caller": {
        "display": "Tester One",
        "type": "tester",
        "company": "Harlow Site Works (demo)",
        "number_masked": "(240) ***-0142"
      },
      "language": "en",
      "call_type": "new_order",
      "outcome": "order_created",
      "summary": "Booked 10 loads of #57 stone for job 4471 tomorrow at 07:00.",
      "actions": [
        {
          "ts": "2026-12-07T15:30:14.000Z",
          "tool": "lookup_caller",
          "label": "Recognized the caller",
          "ok": true,
          "ref": null
        },
        {
          "ts": "2026-12-07T15:30:58.000Z",
          "tool": "create_order",
          "label": "Created order ORD-48201",
          "ok": true,
          "ref": { "kind": "order", "id": "ORD-48201" }
        }
      ],
      "transcript": [
        { "role": "agent", "text": "Stonebridge Haul dispatch, this is the AI assistant on a recorded line. How can I help?", "ts": 0 },
        { "role": "caller", "text": "I need ten loads of 57 stone on job 4471 tomorrow at seven.", "ts": 5 }
      ],
      "recording_url": null
    }
  }
}

3. order.created #

Emitted when create_order creates a new order.

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a03",
  "type": "order.created",
  "created_at": "2026-12-07T15:30:58.000Z",
  "tenant": "stonebridge",
  "data": {
    "order": {
      "order_id": "ORD-48201",
      "job_code": "4471",
      "job_name": "Courthouse Road Site Prep",
      "customer": "Harlow Site Works (demo)",
      "material": "#57 stone",
      "material_sku": "57",
      "quantity": 10,
      "unit": "loads",
      "trucks_requested": 3,
      "truck_type": "tri-axle",
      "delivery_date": "2026-12-08",
      "start_time": "07:00",
      "site_contact_name": "Garrett Harlow",
      "site_contact_phone": "(540) ***-0111",
      "notes": "Use the north gate.",
      "status": "scheduled",
      "loads_total": 10,
      "loads_delivered": 0,
      "created_by": "ai",
      "source_call_id": "call_7f3a91c2",
      "created_at": "2026-12-07T15:30:58.000Z",
      "updated_at": "2026-12-07T15:30:58.000Z",
      "history": [
        { "ts": "2026-12-07T15:30:58.000Z", "actor": "ai", "change": "Order created from a phone call" }
      ]
    }
  }
}

4. order.updated #

Emitted when update_order modifies an existing order. Includes changes, listing every modified field name.

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a04",
  "type": "order.updated",
  "created_at": "2026-12-07T15:35:12.000Z",
  "tenant": "stonebridge",
  "data": {
    "order": {
      "order_id": "ORD-48201",
      "job_code": "4471",
      "job_name": "Courthouse Road Site Prep",
      "customer": "Harlow Site Works (demo)",
      "material": "#57 stone",
      "material_sku": "57",
      "quantity": 12,
      "unit": "loads",
      "trucks_requested": 3,
      "truck_type": "tri-axle",
      "delivery_date": "2026-12-08",
      "start_time": "07:00",
      "site_contact_name": "Garrett Harlow",
      "site_contact_phone": "(540) ***-0111",
      "notes": "Use the north gate. Call foreman 10 minutes out.",
      "status": "scheduled",
      "loads_total": 12,
      "loads_delivered": 0,
      "created_by": "ai",
      "source_call_id": "call_7f3a91c2",
      "created_at": "2026-12-07T15:30:58.000Z",
      "updated_at": "2026-12-07T15:35:12.000Z",
      "history": [
        { "ts": "2026-12-07T15:30:58.000Z", "actor": "ai", "change": "Order created from a phone call" },
        { "ts": "2026-12-07T15:35:12.000Z", "actor": "ai", "change": "Updated quantity to 12 loads, notes" }
      ]
    },
    "changes": ["quantity", "notes"]
  }
}

5. order.cancelled #

Emitted when cancel_order cancels an order whose trucks are not rolling.

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a05",
  "type": "order.cancelled",
  "created_at": "2026-12-07T15:40:00.000Z",
  "tenant": "stonebridge",
  "data": {
    "order": {
      "order_id": "ORD-48195",
      "job_code": "4471",
      "job_name": "Courthouse Road Site Prep",
      "customer": "Harlow Site Works (demo)",
      "material": "#57 stone",
      "material_sku": "57",
      "quantity": 8,
      "unit": "loads",
      "trucks_requested": 2,
      "truck_type": "tri-axle",
      "delivery_date": "2026-12-08",
      "start_time": "07:00",
      "site_contact_name": "",
      "site_contact_phone": "",
      "notes": "North gate opens at 06:45.",
      "status": "cancelled",
      "loads_total": 8,
      "loads_delivered": 0,
      "created_by": "seed",
      "source_call_id": null,
      "created_at": "2026-12-07T10:00:00.000Z",
      "updated_at": "2026-12-07T15:40:00.000Z",
      "history": [
        { "ts": "2026-12-07T15:40:00.000Z", "actor": "ai", "change": "Cancelled: Site rained out" }
      ]
    },
    "reason": "Site rained out"
  }
}

6. driver.availability_logged #

Emitted when log_driver_availability records available trucks for an upcoming day.

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a06",
  "type": "driver.availability_logged",
  "created_at": "2026-12-07T14:02:10.000Z",
  "tenant": "stonebridge",
  "data": {
    "availability": {
      "id": "AV-3101",
      "driver_name": "Marcos Villanueva",
      "carrier": "Villanueva Trucking (demo)",
      "date": "2026-12-08",
      "trucks_available": 2,
      "truck_type": "tri-axle",
      "start_time": "06:00",
      "notes": "Can run Richmond or Fredericksburg.",
      "source_call_id": "call_41aa0c9e",
      "logged_at": "2026-12-07T14:02:10.000Z"
    }
  }
}

7. escalation.created #

Emitted when escalate_to_dispatcher opens an escalation. Note callback_number carries the unmasked E.164 callback number for dispatcher follow-up.

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a07",
  "type": "escalation.created",
  "created_at": "2026-12-07T15:13:20.000Z",
  "tenant": "stonebridge",
  "data": {
    "escalation": {
      "id": "ESC-1001",
      "call_id": "call_52be0d17",
      "reason": "jobsite_issue",
      "priority": "urgent",
      "summary": "Gate locked at the Courthouse Road site, nobody on site, truck T-118 is waiting loaded.",
      "caller_display": "Luis Ortega, Ortega Hauling (demo)",
      "callback_number_masked": "(301) ***-0151",
      "callback_number": "+13015550151",
      "status": "open",
      "transferred": false,
      "callback_minutes": 10,
      "created_at": "2026-12-07T15:13:20.000Z",
      "claimed_by": null,
      "resolved_at": null
    }
  }
}

8. escalation.claimed #

Emitted when a dispatcher claims an escalation from the board (POST /api/board/escalations/:id/claim).

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a08",
  "type": "escalation.claimed",
  "created_at": "2026-12-07T15:14:05.000Z",
  "tenant": "stonebridge",
  "data": {
    "escalation": {
      "id": "ESC-1001",
      "call_id": "call_52be0d17",
      "reason": "jobsite_issue",
      "priority": "urgent",
      "summary": "Gate locked at the Courthouse Road site, nobody on site, truck T-118 is waiting loaded.",
      "caller_display": "Luis Ortega, Ortega Hauling (demo)",
      "callback_number_masked": "(301) ***-0151",
      "status": "claimed",
      "transferred": false,
      "callback_minutes": 10,
      "created_at": "2026-12-07T15:13:20.000Z",
      "claimed_by": "Dispatcher",
      "resolved_at": null
    },
    "changes": ["status", "claimed_by"]
  }
}

9. escalation.resolved #

Emitted when a dispatcher resolves an escalation from the board (POST /api/board/escalations/:id/resolve).

JSON
{
  "id": "evt_1001a2b3c4d54e6f8a9b0c1d2e3f4a09",
  "type": "escalation.resolved",
  "created_at": "2026-12-07T15:21:30.000Z",
  "tenant": "stonebridge",
  "data": {
    "escalation": {
      "id": "ESC-1001",
      "call_id": "call_52be0d17",
      "reason": "jobsite_issue",
      "priority": "urgent",
      "summary": "Gate locked at the Courthouse Road site, nobody on site, truck T-118 is waiting loaded.",
      "caller_display": "Luis Ortega, Ortega Hauling (demo)",
      "callback_number_masked": "(301) ***-0151",
      "status": "resolved",
      "transferred": false,
      "callback_minutes": 10,
      "created_at": "2026-12-07T15:13:20.000Z",
      "claimed_by": "Dispatcher",
      "resolved_at": "2026-12-07T15:21:30.000Z"
    },
    "changes": ["status", "resolved_at"]
  }
}