collect

View as Markdown

collect

collect(params): Promise<CallCollect> - See CallCollect for more details.

Collect user input. For methods that include a prompt to the user, please see promptAudio, promptRingtone, or promptTTS.

Parameters

NameTypeDescription
paramsObject-
params.continuous?booleanDetect utterances and digits until stopped. Defaults to false.
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.
params.initialTimeout?numberNumber of seconds to wait for initial input before giving up. Default is 4 seconds. Will be used only when startInputTimers is true or when the timer is started manually via the startInputTimers method.
params.partialResults?booleanIf true, partial result events are fired. Default is false.
params.sendStartOfInput?booleanIf true, the startOfInput event is fired when input is detected. Default is false.
params.startInputTimers?booleanIf true, the initialTimeout timer is started. Default is false.

Returns

Promise<CallCollect> - See CallCollect for more details.

Examples

Collecting digits input:

1const collect = await call.collect({
2 digits: {
3 max: 5,
4 digitTimeout: 2,
5 terminators: "#*",
6 },
7});
8const { type, digits, terminator } = await collect.ended();

Collecting speech input:

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

Collecting digits and listening for results using the events:

1call.on("collect.started", (collect) => {
2 console.log("collect.started", collect);
3});
4call.on("collect.startOfInput", (collect) => {
5 console.log("Input collection started.");
6});
7call.on("collect.updated", (collect) => {
8 console.log("collect.updated", collect.digits);
9});
10call.on("collect.ended", (collect) => {
11 console.log("collect.ended", collect.digits);
12});
13call.on("collect.failed", (collect) => {
14 console.log("collect.failed", collect.reason);
15});
16
17const collect = await call.collect({
18 digits: {
19 max: 4,
20 digitTimeout: 10,
21 terminators: "#",
22 },
23 partialResults: true,
24 sendStartOfInput: true,
25});