{
  "name": "Telegram channel monitor: new posts to Slack (core nodes only)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 1
            }
          ]
        }
      },
      "id": "c26a55bc-748c-4734-8f39-22b8683c825c",
      "name": "Every hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [0, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/fetchwright~telegram-channel-scraper/run-sync-get-dataset-items?timeout=240&memory=512&maxTotalChargeUsd=0.1",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "{\n  \"channels\": [\"telegram\", \"durov\"],\n  \"maxPostsPerChannel\": 50,\n  \"onlyNewPosts\": true,\n  \"monitorName\": \"n8n-telegram-to-slack-http\",\n  \"includeChannelInfo\": false\n}",
        "options": {
          "timeout": 310000
        }
      },
      "id": "598909d0-b529-4b73-9c83-01d065a245c6",
      "name": "Run Telegram Channel Scraper",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [240, 0]
    },
    {
      "parameters": {
        "jsCode": "// Keep only readable post rows; channel and diagnostic rows are dropped.\n// Escape &, < and > so post text cannot trigger Slack mentions (<!channel>, <@U...>) or fake links.\nconst esc = s => String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\nreturn $input.all()\n  .filter(item => item.json.type === 'post' && item.json.status === 'ok')\n  .map(item => ({\n    json: {\n      postKey: `${item.json.channel}/${item.json.postId}`,\n      channel: esc(item.json.channel),\n      postId: item.json.postId,\n      date: item.json.date,\n      text: esc((item.json.text || '').slice(0, 2500)),\n      url: esc(item.json.url),\n      views: item.json.views,\n      matchedKeywords: (item.json.matchedKeywords || []).join(', '),\n      cashtags: (item.json.cashtags || []).join(', ')\n    }\n  }));"
      },
      "id": "9ae5afd9-7399-4d6d-9171-c44fca860edf",
      "name": "Keep post rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [480, 0]
    },
    {
      "parameters": {
        "authentication": "accessToken",
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#telegram-alerts",
          "mode": "name"
        },
        "messageType": "text",
        "text": "=*{{ $json.channel }}* {{ $json.date }}\n{{ $json.text }}\n{{ $json.url }}",
        "otherOptions": {
          "includeLinkToWorkflow": false,
          "unfurl_links": false
        }
      },
      "id": "ffc835e2-ab88-48aa-bae6-0026f424eccc",
      "name": "Post to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [720, 0]
    },
    {
      "parameters": {
        "content": "## Setup (3 fields)\n1. **Run Telegram Channel Scraper**: under Credential for Header Auth, create a *Header Auth* credential: Name `Authorization`, Value `Bearer ` followed by your Apify API token. Edit `channels` in the JSON body.\n2. **Post to Slack**: select your Slack credential and the channel to post in (default `#telegram-alerts`).\n\nNo community node needed: this calls Apify's run-sync-get-dataset-items endpoint, which waits for the run and returns its rows.\n\n`onlyNewPosts` + `monitorName` make each run return only posts not returned before, so Slack gets each post once. Give each separate workflow its own `monitorName`.\n\nKeyword alerts: add `\"searchQueries\": [\"bitcoin\", \"#update\"]` to the body. Changing filters starts a new watch whose first run returns only the newest posts.\n\nThe synchronous endpoint answers 408 after 300 s; the run is capped at 240 s. If a request fails, open the run in Apify Console: its rows are in the run's dataset and will not be returned again.\n\nCost: $0.30 per 1,000 posts (Apify Free plan) + $0.00005 per run. `maxTotalChargeUsd=0.1` caps one run at $0.10.",
        "height": 480,
        "width": 520,
        "color": 7
      },
      "id": "f22e0d82-1d15-4cc8-a9ba-5b13e82ca0fe",
      "name": "Setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [0, 200]
    }
  ],
  "connections": {
    "Every hour": {
      "main": [
        [
          {
            "node": "Run Telegram Channel Scraper",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Telegram Channel Scraper": {
      "main": [
        [
          {
            "node": "Keep post rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep post rows": {
      "main": [
        [
          {
            "node": "Post to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "pinData": {}
}
