{
  "name": "Customer quotes in, personal data kept apart",
  "nodes": [
    {
      "id": "15ffa9ea-c1ff-49cd-ad9b-ee4346e22006",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -688,
        -160
      ],
      "parameters": {
        "content": "## Customer quotes in, personal data kept apart\nA customer quote sent to a webhook is split in two: the words go to your content sheet only with consent, and the name and email go to a private consent log.\n\n### You need\n- A Google Sheets login and 2 sheets:\n- Content Briefs: Intake ID, Received At, Campaign ID, Quote, Segment, Consent, Source\n- Consent Log, in a private sheet only you can open: Intake ID, Received At, Name, Email, Consent, Consent Text\n- A tool that can send JSON to a webhook: campaignId, quote, customerName, customerEmail, consent, segment\n- A Telegram bot and your chat ID, for the failure alert\n\n### Set it up\n1. Pick your content sheet in **Save the clean brief** and your private sheet in **Save the consent record**.\n2. Turn the workflow on and copy the Production URL from **Quote comes in**.\n3. Point your form or CRM at that URL with POST.\n4. Failure alert: put your chat ID in **Write the failure alert** and your bot in **Send the failure alert**. Then in Workflow settings, set Error workflow to this workflow.\n\n### Test it\n- Send a test with consent set to yes, then one with consent set to no.\n- With yes, the quote shows in Content Briefs. With no, the row has no quote. Emails and phone numbers inside a quote are removed.",
        "height": 884,
        "width": 560,
        "color": 4
      }
    },
    {
      "id": "cf861cfc-639e-464f-bde2-a5f3b2db6d11",
      "name": "Note: split",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -48,
        -120
      ],
      "parameters": {
        "content": "## Split it\nEmails and phone numbers inside the quote are removed. The quote is kept only when the person said yes.",
        "height": 560,
        "width": 760,
        "color": 7
      }
    },
    {
      "id": "e6ee33ba-d48c-4f36-b98a-60fe5fa83cd4",
      "name": "Note: store",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        792,
        -160
      ],
      "parameters": {
        "content": "## Store it apart\nThe content sheet never holds a name or an email. Keep the consent log in a sheet your content team cannot open.",
        "height": 960,
        "width": 1000,
        "color": 7
      }
    },
    {
      "id": "04b18758-46e2-4bea-8b9d-a2ecc435e540",
      "name": "Quote comes in",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        100
      ],
      "parameters": {
        "path": "campaign-intake",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "webhookId": "73289ca8-d0aa-4f02-97e0-165cb6c31dff"
    },
    {
      "id": "85a91a64-dae9-4fca-9cda-dd84fab3d9ba",
      "name": "Split off personal data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        100
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const b = $input.first().json.body || {};\nconst text = v => String(v ?? '').trim();\nconst scrub = t => t\n  .replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}/g, '[email removed]')\n  .replace(/\\+?\\d[\\d\\s().-]{7,}\\d/g, '[phone removed]');\nconst consent = b.consent === true || /^(yes|true|y|1)$/i.test(text(b.consent));\nconst campaignId = text(b.campaignId || b.campaign);\nconst quote = scrub(text(b.quote || b.text));\nconst problem = !campaignId ? 'campaignId is missing.' : !quote ? 'quote is missing.' : '';\nreturn [{ json: {\n  valid: !problem, problem, receivedAt: $now.toISO(),\n  intakeId: 'intake-' + $now.toFormat('yyyyLLddHHmmss') + '-' + Math.random().toString(36).slice(2, 6),\n  clean: { campaignId, quote: consent ? quote : '', segment: text(b.segment), consent, source: text(b.source) || 'webhook' },\n  personal: { name: text(b.customerName || b.name), email: text(b.customerEmail || b.email), consent, consentText: text(b.consentText) },\n} }];"
      }
    },
    {
      "id": "4607ae34-4211-493f-9e5f-e3416c9f4db8",
      "name": "Good request?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        480,
        100
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.valid === true }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "a4b1fb4d-3f3d-466c-ae6a-ca20d4450fa5",
      "name": "Save the clean brief",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        840,
        0
      ],
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Content Briefs",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Intake ID": "={{ $json.intakeId }}",
            "Received At": "={{ $json.receivedAt }}",
            "Campaign ID": "={{ $json.clean.campaignId }}",
            "Quote": "={{ $json.clean.quote }}",
            "Segment": "={{ $json.clean.segment }}",
            "Consent": "={{ $json.clean.consent ? 'Yes' : 'No' }}",
            "Source": "={{ $json.clean.source }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Intake ID",
              "displayName": "Intake ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Received At",
              "displayName": "Received At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Campaign ID",
              "displayName": "Campaign ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Quote",
              "displayName": "Quote",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Segment",
              "displayName": "Segment",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Consent",
              "displayName": "Consent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Source",
              "displayName": "Source",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "4440f8a7-4b13-4ce4-9114-74e2de64175f",
      "name": "Save the consent record",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1080,
        0
      ],
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Consent Log",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Intake ID": "={{ $('Split off personal data').item.json.intakeId }}",
            "Received At": "={{ $('Split off personal data').item.json.receivedAt }}",
            "Name": "={{ $('Split off personal data').item.json.personal.name }}",
            "Email": "={{ $('Split off personal data').item.json.personal.email }}",
            "Consent": "={{ $('Split off personal data').item.json.personal.consent ? 'Yes' : 'No' }}",
            "Consent Text": "={{ $('Split off personal data').item.json.personal.consentText }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Intake ID",
              "displayName": "Intake ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Received At",
              "displayName": "Received At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Consent",
              "displayName": "Consent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Consent Text",
              "displayName": "Consent Text",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "657162c2-e94d-45bb-b64d-307be5e568dc",
      "name": "Answer OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1320,
        0
      ],
      "parameters": {
        "options": {
          "responseCode": 200,
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        },
        "respondWith": "json",
        "responseBody": "={{ { ok: true, intakeId: $('Split off personal data').item.json.intakeId } }}"
      }
    },
    {
      "id": "bdb5ba1a-7863-4931-8948-9c0a59497db9",
      "name": "Answer the problem",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        840,
        240
      ],
      "parameters": {
        "options": {
          "responseCode": 400,
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        },
        "respondWith": "json",
        "responseBody": "={{ { ok: false, problem: $json.problem } }}"
      }
    },
    {
      "id": "85f77cb3-1bb9-47b7-935f-86af85a19e1a",
      "name": "When this workflow fails",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -648,
        804
      ],
      "parameters": {}
    },
    {
      "id": "61c0b026-0caf-4fef-9da4-4bcdb6dfab61",
      "name": "Write the failure alert",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -428,
        804
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_TELEGRAM_CHAT_ID"
            },
            {
              "id": "f2",
              "name": "message",
              "type": "string",
              "value": "={{ 'A workflow stopped.\\n\\nWorkflow: ' + (($json.workflow || {}).name || 'unknown') + '\\nFailed step: ' + (($json.execution || {}).lastNodeExecuted || 'unknown') + '\\nWhy: ' + String((($json.execution || {}).error || {}).message || 'n8n did not give a reason.').slice(0, 300) + (($json.execution || {}).url ? '\\nOpen the run: ' + $json.execution.url : '') }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "c1354cf7-c2d1-471c-9c1e-2e631afa10f0",
      "name": "Send the failure alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -208,
        804
      ],
      "parameters": {
        "chatId": "={{ $json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "Quote comes in": {
      "main": [
        [
          {
            "node": "Split off personal data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split off personal data": {
      "main": [
        [
          {
            "node": "Good request?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Good request?": {
      "main": [
        [
          {
            "node": "Save the clean brief",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Answer the problem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save the clean brief": {
      "main": [
        [
          {
            "node": "Save the consent record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save the consent record": {
      "main": [
        [
          {
            "node": "Answer OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When this workflow fails": {
      "main": [
        [
          {
            "node": "Write the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the failure alert": {
      "main": [
        [
          {
            "node": "Send the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
