From 5584de38e02e9e23ed50fab81e129406ffd6eb29 Mon Sep 17 00:00:00 2001 From: Fizzlepoof Date: Wed, 13 May 2026 20:10:25 +0000 Subject: [PATCH] fix(n8n): restore paperless webhook compatibility --- n8n-workflows/17-paperless-intake-triage.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/n8n-workflows/17-paperless-intake-triage.json b/n8n-workflows/17-paperless-intake-triage.json index eb8df55..9f8e095 100644 --- a/n8n-workflows/17-paperless-intake-triage.json +++ b/n8n-workflows/17-paperless-intake-triage.json @@ -20,7 +20,7 @@ }, { "parameters": { - "jsCode": "\nconst body = $json.body || $json;\nconst id = body.document_id || body.id || body.document;\nif (!id) throw new Error('Missing document_id/id in Paperless webhook payload');\nreturn [{ json: { document_id: String(id), received_at: new Date().toISOString(), webhook_payload_keys: Object.keys(body) } }];\n" + "jsCode": "\nconst body = $json.body || $json;\nlet id = body.document_id || body.id || body.doc_id || body.pk || body.document;\nif (!id || (typeof id === 'string' && id.includes('{'))) {\n id = null;\n}\nreturn [{ json: { document_id: id ? String(id) : null, received_at: new Date().toISOString(), webhook_payload_keys: Object.keys(body) } }];\n" }, "id": "extract-doc-id", "name": "Extract Document ID", @@ -33,7 +33,7 @@ }, { "parameters": { - "url": "={{($env.PAPERLESS_BASE_URL || 'https://paperless.paccoco.com').replace(/\\/$/, '') + '/api/documents/' + $json.document_id + '/'}}", + "url": "={{($env.PAPERLESS_BASE_URL || 'https://paperless.paccoco.com').replace(/\\/$/, '') + '/api/documents/' + ($json.document_id ? ($json.document_id + '/') : '?ordering=-added&page_size=1')}}", "sendHeaders": true, "headerParameters": { "parameters": [ @@ -62,7 +62,7 @@ }, { "parameters": { - "jsCode": "\nconst doc = $json;\nconst truncate = (s, n=9000) => String(s || '').replace(/\\s+/g, ' ').trim().slice(0, n);\nconst archiveUrl = `${($env.PAPERLESS_BASE_URL || 'https://paperless.paccoco.com').replace(/\\/$/, '')}/documents/${doc.id}/details`;\nconst payload = {\n id: doc.id,\n title: doc.title || null,\n original_filename: doc.original_filename || doc.archive_filename || null,\n created: doc.created || null,\n added: doc.added || doc.created_date || null,\n correspondent: doc.correspondent_detail?.name || doc.correspondent || null,\n document_type: doc.document_type_detail?.name || doc.document_type || null,\n tags: (doc.tags_detail || doc.tags || []).map(t => typeof t === 'string' ? t : (t.name || t.id)).filter(Boolean),\n archive_url: archiveUrl,\n content: truncate(doc.content || doc.text || '')\n};\nconst schema = `Return STRICT JSON only with exactly these keys: summary, suggested_title, document_type, suggested_correspondent, suggested_tags, due_date, needs_review, urgency, reason, confidence. document_type must be one of bill, receipt, school, medical, tax, insurance, legal, manual, letter, other. due_date is YYYY-MM-DD or null. urgency is none, low, medium, high. confidence is high, medium, low.`;\nreturn [{ json: { document: payload, llm_messages: [\n { role: 'system', content: 'You triage Paperless-NGX documents for a human review-first dashboard. Never invent due dates. Be conservative. ' + schema },\n { role: 'user', content: JSON.stringify(payload) }\n] } }];\n" + "jsCode": "\nconst response = $json;\nconst doc = response.results ? response.results[0] : response;\nif (!doc || !doc.id) throw new Error('No document found in Paperless API response');\nconst truncate = (s, n=9000) => String(s || '').replace(/\\s+/g, ' ').trim().slice(0, n);\nconst archiveUrl = `${($env.PAPERLESS_BASE_URL || 'https://paperless.paccoco.com').replace(/\\/$/, '')}/documents/${doc.id}/details`;\nconst payload = {\n id: doc.id,\n title: doc.title || 'Untitled',\n original_filename: doc.original_filename || doc.original_file_name || doc.archive_filename || null,\n created: doc.created || null,\n added: doc.added || doc.created_date || null,\n correspondent: doc.correspondent_detail?.name || doc.correspondent_name || doc.correspondent || null,\n document_type: doc.document_type_detail?.name || doc.document_type_name || doc.document_type || null,\n tags: (doc.tags_detail || doc.tags || []).map(t => typeof t === 'string' ? t : (t.name || t.id)).filter(Boolean),\n archive_url: archiveUrl,\n content: truncate(doc.content || doc.text || '')\n};\nconst schema = `Return STRICT JSON only with exactly these keys: summary, suggested_title, document_type, suggested_correspondent, suggested_tags, due_date, needs_review, urgency, reason, confidence. document_type must be one of bill, receipt, school, medical, tax, insurance, legal, manual, letter, other. due_date is YYYY-MM-DD or null. urgency is none, low, medium, high. confidence is high, medium, low.`;\nreturn [{ json: { document: payload, llm_messages: [\n { role: 'system', content: 'You triage Paperless-NGX documents for a human review-first dashboard. Never invent due dates. Be conservative. ' + schema },\n { role: 'user', content: JSON.stringify(payload) }\n] } }];\n" }, "id": "prepare-triage", "name": "Prepare Compact Triage Payload",