{
  "id": "roVzAsXzSDUWxYQb",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Smart Lead Tagging & Routing",
  "tags": [],
  "nodes": [
    {
      "id": "14abd76c-5099-45d6-9ff3-f95af9f47056",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -2640,
        736
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "73d64595-b0ba-4a49-b03e-aeeff73b40be",
      "name": "Sticky Note - Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3072,
        592
      ],
      "parameters": {
        "color": 4,
        "width": 360,
        "height": 352,
        "content": "## \ud83e\udd16 AI-POWERED LEAD ROUTING WORKFLOW\n\nThis workflow uses AI to intelligently categorize and route leads:\n\n1. Fetches opportunities from HighLevel\n2. Gets contact details for each opportunity\n3. AI analyzes lead intent (Demo/Support/Partnership)\n4. Routes leads to appropriate teams via email\n\n**Trigger:** Manual execution\n**AI Model:** Azure OpenAI GPT-4o-mini"
      },
      "typeVersion": 1
    },
    {
      "id": "ff1ad33d-0c3d-465d-a509-ca49f0b2a5d5",
      "name": "Sticky Note - Data Collection",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2416,
        384
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 304,
        "content": "## \ud83d\udce5 DATA COLLECTION PHASE\n\n**Step 1:** Fetch all opportunities from HighLevel CRM\n**Step 2:** Get detailed contact information for each opportunity\n\nThis provides complete lead data (name, email, notes) needed for AI analysis.\n\n**Output:** Enriched lead data ready for AI processing"
      },
      "typeVersion": 1
    },
    {
      "id": "dfa52319-320d-475b-9262-b8f624f53013",
      "name": "Sticky Note - AI Analysis",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2080,
        1072
      ],
      "parameters": {
        "color": 6,
        "width": 340,
        "height": 280,
        "content": "## \ud83e\udde0 AI ANALYSIS PHASE\n\n**AI Agent:** Analyzes lead message/notes to determine intent\n\n**Azure OpenAI Model:** GPT-4o-mini processes contact data and classifies leads\n\n**Prompt:** \"You are an AI lead router. Suggest the scope of lead\"\n\n**Output:** AI classification (Demo Request, Support Query, or Partnership Inquiry)"
      },
      "typeVersion": 1
    },
    {
      "id": "52a4bef2-ff2f-4c34-ac9e-aea35f8c6f89",
      "name": "Sticky Note - Routing Logic",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        624
      ],
      "parameters": {
        "color": 7,
        "width": 360,
        "height": 352,
        "content": "## \ud83d\udd00 INTELLIGENT ROUTING\n\nBased on AI classification, leads are routed to:\n\n**\ud83c\udfaf Demo Requests** \u2192 demo@company.com\n**\ud83d\udee0\ufe0f Support Queries** \u2192 support@company.com\n**\ud83e\udd1d Partnership Inquiries** \u2192 partnership@company.com\n\nEach email includes:\n- Contact name\n- Email address\n- Original message/notes\n\nEnsures leads reach the right team instantly!"
      },
      "typeVersion": 1
    },
    {
      "id": "ce2aa645-d4a4-401b-afd2-2de399a3590a",
      "name": "Sticky Note - Processing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1776,
        368
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "height": 316,
        "content": "## \u2699\ufe0f POST-PROCESSING\n\nJavaScript code node that processes AI output and prepares data for routing conditions.\n\n**Purpose:** Transforms AI response into usable format for conditional branching.\n\n**Note:** Consider updating this node's logic based on specific AI response structure."
      },
      "typeVersion": 1
    },
    {
      "id": "2b1578f2-7e7f-4874-8481-7e615ade490a",
      "name": "Check: Demo Request?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1392,
        656
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"choices\"][0][\"message\"][\"content\"]}}",
              "value2": "Demo",
              "operation": "contains"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d2b3fe52-4857-4031-9ef1-e689678b3ef8",
      "name": "Route to Demo Team",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        -1088,
        544
      ],
      "parameters": {
        "text": "Lead Details:\n\nName: {{$json[\"contact\"].firstName}} {{$json[\"contact\"].lastName}}\nEmail: {{$json[\"contact\"].email}}\nMessage: {{$json[\"contact\"].notes}}",
        "options": {},
        "subject": "New Demo Request Lead",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9d878a92-9ffe-4c9b-aea5-9d54c750ae0e",
      "name": "Check: Support Query?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1392,
        848
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"choices\"][0][\"message\"][\"content\"]}}",
              "value2": "Support",
              "operation": "contains"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1e6fabeb-1f5d-4715-b579-483b99249102",
      "name": "Route to Support Team",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        -1088,
        800
      ],
      "parameters": {
        "text": "Lead Details:\n\nName: {{$json[\"contact\"].firstName}} {{$json[\"contact\"].lastName}}\nEmail: {{$json[\"contact\"].email}}\nMessage: {{$json[\"contact\"].notes}}",
        "options": {},
        "subject": "New Support Query Lead",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "649aa2c1-f3e0-4da9-8a4a-9077273a55f8",
      "name": "Check: Partnership Inquiry?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1392,
        1056
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"choices\"][0][\"message\"][\"content\"]}}",
              "value2": "Partnership",
              "operation": "contains"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "dc06d9fa-a7c1-4cc2-9161-231ac977e44f",
      "name": "Route to Partnership Team",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        -1088,
        1008
      ],
      "parameters": {
        "text": "Lead Details:\n\nName: {{$json[\"contact\"].firstName}} {{$json[\"contact\"].lastName}}\nEmail: {{$json[\"contact\"].email}}\nMessage: {{$json[\"contact\"].notes}}",
        "options": {},
        "subject": "New Partnership Lead",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "050df426-cc6c-42d4-9d98-7af4752f1e97",
      "name": "AI Lead Classifier Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1984,
        736
      ],
      "parameters": {
        "text": "You are an AI lead router. Suggest the scope of lead",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "dbc6739b-dd49-481a-9b77-d7303229142f",
      "name": "Fetch All Opportunities",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        -2400,
        736
      ],
      "parameters": {
        "filters": {},
        "resource": "opportunity",
        "operation": "getAll",
        "returnAll": true,
        "requestOptions": {}
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "bd6b5b4f-a0aa-42c9-8f00-ea15de067a70",
      "name": "Azure OpenAI GPT-4o-mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        -2016,
        928
      ],
      "parameters": {
        "model": "gpt-4o-mini",
        "options": {}
      },
      "credentials": {
        "azureOpenAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "91516bae-94ac-4647-8985-4eca9526d15e",
      "name": "Process AI Response",
      "type": "n8n-nodes-base.code",
      "position": [
        -1632,
        736
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 1;\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "fe176854-c40c-4925-abef-2826261ff25b",
      "name": "Fetch Contact Details",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        -2192,
        736
      ],
      "parameters": {
        "contactId": "={{ $json.contactId }}",
        "operation": "get",
        "requestOptions": {}
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3e6ac3e5-2786-42fb-b411-3ec2064cbdd9",
  "connections": {
    "Process AI Response": {
      "main": [
        [
          {
            "node": "Check: Demo Request?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check: Support Query?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check: Partnership Inquiry?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check: Demo Request?": {
      "main": [
        [
          {
            "node": "Route to Demo Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check: Support Query?": {
      "main": [
        [
          {
            "node": "Route to Support Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Contact Details": {
      "main": [
        [
          {
            "node": "AI Lead Classifier Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch All Opportunities": {
      "main": [
        [
          {
            "node": "Fetch Contact Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Lead Classifier Agent": {
      "main": [
        [
          {
            "node": "Process AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Azure OpenAI GPT-4o-mini": {
      "ai_languageModel": [
        [
          {
            "node": "AI Lead Classifier Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check: Partnership Inquiry?": {
      "main": [
        [
          {
            "node": "Route to Partnership Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Fetch All Opportunities",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}