Default Nodes

Default nodes in Bot Studio are designed for cross-platform compatibility, ensuring they function uniformly across all processes and platforms. In this documentation, we will see how they work.

Webhook Request Event

This event is triggered when an API request is received. The bots utilize Express.js and HTTP servers, so this event captures the variables passed as Express.js request parameters, such as query and body.

Additionally, it returns the useragent and cookies variables, obtained through the express-useragent and cookie-parser modules.

Condition

The "Condition" node checks whether two inputs satisfy a specified condition. Depending on the result, it triggers either the "true" output (if the condition is met) or the "false" output (if not).

This node requires three parameters:

  • input_1: The first input. Should be a string.
  • input_2: The second input. Should be a string.
  • condition: The condition to be applied for the comparison. This should be a string.

The available conditions are:

  • match: Checks if the first input matches the second.
  • start: Checks if the first input starts with the second.
  • end: Checks if the first input ends with the second.
  • include: Checks if the first input contains the second.
  • greater: Checks if the first input is greater than the second.
  • less: Checks if the first input is less than the second.
  • regexp: Checks if the first input matches the second using a regular expression.
  • type: Checks if the data type of the first input matches the second (e.g., string).

This node has only two outputs:

  • true: Triggered when the condition is met.
  • false: Triggered when the condition is not met.

Delay

The "Delay" node introduces a pause in the process. The delay duration must be between 0 and 10,000 milliseconds (10 seconds). For example, a delay of 2 seconds is equivalent to 2000 milliseconds.

If the specified delay is less than 0, it will default to 0. If it exceeds 10,000 milliseconds, it will be capped at 10,000.

This node requires the following parameter:

  • ms: The delay duration in milliseconds.

Random

The "Random" node selects a random output from the connected nodes. If no nodes are connected, no selection occurs.

This node has only three outputs for triggering subsequent nodes:

  • 1
  • 2
  • 3

One of these outputs will be randomly selected to execute the connected nodes.

This node supports only three outputs. To introduce more random choices, additional "Random" nodes need to be created.

Set Variable

The "Set Variable" node is used to manage variables. It allows you to create, modify, or remove a variable. To remove a variable, specify its name without providing a value. To create or modify a variable, specify both the name and value.

This node requires two parameters:

  • name: The name of the variable.
  • value: The value of the variable.

Assign Variables

The "Assign Variables" node assigns JSON objects to the variable list and supports nested variables. Unlike the Set Variable node, it can create nested variables but cannot remove existing variables unless they are nested.

This node requires a json input for transferring data. This data is assigned to the variable list. For example, with the following JSON input:

{
  "variable_name_here": ["variable_value_here"]
}

A new variable named variable_name_here will be created with the corresponding value.

You can also pass data directly using the json parameter. If no json input is connected, this data will be used instead.

API Request

The "API Request" node enables your bot to interact with external applications via API requests. It is powered by the JavaScript Fetch API.

You can specify request parameters (e.g., queries, headers, body) as a JSON object. Upon a successful request, the node returns status, statusText, ok, redirected, url, and the JSON response.

Note: The node's address must use the HTTP protocol to avoid blocking the request.

This node uses a json input for sending the request. For example:

{
  "method": "POST",
  "body": {
    "number": 2
  }
}

The body parameter is automatically converted into a JSON string during processing, and the request content type will be set to application/json.

You can also pass data directly using the json parameter. If no json input is connected, this data will be used for the request.

The node uses a json output to transfer the request result.

Python

The "Python" node allows your bot to execute Python code for enhanced control. It runs in an isolated environment managed by Bot Studio, ensuring security and resource efficiency. More details on the isolation mechanism can be found here.

Key limitations for Python code execution:

  • Memory Limit: 20MB
  • Execution Time Limit: 5 seconds
  • Module Restrictions: Only a limited set of default Python modules are available.

If the code exceeds these limits or uses disallowed modules, the process will automatically stop without producing output.

The Python nodes provide a default context object for process integration, containing:

  • variables: An object list of all process variables. You can modify this list to change variables.
  • inputs: An array of connected JSON object inputs to the Python code with their data.
  • output: An object containing all JSON data to be transferred to the next node.
  • execute_next: By default, subsequent nodes execute after the Python node. Set this to False to stop further processes.

Example: To set a new variable using the Python node, use:

context["variables"]["new_variable"] = "value"

Example: For specifying a JSON output, use:

context["output"] = { "test": True }

Example: To retrieve a value from the first connected input:

context["variables"]["message"] = context["inputs"][0]["message"]

Example: To stop the subsequent connected node:

context["execute_next"] = False

This node accepts json input and output for handling JSON data.

JavaScript

JavaScript nodes run in an isolated environment powered by isolated-vm. This environment has limitations, such as the inability to import modules or perform certain actions like making API requests using the fetch method.

Key limitations for JavaScript code execution:

  • Memory Limit: 10MB
  • Execution Time Limit: 5 seconds

If the code exceeds these limitations or uses disallowed features, it will not produce any output.

The JavaScript nodes provide a default context object for process integration, containing:

  • variables: An object list of all process variables. You can modify this list to change variables.
  • inputs: An array of connected JSON object inputs to the JavaScript code with their data.
  • output: An object containing all JSON data to be transferred to the next node.
  • executeNext: By default, subsequent nodes execute after the JavaScript node. Set this to false to stop further processes.

Example: To set a new variable using the JavaScript node, use:

context.variables.new_variable = "value";

Example: For specifying a JSON output, use:

context.output = { test: True };

Example: To retrieve a value from the first connected input:

context.variables.message = context.inputs[0].message;

Example: To stop the subsequent connected node:

context.executeNext = false;

This node accepts json input and output for handling JSON data.

KVDB

The "KVDB" node integrates with Bot Studio's built-in key-value database, allowing you to retrieve, set, modify, or delete data.

To modify or delete data, provide the key and value inputs. To delete data, set the value to null. To create or modify data, provide a value. If a key input is provided, the node returns an object containing the key's value. Use the Assign Variables node to assign and utilize this data.

If no key input is provided, the kvdb object containing all key-value data will be returned.

This node uses a json output to return the result as JSON data.

It requires two parameters: key and value.

Log

The "Log" node adds new entries to the built-in log system. Logs can include any datatype without limitations.

Logs are saved in JSON format. This node accepts a json input, and if none is provided, it will use the specified data parameter.