Calls on your Twilio

Base URL: https://chatsa.co/api/v1

Make and take phone calls on a business's own Twilio numbers: click-to-call for reps, inbound forwarding with voicemail and a missed-call text, and an AI that answers the phone from the business's ChatSa chatbot. The business's Twilio account carries and pays for the calls.

Being rolled out. Calls are not on yet: ask ChatSa when they will be. Until then every request answers 503 voice_disabled. AI answering is turned on separately; until then "ai_answers": true answers 409 ai_unavailable.

Paths are under https://chatsa.co/api/v1/voice. Authenticate with an API key that has voice:call, voice:read or voice:manage, or with a partner account key (which may do everything below). Phone numbers are E.164. Rate limits per key: 60 writes and 600 reads a minute (429 rate_limited, with Retry-After). A key limited to some chatbots sees and uses only the numbers connected to one of them.

Before the first call, save the Twilio credentials and connect the number with the SMS API (POST /sms/credentials, then POST /sms/numbers/{sid}/connect, scope sms:manage). So SMS must be on as well, and the number must be able to text. Disconnecting the number there gives its calls back too.

People's calls#

POST /api/v1/voice/calls
Authorization: Bearer csa_…

{
  "from_number": "+14155550123",
  "to": "+14155550199",
  "agent_phone": "+14155550111",
  "record": true,
  "detect_voicemail": false,
  "idempotency_key": "job-8812-call-1"
}

Scope voice:call.

  1. Twilio rings agent_phone (the rep's own phone) from from_number, for up to 25 seconds.
  2. When the rep answers they hear "Connecting you now." (with record: true: "This call is recorded. Connecting you now.").
  3. Twilio dials to for up to 30 seconds, showing from_number as the caller ID.
  4. With record: true, the customer hears "This call is recorded." when they pick up. ChatSa always announces a recording, so two-party-consent states such as California are covered. The recording has two channels, one per side.
  • agent_phone and to must differ.
  • detect_voicemail: true runs Twilio's answering machine detection on the customer's leg (it fills answered_by; Twilio charges extra).
  • idempotency_key is required (1–100 of A-Z a-z 0-9 . _ : -; the Idempotency-Key header works too), unique per workspace for good: the same key answers the first call again (200); with a different to, agent_phone or from_number it answers 409 idempotency_key_reused.
  • Quiet hours: no call before 8 am or from 9 pm at the customer's location, by the same rules as texts, except a call back within 30 minutes of the customer's own call or text.
AnswerMeaning
201Twilio is ringing the rep (status: "queued")
200A replay of an earlier call with this key
202 with status: "pending"Twilio timed out: the call may be ringing; call.completed will tell. It is never started again with this key.
400 invalid_requestA phone number is malformed, agent_phone is to, or idempotency_key is missing
404 number_not_foundfrom_number isn't a connected number this key may use
409 not_connected, needs_reconnectCredentials missing or refused
422 quiet_hoursWith allowed_at and time_zones
422 voice_not_supportedThe number can't make calls
422 twilio_refusedTwilio refused the call (id, status: "failed", twilio_code)
429 twilio_rate_limitedNothing was started: retry with the same key

GET /calls/{id} (voice:read) reads one call (with fresh recording links); GET /calls?contact=+1… lists a customer's calls, both ways, newest first (from_number, before, limit 1–100, default 50).

Inbound calls#

PUT /api/v1/voice/numbers/PN0123…

{
  "forward_to": "+14155550111",
  "ring_seconds": 20,
  "voicemail": true,
  "voicemail_greeting": "You've reached Acme Plumbing. Leave a message after the beep.",
  "missed_call_text": "Sorry we missed your call! Reply here and we'll help.",
  "record_inbound": false,
  "ai_answers": false,
  "replace": false
}

Scope voice:manage. The number must be connected (404 number_not_connected otherwise). Fields left out keep their value; null clears forward_to, the greetings and missed_call_text.

FieldDefaultMeaning
forward_tononeWho rings when a customer calls (the phone shows the caller's number). Not the number itself.
ring_seconds205–60
voicemailtrueTake a message when nobody answers: the greeting, a beep, then up to 2 minutes (# ends it)
voicemail_greeting"You've reached (the business). Please leave a message after the beep, and we'll call you back."Up to 500 characters
missed_call_textnoneTexted to the caller when nobody answers (up to 480 characters), once per call, through every SMS rule: a caller who opted out of texts gets none
record_inboundfalseRecord forwarded calls; the caller hears "This call is recorded." first
ai_answersfalseThe AI answers first (below)
greetingthe chatbot's greetingThe AI's first words (up to 500 characters)
chatbot_idas connectedThe chatbot whose knowledge, voice and persona answer the calls; null unties the number
replacefalseTake the number's calls from another webhook or TwiML app (below)

When a customer calls:

  1. The AI answers, when AI answering is on (below).
  2. Otherwise forward_to rings for ring_seconds.
  3. When nobody answers, or there is no forward_to: the missed-call text goes out, then voicemail takes a message. With voicemail off, the caller hears that no one is available.

ChatSa takes the number's calls only while forward_to, ai_answers or voicemail is on. voicemail is on by default, so the first PUT takes the calls unless it sends "voicemail": false and no forward_to. Never silent: a number whose calls go to another webhook or TwiML app answers 409 voice_webhook_in_use with current: { voice_url, voice_application_sid } and changes nothing; send "replace": true to take it. The previous set-up is put back when inbound calling is switched off or the number is disconnected.

ErrorWhen
400 invalid_requestA field is malformed, or forward_to is the number itself
403 forbiddenA chatbot_id this key may not use, or null with a key limited to chatbots
404 number_not_connectedConnect the number first
404 not_foundchatbot_id isn't one of the workspace's chatbots
404 number_not_foundThe number is no longer on the Twilio account
409 voice_webhook_in_useSee above
409 voice_on_sip_trunkThe number's calls go to a SIP trunk: remove it from the trunk in Twilio first
409 ai_unavailable, chatbot_requiredAI answering isn't on yet, or the number has no chatbot
409 not_connected, needs_reconnectCredentials missing or refused
422 voice_not_supportedThe number can't take calls
502 ai_setup_failedThe AI could not be set up: the other settings were saved, AI answering stays as it was. Try again.
502 twilio_unavailableTwilio could not be reached, or didn't update the number

GET /numbers (voice:read) lists the connected numbers' settings; GET /numbers/{sid} reads one. Besides the fields above, each has sid, phone_number, capabilities, inbound_calls (ChatSa takes the number's calls now) and ai_ready (AI answering is on and set up).

AI answering#

PUT /numbers/{sid} with { "ai_answers": true, "greeting": "Thanks for calling Acme Plumbing!", "chatbot_id": "6f1c…" }. The number must be tied to a chatbot (409 chatbot_required otherwise); a chatbot_id in the same request does it.

  • The AI answers from the chatbot's knowledge, in its voice and language (or the caller's, when they speak another), and can ask your connected app who is calling and pass on questions only your data can answer (see Connect).
  • On a North American (+1) number it says first that it is the business's AI assistant (California SB 1001): "Hi, you've reached Acme Plumbing's AI assistant. This call is recorded. Thanks for calling Acme Plumbing!" On other numbers it opens with the greeting, then "This call is recorded." It never claims to be a person or denies being an AI.
  • AI calls are always recorded.
  • With forward_to set, it can transfer the caller to a person; if nobody answers, the missed-call text and voicemail follow. Without forward_to, it offers to take a message.
  • AI calls use the workspace plan's voice minutes. If the AI can't take a call (less than a minute left on the plan, for example), the call goes on as if AI answering were off: forward_to, then voicemail.
  • AI calls last at most 15 minutes.

The Call object and call.completed#

{
  "id": "5d3f…",
  "direction": "outbound",
  "ai": false,
  "mode": "bridge",
  "from": "+14155550123",
  "to": "+14155550199",
  "contact": "+14155550199",
  "agent_phone": "+14155550111",
  "status": "completed",
  "outcome": "conversation",
  "agent_answered": true,
  "client_answered": true,
  "answered_by": "unknown",
  "both_spoke": true,
  "both_spoke_basis": "answered_duration",
  "duration_sec": 120,
  "talk_sec": 95,
  "recording_url": "https://www.chatsa.co/api/v1/voice/recordings/5d3f…?kind=call&expires=…&signature=…",
  "recording_expires_at": "…",
  "voicemail_url": null,
  "voicemail_duration_sec": null,
  "transferred": false,
  "transcript": null,
  "summary": null,
  "missed_call_text_id": null,
  "chatbot_id": null,
  "twilio_call_sid": "CA…",
  "started_at": "…",
  "ended_at": "…"
}
  • mode: bridge (a rep's call), forward (an inbound call rung through), voicemail, or ai. An AI call keeps ai after a transfer (transferred: true).
  • contact is the customer; agent_phone is the rep, or the forward_to number rung for an inbound call.
  • status is Twilio's call status (queued, ringing, in-progress, completed, busy, no-answer, failed, canceled), or pending after a timeout.
  • outcome: conversation, short, agent_no_answer, no_answer, busy, failed, canceled, missed or voicemail; in_progress until the call ends.
  • answered_by: with voicemail detection, human, machine, fax or unknown; without it, unknown once the customer answered, else null.
  • both_spoke is what to count as a real conversation: for people's and forwarded calls, both sides answered (not a machine or fax, when detection is on) and talked at least 10 seconds; for AI calls, the caller spoke in the transcript.
  • AI calls carry transcript (Agent: / User: lines) and summary. Their recording_url is the AI conversation's recording, or the person's part after a transfer with record_inbound on.
  • missed_call_text_id is the id of the text sent after a missed call; read it with GET /sms/messages/{id}.

call.completed (data = the Call object) is sent once per call, when the call has ended and its recording, voicemail or AI transcript has arrived. If one never arrives, it is sent without it 10 to 15 minutes after the call ended. call.voicemail (id, from, to, duration_sec, recording_url, recording_expires_at, at) is sent when a voicemail is ready. Subscribe to call.* or each event (Webhooks); they reach your endpoints the same way as SMS events.

Recordings#

recording_url and voicemail_url are signed links, valid 1 hour, that need no API key: the link is the authorization. An expired or altered link answers 404; GET /calls/{id} gives fresh ones. Links in events expire an hour after the event was made, retries included, so fetch the audio promptly or read the call again. Follow redirects: a Twilio recording (MP3) may come as a redirect to Twilio's own short-lived link.

ChatSa stores no audio: recordings stay in the business's Twilio account (people's and forwarded calls, voicemail) or with ChatSa's voice provider (AI calls), and a person's erasure deletes them there too.