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:
You can set a variable with:
Welcome to our service!
).Examples:
Note: If the
return
keyword is omitted, it is automatically added.
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:
Resets the variable to its uninitialized state.
Converts the variable into a list and appends new values.
Sets the variable as web
or whatsapp
based on the user’s platform.
Saves the conversation transcript into a variable. Useful for sending recaps or providing AI context.
Assigns the unique ID corresponding to the current user interaction.
Generates a unique ID using the CUID algorithm.
The Pop operation removes the last item from the list variable you provide, and stores that item in the Popped item variable. It is particularly useful when you want to build a loop that processes list items one by one.
The Shift operation removes the first item from the list variable you provide, and stores that item In the Shifted item variable. It is particularly useful when you want to build a loop that processes list items one by one.
Sets the variable with values like:
morning
afternoon
evening
night
This is determined based on the user’s local time.
Fetch data from a corresponding index in two parallel lists.
Example:
Labels
: [Action, Drama, Comedy]
IDs
: [123, 456, 789]
Selected ID
is set to 456
.Assign date values:
Yesterday
, Now
, or Tomorrow
in ISO format.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.
By default, variables are session-specific. Enabling this option will save the variable in the Submissions table for future reference.