{ "name": "DefectRAG Corrective Actions — INACTIVE REVIEW TEMPLATE", "active": false, "settings": { "executionOrder": "v1", "saveDataSuccessExecution": "none", "saveDataErrorExecution": "none", "saveManualExecutions": false }, "nodes": [ { "id": "webhook", "name": "Authenticated case event", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "defectrag-corrective-actions", "authentication": "headerAuth", "responseMode": "responseNode", "options": {} }, "credentials": { "httpHeaderAuth": { "id": "CONFIGURE_IN_N8N", "name": "DefectRAG CA inbound key" } } }, { "id": "validate", "name": "Validate case event", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 220, 0 ], "parameters": { "jsCode": "const b=$input.first().json.body;const u=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;if(!b||!u.test(b.event_id)||!u.test(b.lease_token)||!u.test(b.case_id)||!['created','updated','reminder','overdue'].includes(b.kind)||!Number.isInteger(b.version)||b.version<1)throw Error('Invalid case event');return [{json:{event_id:b.event_id,lease_token:b.lease_token}}];" } }, { "id": "begin", "name": "Reserve notification effect", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 440, 0 ], "parameters": { "method": "POST", "url": "https://PROJECT_REF.supabase.co/functions/v1/corrective-actions", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "X-DefectRAG-Operation", "value": "effect" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ {operation:'begin',event_id:$json.event_id,lease_token:$json.lease_token} }}", "options": { "timeout": 10000 } }, "credentials": { "httpHeaderAuth": { "id": "CONFIGURE_IN_N8N", "name": "DefectRAG CA callback bearer" } } }, { "id": "decision", "name": "Effect requires execution", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 660, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "typeValidation": "strict" }, "conditions": [ { "leftValue": "={{ $json.execute }}", "rightValue": true, "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "options": {} } }, { "id": "email", "name": "Notify verified supervisor", "type": "n8n-nodes-base.emailSend", "typeVersion": 2.1, "position": [ 880, -100 ], "parameters": { "fromEmail": "CONFIGURE_VERIFIED_SENDER@example.invalid", "toEmail": "={{ $json.recipient_email }}", "subject": "={{ ({created:'DefectRAG: New corrective action for you · due '+DateTime.fromISO($json.due_at).setZone('Asia/Kuala_Lumpur').toFormat('ccc d LLL, h:mm a'),updated:'DefectRAG: Case update · now '+$json.state,reminder:'DefectRAG: Friendly reminder · due '+DateTime.fromISO($json.due_at).setZone('Asia/Kuala_Lumpur').toFormat('ccc d LLL, h:mm a'),overdue:'DefectRAG: Quick check-in · was due '+DateTime.fromISO($json.due_at).setZone('Asia/Kuala_Lumpur').toFormat('ccc d LLL, h:mm a'),done:'DefectRAG: Nice work · case '+$json.state.toLowerCase(),cancelled:'DefectRAG: Case cancelled · no action needed'})[($json.kind==='updated'&&['Resolved','Closed'].includes($json.state)?'done':$json.kind==='updated'&&$json.state==='Cancelled'?'cancelled':$json.kind)] }}", "emailFormat": "both", "text": "=A corrective action case needs attention.\n\nWhat happened: {{ ({created:'New case created',updated:'Case updated',reminder:'Due within 24 hours',overdue:'Overdue'})[$json.kind] || $json.kind }}\nCase: {{ $json.case_id.slice(0,8) }} · Priority: {{ $json.priority }} · Status: {{ $json.state }}\nDue: {{ DateTime.fromISO($json.due_at).setZone('Asia/Kuala_Lumpur').toFormat('cccc d LLL yyyy, h:mm a') }} (Malaysia time)\n\nSent to the case supervisor{{ $json.cc_email ? ', with the person responsible copied' : '' }}.\nOpen the case (sign in with your security code): https://wizzas-defectrag.hf.space/#cases\nPhotos and notes stay private inside DefectRAG.", "options": { "appendAttribution": false, "ccEmail": "={{ $json.cc_email || '' }}" }, "html": "=\n\nDefectRAG corrective action\n\n{{ ({created:'New case',updated:'Quick update',reminder:'Friendly reminder',overdue:'Needs a little attention',done:'All done',cancelled:'Cancelled'})[($json.kind==='updated'&&['Resolved','Closed'].includes($json.state)?'done':$json.kind==='updated'&&$json.state==='Cancelled'?'cancelled':$json.kind)] }} · due {{ DateTime.fromISO($json.due_at).setZone('Asia/Kuala_Lumpur').toFormat(\"cccc, d LLL 'at' h:mm a\") }} · priority {{ $json.priority }}​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ \n
\n\n\n\n\n\n\n\n\n\n
DefectRAG / Corrective actions
\"DefectRAG
{{ ({created:'New case',updated:'Quick update',reminder:'Friendly reminder',overdue:'Needs a little attention',done:'All done',cancelled:'Cancelled'})[($json.kind==='updated'&&['Resolved','Closed'].includes($json.state)?'done':$json.kind==='updated'&&$json.state==='Cancelled'?'cancelled':$json.kind)] }}
{{ ({created:'Hi! A new corrective action is ready for you',updated:'Hi! This case is now '+$json.state,reminder:'Hi! Just a gentle heads-up',overdue:'Hi! This case could use a quick check-in',done:'Nice work! This case is '+$json.state.toLowerCase(),cancelled:'Hi! This case was cancelled'})[($json.kind==='updated'&&['Resolved','Closed'].includes($json.state)?'done':$json.kind==='updated'&&$json.state==='Cancelled'?'cancelled':$json.kind)] }}
{{ ({created:'A Staff review spotted a defect that needs fixing. No need to worry, this is a normal follow-up: take a look when you can and agree the next step together. It’s due on ',updated:'There’s a small update on this corrective action. Open it whenever you’re ready to see what changed. It’s due on ',reminder:'This case is due on ',overdue:'This case was due on ',done:'Thanks for following it through! It was due on ',cancelled:'No further work is needed. It was due on '})[($json.kind==='updated'&&['Resolved','Closed'].includes($json.state)?'done':$json.kind==='updated'&&$json.state==='Cancelled'?'cancelled':$json.kind)] }}{{ DateTime.fromISO($json.due_at).setZone('Asia/Kuala_Lumpur').toFormat(\"cccc, d LLL 'at' h:mm a\") }}{{ ({created:'.',updated:'.',reminder:' and is still open. A quick look at progress is all it needs.',overdue:' and is still open. No stress, could you check in with the person responsible today and update the case?',done:'. Nothing else is needed unless the case is reopened.',cancelled:'.'})[($json.kind==='updated'&&['Resolved','Closed'].includes($json.state)?'done':$json.kind==='updated'&&$json.state==='Cancelled'?'cancelled':$json.kind)] }}
\n\n\n\n\n
Case{{ $json.case_id.slice(0,8) }}
Status{{ $json.state }}
Priority{{ $json.priority }}
Due{{ DateTime.fromISO($json.due_at).setZone('Asia/Kuala_Lumpur').toFormat('d LLL yyyy, h:mm a') }} (Malaysia time)
View case
You are receiving this as the supervisor{{ $json.cc_email ? ' or the person responsible' : '' }} on this case. Photos and review notes stay inside DefectRAG, so you will need to sign in with your security code to see them.
" }, "credentials": { "smtp": { "id": "CONFIGURE_IN_N8N", "name": "DefectRAG CA isolated TEST SMTP" } } }, { "id": "accept", "name": "Verify supervisor acceptance", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1100, -100 ], "parameters": { "jsCode": "const r=$input.first().json;const reserved=$('Reserve notification effect').first().json;const accepted=Array.isArray(r.accepted)?r.accepted.map(e=>String(e).toLowerCase()):[];const required=[reserved.recipient_email,reserved.cc_email].filter(Boolean).map(e=>String(e).toLowerCase());if(!required.length||!required.every(e=>accepted.includes(e))||(r.rejected||[]).length||typeof r.messageId!=='string'||!r.messageId||r.messageId.length>200)throw Error('SMTP acceptance not verified');const e=$('Validate case event').first().json;return [{json:{operation:'finish',event_id:e.event_id,lease_token:e.lease_token,receipt:r.messageId}}];" } }, { "id": "finish", "name": "Record notification receipt", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1320, -100 ], "parameters": { "method": "POST", "url": "https://PROJECT_REF.supabase.co/functions/v1/corrective-actions", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "X-DefectRAG-Operation", "value": "effect" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ $json }}", "options": { "timeout": 10000 } }, "credentials": { "httpHeaderAuth": { "id": "CONFIGURE_IN_N8N", "name": "DefectRAG CA callback bearer" } } }, { "id": "done", "name": "Require durable completion", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1540, 0 ], "parameters": { "jsCode": "if($input.first().json.done!==true)throw Error('Ambiguous notification requires manual reconciliation');return [{json:{event_id:$('Validate case event').first().json.event_id,completed:true}}];" } }, { "id": "response", "name": "Workflow completed", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.4, "position": [ 1760, 0 ], "parameters": { "respondWith": "json", "responseBody": "={{ $json }}", "options": { "responseCode": 200 } } } ], "connections": { "Authenticated case event": { "main": [ [ { "node": "Validate case event", "type": "main", "index": 0 } ] ] }, "Validate case event": { "main": [ [ { "node": "Reserve notification effect", "type": "main", "index": 0 } ] ] }, "Reserve notification effect": { "main": [ [ { "node": "Effect requires execution", "type": "main", "index": 0 } ] ] }, "Effect requires execution": { "main": [ [ { "node": "Notify verified supervisor", "type": "main", "index": 0 } ], [ { "node": "Require durable completion", "type": "main", "index": 0 } ] ] }, "Notify verified supervisor": { "main": [ [ { "node": "Verify supervisor acceptance", "type": "main", "index": 0 } ] ] }, "Verify supervisor acceptance": { "main": [ [ { "node": "Record notification receipt", "type": "main", "index": 0 } ] ] }, "Record notification receipt": { "main": [ [ { "node": "Require durable completion", "type": "main", "index": 0 } ] ] }, "Require durable completion": { "main": [ [ { "node": "Workflow completed", "type": "main", "index": 0 } ] ] } } }