Node.js microservice for WhatsApp Web integration using QR code authentication (Baileys).
This service is designed for fast backend integration:
- One WhatsApp session per
userId - HTTP endpoints to generate QR, check session status, and send messages
- Inbound and outbound status webhooks to your backend API
- Node.js
18+(recommended20+) - npm
npm installcp .env.example .envSet at least:
SERVICE_API_KEYINTERNAL_API_KEYBACKEND_WEBHOOK_URL
Optional but recommended:
BACKEND_STATUS_WEBHOOK_URLSESSIONS_DIROUTBOUND_ACK_TIMEOUT_MS
npm run devService starts on http://localhost:3001 by default.
- Health check:
curl -X GET "http://localhost:3001/health"- Request QR for a user session:
curl -X GET "http://localhost:3001/qr?userId=00000000-0000-0000-0000-000000000000" \
-H "X-Internal-Api-Key: change-me"- Scan the QR in WhatsApp mobile app.
- Confirm session is connected:
curl -X GET "http://localhost:3001/status?userId=00000000-0000-0000-0000-000000000000" \
-H "X-Internal-Api-Key: change-me"- Send a message:
curl -X POST "http://localhost:3001/send" \
-H "Content-Type: application/json" \
-H "X-Internal-Api-Key: change-me" \
-d '{
"userId": "00000000-0000-0000-0000-000000000000",
"number": "5511999999999",
"message": "Hello from Kurtiu"
}'GET /healthGET /qr?userId=<id>GET /status?userId=<id>POST /send
Auth header required for all endpoints except /health:
X-Internal-Api-Key: <SERVICE_API_KEY>
Copy .env.example to .env and adjust values:
PORT(default3001)BACKEND_WEBHOOK_URLBACKEND_STATUS_WEBHOOK_URL(optional, auto-derived if empty)INTERNAL_API_KEYSERVICE_API_KEYSESSIONS_DIR(default./sessions)REQUEST_TIMEOUT_MS(default10000)OUTBOUND_ACK_TIMEOUT_MS(default8000)MAX_SEND_RETRIES(default3)
npm run dev- development mode with watchnpm run build- TypeScript compile todist/npm start- rundist/index.js
Session statuses:
initializingconnectingawaiting_qrconnectedunhealthydisconnected
Each session is isolated by userId and persisted at sessions/<userId>/ by default.
Detailed docs are in ./docs:
docs/README.mddocs/API.mddocs/ARCHITECTURE.mddocs/WEBHOOKS.mddocs/TROUBLESHOOTING.mddocs/DEPLOYMENT.mddocs/CONTRIBUTING.mddocs/examples/
Contributions are welcome.
Start with docs/CONTRIBUTING.md for setup, scope, and PR guidelines.