{
  "name": "Vorlux AI | Email Newsletter Builder",
  "active": false,
  "nodes": [
    { "parameters": { "rule": { "interval": [{ "field": "weeks", "weeksInterval": 1 }] } }, "id": "sched", "name": "Weekly Schedule", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [220, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/blog/posts", "method": "GET", "qs": { "status": "published", "limit": 5, "sort": "-createdAt" }, "options": { "timeout": 15000 } }, "id": "fetch-posts", "name": "Fetch Recent Posts", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 200] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/community/stats", "method": "GET", "options": { "timeout": 10000 } }, "id": "fetch-community", "name": "Fetch Community Stats", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 400] },
    { "parameters": { "mode": "runOnceForAllItems", "jsCode": "const posts = $('Fetch Recent Posts').first().json.data || [];\nconst stats = $('Fetch Community Stats').first().json;\nconst articles = posts.map(p => ({ title: p.title, url: p.url || p.slug, excerpt: (p.excerpt || p.description || '').substring(0, 150) }));\nconst newsletter = {\n  subject: 'Vorlux AI Weekly — ' + new Date().toLocaleDateString('en-US', { month: 'short', day: 'numeric' }),\n  articles,\n  communityHighlight: { members: stats.totalMembers || 0, newThisWeek: stats.newMembers || 0 },\n  generatedAt: new Date().toISOString()\n};\nreturn [{ json: newsletter }];" }, "id": "build", "name": "Build Newsletter", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [720, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/newsletter/drafts", "method": "POST", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify($json) }}", "options": { "timeout": 15000 } }, "id": "save-draft", "name": "Save Newsletter Draft", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, 300] },
    { "parameters": { "method": "POST", "url": "={{$env.DISCORD_CONTENT_WEBHOOK}}", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ content: '📰 **Newsletter Draft Ready**\\nSubject: ' + $('Build Newsletter').first().json.subject + '\\nArticles: ' + $('Build Newsletter').first().json.articles.length + '\\nReview and send from the Hub.' }) }}" }, "id": "notify", "name": "Discord Notify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1200, 300] }
  ],
  "connections": {
    "Weekly Schedule": { "main": [[{ "node": "Fetch Recent Posts", "type": "main", "index": 0 }, { "node": "Fetch Community Stats", "type": "main", "index": 0 }]] },
    "Fetch Recent Posts": { "main": [[{ "node": "Build Newsletter", "type": "main", "index": 0 }]] },
    "Fetch Community Stats": { "main": [[{ "node": "Build Newsletter", "type": "main", "index": 0 }]] },
    "Build Newsletter": { "main": [[{ "node": "Save Newsletter Draft", "type": "main", "index": 0 }]] },
    "Save Newsletter Draft": { "main": [[{ "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
