execute
Execute a specified section or URL as a subroutine, and upon completion, return to the current document. Use the return statement to pass any return values or objects back to the current document.
Properties
execute
An object that accepts the following properties.
execute.dest
Accepts any valid destination
execute.params
Named parameters to send to section or URL. After variable expansion, params can nest objects and arrays at most 63 levels
deep, counting the params object itself. If params is nested deeper, the section or URL isn’t executed, a
relay_script_nested_too_deep warning is reported, and the methods after execute in the
current section don’t run.
execute.meta
User-defined metadata. This data is ignored by SignalWire and can be used for your own tracking purposes.
execute.on_return
Array of SWML methods to execute when the executed section or URL returns.
execute.result
Instructions to run based on the value returned by the executed section or URL. result is processed after the section or
URL returns and before on_return, and only when the section or URL set a return_value (for example, with
return).
An object-shaped result is handled like the switch method: its case keys are matched
against return_value. An array-shaped result is handled like the cond method: a list of
conditions checked in order.
Valid Destinations
The destination string can be one of:
"section_name"- section in the current document to execute. (For example:main)- A URL (http or https) - URL pointing to the document to execute. An HTTP POST request will be sent to the URL. The
paramsobject is passed, along with the variables and thecallobject. Authentication can also be set in the url in the format ofusername:password@url. - An inline SWML document (as a JSON string) - SWML document provided directly as a JSON string.
Examples
Executing a subroutine
Executing a subroutine and branching on return
Execute a SWML script hosted on a server
A minimal server for this SWML script can be written as follows:
Python/Flask
JavaScript/Express
This server (running on localhost) can be made accessible to the wider web (and thus this SWML script) using forwarding tools like ngrok.
Visit ngrok.com to learn how.
The server will be sent the following payload:
The call object is described in detail in the Calling overview. All variables created
within the SWML document are passed inside vars, and the params object contains the parameters defined in the params
parameter of execute.