{
  "id": "rss-discover-03",
  "meta": {
    "instanceId": "vorlux-hub"
  },
  "name": "Vorlux AI | RSS Source Discovery (Weekly)",
  "active": true,
  "nodes": [
    {
      "id": "c3d4e5f6-0003-4ccc-8003-000000000001",
      "name": "Weekly Sunday",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [220, 300],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 168
            }
          ]
        }
      }
    },
    {
      "id": "c3d4e5f6-0003-4ccc-8003-000000000002",
      "name": "Get Topic Categories",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 300],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/content/categories",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "c3d4e5f6-0003-4ccc-8003-000000000003",
      "name": "Generate Search Queries",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [700, 300],
      "notes": "Generates search queries for discovering new RSS feeds based on our categories",
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const categories = ($input.first().json.data || []).map(c => c.name || c.title);\nconst defaultCategories = ['AI', 'Streaming', 'VTuber', 'Web Development', 'Community Building', 'Content Creation', 'Gaming Technology'];\nconst allCats = [...new Set([...categories, ...defaultCategories])];\n\nconst queries = allCats.flatMap(cat => [\n  `${cat} RSS feed`,\n  `${cat} blog RSS`,\n  `best ${cat} news feeds`,\n  `${cat} technology blog atom feed`\n]);\n\n// Known feed discovery endpoints\nconst knownSources = [\n  { url: 'https://hnrss.org/newest?q=AI', name: 'HN AI', category: 'AI' },\n  { url: 'https://hnrss.org/newest?q=streaming', name: 'HN Streaming', category: 'Streaming' },\n  { url: 'https://blog.google/technology/ai/rss/', name: 'Google AI Blog', category: 'AI' },\n  { url: 'https://openai.com/blog/rss/', name: 'OpenAI Blog', category: 'AI' },\n  { url: 'https://www.theverge.com/rss/index.xml', name: 'The Verge', category: 'Tech' },\n  { url: 'https://techcrunch.com/feed/', name: 'TechCrunch', category: 'Tech' },\n  { url: 'https://dev.to/feed', name: 'Dev.to', category: 'Web Development' },\n  { url: 'https://css-tricks.com/feed/', name: 'CSS Tricks', category: 'Web Development' },\n  { url: 'https://nextjs.org/feed.xml', name: 'Next.js Blog', category: 'Web Development' }\n];\n\nreturn [{ json: { queries, categories: allCats, knownSources, queryCount: queries.length } }];"
      }
    },
    {
      "id": "c3d4e5f6-0003-4ccc-8003-000000000004",
      "name": "Validate Known Sources",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [940, 300],
      "notes": "Checks each known RSS source to verify it is still active and returning content",
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const sources = $input.first().json.knownSources || [];\nconst validated = [];\n\nfor (const source of sources) {\n  try {\n    const res = await fetch(source.url, { signal: AbortSignal.timeout(8000) });\n    const text = await res.text();\n    const hasRssContent = text.includes('<rss') || text.includes('<feed') || text.includes('<item') || text.includes('<entry');\n    if (hasRssContent) {\n      const itemCount = (text.match(/<item/gi) || text.match(/<entry/gi) || []).length;\n      validated.push({ ...source, status: 'active', itemCount, lastChecked: new Date().toISOString() });\n    } else {\n      validated.push({ ...source, status: 'invalid_format' });\n    }\n  } catch (err) {\n    validated.push({ ...source, status: 'unreachable', error: String(err).substring(0, 80) });\n  }\n}\n\nreturn [{ json: { validatedSources: validated, activeCount: validated.filter(v => v.status === 'active').length, totalChecked: validated.length } }];"
      }
    },
    {
      "id": "c3d4e5f6-0003-4ccc-8003-000000000005",
      "name": "Store Discovered Feeds",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1180, 200],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/content/rss/feeds/discover",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ feeds: ($json.validatedSources || []).filter(s => s.status === 'active'), source: 'auto_discovery' }) }}",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "c3d4e5f6-0003-4ccc-8003-000000000006",
      "name": "Discord Report",
      "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\":\"RSS Source Discovery Report\",\"description\":\"Checked: {{ $json.totalChecked }} sources\\nActive: {{ $json.activeCount }}\\n\\nSources:\\n{{ ($json.validatedSources || []).map(s => (s.status === 'active' ? '\\u2705' : '\\u274c') + ' ' + s.name + ' (' + s.category + ')').join('\\\\n') }}\",\"color\":5793266,\"footer\":{\"text\":\"Weekly RSS Discovery - Sunday\"}}]}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Weekly Sunday": {
      "main": [
        [
          {
            "node": "Get Topic Categories",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Topic Categories": {
      "main": [
        [
          {
            "node": "Generate Search Queries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Search Queries": {
      "main": [
        [
          {
            "node": "Validate Known Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Known Sources": {
      "main": [
        [
          {
            "node": "Store Discovered Feeds",
            "type": "main",
            "index": 0
          },
          {
            "node": "Discord Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  },
  "tags": [
    { "name": "rss" },
    { "name": "discovery" },
    { "name": "content" }
  ],
  "versionId": "2"
}