prompt

View as Markdown

prompt

  • prompt(params): Promise<CallPrompt> - See CallPrompt for more details.

Generic method to prompt the user for input. Please see promptAudio, promptRingtone, promptTTS for the more specific methods.

Parameters

NameTypeDescription
paramsObject-
params.playlistVoicePlaylistA media playlist to play.
params.digits?CollectDigitsConfigConfiguration for collecting digits. You must either set this, or speech.
params.speech?CollectSpeechConfigConfiguration for collecting speech. You must either set this, or digits. Pass an empty object to use the default configuration.
params.initialTimeout?numberInitial timeout in seconds. Default is 4 seconds.

Returns

Promise<CallPrompt> - See CallPrompt for more details.

Examples

Prompting for digits and waiting for a result:

1const prompt = await call.prompt({
2 playlist: new Voice.Playlist().add(
3 Voice.Playlist.TTS({ text: "Please enter your PIN" })
4 ),
5 digits: {
6 max: 5,
7 digitTimeout: 2,
8 terminators: "#*",
9 },
10});
11const { type, digits, terminator } = await prompt.ended();

Prompting for speech and waiting for a result:

1const prompt = await call.prompt({
2 // prettier-ignore
3 playlist: new Voice.Playlist().add(
4 Voice.Playlist.TTS({ text: "Please say your PIN" })
5 ),
6 speech: {
7 endSilenceTimeout: 1,
8 speechTimeout: 60,
9 language: "en-US",
10 hints: [],
11 },
12});
13
14const { type, speech } = await prompt.ended();

Prompting for speech and listening for results using the events:

1call.on("prompt.started", (p) => {
2 console.log("prompt.started", p.id);
3});
4call.on("prompt.updated", (p) => {
5 console.log("prompt.updated", p.id);
6});
7call.on("prompt.failed", (p) => {
8 console.log("prompt.failed", p.id, p.reason);
9});
10call.on("prompt.ended", (p) => {
11 console.log("prompt.ended", p.id, p.text);
12});
13
14const prompt = await call.prompt({
15 // prettier-ignore
16 playlist: new Voice.Playlist().add(
17 Voice.Playlist.TTS({ text: "Please say your PIN" })
18 ),
19 speech: {},
20});