{
  "id": "5pnfN8HhmPsRlM1Z",
  "name": "Smart Trade Alert Dispatcher for Slack & Telegram",
  "tags": [],
  "nodes": [
    {
      "id": "993121a7-0a99-4a32-a758-9a76a9df7639",
      "name": "Workflow Error Handler",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        -544,
        848
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "78fdedaa-8b2c-498a-8b56-897cfc30f335",
      "name": "Send a message1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -192,
        848
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=\ud83d\udea8 *Workflow Error Alert*  *Error Node:* {{ $json.node.name }} *Error Message:* {{ $json.error.message }} *Timestamp:* {{ $now.toISO() }}  Please investigate immediately.",
        "options": {},
        "subject": "Workflow Error Alert",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e3b414e6-21d4-4fd0-84e6-e288eea17843",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -624,
        688
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 336,
        "content": "## Error Handling\nSends alerts when the workflow fails\n"
      },
      "typeVersion": 1
    },
    {
      "id": "40fe87cb-d337-4c3c-bef8-09cc714538be",
      "name": "Overview Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1536,
        -768
      ],
      "parameters": {
        "width": 674,
        "height": 448,
        "content": "## \ud83d\udcca Smart Trade Alert Dispatcher for Slack & Telegram\n\n### How it works\nThis workflow monitors Apple stock (AAPL) in real-time using RSI indicators and price data from TwelveData API. It analyzes momentum patterns, detects oversold/overbought conditions, and uses GPT-4 to generate human-readable market summaries. High-priority signals trigger immediate Telegram alerts, while lower-priority updates go to Slack.\n\n### Setup steps\n1. Add your TwelveData API key to both HTTP Request nodes\n2. Configure OpenAI credentials for the AI agent\n3. Connect Telegram and Slack accounts\n4. Update Telegram chat ID and Slack channel ID\n5. Adjust the schedule trigger interval (default: every minute)\n6. Test with manual execution before enabling schedule\n\n**Use case**: Perfect for traders who want automated technical analysis alerts without constantly watching charts."
      },
      "typeVersion": 1
    },
    {
      "id": "75bfec43-ce06-4d01-a832-cd24efb737e4",
      "name": "Data Collection Section",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -592,
        -384
      ],
      "parameters": {
        "color": 7,
        "width": 620,
        "height": 880,
        "content": "## \ud83d\udce1 Data Collection\nFetches real-time AAPL data from TwelveData API:\n- RSI (14-period, 5min intervals) for momentum\n- Price quotes with volume metrics\n\nBoth requests run in parallel for efficiency, then merge into a single data stream."
      },
      "typeVersion": 1
    },
    {
      "id": "1cea4fab-9245-4720-84c6-94b8dee55b13",
      "name": "Signal Processing Section",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        64,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 608,
        "content": "## \ud83e\uddee Signal Processing\nCalculates trading signals by:\n- Classifying momentum (oversold/overbought)\n- Comparing volume vs average\n- Determining action: PREPARE_BUY, WATCH, or WAIT\n\nOutputs structured data for AI analysis."
      },
      "typeVersion": 1
    },
    {
      "id": "373156cb-ecd6-4911-bc2f-e6be1be7b333",
      "name": "AI Analysis Section",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        352,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 848,
        "content": "## \ud83e\udd16 AI Market Analysis\nGPT-4 transforms raw signals into professional market updates using:\n- Clear bullet-point formatting\n- Neutral, factual language\n- No exaggeration or financial advice\n\nProduces Slack-ready summaries for quick decision-making."
      },
      "typeVersion": 1
    },
    {
      "id": "1d4af6fa-fcb1-43ab-928f-8c214fe2595b",
      "name": "Alerts Section",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 656,
        "height": 752,
        "content": "## \ud83d\udea8 Priority Routing & Alerts\nCalculates alert priority based on RSI + volume:\n- **HIGH**: RSI <30 + high volume \u2192 Telegram\n- **MEDIUM/LOW**: Other conditions \u2192 Slack\n\nEnsures critical signals reach you instantly while filtering noise."
      },
      "typeVersion": 1
    },
    {
      "id": "c67da394-3a8c-400c-8106-0d99312837b2",
      "name": "Security Notice",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1728,
        176
      ],
      "parameters": {
        "color": 3,
        "width": 380,
        "height": 180,
        "content": "## \ud83d\udd10 Security & API Keys\n**Required credentials:**\n- TwelveData API (free tier available)\n- OpenAI API for GPT-4\n- Telegram Bot Token\n- Slack OAuth2\n\nRemove all personal IDs before sharing this template."
      },
      "typeVersion": 1
    },
    {
      "id": "66707290-9f75-4eb4-a163-b4b0d93678f2",
      "name": "Fetch RSI Indicator",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -432,
        -160
      ],
      "parameters": {
        "url": "https://api.twelvedata.com/rsi?symbol=AAPL&interval=5min&time_period=14&apikey=YOUR_TOKEN_HERE",
        "options": {}
      },
      "typeVersion": 4.3
    },
    {
      "id": "2563d043-770e-4d3d-895f-a7b947588c57",
      "name": "Fetch Price & Volume Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -432,
        208
      ],
      "parameters": {
        "url": "https://api.twelvedata.com/quote?symbol=AAPL&apikey=YOUR_TOKEN_HERE",
        "options": {}
      },
      "typeVersion": 4.3
    },
    {
      "id": "a3f1670c-aa4f-46cd-b217-d4e91591da16",
      "name": "Merge API Responses",
      "type": "n8n-nodes-base.merge",
      "position": [
        -96,
        16
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "1ee35512-7dea-49fa-a05e-f038666e2ff7",
      "name": "Calculate Trading Signals",
      "type": "n8n-nodes-base.code",
      "position": [
        160,
        16
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// --- Extract RSI ---\nconst rsiItem = items.find(i => i.json.meta?.indicator?.name?.includes(\"RSI\"));\nconst rsi = rsiItem ? Number(rsiItem.json.values[0].rsi) : null;\n\n// --- Extract Price Data ---\nconst priceItem = items.find(i => i.json.symbol);\nconst price = priceItem ? Number(priceItem.json.close) : null;\nconst volume = priceItem ? Number(priceItem.json.volume) : null;\nconst avgVolume = priceItem ? Number(priceItem.json.average_volume) : null;\n\n// --- Momentum Classification ---\nlet momentum = \"UNKNOWN\";\nif (rsi !== null) {\n  if (rsi < 30) momentum = \"OVERSOLD\";\n  else if (rsi < 35) momentum = \"NEAR_OVERSOLD\";\n  else if (rsi < 60) momentum = \"NEUTRAL\";\n  else if (rsi < 70) momentum = \"NEAR_OVERBOUGHT\";\n  else momentum = \"OVERBOUGHT\";\n}\n\n// --- Volume Signal ---\nconst volumeSignal =\n  volume && avgVolume && volume > avgVolume\n    ? \"HIGH_VOLUME\"\n    : \"NORMAL_VOLUME\";\n\n// --- Final Action ---\nlet action = \"WAIT\";\nif (momentum === \"OVERSOLD\") action = \"PREPARE_BUY\";\nelse if (momentum === \"NEAR_OVERSOLD\") action = \"WATCH\";\n\n// --- Output ---\nreturn [{\n  json: {\n    symbol: priceItem.json.symbol,\n    price,\n    rsi,\n    momentum,\n    volume,\n    avgVolume,\n    volumeSignal,\n    action\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "e8aabe3d-ff94-4456-bcf9-84acc00807c0",
      "name": "Generate AI Summary",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        448,
        16
      ],
      "parameters": {
        "text": "=Create a Slack-ready market update using the signal data below.\n\nUse:\n\u2022 A short title\n\u2022 Bullet points (\u2022)\n\u2022 A bold Action line\n\u2022 No markdown headers (###)\n\nData:\nSymbol: {{$json.symbol}}\nPrice: {{$json.price}}\nRSI: {{$json.rsi}}\nMomentum: {{$json.momentum}}\nVolume: {{$json.volume}}\nAverage Volume: {{$json.avgVolume}}\nVolume Signal: {{$json.volumeSignal}}\nAction: {{$json.action}}\n",
        "options": {
          "maxIterations": 30,
          "systemMessage": "You are a professional market analysis assistant.\nYour task is to convert structured trading signals into short, clear, and professional summaries for managers.\nBe concise, neutral, and factual.\nDo NOT give financial advice.\nDo NOT exaggerate.\nFocus on signal interpretation and recommended monitoring action.\n"
        },
        "promptType": "define"
      },
      "typeVersion": 3
    },
    {
      "id": "66916e79-e8d7-4aca-96ac-466a7cabacce",
      "name": "OpenAI GPT-4 Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        432,
        304
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {},
        "responsesApiEnabled": false
      },
      "typeVersion": 1.3
    },
    {
      "id": "22fa88f8-9642-4296-9cdb-dd56859a5905",
      "name": "Assign Alert Priority",
      "type": "n8n-nodes-base.code",
      "position": [
        800,
        16
      ],
      "parameters": {
        "jsCode": "const { rsi, volumeSignal, action } = $json;\n\nlet priority = \"LOW\";\n\nif (rsi < 30 && volumeSignal === \"HIGH_VOLUME\") {\n  priority = \"HIGH\";\n} else if (rsi < 40 || volumeSignal === \"HIGH_VOLUME\") {\n  priority = \"MEDIUM\";\n}\n\nreturn [{\n  json: {\n    ...$json,\n    priority\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "c71b4fe8-9351-414f-b583-20aa45f68268",
      "name": "Route by Priority",
      "type": "n8n-nodes-base.if",
      "position": [
        1120,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "371238d2-805a-4584-b073-052140434bdd",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.priority }}",
              "rightValue": "HIGH"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "4dec4c2a-3463-4370-823e-3e0d64b5933e",
      "name": "Send to Slack (Low Priority)",
      "type": "n8n-nodes-base.slack",
      "position": [
        1424,
        144
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_SLACK_CHANNEL_ID",
          "cachedResultName": "trading-alerts"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.4
    },
    {
      "id": "49ea04be-b7ac-4cc3-ab77-344d40577acc",
      "name": "Send to Telegram (High Priority)",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1424,
        -96
      ],
      "parameters": {
        "text": "=\ud83d\udea8 *Trade Alert \u2013 {{$json.priority}} Priority*\n\n{{$json.output}}\n\n_Action:_ {{$json.action}}\n",
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f173ecd5-67a7-4e68-8dde-b25bd7325b2c",
      "name": "Schedule Trigger1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -816,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.3
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6a2bc643-09db-4842-82e6-7b064f1921c5",
  "connections": {
    "Route by Priority": {
      "main": [
        [
          {
            "node": "Send to Telegram (High Priority)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send to Slack (Low Priority)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "Fetch Price & Volume Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch RSI Indicator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4 Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate AI Summary",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Fetch RSI Indicator": {
      "main": [
        [
          {
            "node": "Merge API Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate AI Summary": {
      "main": [
        [
          {
            "node": "Assign Alert Priority",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge API Responses": {
      "main": [
        [
          {
            "node": "Calculate Trading Signals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Assign Alert Priority": {
      "main": [
        [
          {
            "node": "Route by Priority",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Error Handler": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Trading Signals": {
      "main": [
        [
          {
            "node": "Generate AI Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Price & Volume Data": {
      "main": [
        [
          {
            "node": "Merge API Responses",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}