Replace subject-based folder hierarchy with a document-type-based layout. Filesystem now establishes broad ownership and locality: - knowledge/ → concepts/ | technologies/ | methods/ - homelab/ → projects/homelab/plans/ | projects/homelab/guides/ - journal/ → records/journal/ - projects/ flat files → per-project sub-folders with overview.md - knowledge/parking-lot.md → inbox/ Deleted files: - Root-level Backend Residency operational files (AGENTS.md, CURRENT.md, ROADMAP.md, SKILLS.md, todo.md, todo.txt) — belong in backend-residency repo - docs/ directory entirely (ADRs belong in bitetrack-api, remaining files unused) - learning/ directory (backend-residency.md deleted; cicd guide moved to knowledge/methods/) - projects/README.md (replaced by individual project overview files)
78 lines
5.4 KiB
Markdown
78 lines
5.4 KiB
Markdown
# 🤖 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 <text>`: Appends entry to `~/Brain/journal/daily/YYYY-MM-DD.md`.
|
|
- `/ask <question>`: RAG search across `~/Brain/knowledge` to answer questions about past study notes.
|