refactor: complete workflow redesign with Code nodes and proper data flow

- Replace Set nodes with Code nodes for JavaScript-based data transformation
- Code node in Extract: maps data array to individual items for iteration
- Code node in Parse: handles JSON parsing with error fallback
- Replace If node with Switch node for more reliable conditional logic
- Remove Split Results node entirely - handled in Code nodes
- Proper error handling for malformed LLM responses
- Should resolve all undefined/toLowerCase errors
This commit is contained in:
Claude Code
2026-03-17 11:42:10 +01:00
parent be2068b7e4
commit 41394554f0

View File

@@ -29,56 +29,15 @@
"jsonBody": "{\"query\":\"SELECT c.id, c.number, c.subject, c.customer_email, c.status, GROUP_CONCAT(t.body SEPARATOR ',') as threads_text FROM conversations c LEFT JOIN threads t ON c.id = t.conversation_id LEFT JOIN conversation_custom_field ccf ON c.id = ccf.conversation_id AND ccf.custom_field_id = 8 WHERE c.status = 1 AND ccf.id IS NULL GROUP BY c.id LIMIT 20\"}"
}
},
{
"id": "uuid-split-results",
"name": "Split Results",
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 3,
"position": [650, 200],
"parameters": {
"batchSize": 1,
"options": {
"basePath": "data"
}
}
},
{
"id": "uuid-extract-data",
"name": "Extract Conversation Data",
"type": "n8n-nodes-base.set",
"typeVersion": 3,
"position": [850, 200],
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [650, 200],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"name": "ticket_id",
"value": "={{ $json.id }}",
"type": "number"
},
{
"name": "ticket_number",
"value": "={{ $json.number }}",
"type": "number"
},
{
"name": "subject",
"value": "={{ $json.subject }}",
"type": "string"
},
{
"name": "problem_text",
"value": "={{ ($json.threads_text || 'No description provided').substring(0, 2000) }}",
"type": "string"
},
{
"name": "customer_email",
"value": "={{ $json.customer_email }}",
"type": "string"
}
]
}
"language": "javascript",
"jsCode": "const data = $input.all()[0].json.data;\nreturn data.map(item => ({\njson: {\nticket_id: item.id,\nticket_number: item.number,\nsubject: item.subject,\nproblem_text: (item.threads_text || 'No description provided').substring(0, 2000),\ncustomer_email: item.customer_email\n}\n}));"
}
},
{
@@ -101,57 +60,28 @@
{
"id": "uuid-parse-response",
"name": "Parse AI Response",
"type": "n8n-nodes-base.set",
"typeVersion": 3,
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [1050, 200],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"name": "response_text",
"value": "={{ $json.choices?.[0]?.message?.content || '{}' }}",
"type": "string"
},
{
"name": "ai_response",
"value": "={{ typeof $json.response_text === 'string' ? JSON.parse($json.response_text) : $json.response_text }}",
"type": "object"
},
{
"name": "vertrauen",
"value": "={{ $json.ai_response?.vertrauen || 0.5 }}",
"type": "number"
}
]
}
"language": "javascript",
"jsCode": "const content = $json.choices?.[0]?.message?.content || '{}';\nlet aiResponse = {};\ntry {\naiResponse = JSON.parse(content);\n} catch(e) {\naiResponse = {kategorie: 'unknown', lösung_typ: 'ESKALATION', vertrauen: 0.3, antwort_text: 'Fehler bei der Analyse'};\n}\nreturn {json: {...$json, response_text: content, ai_response: aiResponse, vertrauen: aiResponse.vertrauen || 0.3}};"
}
},
{
"id": "uuid-check-confidence",
"name": "Check Confidence >= 0.6",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"type": "n8n-nodes-base.switch",
"typeVersion": 1,
"position": [1250, 200],
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"extractValue": false
},
"combinator": "and",
"conditions": [
{
"id": "condition_1",
"leftValue": "={{ $json.vertrauen }}",
"rightValue": 0.6,
"operator": {
"name": "filter.operator.gte",
"value": ">="
}
}
]
}
"options": [
{
"condition": "numberGreaterThanOrEqual",
"value1": "={{ $json.vertrauen }}",
"value2": 0.6
}
]
}
},
{
@@ -208,16 +138,6 @@
]
},
"Get Unprocessed Conversations": {
"main": [
[
{
"node": "Split Results",
"index": 0
}
]
]
},
"Split Results": {
"main": [
[
{