promptRingtone

View as Markdown

promptRingtone

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

Play a ringtone while collecting user input from the call, such as digits or speech.

Parameters

NameTypeDescription
paramsObject-
params.nameRingtoneNameThe name of the ringtone.
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.duration?numberDuration of ringtone to play. Defaults to 1 ringtone iteration.
params.initialTimeout?numberInitial timeout in seconds. Default is 4 seconds.
params.volume?numberVolume value between -40dB and +40dB where 0 is unchanged. Default is 0.

Returns

Promise<CallPrompt> - See CallPrompt for more details.

Examples

Prompting for digits and waiting for a result:

1const prompt = await call.promptRingtone({
2 name: "it",
3 duration: 10,
4 digits: {
5 max: 5,
6 digitTimeout: 2,
7 terminators: "#*",
8 },
9});
10const { type, digits, terminator } = await prompt.ended();

Prompting for speech and waiting for a result:

1const prompt = await call.promptRingtone({
2 name: "it",
3 duration: 10,
4 speech: {
5 endSilenceTimeout: 1,
6 speechTimeout: 60,
7 language: "en-US",
8 hints: [],
9 },
10});
11const { type, text, terminator } = 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.promptRingtone({
15 name: "it",
16 duration: 10,
17 speech: {},
18});