*** id: 23836b49-53b5-4b7e-a63e-ae1384bd30bc title: connect slug: /reference/connect description: >- Connect to a phone number, SIP URI, Call Fabric resource, queue, or WebSocket stream. max-toc-depth: 3 ---------------- [statuscallbacks]: #statuscallbacks Connect to a phone number, SIP URI, Call Fabric resource, queue, or WebSocket stream. ## **Properties** 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](#dialing-strategies) below. Delay answer until the B-leg answers. Bearer token sent as an `Authorization` header during the WebSocket handshake. **Stream destinations only.** 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](#properties-for-destination). Webhook url to send call status change notifications to for all legs. Can be overwritten on each [destination](#properties-for-destination). Authentication can also be set in the url in the format of `username:password@url`. Learn more about [status callbacks][statuscallbacks]. 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.** Comma-separated string of codecs to offer. Has no effect on calls to phone numbers. 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 The amount of time, in seconds, to wait for the `confirm` script to execute. Custom key-value pairs sent in the WebSocket start message. **Stream destinations only.** The encryption method to use for the call. Possible values: `mandatory`, `optional`, `forbidden`. Caller ID number. Optional. Can be overwritten on each [destination](#properties-for-destination). Custom SIP headers to add to INVITE. Has no effect on calls to phone numbers. The name of the header. The value of the header. Maximum duration, in seconds, allowed for the call. Stream name identifier. **Stream destinations only.** SIP password to use for authentication when dialing a SIP URI. Has no effect on calls to phone numbers. Enable realtime mode for bidirectional audio. **Stream destinations only.** 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`](/docs/swml/reference/switch#properties) when the `return_value` is a object, and will use the [`cond properties`](/docs/swml/reference/cond#properties) method when the `return_value` is an array. See [Variables](#variables) for details. Array of `play` URIs to play as ringback tone. 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. 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](#connect-status-callbacks). For stream destinations, reports stream status notifications. See [Stream Status Callbacks](#stream-status-callbacks). HTTP method for the status webhook. Possible values: `GET`, `POST`. **Stream destinations only.** Maximum time, in seconds, to wait for an answer. 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:`). SIP username to use for authentication when dialing a SIP URI. Has no effect on calls to phone numbers. 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: 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`) Array of [`destination`](#properties-for-destination) objects to dial in order. Each destination is tried sequentially — if the first fails, the next is attempted. Array of [`destination`](#properties-for-destination) objects to dial simultaneously. The first destination to answer is bridged and the rest are cancelled. Array of arrays combining both strategies. Each inner array is a group of destinations dialed simultaneously. The outer array attempts each group in order — if no destination answers in the first group, the next group is tried. ## **Properties for `destination`** 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`) An array of call state event names to be notified about. Allowed event names are `created`, `ringing`, `answered`, and `ended`. Webhook url to send call state change notifications to. Authentication can also be set in the url in the format of `username:password@url`. Confirmation script to execute on this destination when answered. Overrides the top-level `confirm`. Applies to phone, SIP, and Call Fabric destinations. 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. Media encryption (SRTP) for this destination. Overrides the top-level `encryption`. **Applies to SIP destinations only.** Possible values: `mandatory`, `optional`, `forbidden`. Caller ID number. Optional. 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`). The type of event. Always `calling.call.state` for this method. The channel for the event, includes the SWML session ID. Unix timestamp (float) when the event was generated. The project ID associated with the call. The Space ID associated with the call. An object containing call state parameters. The call ID. The node handling the call. The current call state. **Valid values:** `created`, `ringing`, `answered`, `ended`. The direction of the call leg (e.g., `outbound`). Details about the device involved in the call. The type of device (e.g., `phone`, `sip`). The originating phone number. The destination phone number. The reason the call ended (only present when `call_state` is `ended`). **Valid values:** `hangup`, `busy`, `no_answer`, `cancel`, `declined`, `error`. ### Raw JSON example ```json { "event_type": "calling.call.state", "event_channel": "swml:xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "timestamp": 1640000000.123, "project_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "space_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "params": { "call_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "node_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "call_state": "answered", "direction": "outbound", "device": { "type": "phone", "params": { "from_number": "+15551231234", "to_number": "+15553214321" } }, "end_reason": null } } ``` *** ## **Connect Status Callbacks** When you provide a top-level `status_url`, SignalWire sends HTTP POST requests reporting the overall status of the connect operation. The type of event. Always `calling.call.connect` for connect status events. The channel for the event, includes the SWML session ID. Unix timestamp (float) when the event was generated. The project ID associated with the call. The Space ID associated with the call. An object containing connect status parameters. The call ID. The node handling the call. The segment ID for the call leg. Present when a segment ID has been assigned. The tag associated with the call. Present when a tag has been set. The current connect state. Possible values: * `connecting` — Attempting to connect * `connected` — Successfully connected * `failed` — Connection failed * `disconnected` — Connection ended The reason the connection failed. Only present when `connect_state` is `failed`. Details about the connected peer. Present when `connect_state` is `connected`. The peer's call ID. The tag associated with the peer call. Present when a tag has been set on the peer. The node ID of the node handling this call. The queue ID when the peer was connected via a queue. Only present for queue-based connections. The queue name when the peer was connected via a queue. Only present for queue-based connections. Details about the peer's device. ### Raw JSON example ```json { "event_type": "calling.call.connect", "event_channel": "swml:xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "timestamp": 1640000000.123, "project_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "space_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "params": { "call_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "node_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "connect_state": "connected", "peer": { "call_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "node_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "device": { "type": "phone", "params": { "from_number": "+15551231234", "to_number": "+15553214321" } } } } } ``` #### Failed state example ```json { "event_type": "calling.call.connect", "event_channel": "swml:xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "timestamp": 1640000000.123, "project_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "space_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "params": { "call_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "node_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "connect_state": "failed", "failed_reason": "no_answer" } } ``` *** ## **Stream Status Callbacks** When connecting to a WebSocket stream destination with a `status_url`, SignalWire sends HTTP requests reporting the stream status. The type of event. Always `calling.call.stream` for stream status events. The channel for the event, includes the SWML session ID. Unix timestamp (float) when the event was generated. The project ID associated with the call. The Space ID associated with the call. An object containing stream status parameters. The control identifier for the stream. The current stream state. Possible values: * `streaming` — Stream is active * `finished` — Stream has ended The WebSocket URL of the stream. The stream name, if one was provided. ### Raw JSON example ```json { "event_type": "calling.call.stream", "event_channel": "swml:xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "timestamp": 1640000000.123, "project_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "space_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "params": { "control_id": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "state": "streaming", "url": "wss://example.com/audio", "name": "my-stream" } } ``` *** ## **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](/docs/platform/resources) and [Addresses](/docs/platform/addresses). ```yaml version: 1.0.0 sections: main: - answer: {} - play: volume: 10 urls: - 'silence:1.0' - 'say:Hello, connecting to a fabric Resource that is a room' - connect: to: /public/test_room ``` ```json { "version": "1.0.0", "sections": { "main": [ { "answer": {} }, { "play": { "volume": 10, "urls": [ "silence:1.0", "say:Hello, connecting to a fabric Resource that is a room" ] } }, { "connect": { "to": "/public/test_room" } } ] } } ``` ### Dial a single phone number ```yaml version: 1.0.0 sections: main: - connect: from: "+15553214321" to: "+15551231234" ``` ```json { "version": "1.0.0", "sections": { "main": [ { "connect": { "from": "+15553214321", "to": "+15551231234" } } ] } } ``` ### Dial numbers in parallel ```yaml version: 1.0.0 sections: main: - connect: parallel: - to: "+15551231234" - to: "+15553214321" ``` ```json { "version": "1.0.0", "sections": { "main": [ { "connect": { "parallel": [ { "to": "+15551231234" }, { "to": "+15553214321" } ] } } ] } } ``` ### Dial SIP serially with a timeout ```yaml version: 1.0.0 sections: main: - connect: timeout: 20 serial: - from: "sip:chris@example.com" to: "sip:alice@example.com" - to: "sip:bob@example.com" codecs: PCMU ``` ```json { "version": "1.0.0", "sections": { "main": [ { "connect": { "timeout": 20, "serial": [ { "from": "sip:chris@example.com", "to": "sip:alice@example.com" }, { "to": "sip:bob@example.com", "codecs": "PCMU" } ] } } ] } } ``` ### Connect to a queue with transfer after bridge ```yaml version: 1.0.0 sections: main: - connect: to: "queue:support" transfer_after_bridge: "https://example.com/post-call-swml" ``` ```json { "version": "1.0.0", "sections": { "main": [ { "connect": { "to": "queue:support", "transfer_after_bridge": "https://example.com/post-call-swml" } } ] } } ``` ### Connect to a WebSocket stream ```yaml version: 1.0.0 sections: main: - answer: {} - connect: to: "stream:wss://example.com/audio" codec: PCMU realtime: true name: my-stream status_url: "https://example.com/stream-status" ``` ```json { "version": "1.0.0", "sections": { "main": [ { "answer": {} }, { "connect": { "to": "stream:wss://example.com/audio", "codec": "PCMU", "realtime": true, "name": "my-stream", "status_url": "https://example.com/stream-status" } } ] } } ```