Call
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.
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const voiceClient = client.voice;
const call = await voiceClient.dialPhone({
from: "+YYYYYYYYYY",
to: "+XXXXXXXXXX"
});
await call.playTTS({ text: "Welcome to SignalWire!" });
In this example, we are answering an incoming call, playing a TTS message and then hanging up.
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const voiceClient = client.voice;
await voiceClient.listen({
topics: ["topic"],
onCallReceived: async (call) => {
call.answer();
console.log("Call received", call.id);
await call.playTTS({ text: "Welcome to SignalWire!" });
call.hangup();
}
});
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
• Optional
headers: SipHeader
[]
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.
Methods
amd
▸ amd(params?
): Promise
<CallDetect
>
Detects the presence of an answering machine. Alias for detectAnsweringMachine.
answer
▸ answer(): Promise
<Call
>
Answers the incoming call.
Parameters
This method has no parameters.
Returns
Promise
<Call
>
Example
In this example, we answer an incoming call on the office
topic.
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const voiceClient = client.voice;
await voiceClient.listen({
topics: ["office"],
onCallReceived: (call) => {
call.answer();
console.log("Call received", call.id);
}
});
collect
collect(params
): Promise
<CallCollect
>
Collect user input. For methods that include a prompt to the user, please see promptAudio, promptRingtone, or promptTTS.
Parameters
Name | Type | Description |
---|---|---|
params | Object | - |
params.continuous? | boolean | Detect utterances and digits until stopped. Defaults to false. |
params.digits? | CollectDigitsConfig | Configuration for collecting digits. You must either set this, or speech . |
params.speech? | CollectSpeechConfig | Configuration for collecting speech. You must either set this, or digits . |
params.initialTimeout? | number | Number of seconds to wait for initial input before giving up. Default is 4 seconds. Will be used only when startInputTimers is true or when the timer is started manually via the startInputTimers method. |
params.partialResults? | boolean | If true, partial result events are fired. Default is false. |
params.sendStartOfInput? | boolean | If true, the startOfInput event is fired when input is detected. Default is false. |
params.startInputTimers? | boolean | If true, the initialTimeout timer is started. Default is false. |
params.listen? | Callback | Callback to listen for events. List of collect events can be found here. Example event: onStarted |
Returns
Promise
<CallCollect
>
A promise that resolves to a CallCollect
object that you can use to
view the current state and results of the collect session.