{
  "name": "Free Lead Catcher (by Radiance Impact)",
  "nodes": [
    {
      "parameters": { "httpMethod": "POST", "path": "lead-catcher/intake", "responseMode": "responseNode", "options": {} },
      "id": "e4e4e4e4-0001-4000-8000-000000000001",
      "name": "Lead Intake (Webhook)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [-700, 0],
      "webhookId": "free-lead-catcher-intake",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "jsCode": "// Free edition: capture + notify only. No qualification rules, no\n// acknowledgement email to the lead -- those are the paid Lead Machine\n// kit's value-add (radianceimpact.com/products/lead-machine).\nconst body = $input.first().json.body || $input.first().json;\nconst clean = (v) => (typeof v === 'string' ? v.trim() : '');\n\nconst name = clean(body.name);\nconst email = clean(body.email).toLowerCase();\nconst message = clean(body.message);\n\nconst errors = [];\nif (!name) errors.push('name is required');\nif (!email || !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email)) errors.push('email is required and must be valid');\nif (!message) errors.push('message is required');\n\nreturn [{ json: { valid: errors.length === 0, errors, lead: { name, email, message, received_at: new Date().toISOString() } } }];\n"
      },
      "id": "e4e4e4e4-0002-4000-8000-000000000002",
      "name": "Validate & Normalise",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-480, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 },
          "conditions": [
            { "id": "f5f5f5f5-0001-4000-8000-000000000001", "leftValue": "={{ $json.valid }}", "rightValue": true, "operator": { "type": "boolean", "operation": "true", "singleValue": true } }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e4e4e4e4-0003-4000-8000-000000000003",
      "name": "Is Valid?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [-260, 0],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": { "respondWith": "json", "responseBody": "={{ { ok: false, errors: $json.errors } }}", "options": { "responseCode": 422 } },
      "id": "e4e4e4e4-0004-4000-8000-000000000004",
      "name": "Respond: Rejected",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [-40, 160]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": { "__rl": true, "mode": "list", "value": "PLACEHOLDER_SHEET_ID", "cachedResultName": "Free Lead Catcher - Leads (replace with your Sheet)" },
        "sheetName": { "__rl": true, "mode": "list", "value": "Leads", "cachedResultName": "Leads" },
        "columns": { "mappingMode": "defineBelow", "value": {
          "name": "={{ $json.lead.name }}",
          "email": "={{ $json.lead.email }}",
          "message": "={{ $json.lead.message }}",
          "received_at": "={{ $json.lead.received_at }}"
        }},
        "options": {}
      },
      "id": "e4e4e4e4-0005-4000-8000-000000000005",
      "name": "Store Lead (Google Sheets)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [-40, -80],
      "credentials": { "googleSheetsOAuth2Api": { "id": "PLACEHOLDER", "name": "Free Lead Catcher - Google Sheets (configure in n8n Credentials)" } },
      "retryOnFail": true,
      "maxTries": 2,
      "waitBetweenTries": 5000,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "fromEmail": "={{ $json.ownerFromEmail || 'no-reply@example.com' }}",
        "toEmail": "={{ $json.ownerNotifyEmail || 'owner@example.com' }}",
        "subject": "=New lead: {{ $json.lead.name }}",
        "emailFormat": "text",
        "text": "=New lead captured.\n\nName: {{ $json.lead.name }}\nEmail: {{ $json.lead.email }}\nMessage:\n{{ $json.lead.message }}\n\nReceived: {{ $json.lead.received_at }}"
      },
      "id": "e4e4e4e4-0006-4000-8000-000000000006",
      "name": "Notify Owner (Email)",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [180, -80],
      "credentials": { "smtp": { "id": "PLACEHOLDER", "name": "Free Lead Catcher - SMTP (configure in n8n Credentials)" } },
      "retryOnFail": true,
      "maxTries": 2,
      "waitBetweenTries": 10000,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": { "respondWith": "json", "responseBody": "={{ { ok: true, message: \"received\" } }}", "options": { "responseCode": 200 } },
      "id": "e4e4e4e4-0007-4000-8000-000000000007",
      "name": "Respond: Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [400, -80]
    }
  ],
  "connections": {
    "Lead Intake (Webhook)": { "main": [[{ "node": "Validate & Normalise", "type": "main", "index": 0 }]] },
    "Validate & Normalise": { "main": [[{ "node": "Is Valid?", "type": "main", "index": 0 }]] },
    "Is Valid?": {
      "main": [
        [{ "node": "Store Lead (Google Sheets)", "type": "main", "index": 0 }],
        [{ "node": "Respond: Rejected", "type": "main", "index": 0 }]
      ]
    },
    "Store Lead (Google Sheets)": { "main": [[{ "node": "Notify Owner (Email)", "type": "main", "index": 0 }]] },
    "Notify Owner (Email)": { "main": [[{ "node": "Respond: Success", "type": "main", "index": 0 }]] }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "active": false,
  "meta": { "templateCredsSetupCompleted": false }
}
