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

1import asyncio
2from signalwire.relay import RelayClient
3
4client = RelayClient(
5 project="your-project-id",
6 token="your-api-token",
7 host="your-space.signalwire.com",
8 contexts=["sales"],
9)
10
11async def main():
12 async with client:
13 # Dynamically subscribe to additional contexts after connecting
14 await client.receive(["support", "billing"])
15 print("Now receiving calls on sales, support, and billing")
16
17asyncio.run(main())

With inbound call handler

1from signalwire.relay import RelayClient
2
3client = RelayClient(
4 project="your-project-id",
5 token="your-api-token",
6 host="your-space.signalwire.com",
7 contexts=["sales"],
8)
9
10@client.on_call
11async def handle_call(call):
12 print(f"Call on context: {call.context}")
13 await call.answer()
14 await call.hangup()
15
16# Subscribe to additional contexts at startup via constructor
17# For runtime subscription after connect, use await client.receive(["support"])
18client.run()