How to use the Set Variable block in Release0 to assign and manipulate data in your chatbot agent
The Set Variable block dynamically assigns, manipulates, and manages variables in workflows, enabling advanced operations and data transformations within your chatbot agent.
The Set Variable block is a versatile tool that allows you to assign, manipulate, and manage variables dynamically in workflows. Below is a comprehensive guide explaining its functionalities and use cases.
The Set Variable block enables you to:
- Assign predefined values or custom values to variables.
- Manipulate variables using JavaScript expressions.
- Transform variables for specific operations (e.g., calculations, string transformations).
- Fetch specific data from lists using index mapping.
- Reset or append values to variables dynamically during execution.
Custom Values
You can set a variable with:
- Plain text (e.g.,
Welcome to our service!
). - Dynamic JavaScript code for advanced operations.
Examples:
Note: If the
return
keyword is omitted, it is automatically added.
Expressions with Existing Variables
Apply operations directly on variables to compute new values.
Examples:
-
Add a Value to a Variable:
-
Compute a Sum of Variables:
-
Extract First Name from Full Name:
-
Transform to Uppercase:
Predefined Value Options
Empty
Resets the variable to its uninitialized state.
Append Values
Converts the variable into a list and appends new values.
Environment Name
Sets the variable as web
or whatsapp
based on the user’s platform.
Transcript
Saves the conversation transcript into a variable. Useful for sending recaps or providing AI context.
Result ID
Assigns the unique ID corresponding to the current user interaction.
Random ID
Generates a unique ID using the CUID algorithm.
Moment of the Day
Sets the variable with values like:
morning
afternoon
evening
night
This is determined based on the user’s local time.
Advanced Operations
Map Item with Same Index
Fetch data from a corresponding index in two parallel lists.
Example:
- Scenario: You have two lists:
Labels
:[Action, Drama, Comedy]
IDs
:[123, 456, 789]
- When the user selects “Drama,” the variable
Selected ID
is set to456
.
Date and Time Presets
Assign date values:
Yesterday
,Now
, orTomorrow
in ISO format.- Optional timezone adjustments.
Client-Side Execution
Run custom JavaScript on the user’s browser to access client-specific properties.
Example: Fetch the user’s geolocation:
Note: Enable “Execute on Client” to use browser-specific features.
Save in Results
By default, variables are session-specific. Enabling this option will save the variable in the Submissions table for future reference.