{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "972907da-000c-4c83-a4d5-af9f47e200e4",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        -1584
      ],
      "parameters": {
        "color": 3,
        "width": 476,
        "height": 424,
        "content": "## CRM New Lead \u2192 Instant SMS + AI Qualification Call\n\n**How it works:**\n1. Receives new lead from CRM via webhook\n2. Normalizes lead data across CRM platforms (HubSpot, Salesforce, Pipedrive)\n3. Creates/updates contact in Aloware with lead score + source\n4. Sends instant personalized SMS within seconds\n5. Routes by lead score: hot leads \u2192 AI Qualification call, warm leads \u2192 nurture sequence\n\n**Setup:**\n- Set n8n Variables: `ALOWARE_API_TOKEN`, `ALOWARE_LINE_PHONE`, `ALOWARE_HOT_SEQUENCE_ID`, `ALOWARE_NURTURE_SEQUENCE_ID`, `LEAD_SCORE_THRESHOLD`, `COMPANY_NAME`\n- Configure CRM to POST new leads to this webhook URL\n- Create 2 Aloware Sequences (hot AI qualification + warm nurture)"
      },
      "typeVersion": 1
    },
    {
      "id": "f38f45a7-a410-47a3-9a69-2155ec9f8da5",
      "name": "Receive & Process Lead",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1936,
        -1344
      ],
      "parameters": {
        "color": 6,
        "width": 880,
        "height": 356,
        "content": "### \ud83d\udce5 Receive & Process Lead"
      },
      "typeVersion": 1
    },
    {
      "id": "57622082-7b31-46fc-8273-383154aa3d9b",
      "name": "Score-Based Routing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2864,
        -1472
      ],
      "parameters": {
        "color": 4,
        "width": 612,
        "height": 460,
        "content": "### \ud83d\udd00 Route by Lead Score"
      },
      "typeVersion": 1
    },
    {
      "id": "e886050c-6dce-4bb0-a951-b889682d67f7",
      "name": "Score Tip",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2880,
        -1376
      ],
      "parameters": {
        "width": 166,
        "height": 112,
        "content": "Score \u2265 threshold (default 70) \u2192 hot lead. Edit `LEAD_SCORE_THRESHOLD` to adjust."
      },
      "typeVersion": 1
    },
    {
      "id": "2f46392d-27e8-457d-92cd-31ffe6ca179b",
      "name": "CRM: New Lead Received",
      "type": "n8n-nodes-base.webhook",
      "position": [
        2000,
        -1248
      ],
      "parameters": {
        "path": "crm-new-lead",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "15d2ef19-1e10-4878-a0e3-40617140a5d0",
      "name": "Normalize Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        2224,
        -1248
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a001",
              "name": "leadPhone",
              "type": "string",
              "value": "={{ $json.body?.phone || $json.phone || $json.properties?.phone?.value || $json.contact?.phone || '' }}"
            },
            {
              "id": "a002",
              "name": "leadFirstName",
              "type": "string",
              "value": "={{ $json.body?.firstname || $json.first_name || $json.properties?.firstname?.value || $json.name?.split(' ')[0] || 'there' }}"
            },
            {
              "id": "a003",
              "name": "leadLastName",
              "type": "string",
              "value": "={{ $json.body?.lastname || $json.last_name || $json.properties?.lastname?.value || $json.name?.split(' ').slice(1).join(' ') || '' }}"
            },
            {
              "id": "a004",
              "name": "leadEmail",
              "type": "string",
              "value": "={{ $json.body?.email || $json.email || $json.properties?.email?.value || '' }}"
            },
            {
              "id": "a005",
              "name": "leadSource",
              "type": "string",
              "value": "={{ $json.body?.lead_source || $json.lead_source || $json.source || $json.utm_source || 'CRM' }}"
            },
            {
              "id": "a006",
              "name": "leadScore",
              "type": "number",
              "value": "={{ Number($json.body?.lead_score || $json.lead_score || $json.score || 0) }}"
            },
            {
              "id": "a007",
              "name": "companyName",
              "type": "string",
              "value": "={{ $json.body?.company || $json.company || '' }}"
            },
            {
              "id": "a008",
              "name": "leadId",
              "type": "string",
              "value": "={{ $json.body?.id || $json.id || $json.contact_id || '' }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "84c28e8e-f68e-41f2-8233-733332f5d6b4",
      "name": "Aloware: Create or Update Contact",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2448,
        -1248
      ],
      "parameters": {
        "url": "https://app.aloware.com/api/v1/webhook/forms",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "api_token",
              "value": "={{ $vars.ALOWARE_API_TOKEN }}"
            },
            {
              "name": "phone_number",
              "value": "={{ $json.leadPhone }}"
            },
            {
              "name": "first_name",
              "value": "={{ $json.leadFirstName }}"
            },
            {
              "name": "last_name",
              "value": "={{ $json.leadLastName }}"
            },
            {
              "name": "email",
              "value": "={{ $json.leadEmail }}"
            },
            {
              "name": "company_name",
              "value": "={{ $json.companyName }}"
            },
            {
              "name": "lead_source",
              "value": "={{ $json.leadSource }}"
            },
            {
              "name": "csf1",
              "value": "={{ 'Lead Score: ' + $json.leadScore }}"
            },
            {
              "name": "force_update",
              "value": "=true"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ac52e64e-432b-4b18-861a-a9086f3e68d8",
      "name": "Aloware: Send Instant Lead SMS",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2656,
        -1248
      ],
      "parameters": {
        "url": "https://app.aloware.com/api/v1/webhook/sms-gateway/send",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "api_token",
              "value": "={{ $vars.ALOWARE_API_TOKEN }}"
            },
            {
              "name": "from",
              "value": "={{ $vars.ALOWARE_LINE_PHONE }}"
            },
            {
              "name": "to",
              "value": "={{ $('Normalize Lead Data').item.json.leadPhone }}"
            },
            {
              "name": "message",
              "value": "=Hi {{ $('Normalize Lead Data').item.json.leadFirstName }}! Thanks for your interest in {{ $vars.COMPANY_NAME }}. I'd love to connect for a quick chat about how we can help. Are you available for a 5-min call? Reply YES or let me know a good time!"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1a1f35a0-0398-41a2-83bf-9975bba80a79",
      "name": "Is Hot Lead?",
      "type": "n8n-nodes-base.if",
      "position": [
        2880,
        -1248
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cond_001",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $('Normalize Lead Data').item.json.leadScore }}",
              "rightValue": "={{ Number($vars.LEAD_SCORE_THRESHOLD || 70) }}"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "8aaaf8ff-7745-42be-b555-51cfc7954771",
      "name": "Aloware: Enroll in AI Qualification Sequence",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3248,
        -1408
      ],
      "parameters": {
        "url": "https://app.aloware.com/api/v1/webhook/sequence-enroll",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "api_token",
              "value": "={{ $vars.ALOWARE_API_TOKEN }}"
            },
            {
              "name": "sequence_id",
              "value": "={{ $vars.ALOWARE_HOT_SEQUENCE_ID }}"
            },
            {
              "name": "phone_number",
              "value": "={{ $('Normalize Lead Data').item.json.leadPhone }}"
            },
            {
              "name": "source",
              "value": "n8n-hot-lead"
            },
            {
              "name": "force_enroll",
              "value": "=true"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "3a321e8b-68d0-46ec-a48f-4622ae13496c",
      "name": "Aloware: Enroll in Nurture Sequence",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3248,
        -1200
      ],
      "parameters": {
        "url": "https://app.aloware.com/api/v1/webhook/sequence-enroll",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "api_token",
              "value": "={{ $vars.ALOWARE_API_TOKEN }}"
            },
            {
              "name": "sequence_id",
              "value": "={{ $vars.ALOWARE_NURTURE_SEQUENCE_ID }}"
            },
            {
              "name": "phone_number",
              "value": "={{ $('Normalize Lead Data').item.json.leadPhone }}"
            },
            {
              "name": "source",
              "value": "n8n-warm-lead"
            },
            {
              "name": "force_enroll",
              "value": "=false"
            }
          ]
        }
      },
      "typeVersion": 4.2
    }
  ],
  "connections": {
    "Is Hot Lead?": {
      "main": [
        [
          {
            "node": "Aloware: Enroll in AI Qualification Sequence",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Aloware: Enroll in Nurture Sequence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Lead Data": {
      "main": [
        [
          {
            "node": "Aloware: Create or Update Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM: New Lead Received": {
      "main": [
        [
          {
            "node": "Normalize Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aloware: Send Instant Lead SMS": {
      "main": [
        [
          {
            "node": "Is Hot Lead?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aloware: Create or Update Contact": {
      "main": [
        [
          {
            "node": "Aloware: Send Instant Lead SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}