{
  "id": "2F21K5DkuYor8mXB",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Commodity News RSS to AI Investment Impact Alerts (RSS + OpenAI + Slack)",
  "tags": [],
  "nodes": [
    {
      "id": "7b5ad516-59d2-4dd1-9bce-2dc26c75d9a4",
      "name": "01 | Click to start execute workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -400,
        -16
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "dfd864f7-5a99-4ae3-bedf-069d461c0ec0",
      "name": "03 | Retrieve only required field",
      "type": "n8n-nodes-base.set",
      "position": [
        48,
        -112
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4f08429d-e067-4397-bfb0-4c0c835a2d2d",
              "name": "title",
              "type": "string",
              "value": "={{ $json.title }}"
            },
            {
              "id": "92b65305-a316-4e72-aedb-a8b51342b960",
              "name": "link",
              "type": "string",
              "value": "={{ $json.link }}"
            },
            {
              "id": "39488063-8ae0-4587-8053-c7201e7d3d99",
              "name": "description",
              "type": "string",
              "value": "={{ $json.content }}"
            },
            {
              "id": "98848218-6800-4701-8162-29d13325c100",
              "name": "date",
              "type": "string",
              "value": "={{ $json.pubDate }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e5371a0f-5ba0-47a8-9880-2e4742e44989",
      "name": "02 | Fetch - CNBC News RSS",
      "type": "n8n-nodes-base.rssFeedRead",
      "onError": "continueErrorOutput",
      "position": [
        -176,
        -16
      ],
      "parameters": {
        "url": "https://www.cnbc.com/id/1+1234567890/device/rss/rss.html",
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "cca8d762-26a8-4216-9461-80ffff5c7dec",
      "name": "04 | Clean - Remove Duplicate News",
      "type": "n8n-nodes-base.code",
      "position": [
        272,
        -112
      ],
      "parameters": {
        "jsCode": "const seen = new Set();\n\nreturn items.filter(item => {\n  const title = item.json.title;\n  \n  if (seen.has(title)) return false;\n  seen.add(title);\n  \n  return true;\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "a51bf52f-7978-4412-b72c-18377556e7d1",
      "name": "05 | Filter relevant data and add score field",
      "type": "n8n-nodes-base.code",
      "position": [
        496,
        -112
      ],
      "parameters": {
        "jsCode": "const keywords = [\"oil\", \"crude\", \"gold\", \"silver\", \"energy\", \"inflation\", \"gasoline\"];\nconst blacklist = [\"defense\", \"broker\", \"pentagon\"];\n\nreturn items\n  .filter(item => {\n    const text = ((item.json.title || \"\") + \" \" + (item.json.description || \"\")).toLowerCase();\n\n    const isRelevant = keywords.some(k => text.includes(k));\n    const isNoise = blacklist.some(b => text.includes(b));\n\n    return isRelevant && !isNoise;\n  })\n  .map(item => {\n    let score = 0;\n    const text = ((item.json.title || \"\") + \" \" + (item.json.description || \"\")).toLowerCase();\n\n    if (text.includes(\"oil\") || text.includes(\"crude\")) score += 3;\n    if (text.includes(\"inflation\")) score += 2;\n    if (text.includes(\"war\") || text.includes(\"iran\")) score += 3;\n    if (text.includes(\"gasoline\") || text.includes(\"fuel\")) score += 2;\n    if (text.includes(\"record\") || text.includes(\"$100\")) score += 2;\n\n    item.json.score = score;\n    return item;\n  });"
      },
      "typeVersion": 2
    },
    {
      "id": "5464f654-7506-4c35-9d11-671d7dbd6e57",
      "name": "06 | Sort high-value news by score field",
      "type": "n8n-nodes-base.sort",
      "position": [
        720,
        -112
      ],
      "parameters": {
        "options": {},
        "sortFieldsUi": {
          "sortField": [
            {
              "order": "descending",
              "fieldName": "score"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1067e17d-00fb-44ad-bcf7-136bc8bc80b2",
      "name": "07 | Limit - Top 3 items",
      "type": "n8n-nodes-base.limit",
      "position": [
        944,
        -112
      ],
      "parameters": {
        "maxItems": 3
      },
      "typeVersion": 1
    },
    {
      "id": "c2519ebb-5409-4f50-b702-742f3268b9d3",
      "name": "08 | Transform - Combine News Text",
      "type": "n8n-nodes-base.code",
      "position": [
        1168,
        -112
      ],
      "parameters": {
        "jsCode": "const combined = items.map((item, i) => {\n  return `${i+1}. ${item.json.title}\\n${item.json.description}`;\n}).join(\"\\n\\n\");\n\nreturn [{ json: { news: combined } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "8f3be482-bce3-4d65-9443-5b094140b6c8",
      "name": "09 | Gemini for User friendly answer",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "onError": "continueErrorOutput",
      "position": [
        1392,
        -112
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-flash-latest",
          "cachedResultName": "models/gemini-flash-latest"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a professional commodity market analyst.\n\nFrom the following news, create a daily investment briefing.\n\nRules:\n- Pick top 3 insights\n- Focus on oil, gold, fuel, inflation, macro trends\n- Explain WHY markets are moving\n- Include current price of mentioned commodities (if available in news or context)\n- If price is mentioned, highlight it as supporting evidence\n- If exact price is not available, mention trend (rising/falling)\n- Keep it simple and actionable\n- No emojis\n\nNews:\n{{$json.news}}\n\nOutput Format:\n\n1. Key Drivers:\n- Include events + price references (e.g., \"Oil crossed $100\")\n\n2. Market Impact:\n- Explain impact with price context\n\n3. Investor Action:\n- Actionable steps\n\n4. Supporting Data:\n- Commodity prices (Oil, Gold, etc.)\n- % change or trend (if available)"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "3e0641e0-6d67-43bb-b0e8-4e6e74066a83",
      "name": "10 | Create User friendly message for slack",
      "type": "n8n-nodes-base.code",
      "position": [
        1744,
        -208
      ],
      "parameters": {
        "jsCode": "return [{\n  subject: `Commodity Alert:`,\n  message: `\n${$input.first().json.content.parts[0].text}\n  `\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "87d927a3-5420-4ed1-8f81-c4832efb08c7",
      "name": "11 | Send a message to slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1968,
        -208
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AP6AD7069",
          "cachedResultName": "all-group-d"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "bdb04628-be94-4545-b025-220edd53f0d9",
      "name": "12 | Send error notification to slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        48,
        80
      ],
      "parameters": {
        "text": "System Alert: Unable to retrieve fresh market data.  Possible Reasons: - Source temporarily unavailable - Network or API timeout - Data provider rate limit reached",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AP6AD7069",
          "cachedResultName": "all-group-d"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "77418b7f-23d5-4aca-9332-81bfbf0fd1da",
      "name": "13 | Send a error notification to slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1744,
        -16
      ],
      "parameters": {
        "text": "System Alert: Unable to retrieve fresh market data.  Possible Reasons: - Source temporarily unavailable - Network or API timeout - Data provider rate limit reached",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AP6AD7069",
          "cachedResultName": "all-group-d"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "af19617b-f63b-420a-abea-d8a00891c807",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1088,
        -704
      ],
      "parameters": {
        "width": 704,
        "height": 368,
        "content": "## How It Works\nThe workflow monitors commodity-related financial news using RSS feeds (such as oil, gold, and macroeconomic updates). It processes incoming articles by filtering for relevant topics like crude oil, gold, silver, and inflation while removing noise and duplicates. The most important news items are then analyzed using OpenAI to determine their impact on commodity investors. The AI generates a concise, actionable investment briefing explaining key market drivers, potential impact, and suggested actions. Finally, the formatted summary is sent as an alert via email.\n\n## Setup steps\n1. Import the workflow into n8n  \n2. Replace Manual Trigger with a **Schedule Trigger (e.g., daily at 8 AM)**  \n3. Add your **Google Gemini API credentials (Google AI Studio)**  \n4. Connect your **Slack credentials**  \n5. Activate the workflow  "
      },
      "typeVersion": 1
    },
    {
      "id": "f2ed25e8-2534-40ca-9196-3491ac7df68b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        224,
        -384
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 432,
        "content": "## Data cleaning & filtering\n\nThis section improves data quality:\n- remove duplicate news (same titles)\n- filter only important topics (crypto, inflation, market, fed, oil)\n- reduce noise and irrelevant content\n\ngoal: keep only high-signal financial insights"
      },
      "typeVersion": 1
    },
    {
      "id": "1ab3a3a1-c343-4ce6-8637-8a20f9dcddc3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        -384
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 432,
        "content": "## Filter\n\nThis section improves data quality:\n- remove duplicate news (same titles)\n- filter only important topics (crypto, inflation, market, fed, oil)\n- reduce noise and irrelevant content\n\ngoal: keep only high-signal financial insights"
      },
      "typeVersion": 1
    },
    {
      "id": "108e932a-552d-498d-a044-651c7a2a8d1e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1360,
        -496
      ],
      "parameters": {
        "color": 7,
        "width": 944,
        "height": 672,
        "content": "## AI analyzing & response delivery\n\nThis section converts raw news into actionable insights:\n- combine into structured input\n- ai generates daily wealth brief\n- format output for readability\n- send to slack channel\n\nfallback: send error message if ai fails"
      },
      "typeVersion": 1
    },
    {
      "id": "f89cbde1-a616-497d-906b-7fcec756ed49",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -496
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 736,
        "content": "## Data collection from RSS\n\nThis section fetches financial news from trusted sources:\n- CNBC News \u2192 oil, gold, and macroeconomic updates\n\ngoal: collect diverse, high-quality financial data for analysis"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "808fb30c-af1f-4ffc-9009-74fee5b23cb9",
  "connections": {
    "07 | Limit - Top 3 items": {
      "main": [
        [
          {
            "node": "08 | Transform - Combine News Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "02 | Fetch - CNBC News RSS": {
      "main": [
        [
          {
            "node": "03 | Retrieve only required field",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "12 | Send error notification to slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "03 | Retrieve only required field": {
      "main": [
        [
          {
            "node": "04 | Clean - Remove Duplicate News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "04 | Clean - Remove Duplicate News": {
      "main": [
        [
          {
            "node": "05 | Filter relevant data and add score field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "08 | Transform - Combine News Text": {
      "main": [
        [
          {
            "node": "09 | Gemini for User friendly answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "01 | Click to start execute workflow": {
      "main": [
        [
          {
            "node": "02 | Fetch - CNBC News RSS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "09 | Gemini for User friendly answer": {
      "main": [
        [
          {
            "node": "10 | Create User friendly message for slack",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "13 | Send a error notification to slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "06 | Sort high-value news by score field": {
      "main": [
        [
          {
            "node": "07 | Limit - Top 3 items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "10 | Create User friendly message for slack": {
      "main": [
        [
          {
            "node": "11 | Send a message to slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "05 | Filter relevant data and add score field": {
      "main": [
        [
          {
            "node": "06 | Sort high-value news by score field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}