Guide FloatChat

Floatchat- User Guid

Script Node

1.Introduction: #

Floatchat provides the Script Node feature, which allows you to include custom JavaScript code that will be executed during the path execution. This enables you to create complex flows with logical operations, arithmetic computations, data processing, and transformations, all without the need for a separate backend infrastructure. The script is executed directly on the Floatchat platform.

The Script Node can send various types of outputs, including text messages, carousels, and messages with options prompts. Additionally, you can branch the path flow execution based on the output of the script and set attributes for further use in subsequent flows.

2. Usage Notes:

Here are some important usage notes for the Script Node in Floatchat:

  • The script code can have a maximum length of 2500 characters.
  • The script should contain a process function, provided by the system, which is used to determine the behavior of the node based on the output of the script execution. The process function is typically included at the end of the script.
  • The script execution has a time window of 10 seconds. If the script does not complete within this time, it will be abruptly terminated.
  • The script should be syntactically correct, and only scripts that execute successfully will be allowed to be saved. Errors will be highlighted with relevant messages. To simulate the execution of a script containing attributes, you can pass a value from the console.
  • Attributes can be accessed within the script using the # character instead of curly braces, following the auto-complete list of attributes.
  • External API calls cannot be made directly from the script node. It is recommended to use the JSON API for such calls and use the Script Node to process or manipulate the output as needed. Certain function availability may be restricted in the sandboxed environment of the script node.
  • Standard libraries like Math, Date/Time functions, and string operations are provided within the script node.
  • You can set up an error message for the script node to be displayed in case of script execution failure or data issues.

3. Sample Use Cases: #

The Script Node in Floatchat can be used for various purposes, including:

  • Computation functions such as interest calculators, temperature converters, currency converters, etc.
  • Evaluating multiple complex conditions and performing different actions or triggering different paths based on the evaluation.
  • String manipulation operations like concatenation or checking for the presence of a substring.
  • Generating random numbers for unique values or associating them with API calls.
  • Retrieving and manipulating the current system date and time.

– Post-processing and transforming data obtained from API calls, strings, or numeric values.

4. Process Function: #

The process function is a mandatory system-provided function that is used to inform the platform about how to process the output of the script node. It should typically be called at the end of the script execution and takes a single JSON object as a parameter, which can be set up according to the intended behavior.

5. Script Node Usage for Flow Operations: #

The Script Node can perform several operations, including:

  • Sending a text message
  • Sending a message with options
  • Setting attributes in the system for a user
  • Changing the path flow execution by triggering a specific path

Each operation requires a specific object structure within the script code, as explained in the documentation. Examples and sample scripts are provided for each operation, including sending messages, carousels, setting attributes, and triggering paths or nodes dynamically based on script output.

Note: When copying the script from this document, ensure that quotation marks (“) are replaced correctly to avoid syntax errors.

What are your feelings
Scroll to Top