1. Install The Botpress CLI
To get started, first install the Botpress CLI globally on your machine. You can do this by running the following command in your terminal:All the following examples use
npm
, but feel free to use the package manager of your choice like yarn
or pnpm
.2. Log in to Botpress
Next, log in to your Botpress account using the Botpress CLI. You can do this by running the following command in your terminal:3. Initialize a New Bot
Next, create a new bot using the Botpress CLI. This will set up a new directory with the necessary files and structure for your bot.4. Install Dependencies and Build
Once the bot is initialized, navigate to the bot directory and install the dependencies:5. Browse the Bot Files
You can now open the bot in VS Code or another code editor of your choice:-
bot.definition.ts
: Contains the bot definition. It exports a data structure that describes your bot—what it can do, and how it can be used. This includes the bot’s actions, events. The definition also allows declaring your bot integration dependencies. Keep reading this documentation to learn about all the concepts you can define in this file. -
src/index.ts
: Contains the bot implementation. It exports a data structure that implements what was defined in the bot definition. Keep reading this documentation to learn about the available callbacks and handlers you can implement. -
.botpress/
: Contains the bot output, generated by the build command. It includes types to help you implement your bot, and bundled JavaScript used to execute it. You can explore its contents, but avoid importing from nested files or folders, as its structure may change. Everything meant to be imported is available from the root of this folder. -
package.json
,tsconfig.json
: As with any Node.js TypeScript project, these files contain your package’s metadata and dependencies, and the TypeScript configuration. Thetsconfig.json
file is pre-configured to offer the best experience with the Botpress SDK. Runnpm run check:type
to check for typing errors.
6. Install the Chat Integration
The Chat integration allows you to chat with your bot using HTTP requests. See the Chat Integration page for more information. To install in your bot-as-code, run the following command:bot.definition.ts
file and add the following code:
7. Implement a message handlers
Let’s add some content to the bot. Open thesrc/index.ts
file and add the following code:
8. Deploy the Bot
Once you’ve made the necessary changes to your bot, you can deploy it to Botpress Cloud. Run the following command:--create-new-bot
flag will create a new bot in your workspace. If you want to deploy to an existing bot, you can omit this flag. The CLI will prompt you for the bot in which you want to deploy.
After deploying, go to the Dashboard. You should see your bot listed there.