8
n8n 中文网amn8n.com

使用机器人自动化Telegram频道帖子反应

高级

这是一个Social Media, AI Summarization领域的自动化工作流,包含 18 个节点。主要使用 Code, Wait, Limit, Telegram, HttpRequest 等节点。 使用机器人轮换和GPT-5-mini自动化Telegram频道帖子反应

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "RsybQdZr1cZ42ZUS",
  "meta": {
    "instanceId": "cefd6d3f9b3c9061f776a00a00144ec1f1ee1977ad3cb7e49aee2e6213fb1e99"
  },
  "name": "使用机器人自动化 Telegram 频道帖子的反应",
  "tags": [],
  "nodes": [
    {
      "id": "34abb54f-61b7-49b9-b310-e344412e7bfa",
      "name": "便签 - Telegram",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        256
      ],
      "parameters": {
        "color": 4,
        "width": 284,
        "height": 708,
        "content": "## 📱 Telegram 触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "d837ab73-8310-4a77-a223-a1d6e5026f55",
      "name": "便利贴 - AI",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        256
      ],
      "parameters": {
        "color": 5,
        "width": 300,
        "height": 704,
        "content": "## 🤖 AI 分析"
      },
      "typeVersion": 1
    },
    {
      "id": "85bedd07-591e-4980-9cee-19b2bb90684b",
      "name": "便利贴 - 处理",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        256
      ],
      "parameters": {
        "color": 6,
        "width": 444,
        "height": 712,
        "content": "## 🔧 数据处理"
      },
      "typeVersion": 1
    },
    {
      "id": "1372c0e3-7635-475f-a122-43875c00b931",
      "name": "便利贴 - 调试",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        992
      ],
      "parameters": {
        "color": 3,
        "width": 444,
        "height": 360,
        "content": "## 🔍 调试记录器"
      },
      "typeVersion": 1
    },
    {
      "id": "5a9b74b8-4163-4fb0-8897-bf5174414542",
      "name": "便利贴 - 循环",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        256
      ],
      "parameters": {
        "color": 7,
        "width": 260,
        "height": 712,
        "content": "## 🔄 批处理器"
      },
      "typeVersion": 1
    },
    {
      "id": "40ead69f-71b1-4d77-8529-33366d97eb79",
      "name": "便利贴 - HTTP",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        672
      ],
      "parameters": {
        "color": 2,
        "width": 408,
        "height": 552,
        "content": "## 🚀 发送反应"
      },
      "typeVersion": 1
    },
    {
      "id": "d7eca245-b056-4319-b54f-dae533dc2c63",
      "name": "便利贴 - 速率限制",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        144
      ],
      "parameters": {
        "width": 408,
        "height": 520,
        "content": "## ⏱️ 速率限制"
      },
      "typeVersion": 1
    },
    {
      "id": "b785f071-8a2a-46a7-88de-67e61b94b1e4",
      "name": "便利贴 - 完成",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        144
      ],
      "parameters": {
        "color": 4,
        "width": 324,
        "height": 528,
        "content": "## ✅ 完成"
      },
      "typeVersion": 1
    },
    {
      "id": "4d93e8bb-273f-4540-9f5c-67acaf4b5164",
      "name": "便签 - 概览",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1552,
        256
      ],
      "parameters": {
        "color": 5,
        "width": 464,
        "height": 864,
        "content": "## 📋 工作流概览"
      },
      "typeVersion": 1
    },
    {
      "id": "5592fc81-7eb0-49a1-bcad-db982a1c403a",
      "name": "HTTP 请求",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        608,
        1072
      ],
      "parameters": {
        "url": "=https://api.telegram.org/bot{{ $json.botToken }}/setMessageReaction",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"chat_id\": \"{{ $json.chatId }}\",\n  \"message_id\": {{ $json.messageId }},\n  \"reaction\": [\n    {\n      \"type\": \"emoji\",\n      \"emoji\": \"{{ $json.emoji }}\"\n    }\n  ]\n}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.2
    },
    {
      "id": "de82667b-a207-4325-8db6-4b04d44ddaa9",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        176,
        672
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "260abb47-d3da-4115-b585-9e66c743f9d3",
      "name": "限制",
      "type": "n8n-nodes-base.limit",
      "position": [
        528,
        480
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "195cbb5d-2262-487c-b5e1-aa2591bad249",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        688,
        480
      ],
      "webhookId": "f333b15c-cfcd-4fdd-b0ca-13862c0617ba",
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "1a067cb4-5370-4d0d-b961-35658fa32176",
      "name": "Telegram 聊天触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -912,
        672
      ],
      "webhookId": "1f47b780-9aa6-4a3e-8373-ede6782af16d",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "4pXtgu0iWtP3aT8Y",
          "name": "n8ntesterbot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "21d9e004-8b32-428f-ad10-a9486bda6652",
      "name": "回复\"全部完成\"消息",
      "type": "n8n-nodes-base.telegram",
      "position": [
        992,
        480
      ],
      "webhookId": "b0818ee4-1727-4954-a8bc-7677800f4400",
      "parameters": {
        "text": "All done!",
        "chatId": "={{ $('Telegram Chat Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "4pXtgu0iWtdemo",
          "name": "n8ntestbot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fef6fa46-d0a0-4767-a092-594afd468205",
      "name": "向模型发送消息",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -656,
        672
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini-2025-08-07",
          "cachedResultName": "GPT-5-MINI-2025-08-07"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "={{ $json.message.text }}"
            },
            {
              "role": "system",
              "content": "=You are a Telegram Reaction Army AI assistant. Your job is to analyze incoming Telegram messages and extract reaction requests.\n\nThe user will provide:\n1. A Telegram message link (e.g., https://t.me/channelname/123)\n2. The number and type of reactions they want\n\nTASK:\n1. Read the user's message carefully\n2. Extract the NUMBER of reactions requested\n3. Check if the user specified PARTICULAR emojis or types\n4. Generate the exact emojis based on their request\n\nAVAILABLE EMOJIS:\n👍, 👎, ❤️, 🔥, 🥰, 👏, 😁, 🤔, 🤯, 😱, 🤬, 😢, 🎉, 🤩, 🤮, 💩, 🙏, 👌, 🕊, 🤡, 🥱, 🥴, 😍, 🐳, ❤️‍🔥, 🌚, 🌭, 💯, 🤣, ⚡️, 🍌, 🏆, 💔, 🤨, 😐, 🍓, 🍾, 💋, 🖕, 😈, 😴, 😭, 🤓, 👻, 👨‍💻, 👀, 🎃, 🙈, 😇, 😨, 🤝, ✍️, 🤗, 🫡, 🎅, 🎄, ☃️, 💅, 🤪, 🗿, 🆒, 💘, 🙉, 🦄, 😘, 💊, 🙊, 😎, 👾, 🤷‍♂️, 🤷, 🤷‍♀️, 😡\n\nEMOJI ALIASES (understand these as the emojis):\n- \"fire\" = 🔥\n- \"heart\" or \"love\" = ❤️\n- \"thumbs up\" or \"like\" = 👍\n- \"party\" or \"celebrate\" = 🎉\n- \"clap\" or \"applause\" = 👏\n- \"thinking\" = 🤔\n- \"crying\" or \"sad\" = 😢\n- \"100\" or \"hundred\" = 💯\n- \"rocket\" or \"lightning\" = ⚡️\n- \"trophy\" or \"winner\" = 🏆\n- \"pray\" or \"please\" = 🙏\n- \"poop\" or \"shit\" = 💩\n- \"angry\" or \"mad\" = 😡\n- \"cool\" or \"sunglasses\" = 😎\n- \"shocked\" or \"mind blown\" = 🤯\n- \"laugh\" or \"laughing\" = 🤣\n\nSPECIFIC REQUEST HANDLING:\n- If user requests specific emojis (e.g., \"5 fire emojis\", \"give me 3 hearts\"), use ONLY that emoji repeated\n- If user mentions multiple specific emojis (e.g., \"2 fire and 3 hearts\"), give exactly what they asked\n- If user says \"random\" or doesn't specify, give random different emojis\n- If the requested emoji is not in the available list, use the closest match or random emojis\n\nOUTPUT FORMAT (CRITICAL):\nYou MUST respond with ONLY a valid JSON array of emoji strings. Nothing else.\n\nExample inputs and outputs:\n\nInput: \"hey reaction army AI i need 5 reactions for my most recent post\"\nOutput: [\"🔥\", \"❤️\", \"😂\", \"👍\", \"🎉\"]\n\nInput: \"give me 5 fire emojis\"\nOutput: [\"🔥\", \"🔥\", \"🔥\", \"🔥\", \"🔥\"]\n\nInput: \"please give me 3 hearts and 2 fire\"\nOutput: [\"❤️\", \"❤️\", \"❤️\", \"🔥\", \"🔥\"]\n\nInput: \"i need 7 thumbs up reactions\"\nOutput: [\"👍\", \"👍\", \"👍\", \"👍\", \"👍\", \"👍\", \"👍\"]\n\nInput: \"reaction army! give me 4 party emojis and 2 claps\"\nOutput: [\"🎉\", \"🎉\", \"🎉\", \"🎉\", \"👏\", \"👏\"]\n\nInput: \"10 random reactions please\"\nOutput: [\"🔥\", \"❤️\", \"😎\", \"🏆\", \"💯\", \"🤯\", \"👍\", \"🎉\", \"😁\", \"⚡️\"]\n\nInput: \"5 fire and 5 hearts\"\nOutput: [\"🔥\", \"🔥\", \"🔥\", \"🔥\", \"🔥\", \"❤️\", \"❤️\", \"❤️\", \"❤️\", \"❤️\"]\n\nRULES:\n- Always output valid JSON array format\n- Each emoji must be a separate string in the array\n- For specific emoji requests, repeat the SAME emoji the requested number of times\n- For mixed requests, follow the exact quantities specified\n- Randomly select emojis ONLY when user doesn't specify which ones\n- If the number cannot be determined, default to 5 reactions\n- Output ONLY the JSON array, no explanations or additional text\n- When repeating emojis, it's OK to have duplicates if that's what the user requested"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "RuZBazyPEFrpp0nP",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "547b3785-236b-4bf9-9cce-8cbe796ea5ba",
      "name": "代码准备",
      "type": "n8n-nodes-base.code",
      "position": [
        -304,
        832
      ],
      "parameters": {
        "jsCode": "// Get the AI response\nconst aiResponse = $input.first().json;\n\n\n// Try to get Telegram input (handle if not executed yet)\nlet telegramInput;\ntry {\n  telegramInput = $('Telegram Chat Trigger').first().json;\n} catch (e) {\n  throw new Error(\"Please trigger the workflow by sending a message to the Telegram bot first!\");\n}\n\nlet emojis = [];\nlet messageId = null;\nlet chatId = \"-1006781233333\"; // Your public channel ID\n\n// Valid Telegram reaction emojis\nconst validEmojis = [\n  \"👍\", \"👎\", \"❤️\", \"🔥\", \"🥰\", \"👏\", \"😁\", \"🤔\", \n  \"🤯\", \"😱\", \"🤬\", \"😢\", \"🎉\", \"🤩\", \"🤮\", \"💩\",\n  \"🙏\", \"👌\", \"🕊\", \"🤡\", \"🥱\", \"🥴\", \"😍\", \"🐳\",\n  \"❤️‍🔥\", \"🌚\", \"🌭\", \"💯\", \"🤣\", \"⚡️\", \"🍌\", \"🏆\",\n  \"💔\", \"🤨\", \"😐\", \"🍓\", \"🍾\", \"💋\", \"🖕\", \"😈\",\n  \"😴\", \"😭\", \"🤓\", \"👻\", \"👨‍💻\", \"👀\", \"🎃\", \"🙈\",\n  \"😇\", \"😨\", \"🤝\", \"✍️\", \"🤗\", \"🫡\", \"🎅\", \"🎄\",\n  \"☃️\", \"💅\", \"🤪\", \"🗿\", \"🆒\", \"💘\", \"🙉\", \"🦄\",\n  \"😘\", \"💊\", \"🙊\", \"😎\", \"👾\", \"🤷‍♂️\", \"🤷\", \"🤷‍♀️\",\n  \"😡\"\n];\n\n// ADD YOUR BOT TOKENS HERE\nconst botTokens = [\n  \"8241237833:AAEbJbNx4-9rTAHJZ_yaShzbqCRwUoD-I3U\",  // replace with your own token\n  \"8339530330:AAG8EYMN1lLKK2yhmxl2fkFlQlKbc-lkuY\",   // replace with your own token\n  \"8333742303:AA1kuLLW1x3WTN2i-9v8xXfjXZ2TSB_i1j\"    // replace with your own token\n];\n\n// Get the original message text from user\nconst userMessage = telegramInput.message?.text || \"\";\n\n// Extract message ID from Telegram link\nconst telegramLinkMatch = userMessage.match(/t\\.me\\/[^\\/]+\\/(\\d+)/i);\nconst messageNumberMatch = userMessage.match(/message\\s+(\\d+)|post\\s+(\\d+)/i);\n\nif (telegramLinkMatch) {\n  messageId = parseInt(telegramLinkMatch[1]);\n} else if (messageNumberMatch) {\n  messageId = parseInt(messageNumberMatch[1] || messageNumberMatch[2]);\n}\n\n// Extract emojis from AI response\nfunction extractArray(str) {\n  if (typeof str !== 'string') return null;\n  const match = str.match(/\\[[\\s\\S]*?\\]/);\n  if (match) {\n    try {\n      return JSON.parse(match[0]);\n    } catch (e) {\n      return null;\n    }\n  }\n  return null;\n}\n\nif (aiResponse.message && aiResponse.message.content) {\n  const content = aiResponse.message.content;\n  emojis = extractArray(content);\n}\nelse if (aiResponse.message && typeof aiResponse.message === 'string') {\n  emojis = extractArray(aiResponse.message);\n}\nelse if (aiResponse.output) {\n  if (typeof aiResponse.output === 'string') {\n    emojis = extractArray(aiResponse.output);\n  } else if (Array.isArray(aiResponse.output)) {\n    emojis = aiResponse.output;\n  }\n}\nelse if (Array.isArray(aiResponse)) {\n  emojis = aiResponse;\n}\nelse if (aiResponse.choices && aiResponse.choices[0]?.message?.content) {\n  const content = aiResponse.choices[0].message.content;\n  emojis = extractArray(content);\n}\n\nif (!Array.isArray(emojis) || emojis.length === 0) {\n  emojis = [\"👍\", \"❤️\", \"🔥\"];\n}\n\n// If no message ID found, throw helpful error\nif (!messageId) {\n  throw new Error(\"❌ Please provide a Telegram message link!\\n\\nExample:\\nhttps://t.me/n8nTesterChannel/62 needs 5 reactions please\");\n}\n\n// Validate emojis\nfunction getRandomValidEmoji(exclude = []) {\n  const available = validEmojis.filter(e => !exclude.includes(e));\n  return available[Math.floor(Math.random() * available.length)];\n}\n\nconst uniqueEmojis = [...new Set(emojis)];\nconst allowDuplicates = uniqueEmojis.length <= 3;\n\nconst requestedCount = emojis.length;\nconst validatedEmojis = [];\nconst usedEmojis = new Set();\n\nfor (let emoji of emojis) {\n  const cleaned = emoji.trim();\n  \n  if (validEmojis.includes(cleaned)) {\n    if (allowDuplicates) {\n      validatedEmojis.push(cleaned);\n    } \n    else if (!usedEmojis.has(cleaned)) {\n      validatedEmojis.push(cleaned);\n      usedEmojis.add(cleaned);\n    } else {\n      let replacement = getRandomValidEmoji([...usedEmojis]);\n      validatedEmojis.push(replacement);\n      usedEmojis.add(replacement);\n    }\n  } else {\n    let replacement = getRandomValidEmoji([...usedEmojis]);\n    validatedEmojis.push(replacement);\n    if (!allowDuplicates) {\n      usedEmojis.add(replacement);\n    }\n  }\n}\n\nwhile (validatedEmojis.length < requestedCount) {\n  let newEmoji = getRandomValidEmoji([...usedEmojis]);\n  validatedEmojis.push(newEmoji);\n  usedEmojis.add(newEmoji);\n}\n\n// Output with message ID and chat ID\nconst output = validatedEmojis.map((emoji, index) => ({\n  emoji: emoji,\n  botToken: botTokens[index % botTokens.length],\n  chatId: chatId,\n  messageId: messageId\n}));\n\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "cd448fc1-a9da-4119-b9bd-812cd7d6e521",
      "name": "调试",
      "type": "n8n-nodes-base.code",
      "position": [
        -96,
        832
      ],
      "parameters": {
        "jsCode": "// Debug - check what we're sending\nconst items = $input.all();\n\nconsole.log(\"Total items:\", items.length);\nitems.forEach((item, index) => {\n  console.log(`Item ${index}:`, {\n    emoji: item.json.emoji,\n    chatId: item.json.chatId,\n    messageId: item.json.messageId,\n    botToken: item.json.botToken.substring(0, 20) + \"...\" // Don't log full token\n  });\n});\n\nreturn items;"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "18398cb2-0854-4f07-be6c-d78ee911d8c8",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Reply \"all done\" message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code Prep": {
      "main": [
        [
          {
            "node": "Debugging",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Debugging": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Code Prep",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Chat Trigger": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 社交媒体, AI 摘要总结

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量18
分类2
节点类型9
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流