Initial commit: Telegram Assistant workflows

This commit is contained in:
mindesbunister
2025-12-19 09:54:03 +01:00
commit b789b060ea
12 changed files with 2404 additions and 0 deletions

359
workflows/deck-current.json Normal file
View File

@@ -0,0 +1,359 @@
{
"name": "Telegram Assistant - Deck Integration",
"active": false,
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "telegram-deck",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-deck-1",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1.1,
"position": [
240,
300
],
"webhookId": "telegram-deck"
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Parse deck command\nconst args = $input.item.json.args || '';\nconst chatId = $input.item.json.chatId;\n\n// Extract subcommand\nconst parts = args.trim().split(/\\s+/);\nconst subCommand = parts[0]?.toLowerCase() || 'help';\nconst taskText = parts.slice(1).join(' ');\n\nreturn {\n chatId: chatId,\n subCommand: subCommand,\n taskText: taskText,\n originalArgs: args\n};"
},
"id": "parse-deck-command-1",
"name": "Parse Deck Command",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
460,
300
]
},
{
"parameters": {
"dataType": "string",
"value1": "={{ $json.subCommand }}",
"rules": {
"rules": [
{
"value2": "add",
"output": 0
},
{
"value2": "list",
"output": 1
}
]
},
"fallbackOutput": 2
},
"id": "switch-deck-action-1",
"name": "Route Deck Action",
"type": "n8n-nodes-base.switch",
"typeVersion": 3,
"position": [
680,
300
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.taskText }}",
"operation": "isNotEmpty"
}
]
}
},
"id": "check-task-text-1",
"name": "Check Task Text",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
900,
200
]
},
{
"parameters": {
"url": "https://api.openai.com/v1/chat/completions",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "openAiApi",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "=Bearer {{ $credentials.openai_api_key }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"Extract task information from user input. Return JSON with: title (required, concise task name), description (optional, details), duedate (optional, YYYY-MM-DD format). For German dates like 'morgen', 'übermorgen', calculate from today ({{ $now.toFormat('yyyy-MM-dd') }}). Be concise.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"{{ $json.taskText }}\"\n }\n ],\n \"temperature\": 0.3,\n \"max_tokens\": 150\n}",
"options": {}
},
"id": "ai-extract-task-1",
"name": "AI Extract Task Details",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
1120,
100
],
"credentials": {
"httpHeaderAuth": {
"id": "openai_api_key",
"name": "OpenAI API Key"
},
"openAiApi": {
"id": "GPzxHwwXxeZg07o5",
"name": "OpenAi account"
}
}
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Parse AI response\nconst aiResponse = $input.item.json.choices[0].message.content;\nlet taskData;\n\ntry {\n // Try to parse as JSON\n taskData = JSON.parse(aiResponse);\n} catch (e) {\n // Fallback to original text\n taskData = {\n title: $input.item.json.taskText.substring(0, 100),\n description: $input.item.json.taskText,\n duedate: null\n };\n}\n\nreturn {\n chatId: $input.item.json.chatId,\n title: taskData.title || 'Untitled Task',\n description: taskData.description || '',\n duedate: taskData.duedate || null\n};"
},
"id": "format-task-data-1",
"name": "Format Task Data",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1340,
100
]
},
{
"parameters": {
"command": "=/home/node/create_card_from_ai.sh \"{{ $json.title }}\" \"{{ $json.description }}\" \"{{ $json.duedate || '' }}\""
},
"id": "create-deck-card-1",
"name": "Create Deck Card",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1,
"position": [
1560,
100
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Check if card creation was successful\nconst output = $input.item.json.stdout || '';\nconst error = $input.item.json.stderr || '';\n\nlet success = false;\nlet cardUrl = '';\n\nif (output.includes('Card created') || !error) {\n success = true;\n // Extract card URL if present in output\n const urlMatch = output.match(/https?:\\/\\/[^\\s]+/);\n cardUrl = urlMatch ? urlMatch[0] : '';\n}\n\nconst responseText = success \n ? `✅ Task added to Nextcloud Deck!\\n\\n📋 *${$input.item.json.title}*${$input.item.json.duedate ? '\\n📅 Due: ' + $input.item.json.duedate : ''}${cardUrl ? '\\n🔗 ' + cardUrl : ''}`\n : `❌ Failed to create task.\\n\\nError: ${error}`;\n\nreturn {\n chatId: $input.item.json.chatId,\n text: responseText,\n parseMode: 'Markdown'\n};"
},
"id": "format-success-response-1",
"name": "Format Success Response",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1780,
100
]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify($json) }}",
"options": {}
},
"id": "respond-result-1",
"name": "Respond Result",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
2000,
300
]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({\n chatId: $json.chatId,\n text: \"❌ Please specify a task to add.\\n\\nExample: /deck add Review Q4 reports by Friday\"\n}) }}",
"options": {}
},
"id": "respond-no-task-1",
"name": "Respond No Task",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
1120,
300
]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({\n chatId: $json.chatId,\n text: \"📋 *Deck Commands*\\n\\n/deck add <task> - Add a task\\n/deck list - List tasks (coming soon)\\n\\nExample:\\n/deck add Review project proposal by tomorrow\"\n}) }}",
"options": {}
},
"id": "respond-deck-help-1",
"name": "Respond Deck Help",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
900,
580
]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({\n chatId: $json.chatId,\n text: \"📋 List functionality coming soon!\\n\\nFor now, check your Nextcloud Deck directly at:\\nhttps://nextcloud.egonetix.de/apps/deck\"\n}) }}",
"options": {}
},
"id": "respond-list-placeholder-1",
"name": "Respond List (Coming Soon)",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
900,
400
]
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Parse Deck Command",
"type": "main",
"index": 0
}
]
]
},
"Parse Deck Command": {
"main": [
[
{
"node": "Route Deck Action",
"type": "main",
"index": 0
}
]
]
},
"Route Deck Action": {
"main": [
[
{
"node": "Check Task Text",
"type": "main",
"index": 0
}
]
]
},
"Check Task Text": {
"main": [
[
{
"node": "AI Extract Task Details",
"type": "main",
"index": 0
}
],
[
{
"node": "Respond No Task",
"type": "main",
"index": 0
}
]
]
},
"AI Extract Task Details": {
"main": [
[
{
"node": "Format Task Data",
"type": "main",
"index": 0
}
]
]
},
"Format Task Data": {
"main": [
[
{
"node": "Create Deck Card",
"type": "main",
"index": 0
}
]
]
},
"Create Deck Card": {
"main": [
[
{
"node": "Format Success Response",
"type": "main",
"index": 0
}
]
]
},
"Format Success Response": {
"main": [
[
{
"node": "Respond Result",
"type": "main",
"index": 0
}
]
]
},
"Respond No Task": {
"main": [
[
{
"node": "Respond Result",
"type": "main",
"index": 0
}
]
]
},
"Respond Deck Help": {
"main": [
[
{
"node": "Respond Result",
"type": "main",
"index": 0
}
]
]
},
"Respond List (Coming Soon)": {
"main": [
[
{
"node": "Respond Result",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {},
"staticData": null,
"meta": null,
"pinData": {},
"triggerCount": 0,
"tags": []
}

File diff suppressed because one or more lines are too long

112
workflows/telegram-ai.json Normal file
View File

@@ -0,0 +1,112 @@
{
"name": "Telegram Assistant - AI Chat",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "4e0e30c5-2360-49e5-a37c-e2558f811341",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-ai-1",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
240,
300
],
"webhookId": "4e0e30c5-2360-49e5-a37c-e2558f811341"
},
{
"parameters": {
"method": "POST",
"url": "https://api.openai.com/v1/chat/completions",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "openAiApi",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"{{ $json.body.args }}\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 500\n}",
"options": {}
},
"id": "call-openai-1",
"name": "Call OpenAI",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
460,
300
],
"credentials": {
"openAiApi": {
"id": "openai_api_key",
"name": "OpenAI API Key"
}
}
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "const aiResponse = $input.item.json.choices[0].message.content;\nconst chatId = $input.item.json.body.chatId;\n\nreturn {\n chatId: chatId,\n text: aiResponse,\n parseMode: 'Markdown'\n};"
},
"id": "format-response-1",
"name": "Format Response",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
680,
300
]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify($json) }}"
},
"id": "respond-1",
"name": "Respond",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
900,
300
]
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Call OpenAI",
"type": "main",
"index": 0
}
]
]
},
"Call OpenAI": {
"main": [
[
{
"node": "Format Response",
"type": "main",
"index": 0
}
]
]
},
"Format Response": {
"main": [
[
{
"node": "Respond",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {}
}

View File

@@ -0,0 +1,179 @@
{
"name": "Telegram Assistant - Deck Integration",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "telegram-deck",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-deck-1",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [240, 300],
"webhookId": "telegram-deck"
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "const args = $input.item.json.args || '';\nconst chatId = $input.item.json.chatId;\nconst parts = args.trim().split(/\\s+/);\nconst subCommand = parts[0]?.toLowerCase() || 'help';\nconst taskText = parts.slice(1).join(' ');\nreturn {chatId, subCommand, taskText, originalArgs: args};"
},
"id": "parse-deck-command-1",
"name": "Parse Deck Command",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [460, 300]
},
{
"parameters": {
"mode": "rules",
"rules": {
"rules": [
{
"operation": "equal",
"value1": "={{ $json.subCommand }}",
"value2": "add"
},
{
"operation": "equal",
"value1": "={{ $json.subCommand }}",
"value2": "list"
}
]
},
"fallbackOutput": "extra"
},
"id": "switch-deck-action-1",
"name": "Route Deck Action",
"type": "n8n-nodes-base.switch",
"typeVersion": 1,
"position": [680, 300]
},
{
"parameters": {
"conditions": {
"string": [{"value1": "={{ $json.taskText }}", "operation": "isNotEmpty"}]
}
},
"id": "check-task-text-1",
"name": "Check Task Text",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [900, 200]
},
{
"parameters": {
"url": "https://api.openai.com/v1/chat/completions",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\"model\": \"gpt-4o-mini\", \"messages\": [{\"role\": \"system\", \"content\": \"Extract task information from user input. Return JSON with: title (required, concise task name), description (optional, details), duedate (optional, YYYY-MM-DD format). For German dates like 'morgen', 'übermorgen', calculate from today ({{ $now.toFormat('yyyy-MM-dd') }}). Be concise.\"}, {\"role\": \"user\", \"content\": \"{{ $json.taskText }}\"}], \"temperature\": 0.3, \"max_tokens\": 150}",
"options": {}
},
"id": "ai-extract-task-1",
"name": "AI Extract Task Details",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [1120, 100],
"credentials": {
"httpHeaderAuth": {
"id": "openai_api_key",
"name": "OpenAI API Key"
}
}
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "const aiResponse = $input.item.json.choices[0].message.content;\nlet taskData;\ntry {taskData = JSON.parse(aiResponse);} catch (e) {taskData = {title: $input.item.json.taskText.substring(0, 100), description: $input.item.json.taskText, duedate: null};}\nreturn {chatId: $input.item.json.chatId, title: taskData.title || 'Untitled Task', description: taskData.description || '', duedate: taskData.duedate || null};"
},
"id": "format-task-data-1",
"name": "Format Task Data",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [1340, 100]
},
{
"parameters": {
"command": "=/home/node/create_card_from_ai.sh \"{{ $json.title }}\" \"{{ $json.description }}\" \"{{ $json.duedate || '' }}\""
},
"id": "create-deck-card-1",
"name": "Create Deck Card",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1,
"position": [1560, 100]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "const output = $input.item.json.stdout || '';\nconst error = $input.item.json.stderr || '';\nlet success = !error || output.includes('Card created');\nconst urlMatch = output.match(/https?:\\/\\/[^\\s]+/);\nconst cardUrl = urlMatch ? urlMatch[0] : '';\nconst responseText = success ? `✅ Task added to Nextcloud Deck!\\n\\n📋 *${$input.item.json.title}*${$input.item.json.duedate ? '\\n📅 Due: ' + $input.item.json.duedate : ''}${cardUrl ? '\\n🔗 ' + cardUrl : ''}` : `❌ Failed to create task.\\n\\nError: ${error}`;\nreturn {chatId: $input.item.json.chatId, text: responseText, parseMode: 'Markdown'};"
},
"id": "format-success-response-1",
"name": "Format Success Response",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [1780, 100]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify($json) }}"
},
"id": "respond-result-1",
"name": "Respond Result",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [2000, 300]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({chatId: $json.chatId, text: \"❌ Please specify a task to add.\\n\\nExample: /deck add Review Q4 reports by Friday\"}) }}"
},
"id": "respond-no-task-1",
"name": "Respond No Task",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [1120, 300]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({chatId: $json.chatId, text: \"📋 *Deck Commands*\\n\\n/deck add <task>\\nOr: 'add a deck called cleaning'\\n\\nExample:\\n/deck add Review project proposal by tomorrow\", parseMode: 'Markdown'}) }}"
},
"id": "respond-deck-help-1",
"name": "Respond Deck Help",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [900, 500]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({chatId: $json.chatId, text: \"📋 List functionality coming soon!\\n\\nFor now, check your Nextcloud Deck at:\\nhttps://nextcloud.egonetix.de/apps/deck\"}) }}"
},
"id": "respond-list-placeholder-1",
"name": "Respond List",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [900, 400]
}
],
"connections": {
"Webhook": {"main": [[{"node": "Parse Deck Command", "type": "main", "index": 0}]]},
"Parse Deck Command": {"main": [[{"node": "Route Deck Action", "type": "main", "index": 0}]]},
"Route Deck Action": {"main": [[{"node": "Check Task Text", "type": "main", "index": 0}], [{"node": "Respond List", "type": "main", "index": 0}], [{"node": "Respond Deck Help", "type": "main", "index": 0}]]},
"Check Task Text": {"main": [[{"node": "AI Extract Task Details", "type": "main", "index": 0}], [{"node": "Respond No Task", "type": "main", "index": 0}]]},
"AI Extract Task Details": {"main": [[{"node": "Format Task Data", "type": "main", "index": 0}]]},
"Format Task Data": {"main": [[{"node": "Create Deck Card", "type": "main", "index": 0}]]},
"Create Deck Card": {"main": [[{"node": "Format Success Response", "type": "main", "index": 0}]]},
"Format Success Response": {"main": [[{"node": "Respond Result", "type": "main", "index": 0}]]},
"Respond No Task": {"main": [[{"node": "Respond Result", "type": "main", "index": 0}]]},
"Respond Deck Help": {"main": [[{"node": "Respond Result", "type": "main", "index": 0}]]},
"Respond List": {"main": [[{"node": "Respond Result", "type": "main", "index": 0}]]}
},
"settings": {}
}

View File

@@ -0,0 +1,157 @@
{
"name": "Telegram Assistant - Email Search",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "telegram-email",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-email-1",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [240, 300],
"webhookId": "telegram-email"
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "const args = $input.item.json.args || '';\nconst chatId = $input.item.json.chatId;\nconst parts = args.trim().split(/\\s+/);\nconst subCommand = parts[0]?.toLowerCase() || 'help';\nconst searchQuery = parts.slice(1).join(' ');\nreturn {chatId, subCommand, searchQuery, originalArgs: args};"
},
"id": "parse-email-command-1",
"name": "Parse Email Command",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [460, 300]
},
{
"parameters": {
"mode": "rules",
"rules": {
"rules": [
{
"operation": "equal",
"value1": "={{ $json.subCommand }}",
"value2": "search"
},
{
"operation": "equal",
"value1": "={{ $json.subCommand }}",
"value2": "recent"
}
]
},
"fallbackOutput": "extra"
},
"id": "switch-email-action-1",
"name": "Route Email Action",
"type": "n8n-nodes-base.switch",
"typeVersion": 1,
"position": [680, 300]
},
{
"parameters": {
"conditions": {
"string": [{"value1": "={{ $json.searchQuery }}", "operation": "isNotEmpty"}]
}
},
"id": "check-search-query-1",
"name": "Check Search Query",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [900, 200]
},
{
"parameters": {
"mailbox": "INBOX",
"options": {"limit": 5, "search": "={{ $json.searchQuery }}"}
},
"id": "imap-search-1",
"name": "IMAP Search",
"type": "n8n-nodes-base.emailReadImap",
"typeVersion": 2,
"position": [1120, 100],
"credentials": {
"imap": {
"id": "BntHPR3YbFD5jAIM",
"name": "IMAP account"
}
}
},
{
"parameters": {
"mode": "runOnceForAllItems",
"jsCode": "const chatId = $input.first().json.chatId;\nconst emails = $input.all();\nif (emails.length === 0) {return {chatId, text: \"📭 No emails found matching your search.\", parseMode: 'Markdown'};}\nlet responseText = `📧 *Found ${emails.length} email${emails.length > 1 ? 's' : ''}:*\\n\\n`;\nemails.forEach((email, index) => {\n const subject = email.json.subject || '(No subject)';\n const from = email.json.from?.text || 'Unknown';\n const date = email.json.date ? new Date(email.json.date).toLocaleDateString('de-DE') : 'Unknown';\n responseText += `${index + 1}. *${subject}*\\n From: ${from}\\n Date: ${date}\\n\\n`;\n});\nif (emails.length === 5) {responseText += \"_Showing first 5 results. Refine your search for more specific results._\";}\nreturn {chatId, text: responseText, parseMode: 'Markdown'};"
},
"id": "format-email-results-1",
"name": "Format Email Results",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [1340, 100]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify($json) }}"
},
"id": "respond-result-1",
"name": "Respond Result",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [1560, 300]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({chatId: $json.chatId, text: \"❌ Please specify what to search for.\\n\\nExample: /email search invoice November\"}) }}"
},
"id": "respond-no-query-1",
"name": "Respond No Query",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [1120, 300]
},
{
"parameters": {
"mailbox": "INBOX",
"options": {"limit": 5}
},
"id": "imap-recent-1",
"name": "IMAP Recent",
"type": "n8n-nodes-base.emailReadImap",
"typeVersion": 2,
"position": [900, 400],
"credentials": {
"imap": {
"id": "BntHPR3YbFD5jAIM",
"name": "IMAP account"
}
}
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({chatId: $json.chatId, text: \"📧 *Email Commands*\\n\\n/email search <query>\\nOr: 'find my train ticket'\\n\\nExamples:\\n/email search invoice from last week\\n/email recent\", parseMode: 'Markdown'}) }}"
},
"id": "respond-email-help-1",
"name": "Respond Email Help",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [900, 500]
}
],
"connections": {
"Webhook": {"main": [[{"node": "Parse Email Command", "type": "main", "index": 0}]]},
"Parse Email Command": {"main": [[{"node": "Route Email Action", "type": "main", "index": 0}]]},
"Route Email Action": {"main": [[{"node": "Check Search Query", "type": "main", "index": 0}], [{"node": "IMAP Recent", "type": "main", "index": 0}], [{"node": "Respond Email Help", "type": "main", "index": 0}]]},
"Check Search Query": {"main": [[{"node": "IMAP Search", "type": "main", "index": 0}], [{"node": "Respond No Query", "type": "main", "index": 0}]]},
"IMAP Search": {"main": [[{"node": "Format Email Results", "type": "main", "index": 0}]]},
"Format Email Results": {"main": [[{"node": "Respond Result", "type": "main", "index": 0}]]},
"Respond No Query": {"main": [[{"node": "Respond Result", "type": "main", "index": 0}]]},
"IMAP Recent": {"main": [[{"node": "Format Email Results", "type": "main", "index": 0}]]},
"Respond Email Help": {"main": [[{"node": "Respond Result", "type": "main", "index": 0}]]}
},
"settings": {}
}

View File

@@ -0,0 +1,275 @@
{
"name": "Telegram Assistant - Receiver",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "8f3f59db-aaa5-4762-9416-94be04131fd2",
"options": {}
},
"id": "telegram-trigger-1",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
240,
300
],
"webhookId": "8f3f59db-aaa5-4762-9416-94be04131fd2"
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$json.message?.text || ''}}",
"operation": "startsWith",
"value2": "/"
}
]
}
},
"id": "check-command-1",
"name": "Check if Command",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
460,
300
]
},
{
"parameters": {
"chatId": "={{ $json.message.chat.id }}",
"text": "=Command received: {{ $json.message.text }}\n\nProcessing...",
"additionalFields": {}
},
"id": "send-ack-1",
"name": "Send Acknowledgment",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1,
"position": [
680,
200
],
"credentials": {
"telegramApi": {
"id": "6Rim8odDFpQoHxCM",
"name": "mortimer"
}
}
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Extract command and parameters\nconst text = $input.item.json.message?.text || '';\nconst chatId = $input.item.json.message?.chat?.id;\nconst messageId = $input.item.json.message?.message_id;\nconst userId = $input.item.json.message?.from?.id;\nconst username = $input.item.json.message?.from?.username || 'unknown';\n\n// Parse command\nconst parts = text.trim().split(/\\s+/);\nconst command = parts[0].toLowerCase();\nconst args = parts.slice(1).join(' ');\n\nreturn {\n command: command,\n args: args,\n chatId: chatId,\n messageId: messageId,\n userId: userId,\n username: username,\n originalText: text\n};"
},
"id": "parse-command-1",
"name": "Parse Command",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
900,
200
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Extract natural language message\nconst text = $input.item.json.message?.text || '';\nconst chatId = $input.item.json.message?.chat?.id;\nconst messageId = $input.item.json.message?.message_id;\nconst userId = $input.item.json.message?.from?.id;\nconst username = $input.item.json.message?.from?.username || 'unknown';\n\nreturn {\n chatId: chatId,\n messageId: messageId,\n userId: userId,\n username: username,\n originalText: text\n};"
},
"id": "parse-natural-language-1",
"name": "Parse Natural Language",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
680,
400
]
},
{
"parameters": {
"method": "POST",
"url": "https://api.openai.com/v1/chat/completions",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "openAiApi",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "=Bearer {{ $credentials.openai_api_key }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"Analyze user intent and classify into one of these categories. Return ONLY valid JSON with no additional text:\\n\\n1. 'deck_add' - User wants to create a task/card in Nextcloud Deck\\n Examples: 'add a deck called cleaning', 'create task review reports', 'remind me to call mom tomorrow'\\n Extract: {intent: 'deck_add', task: 'task description', duedate: 'YYYY-MM-DD or null'}\\n\\n2. 'email_search' - User wants to search emails\\n Examples: 'find my train ticket', 'search for invoice', 'show emails from last week'\\n Extract: {intent: 'email_search', query: 'search terms'}\\n\\n3. 'general_chat' - General questions, conversation\\n Examples: 'what's the weather', 'explain quantum physics', 'tell me a joke'\\n Extract: {intent: 'general_chat', question: 'full question'}\\n\\nFor dates like 'today', 'tomorrow', 'next week', calculate from today: {{ $now.toFormat('yyyy-MM-dd') }}.\\nFor German: 'morgen' = tomorrow, 'übermorgen' = day after tomorrow.\\n\\nReturn JSON format: {\\\"intent\\\": \\\"category\\\", ...extracted_data}\"\n },\n {\n \"role\": \"user\",\n \"content\": \"{{ $json.originalText }}\"\n }\n ],\n \"temperature\": 0.3,\n \"max_tokens\": 150\n}",
"options": {}
},
"id": "ai-classify-intent-1",
"name": "AI Classify Intent",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
900,
400
],
"credentials": {
"httpHeaderAuth": {
"id": "openai_api_key",
"name": "OpenAI API Key"
}
}
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Parse AI classification result\nconst aiResponse = $input.item.json.choices[0].message.content;\nconst chatId = $input.item.json.chatId;\nconst userId = $input.item.json.userId;\nconst username = $input.item.json.username;\nconst originalText = $input.item.json.originalText;\n\nlet classification;\ntry {\n classification = JSON.parse(aiResponse);\n} catch (e) {\n // Fallback to general chat if parsing fails\n classification = {\n intent: 'general_chat',\n question: originalText\n };\n}\n\n// Map intent to command format for router\nlet command, args;\n\nswitch (classification.intent) {\n case 'deck_add':\n command = '/deck';\n args = 'add ' + (classification.task || originalText);\n break;\n case 'email_search':\n command = '/email';\n args = 'search ' + (classification.query || originalText);\n break;\n case 'general_chat':\n default:\n command = '/ask';\n args = classification.question || originalText;\n break;\n}\n\nreturn {\n command: command,\n args: args,\n chatId: chatId,\n userId: userId,\n username: username,\n originalText: originalText,\n classifiedIntent: classification.intent\n};"
},
"id": "format-as-command-1",
"name": "Format as Command",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1120,
400
]
},
{
"parameters": {
"method": "POST",
"url": "=https://flow.egonetix.de/webhook/telegram-router-direct",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json) }}",
"options": {
"response": {
"response": {
"neverError": true
}
}
}
},
"id": "call-router-natural-1",
"name": "Call Router (Natural Language)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
1340,
400
]
},
{
"parameters": {
"method": "POST",
"url": "=https://flow.egonetix.de/webhook/telegram-router-direct",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json) }}",
"options": {
"response": {
"response": {
"neverError": true
}
}
}
},
"id": "call-router-1",
"name": "Call Router Workflow",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
1120,
200
]
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Check if Command",
"type": "main",
"index": 0
}
]
]
},
"Check if Command": {
"main": [
[
{
"node": "Send Acknowledgment",
"type": "main",
"index": 0
}
],
[
{
"node": "Parse Natural Language",
"type": "main",
"index": 0
}
]
]
},
"Parse Natural Language": {
"main": [
[
{
"node": "AI Classify Intent",
"type": "main",
"index": 0
}
]
]
},
"AI Classify Intent": {
"main": [
[
{
"node": "Format as Command",
"type": "main",
"index": 0
}
]
]
},
"Format as Command": {
"main": [
[
{
"node": "Call Router (Natural Language)",
"type": "main",
"index": 0
}
]
]
},
"Send Acknowledgment": {
"main": [
[
{
"node": "Parse Command",
"type": "main",
"index": 0
}
]
]
},
"Parse Command": {
"main": [
[
{
"node": "Call Router Workflow",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {}
}

View File

@@ -0,0 +1,175 @@
{
"name": "Telegram Assistant - Router",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "79209f6f-28f3-4782-8366-2517e47adc0e",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-router-1",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [240, 300],
"webhookId": "79209f6f-28f3-4782-8366-2517e47adc0e"
},
{
"parameters": {
"mode": "rules",
"rules": {
"rules": [
{
"operation": "equal",
"value1": "={{ $json.command }}",
"value2": "/start"
},
{
"operation": "equal",
"value1": "={{ $json.command }}",
"value2": "/help"
},
{
"operation": "equal",
"value1": "={{ $json.command }}",
"value2": "/deck"
},
{
"operation": "equal",
"value1": "={{ $json.command }}",
"value2": "/email"
},
{
"operation": "equal",
"value1": "={{ $json.command }}",
"value2": "/ask"
}
]
},
"fallbackOutput": "extra"
},
"id": "switch-command-1",
"name": "Route Command",
"type": "n8n-nodes-base.switch",
"typeVersion": 1,
"position": [460, 300]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({chatId: $json.chatId, text: \"👋 Welcome to your Telegram Assistant!\\n\\nI can help you with:\\n\\n📋 /deck - Manage Nextcloud Deck tasks\\n📧 /email - Search your emails\\n💬 /ask - Chat with AI\\n❓ /help - Show this message\\n\\nOr just chat naturally - I understand!\", parseMode: 'Markdown'}) }}"
},
"id": "respond-start-1",
"name": "Respond Start",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [680, 100]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({chatId: $json.chatId, text: \"🤖 *Telegram Assistant Help*\\n\\n📋 *Deck:*\\n /deck add <task>\\n Or: 'add a deck called cleaning'\\n\\n📧 *Email:*\\n /email search <query>\\n Or: 'find my train ticket'\\n\\n💬 *AI:*\\n /ask <question>\\n Or: 'what's the weather?'\", parseMode: 'Markdown'}) }}"
},
"id": "respond-help-1",
"name": "Respond Help",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [680, 200]
},
{
"parameters": {
"url": "=https://flow.egonetix.de/webhook/c1294640-f15e-411e-b38b-8b69b8419bce",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json) }}",
"options": {}
},
"id": "call-deck-1",
"name": "Call Deck Workflow",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [680, 300]
},
{
"parameters": {
"url": "=https://flow.egonetix.de/webhook/telegram-email",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json) }}",
"options": {}
},
"id": "call-email-1",
"name": "Call Email Workflow",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [680, 400]
},
{
"parameters": {
"url": "=https://flow.egonetix.de/webhook/4e0e30c5-2360-49e5-a37c-e2558f811341",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json) }}",
"options": {}
},
"id": "call-ai-1",
"name": "Call AI Workflow",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [680, 500]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({chatId: $json.chatId, text: \"❌ Unknown command: \" + $json.command + \"\\n\\nType /help to see available commands.\"}) }}"
},
"id": "respond-unknown-1",
"name": "Respond Unknown",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [680, 600]
},
{
"parameters": {
"chatId": "={{ $json.chatId }}",
"text": "={{ $json.text }}",
"additionalFields": {"parse_mode": "={{ $json.parseMode || 'HTML' }}"}
},
"id": "send-telegram-1",
"name": "Send Telegram Response",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.1,
"position": [900, 300],
"credentials": {
"telegramApi": {
"id": "6Rim8odDFpQoHxCM",
"name": "mortimer"
}
}
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({ success: true }) }}"
},
"id": "respond-ok-1",
"name": "Respond OK",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [1120, 300]
}
],
"connections": {
"Webhook": {"main": [[{"node": "Route Command", "type": "main", "index": 0}]]},
"Route Command": {"main": [[{"node": "Respond Start", "type": "main", "index": 0}], [{"node": "Respond Help", "type": "main", "index": 0}], [{"node": "Call Deck Workflow", "type": "main", "index": 0}], [{"node": "Call Email Workflow", "type": "main", "index": 0}], [{"node": "Call AI Workflow", "type": "main", "index": 0}], [{"node": "Respond Unknown", "type": "main", "index": 0}]]},
"Respond Start": {"main": [[{"node": "Send Telegram Response", "type": "main", "index": 0}]]},
"Respond Help": {"main": [[{"node": "Send Telegram Response", "type": "main", "index": 0}]]},
"Call Deck Workflow": {"main": [[{"node": "Send Telegram Response", "type": "main", "index": 0}]]},
"Call Email Workflow": {"main": [[{"node": "Send Telegram Response", "type": "main", "index": 0}]]},
"Call AI Workflow": {"main": [[{"node": "Send Telegram Response", "type": "main", "index": 0}]]},
"Respond Unknown": {"main": [[{"node": "Send Telegram Response", "type": "main", "index": 0}]]},
"Send Telegram Response": {"main": [[{"node": "Respond OK", "type": "main", "index": 0}]]}
},
"settings": {}
}