{
  "name": "Vorlux AI | Clip Hunter Queue (with Twitch API)",
  "nodes": [
    {
      "id": "a147748c-e447-438d-a1cd-f226b7cab7f4",
      "name": "Every 30min",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      }
    },
    {
      "id": "01472ecb-2834-4657-9c10-d059dcba9d1c",
      "name": "Fetch Chat",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/chat/messages?limit=200&period=30m",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "c1cd9991-59b8-46a7-bcb2-1deb66ec7e50",
      "name": "Find Hype",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        300
      ],
      "notes": "Scans chat for hype keywords: clip, POG, insane, omg, etc. Groups by minute.",
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const msgs=$input.first().json.data||[];\nconst hype=/\\b(clip|CLIP|POG|omg|insane|clutch|!clip|amazing|highlight)\\b/i;\nconst hits=msgs.filter(m=>hype.test(m.content||''));\nconst map={};\nfor(const m of hits){const k=new Date(m.timestamp).toISOString().slice(0,16);if(!map[k])map[k]={ts:m.timestamp,msgs:[],score:0};map[k].msgs.push(m.content);map[k].score++;}\nconst moments=Object.values(map).sort((a,b)=>b.score-a.score).slice(0,5);\nreturn [{json:{moments,hasClips:moments.length>0,total:hits.length}}];"
      }
    },
    {
      "id": "d9adc6e3-1e55-42fc-947c-57da866774a1",
      "name": "Has Clips?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        940,
        300
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.hasClips }}",
              "rightValue": "true",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "7cfc6239-09c4-4f65-99b7-0b027c2efe7e",
      "name": "Queue Clips",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1180,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/content/clips/queue",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({moments:$json.moments}) }}",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "0f812306-1aad-421a-9491-8a95ad6b4f28",
      "name": "Notify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1180,
        400
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_CONTENT_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"\ud83c\udfac {{ $json.moments.length }} Clip Moments Found\",\"color\":16753920,\"footer\":{\"text\":\"{{ $json.total }} hype messages scanned\"}}]}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "31b5418c-3590-4490-b759-f7bb7954e88f",
      "name": "Create Twitch Clips",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1180,
        300
      ],
      "notes": "Creates actual Twitch clips via API for top hype moments",
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/integrations/twitch/clips/create",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"moments\":{{ JSON.stringify($json.moments.slice(0, 3)) }},\"broadcasterId\":\"{{$env.TWITCH_BROADCASTER_ID}}\"}",
        "options": {
          "timeout": 30000
        }
      }
    }
  ],
  "connections": {
    "Every 30min": {
      "main": [
        [
          {
            "node": "Fetch Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Chat": {
      "main": [
        [
          {
            "node": "Find Hype",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Hype": {
      "main": [
        [
          {
            "node": "Has Clips?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Clips?": {
      "main": [
        [
          {
            "node": "Queue Clips",
            "type": "main",
            "index": 0
          },
          {
            "node": "Notify",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create Twitch Clips",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  }
}