{
  "id": "lead-capture-automation-001",
  "name": "Lead Capture & CRM Automation",
  "nodes": [
    {
      "parameters": {
        "content": "## \ud83d\udce5 Intake\nWebsite contact form posts here. Normalizes raw form fields into a clean shape.",
        "height": 200,
        "width": 320,
        "color": 5
      },
      "id": "sticky-intake",
      "name": "Sticky Note - Intake",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        180,
        80
      ]
    },
    {
      "parameters": {
        "content": "## \ud83e\udde0 Score & Route\nScores the lead (budget mentioned, phone provided, urgency keywords) and routes hot leads to instant Slack alert.",
        "height": 220,
        "width": 360,
        "color": 4
      },
      "id": "sticky-score",
      "name": "Sticky Note - Score",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        900,
        60
      ]
    },
    {
      "parameters": {
        "content": "## \ud83d\udce4 Record & Confirm\nEvery valid lead lands in the CRM sheet and gets an instant confirmation email \u2014 no lead falls through the cracks.",
        "height": 200,
        "width": 340,
        "color": 3
      },
      "id": "sticky-record",
      "name": "Sticky Note - Record",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1620,
        360
      ]
    },
    {
      "parameters": {
        "path": "lead-capture",
        "httpMethod": "POST",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "node-webhook",
      "name": "Website Form Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        360
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "name",
              "type": "string",
              "value": "={{ $json.body.name }}"
            },
            {
              "id": "a2",
              "name": "email",
              "type": "string",
              "value": "={{ $json.body.email.toLowerCase().trim() }}"
            },
            {
              "id": "a3",
              "name": "phone",
              "type": "string",
              "value": "={{ $json.body.phone || '' }}"
            },
            {
              "id": "a4",
              "name": "message",
              "type": "string",
              "value": "={{ $json.body.message || '' }}"
            },
            {
              "id": "a5",
              "name": "source",
              "type": "string",
              "value": "={{ $json.body.source || 'website' }}"
            },
            {
              "id": "a6",
              "name": "submittedAt",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        }
      },
      "id": "node-normalize",
      "name": "Normalize Lead Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        360
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "cond-email",
              "leftValue": "={{ $json.email }}",
              "rightValue": "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "node-if-valid-email",
      "name": "Valid Email?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        700,
        360
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"status\": \"error\", \"message\": \"A valid email address is required.\" } }}",
        "options": {
          "responseCode": 400
        }
      },
      "id": "node-respond-invalid",
      "name": "Invalid Email Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        940,
        540
      ]
    },
    {
      "parameters": {
        "jsCode": "const lead = $input.first().json;\nlet score = 40;\nconst msg = (lead.message || '').toLowerCase();\nif (lead.phone) score += 20;\nif (/urgent|asap|this week|budget|ready to/.test(msg)) score += 25;\nif (/just looking|curious|maybe/.test(msg)) score -= 15;\nif (!/gmail|yahoo|hotmail|outlook/.test(lead.email)) score += 15;\nscore = Math.max(0, Math.min(100, score));\nconst tier = score >= 70 ? 'hot' : score >= 40 ? 'warm' : 'cold';\nreturn [{ json: { ...lead, leadScore: score, tier } }];"
      },
      "id": "node-score",
      "name": "Score Lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        940,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "cond-hot",
              "leftValue": "={{ $json.tier }}",
              "rightValue": "hot",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "node-if-hot",
      "name": "Hot Lead?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1180,
        300
      ]
    },
    {
      "parameters": {
        "channel": "#sales-leads",
        "text": "=\ud83d\udd25 *Hot lead just came in* ({{ $json.leadScore }}/100)\n*{{ $json.name }}* \u2014 {{ $json.email }}\n{{ $json.phone }}\n\"{{ $json.message }}\"",
        "otherOptions": {}
      },
      "id": "node-slack",
      "name": "Notify Sales (Hot Lead)",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1420,
        180
      ]
    },
    {
      "parameters": {
        "mode": "chooseBranch",
        "output": "input1"
      },
      "id": "node-merge",
      "name": "Merge Branches",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1660,
        300
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "sheetName": "Leads",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Name": "={{ $json.name }}",
            "Email": "={{ $json.email }}",
            "Phone": "={{ $json.phone }}",
            "Message": "={{ $json.message }}",
            "Score": "={{ $json.leadScore }}",
            "Tier": "={{ $json.tier }}",
            "Source": "={{ $json.source }}",
            "Submitted At": "={{ $json.submittedAt }}"
          }
        }
      },
      "id": "node-sheets",
      "name": "Log Lead to CRM Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1900,
        300
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.email }}",
        "subject": "Thanks for reaching out, {{ $json.name }}!",
        "message": "=Hi {{ $json.name }},\n\nThanks for getting in touch \u2014 we received your message and a member of our team will follow up within one business day.\n\nTalk soon,\nThe Team",
        "options": {}
      },
      "id": "node-email",
      "name": "Send Confirmation Email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        2140,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"status\": \"ok\", \"tier\": $json.tier, \"leadScore\": $json.leadScore } }}",
        "options": {}
      },
      "id": "node-respond-success",
      "name": "Success Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        2380,
        300
      ]
    }
  ],
  "connections": {
    "Website Form Webhook": {
      "main": [
        [
          {
            "node": "Normalize Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Lead Data": {
      "main": [
        [
          {
            "node": "Valid Email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Valid Email?": {
      "main": [
        [
          {
            "node": "Score Lead",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Invalid Email Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score Lead": {
      "main": [
        [
          {
            "node": "Hot Lead?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hot Lead?": {
      "main": [
        [
          {
            "node": "Notify Sales (Hot Lead)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge Branches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Sales (Hot Lead)": {
      "main": [
        [
          {
            "node": "Merge Branches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Branches": {
      "main": [
        [
          {
            "node": "Log Lead to CRM Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Lead to CRM Sheet": {
      "main": [
        [
          {
            "node": "Send Confirmation Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Confirmation Email": {
      "main": [
        [
          {
            "node": "Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}