[
  {
    "id": "leadSpeedFlow01",
    "name": "Lead capture and speed-to-lead",
    "nodes": [
      {
        "parameters": {
          "httpMethod": "POST",
          "path": "new-lead",
          "responseMode": "responseNode",
          "options": {}
        },
        "id": "n1",
        "name": "New lead (webhook)",
        "type": "n8n-nodes-base.webhook",
        "typeVersion": 2,
        "position": [
          0,
          200
        ],
        "webhookId": "new-lead-flowplaybook"
      },
      {
        "parameters": {
          "assignments": {
            "assignments": [
              {
                "id": "a1",
                "name": "name",
                "value": "={{ $json.body.name }}",
                "type": "string"
              },
              {
                "id": "a2",
                "name": "email",
                "value": "={{ $json.body.email }}",
                "type": "string"
              },
              {
                "id": "a3",
                "name": "company",
                "value": "={{ $json.body.company }}",
                "type": "string"
              },
              {
                "id": "a4",
                "name": "job_title",
                "value": "={{ $json.body.job_title }}",
                "type": "string"
              },
              {
                "id": "a5",
                "name": "employees",
                "value": "={{ $json.body.employees }}",
                "type": "number"
              },
              {
                "id": "a6",
                "name": "budget_usd",
                "value": "={{ $json.body.budget_usd }}",
                "type": "number"
              },
              {
                "id": "a7",
                "name": "message",
                "value": "={{ $json.body.message }}",
                "type": "string"
              },
              {
                "id": "a8",
                "name": "source",
                "value": "={{ $json.body.source || 'website form' }}",
                "type": "string"
              }
            ]
          },
          "options": {}
        },
        "id": "n2",
        "name": "Clean fields",
        "type": "n8n-nodes-base.set",
        "typeVersion": 3.4,
        "position": [
          220,
          200
        ]
      },
      {
        "parameters": {
          "jsCode": "// Score an inbound lead 0-100 against a simple ICP\nconst l = $input.first().json;\nlet score = 0;\nconst reasons = [];\n\nconst employees = Number(l.employees) || 0;\nif (employees >= 200) { score += 30; reasons.push('200+ employees'); }\nelse if (employees >= 50) { score += 20; reasons.push('50-199 employees'); }\nelse if (employees >= 10) { score += 10; reasons.push('10-49 employees'); }\n\nconst budget = Number(l.budget_usd) || 0;\nif (budget >= 10000) { score += 30; reasons.push('budget $10k+'); }\nelse if (budget >= 2000) { score += 20; reasons.push('budget $2k+'); }\nelse if (budget > 0) { score += 10; reasons.push('has a budget'); }\n\nif (/(founder|ceo|owner|director|head|vp|chief|cfo|coo|cmo)/i.test(l.job_title || '')) {\n  score += 25; reasons.push('decision-maker title');\n}\nif (/(asap|this month|this week|urgent|now)/i.test(l.message || '')) {\n  score += 15; reasons.push('urgent timeline');\n}\nif (/@(gmail|yahoo|hotmail|outlook|icloud)\\./i.test(l.email || '')) {\n  score -= 10; reasons.push('free email domain');\n}\n\nscore = Math.max(0, Math.min(100, score));\nconst tier = score >= 60 ? 'hot' : score >= 30 ? 'warm' : 'cold';\nreturn [{ json: { ...l, score, tier, reasons: reasons.join(', ') } }];"
        },
        "id": "n3",
        "name": "Score lead",
        "type": "n8n-nodes-base.code",
        "typeVersion": 2,
        "position": [
          440,
          200
        ]
      },
      {
        "parameters": {
          "conditions": {
            "options": {
              "caseSensitive": true,
              "leftValue": "",
              "typeValidation": "strict",
              "version": 2
            },
            "conditions": [
              {
                "id": "c1",
                "leftValue": "={{ $json.score }}",
                "rightValue": 60,
                "operator": {
                  "type": "number",
                  "operation": "gte"
                }
              }
            ],
            "combinator": "and"
          },
          "options": {}
        },
        "id": "n4",
        "name": "Hot lead? (score 60+)",
        "type": "n8n-nodes-base.if",
        "typeVersion": 2.2,
        "position": [
          660,
          200
        ]
      },
      {
        "parameters": {
          "fromEmail": "hello@360automate.test",
          "toEmail": "sales@360automate.test",
          "subject": "=🔥 Hot lead ({{ $json.score }}/100): {{ $json.name }} at {{ $json.company }}",
          "emailFormat": "text",
          "text": "=Score: {{ $json.score }} ({{ $json.tier }})\nWhy: {{ $json.reasons }}\n\nName: {{ $json.name }}\nTitle: {{ $json.job_title }}\nCompany: {{ $json.company }} ({{ $json.employees }} employees)\nBudget: ${{ $json.budget_usd }}\nEmail: {{ $json.email }}\nSource: {{ $json.source }}\n\nMessage:\n{{ $json.message }}\n\nReply within 5 minutes.",
          "options": {}
        },
        "id": "n5",
        "name": "Alert sales team",
        "type": "n8n-nodes-base.emailSend",
        "typeVersion": 2.1,
        "position": [
          900,
          60
        ],
        "credentials": {
          "smtp": {
            "id": "mailpitSmtp01",
            "name": "Local Mailpit SMTP"
          }
        }
      },
      {
        "parameters": {
          "fromEmail": "hello@360automate.test",
          "toEmail": "={{ $('Score lead').item.json.email }}",
          "subject": "=Thanks {{ $('Score lead').item.json.name }} - here is a link to book a call",
          "emailFormat": "text",
          "text": "=Hi {{ $('Score lead').item.json.name }},\n\nThanks for reaching out. Pick a time that suits you and we will walk through your project:\nhttps://example.com/book\n\nSpeak soon,\nThe FlowPlaybook team",
          "options": {}
        },
        "id": "n6",
        "name": "Instant reply: book a call",
        "type": "n8n-nodes-base.emailSend",
        "typeVersion": 2.1,
        "position": [
          1120,
          60
        ],
        "credentials": {
          "smtp": {
            "id": "mailpitSmtp01",
            "name": "Local Mailpit SMTP"
          }
        }
      },
      {
        "parameters": {
          "fromEmail": "hello@360automate.test",
          "toEmail": "={{ $json.email }}",
          "subject": "=Thanks {{ $json.name }} - a guide to get you started",
          "emailFormat": "text",
          "text": "=Hi {{ $json.name }},\n\nThanks for getting in touch. While we review your message, this guide is a good place to start:\nhttps://example.com/guide\n\nIf you have questions, just reply to this email.\n\nThe FlowPlaybook team",
          "options": {}
        },
        "id": "n7",
        "name": "Nurture reply: send guide",
        "type": "n8n-nodes-base.emailSend",
        "typeVersion": 2.1,
        "position": [
          900,
          340
        ],
        "credentials": {
          "smtp": {
            "id": "mailpitSmtp01",
            "name": "Local Mailpit SMTP"
          }
        }
      },
      {
        "parameters": {
          "respondWith": "json",
          "responseBody": "={{ { \"status\": \"received\", \"tier\": $('Score lead').item.json.tier, \"score\": $('Score lead').item.json.score } }}",
          "options": {}
        },
        "id": "n8",
        "name": "Respond to form",
        "type": "n8n-nodes-base.respondToWebhook",
        "typeVersion": 1.4,
        "position": [
          1340,
          200
        ]
      }
    ],
    "connections": {
      "New lead (webhook)": {
        "main": [
          [
            {
              "node": "Clean fields",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Clean fields": {
        "main": [
          [
            {
              "node": "Score lead",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Score lead": {
        "main": [
          [
            {
              "node": "Hot lead? (score 60+)",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Hot lead? (score 60+)": {
        "main": [
          [
            {
              "node": "Alert sales team",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "Nurture reply: send guide",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Alert sales team": {
        "main": [
          [
            {
              "node": "Instant reply: book a call",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Instant reply: book a call": {
        "main": [
          [
            {
              "node": "Respond to form",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Nurture reply: send guide": {
        "main": [
          [
            {
              "node": "Respond to form",
              "type": "main",
              "index": 0
            }
          ]
        ]
      }
    },
    "settings": {
      "executionOrder": "v1"
    },
    "active": false
  }
]