How riozee/miki-whatsappbot works
Project Type and Purpose
• This is a Node.js + TypeScript WhatsApp chat-bot (“Miki”) built around a plugin-based command framework. It connects to WhatsApp, listens for messages, and dispatches them to modular command handlers (plugins).
File Structure Overview
• Top-level config & metadata:
• miki-config.json – runtime configuration for the bot
• languages/en.json, id.json – i18n message templates
• package.json, tsconfig.json – build and dependency definitions
• src/ – main application code:
• main.ts – entrypoint; initializes the WhatsApp client and event loop
• handlers/ – core event processing:
– database.ts – persistence layer (e.g., read/write user state)
– handler.ts – central dispatcher that routes incoming messages to plugins
• plugins/ – each .ts file implements a single chat command or feature
• utils/ – shared functions and constants (logging, message builders, helper methods)
• .vscode, linting/prettier configs, and license are auxiliary.
Key Architectural Patterns
• Event-Driven / Plugin Architecture: Incoming WhatsApp events → handler → appropriate plugin → optional database calls or utils → reply.
• Modular Separation:
• Core Engine (main.ts + handler.ts)
• Plugins (individual features)
• Services (database handler)
• Shared Utilities (logging, constants, i18n)
Main Components
a. WhatsApp Client (external service)
b. Bot Core (main.ts + handler.ts)
c. Plugin Modules (each command in src/plugins/)
d. Database/Persistence Layer (e.g., local JSON or external DB via handlers/database.ts)
e. Configuration & Language Store (miki-config.json + languages/*.json)
f. Utilities Library (src/utils/)
Relationships and Data Flow
• Delivers “message” events via Baileys or similar WA API
• Extracts command identifier, user metadata
• Routes to the specific plugin based on command name
• read/write user stats, AFK flags, warning counts, etc.
• Sends replies, media, or stickers back to the user
• Config & Language are read by Bot Core & Plugins at startup or runtime