{
  "name": "Website lead → WhatsApp alert (OOP Solutions tutorial)",
  "nodes": [
    {
      "id": "note-tutorial",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -60
      ],
      "parameters": {
        "width": 560,
        "height": 220,
        "content": "## WhatsApp alert for every website lead\n1. **WhatsApp Alert** node: replace `YOUR_PHONE_NUMBER_ID` in the URL and `YOUR_WHATSAPP_NUMBER` in the body (country code, no +).\n2. Create a **Header Auth** credential: Name `Authorization`, Value `Bearer <your WhatsApp Cloud API token>`, and select it in the node.\n3. Click **Execute workflow**, POST a test lead to the Test URL, check your phone. Then **Publish** / **Activate** and point your form at the Production URL.\nTutorial: https://oopsolutions.com/blog/n8n-whatsapp-lead-alert"
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-capture",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "19431991-b65e-4d78-9fe6-4ae5415b59a9",
      "name": "Lead Form",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "ccd72cdb-8e1c-4cde-863f-4db89231ebbf"
    },
    {
      "parameters": {
        "jsCode": "\n// Accepts JSON or form posts. Field names are flexible (name/fullName, phone/whatsapp, ...).\nconst b = $input.first().json.body || {};\nconst pick = (...keys) => { for (const k of keys) if (b[k] != null && String(b[k]).trim()) return String(b[k]).trim(); return ''; };\nconst lead = {\n  leadId: 'L-' + Date.now().toString(36).toUpperCase(),\n  receivedAt: new Date().toISOString(),\n  name: pick('name', 'fullName', 'full_name'),\n  email: pick('email', 'Email').toLowerCase(),\n  phone: pick('phone', 'whatsapp', 'mobile'),\n  company: pick('company', 'business', 'organization'),\n  message: pick('message', 'details', 'notes').slice(0, 2000),\n  source: pick('source', 'utm_source') || 'website',\n  status: 'new',\n};\nconst emailOk = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(lead.email);\nconst errors = [];\nif (!lead.name) errors.push('name is required');\nif (!emailOk && !lead.phone) errors.push('a valid email or phone is required');\nreturn [{ json: { ...lead, valid: errors.length === 0, errors } }];\n"
      },
      "id": "a28ae11c-2aef-4d31-b6f8-4d1642003e2a",
      "name": "Clean & Validate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "09cdc626-c35b-4543-a1bd-06c92e7240f1",
              "leftValue": "={{ $json.valid }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "dc3fb0c1-1c3d-4bbe-84c6-644b03564521",
      "name": "Is Valid?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        480,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "\nreturn $input.all().map(i => { const { valid, errors, ...lead } = i.json; return { json: lead }; });\n"
      },
      "id": "a256a37c-3770-42e2-b06c-993e6af72a1c",
      "name": "Remove Helper Fields",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v21.0/YOUR_PHONE_NUMBER_ID/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ messaging_product: 'whatsapp', to: 'YOUR_WHATSAPP_NUMBER', type: 'text', text: { body: 'New lead: ' + $json.name + ' | ' + ($json.phone || $json.email) + ' | ' + ($json.message || '').slice(0, 300) } }) }}",
        "options": {}
      },
      "id": "b445f6ba-abd7-4643-a41b-925f132cf1c0",
      "name": "WhatsApp Alert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        200
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ ok: true, leadId: $('Remove Helper Fields').first().json.leadId }) }}",
        "options": {}
      },
      "id": "cabefa7c-6b99-41b0-84ec-e149b8f639e6",
      "name": "Respond OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1200,
        200
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ ok: false, errors: $json.errors }) }}",
        "options": {
          "responseCode": 400
        }
      },
      "id": "88fed87b-926e-4892-824d-015d6e85b366",
      "name": "Respond Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        720,
        420
      ]
    }
  ],
  "connections": {
    "Lead Form": {
      "main": [
        [
          {
            "node": "Clean & Validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean & Validate": {
      "main": [
        [
          {
            "node": "Is Valid?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Valid?": {
      "main": [
        [
          {
            "node": "Remove Helper Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Helper Fields": {
      "main": [
        [
          {
            "node": "WhatsApp Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Alert": {
      "main": [
        [
          {
            "node": "Respond OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
