{
  "name": "AI Lead Qualification & Routing",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-intake",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Webhook - Lead Intake",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://localhost:3000/api/leads/analyze",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json.body.name }}"
            },
            {
              "name": "email",
              "value": "={{ $json.body.email }}"
            },
            {
              "name": "company",
              "value": "={{ $json.body.company }}"
            },
            {
              "name": "message",
              "value": "={{ $json.body.message }}"
            },
            {
              "name": "phone",
              "value": "={{ $json.body.phone }}"
            },
            {
              "name": "source",
              "value": "={{ $json.body.source || 'n8n' }}"
            },
            {
              "name": "job_title",
              "value": "={{ $json.body.job_title }}"
            }
          ]
        },
        "options": {
          "timeout": 30000
        }
      },
      "id": "http-analyze",
      "name": "AI Lead Analysis",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        480,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.analysis.category }}",
              "operation": "equals",
              "value2": "HOT"
            }
          ]
        }
      },
      "id": "if-hot",
      "name": "Is HOT Lead?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        720,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.analysis.category }}",
              "operation": "equals",
              "value2": "WARM"
            }
          ]
        }
      },
      "id": "if-warm",
      "name": "Is WARM Lead?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        720,
        520
      ]
    },
    {
      "parameters": {
        "channel": "#sales-alerts",
        "text": "\ud83d\udd25 *HOT LEAD ALERT* \u2014 Score: {{ $json.analysis.score }}/100\n\n*Name:* {{ $json.name || $node['AI Lead Analysis'].json.analysis.summary }}\n*Company:* {{ $json.company }}\n*Email:* {{ $json.email }}\n\n*AI Summary:*\n{{ $json.analysis.summary }}\n\n*Recommended Action:*\n{{ $json.analysis.recommended_action }}\n\n*Budget:* {{ $json.analysis.budget }} | *Urgency:* {{ $json.analysis.urgency }} | *Deal Size:* {{ $json.analysis.estimated_deal_size }}",
        "otherOptions": {}
      },
      "id": "slack-hot",
      "name": "Slack Alert (HOT)",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [
        960,
        200
      ],
      "notes": "Send immediate Slack notification for HOT leads"
    },
    {
      "parameters": {
        "application": "YOUR_AIRTABLE_BASE_ID",
        "table": "Leads",
        "options": {},
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldName": "Name",
              "fieldValue": "={{ $json.name }}"
            },
            {
              "fieldName": "Email",
              "fieldValue": "={{ $json.email }}"
            },
            {
              "fieldName": "Company",
              "fieldValue": "={{ $json.company }}"
            },
            {
              "fieldName": "Score",
              "fieldValue": "={{ $json.analysis.score }}"
            },
            {
              "fieldName": "Category",
              "fieldValue": "={{ $json.analysis.category }}"
            },
            {
              "fieldName": "Intent",
              "fieldValue": "={{ $json.analysis.intent }}"
            },
            {
              "fieldName": "Budget",
              "fieldValue": "={{ $json.analysis.budget }}"
            },
            {
              "fieldName": "Urgency",
              "fieldValue": "={{ $json.analysis.urgency }}"
            },
            {
              "fieldName": "Summary",
              "fieldValue": "={{ $json.analysis.summary }}"
            },
            {
              "fieldName": "Source",
              "fieldValue": "={{ $json.source || 'n8n' }}"
            },
            {
              "fieldName": "Status",
              "fieldValue": "HOT - Immediate Action"
            }
          ]
        }
      },
      "id": "airtable-hot",
      "name": "CRM - HOT Lead",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 1,
      "position": [
        960,
        340
      ],
      "notes": "Push HOT lead to Airtable with priority tag"
    },
    {
      "parameters": {
        "application": "YOUR_AIRTABLE_BASE_ID",
        "table": "Leads",
        "options": {},
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldName": "Name",
              "fieldValue": "={{ $json.name }}"
            },
            {
              "fieldName": "Email",
              "fieldValue": "={{ $json.email }}"
            },
            {
              "fieldName": "Company",
              "fieldValue": "={{ $json.company }}"
            },
            {
              "fieldName": "Score",
              "fieldValue": "={{ $json.analysis.score }}"
            },
            {
              "fieldName": "Category",
              "fieldValue": "={{ $json.analysis.category }}"
            },
            {
              "fieldName": "Summary",
              "fieldValue": "={{ $json.analysis.summary }}"
            },
            {
              "fieldName": "Status",
              "fieldValue": "WARM - Nurture Sequence"
            }
          ]
        }
      },
      "id": "airtable-warm",
      "name": "CRM - WARM Lead",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 1,
      "position": [
        960,
        480
      ],
      "notes": "Push WARM lead to nurture pipeline"
    },
    {
      "parameters": {
        "application": "YOUR_AIRTABLE_BASE_ID",
        "table": "Leads",
        "options": {},
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldName": "Name",
              "fieldValue": "={{ $json.name }}"
            },
            {
              "fieldName": "Email",
              "fieldValue": "={{ $json.email }}"
            },
            {
              "fieldName": "Score",
              "fieldValue": "={{ $json.analysis.score }}"
            },
            {
              "fieldName": "Category",
              "fieldValue": "COLD"
            },
            {
              "fieldName": "Status",
              "fieldValue": "COLD - Archived"
            }
          ]
        }
      },
      "id": "airtable-cold",
      "name": "CRM - COLD Lead",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 1,
      "position": [
        960,
        640
      ],
      "notes": "Archive COLD leads"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, message: 'Lead processed', lead_id: $json.lead_id, category: $json.analysis.category }) }}"
      },
      "id": "respond-webhook",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1200,
        300
      ]
    }
  ],
  "connections": {
    "Webhook - Lead Intake": {
      "main": [
        [
          {
            "node": "AI Lead Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Lead Analysis": {
      "main": [
        [
          {
            "node": "Is HOT Lead?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Is WARM Lead?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is HOT Lead?": {
      "main": [
        [
          {
            "node": "Slack Alert (HOT)",
            "type": "main",
            "index": 0
          },
          {
            "node": "CRM - HOT Lead",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is WARM Lead?": {
      "main": [
        [
          {
            "node": "CRM - WARM Lead",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "CRM - COLD Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack Alert (HOT)": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM - HOT Lead": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM - WARM Lead": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM - COLD Lead": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    {
      "name": "lead-qualification"
    },
    {
      "name": "ai-agent"
    },
    {
      "name": "sales-automation"
    }
  ]
}