diff --git a/n8n-workflows/workflow-a-mail-processing.json b/n8n-workflows/workflow-a-mail-processing.json new file mode 100644 index 0000000..6ed7f1d --- /dev/null +++ b/n8n-workflows/workflow-a-mail-processing.json @@ -0,0 +1,368 @@ +{ + "name": "Workflow A – Mail Processing & KI Analysis", + "description": "Automated workflow to process support tickets, analyze them with AI, search knowledge base, and provide intelligent suggestions.", + "nodes": [ + { + "id": "uuid-trigger-1", + "name": "Cron Trigger", + "type": "n8n-nodes-base.cron", + "typeVersion": 1, + "position": [ + 250, + 200 + ], + "parameters": { + "cronExpression": "*/5 * * * *", + "timezone": "Europe/Berlin" + } + }, + { + "id": "uuid-freescout-1", + "name": "Freescout Get Conversations", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4, + "position": [ + 450, + 200 + ], + "parameters": { + "authentication": "predefinedCredentialType", + "url": "https://ekshelpdesk.fft-it.de/api/v1/mailboxes/1/conversations", + "method": "GET", + "options": {}, + "sendQuery": true, + "queryParameters": { + "parameters": [ + { + "name": "status", + "value": "active" + }, + { + "name": "limit", + "value": "20" + }, + { + "name": "processed_by_ai", + "value": "false" + } + ] + } + }, + "credentials": { + "httpBasicAuth": "Freescout API" + } + }, + { + "id": "uuid-loop-1", + "name": "Loop Through Conversations", + "type": "n8n-nodes-base.loop", + "typeVersion": 1, + "position": [ + 650, + 200 + ], + "parameters": { + "iterations": "={{ $json.body._embedded.conversations.length }}", + "dataPropertyName": "body._embedded.conversations" + } + }, + { + "id": "uuid-set-extract-1", + "name": "Extract Conversation Data", + "type": "n8n-nodes-base.set", + "typeVersion": 3, + "position": [ + 850, + 200 + ], + "parameters": { + "options": {}, + "assignments": { + "assignments": [ + { + "name": "ticket_id", + "value": "={{ $json.id }}", + "type": "string" + }, + { + "name": "subject", + "value": "={{ $json.subject }}", + "type": "string" + }, + { + "name": "problem_text", + "value": "={{ $json.threads[0].body || 'No description' }}", + "type": "string" + }, + { + "name": "customer_name", + "value": "={{ $json.customer_name }}", + "type": "string" + }, + { + "name": "status", + "value": "={{ $json.status }}", + "type": "string" + }, + { + "name": "mailbox_id", + "value": 1, + "type": "number" + } + ] + } + } + }, + { + "id": "uuid-milvus-query-1", + "name": "Milvus Query KB", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4, + "position": [ + 1050, + 200 + ], + "parameters": { + "authentication": "none", + "url": "http://milvus:9091/api/v1/search", + "method": "POST", + "headers": { + "Content-Type": "application/json" + }, + "body": { + "RAW_JSON": true, + "parameters": "={{ JSON.stringify({\n \"collection_name\": \"knowledge_base_embeddings\",\n \"search_params\": {\n \"metric_type\": \"L2\",\n \"params\": {\n \"nprobe\": 10\n }\n },\n \"annnSearch\": {\n \"field\": \"embedding\",\n \"limit\": 3,\n \"metric_type\": \"L2\"\n },\n \"output_fields\": [\"title\", \"content\", \"category\", \"solution_type\", \"created_at\"]\n}) }}" + } + } + } + }, + { + "id": "uuid-llm-call-1", + "name": "LiteLLM AI Analysis", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4, + "position": [ + 1250, + 200 + ], + "parameters": { + "authentication": "none", + "url": "http://llm:8000/v1/chat/completions", + "method": "POST", + "headers": { + "Content-Type": "application/json" + }, + "body": { + "RAW_JSON": true, + "parameters": "={{ JSON.stringify({\n \"model\": \"gpt-3.5-turbo\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"Du bist ein IT-Support-Assistent. Analysiere das folgende Support-Ticket und:\\n1. Verstehe das Problem\\n2. Schaue in der Wissensdatenbank nach ähnlichen Problemen\\n3. Gib einen strukturierten Vorschlag zurück als JSON\\n\\nDie Lösung kann sein:\\n- BARAMUNDI_JOB: Ein automatisierter Job im Baramundi System\\n- AUTOMATISCHE_ANTWORT: Eine automatische Antwort an den Kunden\\n- ESKALATION: Manuelle Eskalation erforderlich\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Ticket ID: {{$json.ticket_id}}\\nSubjekt: {{$json.subject}}\\nProblem: {{$json.problem_text}}\\n\\nÄhnliche KB-Einträge (Top 3):\\n\" + ($json.kb_results || []).slice(0, 3).map((r, i) => `${i+1}. ${r.title}\\n${r.content}`).join('\\n\\n') + \"\\n\\nGib deine Analyse als JSON zurück mit folgendem Format:\\n{\\\"kategorie\\\": \\\"Hardware|Software|Account|Netzwerk|Sonstiges\\\", \\\"problem_verstanden\\\": \\\"Kurze Zusammenfassung\\\", \\\"lösung_typ\\\": \\\"BARAMUNDI_JOB|AUTOMATISCHE_ANTWORT|ESKALATION\\\", \\\"baramundi_job\\\": {\\\"name\\\": \\\"Job-Name\\\", \\\"parameter\\\": {}}, \\\"antwort_text\\\": \\\"Kundenfreundliche Antwort\\\", \\\"vertrauen\\\": 0.75, \\\"begründung\\\": \\\"Warum diese Lösung?\\\"}\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 1000\n}) }}" + } + } + } + }, + { + "id": "uuid-parse-response-1", + "name": "Parse AI Response", + "type": "n8n-nodes-base.set", + "typeVersion": 3, + "position": [ + 1450, + 200 + ], + "parameters": { + "options": {}, + "assignments": { + "assignments": [ + { + "name": "ai_response_raw", + "value": "={{ $json.choices[0].message.content }}", + "type": "string" + }, + { + "name": "ai_response", + "value": "={{ JSON.parse($json.ai_response_raw.match(/\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}/)[0]) }}", + "type": "object" + } + ] + } + } + }, + { + "id": "uuid-filter-confidence-1", + "name": "Filter by Confidence", + "type": "n8n-nodes-base.if", + "typeVersion": 2, + "position": [ + 1650, + 200 + ], + "parameters": { + "conditions": { + "options": { + "caseSensitive": true, + "extractValue": false + }, + "combinator": "and", + "conditions": [ + { + "id": "condition_1", + "leftValue": "={{ $json.ai_response.vertrauen }}", + "rightValue": 0.6, + "operator": { + "name": "filter.operator.gte", + "value": ">=" + } + } + ] + } + } + }, + { + "id": "uuid-freescout-update-1", + "name": "Freescout Save Suggestion", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4, + "position": [ + 1850, + 100 + ], + "parameters": { + "authentication": "predefinedCredentialType", + "url": "https://ekshelpdesk.fft-it.de/api/v1/conversations/{{ $json.ticket_id }}", + "method": "PUT", + "headers": { + "Content-Type": "application/json" + }, + "body": { + "RAW_JSON": true, + "parameters": "={{ JSON.stringify({\n \"custom_fields\": {\n \"AI_SUGGESTION\": $json.ai_response.antwort_text,\n \"AI_SUGGESTION_STATUS\": \"PENDING\",\n \"PROCESSED_BY_AI\": true,\n \"AI_CATEGORY\": $json.ai_response.kategorie,\n \"AI_CONFIDENCE\": $json.ai_response.vertrauen,\n \"AI_SOLUTION_TYPE\": $json.ai_response.lösung_typ,\n \"AI_REASONING\": $json.ai_response.begründung\n }\n}) }}" + } + } + }, + "credentials": { + "httpBasicAuth": "Freescout API" + } + }, + { + "id": "uuid-no-action-1", + "name": "Low Confidence - No Action", + "type": "n8n-nodes-base.set", + "typeVersion": 3, + "position": [ + 1850, + 350 + ], + "parameters": { + "options": {}, + "assignments": { + "assignments": [ + { + "name": "skip_reason", + "value": "Confidence below threshold ({{ $json.ai_response.vertrauen }} < 0.6)", + "type": "string" + }, + { + "name": "processed", + "value": false, + "type": "boolean" + } + ] + } + } + } + ], + "connections": { + "Cron Trigger": { + "main": [ + [ + { + "node": "Freescout Get Conversations", + "index": 0 + } + ] + ] + }, + "Freescout Get Conversations": { + "main": [ + [ + { + "node": "Loop Through Conversations", + "index": 0 + } + ] + ] + }, + "Loop Through Conversations": { + "main": [ + [ + { + "node": "Extract Conversation Data", + "index": 0 + } + ] + ] + }, + "Extract Conversation Data": { + "main": [ + [ + { + "node": "Milvus Query KB", + "index": 0 + } + ] + ] + }, + "Milvus Query KB": { + "main": [ + [ + { + "node": "LiteLLM AI Analysis", + "index": 0 + } + ] + ] + }, + "LiteLLM AI Analysis": { + "main": [ + [ + { + "node": "Parse AI Response", + "index": 0 + } + ] + ] + }, + "Parse AI Response": { + "main": [ + [ + { + "node": "Filter by Confidence", + "index": 0 + } + ] + ] + }, + "Filter by Confidence": { + "main": [ + [ + { + "node": "Freescout Save Suggestion", + "index": 0 + } + ], + [ + { + "node": "Low Confidence - No Action", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "errorHandler": "continueOnError", + "timezone": "Europe/Berlin" + }, + "owner": "admin", + "versionId": "1" +}