Template project to facilitate implementing, compiling, and building Botica bots in Typescript using npm and botica-lib-node.
Important
If you plan to use Javascript, not Typescript, to develop your bot, use the botica-seed-node template.
You have two main options for setting up your bot project:
If you want to create this bot as a subdirectory to an existing Botica project
(e.g., alongside your environment.yml file), use the Botica Director's init
command:
./botica-director init typescript <your-bot-directory-name>Replace <your-bot-directory-name> with the desired folder name for your bot's
project (e.g., worker-bot). This command will create the project files
directly in that subdirectory.
If you want to develop this bot in its own dedicated Git repository, click the Use this template button on GitHub to create a new repository based on this one.
First, modify the package.json file to match your project's details,
specifically the name and author properties.
Then, install the project's dependencies using npm. Make sure you have node
and npm installed on your machine.
npm installYour bot's logic begins by calling the asynchronous botica() function. This
returns a Bot instance that you can use to register listeners (bot.on()),
define proactive tasks (bot.proactive()), and interact with the Botica
environment. Make you sure you start the bot after configuring it, with await bot.start().
You can follow one of these examples for inspiration.
Tip
Full project examples are also available, with their respective Node implementations using TypeScript. Check out botica-infrastructure-fishbowl.
How you run your bot depends on how you set it up in Step 1.
The Botica Director can automatically build your bot from the source code before starting the environment. You do not need to run any manual build scripts.
In your environment.yml file, use the build property to point to your bot's
directory:
bots:
my-ts-bot:
# The 'build' property tells the Director to build a Docker image from the
# project located at the specified relative path before running it.
build: "./worker-bot"
replicas: 1
lifecycle:
type: reactiveWhen you run ./botica-director, it will detect the build property, execute
the build process defined in the project's Dockerfile, and then launch the
container.
If you are working in a standalone repository, you need to manually build the
Docker image so it is available to your Docker daemon. You can tag it however
you like (e.g., my-org/my-bot:latest):
docker build -t my-org/my-bot:latest .In your environment.yml file, use the image property to reference the tag
you just created:
bots:
my-ts-bot:
# The 'image' property tells the Director to look for an existing
# Docker image with this tag.
image: "my-org/my-bot:latest"
replicas: 1
lifecycle:
type: reactive