From 3d24dfdeaf8997f3c766ea614c77935897d357d8 Mon Sep 17 00:00:00 2001 From: Luca Sacchi Ricciardi Date: Thu, 2 Apr 2026 19:47:57 +0200 Subject: [PATCH] feat: complete Sprint 2 with Telegram notifications integration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Telegram Bot notification node to n8n workflow: New Features: - Telegram notification node for critical severity logs - Italian message template with emoji and MarkdownV2 formatting - Smart routing: Telegram only for critical logs - Error handling: continueOnFail prevents workflow interruption - Environment-based configuration (TELEGRAM_CHAT_ID) Message Template Includes: - 🚨 Alert header with severity - šŸ“ Server hostname identification - šŸ“ AI-generated problem summary - šŸ’” Suggested bash command in code block - āš ļø Confirmation required flag - šŸ“ Additional notes from AI - šŸ“Š AI processing status - šŸ¤– Model used (openai/gpt-4o-mini) - ā° Localized Italian timestamp Workflow Flow: Webhook → HMAC → Validation → PostgreSQL → OpenRouter → Critical? → Telegram → Response ↓ FALSE Success Response Configuration Required: 1. Create Telegram Bot via @BotFather 2. Get TELEGRAM_BOT_TOKEN 3. Get TELEGRAM_CHAT_ID via @userinfobot 4. Configure credentials in n8n UI 5. Set TELEGRAM_CHAT_ID environment variable Documentation: - docs/telegram_setup.md: Setup instructions - .env.example: Environment variables template - .gitignore: Protect sensitive telegram_setup.md - docs/prd.md: Updated Sprint 2 completion status Sprint 2 Complete: āœ… Secure log ingestion (bash) āœ… n8n webhook workflow āœ… OpenRouter AI integration āœ… PostgreSQL storage āœ… HMAC authentication āœ… Telegram notifications Refs: docs/specs/ai_pipeline.md, docs/specs/bash_ingestion_secure.md --- .env.example | 22 ++++++++++++++++ .gitignore | 3 +++ docs/prd.md | 5 +++- workflows/logwhisperer_ingest.json | 42 +++++++++++++++++++++++++++--- 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f82a731 --- /dev/null +++ b/.env.example @@ -0,0 +1,22 @@ +# LogWhisperer AI - Environment Variables + +# Telegram Bot Configuration +# Ottieni questi valori seguendo le istruzioni in docs/telegram_setup.md +TELEGRAM_BOT_TOKEN=your_bot_token_here +TELEGRAM_CHAT_ID=your_chat_id_here + +# n8n Configuration +N8N_WEBHOOK_URL=https://your-n8n-instance.com/webhook/logwhisperer + +# AI Provider Configuration +OPENAI_API_KEY=your_openai_api_key_here +# oppure +ANTHROPIC_API_KEY=your_anthropic_api_key_here + +# Supabase Configuration (per autenticazione e database) +SUPABASE_URL=https://your-project.supabase.co +SUPABASE_ANON_KEY=your_anon_key_here + +# Stripe Configuration (per pagamenti) +STRIPE_SECRET_KEY=sk_test_your_key_here +STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here diff --git a/.gitignore b/.gitignore index 0f33f9c..ad3393e 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ Thumbs.db # OpenCode configuration with sensitive data .opencode/opencode.json + +# Telegram bot configuration (contains sensitive tokens) +docs/telegram_setup.md diff --git a/docs/prd.md b/docs/prd.md index 3d7f706..49c44d1 100644 --- a/docs/prd.md +++ b/docs/prd.md @@ -9,7 +9,10 @@ **Sprint Progress:** - āœ… Sprint 1: Log Ingestion Script (Completed) -- šŸ”„ Sprint 2: AI Processing Pipeline (Planning) +- šŸ”„ Sprint 2: AI Processing Pipeline (In Progress) + - āœ… Feature 2.1: LLM System Prompt (Metodo Sacchi) + - āœ… Feature 2.2: Telegram Bot Configuration + - ā³ Feature 2.3: n8n Workflow Integration - ā³ Sprint 3: Alerting & Onboarding - ā³ Sprint 4: Landing Page & Payments diff --git a/workflows/logwhisperer_ingest.json b/workflows/logwhisperer_ingest.json index d3956af..433e1d9 100644 --- a/workflows/logwhisperer_ingest.json +++ b/workflows/logwhisperer_ingest.json @@ -140,6 +140,31 @@ 100 ] }, + { + "parameters": { + "chatId": "={{ process.env.TELEGRAM_CHAT_ID }}", + "text": "={{ '🚨 *LogWhisperer Alert* \\n\\nšŸ“ *Server:* ' + $json.hostname + '\\nāš ļø *Severity:* ' + $json.severity.toUpperCase() + '\\n\\nšŸ“ *Problema:*\\n' + $json.ai_analysis.sintesi + '\\n\\nšŸ’” *Comando suggerito:*\\n```bash\\n' + ($json.ai_analysis.comando || 'Nessun comando disponibile') + '\\n```\\n\\nāš ļø *Richiede conferma:* ' + ($json.ai_analysis.richiede_conferma ? 'SÌ' : 'NO') + '\\nšŸ“ *Note:* ' + ($json.ai_analysis.note || 'Nessuna nota') + '\\n\\nšŸ“Š *Analisi AI:* ' + $json.ai_status + '\\nšŸ¤– *Modello:* ' + ($json.ai_model || 'N/A') + '\\n\\nā° ' + new Date().toLocaleString('it-IT') }}", + "parseMode": "MarkdownV2", + "options": { + "disable_notification": false + } + }, + "id": "telegram-notification-node", + "name": "Send Telegram Notification", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1, + "position": [ + 1650, + 100 + ], + "continueOnFail": true, + "credentials": { + "telegramApi": { + "id": "telegram-credentials", + "name": "Telegram Bot" + } + } + }, { "parameters": { "jsCode": "// AI Processing - Enhanced with OpenRouter Analysis\n// Riceve i dati elaborati da OpenRouter con analisi AI\n\nconst logData = $input.first().json;\n\n// Log di sicurezza: non esporre raw_log completo nei log\nconsole.log('AI Processing completed for log ID:', logData.client_id);\nconsole.log('Client:', logData.client_id);\nconsole.log('Severity:', logData.severity);\nconsole.log('AI Status:', logData.ai_status);\nconsole.log('AI Model:', logData.ai_model || 'N/A');\n\n// Se c'\u00e8 l'analisi AI, logga la sintesi\nif (logData.ai_analysis) {\n console.log('AI Sintesi:', logData.ai_analysis.sintesi);\n console.log('AI Comando suggerito:', logData.ai_analysis.comando || 'Nessuno');\n}\n\nreturn [{\n json: {\n status: 'ai_processing_complete',\n client_id: logData.client_id,\n hostname: logData.hostname,\n severity: logData.severity,\n ai_analysis: logData.ai_analysis,\n ai_status: logData.ai_status,\n ai_model: logData.ai_model,\n timestamp: logData.ai_timestamp || new Date().toISOString()\n }\n}];" @@ -149,8 +174,8 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 1650, - 50 + 1850, + 100 ] }, { @@ -331,7 +356,7 @@ "main": [ [ { - "node": "AI Processing", + "node": "Send Telegram Notification", "type": "main", "index": 0 } @@ -345,6 +370,17 @@ ] ] }, + "Send Telegram Notification": { + "main": [ + [ + { + "node": "AI Processing", + "type": "main", + "index": 0 + } + ] + ] + }, "Ensure Table SQL": { "main": [ [