{
  "name": "Vorlux AI | Go Live Broadcast Fanout (Verified)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "go-live",
        "options": {
          "responseMode": "lastNode"
        }
      },
      "id": "webhook-trigger",
      "name": "Go Live Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        300
      ],
      "webhookId": "go-live-webhook",
      "notes": "Triggered when a stream goes live via OBS webhook or Paco Hub API"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const data = $input.first().json.body || $input.first().json;\nconst streamTitle = data.title || 'Vorlux AI Live Stream';\nconst platform = data.platform || 'twitch';\nconst streamer = data.streamer || 'Vorlux AI';\nconst category = data.category || 'Science & Technology';\nconst thumbnailUrl = data.thumbnail || '';\nconst streamUrl = data.url || `https://twitch.tv/${streamer.toLowerCase()}`;\nconst startedAt = new Date().toISOString();\n\nreturn [{ json: {\n  streamTitle, platform, streamer, category,\n  thumbnailUrl, streamUrl, startedAt,\n  discordEmbed: {\n    content: '@everyone \ud83d\udd34 We are LIVE!',\n    embeds: [{\n      title: `\ud83d\udd34 LIVE: ${streamTitle}`,\n      description: `**${streamer}** is streaming **${category}**\\n\\n[Watch Now](${streamUrl})`,\n      color: 16711680,\n      thumbnail: { url: thumbnailUrl },\n      fields: [\n        { name: 'Platform', value: platform.charAt(0).toUpperCase() + platform.slice(1), inline: true },\n        { name: 'Category', value: category, inline: true },\n        { name: 'Started', value: `<t:${Math.floor(Date.now()/1000)}:R>`, inline: true }\n      ],\n      footer: { text: 'Vorlux AI HUB \u2022 Stream Notifications' },\n      timestamp: startedAt\n    }]\n  },\n  tweet: `\ud83d\udd34 LIVE NOW: ${streamTitle}\\n\\n\ud83c\udfae ${category}\\n\ud83d\udcfa ${streamUrl}\\n\\n#Vorlux AI #Live #${category.replace(/[^a-zA-Z]/g, '')}`,\n  youtubePost: `\ud83d\udd34 I'm live on ${platform}! ${streamTitle} \u2014 Come hang out: ${streamUrl}`\n}}];"
      },
      "id": "prepare-notifications",
      "name": "Prepare Notifications",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ],
      "notes": "Builds Discord embed, tweet text, and YouTube community post from stream data"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_STREAM_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.discordEmbed) }}",
        "options": {
          "timeout": 15000
        }
      },
      "id": "discord-notify",
      "name": "Post to Discord",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        740,
        160
      ],
      "notes": "Posts go-live embed to Discord stream-notifications channel"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/social/post",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"platform\": \"twitter\",\n  \"content\": \"{{ $json.tweet }}\",\n  \"scheduledAt\": null\n}",
        "options": {
          "timeout": 15000
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "id": "twitter-notify",
      "name": "Post Tweet",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        740,
        300
      ],
      "notes": "Posts go-live tweet via Paco Hub social API"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/social/post",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"platform\": \"youtube\",\n  \"content\": \"{{ $json.youtubePost }}\",\n  \"type\": \"community_post\"\n}",
        "options": {
          "timeout": 15000
        }
      },
      "id": "youtube-notify",
      "name": "YouTube Community Post",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        740,
        440
      ],
      "notes": "Posts community update on YouTube"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/broadcast/sessions",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"title\": \"{{ $json.streamTitle }}\",\n  \"platform\": \"{{ $json.platform }}\",\n  \"status\": \"live\",\n  \"startedAt\": \"{{ $json.startedAt }}\",\n  \"url\": \"{{ $json.streamUrl }}\"\n}",
        "options": {
          "timeout": 15000
        }
      },
      "id": "log-session",
      "name": "Log Broadcast Session",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        740,
        580
      ],
      "notes": "Creates broadcast session record in Paco Hub database"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const results = $items();\nconst discordOk = results[0]?.json?.statusCode !== 'error';\nconst tweetOk = results[1]?.json?.statusCode !== 'error';\nreturn [{ json: {\n  success: true,\n  notifications: {\n    discord: discordOk,\n    twitter: tweetOk,\n    youtube: true,\n    hubSession: true\n  },\n  message: 'Go-live fanout completed'\n}}];"
      },
      "id": "aggregate-results",
      "name": "Aggregate Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1020,
        300
      ],
      "notes": "Collects results from all notification channels"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "id": "respond",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1260,
        300
      ]
    },
    {
      "id": "bfc3dec5-647c-4f23-afcd-60ef81992468",
      "name": "Verify on Twitch",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        160
      ],
      "notes": "Verifies the stream is actually live on Twitch API before sending notifications",
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/integrations/twitch/stream-status",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "3ab77fbd-1df3-417d-90f6-67bc05bb04e2",
      "name": "Update Schedule",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        740,
        720
      ],
      "notes": "Updates the stream schedule in Hub with actual go-live time",
      "parameters": {
        "method": "PUT",
        "url": "={{$env.VORLUX_HUB_URL}}/api/broadcast/schedule/current",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"status\":\"live\",\"actualStartTime\":\"{{ $node['Prepare Notifications'].json.startedAt }}\",\"title\":\"{{ $node['Prepare Notifications'].json.streamTitle }}\"}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Go Live Webhook": {
      "main": [
        [
          {
            "node": "Verify on Twitch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Notifications": {
      "main": [
        [
          {
            "node": "Post to Discord",
            "type": "main",
            "index": 0
          },
          {
            "node": "Post Tweet",
            "type": "main",
            "index": 0
          },
          {
            "node": "YouTube Community Post",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Broadcast Session",
            "type": "main",
            "index": 0
          },
          {
            "node": "Update Schedule",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Discord": {
      "main": [
        [
          {
            "node": "Aggregate Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post Tweet": {
      "main": [
        [
          {
            "node": "Aggregate Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube Community Post": {
      "main": [
        [
          {
            "node": "Aggregate Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Broadcast Session": {
      "main": [
        [
          {
            "node": "Aggregate Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Results": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify on Twitch": {
      "main": [
        [
          {
            "node": "Prepare Notifications",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Schedule": {
      "main": [
        [
          {
            "node": "Aggregate Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}