{
  "name": "Vorlux AI | Engagement Rewards (Streaks & Tiers)",
  "nodes": [
    {
      "id": "876b0273-013c-4841-860a-c550848f599e",
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      }
    },
    {
      "id": "665351f2-ec4c-4ca2-9539-c0c047bffd1e",
      "name": "Process",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const d = $input.first().json;\nconst members = d.data || d.body?.data || [];\nconst awards = [];\nfor (const m of members) {\n  // Activity-based badges\n  if (m.messages >= 100 && !m.badges?.includes('chatterbox'))\n    awards.push({userId: m.userId, badge: 'chatterbox', reason: '100+ messages this week'});\n  if (m.helpfulVotes >= 10 && !m.badges?.includes('helper'))\n    awards.push({userId: m.userId, badge: 'helper', reason: '10+ helpful votes'});\n  \n  // Streak badges\n  const streak = m.streakDays || 0;\n  if (streak >= 7 && !m.badges?.includes('streak_7'))\n    awards.push({userId: m.userId, badge: 'streak_7', reason: '7-day activity streak \ud83d\udd25'});\n  if (streak >= 30 && !m.badges?.includes('streak_30'))\n    awards.push({userId: m.userId, badge: 'streak_30', reason: '30-day activity streak \ud83d\udd25\ud83d\udd25'});\n  if (streak >= 100 && !m.badges?.includes('streak_100'))\n    awards.push({userId: m.userId, badge: 'streak_100', reason: '100-day activity streak \ud83d\udd25\ud83d\udd25\ud83d\udd25'});\n  \n  // Tier badges\n  if (m.totalMessages >= 1000 && !m.badges?.includes('veteran'))\n    awards.push({userId: m.userId, badge: 'veteran', reason: '1000+ total messages'});\n  if (m.totalMessages >= 5000 && !m.badges?.includes('legend'))\n    awards.push({userId: m.userId, badge: 'legend', reason: '5000+ total messages'});\n}\nreturn [{json: {awards, count: awards.length, processedAt: new Date().toISOString()}}];"
      },
      "notes": "Checks activity badges, streak milestones (7/30/100 days), and tier progression"
    },
    {
      "id": "de9d58e8-0bbd-4fc7-b69a-aa15afed610a",
      "name": "Execute",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/orchestrator/execute",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"action\":\"engagement_rewards\",\"params\":{{ JSON.stringify($json) }}}",
        "options": {
          "timeout": 60000
        }
      }
    },
    {
      "id": "2bcf97bb-5090-4168-a5d2-8fc8c1d7232b",
      "name": "Notify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        400
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"Engagement Rewards\",\"color\":5793266}]}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Schedule": {
      "main": [
        [
          {
            "node": "Process",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process": {
      "main": [
        [
          {
            "node": "Execute",
            "type": "main",
            "index": 0
          },
          {
            "node": "Notify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}