{
  "name": "Vorlux AI | Poll Results to Actions",
  "nodes": [
    {
      "id": "68afc5be-3b96-40da-90fd-e8a39d0bdea1",
      "name": "Poll Ended",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        300
      ],
      "webhookId": "86e95cee-f1aa-4c6e-bc03-c60867a23368",
      "parameters": {
        "httpMethod": "POST",
        "path": "poll-action",
        "options": {
          "responseMode": "lastNode"
        }
      }
    },
    {
      "id": "bde07bad-af24-47e0-a230-0dab24a885c3",
      "name": "Parse Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const d=$input.first().json.body||$input.first().json;\nconst opts=d.options||[];\nconst total=opts.reduce((s,o)=>s+(o.votes||0),0);\nconst winner=opts.sort((a,b)=>(b.votes||0)-(a.votes||0))[0]||{label:'None',votes:0};\nreturn [{json:{question:d.question||d.title||'',winner:winner.label||winner.text,winnerPct:total>0?Math.round(winner.votes/total*100):0,totalVotes:total,options:opts}}];"
      }
    },
    {
      "id": "033c1e90-d435-45bb-ae54-c31e34f80e02",
      "name": "Create Task",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/tasks",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"title\":\"Poll: {{ $json.winner }}\",\"description\":\"{{ $json.winnerPct }}% voted for {{ $json.winner }}. Question: {{ $json.question }}\",\"priority\":\"medium\",\"source\":\"poll\"}",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "83c98b7a-db4a-4758-b22a-ff05991c1131",
      "name": "Announce",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        400
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_ANNOUNCE_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"\ud83d\udcca {{ $json.question }}\",\"description\":\"Winner: **{{ $json.winner }}** ({{ $json.winnerPct }}%)\\nTotal: {{ $json.totalVotes }} votes\",\"color\":5793266}]}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "f37c5a7a-c77c-4134-975c-0238fa1756c1",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        940,
        300
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({winner:$json.winner,pct:$json.winnerPct}) }}"
      }
    }
  ],
  "connections": {
    "Poll Ended": {
      "main": [
        [
          {
            "node": "Parse Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Results": {
      "main": [
        [
          {
            "node": "Create Task",
            "type": "main",
            "index": 0
          },
          {
            "node": "Announce",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Task": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Announce": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  }
}