API · Connect your systems
Hooks
A hook is a rule you set: when the call starts, or when the visitor says certain words, we call your server and wait for the answer, so it is in hand before the avatar replies. No holding line, no judgement call by the AI: the rule matches, the hook runs.
Two triggers
| call_start | pattern | |
|---|---|---|
| Runs | Once, as the call starts | On every visitor turn (spoken or typed) whose words match. Never on the avatar's own lines |
| Your server gets | The session, your ids, the language | The same, plus the visitor's words (text) and what matched (match) |
| The visitor waits? | No: it runs while the greeting plays. An AI-written greeting waits up to 1.5 s for it; a fixed or exact greeting doesn't wait, and a late answer rides the first reply | Yes: the reply waits for your answer |
timeout_s | 1 to 10 seconds, default 5 | 0.5 to 5 seconds, default 2 |
| Typical use | Who is this visitor? Their orders, plan, open tickets. And: telling your server a call has started, with its session_id | Fetch details when a topic or an id comes up: returns, opening hours, an order number |
Create a hook
/v1/agent/{agent_id}/hooksA call-start hook that loads the visitor's open orders for the whole call:
curl -X POST https://talk.selviaai.com/v1/agent/7/hooks \
-H "Authorization: Bearer $SELVIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "open_orders",
"trigger": "call_start",
"url": "https://shop.example.com/selvia/hooks/open-orders",
"headers": {"Authorization": "Bearer YOUR_OWN_TOKEN"},
"scope": "call"
}'A pattern hook that fetches the returns policy when the visitor talks about returns:
curl -X POST https://talk.selviaai.com/v1/agent/7/hooks \
-H "Authorization: Bearer $SELVIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "returns_policy",
"trigger": "pattern",
"pattern": {"words": ["return", "returns", "refund", "money back"]},
"url": "https://shop.example.com/selvia/hooks/returns",
"timeout_s": 1.5
}'| Field | Rule |
|---|---|
name | Lowercase letters, digits and _, starting with a letter, at most 64. Unique per agent. |
title | Optional. A readable name for people, like “Order details”: at most 80 characters, one line. The console shows it. |
trigger | call_start or pattern. |
pattern | Pattern hooks only: {"words": [...]} or {"regex": "..."}. Read “Patterns” below. |
url | Your endpoint. https:// only, a public address. See Your endpoint. |
headers | Up to 10 of your own headers, such as an API key for your server. Stored encrypted, never shown again (lists show a short hint). |
scope | What your data is used for: turn (default) the next reply only, call every reply until the call ends. |
timeout_s | See the table above. |
enabled | false keeps the hook but stops it running. |
The first tool or hook you add to an agent comes back with the agent's signing secret (whsec_…). It is shown this once: store it on your server, and use it to check that our calls are really ours.
201 Created (the agent's first tool or hook)
{
"name": "open_orders",
"trigger": "call_start",
"scope": "call",
"timeout_s": 5,
"url": "https://shop.example.com/selvia/hooks/open-orders",
"headers": [{ "name": "Authorization", "hint": "…OKEN" }],
"enabled": true,
"signing_secret": "whsec_…",
"signing_secret_note": "Shown once. Use it to check X-Selvia-Signature on our calls; …"
}What your server receives
An HTTPS POST, signed, with Content-Type: application/json. The full list of fields and headers is on Your endpoint.
call_start
{
"type": "hook",
"name": "open_orders",
"trigger": "call_start",
"session_id": "8d137734-f23f-4f1b-8480-0a57b8463ebb",
"external_user_id": "u_88",
"agent_id": 7,
"language": "en",
"call_id": "c_4ac8142cec942a99",
"sent_at": "2026-11-27T17:43:37Z"
}pattern
{
"type": "hook",
"name": "returns_policy",
"trigger": "pattern",
"match": "refund",
"text": "What's your refund policy?",
"turn_id": 3,
"session_id": "8d137734-f23f-4f1b-8480-0a57b8463ebb",
"agent_id": 7,
"language": "en",
"call_id": "c_55319de1bcba1e70",
"sent_at": "2026-11-27T17:45:35Z"
}external_user_id and external_session_id are there when the session was started with them. Use the session_id to send messages to this call later, from anywhere in your systems.
Your answer
A JSON object, status 200. Every part is optional; {} means “nothing to add”.
| Field | What we do with it |
|---|---|
data | Any JSON. Given to the AI as information from your system, labelled with the hook's name, for one reply (scope: turn) or every reply (scope: call). At most 8,000 characters reach the AI; keep it to what the conversation needs. |
messages | Optional messages, exactly as you would post them mid-call: an instruction for the next reply, a call-scope fact, or an exact line for the next pause. |
Answer to call_start (kept for the whole call)
{
"data": {
"open_orders": [
{ "order_id": "A4512", "items": "leather sandals", "status": "shipped", "arrives": "Friday" },
{ "order_id": "A4630", "items": "white trainers", "status": "packing" }
]
}
}Answer to pattern, with a message
{
"data": { "returns": "Free returns within 30 days of delivery. Refunds reach the card in 5 business days." },
"messages": [
{ "text": "If she wants to return something, offer to start the return for her.", "scope": "turn" }
]
}⚠ scope: turn data is forgotten after one reply
scope: "turn", the AI sees your data for its next reply only, then has no recollection of it: only what it said aloud stays in the conversation. Facts the AI should keep for the rest of the call need scope: "call" on the hook, or a call-scope message in your answer.Patterns
words
{"words": ["refund", "money back"]}: the hook runs when the visitor's turn contains any of them as whole words, in any case. Phrases work. Up to 50 words or phrases. match tells you which one matched.
regex
{"regex": "\\b[A-Z]\\d{4,6}\\b"}: the hook runs when the regular expression finds a match. Up to 500 characters; it is checked when you save it. Matching is case-sensitive: start with (?i) to ignore case. A pattern that takes too long on a turn is skipped for that turn.
⚠ The visitor's words are speech turned into text
A4512, a 4512, A-4512 or A four five one two; “e-mail” as email. Write patterns that allow for this, try them with the Test call (below) using a few spellings, and prefer a tool when the value must be exact: the AI reads it from the whole conversation and sends it clean.Timing
⚠ Pattern hooks hold the reply
- •Same words, same answer. Within one call, when the same pattern hook matches the same words again, the first answer is used again and your server isn't called. A new match (another order number) calls you again.
- •No answer, no guessing. If your server times out, errors, or answers something that isn't a JSON object, the AI is told your system didn't answer and not to guess. The call goes on.
- •One retry. A connection error or a 502, 503 or 504 is retried once if time is left, with the same
call_id.
Test, list, change, delete
/v1/agent/{agent_id}/hooks/{name}/testCalls your endpoint once from our server, signed like a live call, with "test": true in the body and session_id: null. Send {"text": "I want a refund"} to try a pattern hook with a sample line. The answer shows your server's status, its time, your answer, and anything a live call would skip or cut. At most 10 tests a minute per agent.
| Route | Does |
|---|---|
GET /v1/agent/{agent_id}/hooks | Every hook of the agent (header values hidden), and whether it has a signing secret. |
GET /v1/agent/{agent_id}/hooks/{name} | One hook. |
PATCH /v1/agent/{agent_id}/hooks/{name} | Change any field but the name. Sending headers replaces them all; {} removes them. |
DELETE /v1/agent/{agent_id}/hooks/{name}?confirm=true | Delete it. |