Skip to content

zYasuo/diet-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Diet Bot

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.


What it does

  • 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.

Tech stack

Area Technology
Language TypeScript (Node.js, ESM)
HTTP Fastify
WhatsApp whatsapp-web.js
Database better-sqlite3 (SQLite)
Scheduling node-cron
Validation zod

Project structure

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.

Setup

  1. Install dependencies

    npm install
  2. Environment

    • Create a .env (see .env.example if present).
    • Optional: DIET_CRON_PHONE — WhatsApp number (with country code) that receives the scheduled diet messages. If not set, the cron is not scheduled.
  3. Run

    npm run dev

    On first run, scan the QR code in the terminal with WhatsApp to link the session.


API (overview)

  • 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).

Testar envio (PowerShell)

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.


About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors