feat: complete Sprint 2 with Telegram notifications integration

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
This commit is contained in:
Luca Sacchi Ricciardi
2026-04-02 19:47:57 +02:00
parent 5aab19626f
commit 3d24dfdeaf
4 changed files with 68 additions and 4 deletions

22
.env.example Normal file
View File

@@ -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

3
.gitignore vendored
View File

@@ -23,3 +23,6 @@ Thumbs.db
# OpenCode configuration with sensitive data
.opencode/opencode.json
# Telegram bot configuration (contains sensitive tokens)
docs/telegram_setup.md

View File

@@ -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

View File

@@ -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": [
[