Skip to content

Execute a remote SWML document and return to the current document. Use %{return_value.['object_field']} to reference the return values from the external SWML.

Output Node Connectors

Condition

string

The condition that is evaluated to determine which path to take. Additional conditions can be added by clicking the Add condition button. Additional conditions will act as JavaScript else-if statements.

Else

string

The path to take if none of the conditions are met.

Node Settings

URL

string

The URL of the SWML document to execute. The URL must return swml in valid JSON or YAML format.

Params

object

The parameters to pass to the SWML document.

Meta

object

The metadata to pass to the SWML document. A JSON object to serialize.

Conditions

string

The conditions that are evaluated to determine which path to take. Additional conditions can be added by clicking the Add condition button. Additional conditions will act as JavaScript else-if statements.

Example

In this example, we will execute a SWML script that is hosted on a remote server. When making a request to the server, we will pass the User and Token parameters.

The SWML document will return a JSON object with a play method field. This play field will be used for TTS (Text-to-Speech) in the current document and will welcome the user with the User parameter and say the Token parameter.

[Execute SWML node example that executes a remote SWML document.]

Call Flow using the Execute SWML node.

Execute SWML Node Settings

  • URL: Self-hosted ngrok URL.
  • Params: { "Content-Type": "application/json", "User": "user_1", "Token": "123" }
  • Meta: None
  • Condition: %{return_value.return_value} === 1

SWML Document

Below is the SWML document that will be executed.

andJSON

sections:
  main:
    - play: 'say: Hello <USER_NAME>, welcome to the SWML demo! Your token is <TOKEN>!'

Server Code

Below is the server code that will return the SWML document.

Node.js
Python

Pre-requisites

  • ExpressJs installed in your environment.
  • ngrok installed in your environment.
const express = require('express');
const ngrok = require('ngrok');
const app = express();

// Body parser middleware to handle JSON payloads
app.use(express.json());

// Define the route
app.post('/swml', (req, res) => {

    let reqBody = req.body;
    console.log(reqBody);

    let user = reqBody.params.User;
    let token = reqBody.params.Token;

    const swml = {
        "sections": {
            "main": [\
                {\
                    "play": `say: Hello ${user}, welcome to the SWML demo! Your token is ${token}!`\
                }\
            ]
        }
    };

    res.json(swml);
});

// Start the server and use ngrok to expose it
const port = 5000;
app.listen(port, async () => {
    const url = await ngrok.connect(port);
    console.log(`Server running on ${url}`);
});

SignalWire Developer Documentation