{
  "name": "Lead generation workflow (mahirmunaj.com)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "new-lead",
        "options": {}
      },
      "id": "88b76f59-5eb4-5797-92e6-41177807e2da",
      "name": "New lead (Webhook)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "name",
              "value": "={{ $json.body.name }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "email",
              "value": "={{ $json.body.email }}",
              "type": "string"
            },
            {
              "id": "3",
              "name": "phone",
              "value": "={{ $json.body.phone }}",
              "type": "string"
            },
            {
              "id": "4",
              "name": "message",
              "value": "={{ $json.body.message }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "448521e0-deea-54c2-a0ea-7f17499bc6e3",
      "name": "Clean fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'gpt-4o-mini', temperature: 0.3, messages: [ { role: 'system', content: \"You qualify inbound leads for a small business. Reply ONLY with JSON: {\\\"score\\\":\\\"hot|warm|cold\\\",\\\"reason\\\":\\\"one short sentence\\\"}. Hot = clear need, budget or timeline.\" }, { role: 'user', content: 'Lead: ' + $json.name + '\\nMessage: ' + $json.message } ] }) }}",
        "options": {}
      },
      "id": "d06577a5-14ad-5196-9da7-c7239339e1ba",
      "name": "AI lead score",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5",
              "name": "score",
              "value": "={{ JSON.parse($json.choices[0].message.content).score }}",
              "type": "string"
            },
            {
              "id": "6",
              "name": "reason",
              "value": "={{ JSON.parse($json.choices[0].message.content).reason }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "867536aa-4c08-588f-ab63-109f25afb181",
      "name": "Parse score",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false
          },
          "conditions": [
            {
              "id": "7",
              "leftValue": "={{ $json.score }}",
              "rightValue": "hot",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "3de8332d-df90-5b92-b0e9-4564be2e8650",
      "name": "Is hot?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        880,
        200
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#leads"
        },
        "text": "=🔥 Hot lead: {{ $('Clean fields').item.json.name }} ({{ $('Clean fields').item.json.email }}): {{ $json.reason }}",
        "otherOptions": {}
      },
      "id": "ec74da71-aac1-5a3f-b588-115a0b0d5989",
      "name": "Slack alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1100,
        120
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        },
        "options": {}
      },
      "id": "2fe52bf9-24d6-5893-ba7e-6e941386b0a7",
      "name": "Log to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        880,
        400
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $('Clean fields').item.json.email }}",
        "subject": "Thanks, we got your message",
        "emailType": "text",
        "message": "=Hi {{ $('Clean fields').item.json.name }},\n\nThanks for reaching out. We've received your message and will get back to you shortly.\n\nTalk soon",
        "options": {}
      },
      "id": "96fd93bd-47d2-5a1a-bc10-d6526d17d5ee",
      "name": "Reply by Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1100,
        400
      ]
    }
  ],
  "connections": {
    "New lead (Webhook)": {
      "main": [
        [
          {
            "node": "Clean fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean fields": {
      "main": [
        [
          {
            "node": "AI lead score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI lead score": {
      "main": [
        [
          {
            "node": "Parse score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse score": {
      "main": [
        [
          {
            "node": "Is hot?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is hot?": {
      "main": [
        [
          {
            "node": "Slack alert",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Log to Google Sheets": {
      "main": [
        [
          {
            "node": "Reply by Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "https://mahirmunaj.com/templates/n8n-lead-generation-workflow"
  }
}