Skip to main content

Types

Helper types.

CollectDigitsConfig

A configuration object to specify how to collect digits.

digits
objectrequired

Object containing the digit collection configuration.

digits.max
numberrequired

Max number of digits to collect.

digits.digitTimeout
number
Default: 5.0

Timeout in seconds between each digit.

digits.terminators
string

DTMF digits that will end the collection.

Example

Collecting digits using call.collect():

const collectObj = await call.collect({
digits: {
max: 4,
digitTimeout: 5,
terminators: "#"
}
});
const { digits, terminator } = await collectObj.ended();

Prompting for digits with TTS using call.promptTTS():

const prompt = await call.promptTTS({
text: "Please enter your 4-digit PIN",
digits: {
max: 4,
digitTimeout: 5,
terminators: "#*"
}
});
const { type, digits, terminator } = await prompt.ended();

CollectSpeechConfig

A configuration object to specify how to collect speech.

speech
objectrequired

Object containing the speech collection configuration.

speech.endSilenceTimeout
number
Default: 1.0

How much silence to wait for end of speech in seconds.

speech.speechTimeout
number
Default: 60

Maximum time to collect speech in seconds.

speech.language
string
Default: "en-US"

Language to detect. Supported languages here.

speech.hints
string[]

Array of expected phrases to detect.

speech.model
string

Enable enhanced speech recognition at an additional cost. Accepted values are enhanced, enhanced.phone_call, or enhanced.video. The value enhanced will automatically detect whether to optimize with the phone_call or video setting.

Example

Collecting speech using call.collect():

const collectObj = await call.collect({
speech: {
endSilenceTimeout: 2,
speechTimeout: 30,
language: "en-US",
hints: ["yes", "no", "maybe"]
}
});
const { speech, text } = await collectObj.ended();

Prompting for speech with TTS using call.promptTTS():

const prompt = await call.promptTTS({
text: "Please say yes or no",
speech: {
endSilenceTimeout: 1,
speechTimeout: 60,
language: "en-US",
hints: ["yes", "no"]
}
});
const { type, text } = await prompt.ended();

SipCodec

A codec for SIP. Possible values are: "PCMU", "PCMA", "OPUS", "G729", "G722", "VP8", "H264".

Example

Using codecs when dialing a SIP endpoint with Voice.DeviceBuilder.Sip():

import { Voice } from "@signalwire/realtime-api";

const devices = new Voice.DeviceBuilder().add(
Voice.DeviceBuilder.Sip({
from: "sip:user1@domain.com",
to: "sip:user2@domain.com",
codecs: ["OPUS", "PCMU"]
})
);

const call = await client.voice.dial({ devices });

SipHeader

A header for SIP. It is an object with the following properties.

Properties

name
stringrequired

Name of the header.

value
stringrequired

Value of the header.

Example

Using custom headers when dialing a SIP endpoint with Voice.DeviceBuilder.Sip():

import { Voice } from "@signalwire/realtime-api";

const devices = new Voice.DeviceBuilder().add(
Voice.DeviceBuilder.Sip({
from: "sip:user1@domain.com",
to: "sip:user2@domain.com",
headers: [
{ name: "X-Custom-Header", value: "my-value" },
{ name: "X-Account-ID", value: "12345" }
]
})
);

const call = await client.voice.dial({ devices });

RingtoneName

The name of a ringtone, based on country-specific ring patterns.

ValueCountry
atAustria
auAustralia
beBelgium
bgBulgaria
brBrazil
chSwitzerland
clChile
cnChina
czCzech Republic
deGermany
dkDenmark
eeEstonia
esSpain
fiFinland
frFrance
grGreece
huHungary
ilIsrael
inIndia
itItaly
jpJapan
ltLithuania
mxMexico
myMalaysia
nlNetherlands
noNorway
nzNew Zealand
phPhilippines
plPoland
ptPortugal
ruRussia
seSweden
sgSingapore
thThailand
twTaiwan
ukUnited Kingdom
usUnited States
veVenezuela
zaSouth Africa

Example

Playing a ringtone with Voice.Playlist.Ringtone():

import { Voice } from "@signalwire/realtime-api";

const playlist = new Voice.Playlist()
.add(Voice.Playlist.Ringtone({ name: "us", duration: 10 }));

await call.play(playlist);

Prompting with a ringtone using call.promptRingtone():

const prompt = await call.promptRingtone({
name: "it",
duration: 10,
digits: {
max: 1,
digitTimeout: 5
}
});
const { digits } = await prompt.ended();

VoiceCallPhoneParams

A device configuration object for calling a phone number. Returned by Voice.DeviceBuilder.Phone() and passed to DeviceBuilder.add().

Properties

type
"phone"required

The device type. Always "phone" for phone devices.

to
stringrequired

Number to call, in E.164 format.

from
string

SignalWire number to use to initiate the call, in E.164 format.

timeout
number
Default: 30

Time to wait for the call to be answered, in seconds.

callStateUrl
string

Webhook URL to which SignalWire will send call status change notifications. See CallState.

callStateEvents
string[]
Default: ["ended"]

Array of event names to be notified about. Allowed values are created, ringing, answered, and ended.

VoiceCallSipParams

A device configuration object for calling a SIP endpoint. Returned by Voice.DeviceBuilder.Sip() and passed to DeviceBuilder.add().

Properties

type
"sip"required

The device type. Always "sip" for SIP devices.

to
stringrequired

SIP endpoint URI to call.

from
stringrequired

SIP endpoint URI to use to initiate the call.

timeout
number
Default: 30

Time to wait for the call to be answered, in seconds.

codecs
SipCodec[]

Array of desired codecs in order of preference. See SipCodec.

headers
SipHeader[]

Array of headers. Must be X- headers only. See SipHeader.

callStateUrl
string

Webhook URL to which SignalWire will send call status change notifications. See CallState.

callStateEvents
string[]
Default: ["ended"]

Array of event names to be notified about. Allowed values are created, ringing, answered, and ended.

webrtcMedia
boolean

Whether to use WebRTC media.

sessionTimeout
number

Session timeout in seconds.

TapDevice

A device to use as a destination for tap. This can be either an RTP device or a WebSocket device.

Properties

type
"rtp" | "ws"required

Type of this device (RTP or WebSocket).

RTP (type = "rtp")

An RTP device has the following properties in addition to the general ones:

addr
stringrequired

RTP IPv4 address.

port
stringrequired

RTP port.

codec
"OPUS" | "PCMA" | "PCMU"

Optional codec to use. It will be the same as the tapped audio if not set.

rate
number

Optional sample rate in Hz. It will be the same as the tapped audio if not set.

ptime
number

Optional packetization time in milliseconds. It will be the same as the tapped audio if not set.

WebSocket (type = "ws")

A WebSocket device has the following properties in addition to the general ones:

uri
stringrequired

Destination URI.

codec
"OPUS" | "PCMA" | "PCMU"

Optional codec to use. It will be the same as the tapped audio if not set.

rate
number

Optional sample rate in Hz. It will be the same as the tapped audio if not set.

Example

Tapping audio to a WebSocket endpoint using call.tapAudio():

const tap = await call.tapAudio({
direction: "both",
device: {
type: "ws",
uri: "wss://example.domain.com/endpoint"
}
});

// Stop the tap when done
await tap.stop();

Tapping audio to an RTP endpoint using call.tap():

const tap = await call.tap({
audio: {
direction: "speak"
},
device: {
type: "rtp",
addr: "192.0.2.1",
port: "1234",
codec: "PCMU"
}
});

await tap.stop();