A WhatsApp bot that sends daily diet menus at scheduled times. It helps users follow their meal plan by delivering the right menu (breakfast, pre-workout, lunch, afternoon snack, dinner) according to the time of day.
- Scheduled diet messages: Sends the day's menu to a WhatsApp number at fixed times (configurable via cron, e.g. 6h, 10h, 12h, 17h, 19h).
- Meal types by time: Picks the correct meal type from the current time (breakfast, pre-workout, lunch, afternoon snack, dinner) and sends the matching menu.
- Diet management: REST API to create and list diets by type.
- Manual send: API to send a custom message to a WhatsApp number.
| Area | Technology |
|---|---|
| Language | TypeScript (Node.js, ESM) |
| HTTP | Fastify |
| whatsapp-web.js | |
| Database | better-sqlite3 (SQLite) |
| Scheduling | node-cron |
| Validation | zod |
src/
├── main.ts # Bootstrap: WhatsApp client, Fastify, DB, routes, cron
├── domain/
│ ├── entitie/ # Diet entity and meal types (breakfast, lunch, etc.)
│ └── ports/ # Interfaces (WhatsApp, scheduler, diet repository)
├── application/
│ ├── use-cases/ # Create diet, find diet by type, send message, send diet by time
│ └── dto/ # Request/response DTOs
└── infra/
├── adapters/ # HTTP routes and controllers (diet, send)
├── client/ # WhatsApp client, DB client
├── outbound/persistence/ # Diet repository (SQLite)
└── scheduler/ # Cron job that triggers “send diet by time”
- Domain: Core entities and ports (no framework dependencies).
- Application: Use cases and DTOs; orchestrate domain and infra via ports.
- Infra: HTTP (Fastify), WhatsApp, SQLite, and cron; implements the ports.
-
Install dependencies
npm install
-
Environment
- Create a
.env(see.env.exampleif present). - Optional:
DIET_CRON_PHONE— WhatsApp number (with country code) that receives the scheduled diet messages. If not set, the cron is not scheduled.
- Create a
-
Run
npm run dev
On first run, scan the QR code in the terminal with WhatsApp to link the session.
- Diets: Create a diet (name, description, type, menu items); list diets by meal type.
- Send: Send a text message to a given WhatsApp number.
Port and exact routes can be checked in src/infra/adapters/ (e.g. diet.route.ts, send.routes.ts).
Com o servidor rodando (npm run dev) e Client is ready! no terminal:
Invoke-RestMethod -Uri "http://localhost:3000/send-message" -Method POST -ContentType "application/json" -Body '{"phone_number": "5519999372271", "message": "Teste"}'Não rode npm run send-test com o servidor no ar: a sessão WhatsApp fica em uso e o script tentará abrir outro navegador com o mesmo perfil e dará erro.