CollectAction

View as MarkdownOpen in Claude

Returned from call.playAndCollect(). Tracks a combined play-and-collect operation where a prompt is played and user input (digits or speech) is collected. Terminal states: finished, error, no_input, no_match.

CollectAction only resolves on collect events. Play events sharing the same controlId are ignored, so await action.wait() returns only when input collection completes.

Inherits all properties and methods from the base Action interface (controlId, isDone, completed, result, wait()).

Properties

No additional properties beyond the base Action interface.

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 const action = await call.playAndCollect(
12 [{ type: 'tts', text: 'Press 1 for sales, 2 for support.' }],
13 { digits: { max: 1, digit_timeout: 5.0 } },
14 );
15
16 const event = await action.wait();
17 const result = event.params.result ?? {};
18 const digit = (result as Record<string, unknown>).digits ?? '';
19 console.log(`User pressed: ${digit}`);
20});
21
22await client.run();