receive

View as MarkdownOpen in Claude

Subscribe to additional contexts for inbound call and message events. Sends a signalwire.receive request to start receiving events on the specified contexts without reconnecting.

Use this to dynamically expand the set of contexts after the initial connection. Contexts passed to the RelayClient constructor are subscribed automatically at connect time — this method is for adding more at runtime.

Contexts are strings that act as routing labels. A phone number configured in your SignalWire dashboard sends calls to a specific context. Subscribe to that context to receive those calls.

Parameters

contexts
list[str]Required

List of context names to subscribe to. If the list is empty, the method returns immediately without sending a request.

Returns

None

Examples

Add contexts at runtime

import asyncio
from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["sales"],
)
async def main():
async with client:
# Dynamically subscribe to additional contexts after connecting
await client.receive(["support", "billing"])
print("Now receiving calls on sales, support, and billing")
asyncio.run(main())

With inbound call handler

from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["sales"],
)
@client.on_call
async def handle_call(call):
print(f"Call on context: {call.context}")
await call.answer()
await call.hangup()
# Subscribe to additional contexts at startup via constructor
# For runtime subscription after connect, use await client.receive(["support"])
client.run()