{
  "name": "Vorlux AI | Community Pulse",
  "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/community/stats",
        "method": "GET",
        "options": {
          "timeout": 15000
        }
      },
      "id": "stats",
      "name": "Community Stats",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        200
      ]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/discord/activity",
        "method": "GET",
        "qs": {
          "period": "24h"
        },
        "options": {
          "timeout": 15000
        }
      },
      "id": "discord",
      "name": "Discord Activity",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        400
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const stats = $('Community Stats').first().json;\nconst discord = $('Discord Activity').first().json;\nconst totalMembers = stats.totalMembers || 0;\nconst activeMembers = discord.activeMembers || stats.activeMembers || 0;\nconst messages = discord.totalMessages || 0;\nconst healthScore = Math.min(100, Math.round((activeMembers / Math.max(totalMembers, 1)) * 100 * 2 + (messages > 50 ? 20 : messages * 0.4)));\nlet sentiment = 'neutral';\nif (healthScore >= 80) sentiment = 'thriving';\nelse if (healthScore >= 60) sentiment = 'healthy';\nelse if (healthScore >= 40) sentiment = 'quiet';\nelse sentiment = 'needs-attention';\nreturn [{ json: { healthScore, sentiment, totalMembers, activeMembers, messages24h: messages, activationRate: Math.round((activeMembers / Math.max(totalMembers, 1)) * 100), date: new Date().toISOString().split('T')[0] } }];"
      },
      "id": "calc",
      "name": "Calculate Pulse",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/metrics/dashboard",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ metric: 'community-pulse', value: $json.healthScore, data: $json }) }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "save",
      "name": "Save Metric",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ content: '\ud83d\udc93 **Community Pulse \u2014 ' + $json.date + '**\\nHealth Score: ' + $json.healthScore + '/100 (' + $json.sentiment + ')\\nMembers: ' + $json.totalMembers + ' | Active: ' + $json.activeMembers + ' (' + $json.activationRate + '%)\\nMessages (24h): ' + $json.messages24h }) }}"
      },
      "id": "notify",
      "name": "Discord Notify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        400
      ]
    }
  ],
  "connections": {
    "Daily Schedule": {
      "main": [
        [
          {
            "node": "Community Stats",
            "type": "main",
            "index": 0
          },
          {
            "node": "Discord Activity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Community Stats": {
      "main": [
        [
          {
            "node": "Calculate Pulse",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Discord Activity": {
      "main": [
        [
          {
            "node": "Calculate Pulse",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Pulse": {
      "main": [
        [
          {
            "node": "Save Metric",
            "type": "main",
            "index": 0
          },
          {
            "node": "Discord Notify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}