# πŸ€– WhatsApp & Telegram AI Assistant Backend Architecture ## 🎯 Motivation & Objectives Create a lightweight, self-hosted chatbot backend running on the `roadtotech.me` homelab cluster that serves as a personal AI assistant over messaging channels (Telegram / WhatsApp). ### Primary Capabilities: 1. **Routine Reminders & Scheduled Alerts**: Cron-based triggers for study blocks, habits, and daily check-ins. 2. **AI Engineering Coach & Job Advice**: Context-aware guidance drawing from the resident's curriculum notes (`~/Brain/knowledge`, `~/Brain/journal`, `~/Brain/practice`). 3. **Quick Thought & Note Ingestion**: Send a text or voice memo to the bot to automatically append notes into `~/Brain/journal/` or `~/Brain/knowledge/parking-lot.md`. --- ## πŸ›οΈ System Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ COMMUNICATION CLIENTS β”‚ β”‚ [ Telegram Mobile App ] / [ WhatsApp Web/App ]β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (Webhook over HTTPS) β”‚ β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ TRAEFIK EDGE REVERSE PROXY (:443) β”‚ β”‚ https://bot.roadtotech.me (Wildcard TLS) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (proxy-net) β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ HOMELAB ASSISTANT BACKEND (FastAPI / Python) β”‚ β”‚ ~/Sites/homelab-assistant β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ APScheduler (Cron/Jobs)β”‚ β”‚ Auth & User Whitelist β”‚ β”‚ β”‚ β”‚ - Daily Coaching (8am) β”‚ β”‚ - Reject unknown IDs β”‚ β”‚ β”‚ β”‚ - Evening Journal Prompβ”‚ β”‚ - Single-user security β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Brain Vault Integration & LLM RAG β”‚ β”‚ β”‚ β”‚ - Read access to ~/Brain β”‚ β”‚ β”‚ β”‚ - LLM Engine: Ollama / Anthropic Claude / OpenAI β”‚ β”‚ β”‚ β”‚ - Tool Use: Read notes, add to journal β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## βš–οΈ Telegram Bot API vs. WhatsApp Cloud API | Metric | Telegram Bot API 🌟 *(Recommended)* | WhatsApp (Cloud API / Baileys) | | :--- | :--- | :--- | | **Setup Friction** | ⚑ **30 Seconds**: Chat with `@BotFather`, get API token | ⚠️ High: Requires Meta Developer Account, Business Verification | | **Cost & Quotas** | πŸ†“ **100% Free**, unlimited messages | ⚠️ Paid conversation tiers after free monthly threshold | | **Formatting** | Full Markdown, inline buttons, audio, custom keyboards | Limited markdown, strict template rules for outbound messages | | **Outbound Cron Messages** | Send messages anytime without pre-approved templates | Requires pre-approved WhatsApp message templates | | **Security** | Simple user ID whitelist (only responds to your Telegram ID)| Phone number whitelist | --- ## πŸš€ Step-by-Step Implementation Roadmap ### Phase 1: Microservice Scaffolding (`~/Sites/homelab-assistant`) * FastAPI application with `python-telegram-bot` (or `aiogram`). * Secure webhook endpoint: `POST https://bot.roadtotech.me/webhook/telegram`. * User ID whitelist middleware: Ignore and drop any message not originating from your authorized Telegram User ID. ### Phase 2: APScheduler Proactive Notifications * Schedule recurring cron jobs: - **08:00 AM**: Daily focus milestone + morning coaching question. - **09:00 PM**: Evening reflection reminder. ### Phase 3: Brain Vault Tools & RAG * Connect the assistant with read/write access to `/home/kiskaadee/Brain`: - `/note `: Appends entry to `~/Brain/journal/daily/YYYY-MM-DD.md`. - `/ask `: RAG search across `~/Brain/knowledge` to answer questions about past study notes.