CallPrompt

View as Markdown

Represents a current or past prompting session in a call. You can obtain instances of this class by starting a Prompt with one of the following methods:

Example

Prompting for a PIN to be entered using the keypad, then waiting for the user to finish entering the PIN before proceeding with the next instructions.

1import { Voice } from "@signalwire/realtime-api";
2
3const client = new Voice.Client({
4 project: "<project-id>",
5 token: "<api-token>",
6 topics: ["office"],
7});
8
9const call = await client.dialPhone({
10 from: "+YYYYYYYYYY",
11 to: "+XXXXXXXXXX",
12});
13
14// Prompt for digits
15const prompt = await call.promptTTS({
16 text: "Please enter your PIN",
17 digits: {
18 max: 5,
19 digitTimeout: 5,
20 terminators: "#*",
21 },
22});
23const { digits } = await prompt.ended();
24
25console.log("Entered PIN:", digits);

Properties

confidence

Confidence level for the speech recognition result (if type is "speech"), from 0 to 100. For example, 83.2.

Syntax: CallPrompt.confidence()

Returns: number


digits

The digits that have been collected (if type is "digit"). For example, "12345".

Syntax: CallPrompt.digits()

Returns: string


id

The unique id for this prompt.

Syntax: CallPrompt.id()

Returns: string


reason

Alias for type, in case of errors. Use this field to check the reason of the error.

Syntax: CallPrompt.reason()

Returns: "no_match" | "no_input" | "error"


terminator

The terminator used to complete the prompt (if type is "digit"). For example, "#".

Syntax: CallPrompt.terminator()

Returns: string


text

The text that has been collected (if type is "speech"). For example, "hello who's there".

Syntax: CallPrompt.text()

Returns: string


type

The type of this prompt.

Syntax: CallPrompt.type()

Returns: "error" | "no_input" | "no_match" | "digit" | "speech"

Methods

ended

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

Returns a promise that is resolved only after this prompt finishes (or is stopped).

Returns

Promise<CallPrompt> - See CallPrompt for more details.

Example

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

setVolume

  • setVolume(volume): Promise<CallPrompt> - See CallPrompt for more details.

Changes the volume of the audio.

Parameters

NameTypeDescription
volumenumberVolume value between -40dB and +40dB.

Returns

Promise<CallPrompt> - See CallPrompt for more details.

Example

1const prompt = await call.promptTTS({
2 text: "Please enter your PIN",
3 digits: {
4 max: 5,
5 digitTimeout: 2,
6 terminators: "#*",
7 },
8});
9await prompt.setVolume(-20);

stop

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

Stops the prompt.

Returns

Promise<CallPrompt> - See CallPrompt for more details.

Example

1const prompt = await call.promptTTS({
2 text: "Please enter your PIN",
3 digits: {
4 max: 5,
5 digitTimeout: 2,
6 terminators: "#*",
7 },
8});
9await prompt.stop();

waitForResult

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

Returns a promise that is resolved only after this prompt finishes (or is stopped).

This method is deprecated. See ended instead.