Calling SWML overview
Calling SWML is the flavor of SWML used to handle voice calls — inbound calls arriving on a phone number configured with a SWML calling handler, outbound REST-initiated calls that point at a SWML URL, and re-fetches triggered by methods that hit an external URL.
For handling inbound SMS and MMS messages, see the Messaging SWML overview.
Document structure
A Calling SWML document follows the standard
SWML document structure — a top-level sections map with
sections.main as the entry point. Each section contains an array of calling methods
that run sequentially.
Webhook and variable payload
When SignalWire fetches a Calling SWML document from an external URL, it POSTs this payload to
your server — on the initial inbound fetch and on every fetch triggered by a method that hits
an external URL (execute with a remote URL,
transfer,
join_conference.wait_url,
enter_queue.wait_url, and
connect.confirm). Your server must respond
with a valid SWML document using one of these content types: application/json,
application/yaml, or text/x-yaml.
Inside the executing document, the call, params, and envs fields are available for
variable expansion via ${...} (JavaScript expressions) and %{...} (path substitution). As
the script runs, methods also populate the vars.* runtime scope — those values are not in
the initial inbound payload, but they are propagated across transfer boundaries and delivered
on subsequent fetches.
call
Information about the current call. Call-specific and read-only. Each call leg (A-leg, B-leg)
has its own unique call object with different call_id, from, to, etc. When connecting
to a new leg, the call object is re-initialized with the new leg’s data.
call.call_id
A unique identifier for the call.
call.call_state
The current state of the call.
call.direction
The direction of this call. Possible values: inbound, outbound.
call.from
The number/URI that initiated this call.
call.headers
The headers associated with this call.
call.headers[].name
The name of the header.
call.headers[].value
The value of the header.
call.node_id
A unique identifier for the node handling the call.
call.project_id
The Project ID this call belongs to.
call.segment_id
A unique identifier for the current call segment.
call.space_id
The Space ID this call belongs to.
call.to
The number/URI of the destination of this call.
call.type
The type of call. Possible values: sip, phone, webrtc.
call.sip_data
SIP-specific data for SIP calls. Only present when call.type is sip. Contains detailed
SIP header information.
call.sip_data.sip_contact_host
The host portion of the SIP Contact header.
call.sip_data.sip_contact_params
Additional parameters from the SIP Contact header.
call.sip_data.sip_contact_port
The port from the SIP Contact header.
call.sip_data.sip_contact_uri
The full URI from the SIP Contact header.
call.sip_data.sip_contact_user
The user portion of the SIP Contact header.
call.sip_data.sip_from_host
The host portion of the SIP From header.
call.sip_data.sip_from_uri
The full URI from the SIP From header.
call.sip_data.sip_from_user
The user portion of the SIP From header.
call.sip_data.sip_req_host
The host portion of the SIP request URI.
call.sip_data.sip_req_uri
The full SIP request URI.
call.sip_data.sip_req_user
The user portion of the SIP request URI.
call.sip_data.sip_to_host
The host portion of the SIP To header.
call.sip_data.sip_to_uri
The full URI from the SIP To header.
call.sip_data.sip_to_user
The user portion of the SIP To header.
params
vars
Runtime variable scope, populated by methods as the script executes. Not part of the
initial inbound payload — values appear here only after a method that sets them has run.
The full vars object is propagated across transfer boundaries (and on remote-URL
execute) and delivered as a top-level vars field on subsequent webhook payloads.
Created by: set — explicitly create or update
variables. Method outputs — many methods auto-populate variables (e.g., prompt_value,
record_url, return_value). See each method’s reference page for what it sets.
Removed by: unset.
Scope: Global within a single call session. Variables persist across all sections and
through execute calls. Connecting to a new call leg resets the vars object to an empty
state.
Access: Variables can be accessed with or without the vars. prefix. When you reference
a variable without a scope prefix (e.g., ${my_variable}), SWML first checks vars. If not
found in vars, it automatically falls back to envs.
envs
Environment variables configured at the account or project level. Account/project-scoped and read-only. Set in your SignalWire account configuration, not within SWML scripts.
Fallback behavior: When you reference a variable without a scope prefix (e.g.,
${my_variable}), SWML first checks vars. If not found in vars, it automatically falls
back to envs.
The envs object is included in POST request bodies to external servers, but the ability
to set environment variables in the SignalWire Dashboard is not yet available in
production. This feature is coming soon.
See Variables for variable-expansion syntax, deployment-mode differences, and tips on accessing nested fields and array elements.
Methods
A method is a single step in a SWML document — each item in a sections.<name> array invokes
one method. Each method’s reference page documents its parameters, defaults, and any output
variables it sets. Methods below are grouped by what they do.
Conversational AI
Hand the call to an AI agent that holds a natural conversation, recognizes intent, and can call out to your backend via SWAIG functions or webhooks.
Hand the call to a SignalWire AI agent that holds a natural conversation and can invoke SWAIG functions.
Hand the call to an Amazon Bedrock-backed AI agent.
Call lifecycle
Control when the call is answered, ended, and what kind of party is on the other end before deciding how to handle it.
Answer an inbound call. Some methods (e.g. play) auto-answer if needed.
End the call.
Detect whether the answering party is a human or an answering machine.
Audio & speech
Play audio to the caller, prompt for input, and stream live transcription or translation. Includes noise reduction for clearer audio.
Play TTS speech, audio files, silence, or ring tones.
Play audio or speech and capture DTMF or speech input.
Stream live transcription of the call.
Stream live translation of the call.
Start the noise reduction filter on the call audio.
Stop the noise reduction filter.
Connecting parties
Bring other phones, SIP endpoints, video rooms, or queued agents into the call.
Dial out to other phone or SIP destinations — series, parallel, or mixed.
Join the call to a conference room.
Join the call to a SignalWire video room.
Place the call in a queue with wait music, timeout, and status callbacks.
Recording & taps
Record the call to storage, or stream call media to an external sink in real time.
Record audio and wait for completion before continuing execution.
Start a background recording of the call.
Stop a background recording started by record_call.
Stream call media to an RTP or WebSocket sink.
Stop a media stream started by tap.
Messaging & side channels
Send messages, faxes, DTMF, and other out-of-band signals from inside a call. Also collects payments and emits custom project events.
Send an outbound SMS to a phone number.
Send DTMF tones into the call.
Send an outbound fax.
Interpret the inbound call as a fax and process it.
Transfer a SIP call by issuing a SIP REFER.
Collect a PCI-compliant payment over the phone.
Emit a custom event onto the project’s event stream.
Control flow
Direct execution within a SWML document — call subroutines, jump between labels, branch on expressions, or tail-call into another document entirely.
Call a named section or external SWML URL as a subroutine.
Return from an execute-invoked section, optionally producing a return_value.
Tail-call into another section or external SWML document — does not return.
Jump to a label within the current section, optionally repeating up to a limit.
Mark a jump target for goto.
Branch on a JavaScript expression.
Branch on a variable’s value with case matching.
State & integration
Manage script variables, pause execution, and reach your backend over HTTP.