Relay

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 is_done, completed, result, control_id, and the wait() method. Specific action types add methods relevant to their operation (e.g., pause() and resume() on PlayAction).

from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
host="your-space.signalwire.com",
contexts=["default"],
)
@client.on_call
async def on_call(call):
await call.answer()
play_action = await call.play([{"type": "tts", "params": {"text": "Hello!"}}])
# Control the in-progress operation
await play_action.pause()
await play_action.resume()
# Wait for completion
event = await play_action.wait()
client.run()

Action (Base Interface)

All action classes share these properties and methods.

Properties

control_id
str

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

is_done
bool

True if the underlying future has resolved (the operation has reached a terminal state).

completed
bool

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

result
Optional[RelayEvent]

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

Methods

wait

wait(timeout=None) -> RelayEvent

Block until the action completes and return the terminal event.

timeout
Optional[float]

Maximum seconds to wait. None waits indefinitely. Raises asyncio.TimeoutError if exceeded.

Subclasses