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

Dialing a phone number and playing a message.

1import { Voice } from "@signalwire/realtime-api";
2
3const client = new Voice.Client({
4 project: "<project-id>",
5 token: "<api-token>",
6 topics: ["office"],
7});
8
9const call = await client.dialPhone({
10 from: "+YYYYYYYYYY",
11 to: "+XXXXXXXXXX",
12});
13
14await call.playTTS({ text: "Welcome to SignalWire!" });

Answering an incoming phone call and playing a message.

1import { Voice } from "@signalwire/realtime-api";
2
3const client = new Voice.Client({
4 project: "<project-id>",
5 token: "<api-token>",
6 topics: ["office"],
7});
8
9client.on("call.received", async (call) => {
10 console.log("Got call", call.from, call.to);
11
12 try {
13 await call.answer();
14 console.log("Inbound call answered");
15
16 await call.playTTS({ text: "Welcome to SignalWire!" });
17 } catch (error) {
18 console.error("Error answering inbound call", error);
19 }
20});

Properties

device

  • device: any

direction

  • direction: "inbound" | "outbound"

Whether you are making or receiving the call.


from

  • from: string

The phone number that the call is coming from.


headers


id

  • Readonly id: string

Unique id for this voice call


state

  • state: created | ringing | answered | ending | ended

The current state of the call.


to

  • to: string

The phone number you are attempting to call.


type

  • type: "phone" | "sip"

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