RELAY
TypeScript API reference for RelayClient, Call, Message, and real-time events
The RELAY namespace provides imperative, event-driven control over voice calls and SMS/MMS messages through a persistent WebSocket connection to SignalWire. While the Agents namespace handles AI-driven conversations declaratively via SWML, RELAY gives you fine-grained, async control over every step of a call — answering, playing prompts, collecting digits, recording, bridging, conferencing, and more.
RELAY uses the JSON-RPC 2.0 protocol over WebSocket (wss://). The client
authenticates once, subscribes to contexts for inbound events, and processes
call and message events in an async event loop. Automatic reconnection with
exponential backoff ensures resilience against transient network failures.
Context Routing
Contexts are routing labels that control which inbound calls and messages are delivered to your application. When you assign a phone number to a context in the SignalWire dashboard, all calls to that number are routed to RELAY clients subscribed to that context.
A client only receives events for its subscribed contexts. This enables multiple applications or workers to handle different call flows on the same project by subscribing to different contexts.
Example
An IVR that answers calls, plays a menu, collects a digit, and routes accordingly:
Classes
WebSocket client for connecting, authenticating, dialing calls, and sending messages.
Call object with methods for answer, hangup, play, record, collect, connect, and more.
Message object for tracking SMS/MMS state and waiting for delivery confirmation.
Async action handles returned from call control methods like play, record, and detect.
Typed event classes for call state changes, playback, recording, and messaging.
Call states, connect states, message states, and event type string constants.
Error thrown when the RELAY server returns an error response.