{
  "name": "Vorlux AI | Support Ticket Escalation",
  "nodes": [
    {
      "id": "7a9a2e88-ea8a-4e60-9328-36d4111cf59d",
      "name": "Check Overdue",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 2
            }
          ]
        }
      }
    },
    {
      "id": "dafff869-f8df-47ba-b4f4-892ddfad892e",
      "name": "Fetch Tickets",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/support/tickets?status=open&overdue=true",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "34a721ae-7d52-4ca2-b35a-2f404cb29714",
      "name": "Evaluate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const tickets = $input.first().json.data || [];const escalations = tickets.filter(t => {const age = (Date.now() - new Date(t.created_at).getTime()) / 3600000;return (t.priority === 'critical' && age > 1) || (t.priority === 'high' && age > 4) || (t.priority === 'medium' && age > 24);}).map(t => ({...t, ageHours: Math.round((Date.now() - new Date(t.created_at).getTime()) / 3600000)}));return [{json: {escalations, count: escalations.length}}];"
      },
      "notes": "Identifies tickets that need escalation based on priority and age"
    },
    {
      "id": "ac83af32-c7a5-43b9-97ce-b4933c95bcc3",
      "name": "Escalate",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        940,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/support/tickets/escalate",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ticketIds: $json.escalations.map(t => t.id)}) }}",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "7434882f-23f9-4e66-ac78-ff34bc5ee08d",
      "name": "Alert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        940,
        400
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"\ud83d\udea8 {{ $json.count }} Tickets Escalated\",\"description\":\"{{ $json.escalations.slice(0,5).map(t => t.title + \" (\" + t.ageHours + \"h, \" + t.priority + \")\").join(\"\\n\") }}\",\"color\":15158332}]}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Check Overdue": {
      "main": [
        [
          {
            "node": "Fetch Tickets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Tickets": {
      "main": [
        [
          {
            "node": "Evaluate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Evaluate": {
      "main": [
        [
          {
            "node": "Escalate",
            "type": "main",
            "index": 0
          },
          {
            "node": "Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}