RelayMessage

wait

View as MarkdownOpen in Claude

Block until the message reaches a terminal state (delivered, undelivered, or failed). Returns the terminal RelayEvent.

Raises asyncio.TimeoutError if timeout is specified and the message does not reach a terminal state within the given duration.

Parameters

timeout
float | NoneDefaults to None

Maximum number of seconds to wait. None waits indefinitely.

Returns

RelayEvent — The event that caused the message to reach its terminal state. Inspect message.state for the final state value.

Example

import asyncio
from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
async def send_with_timeout():
async with client:
message = await client.send_message(
to_number="+15551234567",
from_number="+15559876543",
body="Your verification code is 123456",
)
try:
event = await message.wait(timeout=30)
if message.state == "delivered":
print("Message delivered successfully")
else:
print(f"Message failed: {message.reason}")
except asyncio.TimeoutError:
print("Timed out waiting for delivery confirmation")
asyncio.run(send_with_timeout())