CallCollect

View as Markdown

Represents a current or past collect session in a call. You can obtain instances of this class by starting at Collect with the following method:

Example

Collecting a PIN with keypad input from the user, then waiting for a result 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// start Collect
15const collect = await call.collect({
16 digits: {
17 max: 5,
18 digitTimeout: 4,
19 terminators: "#*",
20 },
21});
22
23await call.playTTS({
24 text: "Please enter your PIN",
25});
26
27const { digits } = await collect.ended();
28
29console.log("PIN collected:", digits);

Properties

confidence

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

Syntax: CallCollect.confidence()

Returns: number


digits

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

Syntax: CallCollect.digits()

Returns: string


id

The unique id for this collect session.

Syntax: CallCollect.id()

Returns: string


reason

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

Syntax: CallCollect.reason()

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


terminator

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

Syntax: CallCollect.terminator()

Returns: string


text

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

Syntax: CallCollect.text()

Returns: string


type

The type of this collect session.

Syntax: CallCollect.type()

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

Methods

ended

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

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

Returns

Promise<CallCollect> - See CallCollect for more details.

Example

1const collect = await call.collect({
2 digits: {
3 max: 4,
4 digitTimeout: 10,
5 terminators: "#",
6 },
7 partialResults: true,
8 sendStartOfInput: true,
9});
10await collect.ended();

startInputTimers

  • startInputTimers(): Promise<CallCollect> - See CallCollect for more details.

Start the initialTimeout timer on an active collect.

Returns

Promise<CallCollect> - See CallCollect for more details.

Example

1const collect = await call.collect({
2 digits: {
3 max: 4,
4 digitTimeout: 10,
5 terminators: "#",
6 },
7 partialResults: true,
8 sendStartOfInput: true,
9 startInputTimers: false,
10});
11// You can add some logic before starting input timers.
12await collect.startInputTimers();

stop

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

Stops the collect session.

Returns

Promise<CallCollect> - See CallCollect for more details.

Example

1const collect = await call.collect({
2 speech: {
3 endSilenceTimeout: 2,
4 speechTimeout: 10,
5 language: "en-US",
6 hints: ["sales", "support", "representative"],
7 },
8 partialResults: true,
9 sendStartOfInput: true,
10});
11await collect.stop();