connect
Connect to a phone number, SIP URI, Resource Address, queue, or WebSocket stream.
Properties
connect
Connects the current call to a destination — a phone number, SIP URI, Resource Address, queue, or WebSocket stream. The object shape depends on the connection type — select a tab below to see the full property schema for each mode.
Single
Parallel
Serial
Serial Parallel
Dial a single destination directly using the to property.
connect.to
Single destination to dial. The value format determines the destination type:
- Phone number — E.164 format, including the leading
+(e.g.,+15552345678). A number without the+, such as15552345678, is rejected. - SIP URI —
sip:orsips:prefix (e.g.,sip:alice@example.com) - Resource Address — address path (e.g.,
/public/test_room) - Queue —
queue:prefix (e.g.,queue:support) - Call —
call:prefix followed by the ID of a call in progress in the same project (e.g.,call:ba79c846-4834-42b9-9cd3-2f87c30f2972). Bridges the caller to that call. See Connect to a call in progress. - WebSocket stream —
stream:wss://prefix (e.g.,stream:wss://example.com/audio). An unencryptedstream:ws://URL is rejected.
The queue:, call:, and stream: prefixes are case-sensitive and must be lowercase. The sip: and sips: prefixes are not case-sensitive.
connect.answer_on_bridge
Delay answer until the B-leg answers.
connect.call_state_events
An array of call state event names to be notified about. Allowed event names are created, ringing, answered, and ended. Each item can also be a SWML variable that resolves to one of these names.
connect.call_state_url
Webhook url to send call status change notifications to. Authentication can also be set in the url in the format of username:password@url. Learn more about status callbacks.
Applies only to phone, SIP, and Resource Address destinations. When to starts with queue:, call:, or stream:, call_state_url and call_state_events aren’t allowed. Queue events go to the status_url of enter_queue, and stream events go to connect.status_url.
connect.codecs
Codecs to offer, as a comma-separated string ("PCMU,PCMA") or an array of strings (["PCMU", "PCMA"]). Supported codecs are PCMU, PCMA, OPUS, G722, G729, AMR-WB, VP8, and H264. Has no effect on calls to phone numbers.
connect.confirm
Confirmation to execute when the call is connected. Can be either:
- A URL (string) that returns a SWML document
- An array of SWML methods to execute inline
Only these methods are allowed, including inside cond and switch branches: cond, switch, set, unset, hangup, play, prompt, record, record_call, stop_record_call, tap, stop_tap, stream, stop_stream, transcribe, transcribe_stop, send_digits, send_sms, denoise, stop_denoise, and user_event.
connect.confirm_timeout
Time, in seconds, allowed for the confirm SWML to run on the answered destination, whether it is fetched from a URL or given inline.
connect.encryption
The encryption method to use for the call. Possible values: mandatory, optional, forbidden.
connect.from
Caller ID number. Optional. Must be a phone number in E.164 format with the leading +, a SIP URI, or a Resource Address; a queue:, call:, or stream: value is rejected.
connect.from_name
The caller ID name shown to the person you’re calling, displayed alongside the from number (sometimes called CNAM). Applies to SIP calls only — it has no effect on calls to phone numbers. Use 1 to 70 characters after variable expansion: letters, digits, spaces, and _, ., -, +, or ,. Text and variables can be combined, such as Support ${vars.dept}.
connect.headers
Custom SIP headers to add to INVITE. Has no effect on calls to phone numbers.
headers[].name
The name of the header. Must be a valid SIP header name, 3 to 256 characters long, that either starts with X- or is one of Privacy, P-Asserted-Identity, or User-to-User. Names starting with SignalWire, X-SignalWire, X-CID, or X-SW-Xregion are reserved and can’t be set. A Privacy header takes effect only with the value id, which hides the caller’s number.
headers[].value
The value of the header. Can’t be empty or contain line breaks.
connect.max_duration
Maximum duration, in seconds, allowed for the call.
connect.password
SIP authentication password for the outbound leg. Only applies to SIP URI targets — ignored for phone, Resource Address, queue, and stream destinations.
connect.result
Action to take based on the result of the call. This will run once the peer leg of the call has ended.
Will use the switch properties when the return_value is a object, and will use the cond properties method when the return_value is an array.
See Variables for details.
connect.ringback
Ringback to play to the caller while phone, SIP, and Resource Address destinations ring. Can be:
- A
playURI, or an array ofplayURIs, to play as the ringback tone falseto turn off SignalWire’s ringback tone and pass the destination’s early media (for example, its own ringback or announcements) through to the callertrueto keep the default ringback tone
connect.session_timeout
Time, in seconds, to set the SIP Session-Expires header in INVITE. Must be a positive, non-zero number. Values from 1 to 15000 take effect; a larger value is accepted but ignored, so the default Session-Expires value is used. Has no effect on calls to phone numbers.
connect.status_url
HTTP or HTTPS webhook URL to deliver status events. For phone, SIP, and Resource Address destinations, reports the connect operation status (connecting, connected, failed, disconnected). See Connect Status Callbacks. For a stream: destination, reports stream status notifications, and http:// still works, unlike a stream status_url set on a destination inside parallel, serial, or serial_parallel. See Stream Status Callbacks.
connect.status_url_method
HTTP method for the status webhook. Possible values: GET, POST. Stream destinations only.
connect.stop_all_on_reject
Stop ringing and disconnect the caller when a destination rejects the call. Can be either:
trueto stop when a destination is busy or declines the call- A non-empty array of the reasons to stop on:
busy,decline,noAnswer
When a destination rejects the call with a matching reason, the destinations ringing alongside it stop ringing. If connect then fails with that reason, the result block runs first, and then the caller is disconnected.
connect.timeout
Maximum time, in seconds, to wait for an answer.
connect.execute_after_queue
SWML to execute on this call after its bridge with the queued call ends. Only applies when to starts with queue:.
Can be either:
- A URL (http or https) that returns a SWML document
- An inline SWML document (as a JSON string)
When omitted, the call hangs up when the bridge ends. Either way, the script does not continue past connect once a queued call has been bridged.
If no queued call is bridged (for example, the queue is empty or doesn’t exist), connect fails, connect_result is set to failed, and result runs.
connect.username
SIP authentication username for the outbound leg. Only applies to SIP URI targets — ignored for phone, Resource Address, queue, and stream destinations.
connect.webrtc_media
If true, WebRTC media is offered to the SIP endpoint. Has no effect on calls to phone numbers.
Stream-specific properties
The following properties apply only when to starts with stream:wss://.
connect.authorization_bearer_token
Bearer token sent as an Authorization header during the WebSocket handshake.
connect.codec
Audio codec for the stream. Supported values: PCMU, PCMA, G722, L16. Codec can include rate and ptime modifiers (e.g., PCMU@40i, L16@24000h@40i).
connect.custom_parameters
Custom key-value pairs sent in the WebSocket start message.
connect.name
Stream name identifier.
connect.realtime
Enable realtime mode for bidirectional audio.
Example
Variables
Set by the method:
- connect_result: (out)
connected|failed. - connect_failed_reason: (out) Detailed reason for failure.
- return_value: (out) Same value as
connect_result.
SWML variables live on the leg that set them, for as long as that leg lasts. A document that runs on the leg connect dialed, such as a confirm script, starts with an empty vars and its own call object. On the leg that issued connect, every variable survives, and connect_result is set when the document resumes. For how legs relate, see Call legs.
StatusCallbacks
Status callbacks are asynchronous, best-effort HTTP notifications: delivery can be delayed or fail silently — if your server is unreachable, the callback simply never arrives. Don’t gate time-critical or business-critical actions solely on receiving one. Confirm state via the REST API before acting, or use a transport with visible failure modes — see Status callback reliability.
A POST request will be sent to call_state_url with a JSON payload when the call state changes.
Only call state events listed in call_state_events will be sent (default: ended).
A call state URL can also receive a calling.call.connect event. When the call that runs connect has its own call state URL, for example because it was itself dialed with a call_state_url, and the connect fails, SignalWire also sends that URL a calling.call.connect event with connect_state set to failed, regardless of call_state_events. That event has the shape described in Connect Status Callbacks.
The fields below describe the calling.call.state payload.
event_type
The type of event: calling.call.state for call state changes.
event_channel
The channel for the event, includes the SWML session ID.
timestamp
Unix timestamp (float) when the event was generated.
project_id
The project ID associated with the call.
space_id
The Space ID associated with the call.
params
An object containing call state parameters.
params.call_id
The call ID.
params.node_id
The node handling the call.
params.segment_id
The segment ID for the call leg. Present when a segment ID has been assigned.
params.tag
The tag associated with the call. Present when a tag has been set.
params.call_state
The current call state. Valid values: created, ringing, answered, ended.
params.parent
The leg’s parent call. Present when the leg has a parent call.
parent.device_type
The device type of the parent call.
parent.call_id
The parent call’s ID.
parent.node_id
The node handling the parent call.
params.peer
The leg’s peer call. Present when the leg has a peer.
peer.call_id
The peer call’s ID.
peer.node_id
The node handling the peer call.
params.direction
The direction of the call leg (e.g., outbound).
params.device
Details about the device involved in the call.
device.type
The type of device: phone, sip, or webrtc.
device.params.from_number
The originating phone number. Present for phone devices.
device.params.to_number
The destination phone number. Present for phone devices.
device.params.from
The originating address. Present for sip and webrtc devices.
device.params.to
The destination address. Present for sip and webrtc devices.
device.params.headers
SIP headers recorded for the device, each with a name and a value. Present for some phone and sip devices.
params.end_reason
The reason the call ended (only present when call_state is ended). Possible values include hangup, cancel, busy, noAnswer, decline, error, abandoned, maxDuration, and notFound; which ones occur depends on how the call ended.
params.end_source
Which side ended the call: inbound, outbound, or none. Present together with end_reason.
params.dial_winner
The string "true" when this leg was the destination that answered a dial. Absent otherwise.
params.sip_data
SIP details for the leg. Present for sip devices while SIP information is available. Each field is present only when its value is known.
sip_data.sip_req_user
User part of the SIP Request-URI. sip_data.sip_req_uri and sip_data.sip_req_host hold the full Request-URI and its host.
sip_data.sip_from_user
User part of the SIP From header. sip_data.sip_from_uri and sip_data.sip_from_host hold the full URI and its host.
sip_data.sip_to_user
User part of the SIP To header. sip_data.sip_to_uri and sip_data.sip_to_host hold the full URI and its host.
sip_data.sip_contact_user
User part of the SIP Contact header. sip_data.sip_contact_uri, sip_data.sip_contact_host, and sip_data.sip_contact_port hold the full URI, its host, and its port (as a string).
sip_data.sip_p_asserted_identity
The SIP P-Asserted-Identity header value.
sip_data.sip_from_params
Parameters of the SIP From header, as string key-value pairs. sip_data.sip_to_params, sip_data.sip_contact_params, and sip_data.sip_req_params hold the parameters of the To header, the Contact header, and the Request-URI.
params.address_id
The ID of the Resource Address involved in the call. Present when known.
params.subscriber_id
The ID of the subscriber involved in the call. Present when known.
params.subscriber_name
The name of the subscriber involved in the call. Present when known.
params.start_time
When the call leg was created, in milliseconds since the Unix epoch. 0 when not available.
params.answer_time
When the call leg was answered, in milliseconds since the Unix epoch. 0 when not available.
params.end_time
When the call leg ended, in milliseconds since the Unix epoch. 0 when not available.
params.audio_in_mos
Estimated audio quality (mean opinion score) of the audio received on the leg. Present when available.
Raw JSON example
Connect Status Callbacks
When you provide a top-level status_url, SignalWire sends HTTP POST requests reporting the overall status of the connect operation.
event_type
The type of event. Always calling.call.connect for connect status events.
event_channel
The channel for the event, includes the SWML session ID.
timestamp
Unix timestamp (float) when the event was generated.
project_id
The project ID associated with the call.
space_id
The Space ID associated with the call.
params
An object containing connect status parameters.
params.call_id
The call ID.
params.node_id
The node handling the call.
params.segment_id
The segment ID for the call leg. Present when a segment ID has been assigned.
params.tag
The tag associated with the call. Present when a tag has been set.
params.connect_state
The current connect state. Possible values:
connecting— Attempting to connectconnected— Successfully connectedfailed— Connection faileddisconnected— Connection ended
params.failed_reason
The reason the connection failed. Only present when connect_state is failed. Uses the same values as the call state end_reason, for example busy, decline, noAnswer, notFound (the queue is empty or doesn’t exist), or error.
params.peer
Details about the peer. Present whenever peer information is available, which includes connected events and can include disconnected events.
peer.call_id
The peer’s call ID.
peer.tag
The tag associated with the peer call. Present when a tag has been set on the peer.
peer.node_id
The node ID of the node handling this call.
peer.queue_id
The queue ID when the peer was connected via a queue. Only present for queue-based connections.
peer.queue_name
The queue name when the peer was connected via a queue. Only present for queue-based connections.
peer.device
Details about the peer’s device.
Raw JSON example
Failed state example
Stream Status Callbacks
When connecting to a WebSocket stream destination with a status_url, SignalWire sends HTTP requests reporting the stream status.
event_type
The type of event. Always calling.call.stream for stream status events.
event_channel
The channel for the event, includes the SWML session ID.
timestamp
Unix timestamp (float) when the event was generated.
project_id
The project ID associated with the call.
space_id
The Space ID associated with the call.
params
An object containing stream status parameters.
params.call_id
The call ID.
params.node_id
The node handling the call.
params.segment_id
The segment ID for the call leg. Present when a segment ID has been assigned.
params.tag
The tag associated with the call. Present when a tag has been set.
params.control_id
The control identifier for the stream.
params.state
The current stream state. Possible values:
streaming— Stream is activefinished— Stream has ended
params.url
The WebSocket URL of the stream.
params.name
The stream name, if one was provided.
Raw JSON example
Examples
Use connect with a Resource Address
Connect to a Resource by using its Address as the to value.
Dial a single phone number
Play a country ringtone while the destination rings
Set answer_on_bridge to true so the caller’s leg isn’t answered until the destination picks up, and use ringback to play the UK ringtone in place of the default tone. The ringtone repeats until the call connects. See playable sounds for the other ringtones and sounds you can use.
Dial numbers in parallel
Dial more than 20 destinations
To reach more than 20 destinations, split them into batches of up to 20 and start the next batch from the result block when connect_result is failed. The batches ring one after another: the second batch starts only after the first batch’s timeout expires with no answer. Put the destinations most likely to answer in the first batch.
This example shows two destinations per batch to keep it short. Each parallel array can hold up to 20.
Dial SIP serially with a timeout
Set the caller ID name on SIP legs
Set from_name at the top level so every device inherits it, then override it on a single destination. agent1 sees the caller ID name “Support Team” (inherited); agent2 sees “Billing Dept” (overridden).
Connect to a queue
Connect to a call in progress
Set to to call: followed by a call ID to bridge the caller to a call that is already in
progress. The call must belong to the same project, can’t be the call running connect, and can’t
be a call controlled by cXML. A call: destination must be the only destination, and call_state_url and call_state_events aren’t allowed with it. When the
call can’t be bridged, for example because it has already ended, connect fails and sets
connect_result to failed.