How unilights/whatsapp-bot works
This is a WhatsApp attendance bot: it reads messages from a configured group, classifies attendance notes, and records them in Google Sheets and optionally MongoDB. Its main workflow handles live messages; when WhatsApp becomes ready, the same orchestrator also starts historical backfill. A shared processed-ID file prevents duplicate handling. The API provides QR-linking/status endpoints and attendance analytics backed by MongoDB. The README documents the supported attendance types, employee sheets, and backfill; source excerpts show the runtime calls. Other subsystems are represented from README capabilities and the source index where their implementation was not sampled.
Main entry points: whatsapp.js WhatsApp client · backfill.js History backfill · api.js HTTP API · sheets.js Sheet writer
Components 17
Message ingestion
- Runtime startup
src/index.js - WhatsApp client
src/whatsapp.js - History backfill
src/backfill.js
Attendance processing
- Message parser
src/parser.js - Type keywords
src/parser-config.js - Processed IDs
src/processed-ids.js - Runtime configuration
src/config.js
Attendance storage
- Sheet writer
src/sheets.js - Attendance store
src/attendance-store.js - MongoDB connection
src/db.js
Linking and analytics
- HTTP API
src/api.js - QR connection state
src/qr-state.js - Dashboard UI
public/index.html
Other components
- HR operator
- WhatsApp group
- Google Sheets
- MongoDB
Connections 28
- HR operator → WhatsApp client: sends messages
README.md - Runtime startup → MongoDB connection: connects
src/index.js - Runtime startup → HTTP API: starts
src/index.js - Runtime startup → WhatsApp client: starts
src/index.js - WhatsApp group → WhatsApp client: delivers events
src/whatsapp.js - WhatsApp client → Message parser: parses messages
src/whatsapp.js - History backfill → WhatsApp group: fetches history
src/backfill.js - WhatsApp client → History backfill: starts on ready
src/whatsapp.js - History backfill → Message parser: parses messages
src/backfill.js - Message parser → Type keywords: matches types
src/parser.js - WhatsApp client → Processed IDs: checks and records IDs
src/whatsapp.js - History backfill → Processed IDs: checks and records IDs
src/backfill.js - WhatsApp client → Sheet writer: writes attendance
src/whatsapp.js - WhatsApp client → Attendance store: saves attendance
src/whatsapp.js - History backfill → Sheet writer: writes attendance
src/backfill.js - History backfill → Attendance store: saves attendance
src/backfill.js - Sheet writer → Google Sheets: appends rows
src/sheets.js - Attendance store → MongoDB connection: uses connection
src/attendance-store.js - MongoDB connection → MongoDB: connects and indexes
src/db.js - HTTP API → Attendance store: queries attendance
src/api.js - HTTP API → MongoDB connection: checks health
src/api.js - WhatsApp client → QR connection state: updates status
src/whatsapp.js - HTTP API → QR connection state: reads status
src/api.js - HR operator → HTTP API: opens linking page
README.md - HTTP API → Dashboard UI: serves UI
src/api.js - Sheet writer → Runtime configuration: reads settings
src/sheets.js - WhatsApp client → Runtime configuration: reads settings
src/whatsapp.js - History backfill → Runtime configuration: reads settings
src/backfill.js