{
  "name": "Vorlux AI | Email Follow-Up",
  "active": false,
  "nodes": [
    { "parameters": { "rule": { "interval": [{ "field": "days", "daysInterval": 1 }] } }, "id": "sched", "name": "Daily Schedule", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [220, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/cc/outbox", "method": "GET", "qs": { "status": "awaiting-reply", "olderThan": "3d" }, "options": { "timeout": 15000 } }, "id": "fetch-pending", "name": "Fetch Pending Follow-Ups", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 300] },
    { "parameters": { "mode": "runOnceForAllItems", "jsCode": "const pending = $input.first().json.data || [];\nconst followUps = pending.map(p => ({\n  id: p.id,\n  to: p.to || p.recipient,\n  subject: 'Re: ' + (p.subject || 'Follow-up'),\n  daysSinceLastContact: Math.floor((Date.now() - new Date(p.sentAt || p.created_at).getTime()) / 86400000),\n  followUpNumber: (p.followUpCount || 0) + 1\n})).filter(f => f.followUpNumber <= 3);\nreturn [{ json: { total: followUps.length, followUps } }];" }, "id": "prepare", "name": "Prepare Follow-Ups", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [700, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/integrations/email", "method": "POST", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ action: 'send-followups', emails: $json.followUps }) }}", "options": { "timeout": 30000 } }, "id": "send", "name": "Send Follow-Ups", "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 Follow-Ups Sent**: ' + $('Prepare Follow-Ups').first().json.total + ' follow-up emails dispatched' }) }}" }, "id": "notify", "name": "Discord Notify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1200, 300] }
  ],
  "connections": {
    "Daily Schedule": { "main": [[{ "node": "Fetch Pending Follow-Ups", "type": "main", "index": 0 }]] },
    "Fetch Pending Follow-Ups": { "main": [[{ "node": "Prepare Follow-Ups", "type": "main", "index": 0 }]] },
    "Prepare Follow-Ups": { "main": [[{ "node": "Send Follow-Ups", "type": "main", "index": 0 }]] },
    "Send Follow-Ups": { "main": [[{ "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
