prompt

View as Markdown

prompt

Generic method to prompt the user for input.

Take a look at promptAudio, promptRingtone, or promptTTS for the more specific input methods.

Parameters

params
objectRequired

Object containing the parameters for prompting the user for input.

playlist
VoicePlaylistRequired

A media playlist to play. See VoicePlaylist.

digits
CollectDigitsConfig

Configuration for collecting digits. You must either set this, or speech. See CollectDigitsConfig.

speech
CollectSpeechConfig

Configuration for collecting speech. You must either set this, or digits. Pass an empty object to use the default configuration. See CollectSpeechConfig.

initialTimeout
numberDefaults to 4

Initial timeout in seconds.

listen
object

Callback to listen for events. List of prompt events can be found here. Example event: onStarted.

Returns

Promise<CallPrompt>

A promise that resolves to a CallPrompt object that you can use to view the current state and results of the prompt session.

Examples

Digits Example

In this example, we dial a phone number and prompt for digits. After the digits are entered or a timeout occurs, the prompt session will end and return the digits results, and the call will hangup. We also listen for prompt events.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice;
6
7// Listen for incoming calls
8await voiceClient.listen({
9 topics: ["office"],
10 onCallReceived: async (call) => {
11 console.log("Call received");
12 // Answer the call
13 call.answer();
14 // Prompt for digits. After the digits are entered or a timeout occurs, the prompt session will end and return the digits results, and the call will hangup.
15 await call.prompt({
16 playlist: new Voice.Playlist().add(
17 Voice.Playlist.TTS({ text: "Please enter your PIN number."})
18 ),
19 digits: {
20 max: 4,
21 digitTimeout: 10,
22 terminators: "#*"
23 },
24 listen: {
25 onStarted: () => console.log("Prompt started!"),
26 onFailed: () => console.log("Prompt failed!"),
27 onUpdated: (promptResult) => console.log("Prompt updated!", promptResult.result),
28 onEnded: (promptResult) => {
29 console.log("Prompt ended!", promptResult.result);
30 call.hangup();
31 }
32 }
33 }).onStarted();
34 }
35});

Speech Example

In this example, we dial a phone number and prompt for speech. After the speech is entered or a timeout occurs, the call will hangup. We also listen for prompt events.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice;
6
7// Listen for incoming calls
8await voiceClient.listen({
9 topics: ["office"],
10 onCallReceived: async (call) => {
11 console.log("Call received");
12 // Answer the call
13 call.answer();
14 // Prompt for speech. After the speech is entered or a timeout occurs, the call will hangup.
15 await call.prompt({
16 playlist: new Voice.Playlist().add(
17 Voice.Playlist.TTS({ text: "Please enter your PIN number."})
18 ),
19 speech: {
20 model: "enhanced.phone_call"
21 },
22 listen: {
23 onStarted: () => console.log("Prompt started!"),
24 onFailed: () => console.log("Prompt failed!"),
25 onUpdated: (promptResult) => console.log("Prompt updated!", promptResult.result),
26 onEnded: (promptResult) => {
27 console.log("Prompt ended!", promptResult.result);
28 call.hangup();
29 }
30 }
31 }).onStarted();
32 }
33});