execute_rpc
execute_rpc
Send a call control command from the running script to another call in the same project, or start a new outbound
call. The commands are the ones the REST Calling API’s Send call commands endpoint accepts, such as
injecting a message into an AI agent’s conversation or taking it off hold. Here they’re named without the calling.
prefix.
The script continues with the next method whether or not the command succeeds. Read last_api_code to check the
result. execute_rpc doesn’t answer the call, so it can run before answer.
Properties
execute_rpc
An object that accepts the following properties.
execute_rpc.method
The command to run, without the calling. prefix: for example ai_message, ai_hold, ai_unhold, user_event,
transfer, or dial. Most commands need call_id. dial starts a new call and doesn’t take one.
execute_rpc.call_id
ID of the call to send the command to. The call must belong to the same project as this script. Most commands need
it. Omit it for dial, which starts a new call and can’t target an existing one.
execute_rpc.node_id
ID of the node handling the target call, as reported in that call’s events. Optional: SignalWire finds the call
from call_id when this is omitted.
execute_rpc.params
The command’s parameters. For every command except dial, these are the same as the params object of the
matching command in Send call commands. For dial, pass devices, the new call’s destination, and
optionally dest_swml, the SWML document or URL to run on the new call when it’s answered.
Variable references anywhere in execute_rpc, including inside params, are expanded before the command
is sent.
Variables
Set by the method:
- last_api_code: (out) The command’s result code as a string:
200when the command was accepted, otherwise an error code such as400(invalid command or parameters) or404(the call wasn’t found). - last_api_message: (out) A short description of the result, such as
Call not found in registry.
Examples
Send a message to an AI agent on another call
This script tells the AI agent on another call that no one is available, then takes the agent off hold. Replace the
call_id with the ID of the call running the agent.
Start a new outbound call
This script plays a message to the caller, then places a separate call to an agent’s phone. When the agent answers,
that call runs the SWML at dest_swml. The new call is independent of the caller’s call; to connect the caller
directly, use connect instead.