dial

View as Markdown

dial

  • dial(params): Promise<Call>

Makes an outbound Call and waits until it has been answered or hung up. This is an advanced method that lets you call multiple devices in parallel or series: for simpler use cases, see dialPhone and dialSip.

With this method you can specify a configuration of devices to call in series and/or in parallel: as soon as one device answers the call, the returned promise is resolved. You specify a configuration through a VoiceDeviceBuilder object.

Parameters

params
VoiceDeviceBuilderRequired

The device builder specifying the devices to call. See VoiceDeviceBuilder.

Returns

Promise<Call>

A call object.

Example

Calls a phone number. If the number doesn’t answer within 30 seconds, calls two different SIP endpoints in parallel.

1import { SignalWire, Voice } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice
6
7const devices = new Voice.DeviceBuilder()
8 .add(Voice.DeviceBuilder.Phone({ from: "+XXXXXX", to: "+YYYYYY", timeout: 30 }))
9 .add([
10 Voice.DeviceBuilder.Sip({ from: "sip:aaa@bbb.cc", to: "sip:xxx@yyy.zz" }),
11 Voice.DeviceBuilder.Sip({ from: "sip:aaa@bbb.cc", to: "sip:ppp@qqq.rr" })
12 ]);
13
14try {
15 const call = await voiceClient.dial(devices);
16 console.log("Call answered", call);
17} catch (e) {
18 console.log("Call not answered", e);
19}