connect
Connect to a phone number, SIP URI, Call Fabric resource, queue, or WebSocket stream.
Properties
connect
Connects the current call to a destination — a phone number, SIP URI, Call Fabric Resource, queue, or WebSocket stream. The connection mode is determined by which property you use. See dialing strategies below.
connect.answer_on_bridge
Delay answer until the B-leg answers.
connect.authorization_bearer_token
Bearer token sent as an Authorization header during the WebSocket handshake. Stream destinations only.
connect.call_state_events
An array of call state event names to be notified about. Allowed event names are created, ringing, answered, and ended. Can be overwritten on each destination.
connect.call_state_url
Webhook url to send call status change notifications to for all legs. Can be overwritten on each destination. Authentication can also be set in the url in the format of username:password@url. Learn more about status callbacks.
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). Stream destinations only.
connect.codecs
Comma-separated string of codecs to offer. 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
connect.confirm_timeout
The amount of time, in seconds, to wait for the confirm script to execute.
connect.custom_parameters
Custom key-value pairs sent in the WebSocket start message. Stream destinations only.
connect.encryption
The encryption method to use for the call. Possible values: mandatory, optional, forbidden.
connect.from
Caller ID number. Optional. Can be overwritten on each destination.
connect.headers
Custom SIP headers to add to INVITE. Has no effect on calls to phone numbers.
headers[].name
The name of the header.
headers[].value
The value of the header.
connect.max_duration
Maximum duration, in seconds, allowed for the call.
connect.name
Stream name identifier. Stream destinations only.
connect.password
SIP password to use for authentication when dialing a SIP URI. Has no effect on calls to phone numbers.
connect.realtime
Enable realtime mode for bidirectional audio. Stream destinations only.
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
Array of play URIs to play as ringback tone.
connect.session_timeout
Time, in seconds, to set the SIP Session-Expires header in INVITE. Must be a positive, non-zero number. Has no effect on calls to phone numbers.
connect.status_url
Webhook URL to deliver status events. For phone, SIP, and Call Fabric destinations, reports the connect operation status (connecting, connected, failed, disconnected). See Connect Status Callbacks. For stream destinations, reports stream status notifications. See Stream Status Callbacks.
connect.status_url_method
HTTP method for the status webhook. Possible values: GET, POST. Stream destinations only.
connect.timeout
Maximum time, in seconds, to wait for an answer.
connect.transfer_after_bridge
SWML to execute after the bridge completes. This defines what should happen after the call is connected and the bridge ends.
Can be either:
- A URL (http or https) that returns a SWML document
- An inline SWML document (as a JSON string)
Required when connecting to a queue (when to starts with queue:).
connect.username
SIP username to use for authentication when dialing a SIP URI. Has no effect on calls to phone numbers.
connect.webrtc_media
If true, WebRTC media is offered to the SIP endpoint. Has no effect on calls to phone numbers.
Dialing strategies
The connect object supports four mutually exclusive dialing strategies. Use exactly one of the following properties:
to
serial
parallel
serial_parallel
connect.to
Single destination to dial. The value format determines the destination type:
- Phone number — E.164 format (e.g.,
+15552345678) - SIP URI — (e.g.,
sip:alice@example.com) - Call Fabric Resource — address path (e.g.,
/public/test_room) - Queue —
queue:prefix (e.g.,queue:support) - WebSocket stream —
stream:wss://prefix (e.g.,stream:wss://example.com/audio)
Properties for destination
connect.to
Destination to dial. Can be:
- Phone number in E.164 format (e.g.,
+15552345678) - SIP URI (e.g.,
sip:alice@example.com) - Call Fabric Resource address (e.g.,
/public/test_room) - Queue (e.g.,
queue:support) - WebSocket stream (e.g.,
stream:wss://example.com/audio)
connect.call_state_events
An array of call state event names to be notified about. Allowed event names are created, ringing, answered, and ended.
connect.call_state_url
Webhook url to send call state change notifications to. Authentication can also be set in the url in the format of username:password@url.
connect.confirm
Confirmation script to execute on this destination when answered. Overrides the top-level confirm. Applies to phone, SIP, and Call Fabric destinations.
connect.confirm_timeout
Seconds to wait for the confirm script to execute on this destination. Overrides the top-level confirm_timeout. Applies to phone, SIP, and Call Fabric destinations.
connect.encryption
Media encryption (SRTP) for this destination. Overrides the top-level encryption. Applies to SIP destinations only.
Possible values: mandatory, optional, forbidden.
connect.from
Caller ID number. Optional.
connect.timeout
Maximum time, in seconds, to wait for destination to answer.
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.
StatusCallbacks
A POST request will be sent to call_state_url with a JSON payload when the call state changes.
Only events listed in call_state_events will be sent (default: ended).
event_type
The type of event. Always calling.call.state for this method.
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.call_state
The current call state. Valid values: created, ringing, answered, ended.
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 (e.g., phone, sip).
device.params.from_number
The originating phone number.
device.params.to_number
The destination phone number.
params.end_reason
The reason the call ended (only present when call_state is ended). Valid values: hangup, busy, no_answer, cancel, declined, error.
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.
params.peer
Details about the connected peer. Present when connect_state is connected.
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.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 Call Fabric
Use a Call Fabric Resource with the connect method by simply including the Resource Address.
Learn more about Resources and Addresses.