Call

View as Markdown

A Call object represents an active call. You can get instances of a Call object from a Voice.Client, by answering or initiating calls.

Examples

In this example, we are dialing a phone number and playing a TTS message.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice;
6
7const call = await voiceClient.dialPhone({
8 from: "+YYYYYYYYYY",
9 to: "+XXXXXXXXXX"
10});
11
12await call.playTTS({ text: "Welcome to SignalWire!" });

In this example, we are answering an incoming call, playing a TTS message and then hanging up.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice;
6
7await voiceClient.listen({
8 topics: ["topic"],
9 onCallReceived: async (call) => {
10 call.answer();
11 console.log("Call received", call.id);
12 await call.playTTS({ text: "Welcome to SignalWire!" });
13 call.hangup();
14 }
15});

Properties

device
any

The device configuration for this call.

direction
"inbound" | "outbound"

Whether you are making or receiving the call.

from
string

The phone number that the call is coming from.

headers
SipHeader[]

Optional SIP headers for this call. See SipHeader.

id
string

Unique ID for this voice call.

state
"created" | "ringing" | "answered" | "ending" | "ended"

The current state of the call.

to
string

The phone number you are attempting to call.

type
"phone" | "sip"

The type of call. Only phone and sip are currently supported.