You will need:
- A published bot with at least one variable
- Basic knowledge of JavaScript/TypeScript
Step 1: Define your Action
First, define an Action that updates your variable.Select the Action’s default name (
New Action) in the upper-left-corner of the editor, then rename it to updateVariable.In the code editor, write code that updates the value of your variable to
newValue and returns an empty object.The exact code depends on the name and scope of the variable you want to update. For example, if you have a user variable named loginEmail, you would write:Erase everything in the code editor, then paste in the following code:
This code snippet assumes that the data type of the variable you’re updating is a
string. If your variable uses a different data type, change this to its corresponding Zod data type.Step 2: Call your Action using the API
Now, you can call your Action using the Runtime API’scallAction endpoint. Just pass in an object that matches the Action’s input schema:
- In an HTTP request
- Using the Botpress client
The variable has been updated from outside the Studio.