A powerful, extensible WhatsApp bot built with TypeScript and modern architecture
This application is a WhatsApp client that connects to WhatsApp Web using Puppeteer, enabling real-time automation and command execution. Built with TypeScript and following modern software architecture principles, it provides a robust and scalable foundation for WhatsApp automation.
- ๐ค Command-based Architecture - Extensible command system with interface-based design
- ๐ Alias Support - Multiple names for the same command
- ๐ก๏ธ Error Handling - Robust error handling with user-friendly messages
- ๐ Type Safety - Full TypeScript implementation
- ๐ฏ Easy to Extend - Add new commands in minutes
- ๐ Group Validation - Built-in group-only command support
- ๐ฌ Real-time Responses - Typing indicators and instant feedback
| Command | Aliases | Description |
|---|---|---|
!help |
!ajuda, !comandos, !commands |
Shows all available commands with descriptions |
!cotacao |
!moeda, !dolar, !bitcoin |
Get current currency exchange rates (USD, BTC, EUR) |
!cep <code> |
- | Search Brazilian postal code information |
!perfil @user |
!foto, !avatar, !pic |
Get user's profile picture |
!mencionar |
!everyone, !all, !todos |
Mention all group members (admin only) |
!sms @user |
- | Send SMS to mentioned user |
Note: All commands start with
!prefix
- Node.js 16+
- npm or yarn
- WhatsApp account
# Clone the repository
git clone git@github.com:caioagiani/whatsapp-bot.git
cd whatsapp-bot
# Install dependencies
npm install --legacy-peer-deps
# or
yarn install
# Configure environment variables
cp .env.example .env
# Edit .env and add your Mobizon API credentials (optional, for SMS feature)
# Start the bot
npm run dev
# or
yarn dev- When you start the bot for the first time, a QR code will appear in your terminal
- Open WhatsApp on your phone
- Go to Settings โ Linked Devices โ Link a Device
- Scan the QR code displayed in your terminal
- Wait for the authentication to complete
โ Your bot is now connected and ready to receive commands!
This project follows a clean, interface-based architecture that makes it easy to maintain and extend.
src/
โโโ app/
โ โโโ commands/ # All command implementations
โ โ โโโ CepCommand.ts
โ โ โโโ EconomyCommand.ts
โ โ โโโ ProfileCommand.ts
โ โ โโโ QuoteCommand.ts
โ โ โโโ SmsCommand.ts
โ โ โโโ index.ts # Command registration
โ โโโ interfaces/ # TypeScript interfaces
โ โ โโโ ICommand.ts # Base command interface
โ โ โโโ Cep.ts
โ โโโ utils/ # Utility classes
โ โโโ BaseCommand.ts # Abstract base class for commands
โ โโโ CommandDispatcher.ts
โโโ config/ # Configuration files
โโโ data/ # WhatsApp session data
โโโ services/ # External services
โ โโโ whatsapp.ts # WhatsApp client setup
โ โโโ mobizon.ts # SMS service
โโโ index.ts # Application entry point
The bot uses a modern command pattern with the following benefits:
- โ
Interface-based design - All commands implement
ICommand - โ
Base class with helpers -
BaseCommandprovides common functionality - โ Automatic registration - Commands are registered at startup
- โ Alias support - Multiple names for the same command
- โ Centralized error handling - Consistent error messages
- โ Type safety - Full TypeScript support
๐ View Technical Documentation for detailed architecture information.
Creating a new command is simple:
// src/app/commands/HelloCommand.ts
import { BaseCommand } from '../utils/BaseCommand';
import type { Message } from 'whatsapp-web.js';
export class HelloCommand extends BaseCommand {
name = 'hello';
description = 'Responds with a greeting';
aliases = ['hi', 'hey', 'ola'];
async execute(message: Message, args: string[]): Promise<Message> {
await this.sendTyping(message);
const name = args.join(' ') || 'friend';
return message.reply(`๐ Hello, ${name}! How can I help you?`);
}
}// src/app/commands/index.ts
import { HelloCommand } from './HelloCommand';
export const initializeCommands = (): void => {
// ... other commands
commandDispatcher.register(new HelloCommand());
};That's it! Your command is now available with all aliases: !hello, !hi, !hey, !ola
Create a .env file in the root directory:
# Mobizon SMS Service (optional)
MOBIZON_URL_SRV=https://api.mobizon.com.br
MOBIZON_API_KEY=your_api_key_hereFor admin-only commands (like !mencionar), configure authorized users in:
src/config/integrantes.json
{
"company": [
{
"numero": "5511999999999",
"admin": true
}
]
}User: !help
Bot: ๐ Available Commands
โโโโโโโโโโโโโโโโโโโโ
๐น !help
Shows all available commands with their descriptions
Aliases: !ajuda, !comandos, !commands
๐น !cotacao
Shows current exchange rates (USD, BTC, EUR)
Aliases: !moeda, !dolar, !bitcoin
...
User: !cotacao
Bot: ๐ Cotaรงรฃo Atual ๐ฐ๐ค๐น
๐ฒ Dรณlar Americano (USD)
Valor atual: R$ 5.25
Valor mais alto: R$ 5.30
Valor mais baixo: R$ 5.20
...
User: !cep 01310-100
Bot: ๐ฎ Informaรงรตes do CEP
CEP: 01310-100
Logradouro: Avenida Paulista
Bairro: Bela Vista
Cidade: Sรฃo Paulo
UF: SP
User: !perfil @John
Bot: ๐ Buscando foto de perfil...
[Sends profile picture]
# Run linter
npm run lint
# Run in development mode with auto-reload
npm run dev-
!cotacao- Returns currency rates -
!moeda- Works as alias for cotacao -
!cep 01310-100- Returns postal code info -
!cep- Returns usage error -
!perfil @user- Returns profile picture (in groups) -
!perfil @user- Returns error (in private chat) -
!invalidcommand- Silently ignored
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Extend
BaseCommandfor new commands - Add proper error handling
- Include JSDoc comments
- Test your changes thoroughly
Copyright ยฉ 2022-2025 Caio Agiani
This project is licensed under the GNU AGPL License.
This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or affiliates. The official WhatsApp website can be found at https://whatsapp.com.
"WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.
Use this bot responsibly and in accordance with WhatsApp's Terms of Service.
Special thanks to:
- @pedroslopez - whatsapp-web.js library
- All contributors who have helped improve this project
- Author: Caio Agiani
- LinkedIn: linkedin.com/in/caioagiani
- Email: caio.agiani14@gmail.com
- GitHub: @caioagiani
If you find this project useful, please consider giving it a โญ๏ธ!
Made with โค๏ธ by Caio Agiani
