connect

View as MarkdownOpen in Claude

Bridge the call to one or more destinations. The devices parameter supports both serial (try one at a time) and parallel (ring simultaneously) dialing strategies.

This method emits calling.call.connect events. See Call Events for payload details.

This method corresponds to the SWML connect verb. See the SWML connect reference for the full specification.

Parameters

devices
Record<string, unknown>[][]Required

An array of device groups for serial/parallel dialing. The outer array is tried serially (one group at a time). Each inner array is dialed in parallel (all devices in the group ring simultaneously).

Each device object contains:

  • "type" — Device type ("phone", "sip")
  • "params" — Type-specific parameters (to_number, from_number, etc.)
ringback
Record<string, unknown>[] | undefined

Media items to play to the caller while the destination is ringing. Same format as play() media items.

tag
string | undefined

Correlation tag for the connected call.

maxDuration
number | undefined

Maximum duration of the connected call in seconds.

maxPricePerMinute
number | undefined

Maximum price per minute for the connected call.

statusUrl
string | undefined

URL to receive connection status webhooks.

Returns

Promise<Record<string, unknown>> — Server response confirming the connect operation.

Example

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_TOKEN!,
6 contexts: ['default']
7});
8
9client.onCall(async (call) => {
10 await call.answer();
11 await call.play([{ type: 'tts', text: 'Connecting you now...' }]);
12
13 // Serial dialing: try first number, then second if no answer
14 const result = await call.connect([
15 [{ type: 'phone', params: { to_number: '+15551234567', from_number: '+15559876543' } }],
16 [{ type: 'phone', params: { to_number: '+15559999999', from_number: '+15559876543' } }],
17 ]);
18 console.log(`Connect result: ${JSON.stringify(result)}`);
19});
20
21await client.run();