RelayMessage

on

View as MarkdownOpen in Claude

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
Callable[[RelayEvent], None]Required

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

Returns

None

Example

import asyncio
from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
async def track_state():
async with client:
message = await client.send_message(
to_number="+15551234567",
from_number="+15559876543",
body="Order confirmed",
)
def on_state_change(event):
print(f"Message {message.message_id} -> {message.state}")
message.on(on_state_change)
await message.wait()
asyncio.run(track_state())