RelayCall

wait_for

View as MarkdownOpen in Claude

Wait for a specific event type on this call, optionally filtered by a predicate function. This is a one-shot listener — it resolves on the first matching event and then removes itself.

Parameters

event_type
strRequired

The event type string to wait for.

predicate
Callable[[RelayEvent], bool] | NoneDefaults to None

Optional filter function. If provided, the wait only resolves when the predicate returns True for a received event.

timeout
float | NoneDefaults to None

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

Returns

RelayEvent — The first event matching the type and optional predicate.

Example

from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
@client.on_call
async def handle_call(call):
await call.answer()
# Wait for a specific play event
action = await call.play([{"type": "tts", "params": {"text": "Hello!"}}])
event = await call.wait_for(
"calling.call.play",
predicate=lambda e: e.params.get("state") == "finished",
timeout=30,
)
print(f"Play finished: {event.params}")
client.run()