158 lines
6.0 KiB
JSON
158 lines
6.0 KiB
JSON
{
|
|
"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": {}
|
|
}
|