You can write custom code to interact with your bot programmatically in many areas of Botpress Studio.
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:
OptionExecutesReusableExample
ActionsWhen 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 CardsAt a specific point in a WorkflowPerform a one-time operation on some data provided by a user
HooksAt a specific stage of the bot’s operationEvery time a bot responds, add the total AI spend for its response to a table
Check out each section below for a more detailed breakdown:

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:
NameDescriptionUsage
AxiosHTTP client for making API requests.Available globally as axios
LodashUtility library for data manipulation.Available globally as _
LuxonLibrary for date/time manipulation.Available globally as luxon
botpress/clientOfficial Botpress HTTP client to query the Botpress API.Available globally as client
bpinternal/zuiA fork of Zod with additional features.Available globally as z / zui
botpress/zaiBotpress 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.