{
  "id": "kjm0WTQM3an5e7Ng",
  "name": "Send gold and WTI price alerts to Telegram with SiftingIO",
  "tags": [],
  "nodes": [
    {
      "id": "4dea1c3d-8deb-413e-ac0d-6153fe76423c",
      "name": "Workflow overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        144
      ],
      "parameters": {
        "width": 526,
        "height": 548,
        "content": "## Gold & WTI price alerts \u2014 SiftingIO \u2192 Telegram\n\nMonitor **Gold (XAUUSD)** and **WTI crude oil (WTIUSD)** every 15 minutes and send Telegram alerts when your chosen thresholds are crossed.\n\n### Requirements\n- An n8n Cloud workspace\n- A SiftingIO API key\n- A Telegram bot credential\n- A Telegram chat ID\n\nThis template uses only built-in n8n nodes. No community package or hardcoded secret is required.\n\nGet a SiftingIO API key:\nhttps://sifting.io/register?utm_source=n8n&utm_medium=workflow_template&utm_campaign=commodity_price_alerts"
      },
      "typeVersion": 1
    },
    {
      "id": "eea5ea55-0412-4424-8d66-6cc6b5d470fe",
      "name": "SiftingIO setup",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        0
      ],
      "parameters": {
        "width": 356,
        "height": 316,
        "content": "### 1. Connect SiftingIO\n\nCreate one **HTTP Header Auth** credential:\n\n- **Header name:** `X-API-Key`\n- **Header value:** your SiftingIO API key\n\nSelect the same credential in both HTTP Request nodes:\n- **Get gold price**\n- **Get WTI price**"
      },
      "typeVersion": 1
    },
    {
      "id": "4a1517f2-6346-45ac-9426-d3c455e318a8",
      "name": "Threshold setup",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        256,
        0
      ],
      "parameters": {
        "width": 366,
        "height": 332,
        "content": "### 2. Configure alert thresholds\n\nOpen **Check alert thresholds**.\n\nFor the first manual test, keep:\n`TEST_MODE = true`\n\nAfter Telegram receives the test message:\n1. Set `TEST_MODE = false`\n2. Edit the Gold and WTI `above` / `below` values\n3. Save the workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "79bc9d7e-b5ee-45a0-b5fd-9199764f6d2a",
      "name": "Telegram setup",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        0
      ],
      "parameters": {
        "width": 386,
        "height": 336,
        "content": "### 3. Connect Telegram and activate\n\n1. Select or create a Telegram bot credential\n2. Replace `REPLACE_WITH_YOUR_CHAT_ID`\n3. Click **Execute workflow** once\n4. Confirm both API requests succeed and Telegram receives the message\n5. Disable test mode, then activate the workflow\n\nThe workflow imports inactive and contains no credentials or API keys."
      },
      "typeVersion": 1
    },
    {
      "id": "cda4158e-c3f2-461e-8966-d3034c8c29c8",
      "name": "Every 15 minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -384,
        480
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1642ca28-f197-4663-b6e7-ca862b8192d8",
      "name": "Get gold price",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -96,
        368
      ],
      "parameters": {
        "url": "https://api.sifting.io/v1/last/trade/commodities/XAUUSD",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.3
    },
    {
      "id": "45f5958e-21c4-4efa-9d42-32b759f6d710",
      "name": "Get WTI price",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -96,
        608
      ],
      "parameters": {
        "url": "https://api.sifting.io/v1/last/trade/commodities/WTIUSD",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.3
    },
    {
      "id": "78268a2f-2ff4-416a-8f3e-0aacd46ef2d6",
      "name": "Wait for both prices",
      "type": "n8n-nodes-base.merge",
      "position": [
        192,
        480
      ],
      "parameters": {},
      "typeVersion": 3
    },
    {
      "id": "e3337276-6d90-4d21-9221-2b4b5a17ccac",
      "name": "Check alert thresholds",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        480
      ],
      "parameters": {
        "jsCode": "// First run: keep TEST_MODE = true so Telegram receives a test message.\n// After the test succeeds, set it to false and edit the thresholds below.\nconst TEST_MODE = true;\n\nconst thresholds = {\n  XAUUSD: { label: 'Gold', above: 4000, below: 2000 },\n  WTIUSD: { label: 'WTI crude oil', above: 120, below: 40 },\n};\n\nfunction readPrice(payload) {\n  const queue = [payload];\n  while (queue.length) {\n    const current = queue.shift();\n    if (!current || typeof current !== 'object') continue;\n\n    const candidates = [\n      current.p, current.price, current.last, current.last_price,\n      current.c, current.close, current.mid, current.m\n    ];\n    for (const value of candidates) {\n      const n = Number(value);\n      if (Number.isFinite(n)) return n;\n    }\n\n    const bid = Number(current.b ?? current.bid);\n    const ask = Number(current.a ?? current.ask);\n    if (Number.isFinite(bid) && Number.isFinite(ask)) return (bid + ask) / 2;\n\n    for (const key of ['data', 'result', 'trade', 'quote']) {\n      if (current[key] && typeof current[key] === 'object') queue.push(current[key]);\n    }\n  }\n\n  throw new Error(`No numeric price found in response: ${JSON.stringify(payload)}`);\n}\n\nconst rows = [\n  { symbol: 'XAUUSD', payload: $('Get gold price').first().json },\n  { symbol: 'WTIUSD', payload: $('Get WTI price').first().json },\n];\n\nconst alerts = [];\nfor (const row of rows) {\n  const price = readPrice(row.payload);\n  const cfg = thresholds[row.symbol];\n\n  if (TEST_MODE) {\n    alerts.push({\n      symbol: row.symbol,\n      price,\n      message: `SiftingIO test alert\\n${cfg.label} (${row.symbol}): ${price}\\nUTC: ${new Date().toISOString()}`\n    });\n    continue;\n  }\n\n  if (price >= cfg.above) {\n    alerts.push({\n      symbol: row.symbol,\n      price,\n      message: `${cfg.label} alert\\n${row.symbol} is ${price}, at or above ${cfg.above}.\\nUTC: ${new Date().toISOString()}`\n    });\n  } else if (price <= cfg.below) {\n    alerts.push({\n      symbol: row.symbol,\n      price,\n      message: `${cfg.label} alert\\n${row.symbol} is ${price}, at or below ${cfg.below}.\\nUTC: ${new Date().toISOString()}`\n    });\n  }\n}\n\nreturn alerts.map((alert) => ({ json: alert }));"
      },
      "typeVersion": 2
    },
    {
      "id": "a668344c-1299-4fcb-a4f3-2a7b84b123fa",
      "name": "Send Telegram alert",
      "type": "n8n-nodes-base.telegram",
      "maxTries": 3,
      "position": [
        640,
        480
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "chatId": "REPLACE_WITH_YOUR_CHAT_ID",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "retryOnFail": true,
      "typeVersion": 1.2,
      "waitBetweenTries": 1000
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "2a5586ef-f276-4150-8b9f-dad961323492",
  "nodeGroups": [],
  "connections": {
    "Get WTI price": {
      "main": [
        [
          {
            "node": "Wait for both prices",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get gold price": {
      "main": [
        [
          {
            "node": "Wait for both prices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every 15 minutes": {
      "main": [
        [
          {
            "node": "Get gold price",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get WTI price",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for both prices": {
      "main": [
        [
          {
            "node": "Check alert thresholds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check alert thresholds": {
      "main": [
        [
          {
            "node": "Send Telegram alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}