8
n8n 中文网amn8n.com

Telegram自动复制器

高级

这是一个Social Media, Multimodal AI领域的自动化工作流,包含 19 个节点。主要使用 If, Set, Code, Html, Telegram 等节点。 基于GPT-4o-mini的Telegram频道内容自动复制与翻译

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "VjbCxJ8Hgo44WZdf",
  "meta": {
    "instanceId": "f5aa635d637faa7cf397adde51f1a02fdf8ac6454c1c6457738ffd11609a900c"
  },
  "name": "Telegram自动复制器",
  "tags": [],
  "nodes": [
    {
      "id": "aeb0620d-095c-4238-8dd0-0232c4905e19",
      "name": "每日计划",
      "type": "n8n-nodes-base.scheduleTrigger",
      "notes": "Triggers the workflow daily at 9 AM. Adjust the time according to your needs.",
      "position": [
        -1220,
        -60
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3ea234cc-4f02-4216-8013-554eb1fba0fd",
      "name": "获取频道页面",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Fetches the HTML content of the source Telegram channel",
      "position": [
        -780,
        -60
      ],
      "parameters": {
        "url": "=https://t.me/s/{{ $('Set Telegram Channels').item.json.sourceChannel }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "id": "eb0d33be-2e66-43cc-90fa-d1b9878615d9",
      "name": "提取帖子内容",
      "type": "n8n-nodes-base.html",
      "notes": "Extracts text, images, and videos from the latest Telegram post",
      "position": [
        -560,
        -60
      ],
      "parameters": {
        "options": {
          "trimValues": false,
          "cleanUpText": false
        },
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "post",
              "cssSelector": "div.tgme_widget_message_wrap:last-of-type div.js-message_text"
            },
            {
              "key": "postId",
              "cssSelector": "div.tgme_widget_message_wrap:last-of-type div.tgme_widget_message_info span.tgme_widget_message_meta"
            },
            {
              "key": "video",
              "attribute": "src",
              "cssSelector": "div.tgme_widget_message_wrap:last-of-type div.tgme_widget_message_bubble a div.tgme_widget_message_video_wrap > video",
              "returnValue": "attribute"
            },
            {
              "key": "photo",
              "attribute": "style",
              "cssSelector": "div.tgme_widget_message_wrap:last-of-type div.tgme_widget_message_bubble div.media_supported_cont > a.tgme_widget_message_photo_wrap",
              "returnValue": "attribute"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "715418a9-9598-460a-817e-e2b681f336c4",
      "name": "清理帖子内容",
      "type": "n8n-nodes-base.code",
      "notes": "Removes original channel signature and cleans up the text",
      "position": [
        -340,
        -60
      ],
      "parameters": {
        "jsCode": "// Clean up the post content by removing original channel signature\nif ($input.first().json.post) {\n  let cleanPost = $input.first().json.post    \n    .replaceAll($('Set Telegram Channels').first().json.channelSignature, '')\n    .trim();\n  \n  $input.first().json.post = cleanPost;\n}\n\nreturn $input.all();"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "31508b88-fd99-4b7c-abb7-52084caf9373",
      "name": "翻译文本",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "notes": "Uses OpenAI to translate the post content to the target language",
      "position": [
        -120,
        -60
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Translate the following text to {{ $('Set Telegram Channels').item.json.targetLanguage }} in a friendly, natural style.\nReturn only the translated text without any additional commentary or formatting.\n\nText to translate:\n{{ $json.post }}"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "hjq9L6ppDLFMNOcE",
          "name": "OpenAi account"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.8
    },
    {
      "id": "e0017199-a33a-4866-9fa8-3be34fbf20e8",
      "name": "处理媒体 URL",
      "type": "n8n-nodes-base.code",
      "notes": "Extracts clean URLs from CSS style attributes for images",
      "position": [
        256,
        -60
      ],
      "parameters": {
        "jsCode": "// Process photo URL from CSS style attribute\nif ($('Extract Post Content').first().json.photo) {\n  const styleAttr = $('Extract Post Content').first().json.photo;\n  const urlMatch = styleAttr.match(/background-image:url\\('([^']+)'\\)/);\n  \n  if (urlMatch && urlMatch[1]) {\n    $input.first().json.photo = urlMatch[1];\n  } else {\n    // Fallback: try to extract from quotes\n    const arr = styleAttr.split(\"'\");\n    if (arr.length >= 2) {\n      $input.first().json.photo = arr[arr.length - 2];\n    }\n  }\n}\n\nreturn $input.all();"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "8f05161f-776b-4684-9acc-d2cc426ad78c",
      "name": "有照片吗?",
      "type": "n8n-nodes-base.if",
      "notes": "Checks if the post contains a photo",
      "position": [
        476,
        -260
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "202a35e0-040c-47d2-9aaa-2f7d295ac2dd",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.photo }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "70c14a77-b297-4ac2-9ec4-a9d7124b7ce4",
      "name": "有视频吗?",
      "type": "n8n-nodes-base.if",
      "notes": "Checks if the post contains a video",
      "position": [
        476,
        140
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "95dcac89-39c4-4a0a-8c1c-e1c560be755f",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $('Extract Post Content').item.json.video }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "11abbf2e-043b-4129-b15b-f625bb12802a",
      "name": "仅文本?",
      "type": "n8n-nodes-base.if",
      "position": [
        476,
        -60
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7d0504ca-12c6-4496-8879-3f7d295ac2dd",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $('Extract Post Content').item.json.video }}",
              "rightValue": ""
            },
            {
              "id": "3cca8e10-546a-4b42-ac6f-0cc91773949c",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $('Extract Post Content').item.json.photo }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "926e4cca-4028-43bf-98ae-4f1e6f38fc08",
      "name": "下载照片",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Downloads the photo from Telegram servers",
      "position": [
        696,
        -260
      ],
      "parameters": {
        "url": "={{ $json.photo }}",
        "options": {
          "timeout": 30000
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "id": "a2349dfe-45f9-4688-a915-0af0587a0e48",
      "name": "下载视频",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Downloads the video from Telegram servers",
      "position": [
        696,
        140
      ],
      "parameters": {
        "url": "={{ $('Extract Post Content').item.json.video }}",
        "options": {
          "timeout": 60000
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "id": "28a45272-c1a7-44cc-b396-aa40485baf37",
      "name": "发送照片到频道",
      "type": "n8n-nodes-base.telegram",
      "notes": "Sends the translated post with photo to target channel",
      "position": [
        916,
        -260
      ],
      "webhookId": "d72b2e9d-c37c-4bbe-985b-8b1699bce9b3",
      "parameters": {
        "chatId": "={{ $('Set Telegram Channels').item.json.targetChannel }}",
        "operation": "sendPhoto",
        "binaryData": true,
        "additionalFields": {
          "caption": "={{ $json.message.content }}\\n{{ $('Set Telegram Channels').item.json.channelSignature }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "XfNUxlQY3eiC3bFY",
          "name": "TelegramAIWriterBot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "cd3f5b26-0250-4a12-9dec-2b82891b1daf",
      "name": "发送视频到频道",
      "type": "n8n-nodes-base.telegram",
      "notes": "Sends the translated post with video to target channel",
      "position": [
        916,
        140
      ],
      "webhookId": "c532eafe-875d-4ac2-8d77-52f5dd84c3c5",
      "parameters": {
        "chatId": "={{ $('Set Telegram Channels').item.json.targetChannel }}",
        "operation": "sendVideo",
        "binaryData": true,
        "additionalFields": {
          "caption": "={{ $json.message.content }}\\n{{ $('Set Telegram Channels').item.json.channelSignature }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "XCmO6hPfws6PgHMt",
          "name": "TelegramBotCryptoApp"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2737cc48-5c12-442a-8f6f-15a4e77f91c4",
      "name": "发送文本到频道",
      "type": "n8n-nodes-base.telegram",
      "notes": "Sends text-only translated posts to target channel",
      "position": [
        696,
        -60
      ],
      "webhookId": "c58b24f7-3799-4021-be07-fe74705ef7c3",
      "parameters": {
        "text": "={{ $json.message.content }}\\n{{ $('Set Telegram Channels').item.json.channelSignature }}",
        "chatId": "={{ $('Set Telegram Channels').item.json.targetChannel }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9cc2d449-c59a-460f-bb50-236cd914783c",
      "name": "📖 设置说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1400,
        -760
      ],
      "parameters": {
        "width": 500,
        "height": 620,
        "content": "## Telegram 频道内容复制器和翻译器"
      },
      "typeVersion": 1
    },
    {
      "id": "5900c319-3a6f-4057-ab5c-209ceb0d9d61",
      "name": "设置 Telegram 频道",
      "type": "n8n-nodes-base.set",
      "notes": "Configure your source channel, target channel, and other settings here",
      "position": [
        -1000,
        -60
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "source_channel",
              "name": "sourceChannel",
              "type": "string",
              "value": "channel_username"
            },
            {
              "id": "target_channel",
              "name": "targetChannel",
              "type": "string",
              "value": "@channel_username"
            },
            {
              "id": "target_language",
              "name": "targetLanguage",
              "type": "string",
              "value": "Persian"
            },
            {
              "id": "channel_signature",
              "name": "channelSignature",
              "type": "string",
              "value": "@channel_username"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "7902b67b-24f5-4d7b-b54e-85b22e97c073",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1020,
        -200
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 220,
        "content": "## 1. 获取源 Telegram 频道的 HTML 内容"
      },
      "typeVersion": 1
    },
    {
      "id": "5c68259a-a22d-4c35-8bbb-7853233e3cb8",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -180
      ],
      "parameters": {
        "color": 7,
        "width": 360,
        "content": "## 2. 使用 AI 进行翻译"
      },
      "typeVersion": 1
    },
    {
      "id": "56690988-fe75-43b6-9919-2e7d52a66bc6",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        226,
        -420
      ],
      "parameters": {
        "color": 7,
        "width": 600,
        "height": 720,
        "content": "## 3. 提取媒体 URL 并识别媒体类型"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6d57d267-bda4-417a-b3f5-3be54a01e92d",
  "connections": {
    "Has Photo?": {
      "main": [
        [
          {
            "node": "Download Photo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Video?": {
      "main": [
        [
          {
            "node": "Download Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Only?": {
      "main": [
        [
          {
            "node": "Send Text to Channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Schedule": {
      "main": [
        [
          {
            "node": "Set Telegram Channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Photo": {
      "main": [
        [
          {
            "node": "Send Photo to Channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Video": {
      "main": [
        [
          {
            "node": "Send Video to Channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Translate Text": {
      "main": [
        [
          {
            "node": "Process Media URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean Post Content": {
      "main": [
        [
          {
            "node": "Translate Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Channel Page": {
      "main": [
        [
          {
            "node": "Extract Post Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Media URLs": {
      "main": [
        [
          {
            "node": "Has Photo?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Has Video?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Text Only?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Post Content": {
      "main": [
        [
          {
            "node": "Clean Post Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Telegram Channels": {
      "main": [
        [
          {
            "node": "Fetch Channel Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 社交媒体, 多模态 AI

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流