{
  "name": "Route and reassign leads with SLA using Google Sheets and Slack",
  "nodes": [
    {
      "id": "081127cd-9a65-420f-bcc9-ec00edd129c0",
      "name": "1) Form Trigger (New Lead)",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        1008,
        656
      ]
    },
    {
      "id": "3379ea2e-316c-407e-adee-75094f1904cd",
      "name": "2) Prep Lead",
      "type": "n8n-nodes-base.code",
      "position": [
        1232,
        656
      ]
    },
    {
      "id": "43e46f8a-bdf3-4617-a342-fbb756f3d986",
      "name": "3) Get Sales List (active=ON)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1456,
        656
      ]
    },
    {
      "id": "4b206a78-d668-4750-b005-99baa882807f",
      "name": "4) Build Sales List",
      "type": "n8n-nodes-base.code",
      "position": [
        1680,
        656
      ]
    },
    {
      "id": "aacd08b3-e26b-4545-b0b1-478c69785d0d",
      "name": "5) Get routing_state (last_index)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1904,
        656
      ]
    },
    {
      "id": "63feae74-e4fa-45fa-85a8-d70cf8264add",
      "name": "6) Initial Assign (Round Robin)",
      "type": "n8n-nodes-base.code",
      "position": [
        2128,
        656
      ]
    },
    {
      "id": "84bd91ec-f4c6-4abb-bc2f-83ec9afffb97",
      "name": "7) Update routing_state",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2352,
        560
      ]
    },
    {
      "id": "e79612be-ccc5-4a59-8da9-fdea4036ae6b",
      "name": "8) Upsert Lead (leads sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2352,
        752
      ]
    },
    {
      "id": "75bd650d-7e5f-46d6-b422-cff871904be9",
      "name": "SLA Trigger (every 1 hour)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1008,
        1184
      ]
    },
    {
      "id": "df9abcc5-683b-4345-9a47-39b0ddeafae2",
      "name": "SLA) Get Sales List",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1232,
        1184
      ]
    },
    {
      "id": "1a849c9c-cac8-4d79-808a-747addc1650d",
      "name": "SLA) Build Sales List",
      "type": "n8n-nodes-base.code",
      "position": [
        1456,
        1184
      ]
    },
    {
      "id": "5a9d1951-f3fe-457a-baf2-64d3016a9f6b",
      "name": "SLA) Get Leads (stage=NEW)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1680,
        1184
      ]
    },
    {
      "id": "848e4f52-21dc-4a4d-b57e-04449767c114",
      "name": "SLA) If last route >= 1 hour",
      "type": "n8n-nodes-base.if",
      "position": [
        1904,
        1184
      ]
    },
    {
      "id": "ef2e8f85-a46f-44af-86a3-60230e7f8d7b",
      "name": "SLA) Re-route to next sales",
      "type": "n8n-nodes-base.code",
      "position": [
        2128,
        1184
      ]
    },
    {
      "id": "0c2f96ca-edd6-4b09-9e56-a29e3d85b005",
      "name": "SLA) Update lead (after reroute)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2576,
        1280
      ]
    },
    {
      "id": "f2b2d1f5-5c79-4c15-bccb-68576372352b",
      "name": "STAGE) Webhook (/demo-stage-update)",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1024,
        1696
      ]
    },
    {
      "id": "bcdaf046-1550-4a7c-9203-fb3d0efd445e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        512
      ],
      "parameters": {
        "width": 1904,
        "height": 432,
        "content": "## Intake & Initial Assignment (Round Robin)"
      }
    },
    {
      "id": "47ba8bf6-9a88-4740-b055-444a71837399",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        992
      ],
      "parameters": {
        "width": 2992,
        "height": 512,
        "content": "## SLA Monitor & Hourly Re-route"
      }
    },
    {
      "id": "2fae9d8f-876c-4402-a2ca-5fac8150ad29",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        1552
      ],
      "parameters": {
        "width": 1488,
        "height": 432,
        "content": "##  \"Contacted\" Stage Update API (Stop Routing)"
      }
    },
    {
      "id": "1d86227e-35f4-4433-9be2-657ed6c8bc0f",
      "name": "STAGE) Update lead stage to CONTACTED",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2144,
        1600
      ]
    },
    {
      "id": "ae3aa50c-f879-4687-a17e-28d8ef01fa0c",
      "name": "SLA) Slack Notify (reroute) & Button",
      "type": "n8n-nodes-base.slack",
      "position": [
        2800,
        1280
      ]
    },
    {
      "id": "50fce6b6-5460-4441-9322-6bf5ef4073cf",
      "name": "9) Slack Notify (New Lead) & Button",
      "type": "n8n-nodes-base.slack",
      "position": [
        2576,
        752
      ]
    },
    {
      "id": "8b9bed18-38c6-462a-b5df-99a84718d4b7",
      "name": "STAGE) Lookup lead by lead_id",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1472,
        1696
      ]
    },
    {
      "id": "ffc50ca6-b358-40f9-a9f9-e3458c1e03e4",
      "name": "STAGE) Prep Payload",
      "type": "n8n-nodes-base.code",
      "position": [
        1248,
        1696
      ]
    },
    {
      "id": "42020b30-cae9-4e49-852f-ccc5c601742b",
      "name": "STAGE) If authorized",
      "type": "n8n-nodes-base.if",
      "position": [
        1920,
        1696
      ]
    },
    {
      "id": "486062f2-bd86-4006-aeea-8ef2a6230101",
      "name": "STAGE) Slack Feedback - Not allowed",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2144,
        1792
      ]
    },
    {
      "id": "08a8fef6-9693-4791-b899-308816a89666",
      "name": "STAGE) Authorize click (must be assigned sales)",
      "type": "n8n-nodes-base.code",
      "position": [
        1696,
        1696
      ]
    },
    {
      "id": "f14e59b3-6f63-4e8d-8186-8874d463047f",
      "name": "🚨 SLACK ESCALATION",
      "type": "n8n-nodes-base.slack",
      "position": [
        3408,
        1088
      ]
    },
    {
      "id": "5cbd553a-7bad-4bfc-8adc-98ce6485806c",
      "name": "Set Manager id",
      "type": "n8n-nodes-base.set",
      "position": [
        2576,
        1088
      ]
    },
    {
      "id": "328f94e0-f496-46d4-ae9b-8396788c94d8",
      "name": "IF route_count >= 10",
      "type": "n8n-nodes-base.if",
      "position": [
        2352,
        1184
      ]
    },
    {
      "id": "78fdb48e-54b1-47fa-8e75-f65820872006",
      "name": "ESC) Get escalation flag",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2800,
        1088
      ]
    },
    {
      "id": "7a5107c4-1ebd-403a-b6d8-a1d0d793d664",
      "name": "ESC) Set escalation flag",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3648,
        1088
      ]
    },
    {
      "id": "12854bb3-1ab6-42a2-ba90-4bb1ee83ddca",
      "name": "ESC) Normalize flag result",
      "type": "n8n-nodes-base.code",
      "position": [
        2992,
        1088
      ]
    },
    {
      "id": "cfd92876-0c6f-4e3a-b4dd-26a6981427e9",
      "name": "ESC) If not escalated yet",
      "type": "n8n-nodes-base.if",
      "position": [
        3200,
        1088
      ]
    },
    {
      "id": "d2c74230-2458-4143-b7ba-e8a73dc3f9b1",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        512
      ],
      "parameters": {
        "width": 752,
        "height": 736,
        "content": "## SLA-Based Lead Routing & Auto Reassignment Workflow\n\nThis workflow implements an SLA-based lead routing system designed to ensure fast response times and prevent lead neglect through automated reas"
      }
    }
  ],
  "connections": {
    "2) Prep Lead": {
      "main": [
        [
          {
            "node": "3) Get Sales List (active=ON)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Manager id": {
      "main": [
        [
          {
            "node": "ESC) Get escalation flag",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4) Build Sales List": {
      "main": [
        [
          {
            "node": "5) Get routing_state (last_index)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA) Get Sales List": {
      "main": [
        [
          {
            "node": "SLA) Build Sales List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "STAGE) Prep Payload": {
      "main": [
        [
          {
            "node": "STAGE) Lookup lead by lead_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF route_count >= 10": {
      "main": [
        [
          {
            "node": "Set Manager id",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "SLA) Update lead (after reroute)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "STAGE) If authorized": {
      "main": [
        [
          {
            "node": "STAGE) Update lead stage to CONTACTED",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "STAGE) Slack Feedback - Not allowed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA) Build Sales List": {
      "main": [
        [
          {
            "node": "SLA) Get Leads (stage=NEW)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🚨 SLACK ESCALATION": {
      "main": [
        [
          {
            "node": "ESC) Set escalation flag",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7) Update routing_state": {
      "main": [
        []
      ]
    },
    "ESC) Get escalation flag": {
      "main": [
        [
          {
            "node": "ESC) Normalize flag result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ESC) If not escalated yet": {
      "main": [
        [
          {
            "node": "🚨 SLACK ESCALATION",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "1) Form Trigger (New Lead)": {
      "main": [
        [
          {
            "node": "2) Prep Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ESC) Normalize flag result": {
      "main": [
        [
          {
            "node": "ESC) If not escalated yet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA Trigger (every 1 hour)": {
      "main": [
        [
          {
            "node": "SLA) Get Sales List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA) Get Leads (stage=NEW)": {
      "main": [
        [
          {
            "node": "SLA) If last route >= 1 hour",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA) Re-route to next sales": {
      "main": [
        [
          {
            "node": "IF route_count >= 10",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8) Upsert Lead (leads sheet)": {
      "main": [
        [
          {
            "node": "9) Slack Notify (New Lead) & Button",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA) If last route >= 1 hour": {
      "main": [
        [
          {
            "node": "SLA) Re-route to next sales",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "3) Get Sales List (active=ON)": {
      "main": [
        [
          {
            "node": "4) Build Sales List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "STAGE) Lookup lead by lead_id": {
      "main": [
        [
          {
            "node": "STAGE) Authorize click (must be assigned sales)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6) Initial Assign (Round Robin)": {
      "main": [
        [
          {
            "node": "7) Update routing_state",
            "type": "main",
            "index": 0
          },
          {
            "node": "8) Upsert Lead (leads sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA) Update lead (after reroute)": {
      "main": [
        [
          {
            "node": "SLA) Slack Notify (reroute) & Button",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5) Get routing_state (last_index)": {
      "main": [
        [
          {
            "node": "6) Initial Assign (Round Robin)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "STAGE) Webhook (/demo-stage-update)": {
      "main": [
        [
          {
            "node": "STAGE) Prep Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA) Slack Notify (reroute) & Button": {
      "main": [
        []
      ]
    },
    "STAGE) Update lead stage to CONTACTED": {
      "main": [
        []
      ]
    },
    "STAGE) Authorize click (must be assigned sales)": {
      "main": [
        [
          {
            "node": "STAGE) If authorized",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}