{
  "name": "TechSavvy Hawaii \u2014 Main Lead Intake",
  "nodes": [
    {
      "id": "node-webhook",
      "name": "Receive Lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "techsavvy-intake",
        "responseMode": "responseNode",
        "options": {}
      }
    },
    {
      "id": "node-respond",
      "name": "Respond 200 OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        460,
        200
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"status\": \"received\", \"message\": \"Lead captured successfully\" }",
        "options": {
          "responseCode": 200,
          "responseHeaders": {
            "entries": [
              {
                "name": "Access-Control-Allow-Origin",
                "value": "*"
              }
            ]
          }
        }
      }
    },
    {
      "id": "node-score",
      "name": "Score & Validate Lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        400
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// \u2500\u2500 Lead Scoring Engine \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nconst data = $input.item.json.body || $input.item.json;\n\n// Required field validation\nconst name = (data.name || '').trim();\nconst email = (data.email || '').trim();\nif (!name || !email) {\n  throw new Error('Missing required fields: name or email');\n}\n\n// Email format check\nconst emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\nif (!emailRegex.test(email)) {\n  throw new Error('Invalid email format: ' + email);\n}\n\n// \u2500\u2500 Scoring \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nlet score = 0;\nconst volumeMap = {\n  'under_10k':  5,\n  '10k_30k':   15,\n  '30k_75k':   30,\n  '75k_plus':  45\n};\n\nconst volume = data.monthly_volume || '';\nscore += volumeMap[volume] || 0;\n\nif (data.wants_statement_review === 'yes') score += 25;\nif (data.wants_terminal === 'yes')         score += 10;\nif (data.wants_cash_discount === 'yes')    score += 10;\nif (data.has_statement_upload === 'yes')   score += 15;\nif (data.phone && data.phone.trim())       score += 5;\n\n// \u2500\u2500 Tier Assignment \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nlet tier;\nif (score >= 40)     tier = 'High';\nelse if (score >= 20) tier = 'Medium';\nelse                  tier = 'Low';\n\n// \u2500\u2500 Stage \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nconst stage = 'New Lead';\n\n// \u2500\u2500 First Name \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nconst firstName = name.split(' ')[0];\n\n// \u2500\u2500 Clean processor name \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nconst processorLabels = {\n  square: 'Square', stripe: 'Stripe', paypal: 'PayPal/Zettle',\n  toast: 'Toast', clover: 'Clover', heartland: 'Heartland',\n  first_data: 'First Data/Fiserv', chase: 'Chase Paymentech',\n  worldpay: 'Worldpay', other: 'Other/Unknown'\n};\nconst processorName = processorLabels[data.current_processor] || data.current_processor || 'Unknown';\n\nreturn {\n  // Passthrough all original fields\n  ...data,\n  // Enriched fields\n  first_name: firstName,\n  lead_score: score,\n  lead_tier: tier,\n  stage: stage,\n  processor_name: processorName,\n  is_high_value: tier === 'High',\n  submitted_date: new Date().toISOString().split('T')[0]\n};"
      }
    },
    {
      "id": "node-airtable",
      "name": "Create Airtable Lead",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2,
      "position": [
        700,
        400
      ],
      "parameters": {
        "operation": "create",
        "base": {
          "__rl": true,
          "value": "YOUR_AIRTABLE_BASE_ID",
          "mode": "id"
        },
        "table": {
          "__rl": true,
          "value": "Leads",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Name": "={{ $json.name }}",
            "Business Name": "={{ $json.business_name }}",
            "Email": "={{ $json.email }}",
            "Phone": "={{ $json.phone || '' }}",
            "Business Type": "={{ $json.business_type || '' }}",
            "Monthly Volume": "={{ $json.monthly_volume || '' }}",
            "Current Processor": "={{ $json.processor_name || '' }}",
            "Wants Terminal": "={{ $json.wants_terminal === 'yes' }}",
            "Wants Statement Review": "={{ $json.wants_statement_review === 'yes' }}",
            "Has Statement Upload": "={{ $json.has_statement_upload === 'yes' }}",
            "Lead Score": "={{ $json.lead_score }}",
            "Lead Tier": "={{ $json.lead_tier }}",
            "Stage": "={{ $json.stage }}",
            "Lead Source": "={{ $json.lead_source || '' }}",
            "Lead Magnet": "={{ $json.lead_magnet || '' }}",
            "Notes": "={{ $json.notes || '' }}",
            "Referral Source": "={{ $json.referral_source || '' }}",
            "Page URL": "={{ $json.page_url || '' }}",
            "Submitted At": "={{ $json.submitted_date }}"
          },
          "options": {
            "typecast": true
          }
        }
      },
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "node-email-all",
      "name": "Send Confirmation Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        940,
        300
      ],
      "parameters": {
        "fromEmail": "kepa@techsavvyhawaii.com",
        "toEmail": "={{ $('Score & Validate Lead').item.json.email }}",
        "subject": "={{ $('Score & Validate Lead').item.json.lead_source === 'calculator' || $('Score & Validate Lead').item.json.lead_source === 'apply' ? 'We got your info, ' + $('Score & Validate Lead').item.json.first_name + ' \u2014 here\\'s what happens next' : 'Your guide is on the way, ' + $('Score & Validate Lead').item.json.first_name }}",
        "emailType": "html",
        "message": "=<!DOCTYPE html>\n<html>\n<body style=\"font-family: -apple-system, sans-serif; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;\">\n\n<h2 style=\"color: #1a1a2e;\">Hey {{ $('Score & Validate Lead').item.json.first_name }},</h2>\n\n{{ $('Score & Validate Lead').item.json.lead_source === 'calculator' || $('Score & Validate Lead').item.json.lead_source === 'apply'\n  ? '<p>We received your submission for <strong>' + ($('Score & Validate Lead').item.json.business_name || 'your business') + '</strong>.</p><p>Based on what you shared, here\\'s what you should know:</p><ul><li>Monthly volume: <strong>' + ($('Score & Validate Lead').item.json.monthly_volume || 'not specified') + '</strong></li><li>Current processor: <strong>' + ($('Score & Validate Lead').item.json.processor_name || 'not specified') + '</strong></li></ul><p>Most businesses in your situation are overpaying by <strong>1.5\u20132.0%</strong> on every transaction. We\\'ll come back to you with a real number \u2014 not a range.</p><p><strong>Next step:</strong> Expect a follow-up from us within 24 hours. If you have a statement handy, reply to this email and attach it \u2014 that gets you to the front of the line.</p>'\n  : '<p>Thanks for downloading <strong>' + ($('Score & Validate Lead').item.json.lead_magnet || 'our guide') + '</strong>. It has everything you need to understand your current processing situation.</p><p><strong>Pro tip:</strong> After reading it, pull out your most recent statement and look for your <em>effective rate</em> (total fees \u00f7 total volume). Most businesses are at 2.5\u20133.5%. Anything over 2% is worth reviewing.</p><p>Want us to do the review for you? <a href=\"https://techsavvyhawaii.com/apply.html\" style=\"color: #2a5298;\">Apply for a free analysis \u2192</a></p>'\n}}\n\n<hr style=\"border: none; border-top: 1px solid #eee; margin: 30px 0;\">\n<p style=\"font-size: 13px; color: #888;\">TechSavvy Hawaii | <a href=\"mailto:kepa@techsavvyhawaii.com\" style=\"color: #667eea;\">kepa@techsavvyhawaii.com</a> | (888)353-5532</p>\n</body>\n</html>",
        "options": {}
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "node-if-high",
      "name": "Is High Value?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        940,
        500
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "cond-tier",
              "leftValue": "={{ $('Score & Validate Lead').item.json.lead_tier }}",
              "rightValue": "High",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "node-sms",
      "name": "Send SMS (High Value)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1180,
        440
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.twilio.com/2010-04-01/Accounts/{{ $credentials.accountSid }}/Messages.json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "To",
              "value": "={{ $('Score & Validate Lead').item.json.phone }}"
            },
            {
              "name": "From",
              "value": "YOUR-TWILIO-NUMBER"
            },
            {
              "name": "Body",
              "value": "=Hey {{ $('Score & Validate Lead').item.json.first_name }}, thanks for reaching out to TechSavvy Hawaii. Based on what you shared, you may be able to reduce your processing costs. I'll follow up shortly \u2014 or feel free to call/text me back at (808)767-5460. - Kepa"
            }
          ]
        },
        "options": {}
      },
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "node-backend",
      "name": "Send to Admin Backend",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        940,
        420
      ],
      "parameters": {
        "method": "POST",
        "url": "https://techsavvyhawaii.com/api/leads/public",
        "sendBody": true,
        "contentType": "json",
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $('Score & Validate Lead').item.json.name }}"
            },
            {
              "name": "business",
              "value": "={{ $('Score & Validate Lead').item.json.business_name || '' }}"
            },
            {
              "name": "phone",
              "value": "={{ $('Score & Validate Lead').item.json.phone || '' }}"
            },
            {
              "name": "email",
              "value": "={{ $('Score & Validate Lead').item.json.email }}"
            },
            {
              "name": "package",
              "value": "terminal"
            },
            {
              "name": "notes",
              "value": "={{ 'Source: ' + ($('Score & Validate Lead').item.json.lead_source || 'unknown') + ' | Volume: ' + ($('Score & Validate Lead').item.json.monthly_volume || 'N/A') + ' | Processor: ' + ($('Score & Validate Lead').item.json.processor_name || 'N/A') + ' | Score: ' + $('Score & Validate Lead').item.json.lead_score + ' (' + $('Score & Validate Lead').item.json.lead_tier + ')' + ($('Score & Validate Lead').item.json.lead_magnet ? ' | Guide: ' + $('Score & Validate Lead').item.json.lead_magnet : '') }}"
            }
          ]
        },
        "options": {
          "ignore400": true
        }
      }
    },
    {
      "id": "node-notify-self",
      "name": "Notify Me (High Value)",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        1180,
        560
      ],
      "parameters": {
        "fromEmail": "kepa@techsavvyhawaii.com",
        "toEmail": "kepa@techsavvyhawaii.com",
        "subject": "=\ud83d\udd25 HIGH VALUE LEAD \u2014 {{ $('Score & Validate Lead').item.json.name }} ({{ $('Score & Validate Lead').item.json.business_name }}) Score: {{ $('Score & Validate Lead').item.json.lead_score }}",
        "emailType": "html",
        "message": "=<h2>New High-Value Lead</h2><table style=\"border-collapse:collapse;width:100%\"><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Name</strong></td><td style=\"padding:8px;border:1px solid #ddd;\">{{ $('Score & Validate Lead').item.json.name }}</td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Business</strong></td><td style=\"padding:8px;border:1px solid #ddd;\">{{ $('Score & Validate Lead').item.json.business_name }}</td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Email</strong></td><td style=\"padding:8px;border:1px solid #ddd;\"><a href=\"mailto:{{ $('Score & Validate Lead').item.json.email }}\">{{ $('Score & Validate Lead').item.json.email }}</a></td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Phone</strong></td><td style=\"padding:8px;border:1px solid #ddd;\">{{ $('Score & Validate Lead').item.json.phone }}</td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Volume</strong></td><td style=\"padding:8px;border:1px solid #ddd;\">{{ $('Score & Validate Lead').item.json.monthly_volume }}</td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Processor</strong></td><td style=\"padding:8px;border:1px solid #ddd;\">{{ $('Score & Validate Lead').item.json.processor_name }}</td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Wants Terminal</strong></td><td style=\"padding:8px;border:1px solid #ddd;\">{{ $('Score & Validate Lead').item.json.wants_terminal }}</td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Wants Review</strong></td><td style=\"padding:8px;border:1px solid #ddd;\">{{ $('Score & Validate Lead').item.json.wants_statement_review }}</td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Score</strong></td><td style=\"padding:8px;border:1px solid #ddd;\"><strong style=\"color:#e53e3e;\">{{ $('Score & Validate Lead').item.json.lead_score }} \u2014 {{ $('Score & Validate Lead').item.json.lead_tier }}</strong></td></tr><tr><td style=\"padding:8px;border:1px solid #ddd;\"><strong>Source</strong></td><td style=\"padding:8px;border:1px solid #ddd;\">{{ $('Score & Validate Lead').item.json.lead_source }}</td></tr></table>",
        "options": {}
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Receive Lead": {
      "main": [
        [
          {
            "node": "Respond 200 OK",
            "type": "main",
            "index": 0
          },
          {
            "node": "Score & Validate Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score & Validate Lead": {
      "main": [
        [
          {
            "node": "Create Airtable Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Airtable Lead": {
      "main": [
        [
          {
            "node": "Send Confirmation Email",
            "type": "main",
            "index": 0
          },
          {
            "node": "Is High Value?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send to Admin Backend",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is High Value?": {
      "main": [
        [
          {
            "node": "Send SMS (High Value)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Notify Me (High Value)",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "errorWorkflow": ""
  },
  "tags": [
    "TechSavvy",
    "Lead Intake"
  ]
}