# Telegram Project Doc Bot Telegram Bot zum Sammeln von Projektdokumentation (Fotos, Sprachnotizen, Text) und automatischer Blogbeitrag-Generierung. ## Tech Stack - **Framework**: NestJS 10 - **Telegram**: nestjs-telegraf + Telegraf - **Database**: PostgreSQL + Drizzle ORM - **Storage**: S3 (MinIO lokal, Hetzner in Produktion) - **AI - Transcription**: OpenAI Whisper - **AI - Generation**: Ollama (lokal) oder OpenAI GPT ## Commands ```bash # Development pnpm start:dev # Start with hot reload # Build pnpm build # Production build # Type check pnpm type-check # Check TypeScript types # Database pnpm db:generate # Generate migrations pnpm db:push # Push schema to database pnpm db:studio # Open Drizzle Studio ``` ## Telegram Commands | Command | Beschreibung | |---------|--------------| | `/start` | Hilfe anzeigen | | `/help` | Hilfe anzeigen | | `/new [Name]` | Neues Projekt erstellen | | `/projects` | Alle Projekte auflisten | | `/switch [ID]` | Projekt wechseln | | `/status` | Status des aktiven Projekts | | `/archive` | Projekt archivieren | | `/generate` | Blogbeitrag generieren | | `/generate [Stil]` | Mit bestimmtem Stil generieren | | `/styles` | VerfΓΌgbare Stile anzeigen | | `/export` | Letzte Generierung als Datei | ## Blog-Stile | Stil | Beschreibung | |------|--------------| | `casual` | Locker & persΓΆnlich | | `formal` | Professionell & sachlich | | `tutorial` | Anleitung mit Schritten | | `diary` | Tagebuch-Stil | ## User Flow ``` 1. /new Gartenhaus-Renovierung β†’ Projekt erstellen 2. πŸ“· Foto senden β†’ Wird gespeichert 3. 🎀 Sprachnotiz senden β†’ Transkribiert + gespeichert 4. "Heute das Fundament gegossen" β†’ Text-Notiz 5. /status β†’ Übersicht 6. /generate tutorial β†’ Blogbeitrag erstellen 7. /export β†’ Als .md Datei ``` ## Environment Variables ```env # Server PORT=3302 # Telegram TELEGRAM_BOT_TOKEN=xxx # Bot Token von @BotFather TELEGRAM_ALLOWED_USERS=123,456 # Optional: Nur diese User IDs erlauben # Database DATABASE_URL=postgresql://postgres:postgres@localhost:5432/projectdoc # Storage (MinIO) S3_ENDPOINT=http://localhost:9000 S3_REGION=us-east-1 S3_ACCESS_KEY=minioadmin S3_SECRET_KEY=minioadmin S3_BUCKET=projectdoc-storage # AI - Transcription (optional, aber empfohlen) OPENAI_API_KEY=sk-xxx # AI - Generation LLM_PROVIDER=ollama # ollama oder openai OLLAMA_URL=http://localhost:11434 OLLAMA_MODEL=gemma3:4b ``` ## Projekt-Struktur ``` services/telegram-project-doc-bot/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ main.ts # Entry point β”‚ β”œβ”€β”€ app.module.ts # Root module β”‚ β”œβ”€β”€ health.controller.ts # Health endpoint β”‚ β”œβ”€β”€ config/ β”‚ β”‚ └── configuration.ts # Config + Blog-Stile β”‚ β”œβ”€β”€ database/ β”‚ β”‚ β”œβ”€β”€ database.module.ts # Drizzle connection β”‚ β”‚ └── schema.ts # DB schema β”‚ β”œβ”€β”€ bot/ β”‚ β”‚ β”œβ”€β”€ bot.module.ts β”‚ β”‚ └── bot.update.ts # Command handlers β”‚ β”œβ”€β”€ project/ β”‚ β”‚ β”œβ”€β”€ project.module.ts β”‚ β”‚ └── project.service.ts # Projekt CRUD β”‚ β”œβ”€β”€ media/ β”‚ β”‚ β”œβ”€β”€ media.module.ts β”‚ β”‚ β”œβ”€β”€ media.service.ts # Foto/Voice/Text verarbeiten β”‚ β”‚ └── storage.service.ts # S3 Upload/Download β”‚ β”œβ”€β”€ transcription/ β”‚ β”‚ β”œβ”€β”€ transcription.module.ts β”‚ β”‚ └── transcription.service.ts # Whisper API β”‚ └── generation/ β”‚ β”œβ”€β”€ generation.module.ts β”‚ └── generation.service.ts # Blogpost AI β”œβ”€β”€ drizzle/ # Migrations β”œβ”€β”€ drizzle.config.ts β”œβ”€β”€ package.json └── Dockerfile ``` ## Lokale Entwicklung ### 1. Bot bei Telegram erstellen 1. Γ–ffne @BotFather in Telegram 2. Sende `/newbot` 3. WΓ€hle einen Namen (z.B. "Project Doc Bot") 4. WΓ€hle einen Username (z.B. "my_projectdoc_bot") 5. Kopiere den Token ### 2. Umgebung vorbereiten ```bash # Docker Services starten (PostgreSQL, MinIO, Ollama) pnpm docker:up # Datenbank erstellen psql -h localhost -U postgres -c "CREATE DATABASE projectdoc;" # Schema pushen cd services/telegram-project-doc-bot cp .env.example .env # Token und Keys eintragen pnpm db:push ``` ### 3. Bot starten ```bash pnpm start:dev ``` ## Features - **Multi-Projekt**: Mehrere Projekte pro User - **Foto-Speicherung**: Fotos in S3 mit Metadaten - **Voice-Transkription**: Automatisch via Whisper - **Text-Notizen**: Einfache Nachrichten werden gespeichert - **Chronologisch**: Alle EintrΓ€ge behalten ihre Reihenfolge - **Mehrere Stile**: casual, formal, tutorial, diary - **Export**: Markdown-Datei zum Download ## Datenbank-Schema ``` projects β”œβ”€β”€ id (UUID) β”œβ”€β”€ telegram_user_id (INT) β”œβ”€β”€ name (TEXT) β”œβ”€β”€ description (TEXT) β”œβ”€β”€ status (TEXT: active, archived, completed) β”œβ”€β”€ created_at, updated_at media_items β”œβ”€β”€ id (UUID) β”œβ”€β”€ project_id (UUID FK) β”œβ”€β”€ type (TEXT: photo, voice, text) β”œβ”€β”€ storage_key (TEXT) β”œβ”€β”€ caption (TEXT) β”œβ”€β”€ transcription (TEXT) β”œβ”€β”€ ai_description (TEXT) β”œβ”€β”€ metadata (JSONB) β”œβ”€β”€ telegram_file_id (TEXT) β”œβ”€β”€ order_index (INT) β”œβ”€β”€ created_at generations β”œβ”€β”€ id (UUID) β”œβ”€β”€ project_id (UUID FK) β”œβ”€β”€ style (TEXT) β”œβ”€β”€ content (TEXT - Markdown) β”œβ”€β”€ pdf_key (TEXT) β”œβ”€β”€ is_latest (BOOL) β”œβ”€β”€ created_at ``` ## Health Check ```bash curl http://localhost:3302/health ``` ## Deployment ### Docker (empfohlen) ```yaml # docker-compose.yml telegram-project-doc-bot: build: ./services/telegram-project-doc-bot restart: always environment: PORT: 3302 TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN} DATABASE_URL: ${DATABASE_URL} S3_ENDPOINT: ${S3_ENDPOINT} S3_ACCESS_KEY: ${S3_ACCESS_KEY} S3_SECRET_KEY: ${S3_SECRET_KEY} S3_BUCKET: projectdoc-storage LLM_PROVIDER: ollama OLLAMA_URL: http://ollama:11434 ports: - "3302:3302" ``` ## Roadmap - [ ] Foto-Vision-Analyse (was ist auf dem Bild?) - [ ] PDF-Export - [ ] Bilder im Blogpost einbetten - [ ] Projekt-Templates - [ ] Web-Dashboard zur Ansicht - [ ] Telegram Mini App fΓΌr bessere UX