# workflow_versions

workflow_id: QMHZ5IAhBvRgyZAc
workflow_name: POST /chat/generate-pdf
trigger: partial_update
created_at: 2025-10-24 14:25:09
workflow_snapshot:
  {"createdAt":"2025-10-23T22:18:56.433Z","updatedAt":"2025-10-24T14:24:58.342Z","id":"QMHZ5IAhBvRgyZAc","name":"POST /chat/generate-pdf","active":true,"isArchived":false,"nodes":[{"parameters":{"httpMethod":"POST","path":"chat/generate-pdf","responseMode":"responseNode","options":{}},"id":"webhook-trigger","name":"POST /chat/generate-pdf","type":"n8n-nodes-base.webhook","typeVersion":2.1,"position":[240,312],"webhookId":"67403d18-ee13-4ad3-b9b7-02d012aeaf0e","onError":"continueRegularOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"message-id-condition","leftValue":"={{ $('POST /chat/generate-pdf').first().json.body.message_id }}","rightValue":"","operator":{"type":"string","operation":"notEmpty"}}],"combinator":"and"},"options":{}},"id":"check-message-id","name":"Check Message ID","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[912,400],"onError":"continueErrorOutput"},{"parameters":{"url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/rest/v1/conversation_messages?select=id,message,created_at,conversation_threads!inner(user_id)&id=eq.' + $('POST /chat/generate-pdf').first().json.body.message_id + '&conversation_threads.user_id=eq.' + $('JWT Validation').first().json.user_id }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"Prefer","value":"return=representation"}]},"options":{"response":{"response":{"responseFormat":"json"}}}},"id":"query-specific-message","name":"Query Specific Message","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1136,320],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/rest/v1/conversation_messages?select=id,message,created_at,conversation_threads!inner(user_id)&conversation_threads.user_id=eq.' + $('JWT Validation').first().json.user_id + '&order=created_at.desc&limit=1' }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"Prefer","value":"return=representation"}]},"options":{"response":{"response":{"responseFormat":"json"}}}},"id":"query-latest-message","name":"Query Latest Message","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1136,512],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"message-exists-condition","leftValue":"={{ $json.id }}","rightValue":"0","operator":{"type":"string","operation":"notEmpty"}}],"combinator":"and"},"options":{}},"id":"check-message-exists","name":"Check Message Exists","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1360,400],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'Not Found', message: 'Message not found or you do not have access to it' }) }}","options":{"responseCode":404}},"id":"return-not-found","name":"Return Not Found","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1584,320]},{"parameters":{"jsCode":"// Get message data from previous node\nconst messageData = $input.first().json;\n\n// Get user ID from JWT Validation\nconst userId = $('JWT Validation').first().json.user_id;\n\n// Extract content from JSONB structure\nconst content = messageData.message.content;\n\n// Format date in Polish\nconst date = new Date(messageData.created_at);\nconst formattedDate = date.toLocaleDateString('pl-PL', {\n  year: 'numeric',\n  month: 'long',\n  day: 'numeric',\n  hour: '2-digit',\n  minute: '2-digit'\n});\n\n// Create HTML for PDF with WOO branding\nconst html = `<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <style>\n    body {\n      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n      line-height: 1.6;\n      color: #333;\n      padding: 40px;\n      max-width: 800px;\n      margin: 0 auto;\n    }\n    .header {\n      display: flex;\n      justify-content: space-between;\n      align-items: center;\n      margin-bottom: 40px;\n      padding-bottom: 20px;\n      border-bottom: 3px solid #4b0082;\n    }\n    .logo {\n      width: 120px;\n      height: 120px;\n    }\n    .title {\n      color: #4b0082;\n      font-size: 24px;\n      font-weight: 600;\n    }\n    .date {\n      color: #666;\n      font-size: 14px;\n      margin-bottom: 20px;\n    }\n    .content {\n      background: #f9f9f9;\n      padding: 30px;\n      border-radius: 8px;\n      border-left: 4px solid #4b0082;\n    }\n    .footer {\n      margin-top: 40px;\n      padding-top: 20px;\n      border-top: 1px solid #ddd;\n      text-align: center;\n      color: #888;\n      font-size: 12px;\n    }\n  </style>\n</head>\n<body>\n  <div class=\"header\">\n    <div class=\"title\">WOO PRO - Wiadomość</div>\n    <img src=\"https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/public/public_files/logo-email.png\" \n         class=\"logo\" alt=\"WOO Logo\">\n  </div>\n  \n  <div class=\"date\">${formattedDate}</div>\n  \n  <div class=\"content\">\n    ${content.replace(/\\n/g, '<br>')}\n  </div>\n  \n  <div class=\"footer\">\n    Wygenerowano przez WOO PRO<br>\n    Ten dokument jest poufny i przeznaczony wyłącznie dla odbiorcy.\n  </div>\n</body>\n</html>`;\n\nreturn [{\n  json: {\n    html: html,\n    fileName: `${userId}/woo-message-${messageData.id}.pdf`,\n    messageId: messageData.id\n  }\n}];"},"id":"prepare-html-template","name":"Prepare HTML Template","type":"n8n-nodes-base.code","typeVersion":2,"position":[1584,512]},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"pdf-success-condition","leftValue":"={{ $json.error }}","rightValue":"false","operator":{"type":"boolean","operation":"false","singleValue":true}}],"combinator":"and"},"options":{}},"id":"check-pdf-success","name":"Check PDF Success","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2032,496],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'PDF Generation Failed', message: $json.message || 'Failed to generate PDF document' }) }}","options":{"responseCode":500}},"id":"return-pdf-error","name":"Return PDF Error","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[2256,416]},{"parameters":{"method":"POST","url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/generated_pdfs/' + $('Prepare HTML Template').first().json.fileName }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Content-Type","value":"application/pdf"}]},"sendBody":true,"contentType":"binaryData","inputDataFieldName":"data","options":{"response":{"response":{"responseFormat":"json"}}}},"id":"upload-pdf-to-storage","name":"Upload PDF to Storage","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2480,608],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"method":"POST","url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/sign/generated_pdfs/' + $('Prepare HTML Template').first().json.fileName }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Content-Type","value":"application/json"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ { expiresIn: 86400 } }}","options":{"response":{"response":{"responseFormat":"json"}}}},"id":"generate-signed-url","name":"Generate Signed URL","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2704,608],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"jsCode":"const signedUrl = $input.first().json.signedURL;\nconst fileName = $('Prepare HTML Template').first().json.fileName;\nconst messageId = $('Prepare HTML Template').first().json.messageId;\n\nreturn [{\n  json: {\n    success: true,\n    message: 'PDF generated successfully',\n    data: {\n      pdfUrl: `https://xxciwnthnnywanbplqwg.supabase.co/storage/v1${signedUrl}`,\n      fileName: fileName,\n      messageId: messageId,\n      expiresIn: '24 hours'\n    }\n  }\n}];"},"id":"format-success-response","name":"Format Success Response","type":"n8n-nodes-base.code","typeVersion":2,"position":[2928,608]},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify($json) }}","options":{"responseCode":200}},"id":"return-success","name":"Return Success","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[3152,608]},{"parameters":{"method":"POST","url":"https://api.pdf.co/v1/pdf/convert/from/html","sendHeaders":true,"headerParameters":{"parameters":[{"name":"x-api-key","value":"reeunlockyourskills@gmail.com_SQcbrlvobSplxYtx2Ed8h2toSbsqenyPfWqLkjpvjc5uj68FXk78S3DNibeAw3v0"},{"name":"Content-Type","value":"application/json"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ { \"html\": $json.html, \"name\": $json.fileName } }}","options":{"response":{"response":{"responseFormat":"json"}}}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1808,512],"id":"f2e54550-eb45-4363-930d-c2908ca394ac","name":"call_generate_pdf"},{"parameters":{"url":"={{ $json.url }}","options":{"response":{"response":{"responseFormat":"file"}}}},"id":"download-pdf-from-url","name":"Download PDF from URL","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2256,608]},{"parameters":{"workflowId":{"__rl":true,"value":"dL4gKHrO0Mtdhpmo","mode":"list","cachedResultUrl":"/workflow/dL4gKHrO0Mtdhpmo","cachedResultName":"JWT Validation Middleware"},"workflowInputs":{"mappingMode":"defineBelow","value":{"headers":"={{ $json.headers }}","body":"={{ $json.body }}"},"matchingColumns":[],"schema":[{"id":"headers","displayName":"headers","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true,"type":"object"},{"id":"body","displayName":"body","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true},{"id":"params","displayName":"params","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true,"type":"object","removed":true}],"attemptToConvertTypes":false,"convertFieldsToString":true},"options":{}},"id":"97fea410-3161-474d-a49e-2dc7804c98db","name":"JWT Validation","type":"n8n-nodes-base.executeWorkflow","typeVersion":1.3,"position":[464,320],"onError":"continueErrorOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"jwt_error_check","leftValue":"={{ $json.is_valid }}","rightValue":"={{ true }}","operator":{"type":"boolean","operation":"false","singleValue":true}}],"combinator":"and"},"options":{}},"id":"1705f618-2fa2-4d37-8ec5-5f117e4df232","name":"Check JWT Error","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[688,320],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ {\n  success: false,\n  data: null,\n  error: 'Unauthorized',\n  metadata: {\n    timestamp: new Date().toISOString()\n  }\n} }}","options":{"responseCode":401}},"id":"dee5bfdc-9a05-4494-80a9-6f36cbcb8d26","name":"JWT Error Response","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[912,192],"onError":"continueRegularOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ {\n  success: false,\n  error: {\n    code: 'UNAUTHORIZED',\n    message: 'Invalid or expired access token'\n  },\n  metadata: {\n    timestamp: new Date().toISOString()\n  }\n} }}","options":{"responseCode":401}},"id":"d0079bd8-15d8-42a8-8418-191fde6dd0f3","name":"Auth Error Response","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[688,512],"onError":"continueRegularOutput"},{"id":"validate-uuid-format","name":"Validate UUID Format","type":"n8n-nodes-base.code","typeVersion":2,"position":[1024,320],"parameters":{"jsCode":"const messageId = $('POST /chat/generate-pdf').first().json.body.message_id;\n\n// UUID v4 regex pattern\nconst uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\nconst isValid = uuidRegex.test(messageId);\n\nreturn [{\n  json: {\n    messageId: messageId,\n    isValidUUID: isValid\n  }\n}];"}},{"id":"check-uuid-valid","name":"Check UUID Valid","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1248,320],"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"uuid-valid-condition","leftValue":"={{ $json.isValidUUID }}","rightValue":"={{ true }}","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"options":{}},"onError":"continueErrorOutput"},{"id":"return-invalid-uuid","name":"Return Invalid UUID","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1472,240],"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ success: false, error: 'Invalid message_id format. Expected valid UUID.' }) }}","options":{"responseCode":400}}}],"connections":{"POST /chat/generate-pdf":{"main":[[{"node":"JWT Validation","type":"main","index":0}]]},"Query Specific Message":{"main":[[{"node":"Check Message Exists","type":"main","index":0}]]},"Query Latest Message":{"main":[[{"node":"Check Message Exists","type":"main","index":0}]]},"Upload PDF to Storage":{"main":[[{"node":"Generate Signed URL","type":"main","index":0}]]},"Generate Signed URL":{"main":[[{"node":"Format Success Response","type":"main","index":0}]]},"Format Success Response":{"main":[[{"node":"Return Success","type":"main","index":0}]]},"Check Message ID":{"main":[[{"node":"Validate UUID Format","type":"main","index":0}],[{"node":"Query Latest Message","type":"main","index":0}]]},"Check Message Exists":{"main":[[{"node":"Prepare HTML Template","type":"main","index":0}],[{"node":"Return Not Found","type":"main","index":0}]]},"Check PDF Success":{"main":[[{"node":"Download PDF from URL","type":"main","index":0}],[{"node":"Return PDF Error","type":"main","index":0}]]},"Prepare HTML Template":{"main":[[{"node":"call_generate_pdf","type":"main","index":0}]]},"call_generate_pdf":{"main":[[{"node":"Check PDF Success","type":"main","index":0}]]},"Download PDF from URL":{"main":[[{"node":"Upload PDF to Storage","type":"main","index":0}]]},"JWT Validation":{"main":[[{"node":"Check JWT Error","type":"main","index":0}],[{"node":"Auth Error Response","type":"main","index":0}]]},"Check JWT Error":{"main":[[{"node":"JWT Error Response","type":"main","index":0}],[{"node":"Check Message ID","type":"main","index":0}]]},"Validate UUID Format":{"main":[[{"node":"Check UUID Valid","type":"main","index":0}]]},"Check UUID Valid":{"main":[[{"node":"Query Specific Message","type":"main","index":0},{"node":"Return Invalid UUID","type":"main","index":0}]]}},"settings":{"saveManualExecutions":true,"saveDataErrorExecution":"all","saveDataSuccessExecution":"all","errorWorkflow":"","executionOrder":"v1"},"staticData":null,"meta":null,"pinData":{},"versionId":"19749b07-a8cb-48ed-9042-0f4a43d99509","triggerCount":1,"shared":[{"createdAt":"2025-10-23T22:18:56.436Z","updatedAt":"2025-10-23T22:18:56.436Z","role":"workflow:owner","workflowId":"QMHZ5IAhBvRgyZAc","projectId":"sVGwG1Ss6aXKNorC","project":{"createdAt":"2025-07-30T12:18:11.485Z","updatedAt":"2025-07-30T12:20:06.951Z","id":"sVGwG1Ss6aXKNorC","name":"Rafał Dębski <rdebski90@gmail.com>","type":"personal","icon":null,"description":null,"projectRelations":[{"createdAt":"2025-07-30T12:18:11.486Z","updatedAt":"2025-07-30T12:18:11.486Z","userId":"512c6fc4-ef1e-46ec-99da-b435fcbf2339","projectId":"sVGwG1Ss6aXKNorC","user":{"createdAt":"2025-07-30T12:18:10.851Z","updatedAt":"2025-10-23T22:43:16.000Z","id":"512c6fc4-ef1e-46ec-99da-b435fcbf2339","email":"rdebski90@gmail.com","firstName":"Rafał","lastName":"Dębski","personalizationAnswers":{"version":"v4","personalization_survey_submitted_at":"2025-07-30T12:20:09.619Z","personalization_survey_n8n_version":"1.104.1"},"settings":{"userActivated":true,"easyAIWorkflowOnboarded":true,"firstSuccessfulWorkflowId":"gp796pP6j8IFZodb","userActivatedAt":1753881412699,"npsSurvey":{"responded":true,"lastShownAt":1755785806897},"dismissedCallouts":{"ragStarterCallout":true}},"disabled":false,"mfaEnabled":false,"lastActiveAt":"2025-10-23","isPending":false}}]}}],"tags":[]}

operations:
  [{"type":"removeConnection","source":"check-uuid-valid","target":"return-invalid-uuid"},{"type":"addConnection","source":"check-uuid-valid","target":"return-invalid-uuid"}]


workflow_id: QMHZ5IAhBvRgyZAc
workflow_name: POST /chat/generate-pdf
trigger: partial_update
created_at: 2025-10-24 14:25:23
workflow_snapshot:
  {"createdAt":"2025-10-23T22:18:56.433Z","updatedAt":"2025-10-24T14:25:10.114Z","id":"QMHZ5IAhBvRgyZAc","name":"POST /chat/generate-pdf","active":true,"isArchived":false,"nodes":[{"parameters":{"httpMethod":"POST","path":"chat/generate-pdf","responseMode":"responseNode","options":{}},"id":"webhook-trigger","name":"POST /chat/generate-pdf","type":"n8n-nodes-base.webhook","typeVersion":2.1,"position":[240,312],"webhookId":"67403d18-ee13-4ad3-b9b7-02d012aeaf0e","onError":"continueRegularOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"message-id-condition","leftValue":"={{ $('POST /chat/generate-pdf').first().json.body.message_id }}","rightValue":"","operator":{"type":"string","operation":"notEmpty"}}],"combinator":"and"},"options":{}},"id":"check-message-id","name":"Check Message ID","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[912,400],"onError":"continueErrorOutput"},{"parameters":{"url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/rest/v1/conversation_messages?select=id,message,created_at,conversation_threads!inner(user_id)&id=eq.' + $('POST /chat/generate-pdf').first().json.body.message_id + '&conversation_threads.user_id=eq.' + $('JWT Validation').first().json.user_id }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"Prefer","value":"return=representation"}]},"options":{"response":{"response":{"responseFormat":"json"}}}},"id":"query-specific-message","name":"Query Specific Message","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1136,320],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/rest/v1/conversation_messages?select=id,message,created_at,conversation_threads!inner(user_id)&conversation_threads.user_id=eq.' + $('JWT Validation').first().json.user_id + '&order=created_at.desc&limit=1' }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"Prefer","value":"return=representation"}]},"options":{"response":{"response":{"responseFormat":"json"}}}},"id":"query-latest-message","name":"Query Latest Message","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1136,512],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"message-exists-condition","leftValue":"={{ $json.id }}","rightValue":"0","operator":{"type":"string","operation":"notEmpty"}}],"combinator":"and"},"options":{}},"id":"check-message-exists","name":"Check Message Exists","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1360,400],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'Not Found', message: 'Message not found or you do not have access to it' }) }}","options":{"responseCode":404}},"id":"return-not-found","name":"Return Not Found","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1584,320]},{"parameters":{"jsCode":"// Get message data from previous node\nconst messageData = $input.first().json;\n\n// Get user ID from JWT Validation\nconst userId = $('JWT Validation').first().json.user_id;\n\n// Extract content from JSONB structure\nconst content = messageData.message.content;\n\n// Format date in Polish\nconst date = new Date(messageData.created_at);\nconst formattedDate = date.toLocaleDateString('pl-PL', {\n  year: 'numeric',\n  month: 'long',\n  day: 'numeric',\n  hour: '2-digit',\n  minute: '2-digit'\n});\n\n// Create HTML for PDF with WOO branding\nconst html = `<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <style>\n    body {\n      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n      line-height: 1.6;\n      color: #333;\n      padding: 40px;\n      max-width: 800px;\n      margin: 0 auto;\n    }\n    .header {\n      display: flex;\n      justify-content: space-between;\n      align-items: center;\n      margin-bottom: 40px;\n      padding-bottom: 20px;\n      border-bottom: 3px solid #4b0082;\n    }\n    .logo {\n      width: 120px;\n      height: 120px;\n    }\n    .title {\n      color: #4b0082;\n      font-size: 24px;\n      font-weight: 600;\n    }\n    .date {\n      color: #666;\n      font-size: 14px;\n      margin-bottom: 20px;\n    }\n    .content {\n      background: #f9f9f9;\n      padding: 30px;\n      border-radius: 8px;\n      border-left: 4px solid #4b0082;\n    }\n    .footer {\n      margin-top: 40px;\n      padding-top: 20px;\n      border-top: 1px solid #ddd;\n      text-align: center;\n      color: #888;\n      font-size: 12px;\n    }\n  </style>\n</head>\n<body>\n  <div class=\"header\">\n    <div class=\"title\">WOO PRO - Wiadomość</div>\n    <img src=\"https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/public/public_files/logo-email.png\" \n         class=\"logo\" alt=\"WOO Logo\">\n  </div>\n  \n  <div class=\"date\">${formattedDate}</div>\n  \n  <div class=\"content\">\n    ${content.replace(/\\n/g, '<br>')}\n  </div>\n  \n  <div class=\"footer\">\n    Wygenerowano przez WOO PRO<br>\n    Ten dokument jest poufny i przeznaczony wyłącznie dla odbiorcy.\n  </div>\n</body>\n</html>`;\n\nreturn [{\n  json: {\n    html: html,\n    fileName: `${userId}/woo-message-${messageData.id}.pdf`,\n    messageId: messageData.id\n  }\n}];"},"id":"prepare-html-template","name":"Prepare HTML Template","type":"n8n-nodes-base.code","typeVersion":2,"position":[1584,512]},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"pdf-success-condition","leftValue":"={{ $json.error }}","rightValue":"false","operator":{"type":"boolean","operation":"false","singleValue":true}}],"combinator":"and"},"options":{}},"id":"check-pdf-success","name":"Check PDF Success","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2032,496],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'PDF Generation Failed', message: $json.message || 'Failed to generate PDF document' }) }}","options":{"responseCode":500}},"id":"return-pdf-error","name":"Return PDF Error","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[2256,416]},{"parameters":{"method":"POST","url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/generated_pdfs/' + $('Prepare HTML Template').first().json.fileName }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Content-Type","value":"application/pdf"}]},"sendBody":true,"contentType":"binaryData","inputDataFieldName":"data","options":{"response":{"response":{"responseFormat":"json"}}}},"id":"upload-pdf-to-storage","name":"Upload PDF to Storage","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2480,608],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"method":"POST","url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/sign/generated_pdfs/' + $('Prepare HTML Template').first().json.fileName }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Content-Type","value":"application/json"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ { expiresIn: 86400 } }}","options":{"response":{"response":{"responseFormat":"json"}}}},"id":"generate-signed-url","name":"Generate Signed URL","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2704,608],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"jsCode":"const signedUrl = $input.first().json.signedURL;\nconst fileName = $('Prepare HTML Template').first().json.fileName;\nconst messageId = $('Prepare HTML Template').first().json.messageId;\n\nreturn [{\n  json: {\n    success: true,\n    message: 'PDF generated successfully',\n    data: {\n      pdfUrl: `https://xxciwnthnnywanbplqwg.supabase.co/storage/v1${signedUrl}`,\n      fileName: fileName,\n      messageId: messageId,\n      expiresIn: '24 hours'\n    }\n  }\n}];"},"id":"format-success-response","name":"Format Success Response","type":"n8n-nodes-base.code","typeVersion":2,"position":[2928,608]},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify($json) }}","options":{"responseCode":200}},"id":"return-success","name":"Return Success","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[3152,608]},{"parameters":{"method":"POST","url":"https://api.pdf.co/v1/pdf/convert/from/html","sendHeaders":true,"headerParameters":{"parameters":[{"name":"x-api-key","value":"reeunlockyourskills@gmail.com_SQcbrlvobSplxYtx2Ed8h2toSbsqenyPfWqLkjpvjc5uj68FXk78S3DNibeAw3v0"},{"name":"Content-Type","value":"application/json"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ { \"html\": $json.html, \"name\": $json.fileName } }}","options":{"response":{"response":{"responseFormat":"json"}}}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1808,512],"id":"f2e54550-eb45-4363-930d-c2908ca394ac","name":"call_generate_pdf"},{"parameters":{"url":"={{ $json.url }}","options":{"response":{"response":{"responseFormat":"file"}}}},"id":"download-pdf-from-url","name":"Download PDF from URL","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2256,608]},{"parameters":{"workflowId":{"__rl":true,"value":"dL4gKHrO0Mtdhpmo","mode":"list","cachedResultUrl":"/workflow/dL4gKHrO0Mtdhpmo","cachedResultName":"JWT Validation Middleware"},"workflowInputs":{"mappingMode":"defineBelow","value":{"headers":"={{ $json.headers }}","body":"={{ $json.body }}"},"matchingColumns":[],"schema":[{"id":"headers","displayName":"headers","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true,"type":"object"},{"id":"body","displayName":"body","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true},{"id":"params","displayName":"params","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true,"type":"object","removed":true}],"attemptToConvertTypes":false,"convertFieldsToString":true},"options":{}},"id":"97fea410-3161-474d-a49e-2dc7804c98db","name":"JWT Validation","type":"n8n-nodes-base.executeWorkflow","typeVersion":1.3,"position":[464,320],"onError":"continueErrorOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"jwt_error_check","leftValue":"={{ $json.is_valid }}","rightValue":"={{ true }}","operator":{"type":"boolean","operation":"false","singleValue":true}}],"combinator":"and"},"options":{}},"id":"1705f618-2fa2-4d37-8ec5-5f117e4df232","name":"Check JWT Error","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[688,320],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ {\n  success: false,\n  data: null,\n  error: 'Unauthorized',\n  metadata: {\n    timestamp: new Date().toISOString()\n  }\n} }}","options":{"responseCode":401}},"id":"dee5bfdc-9a05-4494-80a9-6f36cbcb8d26","name":"JWT Error Response","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[912,192],"onError":"continueRegularOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ {\n  success: false,\n  error: {\n    code: 'UNAUTHORIZED',\n    message: 'Invalid or expired access token'\n  },\n  metadata: {\n    timestamp: new Date().toISOString()\n  }\n} }}","options":{"responseCode":401}},"id":"d0079bd8-15d8-42a8-8418-191fde6dd0f3","name":"Auth Error Response","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[688,512],"onError":"continueRegularOutput"},{"id":"validate-uuid-format","name":"Validate UUID Format","type":"n8n-nodes-base.code","typeVersion":2,"position":[1024,320],"parameters":{"jsCode":"const messageId = $('POST /chat/generate-pdf').first().json.body.message_id;\n\n// UUID v4 regex pattern\nconst uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\nconst isValid = uuidRegex.test(messageId);\n\nreturn [{\n  json: {\n    messageId: messageId,\n    isValidUUID: isValid\n  }\n}];"}},{"id":"check-uuid-valid","name":"Check UUID Valid","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1248,320],"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"uuid-valid-condition","leftValue":"={{ $json.isValidUUID }}","rightValue":"={{ true }}","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"options":{}},"onError":"continueErrorOutput"},{"id":"return-invalid-uuid","name":"Return Invalid UUID","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1472,240],"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ success: false, error: 'Invalid message_id format. Expected valid UUID.' }) }}","options":{"responseCode":400}}}],"connections":{"POST /chat/generate-pdf":{"main":[[{"node":"JWT Validation","type":"main","index":0}]]},"Query Specific Message":{"main":[[{"node":"Check Message Exists","type":"main","index":0}]]},"Query Latest Message":{"main":[[{"node":"Check Message Exists","type":"main","index":0}]]},"Upload PDF to Storage":{"main":[[{"node":"Generate Signed URL","type":"main","index":0}]]},"Generate Signed URL":{"main":[[{"node":"Format Success Response","type":"main","index":0}]]},"Format Success Response":{"main":[[{"node":"Return Success","type":"main","index":0}]]},"Check Message ID":{"main":[[{"node":"Validate UUID Format","type":"main","index":0}],[{"node":"Query Latest Message","type":"main","index":0}]]},"Check Message Exists":{"main":[[{"node":"Prepare HTML Template","type":"main","index":0}],[{"node":"Return Not Found","type":"main","index":0}]]},"Check PDF Success":{"main":[[{"node":"Download PDF from URL","type":"main","index":0}],[{"node":"Return PDF Error","type":"main","index":0}]]},"Prepare HTML Template":{"main":[[{"node":"call_generate_pdf","type":"main","index":0}]]},"call_generate_pdf":{"main":[[{"node":"Check PDF Success","type":"main","index":0}]]},"Download PDF from URL":{"main":[[{"node":"Upload PDF to Storage","type":"main","index":0}]]},"JWT Validation":{"main":[[{"node":"Check JWT Error","type":"main","index":0}],[{"node":"Auth Error Response","type":"main","index":0}]]},"Check JWT Error":{"main":[[{"node":"JWT Error Response","type":"main","index":0}],[{"node":"Check Message ID","type":"main","index":0}]]},"Validate UUID Format":{"main":[[{"node":"Check UUID Valid","type":"main","index":0}]]},"Check UUID Valid":{"main":[[{"node":"Query Specific Message","type":"main","index":0},{"node":"Return Invalid UUID","type":"main","index":0}]]}},"settings":{"saveManualExecutions":true,"saveDataErrorExecution":"all","saveDataSuccessExecution":"all","errorWorkflow":"","executionOrder":"v1"},"staticData":null,"meta":null,"pinData":{},"versionId":"a00afb45-9926-4b08-86d4-d1ac8dcc3bc0","triggerCount":1,"shared":[{"createdAt":"2025-10-23T22:18:56.436Z","updatedAt":"2025-10-23T22:18:56.436Z","role":"workflow:owner","workflowId":"QMHZ5IAhBvRgyZAc","projectId":"sVGwG1Ss6aXKNorC","project":{"createdAt":"2025-07-30T12:18:11.485Z","updatedAt":"2025-07-30T12:20:06.951Z","id":"sVGwG1Ss6aXKNorC","name":"Rafał Dębski <rdebski90@gmail.com>","type":"personal","icon":null,"description":null,"projectRelations":[{"createdAt":"2025-07-30T12:18:11.486Z","updatedAt":"2025-07-30T12:18:11.486Z","userId":"512c6fc4-ef1e-46ec-99da-b435fcbf2339","projectId":"sVGwG1Ss6aXKNorC","user":{"createdAt":"2025-07-30T12:18:10.851Z","updatedAt":"2025-10-23T22:43:16.000Z","id":"512c6fc4-ef1e-46ec-99da-b435fcbf2339","email":"rdebski90@gmail.com","firstName":"Rafał","lastName":"Dębski","personalizationAnswers":{"version":"v4","personalization_survey_submitted_at":"2025-07-30T12:20:09.619Z","personalization_survey_n8n_version":"1.104.1"},"settings":{"userActivated":true,"easyAIWorkflowOnboarded":true,"firstSuccessfulWorkflowId":"gp796pP6j8IFZodb","userActivatedAt":1753881412699,"npsSurvey":{"responded":true,"lastShownAt":1755785806897},"dismissedCallouts":{"ragStarterCallout":true}},"disabled":false,"mfaEnabled":false,"lastActiveAt":"2025-10-23","isPending":false}}]}}],"tags":[]}

operations:
  [{"type":"removeConnection","source":"check-uuid-valid","target":"query-specific-message"},{"type":"removeConnection","source":"check-uuid-valid","target":"return-invalid-uuid"},{"type":"addConnection","source":"check-uuid-valid","target":"query-specific-message"},{"type":"addConnection","source":"check-uuid-valid","target":"return-invalid-uuid"}]


workflow_id: QMHZ5IAhBvRgyZAc
workflow_name: POST /chat/generate-pdf
trigger: partial_update
created_at: 2025-10-24 14:25:52
workflow_snapshot:
  {"createdAt":"2025-10-23T22:18:56.433Z","updatedAt":"2025-10-24T14:25:23.457Z","id":"QMHZ5IAhBvRgyZAc","name":"POST /chat/generate-pdf","active":true,"isArchived":false,"nodes":[{"parameters":{"httpMethod":"POST","path":"chat/generate-pdf","responseMode":"responseNode","options":{}},"id":"webhook-trigger","name":"POST /chat/generate-pdf","type":"n8n-nodes-base.webhook","typeVersion":2.1,"position":[240,312],"webhookId":"67403d18-ee13-4ad3-b9b7-02d012aeaf0e","onError":"continueRegularOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"message-id-condition","leftValue":"={{ $('POST /chat/generate-pdf').first().json.body.message_id }}","rightValue":"","operator":{"type":"string","operation":"notEmpty"}}],"combinator":"and"},"options":{}},"id":"check-message-id","name":"Check Message ID","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[912,400],"onError":"continueErrorOutput"},{"parameters":{"url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/rest/v1/conversation_messages?select=id,message,created_at,conversation_threads!inner(user_id)&id=eq.' + $('POST /chat/generate-pdf').first().json.body.message_id + '&conversation_threads.user_id=eq.' + $('JWT Validation').first().json.user_id }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"Prefer","value":"return=representation"}]},"options":{"response":{"response":{"responseFormat":"json"}}}},"id":"query-specific-message","name":"Query Specific Message","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1136,320],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/rest/v1/conversation_messages?select=id,message,created_at,conversation_threads!inner(user_id)&conversation_threads.user_id=eq.' + $('JWT Validation').first().json.user_id + '&order=created_at.desc&limit=1' }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"Prefer","value":"return=representation"}]},"options":{"response":{"response":{"responseFormat":"json"}}}},"id":"query-latest-message","name":"Query Latest Message","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1136,512],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"message-exists-condition","leftValue":"={{ $json.id }}","rightValue":"0","operator":{"type":"string","operation":"notEmpty"}}],"combinator":"and"},"options":{}},"id":"check-message-exists","name":"Check Message Exists","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1360,400],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'Not Found', message: 'Message not found or you do not have access to it' }) }}","options":{"responseCode":404}},"id":"return-not-found","name":"Return Not Found","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1584,320]},{"parameters":{"jsCode":"// Get message data from previous node\nconst messageData = $input.first().json;\n\n// Get user ID from JWT Validation\nconst userId = $('JWT Validation').first().json.user_id;\n\n// Extract content from JSONB structure\nconst content = messageData.message.content;\n\n// Format date in Polish\nconst date = new Date(messageData.created_at);\nconst formattedDate = date.toLocaleDateString('pl-PL', {\n  year: 'numeric',\n  month: 'long',\n  day: 'numeric',\n  hour: '2-digit',\n  minute: '2-digit'\n});\n\n// Create HTML for PDF with WOO branding\nconst html = `<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <style>\n    body {\n      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n      line-height: 1.6;\n      color: #333;\n      padding: 40px;\n      max-width: 800px;\n      margin: 0 auto;\n    }\n    .header {\n      display: flex;\n      justify-content: space-between;\n      align-items: center;\n      margin-bottom: 40px;\n      padding-bottom: 20px;\n      border-bottom: 3px solid #4b0082;\n    }\n    .logo {\n      width: 120px;\n      height: 120px;\n    }\n    .title {\n      color: #4b0082;\n      font-size: 24px;\n      font-weight: 600;\n    }\n    .date {\n      color: #666;\n      font-size: 14px;\n      margin-bottom: 20px;\n    }\n    .content {\n      background: #f9f9f9;\n      padding: 30px;\n      border-radius: 8px;\n      border-left: 4px solid #4b0082;\n    }\n    .footer {\n      margin-top: 40px;\n      padding-top: 20px;\n      border-top: 1px solid #ddd;\n      text-align: center;\n      color: #888;\n      font-size: 12px;\n    }\n  </style>\n</head>\n<body>\n  <div class=\"header\">\n    <div class=\"title\">WOO PRO - Wiadomość</div>\n    <img src=\"https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/public/public_files/logo-email.png\" \n         class=\"logo\" alt=\"WOO Logo\">\n  </div>\n  \n  <div class=\"date\">${formattedDate}</div>\n  \n  <div class=\"content\">\n    ${content.replace(/\\n/g, '<br>')}\n  </div>\n  \n  <div class=\"footer\">\n    Wygenerowano przez WOO PRO<br>\n    Ten dokument jest poufny i przeznaczony wyłącznie dla odbiorcy.\n  </div>\n</body>\n</html>`;\n\nreturn [{\n  json: {\n    html: html,\n    fileName: `${userId}/woo-message-${messageData.id}.pdf`,\n    messageId: messageData.id\n  }\n}];"},"id":"prepare-html-template","name":"Prepare HTML Template","type":"n8n-nodes-base.code","typeVersion":2,"position":[1584,512]},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"pdf-success-condition","leftValue":"={{ $json.error }}","rightValue":"false","operator":{"type":"boolean","operation":"false","singleValue":true}}],"combinator":"and"},"options":{}},"id":"check-pdf-success","name":"Check PDF Success","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2032,496],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'PDF Generation Failed', message: $json.message || 'Failed to generate PDF document' }) }}","options":{"responseCode":500}},"id":"return-pdf-error","name":"Return PDF Error","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[2256,416]},{"parameters":{"method":"POST","url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/generated_pdfs/' + $('Prepare HTML Template').first().json.fileName }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Content-Type","value":"application/pdf"}]},"sendBody":true,"contentType":"binaryData","inputDataFieldName":"data","options":{"response":{"response":{"responseFormat":"json"}}}},"id":"upload-pdf-to-storage","name":"Upload PDF to Storage","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2480,608],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"method":"POST","url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/sign/generated_pdfs/' + $('Prepare HTML Template').first().json.fileName }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Content-Type","value":"application/json"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ { expiresIn: 86400 } }}","options":{"response":{"response":{"responseFormat":"json"}}}},"id":"generate-signed-url","name":"Generate Signed URL","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2704,608],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"jsCode":"const signedUrl = $input.first().json.signedURL;\nconst fileName = $('Prepare HTML Template').first().json.fileName;\nconst messageId = $('Prepare HTML Template').first().json.messageId;\n\nreturn [{\n  json: {\n    success: true,\n    message: 'PDF generated successfully',\n    data: {\n      pdfUrl: `https://xxciwnthnnywanbplqwg.supabase.co/storage/v1${signedUrl}`,\n      fileName: fileName,\n      messageId: messageId,\n      expiresIn: '24 hours'\n    }\n  }\n}];"},"id":"format-success-response","name":"Format Success Response","type":"n8n-nodes-base.code","typeVersion":2,"position":[2928,608]},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify($json) }}","options":{"responseCode":200}},"id":"return-success","name":"Return Success","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[3152,608]},{"parameters":{"method":"POST","url":"https://api.pdf.co/v1/pdf/convert/from/html","sendHeaders":true,"headerParameters":{"parameters":[{"name":"x-api-key","value":"reeunlockyourskills@gmail.com_SQcbrlvobSplxYtx2Ed8h2toSbsqenyPfWqLkjpvjc5uj68FXk78S3DNibeAw3v0"},{"name":"Content-Type","value":"application/json"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ { \"html\": $json.html, \"name\": $json.fileName } }}","options":{"response":{"response":{"responseFormat":"json"}}}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1808,512],"id":"f2e54550-eb45-4363-930d-c2908ca394ac","name":"call_generate_pdf"},{"parameters":{"url":"={{ $json.url }}","options":{"response":{"response":{"responseFormat":"file"}}}},"id":"download-pdf-from-url","name":"Download PDF from URL","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2256,608]},{"parameters":{"workflowId":{"__rl":true,"value":"dL4gKHrO0Mtdhpmo","mode":"list","cachedResultUrl":"/workflow/dL4gKHrO0Mtdhpmo","cachedResultName":"JWT Validation Middleware"},"workflowInputs":{"mappingMode":"defineBelow","value":{"headers":"={{ $json.headers }}","body":"={{ $json.body }}"},"matchingColumns":[],"schema":[{"id":"headers","displayName":"headers","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true,"type":"object"},{"id":"body","displayName":"body","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true},{"id":"params","displayName":"params","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true,"type":"object","removed":true}],"attemptToConvertTypes":false,"convertFieldsToString":true},"options":{}},"id":"97fea410-3161-474d-a49e-2dc7804c98db","name":"JWT Validation","type":"n8n-nodes-base.executeWorkflow","typeVersion":1.3,"position":[464,320],"onError":"continueErrorOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"jwt_error_check","leftValue":"={{ $json.is_valid }}","rightValue":"={{ true }}","operator":{"type":"boolean","operation":"false","singleValue":true}}],"combinator":"and"},"options":{}},"id":"1705f618-2fa2-4d37-8ec5-5f117e4df232","name":"Check JWT Error","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[688,320],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ {\n  success: false,\n  data: null,\n  error: 'Unauthorized',\n  metadata: {\n    timestamp: new Date().toISOString()\n  }\n} }}","options":{"responseCode":401}},"id":"dee5bfdc-9a05-4494-80a9-6f36cbcb8d26","name":"JWT Error Response","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[912,192],"onError":"continueRegularOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ {\n  success: false,\n  error: {\n    code: 'UNAUTHORIZED',\n    message: 'Invalid or expired access token'\n  },\n  metadata: {\n    timestamp: new Date().toISOString()\n  }\n} }}","options":{"responseCode":401}},"id":"d0079bd8-15d8-42a8-8418-191fde6dd0f3","name":"Auth Error Response","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[688,512],"onError":"continueRegularOutput"},{"id":"validate-uuid-format","name":"Validate UUID Format","type":"n8n-nodes-base.code","typeVersion":2,"position":[1024,320],"parameters":{"jsCode":"const messageId = $('POST /chat/generate-pdf').first().json.body.message_id;\n\n// UUID v4 regex pattern\nconst uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\nconst isValid = uuidRegex.test(messageId);\n\nreturn [{\n  json: {\n    messageId: messageId,\n    isValidUUID: isValid\n  }\n}];"}},{"id":"check-uuid-valid","name":"Check UUID Valid","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1248,320],"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"uuid-valid-condition","leftValue":"={{ $json.isValidUUID }}","rightValue":"={{ true }}","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"options":{}},"onError":"continueErrorOutput"},{"id":"return-invalid-uuid","name":"Return Invalid UUID","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1472,240],"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ success: false, error: 'Invalid message_id format. Expected valid UUID.' }) }}","options":{"responseCode":400}}}],"connections":{"POST /chat/generate-pdf":{"main":[[{"node":"JWT Validation","type":"main","index":0}]]},"Query Specific Message":{"main":[[{"node":"Check Message Exists","type":"main","index":0}]]},"Query Latest Message":{"main":[[{"node":"Check Message Exists","type":"main","index":0}]]},"Upload PDF to Storage":{"main":[[{"node":"Generate Signed URL","type":"main","index":0}]]},"Generate Signed URL":{"main":[[{"node":"Format Success Response","type":"main","index":0}]]},"Format Success Response":{"main":[[{"node":"Return Success","type":"main","index":0}]]},"Check Message ID":{"main":[[{"node":"Validate UUID Format","type":"main","index":0}],[{"node":"Query Latest Message","type":"main","index":0}]]},"Check Message Exists":{"main":[[{"node":"Prepare HTML Template","type":"main","index":0}],[{"node":"Return Not Found","type":"main","index":0}]]},"Check PDF Success":{"main":[[{"node":"Download PDF from URL","type":"main","index":0}],[{"node":"Return PDF Error","type":"main","index":0}]]},"Prepare HTML Template":{"main":[[{"node":"call_generate_pdf","type":"main","index":0}]]},"call_generate_pdf":{"main":[[{"node":"Check PDF Success","type":"main","index":0}]]},"Download PDF from URL":{"main":[[{"node":"Upload PDF to Storage","type":"main","index":0}]]},"JWT Validation":{"main":[[{"node":"Check JWT Error","type":"main","index":0}],[{"node":"Auth Error Response","type":"main","index":0}]]},"Check JWT Error":{"main":[[{"node":"JWT Error Response","type":"main","index":0}],[{"node":"Check Message ID","type":"main","index":0}]]},"Validate UUID Format":{"main":[[{"node":"Check UUID Valid","type":"main","index":0}]]},"Check UUID Valid":{"main":[[{"node":"Query Specific Message","type":"main","index":0},{"node":"Return Invalid UUID","type":"main","index":0}]]}},"settings":{"saveManualExecutions":true,"saveDataErrorExecution":"all","saveDataSuccessExecution":"all","errorWorkflow":"","executionOrder":"v1"},"staticData":null,"meta":null,"pinData":{},"versionId":"11060d78-19bf-44f4-86ef-4ee63f801b96","triggerCount":1,"shared":[{"createdAt":"2025-10-23T22:18:56.436Z","updatedAt":"2025-10-23T22:18:56.436Z","role":"workflow:owner","workflowId":"QMHZ5IAhBvRgyZAc","projectId":"sVGwG1Ss6aXKNorC","project":{"createdAt":"2025-07-30T12:18:11.485Z","updatedAt":"2025-07-30T12:20:06.951Z","id":"sVGwG1Ss6aXKNorC","name":"Rafał Dębski <rdebski90@gmail.com>","type":"personal","icon":null,"description":null,"projectRelations":[{"createdAt":"2025-07-30T12:18:11.486Z","updatedAt":"2025-07-30T12:18:11.486Z","userId":"512c6fc4-ef1e-46ec-99da-b435fcbf2339","projectId":"sVGwG1Ss6aXKNorC","user":{"createdAt":"2025-07-30T12:18:10.851Z","updatedAt":"2025-10-23T22:43:16.000Z","id":"512c6fc4-ef1e-46ec-99da-b435fcbf2339","email":"rdebski90@gmail.com","firstName":"Rafał","lastName":"Dębski","personalizationAnswers":{"version":"v4","personalization_survey_submitted_at":"2025-07-30T12:20:09.619Z","personalization_survey_n8n_version":"1.104.1"},"settings":{"userActivated":true,"easyAIWorkflowOnboarded":true,"firstSuccessfulWorkflowId":"gp796pP6j8IFZodb","userActivatedAt":1753881412699,"npsSurvey":{"responded":true,"lastShownAt":1755785806897},"dismissedCallouts":{"ragStarterCallout":true}},"disabled":false,"mfaEnabled":false,"lastActiveAt":"2025-10-23","isPending":false}}]}}],"tags":[]}

operations:
  [{"type":"fixConnections","nodeId":"check-uuid-valid","connections":{"main":[[{"node":"Query Specific Message","type":"main","index":0}],[{"node":"Return Invalid UUID","type":"main","index":0}]]}}]


workflow_id: QMHZ5IAhBvRgyZAc
workflow_name: POST /chat/generate-pdf
trigger: partial_update
operations: [{"type":"updateNode","nodeId":"Check UUID Valid","updates":{}}]
created_at: 2025-10-24 14:26:35
workflow_snapshot:
  {"createdAt":"2025-10-23T22:18:56.433Z","updatedAt":"2025-10-24T14:26:04.559Z","id":"QMHZ5IAhBvRgyZAc","name":"POST /chat/generate-pdf","active":true,"isArchived":false,"nodes":[{"parameters":{"httpMethod":"POST","path":"chat/generate-pdf","responseMode":"responseNode","options":{}},"id":"webhook-trigger","name":"POST /chat/generate-pdf","type":"n8n-nodes-base.webhook","typeVersion":2.1,"position":[240,312],"webhookId":"67403d18-ee13-4ad3-b9b7-02d012aeaf0e","onError":"continueRegularOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"message-id-condition","leftValue":"={{ $('POST /chat/generate-pdf').first().json.body.message_id }}","rightValue":"","operator":{"type":"string","operation":"notEmpty"}}],"combinator":"and"},"options":{}},"id":"check-message-id","name":"Check Message ID","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[912,400],"onError":"continueErrorOutput"},{"parameters":{"url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/rest/v1/conversation_messages?select=id,message,created_at,conversation_threads!inner(user_id)&id=eq.' + $('POST /chat/generate-pdf').first().json.body.message_id + '&conversation_threads.user_id=eq.' + $('JWT Validation').first().json.user_id }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"Prefer","value":"return=representation"}]},"options":{"response":{"response":{"responseFormat":"json"}}}},"id":"query-specific-message","name":"Query Specific Message","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1136,320],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/rest/v1/conversation_messages?select=id,message,created_at,conversation_threads!inner(user_id)&conversation_threads.user_id=eq.' + $('JWT Validation').first().json.user_id + '&order=created_at.desc&limit=1' }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"Prefer","value":"return=representation"}]},"options":{"response":{"response":{"responseFormat":"json"}}}},"id":"query-latest-message","name":"Query Latest Message","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1136,512],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"message-exists-condition","leftValue":"={{ $json.id }}","rightValue":"0","operator":{"type":"string","operation":"notEmpty"}}],"combinator":"and"},"options":{}},"id":"check-message-exists","name":"Check Message Exists","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1360,400],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'Not Found', message: 'Message not found or you do not have access to it' }) }}","options":{"responseCode":404}},"id":"return-not-found","name":"Return Not Found","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1584,320]},{"parameters":{"jsCode":"// Get message data from previous node\nconst messageData = $input.first().json;\n\n// Get user ID from JWT Validation\nconst userId = $('JWT Validation').first().json.user_id;\n\n// Extract content from JSONB structure\nconst content = messageData.message.content;\n\n// Format date in Polish\nconst date = new Date(messageData.created_at);\nconst formattedDate = date.toLocaleDateString('pl-PL', {\n  year: 'numeric',\n  month: 'long',\n  day: 'numeric',\n  hour: '2-digit',\n  minute: '2-digit'\n});\n\n// Create HTML for PDF with WOO branding\nconst html = `<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <style>\n    body {\n      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n      line-height: 1.6;\n      color: #333;\n      padding: 40px;\n      max-width: 800px;\n      margin: 0 auto;\n    }\n    .header {\n      display: flex;\n      justify-content: space-between;\n      align-items: center;\n      margin-bottom: 40px;\n      padding-bottom: 20px;\n      border-bottom: 3px solid #4b0082;\n    }\n    .logo {\n      width: 120px;\n      height: 120px;\n    }\n    .title {\n      color: #4b0082;\n      font-size: 24px;\n      font-weight: 600;\n    }\n    .date {\n      color: #666;\n      font-size: 14px;\n      margin-bottom: 20px;\n    }\n    .content {\n      background: #f9f9f9;\n      padding: 30px;\n      border-radius: 8px;\n      border-left: 4px solid #4b0082;\n    }\n    .footer {\n      margin-top: 40px;\n      padding-top: 20px;\n      border-top: 1px solid #ddd;\n      text-align: center;\n      color: #888;\n      font-size: 12px;\n    }\n  </style>\n</head>\n<body>\n  <div class=\"header\">\n    <div class=\"title\">WOO PRO - Wiadomość</div>\n    <img src=\"https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/public/public_files/logo-email.png\" \n         class=\"logo\" alt=\"WOO Logo\">\n  </div>\n  \n  <div class=\"date\">${formattedDate}</div>\n  \n  <div class=\"content\">\n    ${content.replace(/\\n/g, '<br>')}\n  </div>\n  \n  <div class=\"footer\">\n    Wygenerowano przez WOO PRO<br>\n    Ten dokument jest poufny i przeznaczony wyłącznie dla odbiorcy.\n  </div>\n</body>\n</html>`;\n\nreturn [{\n  json: {\n    html: html,\n    fileName: `${userId}/woo-message-${messageData.id}.pdf`,\n    messageId: messageData.id\n  }\n}];"},"id":"prepare-html-template","name":"Prepare HTML Template","type":"n8n-nodes-base.code","typeVersion":2,"position":[1584,512]},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"pdf-success-condition","leftValue":"={{ $json.error }}","rightValue":"false","operator":{"type":"boolean","operation":"false","singleValue":true}}],"combinator":"and"},"options":{}},"id":"check-pdf-success","name":"Check PDF Success","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2032,496],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'PDF Generation Failed', message: $json.message || 'Failed to generate PDF document' }) }}","options":{"responseCode":500}},"id":"return-pdf-error","name":"Return PDF Error","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[2256,416]},{"parameters":{"method":"POST","url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/generated_pdfs/' + $('Prepare HTML Template').first().json.fileName }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Content-Type","value":"application/pdf"}]},"sendBody":true,"contentType":"binaryData","inputDataFieldName":"data","options":{"response":{"response":{"responseFormat":"json"}}}},"id":"upload-pdf-to-storage","name":"Upload PDF to Storage","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2480,608],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"method":"POST","url":"={{ 'https://xxciwnthnnywanbplqwg.supabase.co/storage/v1/object/sign/generated_pdfs/' + $('Prepare HTML Template').first().json.fileName }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ $('POST /chat/generate-pdf').first().json.headers.authorization }}"},{"name":"apikey","value":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh4Y2l3bnRobm55d2FuYnBscXdnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAzMzM0NjYsImV4cCI6MjA3NTkwOTQ2Nn0.gVvLw4aHwKG3TFhoQv6MwvoennmFVgmbLTOOpZLBQO8"},{"name":"Content-Type","value":"application/json"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ { expiresIn: 86400 } }}","options":{"response":{"response":{"responseFormat":"json"}}}},"id":"generate-signed-url","name":"Generate Signed URL","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2704,608],"alwaysOutputData":true,"onError":"continueRegularOutput"},{"parameters":{"jsCode":"const signedUrl = $input.first().json.signedURL;\nconst fileName = $('Prepare HTML Template').first().json.fileName;\nconst messageId = $('Prepare HTML Template').first().json.messageId;\n\nreturn [{\n  json: {\n    success: true,\n    message: 'PDF generated successfully',\n    data: {\n      pdfUrl: `https://xxciwnthnnywanbplqwg.supabase.co/storage/v1${signedUrl}`,\n      fileName: fileName,\n      messageId: messageId,\n      expiresIn: '24 hours'\n    }\n  }\n}];"},"id":"format-success-response","name":"Format Success Response","type":"n8n-nodes-base.code","typeVersion":2,"position":[2928,608]},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify($json) }}","options":{"responseCode":200}},"id":"return-success","name":"Return Success","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[3152,608]},{"parameters":{"method":"POST","url":"https://api.pdf.co/v1/pdf/convert/from/html","sendHeaders":true,"headerParameters":{"parameters":[{"name":"x-api-key","value":"reeunlockyourskills@gmail.com_SQcbrlvobSplxYtx2Ed8h2toSbsqenyPfWqLkjpvjc5uj68FXk78S3DNibeAw3v0"},{"name":"Content-Type","value":"application/json"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ { \"html\": $json.html, \"name\": $json.fileName } }}","options":{"response":{"response":{"responseFormat":"json"}}}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1808,512],"id":"f2e54550-eb45-4363-930d-c2908ca394ac","name":"call_generate_pdf"},{"parameters":{"url":"={{ $json.url }}","options":{"response":{"response":{"responseFormat":"file"}}}},"id":"download-pdf-from-url","name":"Download PDF from URL","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2256,608]},{"parameters":{"workflowId":{"__rl":true,"value":"dL4gKHrO0Mtdhpmo","mode":"list","cachedResultUrl":"/workflow/dL4gKHrO0Mtdhpmo","cachedResultName":"JWT Validation Middleware"},"workflowInputs":{"mappingMode":"defineBelow","value":{"headers":"={{ $json.headers }}","body":"={{ $json.body }}"},"matchingColumns":[],"schema":[{"id":"headers","displayName":"headers","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true,"type":"object"},{"id":"body","displayName":"body","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true},{"id":"params","displayName":"params","required":false,"defaultMatch":false,"display":true,"canBeUsedToMatch":true,"type":"object","removed":true}],"attemptToConvertTypes":false,"convertFieldsToString":true},"options":{}},"id":"97fea410-3161-474d-a49e-2dc7804c98db","name":"JWT Validation","type":"n8n-nodes-base.executeWorkflow","typeVersion":1.3,"position":[464,320],"onError":"continueErrorOutput"},{"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"jwt_error_check","leftValue":"={{ $json.is_valid }}","rightValue":"={{ true }}","operator":{"type":"boolean","operation":"false","singleValue":true}}],"combinator":"and"},"options":{}},"id":"1705f618-2fa2-4d37-8ec5-5f117e4df232","name":"Check JWT Error","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[688,320],"onError":"continueErrorOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ {\n  success: false,\n  data: null,\n  error: 'Unauthorized',\n  metadata: {\n    timestamp: new Date().toISOString()\n  }\n} }}","options":{"responseCode":401}},"id":"dee5bfdc-9a05-4494-80a9-6f36cbcb8d26","name":"JWT Error Response","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[912,192],"onError":"continueRegularOutput"},{"parameters":{"respondWith":"json","responseBody":"={{ {\n  success: false,\n  error: {\n    code: 'UNAUTHORIZED',\n    message: 'Invalid or expired access token'\n  },\n  metadata: {\n    timestamp: new Date().toISOString()\n  }\n} }}","options":{"responseCode":401}},"id":"d0079bd8-15d8-42a8-8418-191fde6dd0f3","name":"Auth Error Response","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[688,512],"onError":"continueRegularOutput"},{"id":"validate-uuid-format","name":"Validate UUID Format","type":"n8n-nodes-base.code","typeVersion":2,"position":[1024,320],"parameters":{"jsCode":"const messageId = $('POST /chat/generate-pdf').first().json.body.message_id;\n\n// UUID v4 regex pattern\nconst uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\nconst isValid = uuidRegex.test(messageId);\n\nreturn [{\n  json: {\n    messageId: messageId,\n    isValidUUID: isValid\n  }\n}];"}},{"id":"check-uuid-valid","name":"Check UUID Valid","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1248,320],"parameters":{"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"conditions":[{"id":"uuid-valid-condition","leftValue":"={{ $json.isValidUUID }}","rightValue":"={{ true }}","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"options":{}},"onError":"continueErrorOutput"},{"id":"return-invalid-uuid","name":"Return Invalid UUID","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1472,240],"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ success: false, error: 'Invalid message_id format. Expected valid UUID.' }) }}","options":{"responseCode":400}}}],"connections":{"POST /chat/generate-pdf":{"main":[[{"node":"JWT Validation","type":"main","index":0}]]},"Query Specific Message":{"main":[[{"node":"Check Message Exists","type":"main","index":0}]]},"Query Latest Message":{"main":[[{"node":"Check Message Exists","type":"main","index":0}]]},"Upload PDF to Storage":{"main":[[{"node":"Generate Signed URL","type":"main","index":0}]]},"Generate Signed URL":{"main":[[{"node":"Format Success Response","type":"main","index":0}]]},"Format Success Response":{"main":[[{"node":"Return Success","type":"main","index":0}]]},"Check Message ID":{"main":[[{"node":"Validate UUID Format","type":"main","index":0}],[{"node":"Query Latest Message","type":"main","index":0}]]},"Check Message Exists":{"main":[[{"node":"Prepare HTML Template","type":"main","index":0}],[{"node":"Return Not Found","type":"main","index":0}]]},"Check PDF Success":{"main":[[{"node":"Download PDF from URL","type":"main","index":0}],[{"node":"Return PDF Error","type":"main","index":0}]]},"Prepare HTML Template":{"main":[[{"node":"call_generate_pdf","type":"main","index":0}]]},"call_generate_pdf":{"main":[[{"node":"Check PDF Success","type":"main","index":0}]]},"Download PDF from URL":{"main":[[{"node":"Upload PDF to Storage","type":"main","index":0}]]},"JWT Validation":{"main":[[{"node":"Check JWT Error","type":"main","index":0}],[{"node":"Auth Error Response","type":"main","index":0}]]},"Check JWT Error":{"main":[[{"node":"JWT Error Response","type":"main","index":0}],[{"node":"Check Message ID","type":"main","index":0}]]},"Validate UUID Format":{"main":[[{"node":"Check UUID Valid","type":"main","index":0}]]},"Check UUID Valid":{"main":[[{"node":"Query Specific Message","type":"main","index":0},{"node":"Return Invalid UUID","type":"main","index":0}]]}},"settings":{"saveManualExecutions":true,"saveDataErrorExecution":"all","saveDataSuccessExecution":"all","errorWorkflow":"","executionOrder":"v1"},"staticData":null,"meta":null,"pinData":{},"versionId":"c69f6fb1-a84c-4a82-8729-b8508cd5cdb6","triggerCount":1,"shared":[{"createdAt":"2025-10-23T22:18:56.436Z","updatedAt":"2025-10-23T22:18:56.436Z","role":"workflow:owner","workflowId":"QMHZ5IAhBvRgyZAc","projectId":"sVGwG1Ss6aXKNorC","project":{"createdAt":"2025-07-30T12:18:11.485Z","updatedAt":"2025-07-30T12:20:06.951Z","id":"sVGwG1Ss6aXKNorC","name":"Rafał Dębski <rdebski90@gmail.com>","type":"personal","icon":null,"description":null,"projectRelations":[{"createdAt":"2025-07-30T12:18:11.486Z","updatedAt":"2025-07-30T12:18:11.486Z","userId":"512c6fc4-ef1e-46ec-99da-b435fcbf2339","projectId":"sVGwG1Ss6aXKNorC","user":{"createdAt":"2025-07-30T12:18:10.851Z","updatedAt":"2025-10-23T22:43:16.000Z","id":"512c6fc4-ef1e-46ec-99da-b435fcbf2339","email":"rdebski90@gmail.com","firstName":"Rafał","lastName":"Dębski","personalizationAnswers":{"version":"v4","personalization_survey_submitted_at":"2025-07-30T12:20:09.619Z","personalization_survey_n8n_version":"1.104.1"},"settings":{"userActivated":true,"easyAIWorkflowOnboarded":true,"firstSuccessfulWorkflowId":"gp796pP6j8IFZodb","userActivatedAt":1753881412699,"npsSurvey":{"responded":true,"lastShownAt":1755785806897},"dismissedCallouts":{"ragStarterCallout":true}},"disabled":false,"mfaEnabled":false,"lastActiveAt":"2025-10-23","isPending":false}}]}}],"tags":[]}


