Use variables in code
If you need more flexibility in how you handle information in Botpress Studio, you can use variables in code (for example, in an Execute Code Card).
Variables in code follow the pattern variabletype.variablename
.
Here are a few examples of how you might use variables in code:
Assign a value to a variable
This is typically how you’d initialize a variable or change its value.
Use variables in conditional statements
This checks the value of a variable and executes code accordingly.
Use variables in functions
Here, you might pass a variable as a function argument or use it inside a function.
Combine variables
You might want to combine or concatenate variables.
Check variable types
Botpress might throw an error if types don’t match. To avoid this, you can use type checking before assigning values.
Use variables with external APIs
If your bot interacts with external services, you might use an environment variable to store an API key: