{
  "name": "Safock template: Website lead to Google Sheets and WhatsApp alert",
  "nodes": [
    {
      "parameters": {
        "content": "## Website lead to Sheets and WhatsApp\nBy Safock (safock.com). Free to use and adapt.\n\n1. Point your website form at this webhook (POST JSON with name, email, company, message).\n2. Google Sheets: connect your account, replace REPLACE_WITH_SHEET_ID and keep a tab named **Leads** with columns name, email, company, message, source, received_at.\n3. WhatsApp: create a Header Auth credential with `Authorization: Bearer <permanent token>`, then replace REPLACE_WITH_PHONE_NUMBER_ID and REPLACE_WITH_SALES_NUMBER (international format, digits only).\n\nFree-form WhatsApp text only delivers inside the 24-hour window. For alerts outside it, switch the body to an approved utility template.",
        "height": 360,
        "width": 460
      },
      "id": "70f1f68d-08cf-424e-8ee2-c61db717de67",
      "name": "Setup notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -500,
        -140
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "new-lead",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "e517d1ad-aaa1-4089-b399-f9902d94f297",
      "name": "New lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "6e5c8728-8bdd-4e5e-bad3-333a37cff004"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a840cd4d-e022-4800-b284-da514c91f622",
              "name": "name",
              "value": "={{ ($json.body.name || '').trim() }}",
              "type": "string"
            },
            {
              "id": "d138e6ff-d0e6-45b0-b492-e69c2268a9b1",
              "name": "email",
              "value": "={{ ($json.body.email || '').trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "d062baf9-ed74-443b-9b9d-e64e40baf445",
              "name": "company",
              "value": "={{ ($json.body.company || '').trim() }}",
              "type": "string"
            },
            {
              "id": "a239b882-96c3-445e-a678-91d3d0511452",
              "name": "message",
              "value": "={{ ($json.body.message || '').trim() }}",
              "type": "string"
            },
            {
              "id": "75b4fb7a-e7a5-4fa0-a3de-f70253c0059d",
              "name": "source",
              "value": "={{ $json.body.source || 'website' }}",
              "type": "string"
            },
            {
              "id": "0c1b7866-07d2-4331-97c6-5a8ec4a6c53d",
              "name": "received_at",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "16eb474c-e194-4c51-bb57-17abdd796411",
      "name": "Clean up fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c9e16ec9-08a0-404e-a23f-5b84af9c0592",
              "leftValue": "={{ /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/.test($json.email) }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e13d1db2-f407-4776-856d-f75d68d8425b",
      "name": "Valid email?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Leads",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "ad195a2d-84eb-4902-b831-2e2a90a790d6",
      "name": "Add to Leads sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        660,
        -100
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v21.0/REPLACE_WITH_PHONE_NUMBER_ID/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ messaging_product: 'whatsapp', to: 'REPLACE_WITH_SALES_NUMBER', type: 'text', text: { body: 'New lead: ' + $('Clean up fields').item.json.name + ' (' + $('Clean up fields').item.json.company + ')\\n' + $('Clean up fields').item.json.email + '\\n\\n' + $('Clean up fields').item.json.message.slice(0, 600) } }) }}",
        "options": {}
      },
      "id": "a3148b8f-fac4-4fd6-818d-a7570c32531e",
      "name": "WhatsApp alert to sales",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        -100
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"ok\": true }",
        "options": {}
      },
      "id": "0ec1b5de-5a62-45c3-9be4-257e369829f4",
      "name": "Reply OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1100,
        -100
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"ok\": false, \"error\": \"A valid email is required.\" }",
        "options": {
          "responseCode": 422
        }
      },
      "id": "cbc53182-a239-4e24-a0f9-c04286f59025",
      "name": "Reply invalid",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        660,
        120
      ]
    }
  ],
  "connections": {
    "New lead": {
      "main": [
        [
          {
            "node": "Clean up fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean up fields": {
      "main": [
        [
          {
            "node": "Valid email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Valid email?": {
      "main": [
        [
          {
            "node": "Add to Leads sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply invalid",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to Leads sheet": {
      "main": [
        [
          {
            "node": "WhatsApp alert to sales",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp alert to sales": {
      "main": [
        [
          {
            "node": "Reply OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
