> ## Documentation Index
> Fetch the complete documentation index at: https://botpress-pb-update-api.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Using code in Studio

You can **write custom code to interact with your bot programmatically** in many areas of Botpress Studio.

<Tip>
  Wherever you write custom code in Studio, you can access the [event object's properties](/studio/guides/advanced/event-properties) to get information about the last event in your bot's operation.
</Tip>

## Language

You can use [TypeScript](https://www.typescriptlang.org) or regular [JavaScript](https://developer.mozilla.org/en-US/docs/Web/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](/studio/concepts/actions)                       | When an [Autonomous Node](/studio/concepts/nodes/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](/studio/concepts/cards/execute-code) | At a specific point in a [Workflow](/studio/concepts/workflows)                                                    | ❌        | Perform a one-time operation on some data provided by a user                  |
| [Hooks](/studio/concepts/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 |

Check out each section below for a more detailed breakdown:

### Actions

[Actions](/studio/concepts/actions) are reusable code snippets that only [Autonomous Nodes](/studio/concepts/nodes/autonomous-node) 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](/studio/concepts/cards/execute-code) execute a one-time piece of code at some point in a [Workflow](/studio/concepts/workflows). 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](/studio/concepts/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](https://axios-http.com/docs/intro)                          | HTTP client for making API requests.                                                      | Available globally as `axios`     |
| [Lodash](https://lodash.com)                                        | Utility library for data manipulation.                                                    | Available globally as `_`         |
| [Luxon](https://moment.github.io/luxon/#/)                          | Library for date/time manipulation.                                                       | Available globally as `luxon`     |
| [`botpress/client`](https://www.npmjs.com/package/@botpress/client) | Official Botpress HTTP client to query the [Botpress API](/api-reference/introduction).   | Available globally as `client`    |
| [`bpinternal/zui`](https://www.npmjs.com/package/@bpinternal/zui)   | A fork of [Zod](https://zod.dev) with additional features.                                | Available globally as `z` / `zui` |
| [`botpress/zai`](https://www.npmjs.com/package/@botpress/zai)       | Botpress utility library that uses AI to manipulate and generate Zui schemas and objects. | Available globally as `zai`       |

<Warning>
  You can't import external libraries into the Studio's code editor.
</Warning>
