Skip to content

Commands & flows ​

One JSON command language controls calls everywhere:

  1. REST — act on a live call from anywhere: POST /v1/calls/{id}/actions with { "commands": [...] }.
  2. Webhook reply — answer a call event with { "commands": [...] } (the TwiML equivalent).
  3. 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.

CommandFields (default)Notes
answer—Answer an inbound call explicitly (most commands auto-answer).
saytext, voice?, language?Text-to-speech.
playurl, loop (1, max 100)Audio file URL.
pauseseconds (0–60)Silence.
gatherinput (["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.
dialtargets (≥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.
transfertarget, mode (blind; or warm), summary?Warm transfers can pass an AI-written summary to the receiving agent.
conferencename, start_on_enter (true), end_on_exit (false), muted (false), role (participant; monitor/whisper/barge), whisper_to?Supervisor listen / whisper / barge.
enqueuequeue, hold_music_url?, max_wait_sec (600)Route to human agents via ACD.
recordaction (start; stop/pause/resume), channels (dual; or mono)Pause/resume around card numbers for PCI.
streamurl, 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_agentagent_id, variables?Hand the call to a hosted AI agent.
assistplaybook_id, action (start; stop), whisper_audio (false)Live sales advisor; suggestions arrive as call.assist.suggestion.
transcribeaction (start; stop), language?Live transcription (call.transcript.*).
send_dtmfdigits (0-9*#, w/W = pause)Navigate a remote IVR.
redirecturl? or flow_id?Continue with another webhook or flow.
smsbody, to? (default: the caller)Send an SMS during the call.
detect_machinewait_for_beep (false), timeout_sec (30)Answering-machine detection → call.machine_detection.
hangupreason?
rejectreason (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.