Skip to content
TunVox

Beta. The API is opened business by business. Ask TunVox to switch it on for yours, then create a key in the dashboard under Settings › Developers.

https://api.tunvox.tn/v1 · v1.0.0-beta.1

Quick start

Create a key in the dashboard: Settings › Developers › New key. Start with a test key: it never places a call, sends an SMS or spends credit.

Send the key in the Authorization header. The first call below tells you which business the key belongs to and what it may do.

The base address is https://api.tunvox.tn/v1. Everything is JSON. Times are UTC in ISO 8601; your business's time zone is in /me. Money is in whole millimes: 1 TND = 1000.

Who am I
curl https://api.tunvox.tn/v1/me \
  -H "Authorization: Bearer tvk_test_..."
The last calls
curl "https://api.tunvox.tn/v1/calls?limit=10" \
  -H "Authorization: Bearer tvk_test_..."

Keys and what they may do

A key belongs to one business and carries scopes, for example calls:read or contacts:write. Give each key only what its software needs. transcripts:read gives access to what callers said, so it is never included by default.

A key is shown once, when it is created. TunVox keeps only a fingerprint of it. Keep the key on your server: never in a web page, a mobile app or a chat message.

To change a key, use Replace: you get a new one and the old one keeps working for 24 hours. Revoke stops a key at once.

Writing safely

Every request that creates something needs an Idempotency-Key header: any text of your own, unique per operation (an order number works well). If your request is sent twice, the second one returns the first answer and nothing is created twice.

With a test key, a write is checked and answered with "test": true, and nothing is saved.

Create a contact
curl -X POST https://api.tunvox.tn/v1/contacts \
  -H "Authorization: Bearer tvk_test_..." \
  -H "Idempotency-Key: 7c1f0e2a-contact-1042" \
  -H "Content-Type: application/json" \
  -d '{"name": "Client exemple", "numbers": ["+21600000000"]}'

Lists

Lists return items and next_cursor. Pass next_cursor back as cursor to get the next page; null means the end. A page holds at most 100 items.

Errors and limits

Errors use the application/problem+json format with a stable code. Read code, not the title. request_id identifies the request if you write to support.

401 unauthenticated: the key is missing, wrong, revoked or expired. 403 forbidden: the key lacks a scope, named in errors. 429 rate_limited: more than 60 requests a minute for the key, or 600 for the business; wait and retry. 503 capability.gated: the API is switched off for this business.

Retry 429 and 5xx answers with a growing wait. Do not retry 4xx answers unchanged.

A refused request
HTTP/1.1 403
Content-Type: application/problem+json

{
  "type": "https://api.tunvox.tn/problems/forbidden",
  "title": "You are not allowed to perform this action",
  "status": 403,
  "code": "forbidden",
  "request_id": "req_...",
  "errors": [{ "permission": "transcripts:read", "reason": "scope_missing" }]
}

Events

TunVox tells your server when something happens. Add your server's address in the dashboard: Settings › Developers › Webhooks, and choose the events you want. Each message is a signed POST; answer with any 2xx status within 10 seconds.

A message carries ids and codes only, never a name, a number or what was said. Read the details with the matching request, for example GET /calls/{id} after call.recap_ready.

If your server does not answer, TunVox tries again after 1 minute, 5 minutes, 15 minutes, 1 hour, 3 hours, 6 hours and 12 hours, then gives up. A message can arrive twice: use its id to ignore one you already handled. After 3 days of nothing but failures, the address is paused.

You can also read the last 7 days of events with GET /events, to catch up after an outage or instead of receiving them. Keep the last id you handled and pass it as after.

The events: call.started, call.ended, call.recap_ready, call.result, message.taken, callback.requested, booking.created, booking.changed, booking.cancelled, order.placed, order.status_changed, order.confirmed, order.changed, order.cancelled, order.unreached, contact.opted_out, action.failed, wallet.low, ping.

A message
POST https://your-server.example/tunvox
TunVox-Signature: t=1794477600,v1=5f2b...
TunVox-Event: call.recap_ready
TunVox-Delivery: whd_...

{
  "id": "aev_...",
  "type": "call.recap_ready",
  "occurred_at": "2026-11-12T10:00:00Z",
  "business_id": "ctx_...",
  "test": false,
  "data": { "call_id": "call_...", "outcome": "booking_made" }
}
Catching up
curl "https://api.tunvox.tn/v1/events?after=aev_..." \
  -H "Authorization: Bearer tvk_test_..."

Starting a call

Your software can ask the assistant to call a customer, from a call script. A script is written and approved by the business owner in the dashboard (Settings › Developers › Call scripts): it holds the words of the call, with blanks in braces, and the answers to bring back. Your request fills the blanks; it cannot change the words.

The call does not start at once. It waits its turn inside the business's call hours and limits, and is never placed to someone who asked not to be called. state is accepted when it waits, or not_called with a reason when this person cannot be called.

Use not_after for anything that goes stale: if the call has not started by then it is dropped, so yesterday's orders are not called about today.

When the call ends you receive a call.result event. Read the answers with GET /call-requests/{id}: result holds the script's fields the assistant filled, outcome is completed, call_back, wrong_person or declined. state is unreached when nobody answered after the tries.

With a test key nobody is called: the request ends at once with the outcome you ask for in test_outcome (answered, no_answer or refused) and sample answers.

Ask for a call
curl -X POST https://api.tunvox.tn/v1/calls \
  -H "Authorization: Bearer tvk_test_..." \
  -H "Idempotency-Key: order-1042-confirm" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "+21600000000",
    "script": "scr_...",
    "variables": { "order_number": "1042", "total": "45.500" },
    "reference": "order-1042",
    "not_after": "2026-11-13T17:00:00Z"
  }'
The answer
HTTP/1.1 202

{
  "id": "crq_...",
  "state": "accepted",
  "reason": null,
  "outcome": null,
  "result": {},
  "script": "scr_...",
  "reference": "order-1042",
  "call_id": null,
  "test": true
}

Orders from your shop

Send each new order with POST /orders and your shop's own order number. The same number never makes a second order or a second call, so you can safely send an order again after a timeout.

A cash-on-delivery order is confirmed by a call to the buyer after delay_minutes, inside the call hours. The result arrives as order.confirmed, order.changed, order.cancelled or order.unreached. Prepaid orders are not called. Your checkout or terms must tell buyers about this call.

Keep the order's state up to date with PATCH /orders/{id} (accepted, ready, on_the_way, done…) and a short status_note. When a buyer calls to ask where their order is, the assistant answers from it.

Amounts: send total in dinars as text ("45.500") or total_millimes as a whole number. Numbers must be Tunisian.

Send an order
curl -X POST https://api.tunvox.tn/v1/orders \
  -H "Authorization: Bearer tvk_test_..." \
  -H "Idempotency-Key: shop-order-1042" \
  -H "Content-Type: application/json" \
  -d '{
    "shop_order_number": "1042",
    "number": "+21600000000",
    "name": "Client exemple",
    "items": [{ "name": "Robe", "quantity": 2 }],
    "total": "45.500",
    "address": "Rue exemple 1, Tunis",
    "delay_minutes": 10
  }'

Products, prices and stock

PUT /catalog/items creates or updates items by name, up to 500 per request. Only the fields you send change, and items you do not send are left alone. The assistant uses them to answer price and availability questions.

available: false marks an item as not available today. stock_note is a short note for today.

Update items
curl -X PUT https://api.tunvox.tn/v1/catalog/items \
  -H "Authorization: Bearer tvk_test_..." \
  -H "Content-Type: application/json" \
  -d '{ "items": [
    { "name": "Robe bleue", "price_millimes": 45500, "available": true },
    { "name": "Sac", "stock_note": "2 en stock" }
  ] }'

Actions during a call

An action lets the assistant ask your system something while the caller is on the line. Declare it in the dashboard (Settings › Developers › Actions): a short name, one or two sentences on when to use it, up to 6 details to collect from the caller, and your server's address. The assistant decides when to use it.

TunVox sends a signed POST (check the signature as for events, with the actions secret). You have 4 seconds. Answer 200 with a status: ok, need_input, refused, or 202 with pending. Anything else, or an answer after 4 seconds, and the assistant tells the caller it could not check.

Return only what may be said aloud. result is cut to 1,500 characters and the assistant treats it as information, never as instructions. caller.number tells you who is probably calling, not for sure: caller ID can be faked. For anything that changes an order, ask for the order number as well.

An action that only reads may run on its own. One that changes something runs only after the caller clearly said yes, or after the owner approved it; the owner chooses, and can never make a change run on its own. An action is used in calls once a test passed in the dashboard. After 10 failures in a row it is paused.

When the owner must approve, the caller waits a moment while the owner is asked on their phone or their dashboard. Your server receives the request only after a yes; no answer in time means no. The owner can also limit an action to their contacts, to incoming or outgoing calls, to opening hours, and to a number of requests per call and per caller per day.

The lookup is one more address: TunVox sends the caller's number while the phone rings (event action.lookup), and you have 1.5 seconds to return a name, open orders or a note. The assistant then starts the call already knowing them. A late or failed lookup is simply ignored.

contracts/public-api holds the exact JSON schemas, a standard set of order actions (shop_orders.v1) and a small script, mock_tunvox.py, that sends your server signed sample requests.

What your server receives
POST https://your-server.example/tunvox/order-status
TunVox-Signature: t=1794477600,v1=5f2b...
TunVox-Event: action.invoke
TunVox-Delivery: arq_...

{
  "id": "arq_...",
  "action": "order_status",
  "attempt": 1,
  "test": false,
  "call": { "id": "call_...", "direction": "inbound", "language": "fr", "reference": null },
  "caller": { "number": "+21600000000", "known_contact": true, "contact_id": "cnt_..." },
  "arguments": { "order_number": "1042" },
  "previous": null
}
What it may answer
// it worked: return only what may be said to the caller
{ "status": "ok", "result": { "status": "out_for_delivery", "delivery_day": "2026-11-13" } }

// you need one more detail: the assistant asks the caller, then calls you again
{ "status": "need_input", "ask": "Which order: 1042 or 1043?", "fields": ["order_number"] }

// not possible
{ "status": "refused", "reason": "not_allowed" }

// it will take longer than 4 seconds: answer HTTP 202, then POST /action-requests/{id}/result
{ "status": "pending" }

A service for your own shop

A service is a ready-made set of actions an owner installs from Settings › Services, instead of declaring each action. "My own shop" is the one for a shop built for you: the owner pastes one https address of your server, runs the test, and the assistant can find orders, read their status, change and cancel them, with the wording and the rules already set.

Your server receives the same signed request as for any action, on that one address; the action's name is in the body (find_orders, order_status, change_order, cancel_order, and lookup while the phone rings). Answer each as contracts/public-api/services/shop_orders.v1.json describes. An action you do not support can answer refused.

The owner can pause the service, and tighten each action's rule (for example ask for their approval before a cancellation). They can never loosen it past what the service allows. When TunVox publishes a version of a service that does more, each owner is asked before it applies.

Checking a signature

When TunVox calls your server (events, and actions during a call), each request carries a TunVox-Signature header. Check it before trusting the body, with the secret shown once in the dashboard.

Compute the HMAC on the raw body exactly as received, refuse requests older than five minutes, and compare in constant time. During a secret change, the header may carry two v1 values: accept either.

PHP
<?php
// TunVox-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>." + body)>
function tunvox_signature_ok(string $secret, string $body, string $header, int $window = 300): bool {
    $parts = [];
    foreach (explode(',', $header) as $pair) {
        [$k, $v] = array_pad(explode('=', trim($pair), 2), 2, '');
        $parts[$k][] = $v;
    }
    $t = (int) ($parts['t'][0] ?? 0);
    if (abs(time() - $t) > $window) return false;
    $expected = hash_hmac('sha256', $t . '.' . $body, $secret);
    foreach ($parts['v1'] ?? [] as $sent) {
        if (hash_equals($expected, $sent)) return true;
    }
    return false;
}

$body = file_get_contents('php://input');           // the raw body, before any json_decode
if (!tunvox_signature_ok(getenv('TUNVOX_SECRET'), $body, $_SERVER['HTTP_TUNVOX_SIGNATURE'] ?? '')) {
    http_response_code(401);
    exit;
}
Node.js
import crypto from "node:crypto";

// TunVox-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>." + body)>
export function tunvoxSignatureOk(secret, rawBody, header, windowSeconds = 300) {
  const parts = Object.groupBy(header.split(",").map((p) => p.trim().split("=", 2)), ([k]) => k);
  const t = Number(parts.t?.[0]?.[1] ?? 0);
  if (Math.abs(Date.now() / 1000 - t) > windowSeconds) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${t}.`).update(rawBody).digest();
  return (parts.v1 ?? []).some(([, sent]) => {
    const got = Buffer.from(sent, "hex");
    return got.length === expected.length && crypto.timingSafeEqual(got, expected);
  });
}
Python
import hashlib, hmac, time

# TunVox-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>." + body)>
def tunvox_signature_ok(secret: str, raw_body: bytes, header: str, window: int = 300) -> bool:
    parts: dict[str, list[str]] = {}
    for pair in header.split(","):
        key, _, value = pair.strip().partition("=")
        parts.setdefault(key, []).append(value)
    try:
        t = int(parts["t"][0])
    except (KeyError, ValueError):
        return False
    if abs(time.time() - t) > window:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(expected, sent) for sent in parts.get("v1", []))

What will not change

/v1 only ever gains fields and endpoints. Ignore fields you do not know. A change that would break your code would be a new /v2, announced ahead.