Voice Client

View as Markdown

The Voice Client allows you to make outbound calls and receive inbound calls. It connects to SignalWire and listens on one or more topics for incoming call events.

1import { Voice } from "@signalwire/realtime-api";
2
3const client = new Voice.Client({
4 project: "<project-id>",
5 token: "<api-token>",
6 topics: ["office"],
7});

Once instantiated, use dialPhone or dialSip to initiate outbound calls, or listen for the call.received event to handle inbound calls. See Events for all available events.

Constructor

new Voice.Client(opts): Voice.Client

Creates a new Voice Client instance.

Parameters

NameTypeDescription
opts.projectstringRequired. SignalWire project ID.
opts.tokenstringRequired. SignalWire API token.
opts.topicsstring[]Required. Topics to listen on for inbound calls (e.g., ["office", "support"]).
opts.debug.logWsTraffic?booleanLog WebSocket traffic for debugging. Default: false.

Examples

Receiving calls

1client.on("call.received", async (call) => {
2 console.log("Got call", call.from, call.to);
3 await call.answer();
4});

Making calls

1const call = await client.dialPhone({
2 from: "+15551234567",
3 to: "+15559876543",
4 timeout: 30,
5});