From 9b7d49ee910328bb3c9d3c0eb8b8ccc2da4f3e56 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Fri, 4 Sep 2026 11:54:52 -0500 Subject: [PATCH] docs(homelab): add WhatsApp and Telegram AI assistant backend architecture plan --- homelab/README.md | 3 + .../chatbot-assistant-backend-architecture.md | 77 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 homelab/chatbot-assistant-backend-architecture.md diff --git a/homelab/README.md b/homelab/README.md index c08c39e..f91b1ab 100644 --- a/homelab/README.md +++ b/homelab/README.md @@ -38,6 +38,9 @@ This section documents the architectural roadmaps, infrastructure designs, deplo - Systemd timer reconciliation, instant `doc2site` reflection, and GitHub offsite backup. 11. [**LVM Storage Optimization & Partition Resizing Strategy**](lvm-storage-optimization-and-resizing.md) - Storage topology analysis, desktop indexer cache reclamation, and zero-data-loss LVM resize runbook. +12. [**WhatsApp & Telegram AI Assistant Backend Architecture**](chatbot-assistant-backend-architecture.md) + - Architecture, channel trade-offs (Telegram vs WhatsApp), APScheduler cron triggers, and Brain vault RAG integration. + diff --git a/homelab/chatbot-assistant-backend-architecture.md b/homelab/chatbot-assistant-backend-architecture.md new file mode 100644 index 0000000..7224861 --- /dev/null +++ b/homelab/chatbot-assistant-backend-architecture.md @@ -0,0 +1,77 @@ +# πŸ€– 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.