collect

View as MarkdownOpen in Claude

Collect DTMF digit or speech input without playing a prompt. Use this when you want to listen for input silently or after a prompt has already been played separately. For collecting input with a prompt, use playAndCollect().

This method emits calling.call.collect events. See Call Events for payload details.

Parameters

digits
Record<string, unknown> | undefined

DTMF digit collection settings.

digits.max
number

Maximum number of digits to collect.

digits.digit_timeout
number

Seconds to wait between digits before completing.

digits.terminators
string

Characters that terminate digit collection (e.g., "#").

speech
Record<string, unknown> | undefined

Speech recognition settings.

speech.end_silence_timeout
number

Seconds of silence to wait before finalizing speech input.

speech.speech_timeout
number

Maximum seconds to listen for speech.

speech.language
string

Speech recognition language code (e.g., "en-US").

speech.hints
string[]

Words or phrases to boost recognition accuracy.

initialTimeout
number | undefined

Seconds to wait for the first input before ending with no_input.

partialResults
boolean | undefined

Enable partial speech recognition results.

continuous
boolean | undefined

Keep collecting after each result instead of stopping.

sendStartOfInput
boolean | undefined

Send an event when input is first detected.

startInputTimers
boolean | undefined

Start input timers immediately. If false, call action.startInputTimers() to start them manually.

controlId
string | undefined

Custom control ID. Auto-generated if not provided.

onCompleted
(event: RelayEvent) => void | Promise<void>

Callback invoked when collection completes.

Returns

Promise<StandaloneCollectAction> — An action handle with stop(), startInputTimers(), and wait() methods.

Example

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_TOKEN!,
6 contexts: ['default']
7});
8
9client.onCall(async (call) => {
10 await call.answer();
11
12 // Collect digits silently (e.g., extension entry)
13 const action = await call.collect({
14 digits: { max: 4, digit_timeout: 3, terminators: '#' },
15 initialTimeout: 10,
16 });
17 const event = await action.wait();
18
19 const result = event.params.result as Record<string, unknown> ?? {};
20 const extension = (result.digits ?? '') as string;
21 console.log(`Extension entered: ${extension}`);
22});
23
24await client.run();