Tonedocs

Webhooks and events

The event catalog, how to verify a signature, what retries look like, and how to replay what you missed.

Calls take minutes and campaigns take hours. Webhooks are how you find out what happened without polling for it.

Registering an endpoint

curl "$TONE_API/v1/integrations/webhooks" \
  -X POST \
  -H "Authorization: Bearer $TONE_LIVE_ADMIN_KEY" \
  -H 'content-type: application/json' \
  -d '{
    "url": "https://your-app.example.com/hooks/tone",
    "events": ["call.completed", "call.failed", "campaign.completed"]
  }'

Endpoints are managed with a live admin key or in the dashboard. Because one endpoint receives both test and live events, a tone_test_ key gets 403 adding, changing or removing one, or reading or rolling its secret — it can still list them.

{
  "data": {
    "id": "d81c...",
    "url": "https://your-app.example.com/hooks/tone",
    "events": ["call.completed", "call.failed", "campaign.completed"],
    "secret": "whsec_8f2a...",
    "...": "..."
  }
}

secret appears once, in this response. Store it. If you lose it you can read it back at GET /v1/integrations/webhooks/{id}/secret with an admin key, or roll it — but don't build on being able to fetch it casually.

Every endpoint signs with its own secret. The org-level GET /v1/integrations/webhooks/signing-secret is only for endpoints created before per-endpoint secrets existed.

An endpoint is not tied to an environment: it receives both test and live events, signed with the same secret. The envelope's environment (test or live) says which one an event came from; it is null only for org-wide events such as a knowledge-base build.

Managing endpoints requires admin scope: the URL decides where your call data goes.

Subscribe only to what you handle. Every event you're subscribed to is an HTTP request to your server, and an endpoint that 500s on events it doesn't care about will eventually be switched off.

Only some agents

An endpoint receives every agent's events unless you limit it. Set agentIds to send it only the events of the agents you name — the usual shape is one endpoint per agent, each pointed at the system that agent's results belong in:

curl "$TONE_API/v1/integrations/webhooks" \
  -X POST \
  -H "Authorization: Bearer $TONE_LIVE_ADMIN_KEY" \
  -H 'content-type: application/json' \
  -d '{
    "url": "https://your-app.example.com/hooks/cod",
    "events": ["call.completed"],
    "agentIds": ["9f1c2d84-4e3a-4f6c-b902-7d1e8a33c451"]
  }'
  • It limits the events that belong to an agent: calls, transfers, campaigns and compliance blocks. A call with no Tone agent — one on a BYO number — never reaches a limited endpoint.
  • Events that belong to no agent (wallet.balance.low, the number.* and knowledge.* events) still arrive if you subscribed to them.
  • An id that is not one of your agents is refused with 422. A PATCH with "agentIds": null sends the endpoint every agent's events again.
  • In the dashboard: Settings → Webhooks, add or edit an endpoint, then Agents → Only these agents. Or from the agent: its After the call tab lists every endpoint with a switch for "send this agent's events here", and Add webhook opens a new endpoint already limited to it. Those switches change the endpoint itself, at once — they are not part of the agent's draft.

Every payload also names its agent (data.call.agent.id), so an endpoint that takes every agent's events can still tell them apart.

Conditions and your own body

An endpoint can send only some events, in a body you write, to an API that wants its own credential. Each endpoint is one action, so one agent can send confirmed orders to one URL and cancelled ones to another, each in the JSON that URL expects:

curl "$TONE_API/v1/integrations/webhooks" \
  -X POST \
  -H "Authorization: Bearer $TONE_LIVE_ADMIN_KEY" \
  -H 'content-type: application/json' \
  -d '{
    "url": "https://api.your-store.example.com/v1/cod/cancel",
    "events": ["call.completed"],
    "agentIds": ["9f1c2d84-4e3a-4f6c-b902-7d1e8a33c451"],
    "conditions": [
      { "field": "outputs.order_confirmed", "op": "eq", "value": "cancelled" }
    ],
    "bodyTemplate": "{\"order_id\": \"{{variables.order_number}}\", \"reason\": {{outputs.cancellation_reason}}, \"tone_call_id\": \"{{call.id}}\"}",
    "auth": { "type": "bearer", "secretId": "3f1a7f6e-2b4c-4d1e-9a8b-5c6d7e8f9a0b" }
  }'

Paths

Conditions and templates name values by path:

PathWhat it is
outputs.<name>A field your agent captured after the call (Data to capture).
goals.<id>An evaluation's verdict: success, failure or unknown.
variables.<name>A variable the call was placed with.
context.<path>The structured context the call was placed with, e.g. context.order.items.0.name.
call.<field>Anything on the call payload: call.id, call.disposition, call.durationSeconds, call.peer, call.summary.
event.<field>event.id (the delivery id), event.type, event.environment, event.createdAt.
links.<name>links.self, links.recording, links.transcript, when the call has them.

On an event about something other than a call, its own data key is the root instead: campaign.status, wallet.balancePaise.

Conditions

Every condition must hold, or nothing is sent and the delivery is logged skipped. They are checked after the call's data is filled — the same wait the standard payload makes for summary and outputs, up to 90 seconds.

opHolds when the value…
eq, neqis, or is not, value. Case and outer spaces are ignored; true equals "true".
in, not_inis, or is not, one of values.
gt, gte, lt, lteis a number above or below value.
exists, not_existsis there or not. Takes no value.

A condition on a value the call does not have is not met, whatever its op — except not_exists. So a call that went to voicemail, which fills no outputs, runs only the endpoints with no condition on its outputs. Keep one endpoint without conditions if you want every call.

A skipped delivery's lastError names the condition that failed: condition_not_met outputs.order_confirmed, or no_value outputs.order_confirmed when the call had nothing there. It never holds the value itself. A skipped delivery spends no retry and never counts toward switching the endpoint off; Retry in the log checks it again against the endpoint's current conditions.

Your own body

bodyTemplate is JSON with {{path}} placeholders, sent in place of the standard payload:

  • A placeholder on its own keeps its type: "reason": {{outputs.cancellation_reason}} sends a string, a number, true or a list as such, and null when the call has no value.
  • Inside quotes it is inserted as text, escaped, so a value can never break out of its string: "note": "Call {{call.id}} lasted {{call.durationSeconds}}s". A missing value is empty.
  • The template is checked when you save it: an unknown path, or JSON that would not parse once filled, is refused with 422.

Deliveries are still signed — over the body you get — and still carry x-tone-event-id, so verifying and de-duplication work unchanged.

Calling your own API

When the URL is an API of yours rather than a receiver you wrote, give the endpoint the credential that API expects. auth references a stored secret — Settings → Secrets — and never holds the value:

  • bearer sends Authorization: Bearer <secret>.
  • basic sends the stored user:password as Basic auth.
  • api_key sends the secret in header (default x-api-key).

The URL must be https://. headers adds static headers, up to 16 — never a credential: authorization and x-tone-* are refused. A secret an endpoint uses cannot be deleted until the endpoint stops using it. Send a test carries the credential too.

Previewing

POST /v1/integrations/webhooks/preview takes conditions and bodyTemplate, saved or not, and answers what a delivery would do for one of your calls: whether every condition holds (matched, and the first miss) and the exact body. Without a callId it uses the newest ended call the conditions accept, else the newest ended call. Nothing is sent.

In the dashboard: edit an endpoint, or Add webhook on an agent's After the call tab. The editor shows the preview beside the body as you type.

The event catalog

EventFires whendata contains
call.initiatedA dial was accepted and the call row exists (outbound and inbound)call
call.answeredThe far end connected to the media path — outbound and inbound alike. call.answeredAt says whencall
call.completedA call ended — any dispositioncall
call.failedA call ended in a non-answer: failed, no_answer, or busycall
call.transfer_startedThe agent began handing the call to a person and their phone is ringingcall, transfer
call.transferredThe person took the call. Not sent on VoiceLink numbers, which never say whether the person answeredcall, transfer
call.transfer_failedNobody took it, or the caller hung up first. The agent comes back on the line if the caller is still there. On Exotel numbers it can also follow a call.transferred a few minutes after the call, when Exotel's call record shows the person never answeredcall, transfer
campaign.completedEvery recipient in a campaign has settledcampaign
campaign.pausedA campaign paused — including the automatic wallet-floor pausecampaign
compliance.check.blockedThe pre-dial gate refused a callcheck
wallet.balance.lowYour balance crossed your low-balance thresholdwallet
number.renewal_dueA renewal is due and your balance cannot cover it. number.releaseAt says when it is released unless you add moneynumber
number.releasedA renewal went unpaid past its releaseAt; the number is gonenumber
number.suspendedNo longer sent — unpaid renewals are now released. Kept so existing subscriptions stay validnumber
number.reactivatedA number suspended under the old policy had its overdue rent paidnumber
knowledge.build.completedA knowledge base finished building and can answer questionsknowledgeBase, build
knowledge.build.failedA build failed; build.error says whyknowledgeBase, build

call.failed fires alongside call.completed, not instead of it. Subscribe to call.completed alone if you branch on disposition yourself; subscribe to call.failed as well if you have a separate path for non-answers. Subscribing to both means two deliveries for one busy signal — which is correct, just make sure that's what you intended.

On an answered call with a Tone agent, call.completed waits up to about 90 seconds for the call's summary. Every other call — BYO, unanswered, failed, voicemail — is delivered at once.

New event types will be added. An unrecognised type should be logged and ignored, not thrown on.

The payload

Every event has the same envelope:

{
  "id": "9e41b7c2-...",
  "type": "call.completed",
  "environment": "live",
  "created_at": "2026-08-24T09:41:07.812Z",
  "data": {
    "call": {
      "id": "3b7e...",
      "status": "ended",
      "disposition": "answered",
      "startedAt": "2026-08-24T09:40:18.000Z",
      "answeredAt": "2026-08-24T09:40:22.000Z",
      "durationSeconds": 45,
      "billedPaise": 480,
      "campaignId": null,
      "summary": "The customer confirmed the order for Thursday delivery.",
      "outputs": { "confirmed": true, "preferred_day": "thursday" },
      "...": "..."
    }
  },
  "links": {
    "self": "https://api.usetone.ai/v1/calls/3b7e...",
    "recording": "https://api.usetone.ai/v1/calls/3b7e.../recording",
    "transcript": "https://api.usetone.ai/v1/calls/3b7e.../transcript"
  }
}
  • id is the event id, repeated in the x-tone-event-id header. Use it as your deduplication key — see Handling duplicates.
  • data is keyed by subject — call, campaign, number, check, wallet, or knowledgeBase + build. For calls, campaigns, numbers and compliance checks the object is identical to what that resource's own GET returns, so there's one shape to learn and a webhook can never disagree with the API. The wallet payload is a three-field subset of GET /v1/wallet (balance, threshold, currency), and the knowledge events carry the base's identity plus the build that just finished.
  • links are offered only when there's something behind them. recording and transcript appear when they exist, so branch on presence rather than fetching and handling a 404.
  • Transfer events carry the attempt they are about as data.transfer (the call's own transfer field is its latest attempt, which can be a later one by the time a retried delivery arrives), and links.handoff: a page showing the person what the caller has said so far. Anyone holding that link can open it for 24 hours, so send it only to the person taking the call.

Transcripts are not inlined. They're multi-kilobyte and would make us a bad neighbour on your server; fetch links.transcript with your API key if you want one.

Verifying the signature

Verify every delivery. Your endpoint URL is reachable by anyone; the signature is what makes a request actually from Tone.

Each delivery carries:

x-tone-timestamp: 1756029667
x-tone-signature: v1=4f7c8e2a...
x-tone-event: call.completed
x-tone-event-id: 9e41b7c2-...
x-tone-delivery-attempt: 1

The signature is HMAC-SHA256 over the literal string {timestamp}.{raw body}, hex-encoded.

import { createHmac, timingSafeEqual } from 'node:crypto';

function verifyTone(rawBody, headers, secret) {
  const timestamp = headers['x-tone-timestamp'];
  const expected = `v1=${createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`)
    .digest('hex')}`;

  // The header may carry SEVERAL space-delimited signatures during a secret
  // rotation. Accept the message if any one matches.
  const provided = String(headers['x-tone-signature']).split(' ');
  const ok = provided.some(
    (sig) =>
      sig.length === expected.length &&
      timingSafeEqual(Buffer.from(sig), Buffer.from(expected)),
  );
  if (!ok) throw new Error('bad signature');

  // Reject anything too old for your tolerance. Five minutes is typical.
  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  if (age > 300) throw new Error('stale');

  return JSON.parse(rawBody);
}
import hmac, hashlib, time

def verify_tone(raw_body: bytes, headers, secret: str) -> bool:
    timestamp = headers["x-tone-timestamp"]
    expected = "v1=" + hmac.new(
        secret.encode(), f"{timestamp}.".encode() + raw_body, hashlib.sha256
    ).hexdigest()
    provided = headers["x-tone-signature"].split(" ")
    if not any(hmac.compare_digest(sig, expected) for sig in provided):
        return False
    return abs(time.time() - int(timestamp)) <= 300

Three things people get wrong:

  1. Sign the raw bytes, not a re-serialized object. If your framework parses JSON before you see it, JSON.stringify(req.body) will not reproduce the original bytes and every signature will fail. Configure a raw-body reader for this route.
  2. Compare in constant time. === on an HMAC leaks timing.
  3. Split on spaces. During a secret rotation the header carries one v1= signature per active secret. A verifier that treats the whole header as a single signature will start rejecting everything the moment you roll — and it'll look like an outage on our side.

The signature deliberately does not cover the URL path, so a proxy that rewrites your path won't break verification.

Rotating the secret

curl "$TONE_API/v1/integrations/webhooks/d81c.../roll-secret" \
  -X POST -H "Authorization: Bearer $TONE_ADMIN_KEY"

You get a new secret and a previousValidUntil about 24 hours out. During that window both secrets sign every delivery — which is exactly why your verifier must handle multiple signatures. Deploy the new secret at your leisure, and the old one stops after the window.

Only one rotation runs at a time. A second roll while the previous secret's 24-hour window is still open answers 409, naming when it closes. Read the current secret with GET /v1/integrations/webhooks/{id}/secret.

Sending a test

Check your handler end to end before a real call does: POST a body of your own to the endpoint, signed with its secret exactly as a delivery is.

curl "$TONE_API/v1/integrations/webhooks/d81c.../test" \
  -X POST \
  -H "Authorization: Bearer $TONE_LIVE_ADMIN_KEY" \
  -H 'content-type: application/json' \
  -d '{
    "eventType": "call.completed",
    "body": { "type": "call.completed", "data": { "call": { "id": "test-order-1", "outputs": { "order_confirmed": "confirmed" } } } }
  }'
{ "data": { "delivered": true, "status": 200, "error": null, "durationMs": 312, "eventId": "test_5b2c..." } }
  • body is sent byte for byte (at most 64 KB). eventType only sets the x-tone-event header.
  • The request carries x-tone-test: 1 and an x-tone-event-id starting test_. Otherwise your server sees a real delivery, so use test data — or skip on that header.
  • error says why nothing answered: timeout (10 seconds), unreachable or blocked_url.
  • Nothing is recorded: no delivery-log row, and a failed test never counts toward switching the endpoint off. You can test a switched-off endpoint before turning it back on.
  • At most 20 tests a minute. A live admin key or the dashboard only, like editing the endpoint.

In the dashboard: Settings → Webhooks → Send test on the endpoint. The body starts as a real delivery for your latest call, so the first test already has your outputs in it.

Responding

Return any 2xx. We don't read the body.

Anything else is a failure, and the split is deliberate:

  • 4xx (except 408 and 429) means your server understood and refused. We don't retry — retrying can't change a 400.
  • 5xx, 408, 429, timeouts, connection errors are retried.

Reply fast, work later. We give up on a delivery after 10 seconds. Verify the signature, enqueue the event, return 200. Doing your database writes and third-party calls inline is the most common cause of a webhook endpoint that fails under exactly the load it needs to survive — a campaign settles calls in clumps.

Retries

A failed delivery is retried with exponential backoff and jitter — 1, 2, 4, 8, 16, 32, 64, 128 minutes, then every four hours — for up to 14 attempts, which spans roughly a day. An overnight outage or a weekend deploy won't lose events.

x-tone-delivery-attempt tells you which attempt you're seeing. 1 is the first.

After 20 consecutive failures across all deliveries, the endpoint is switched off and we email your organization's owners and admins. Re-enable it from the dashboard once it's fixed. This isn't punitive: an endpoint that has been dead for a day is a queue that grows forever.

Handling duplicates

Design for at-least-once. A delivery whose response we never saw — you returned 200 a moment after our 10-second timeout — gets retried, and you'll process the same event twice.

Deduplicate on x-tone-event-id (identical to the payload's id), which is stable across every retry of that delivery. Storing it in a table with a unique constraint is the whole solution.

Also don't assume ordering. Deliveries go out in parallel, so even first attempts can arrive out of order: on a short call, call.initiated can land after call.completed, and a retry widens the gap. The body is the call as it is when the delivery is sent, not when the event happened, so that late call.initiated already reads "status": "ended". Treat type as "this happened" and data.call.status as "where the call is now", never move a call's state backwards, or reconcile against GET /v1/calls/{id}, which is always current.

Replaying what you missed

Your endpoint was down, or you're reconciling. GET /v1/events lists everything we sent, newest first, for the last 30 days — in your key's environment only: a test key lists test events, a live key everything else:

curl -H "Authorization: Bearer $TONE_KEY" \
  "$TONE_API/v1/events?type=call.completed&limit=100"
{
  "data": [
    {
      "id": "9e41b7c2-...",
      "type": "call.completed",
      "environment": "live",
      "subjectType": "call",
      "subjectId": "3b7e...",
      "createdAt": "2026-08-24T09:41:07.812Z",
      "delivery": {
        "endpointId": "d81c...",
        "status": "failed",
        "attempts": 14,
        "lastStatus": 502,
        "deliveredAt": null
      }
    }
  ]
}

The id is the same one we sent in x-tone-event-id, so reconciling against your own dedupe table needs no mapping. delivery tells you what actually happened to it — including that it failed 14 times against a 502.

Fetch one with its payload:

curl -H "Authorization: Bearer $TONE_KEY" "$TONE_API/v1/events/9e41b7c2-..."

One caveat worth knowing: the payload on this endpoint is re-rendered from current state, not replayed from a stored snapshot. If a transcript landed after the delivery went out, you'll see it here even though the original body didn't have it. That's usually what you want when reconciling — it's the truth now — but it means this is not a byte-for-byte record of what we signed.

An event subscribed by two endpoints appears twice, once per endpoint. Each is a genuinely separate delivery with its own outcome.

Was this page helpful?

On this page