For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions & Utilities
      • LiveWire
      • PomBuilder
      • Prefabs
      • SkillBase
      • SkillManager
      • SkillRegistry
      • Skills
      • SwaigFunction
      • SwmlBuilder
      • SWMLService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
        • on
        • wait
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • ChatResource
      • Compat
      • Datasphere
      • Fabric
      • ImportedNumbersResource
      • Logs
      • LookupResource
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSubResource
      • Queues
      • Recordings
      • Registry
      • RestClient
      • RestError
      • Short Codes
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
RELAYMessage

on

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

wait

Next
Built with

Register an event listener for state changes on this message. The handler is called each time a messaging.state event is received for this message, allowing you to react to intermediate states before the terminal state is reached.

Parameters

handler
(event: RelayEvent) => void | Promise<void>Required

A function that receives a RelayEvent on each state change. Both synchronous and async handlers are supported.

Returns

void

Example

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_API_TOKEN!,
6 contexts: ['default']
7});
8
9await client.connect();
10
11const message = await client.sendMessage({
12 toNumber: '+15551234567',
13 fromNumber: '+15559876543',
14 body: 'Order confirmed',
15});
16
17const onStateChange = (event) => {
18 console.log(`Message ${message.messageId} -> ${message.state}`);
19};
20
21message.on(onStateChange);
22await message.wait();
23
24await client.disconnect();