{
  "name": "Vorlux AI | Weekly Growth Digest (with Trends)",
  "nodes": [
    {
      "id": "6dfc1bbf-ac25-4aab-9a91-b54deca02eeb",
      "name": "Weekly Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 168
            }
          ]
        }
      }
    },
    {
      "id": "1aef420d-917f-47af-81cd-bbaa4c2eceef",
      "name": "Twitch Stats",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        160
      ],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/integrations/twitch/stats?period=7d",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "87af5218-728c-4f85-99e4-335109e37f3a",
      "name": "YouTube Stats",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/integrations/youtube/stats?period=7d",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "21e5635a-741b-4110-af0d-698ea54a1c66",
      "name": "Hub Stats",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        440
      ],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/analytics/summary?period=7d",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "d9662d52-a881-4348-b0a8-083b5258c0f7",
      "name": "Build Digest",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        740,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const tw = $node['Twitch Stats'].json.data || {};\nconst yt = $node['YouTube Stats'].json.data || {};\nconst hub = $node['Hub Stats'].json.data || {};\nconst prev = $node['Previous Week'].json.data || {};\n\n// Calculate trends\nfunction trend(current, previous) {\n  if (!previous || previous === 0) return '\u2014';\n  const pct = Math.round(((current - previous) / previous) * 100);\n  return pct > 0 ? '\u2191' + pct + '%' : pct < 0 ? '\u2193' + Math.abs(pct) + '%' : '\u2192 0%';\n}\n\nconst twTrend = trend(tw.avgViewers || 0, prev.twitch?.avgViewers || 0);\nconst ytTrend = trend(yt.views || 0, prev.youtube?.views || 0);\nconst hubTrend = trend(hub.activeUsers || 0, prev.hub?.activeUsers || 0);\n\nreturn [{json: {embeds: [{\n  title: '\ud83d\udcc8 Weekly Growth Digest',\n  color: 5793266,\n  fields: [\n    {name: '\ud83d\udfe3 Twitch ' + twTrend, value: 'Viewers: ' + (tw.avgViewers||0) + ' | Follows: ' + (tw.followers||0), inline: true},\n    {name: '\ud83d\udd34 YouTube ' + ytTrend, value: 'Views: ' + (yt.views||0) + ' | Subs: ' + (yt.subscribers||0), inline: true},\n    {name: '\ud83c\udfe0 Hub ' + hubTrend, value: 'Users: ' + (hub.activeUsers||0) + ' | Tasks: ' + (hub.tasksCompleted||0), inline: true},\n  ],\n  footer: {text: 'Vorlux AI Weekly Digest \u2022 Trends vs previous week'},\n  timestamp: new Date().toISOString()\n}]}]};"
      },
      "notes": "Builds digest with \u2191/\u2193 trend arrows compared to previous week"
    },
    {
      "id": "b749dceb-6bed-457a-a24e-e46de4fe0299",
      "name": "Post Digest",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        980,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_ANNOUNCE_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "6f7f2a7f-ac8f-4620-87c2-a8bdc04e4834",
      "name": "Previous Week",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        580
      ],
      "notes": "Gets previous week stats for trend comparison",
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/analytics/summary?period=14d&offset=7d",
        "options": {
          "timeout": 15000
        }
      }
    }
  ],
  "connections": {
    "Weekly Schedule": {
      "main": [
        [
          {
            "node": "Twitch Stats",
            "type": "main",
            "index": 0
          },
          {
            "node": "YouTube Stats",
            "type": "main",
            "index": 0
          },
          {
            "node": "Hub Stats",
            "type": "main",
            "index": 0
          },
          {
            "node": "Previous Week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Twitch Stats": {
      "main": [
        [
          {
            "node": "Build Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube Stats": {
      "main": [
        [
          {
            "node": "Build Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hub Stats": {
      "main": [
        [
          {
            "node": "Build Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Digest": {
      "main": [
        [
          {
            "node": "Post Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Previous Week": {
      "main": [
        [
          {
            "node": "Build Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  }
}