Actions

View as MarkdownOpen in Claude

Action objects are returned from call control methods like play(), record(), and detect(). They provide a common interface for tracking and controlling in-progress operations on a Call.

All action classes extend a shared base that provides isDone, completed, result, controlId, and the wait() method. Specific action types add methods relevant to their operation (e.g., pause() and resume() on PlayAction).

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 playAction = await call.play([{ type: 'tts', text: 'Hello!' }]);
12
13 // Control the in-progress operation
14 await playAction.pause();
15 await playAction.resume();
16
17 // Wait for completion
18 const event = await playAction.wait();
19});
20
21await client.run();

Action (Base Interface)

All action classes share these properties and methods.

Properties

controlId
string

Unique identifier for this operation, used to correlate commands and events.

isDone
boolean

true if the underlying promise has resolved (the operation has reached a terminal state).

completed
boolean

true once the action has finished and the terminal event has been processed.

result
RelayEvent | null

The terminal RelayEvent for this action, or null if the action has not yet completed.

Methods

wait

Await the action’s completion and return the terminal event.

timeout
number | undefined

Maximum milliseconds to wait. undefined waits indefinitely. Throws an Error if exceeded.

Subclasses