Wherever you write custom code in Studio, you can access the event object’s properties to get information about the last event in your bot’s operation.
Language
You can use TypeScript or regular JavaScript for custom code.Where you can use code
Depending on your needs, you have a few options on where to write code in Studio. Here’s a cheat sheet:Option | Executes | Reusable | Example |
---|---|---|---|
Actions | When an Autonomous Node decides to (based on the conversation’s context) | ✅ | Make an API call to a weather service whenever the user asks for the weather |
Execute Code Cards | At a specific point in a Workflow | ❌ | Perform a one-time operation on some data provided by a user |
Hooks | At a specific stage of the bot’s operation | ✅ | Every time a bot responds, add the total AI spend for its response to a table |
Actions
Actions are reusable code snippets that only Autonomous Nodes can use. Use Actions when:- You need to execute a piece of code more than once
- You want AI to decide when to execute your code
Execute Code Cards
Execute Code Cards execute a one-time piece of code at some point in a Workflow. They’re not reusable and can’t be added to an Autonomous Node. Use Execute Code Cards when:- You only need to execute a piece of code in one place
- You want complete control over when the code executes
Hooks
Hooks execute code at specific stages of your bot’s operation, like before every user message or after every conversation ends. They operate separately from your bot’s conversational logic—when you create a Hook, it always executes at the same stage, no matter what changes you make to your Workflow. Use Hooks when:- You need to execute a piece of code every time your bot reaches a certain stage of its operation
- You need access to information about the Autonomous Node’s iteration or the current turn’s metadata
Libraries
The following libraries come pre-installed in the Studio’s code editor:Name | Description | Usage |
---|---|---|
Axios | HTTP client for making API requests. | Available globally as axios |
Lodash | Utility library for data manipulation. | Available globally as _ |
Luxon | Library for date/time manipulation. | Available globally as luxon |
botpress/client | Official Botpress HTTP client to query the Botpress API. | Available globally as client |
bpinternal/zui | A fork of Zod with additional features. | Available globally as z / zui |
botpress/zai | Botpress utility library that uses AI to manipulate and generate Zui schemas and objects. | Available globally as zai |
You can’t import external libraries into the Studio’s code editor.