Commands & flows
One JSON command language controls calls everywhere:
- REST — act on a live call from anywhere:
POST /v1/calls/{id}/actionswith{ "commands": [...] }. - Webhook reply — answer a call event with
{ "commands": [...] }(the TwiML equivalent). - JSON flows — save a command list as a call flow (
{ "version": 1, "start": [...] }) and attach it to numbers, calls or campaigns.
ts
import { VoiceResponse, Flow, say } from "@kolwire/sdk";
// 1. REST
await vi.calls.actions(callId, { commands: [{ command: "say", text: "Please hold." }, { command: "enqueue", queue: "support" }] });
// 2. Webhook reply — serializes to { commands: [...] }
res.json(new VoiceResponse().say("Hi!").connectAgent("agt_123"));
// 3. Flow — serializes to { version: 1, start: [...] }
const flow = new Flow()
.say("Thanks for calling Acme.")
.gather({ input: ["dtmf", "speech"], max_digits: 1, prompt: say("Press 1 or say sales. Press 2 or say support.") }, {
"1": (b) => b.enqueue("sales"),
sales: (b) => b.enqueue("sales"),
"2": (b) => b.connectAgent("agt_support"),
default: (b) => b.say("Sorry, goodbye.").hangup(),
})
.build();
await vi.callFlows.create({ name: "Main IVR", definition: flow });python
from kolwire import VoiceResponse, Flow, say
client.calls.actions(call_id, commands=[{"command": "say", "text": "Please hold."},
{"command": "enqueue", "queue": "support"}])
VoiceResponse().say("Hi!").connect_agent("agt_123").to_dict()
flow = Flow().say("Thanks for calling Acme.").gather(
input=["dtmf", "speech"], max_digits=1,
prompt=say("Press 1 or say sales. Press 2 or say support."),
branches={
"1": lambda b: b.enqueue("sales"),
"sales": lambda b: b.enqueue("sales"),
"2": lambda b: b.connect_agent("agt_support"),
"default": lambda b: b.say("Sorry, goodbye.").hangup(),
},
).to_dict()
client.call_flows.create(name="Main IVR", definition=flow)Command reference
Defaults are applied server-side when a field is omitted.
| Command | Fields (default) | Notes |
|---|---|---|
answer | — | Answer an inbound call explicitly (most commands auto-answer). |
say | text, voice?, language? | Text-to-speech. |
play | url, loop (1, max 100) | Audio file URL. |
pause | seconds (0–60) | Silence. |
gather | input (["dtmf"]; dtmf/speech), prompt? (a say or play), max_digits (1, max 64), timeout_sec (5, 1–60), terminator ("#"), language?, branches?, action_url? | Emits call.gather.completed. branches (flows only) maps digits or a speech keyword to a command list; "default" runs when nothing matched. action_url overrides where the result is posted in webhook mode. |
dial | targets (≥1: E.164, sip:uri, client:<user>, agent:<team_agent_id>), strategy (sequential; or simultaneous), timeout_sec (30, 5–120), caller_id?, record?, whisper? | whisper is said to the callee before connecting. |
transfer | target, mode (blind; or warm), summary? | Warm transfers can pass an AI-written summary to the receiving agent. |
conference | name, start_on_enter (true), end_on_exit (false), muted (false), role (participant; monitor/whisper/barge), whisper_to? | Supervisor listen / whisper / barge. |
enqueue | queue, hold_music_url?, max_wait_sec (600) | Route to human agents via ACD. |
record | action (start; stop/pause/resume), channels (dual; or mono) | Pause/resume around card numbers for PCI. |
stream | url, action (start; stop), track (both; inbound/outbound), bidirectional (false), codec (pcm16; mulaw), sample_rate (16000; 8000) | Raw audio to your WebSocket — BYO voice agent. |
connect_agent | agent_id, variables? | Hand the call to a hosted AI agent. |
assist | playbook_id, action (start; stop), whisper_audio (false) | Live sales advisor; suggestions arrive as call.assist.suggestion. |
transcribe | action (start; stop), language? | Live transcription (call.transcript.*). |
send_dtmf | digits (0-9*#, w/W = pause) | Navigate a remote IVR. |
redirect | url? or flow_id? | Continue with another webhook or flow. |
sms | body, to? (default: the caller) | Send an SMS during the call. |
detect_machine | wait_for_beep (false), timeout_sec (30) | Answering-machine detection → call.machine_detection. |
hangup | reason? | |
reject | reason (rejected; or busy) | Reject an inbound call without answering. |
Commands run in order. A command that waits for input (gather, dial, enqueue, connect_agent) holds the list until it completes; in webhook mode the next event is posted to you and your reply continues the call.
JSON flows
json
{
"version": 1,
"start": [
{ "command": "say", "text": "Thanks for calling." },
{ "command": "gather", "max_digits": 1, "prompt": { "command": "say", "text": "Press 1 for sales." },
"branches": {
"1": [{ "command": "enqueue", "queue": "sales" }],
"default": [{ "command": "hangup" }]
} }
]
}Attach a flow to a number (voice_config: { mode: "flow", flow_id }), to an outbound call (flow_id on calls.create) or to a campaign. Flows are validated when saved.