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:
@@ -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\"}"
|
"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",
|
"id": "uuid-extract-data",
|
||||||
"name": "Extract Conversation Data",
|
"name": "Extract Conversation Data",
|
||||||
"type": "n8n-nodes-base.set",
|
"type": "n8n-nodes-base.code",
|
||||||
"typeVersion": 3,
|
"typeVersion": 2,
|
||||||
"position": [850, 200],
|
"position": [650, 200],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"options": {},
|
"language": "javascript",
|
||||||
"assignments": {
|
"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}));"
|
||||||
"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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -101,57 +60,28 @@
|
|||||||
{
|
{
|
||||||
"id": "uuid-parse-response",
|
"id": "uuid-parse-response",
|
||||||
"name": "Parse AI Response",
|
"name": "Parse AI Response",
|
||||||
"type": "n8n-nodes-base.set",
|
"type": "n8n-nodes-base.code",
|
||||||
"typeVersion": 3,
|
"typeVersion": 2,
|
||||||
"position": [1050, 200],
|
"position": [1050, 200],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"options": {},
|
"language": "javascript",
|
||||||
"assignments": {
|
"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}};"
|
||||||
"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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "uuid-check-confidence",
|
"id": "uuid-check-confidence",
|
||||||
"name": "Check Confidence >= 0.6",
|
"name": "Check Confidence >= 0.6",
|
||||||
"type": "n8n-nodes-base.if",
|
"type": "n8n-nodes-base.switch",
|
||||||
"typeVersion": 2,
|
"typeVersion": 1,
|
||||||
"position": [1250, 200],
|
"position": [1250, 200],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"conditions": {
|
"options": [
|
||||||
"options": {
|
{
|
||||||
"caseSensitive": true,
|
"condition": "numberGreaterThanOrEqual",
|
||||||
"extractValue": false
|
"value1": "={{ $json.vertrauen }}",
|
||||||
},
|
"value2": 0.6
|
||||||
"combinator": "and",
|
}
|
||||||
"conditions": [
|
]
|
||||||
{
|
|
||||||
"id": "condition_1",
|
|
||||||
"leftValue": "={{ $json.vertrauen }}",
|
|
||||||
"rightValue": 0.6,
|
|
||||||
"operator": {
|
|
||||||
"name": "filter.operator.gte",
|
|
||||||
"value": ">="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -208,16 +138,6 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"Get Unprocessed Conversations": {
|
"Get Unprocessed Conversations": {
|
||||||
"main": [
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"node": "Split Results",
|
|
||||||
"index": 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"Split Results": {
|
|
||||||
"main": [
|
"main": [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user