{
  "name": "AI Lead Scoring + Routing",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-scoring",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Webhook \u2014 nowy lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        400
      ]
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "Jeste\u015b ekspertem od kwalifikacji lead\u00f3w B2B w polskim M\u015aP. Oce\u0144 lead w skali 1-10 na podstawie podanych danych. Zwr\u00f3\u0107 JSON: {\"score\": <number>, \"reasoning\": \"<kr\u00f3tkie uzasadnienie po polsku>\", \"segment\": \"hot|warm|cold\"}\n\nKryteria scoringu:\n- Wielko\u015b\u0107 firmy (>50 pracownik\u00f3w = +2)\n- Bud\u017cet (podany i >5000 PLN = +2)\n- Pilno\u015b\u0107 (szuka rozwi\u0105zania teraz = +2)\n- Dopasowanie do ICP (bran\u017ca, lokalizacja = +2)\n- Kompletno\u015b\u0107 danych (email firmowy, telefon = +2)\n\nSegmenty: hot (8-10), warm (4-7), cold (1-3)"
            },
            {
              "role": "user",
              "content": "Dane leada:\n- Imi\u0119: {{$json.body.name}}\n- Email: {{$json.body.email}}\n- Firma: {{$json.body.company}}\n- Stanowisko: {{$json.body.position}}\n- Wielko\u015b\u0107 firmy: {{$json.body.company_size}}\n- Bud\u017cet: {{$json.body.budget}}\n- Wiadomo\u015b\u0107: {{$json.body.message}}\n- \u0179r\u00f3d\u0142o: {{$json.body.source}}"
            }
          ]
        },
        "options": {
          "temperature": 0.3,
          "maxTokens": 200,
          "response_format": {
            "type": "json_object"
          }
        }
      },
      "id": "openai-score",
      "name": "OpenAI \u2014 oce\u0144 lead",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        480,
        400
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const aiResponse = JSON.parse($input.item.json.message.content);\nconst leadData = $('Webhook \u2014 nowy lead').item.json.body;\n\nreturn {\n  json: {\n    ...leadData,\n    score: aiResponse.score,\n    reasoning: aiResponse.reasoning,\n    segment: aiResponse.segment,\n    scored_at: new Date().toISOString()\n  }\n};"
      },
      "id": "parse-score",
      "name": "Parsuj wynik scoringu",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "hot",
              "leftValue": "={{$json.score}}",
              "rightValue": 7,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-hot",
      "name": "IF \u2014 gor\u0105cy lead (>7)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        960,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "warm",
              "leftValue": "={{$json.score}}",
              "rightValue": 3,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-warm",
      "name": "IF \u2014 ciep\u0142y lead (4-7)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1200,
        560
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://REPLACE_WITH_YOUR_CRM_URL/api/contacts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer REPLACE_WITH_YOUR_CRM_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{$json.name}}"
            },
            {
              "name": "email",
              "value": "={{$json.email}}"
            },
            {
              "name": "company",
              "value": "={{$json.company}}"
            },
            {
              "name": "score",
              "value": "={{$json.score}}"
            },
            {
              "name": "segment",
              "value": "hot"
            },
            {
              "name": "source",
              "value": "={{$json.source}}"
            },
            {
              "name": "notes",
              "value": "={{$json.reasoning}}"
            }
          ]
        },
        "options": {}
      },
      "id": "crm-push-hot",
      "name": "CRM \u2014 dodaj gor\u0105cy lead",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        280
      ]
    },
    {
      "parameters": {
        "channel": "#sprzedaz",
        "text": ":fire: *Gor\u0105cy lead!* (Score: {{$json.score}}/10)\n\n*{{$json.name}}* z {{$json.company}}\nStanowisko: {{$json.position}}\nEmail: {{$json.email}}\nBud\u017cet: {{$json.budget}}\n\n_{{$json.reasoning}}_",
        "otherOptions": {}
      },
      "id": "slack-notify",
      "name": "Slack \u2014 powiadom zesp\u00f3\u0142",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1440,
        280
      ],
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Nurture",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Data": "={{$json.scored_at}}",
            "Imi\u0119": "={{$json.name}}",
            "Email": "={{$json.email}}",
            "Firma": "={{$json.company}}",
            "Score": "={{$json.score}}",
            "Segment": "warm",
            "Uzasadnienie": "={{$json.reasoning}}"
          },
          "matchingColumns": []
        },
        "options": {}
      },
      "id": "gsheets-nurture",
      "name": "Google Sheets \u2014 lista nurture",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1440,
        480
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Archiwum",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Data": "={{$json.scored_at}}",
            "Imi\u0119": "={{$json.name}}",
            "Email": "={{$json.email}}",
            "Firma": "={{$json.company}}",
            "Score": "={{$json.score}}",
            "Uzasadnienie": "={{$json.reasoning}}"
          },
          "matchingColumns": []
        },
        "options": {}
      },
      "id": "gsheets-archive",
      "name": "Google Sheets \u2014 archiwum",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1440,
        680
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\"status\": \"scored\", \"score\": {{$('Parsuj wynik scoringu').item.json.score}}, \"segment\": \"{{$('Parsuj wynik scoringu').item.json.segment}}\"}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "webhook-response",
      "name": "Webhook \u2014 odpowied\u017a",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1680,
        400
      ]
    }
  ],
  "connections": {
    "Webhook \u2014 nowy lead": {
      "main": [
        [
          {
            "node": "OpenAI \u2014 oce\u0144 lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI \u2014 oce\u0144 lead": {
      "main": [
        [
          {
            "node": "Parsuj wynik scoringu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parsuj wynik scoringu": {
      "main": [
        [
          {
            "node": "IF \u2014 gor\u0105cy lead (>7)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF \u2014 gor\u0105cy lead (>7)": {
      "main": [
        [
          {
            "node": "CRM \u2014 dodaj gor\u0105cy lead",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "IF \u2014 ciep\u0142y lead (4-7)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM \u2014 dodaj gor\u0105cy lead": {
      "main": [
        [
          {
            "node": "Slack \u2014 powiadom zesp\u00f3\u0142",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack \u2014 powiadom zesp\u00f3\u0142": {
      "main": [
        [
          {
            "node": "Webhook \u2014 odpowied\u017a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF \u2014 ciep\u0142y lead (4-7)": {
      "main": [
        [
          {
            "node": "Google Sheets \u2014 lista nurture",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets \u2014 archiwum",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets \u2014 lista nurture": {
      "main": [
        [
          {
            "node": "Webhook \u2014 odpowied\u017a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets \u2014 archiwum": {
      "main": [
        [
          {
            "node": "Webhook \u2014 odpowied\u017a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "staticData": null,
  "tags": [
    {
      "name": "lead-scoring"
    },
    {
      "name": "ai"
    },
    {
      "name": "crm"
    },
    {
      "name": "automatyzacja"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2026-04-08T00:00:00.000Z",
  "versionId": "1"
}