Untested in long run
v2.2b is in beta, long term & continuous process are currently being tested. Please refer to a stable version in different branch.
WhatsApp AI Bot that watches your chats, runs each message through rules you define, and routes what matters: forwarded, summarized, or skipped, automatically.
- AI-Powered Message Analysis: OpenAI-compatible models route messages intelligently
- Web UI Control: manage routes, rules, and logs from the browser
- Complete Media Support: forwards images, videos, and documents
- Many-to-Many Rule System: reusable rules across multiple forward routes
- Batch Processing: configurable cron interval
- Auto-Cleanup: automatic message retention with configurable TTL
Each forward route can have rules attached, plain-text instructions that tell the AI what to do. Every batch cycle, the AI reads pending messages against those rules and decides:
| Action | What happens |
|---|---|
| Forward | Send the original message as-is |
| Summarize | Condense multiple messages into one |
| Rewrite | Send something entirely different based on the content |
| Skip | Incomplete context (e.g. unanswered question), hold for next batch |
| Drop | Spam or irrelevant, mark as sent without forwarding |
The AI can handle fragmentation (merging related short messages) and adapts based on volume (prefers summaries when 3+ messages pile up).
- No rules = plain forward.
- Add a one-liner = light filter.
- Write a detailed rule = full editorial control over what gets sent and how.
- Full app control from Web UI
- Notify admin on error
- logging massively improved across the app
- added LLM path exfiltration guardrail
- path traversal issue fixed
Two ways to run it. Docker brings up everything (database, bot, watchdog, dashboard) in one command.
The stack is four containers:
| Container | Role | Port |
|---|---|---|
autoforward-mysql |
MySQL 8 database | internal |
autoforward-bot |
WhatsApp client + AI + internal API | 3001 |
autoforward-watchdog |
Start/stop/restart the bot, stream logs | 3002 |
autoforward-dashboard |
nginx serving the built web UI | 8080 |
The watchdog and web interface stays up even when the bot is down, this allow the user to turn the bot online effortlessly.
-
Clone the repository
git clone <repository-url> cd autoforward
-
Create the environment file
cp .env.example .env
-
Fill in
.env.# Your WhatsApp number, digits only (no + or country code) ADMIN_NUMBER=628123456789 # OpenAI-compatible model provider OPENAI_API_KEY=sk-your-key OPENAI_BASE_URL=http://host.docker.internal:20128/v1 AI_MODEL_NAME=ambatukam-6.7-max # MySQL DATABASE_USER=autoforward DATABASE_PASSWORD=change-me DATABASE_NAME=autoforward DATABASE_URL="mysql://autoforward:change-me@mysql:3306/autoforward"
Running the model server on your host (LM Studio, Ollama, 9router, etc.)? Point
OPENAI_BASE_URLathost.docker.internal, notlocalhost, or the container cannot see it. -
Build the dashboard. The nginx container serves
web/dist, so it has to exist first:cd web npm install npm run build cd ..
-
Start everything
docker compose up -d --build
-
Open the dashboard at http://localhost:8080 and scan the QR code shown there. It is also printed in the bot logs:
docker logs autoforward-bot -f
Wait for
WhatsApp Connection Ready. From the dashboard you can add forwards, write rules, watch logs, and start/stop the bot.
Rebuilt the web UI later? Just run npm run build again in web/ and refresh the browser. The dist folder is bind-mounted, so no container restart is needed.
-
Prerequisites
- Node.js 22+
- MySQL 8.0+
- npm
-
Install dependencies
npm install
-
Point
.envat your local databaseDATABASE_HOST=localhost DATABASE_PORT=3306 DATABASE_USER=autoforward DATABASE_PASSWORD=your_password DATABASE_NAME=autoforward DATABASE_URL="mysql://autoforward:your_password@localhost:3306/autoforward" -
Apply database migrations
npx prisma generate npx prisma migrate deploy
-
Start the bot
npm run dev
-
Start the dashboard (separate terminal, hot-reloads at http://localhost:5173)
cd web npm install npm run dev
The watchdog is optional in local dev: it drives the Docker containers, so it only matters when the bot runs containerized. To run it anyway:
npx tsx watchdog/index.tsAll settings live in .env. Docker reads it via env_file, local dev loads it with dotenv.
Core
| Variable | Required | Description |
|---|---|---|
ADMIN_NUMBER |
Yes | Your WhatsApp number, digits only. Used for error alerts and bot identification |
OPENAI_API_KEY |
Yes | API key for the OpenAI-compatible service |
OPENAI_BASE_URL |
Yes | Base URL of the model provider (.../v1) |
AI_MODEL_NAME |
Yes | Model used to classify and rewrite messages |
Database
| Variable | Required | Description |
|---|---|---|
DATABASE_USER |
Yes | MySQL user |
DATABASE_PASSWORD |
Yes | MySQL password |
DATABASE_NAME |
Yes | MySQL database name |
DATABASE_HOST |
Yes | Database host: mysql in Docker, localhost for local dev |
DATABASE_PORT |
No | Database port |
DATABASE_URL |
Yes | Full connection string, used by Prisma migrations |
Batch and storage
| Variable | Required | Description |
|---|---|---|
BATCH_FORWARD_INTERVAL_MINUTES |
No | How often pending messages are processed (1-59) |
CLEANUP_RETENTION_DAYS |
No | Days before sent messages and media are deleted (min 1) |
STORAGE_DIR |
No | Where downloaded media is written |
AUTH_STATE_DIR |
No | Where WhatsApp session credentials are stored |
CACHE_TTL_SECONDS |
No | TTL for cached group metadata |
GROUP_CACHE_TTL_SECONDS |
No | TTL for the Baileys socket group cache |
Services
| Variable | Required | Description |
|---|---|---|
INTERNAL_HTTP_PORT |
No | Bot internal API the dashboard calls |
WATCHDOG_HTTP_PORT |
No | Watchdog API (lifecycle + logs) |
DASHBOARD_PORT |
No | Host port for the dashboard container |
BOT_CONTAINER_NAME |
No | Container the watchdog supervises |
DEBUG |
No | true enables verbose debug logs in console and dashboard |
Defaults for optional variables are documented in .env.example.
INTERNAL_HTTP_PORTandVITE_BOT_URLmust point at the same port, and so mustWATCHDOG_HTTP_PORTandVITE_WATCHDOG_URL. A mismatch does not crash anything, but the dashboard shows the bot as offline because the browser is calling a port nothing listens on. Compose also publishes${PORT}:${PORT}, so the two port variables must also differ from each other.
The only value that changes between the two is the database host:
Docker uses the compose service name mysql:
DATABASE_HOST=mysql
DATABASE_URL="mysql://autoforward:password@mysql:3306/autoforward"Local uses localhost (or your MySQL server IP):
DATABASE_HOST=localhost
DATABASE_URL="mysql://autoforward:password@localhost:3306/autoforward"- Cleanup saved files
- Rewrite message handler to return the processed message IDs, not just the processed count for error handling
- Introduce message uniqueness using msg.key.id to prevent duplicate chat
- add cron run state so cron cannot run when its still running
- Adding sent chat history for model context
- File & folder structure refactor
Released under the MIT License.
You are free to use, modify, and distribute this software, including commercially, as long as the copyright notice and license text are preserved. The software comes with no warranty.