How cietsthydroxide/miki_whatsappbot works
Project Type and Purpose
• This is a Node.js–based WhatsApp chat bot (“Miki WhatsApp Bot”).
• It uses an event‐driven architecture to listen to incoming messages, route them to command handlers, optionally persist or read data, then send replies back through the WhatsApp API.
File Structure Analysis
• Top-level files
• index.js – entry point that bootstraps the bot
• bot_settings.json – configuration (API keys, prefixes, etc.)
• message.txt – templated messages or help text
• core/ directory – the heart of the system
• _client.js / _client-test.js – wrapper around WhatsApp connection (login, event subscription)
• _command.js – central dispatcher that parses an incoming message into a command name + arguments
• _database.js – JSON file I/O layer, reads/writes core/database/*.json
• _utils.js – helper functions (formatting, randomization, etc.)
• main.js – brings together client, command dispatcher, database
• commands/ directory – each JS file implements a single bot command, following a consistent interface (execute, name, description)
• classes/WarningPoint.js – domain class used by commands (represents a user warning entry)
• core/database/ – persistent data store in JSON (data.json for live, data-test.json for tests)
• test.js – lightweight smoke test harness
Key Insights from README
• Minimal README points to a repository migration, but project purpose/self-description is that of a modular WhatsApp bot with pluggable commands and simple JSON persistence.
a. Main Components
1. WhatsApp Client Adapter
2. Command Dispatcher
3. Command Modules
4. Database Layer
5. Utility & Domain Classes
6. Configuration (bot_settings.json)
b. Relationships & Data Flow
• Incoming WhatsApp message → Client Adapter
• Client Adapter emits “message” event → Command Dispatcher
• Dispatcher parses message, looks up correct Command Module → execute()
• Command Module may read/write via Database Layer → JSON files
• Command Module may use Utility functions or Domain Classes
• Command Module returns response → Dispatcher → Client Adapter → WhatsApp
c. Architectural Patterns
• Event-driven (publish/subscribe on incoming messages)
• Command pattern (each command is a self-contained handler)
• Layered (Adapter → Dispatcher → Modules → Persistence)
d. Relevant Technologies
• Node.js runtime
• whatsapp-web.js (or similar) in core/_client
• JSON file storage for persistence
• Custom ES6 classes for domain logic