execute

View as MarkdownOpen in Claude

Send a raw JSON-RPC 2.0 request to the RELAY server and return the parsed response. This is the low-level RPC method that all other client and call control methods are built on.

If the client is not currently connected (e.g., during a reconnect cycle), the request is automatically queued and sent after re-authentication completes.

This method has a default timeout of 10 seconds. If no response is received within that window, it raises RelayError and forces a reconnection attempt, as the timeout may indicate a half-open WebSocket connection.

Most developers should use the higher-level methods like dial(), send_message(), and the Call control methods instead of calling execute() directly. Use execute() only for custom or unsupported RPC methods.

Parameters

method
strRequired

Full JSON-RPC method name (e.g., "calling.answer", "calling.play", "messaging.send"). The method name must include the namespace prefix.

params
dict[str, Any]Required

Parameters for the RPC call. Typically includes node_id and call_id for calling methods, along with method-specific parameters.

Returns

dict — The result object from the JSON-RPC response. Structure depends on the method called.

Example

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=["default"],
8)
9
10@client.on_call
11async def handle_call(call):
12 # Send a custom RPC request using the call's identifiers
13 result = await client.execute("calling.answer", {
14 "node_id": call.node_id,
15 "call_id": call.call_id,
16 })
17 print(f"Answer result: {result}")
18
19client.run()