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:
@@ -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": [
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user