{
  "name": "Vorlux AI | Follow-up Orchestrator (Auto-Reassign)",
  "nodes": [
    {
      "id": "54df2b07-98cb-4782-b09b-09069f795718",
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 240
            }
          ]
        }
      }
    },
    {
      "id": "f2dc78f4-3df9-4644-893c-9994466a02e3",
      "name": "Fetch Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/tasks?status=in_progress&overdue=true",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "82e21c09-953b-4a21-a157-48adf93ec6e7",
      "name": "Process",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        740,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const tasks = $input.first().json.data || [];\nif (!tasks.length) return [{json: {overdue: [], count: 0, skip: true}}];\nconst overdue = tasks.map(t => ({\n  id: t.id, title: t.title,\n  assignee: t.assignee?.name || 'Unassigned',\n  daysOverdue: Math.round((Date.now() - new Date(t.due_at || t.dueAt || Date.now()).getTime()) / 86400000),\n  priority: t.priority\n})).sort((a, b) => b.daysOverdue - a.daysOverdue);\nconst critical = overdue.filter(t => t.daysOverdue > 3);\nreturn [{json: {overdue, count: overdue.length, critical: critical.length, skip: false}}];"
      }
    },
    {
      "id": "3483df85-2a58-477c-b9f5-263d4824700f",
      "name": "Post Discord",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        980,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.embeds ? $json : {embeds:[{title:$json.mood||$json.status||\"Update\",description:JSON.stringify($json).substring(0,500),color:5793266}]}) }}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "46d9003d-c0f5-4f88-b3be-cb55f93fcc72",
      "name": "Auto Reassign",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        940,
        200
      ],
      "notes": "Automatically reassigns tasks overdue by 3+ days to available agents",
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/tasks/reassign",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"taskIds\":{{ JSON.stringify($json.overdue.filter(t => t.daysOverdue > 3).map(t => t.id)) }},\"reason\":\"auto_reassign_overdue\"}",
        "options": {
          "timeout": 15000
        }
      }
    }
  ],
  "connections": {
    "Schedule": {
      "main": [
        [
          {
            "node": "Fetch Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Data": {
      "main": [
        [
          {
            "node": "Process",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process": {
      "main": [
        [
          {
            "node": "Post Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}