This is a library to create WhatsApp bots. It is a WhatsApp implementation of the @totigm/bot-builder package, which handles all the commands stuff behind the scenes, so you can focus on your bot's logic.
The whatsapp-web.js library is used for this implementation.
npm i @totigm/whatsapp-bot
or
yarn add @totigm/whatsapp-bot
You can use this WhatsApp bot template to generate your own. This template has everything set up for you, so you can start coding your bot right away.
The template has TypeScript, Docker, ESLint, and Prettier already configured, so you have a nice developer experience and a production-ready bot.
Start adding commands to your bot by checking the reference documentation.
The WhatsApp bot template and bot examples are also a good reference on how to use this library.
import WhatsappBot from "@totigm/whatsapp-bot";
const bot = new WhatsappBot();
bot.addCommand(
"hey",
async (message, client) => {
const chatId = message.from;
const contact = await client.getContactById(chatId);
return `Hey ${contact.pushname}! How are you doing?`;
},
{
description: "Say hey",
explanation: "The bot will say hey to the user using their WhatsApp's name",
example: {
output: "Hey Toti! How are you doing?",
},
},
);
The previous code will create a bot that works like this:
- WhatsApp stickers bot: WhatsApp bot that converts images and videos to stickers.
When you create a bot, you can pass an options object to customize it. Check its options documentation for more information.
const options = { ... };
const bot = new WhatsappBot(options);
To deploy your WhatsApp bot, check out this template, which creates a Docker image with everything needed for the whatsapp-web.js library to work. This will help you to deploy your bot to the cloud provider of your choice.
This library automatically checks if the app is being run on a Docker container and set its configurations according to that, so you don't have to worry about it.
Contributions are more than welcome!
We think that you might have great ideas to make this project even better. If you do, please create a pull request and/or issue following the contribution guidelines.
Give a ⭐️ if this project helped you!
Copyright © 2022 Toti Muñoz.
This project is MIT licensed.
This project was made with ❤ and TypeScript