File size: 4,712 Bytes
281f32d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{
  "name": "Lead Qualification with LLM Scoring",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "new-lead",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "1",
      "name": "Webhook - New Lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "jsCode": "// Normalize incoming lead payload from form/CRM webhook\nconst body = $input.first().json.body || $input.first().json;\nreturn [{\n  json: {\n    name: body.name || '',\n    email: body.email || '',\n    company: body.company || '',\n    message: body.message || '',\n    source: body.source || 'unknown'\n  }\n}];"
      },
      "id": "2",
      "name": "Normalize Lead Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "complete",
        "modelId": "gpt-4o-mini",
        "prompt": "You are a B2B lead qualifier. Given this lead's company, message, and source, score it 1-10 for sales-readiness and return a one-sentence reason. Respond as strict JSON: {\"score\": number, \"reason\": string}.\n\nCompany: {{$json.company}}\nMessage: {{$json.message}}\nSource: {{$json.source}}",
        "options": { "temperature": 0.2 }
      },
      "id": "3",
      "name": "Score Lead (LLM)",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [680, 300],
      "notes": "Swap for any chat-completion node (OpenAI, Anthropic, Azure OpenAI). Keep temperature low for consistent scoring."
    },
    {
      "parameters": {
        "jsCode": "const raw = $input.first().json.message?.content || $input.first().json.text || '{}';\nlet parsed;\ntry {\n  parsed = JSON.parse(raw);\n} catch (e) {\n  parsed = { score: 0, reason: 'parse_error' };\n}\nreturn [{ json: { ...$('Normalize Lead Data').first().json, ...parsed } }];"
      },
      "id": "4",
      "name": "Parse LLM Output",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [900, 300],
      "notes": "Always parse defensively — models occasionally wrap JSON in prose or markdown fences despite instructions."
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "leftValue": "={{$json.score}}",
              "rightValue": 6,
              "operator": { "type": "number", "operation": "gte" }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "5",
      "name": "Score >= 6?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [1120, 300]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "post",
        "channel": "#hot-leads",
        "text": "🔥 Hot lead ({{$json.score}}/10): {{$json.name}} @ {{$json.company}} — {{$json.reason}}"
      },
      "id": "6",
      "name": "Notify Sales (Slack)",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [1340, 200]
    },
    {
      "parameters": {
        "operation": "append",
        "sheetName": "Nurture Queue",
        "columns": {
          "value": {
            "name": "={{$json.name}}",
            "email": "={{$json.email}}",
            "score": "={{$json.score}}",
            "reason": "={{$json.reason}}"
          }
        }
      },
      "id": "7",
      "name": "Log to Nurture Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [1340, 400]
    }
  ],
  "connections": {
    "Webhook - New Lead": { "main": [[{ "node": "Normalize Lead Data", "type": "main", "index": 0 }]] },
    "Normalize Lead Data": { "main": [[{ "node": "Score Lead (LLM)", "type": "main", "index": 0 }]] },
    "Score Lead (LLM)": { "main": [[{ "node": "Parse LLM Output", "type": "main", "index": 0 }]] },
    "Parse LLM Output": { "main": [[{ "node": "Score >= 6?", "type": "main", "index": 0 }]] },
    "Score >= 6?": {
      "main": [
        [{ "node": "Notify Sales (Slack)", "type": "main", "index": 0 }],
        [{ "node": "Log to Nurture Sheet", "type": "main", "index": 0 }]
      ]
    }
  },
  "meta": {
    "description": "Scores inbound leads with an LLM and routes hot leads to Slack, cold ones to a nurture sheet. Replace credential-bound nodes (OpenAI, Slack, Google Sheets) with your own connected accounts before running.",
    "requiredCredentials": ["OpenAI API (or equivalent chat-completion provider)", "Slack OAuth", "Google Sheets OAuth"]
  }
}