{
  "name": "Vorlux AI | Email Triage",
  "active": false,
  "nodes": [
    { "parameters": { "rule": { "interval": [{ "field": "minutes", "minutesInterval": 30 }] } }, "id": "sched", "name": "Every 30 Min", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [220, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/inbox", "method": "GET", "qs": { "status": "unread" }, "options": { "timeout": 15000 } }, "id": "fetch-inbox", "name": "Fetch Unread Emails", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 300] },
    { "parameters": { "mode": "runOnceForAllItems", "jsCode": "const emails = $input.first().json.data || $input.first().json.emails || [];\nconst categorized = emails.map(e => {\n  const subject = (e.subject || '').toLowerCase();\n  let category = 'general';\n  let agent = 'support-agent';\n  let priority = 'medium';\n  if (/bug|error|broken|fix/i.test(subject)) { category = 'support'; agent = 'ticket-handler'; priority = 'high'; }\n  else if (/invoice|payment|billing|refund/i.test(subject)) { category = 'finance'; agent = 'revenue-tracker'; priority = 'high'; }\n  else if (/partner|sponsor|collab/i.test(subject)) { category = 'partnership'; agent = 'partnership-manager'; priority = 'medium'; }\n  else if (/subscribe|newsletter|content/i.test(subject)) { category = 'content'; agent = 'content-writer'; priority = 'low'; }\n  return { id: e.id, subject: e.subject, from: e.from, category, agent, priority };\n});\nreturn [{ json: { total: categorized.length, categorized, byCategory: { support: categorized.filter(c => c.category === 'support').length, finance: categorized.filter(c => c.category === 'finance').length, partnership: categorized.filter(c => c.category === 'partnership').length, content: categorized.filter(c => c.category === 'content').length, general: categorized.filter(c => c.category === 'general').length } } }];" }, "id": "triage", "name": "Triage Emails", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [700, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/cron/email-triage", "method": "POST", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ emails: $json.categorized }) }}", "options": { "timeout": 15000 } }, "id": "dispatch", "name": "Dispatch to Agents", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, 300] },
    { "parameters": { "method": "POST", "url": "={{$env.DISCORD_OPS_WEBHOOK}}", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ content: '📧 **Email Triage**\\nProcessed: ' + $('Triage Emails').first().json.total + '\\nSupport: ' + $('Triage Emails').first().json.byCategory.support + ' | Finance: ' + $('Triage Emails').first().json.byCategory.finance + ' | Partners: ' + $('Triage Emails').first().json.byCategory.partnership }) }}" }, "id": "notify", "name": "Discord Notify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1200, 300] }
  ],
  "connections": {
    "Every 30 Min": { "main": [[{ "node": "Fetch Unread Emails", "type": "main", "index": 0 }]] },
    "Fetch Unread Emails": { "main": [[{ "node": "Triage Emails", "type": "main", "index": 0 }]] },
    "Triage Emails": { "main": [[{ "node": "Dispatch to Agents", "type": "main", "index": 0 }]] },
    "Dispatch to Agents": { "main": [[{ "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
