{
  "id": "1Eoh3Dsd2darAIZd",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Consent Request Banner + Preference Center Automation",
  "tags": [],
  "nodes": [
    {
      "id": "99a66271-125c-4d38-9c5f-0cfcbf600f24",
      "name": "Overview Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        1456
      ],
      "parameters": {
        "width": 420,
        "height": 496,
        "content": "## \ud83d\udcdd Consent Request Banner + Preference Center Automation\n\n### How it works\nThis workflow captures user consent submissions via webhook, stores records in Google Sheets, and sends personalized confirmation emails using AI. When a user submits their consent preferences, the workflow logs their data, generates a professional HTML thank-you email with Azure OpenAI, and notifies your team via Slack.\n\n### Setup steps\n1. Connect **Google Sheets OAuth2** for data storage\n2. Configure **Azure OpenAI** credentials for email generation\n3. Set up **SMTP** credentials for sending emails\n4. Connect **Slack API** for team notifications\n5. Replace placeholder email addresses and Slack channel\n6. Activate workflow and integrate webhook URL into your consent form"
      },
      "typeVersion": 1
    },
    {
      "id": "9954700f-022c-47a9-9d1c-a46e00fc2d82",
      "name": "Trigger Section Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        1296
      ],
      "parameters": {
        "color": 2,
        "width": 388,
        "height": 672,
        "content": "## \ud83d\udce5 Webhook & Data Preparation\nReceives consent form submissions via POST request and extracts name, email, version, and timestamp into structured fields ready for storage."
      },
      "typeVersion": 1
    },
    {
      "id": "18fed63f-6a2b-4250-ad29-2ba54c465efe",
      "name": "Storage Section Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        448,
        1296
      ],
      "parameters": {
        "color": 2,
        "width": 260,
        "height": 668,
        "content": "## \ud83d\udcbe Google Sheets Storage\nAppends or updates consent records in a centralized Google Sheet for compliance tracking and audit purposes."
      },
      "typeVersion": 1
    },
    {
      "id": "bab6f552-3e88-4597-ac40-9133a140e169",
      "name": "AI Section Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        1296
      ],
      "parameters": {
        "color": 2,
        "width": 276,
        "height": 668,
        "content": "## \ud83e\udd16 AI Email Generation\nUses Azure OpenAI to create personalized HTML confirmation emails that thank users and reassure them about data security."
      },
      "typeVersion": 1
    },
    {
      "id": "09bf0f37-3354-43d2-bca4-d935f2e22028",
      "name": "Notifications Section Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1104,
        1296
      ],
      "parameters": {
        "color": 2,
        "width": 628,
        "height": 672,
        "content": "## \ud83d\udce7 Email & Slack Delivery\nSends the AI-generated confirmation email to the user and posts a formatted notification to your team's Slack channel for immediate visibility."
      },
      "typeVersion": 1
    },
    {
      "id": "3f7558cf-e705-4f9f-bdf3-648e04622de7",
      "name": "Security Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        1216
      ],
      "parameters": {
        "color": 3,
        "width": 300,
        "height": 184,
        "content": "## \ud83d\udd10 Credentials & Security\nUse OAuth2 for Google Sheets, API keys for Azure OpenAI and Slack. Configure SMTP for email delivery. Remove all personal identifiers before sharing this template."
      },
      "typeVersion": 1
    },
    {
      "id": "91bac74a-a1f3-4931-9caf-0e2cb93ee828",
      "name": "Receive Consent Form",
      "type": "n8n-nodes-base.webhook",
      "position": [
        48,
        1504
      ],
      "parameters": {
        "path": "88662151-4279-4a8e-903f-616e18310dc9",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "ef52d87a-9db6-46e2-a43e-e4604a9800dd",
      "name": "Store Consent Record",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        496,
        1504
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "version",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "version",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RjDYyDJoaGS0HuUqUGEqz94rRo-7TpTgEVkw30Hsdy0/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1RjDYyDJoaGS0HuUqUGEqz94rRo-7TpTgEVkw30Hsdy0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RjDYyDJoaGS0HuUqUGEqz94rRo-7TpTgEVkw30Hsdy0/edit?usp=drivesdk",
          "cachedResultName": "Consent Sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "bc18b374-662f-405d-b65a-418cfc3f5dd4",
      "name": "Generate Thank You Email",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        720,
        1504
      ],
      "parameters": {
        "text": "=You are given the following user data:\n\n[\n  {\n    \"name\": \"{{ $json.name }}\",\n    \"email\": \"{{ $json.email }}\",\n    \"version\": \"{{ $json.version }}\",\n    \"timestamp\": \"{{ $json.timestamp }}\"\n  }\n]\n\n\nUsing this data, generate a full HTML email saying:\n\nThank you for submitting the query\n\nTheir data (name, email, version) has been received\n\nWe will keep their data safe and secure\n\nA follow-up team member will get in touch soon\n\nOutput only the HTML code for the email.\n",
        "options": {
          "systemMessage": "You are an AI email-generation assistant.\nYour job is to take user-provided JSON input and generate a clean, responsive HTML email.\n\nRules you must follow:\n\nThe email must be fully HTML formatted (inline CSS allowed).\n\nThe tone should be professional, polite, and reassuring.\n\nInsert all dynamic data (name, email, version, timestamp) wherever appropriate.\n\nDo not hallucinate extra fields.\n\nOnly output HTML. No markdown, no explanations.\n\nKeep the email short, clear, and user-friendly.\n\nConfirm that the user's data will be kept safe and used only for their intended purpose.\n\nUse <p>, <div>, <table>, <strong> etc. for structure\u2014avoid external CSS."
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "99666648-fee1-46bc-ae3d-2e35b8c01b6a",
      "name": "Send Confirmation Email",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1296,
        1408
      ],
      "parameters": {
        "html": "={{ $json.html_body }}",
        "options": {},
        "subject": "={{ $json.subject }}",
        "toEmail": "={{ $('Store Consent Record').item.json.email }}",
        "fromEmail": "noreply@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "04e1e7ae-7579-4760-b8ad-ea072ecd8b09",
      "name": "Format Email Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1072,
        1504
      ],
      "parameters": {
        "jsCode": "// Input example:\n// [\n//   {\n//     \"output\": \"<div>....HTML....</div>\"\n//   }\n// ]\n\n// 1. Get HTML from previous node\nconst html = items[0].json.output;\n\n// 2. Define subject (you can change this anytime)\nconst subject = \"Thank You for Your Submission\";\n\n// 3. Return separated fields\nreturn [\n  {\n    json: {\n      subject,\n      html_body: html\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "c5d695d3-a9c5-490d-b0df-e47a17239622",
      "name": "Notify Team on Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1520,
        1600
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09GNB90TED",
          "cachedResultName": "general-information"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "856d21fb-24c3-4f8d-a4fc-f625480d9e2f",
      "name": "Format Slack Message",
      "type": "n8n-nodes-base.code",
      "position": [
        1296,
        1600
      ],
      "parameters": {
        "jsCode": "// Get the HTML email body\nconst html = items[0].json.html_body;\n\n// Helper function to strip HTML tags\nfunction stripHtml(html) {\n  return html\n    .replace(/<br\\s*\\/?>/gi, \"\\n\")\n    .replace(/<\\/p>/gi, \"\\n\")\n    .replace(/<\\/div>/gi, \"\\n\")\n    .replace(/<\\/tr>/gi, \"\\n\")\n    .replace(/<[^>]*>/g, \"\")\n    .replace(/\\n\\s*\\n/g, \"\\n\")\n    .trim();\n}\n\nconst text = stripHtml(html);\n\n// Extract fields using regex\nconst nameMatch = text.match(/Name:\\s*(.*)/);\nconst emailMatch = text.match(/Email:\\s*(.*)/);\nconst versionMatch = text.match(/Version:\\s*(.*)/);\n\n// Fallback if not found\nconst name = nameMatch ? nameMatch[1].trim() : \"Not Available\";\nconst email = emailMatch ? emailMatch[1].trim() : \"Not Available\";\nconst version = versionMatch ? versionMatch[1].trim() : \"Not Available\";\n\n// Create Slack formatted message\nconst slackMessage = `\n*New Form Submission Received* \ud83c\udf89\n\n*Name:* ${name}\n*Email:* ${email}\n*Version:* ${version}\n\nThe user has submitted the consent form query and their data has been safely recorded.\n`;\n\nreturn [\n  {\n    json: {\n      text: slackMessage.trim()\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "660d56f9-0aa4-4d42-b954-8325bebbed60",
      "name": "Prepare Consent Record1",
      "type": "n8n-nodes-base.set",
      "position": [
        272,
        1504
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "name",
              "value": "={{ $json.body.name }}"
            },
            {
              "name": "email",
              "value": "={{ $json.body.email }}"
            },
            {
              "name": "version",
              "value": "={{ $json.body.version }}"
            },
            {
              "name": "timestamp",
              "value": "={{$now}}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "6e8d46b5-be5b-48a3-81a7-4e7bcef14129",
      "name": "Azure OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        800,
        1728
      ],
      "parameters": {
        "model": "gpt-4o-mini",
        "options": {}
      },
      "credentials": {
        "azureOpenAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6d4dd8ae-bc7d-492f-874f-efdc0aabacb9",
  "connections": {
    "Format Email Data": {
      "main": [
        [
          {
            "node": "Format Slack Message",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Confirmation Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Slack Message": {
      "main": [
        [
          {
            "node": "Notify Team on Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Consent Form": {
      "main": [
        [
          {
            "node": "Prepare Consent Record1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store Consent Record": {
      "main": [
        [
          {
            "node": "Generate Thank You Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Consent Record1": {
      "main": [
        [
          {
            "node": "Store Consent Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Azure OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Thank You Email",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Generate Thank You Email": {
      "main": [
        [
          {
            "node": "Format Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}