For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
ReferenceGuides
ReferenceGuides
  • Core
    • Introduction to SWML
    • Expressions
    • Template functions
    • Variables
    • Errors
  • Calling
    • Overview
    • ai
    • ai_sidecar
    • amazon_bedrock
    • answer
    • cond
    • connect
    • denoise
    • detect_machine
    • enter_queue
    • execute
    • goto
    • hangup
    • join_conference
    • join_room
    • label
    • live_transcribe
    • live_translate
    • pay
    • play
    • prompt
    • receive_fax
    • record
    • record_call
    • request
    • return
    • send_digits
    • send_fax
    • send_sms
    • set
    • sip_refer
    • sleep
    • stop_denoise
    • stop_record_call
    • stop_tap
    • switch
    • tap
    • transcribe
    • transcribe_stop
    • transfer
    • unset
    • user_event
  • Messaging
    • Overview
    • execute
    • goto
    • label
    • receive
    • reply
    • request
    • return
    • switch
    • transfer
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Document structure
  • Webhook and variable payload
  • Methods
  • Conversational AI
  • Call lifecycle
  • Audio & speech
  • Connecting parties
  • Recording & taps
  • Messaging & side channels
  • Control flow
  • State & integration
Calling

Calling SWML overview

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

ai

Next
Built with

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.

1version: 1.0.0
2sections:
3 main:
4 - answer: {}
5 - play:
6 url: "say:Hello!"
7 - hangup: {}

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.

Payload
1{
2 "call": {
3 "call_id": "c2d3e4f5-a6b7-8901-cdef-234567890abc",
4 "node_id": "a1b2c3d4-1111-2222-3333-444455556666",
5 "segment_id": "d3e4f5a6-b7c8-9012-defa-345678901bcd",
6 "call_state": "created",
7 "direction": "inbound",
8 "type": "sip",
9 "from": "sip:user@example.com",
10 "to": "sip:destination@yourdomain.com",
11 "headers": [],
12 "project_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
13 "space_id": "d3e4f5a6-b7c8-9012-defa-345678901bcd"
14 },
15 "vars": {
16 "user_selection": "1"
17 },
18 "envs": {
19 "api_key": "<YOUR_API_KEY>",
20 "webhook_url": "https://example.com/webhook",
21 "id": "12345",
22 "case_number": "54321"
23 },
24 "params": {
25 "department": "sales"
26 }
27}
call
object

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
string

A unique identifier for the call.

call.call_state
string

The current state of the call.

call.direction
string

The direction of this call. Possible values: inbound, outbound.

call.from
string

The number/URI that initiated this call.

call.headers
object[]

The headers associated with this call.

call.headers[].name
string

The name of the header.

call.headers[].value
string

The value of the header.

call.node_id
string

A unique identifier for the node handling the call.

call.project_id
string

The Project ID this call belongs to.

call.segment_id
string

A unique identifier for the current call segment.

call.space_id
string

The Space ID this call belongs to.

call.to
string

The number/URI of the destination of this call.

call.type
string

The type of call. Possible values: sip, phone, webrtc.

call.sip_data
object

SIP-specific data for SIP calls. Only present when call.type is sip. Contains detailed SIP header information.

call.sip_data.sip_contact_host
string

The host portion of the SIP Contact header.

call.sip_data.sip_contact_params
object

Additional parameters from the SIP Contact header.

call.sip_data.sip_contact_port
string

The port from the SIP Contact header.

call.sip_data.sip_contact_uri
string

The full URI from the SIP Contact header.

call.sip_data.sip_contact_user
string

The user portion of the SIP Contact header.

call.sip_data.sip_from_host
string

The host portion of the SIP From header.

call.sip_data.sip_from_uri
string

The full URI from the SIP From header.

call.sip_data.sip_from_user
string

The user portion of the SIP From header.

call.sip_data.sip_req_host
string

The host portion of the SIP request URI.

call.sip_data.sip_req_uri
string

The full SIP request URI.

call.sip_data.sip_req_user
string

The user portion of the SIP request URI.

call.sip_data.sip_to_host
string

The host portion of the SIP To header.

call.sip_data.sip_to_uri
string

The full URI from the SIP To header.

call.sip_data.sip_to_user
string

The user portion of the SIP To header.

params
object

Parameters passed by the calling execute or transfer step. Empty {} on the initial inbound fetch. Section-scoped — each execute/transfer replaces (does not merge with) the caller’s params; when an execute returns, the caller’s original params are restored.

vars
object

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
object

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.

ai

Hand the call to a SignalWire AI agent that holds a natural conversation and can invoke SWAIG functions.

amazon_bedrock

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

Answer an inbound call. Some methods (e.g. play) auto-answer if needed.

hangup

End the call.

detect_machine

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. Run background transcription of the call, and reduce noise for clearer audio.

play

Play TTS speech, audio files, silence, or ring tones.

prompt

Play audio or speech and capture DTMF or speech input.

live_transcribe

Stream live transcription of the call.

live_translate

Stream live translation of the call.

transcribe

Transcribe the entire call in the background.

transcribe_stop

Stop a background transcription started by transcribe.

denoise

Start the noise reduction filter on the call audio.

stop_denoise

Stop the noise reduction filter.

Connecting parties

Bring other phones, SIP endpoints, video rooms, or queued agents into the call.

connect

Dial out to other phone or SIP destinations — series, parallel, or mixed.

join_conference

Join the call to a conference room.

join_room

Join the call to a SignalWire video room.

enter_queue

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

Record audio and wait for completion before continuing execution.

record_call

Start a background recording of the call.

stop_record_call

Stop a background recording started by record_call.

tap

Stream call media to an RTP or WebSocket sink.

stop_tap

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_sms

Send an outbound SMS to a phone number.

send_digits

Send DTMF tones into the call.

send_fax

Send an outbound fax.

receive_fax

Interpret the inbound call as a fax and process it.

sip_refer

Transfer a SIP call by issuing a SIP REFER.

pay

Collect a PCI-compliant payment over the phone.

user_event

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.

execute

Call a named section or external SWML URL as a subroutine.

return

Return from an execute-invoked section, optionally producing a return_value.

transfer

Tail-call into another section or external SWML document — does not return.

goto

Jump to a label within the current section, optionally repeating up to a limit.

label

Mark a jump target for goto.

cond

Branch on a JavaScript expression.

switch

Branch on a variable’s value with case matching.

State & integration

Manage script variables, pause execution, and reach your backend over HTTP.

set

Set one or more script variables.

unset

Remove one or more script variables.

sleep

Pause execution for a specified duration.

request

Make an HTTP request to an external URL; optionally parse the response into variables.