8
n8n 中文网amn8n.com

多用户YouTube摘要器Telegram机器人

中级

这是一个Content Creation, AI Chatbot领域的自动化工作流,包含 14 个节点。主要使用 If, Set, Code, Telegram, HttpRequest 等节点。 多用户Telegram机器人,使用GPT-4o摘要和重新利用YouTube视频

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "WhaOZtqmJ5c3XITs",
  "meta": {
    "instanceId": "dd02248de4c4b9964fc813dc470060def2559fc51a712b5d5a059af028dbc806",
    "templateCredsSetupCompleted": true
  },
  "name": "多用户YouTube摘要器Telegram机器人",
  "tags": [
    {
      "id": "SMT2ut5VYVrJOgut",
      "name": "youtube",
      "createdAt": "2025-06-30T08:40:55.235Z",
      "updatedAt": "2025-06-30T08:40:55.235Z"
    },
    {
      "id": "hph9VLUPCMHpsvSv",
      "name": "openai",
      "createdAt": "2025-06-30T08:39:10.366Z",
      "updatedAt": "2025-06-30T08:39:10.366Z"
    },
    {
      "id": "tUeZKzt938bXg8LF",
      "name": "telegram",
      "createdAt": "2025-06-30T08:41:15.614Z",
      "updatedAt": "2025-06-30T08:41:15.614Z"
    },
    {
      "id": "F5VpnJWM04Me0ZD2",
      "name": "chatbot",
      "createdAt": "2025-06-30T08:41:22.379Z",
      "updatedAt": "2025-06-30T08:41:22.379Z"
    },
    {
      "id": "uABH3QyIGSUmT7AF",
      "name": "rapidapi",
      "createdAt": "2025-06-30T08:41:26.545Z",
      "updatedAt": "2025-06-30T08:41:26.545Z"
    },
    {
      "id": "egtP0LfV8KaAj1YV",
      "name": "multiuser",
      "createdAt": "2025-06-30T08:41:33.986Z",
      "updatedAt": "2025-06-30T08:41:33.986Z"
    },
    {
      "id": "X8lvHiSMCOg8UP1u",
      "name": "transcriptor",
      "createdAt": "2025-06-30T08:41:42.229Z",
      "updatedAt": "2025-06-30T08:41:42.229Z"
    }
  ],
  "nodes": [
    {
      "id": "bd3d13e0-2b23-46d8-ab56-518184f4c23c",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        140,
        500
      ],
      "parameters": {
        "sessionKey": "={{ $('Check: Is YouTube Link?').item.json.message.chat.id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "d22d84d9-2b00-4593-9924-1684ee026fbb",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        -260
      ],
      "parameters": {
        "color": 3,
        "width": 800,
        "height": 440,
        "content": "## 🔗 YouTube链接处理流程"
      },
      "typeVersion": 1
    },
    {
      "id": "1eca3b2c-0b1a-424a-b8c2-d14189818f77",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        180
      ],
      "parameters": {
        "color": 5,
        "width": 800,
        "height": 700,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "b2d752d1-ac81-4a82-a8e9-e4a88ac97cb0",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        -260
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 380,
        "content": "## 🔐 所需API密钥与设置"
      },
      "typeVersion": 1
    },
    {
      "id": "9cdbf9d1-7487-4c56-8f56-c266cc30da3e",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -40,
        500
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "YOUR_OPENAI_API_KEY",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "656df439-1202-45c1-8cab-50835fc8a530",
      "name": "触发器:Telegram机器人消息",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -580,
        160
      ],
      "webhookId": "e19c3a30-9202-4029-855b-486e074df0e3",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "YOUR_TELEGRAMBOT_API_KEY",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7e9b5742-db7b-4fbb-9f46-84ec64640e8e",
      "name": "检查:是否为YouTube链接?",
      "type": "n8n-nodes-base.if",
      "position": [
        -340,
        160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9177ca8c-fa10-4d34-a080-eeddeeec3319",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.message.text }}",
              "rightValue": "https"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "05b27964-d268-46d0-bb08-67650a5a08a7",
      "name": "提取聊天和视频ID",
      "type": "n8n-nodes-base.set",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "9df2601d-3f98-4152-9973-8f1e59585fba",
              "name": "videoId",
              "type": "string",
              "value": "={{ $json[\"message\"][\"text\"].match(/(?:v=|youtu\\.be\\/)([a-zA-Z0-9_-]+)/)[1] }}\n"
            },
            {
              "id": "6b989928-41d0-4913-8f4b-e951a8fa9136",
              "name": "chatId",
              "type": "string",
              "value": "={{ $json[\"message\"][\"chat\"][\"id\"] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "6ec62300-e1b0-44ee-b02e-dd311b3ba0fb",
      "name": "获取YouTube字幕(通过RapidAPI)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        220,
        0
      ],
      "parameters": {
        "url": "=https://youtube-transcript3.p.rapidapi.com/api/transcript?videoId={{ $json.videoId }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-RapidAPI-Key",
              "value": "YOUR_RAPIDAPI_KEY_HERE"
            },
            {
              "name": "X-RapidAPI-Host",
              "value": "YOUR_RAPIDAPI_HOST_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "43eff5c7-3510-489f-86c1-a6d4eddb02d8",
      "name": "清理字幕符号",
      "type": "n8n-nodes-base.set",
      "position": [
        440,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "74c4d613-8154-41e2-90b5-0e837de83a69",
              "name": "fullTranscript",
              "type": "string",
              "value": "={{ \n  $json.transcript\n    .map(item => item.text)\n    .join(\" \")\n    .replace(/'/g, \"'\")\n    .replace(/"/g, '\"')\n    .replace(/&/g, '&')\n}}\n"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9a98d935-bee8-4f40-99fb-d27362c3292f",
      "name": "AI聊天和摘要代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        0,
        280
      ],
      "parameters": {
        "text": "={{ $json.message?.text ? $json.message.text : $json.fullTranscript }}",
        "options": {
          "systemMessage": "You are an assistant who chats with users and also summarizes YouTube videos when requested.\n\nIMPORTANT:\n1)Dont force the user to provide provide the transcript or youtube video link.\n\n\nIf the user sends a YouTube link and asks for a summary, generate a concise summary of that video.\n\nOtherwise, reply normally and help with any other requests.\nKeep the conversation context.\nIf the user requests modifications to a previous summary, adjust the existing summary rather than starting from scratch"
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "64cdc4a6-a746-4bb6-a564-620ada0a3e8f",
      "name": "清理AI输出格式",
      "type": "n8n-nodes-base.code",
      "position": [
        320,
        280
      ],
      "parameters": {
        "jsCode": "const raw = $json[\"output\"];\n\n// Step 1: Clean and format the structure\nlet cleaned = raw\n  .replace(/\\*\\*/g, '')               // Remove bold markers\n  .replace(/\\\\n/g, '\\n')              // Replace literal \\n with real newlines\n  .replace(/\\* /g, '- ')              // Convert bullets from * to -\n  .replace(/\\*/g, '')                 // Remove stray asterisks\n  .replace(/_/g, '')                  // Remove underscores\n  .replace(/`/g, '')                  // Remove backticks\n  .replace(/>/g, '')                  // Remove blockquote symbols\n  .replace(/#/g, '');                 // Remove markdown headers\n\n// Step 2: Normalize spacing and extra newlines\ncleaned = cleaned\n  .replace(/\\n{3,}/g, '\\n\\n')         // Collapse 3+ newlines to 2\n  .replace(/[ ]{2,}/g, ' ')           // Collapse multiple spaces\n  .trim();\n\nreturn [{\n  cleanedMessage: cleaned\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "a77693f4-387c-436f-805c-35cf577aae4b",
      "name": "发送回复到Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        500,
        280
      ],
      "webhookId": "ef39c60c-4503-4d61-895d-0d3c76e5eb45",
      "parameters": {
        "text": "={{ $json.cleanedMessage }}",
        "chatId": "={{ $('Trigger: Telegram Bot Message').item.json.message.chat.id }}",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "YOUR_TELEGRAMBOT_API_KEY",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0016fa99-cf96-4aae-8aef-d817a7841195",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        280
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 580,
        "content": "## 🧠 工作流逻辑概述"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "42e4d264-16f6-47c2-a0eb-ae29c0749b00",
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Chat & Summarizer Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Chat & Summarizer Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check: Is YouTube Link?": {
      "main": [
        [
          {
            "node": "Extract Chat & Video ID",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Chat & Summarizer Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Chat & Video ID": {
      "main": [
        [
          {
            "node": "Fetch YouTube Transcript (via RapidAPI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean Transcript Symbols": {
      "main": [
        [
          {
            "node": "AI Chat & Summarizer Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Chat & Summarizer Agent": {
      "main": [
        [
          {
            "node": "Clean AI Output Formatting",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean AI Output Formatting": {
      "main": [
        [
          {
            "node": "Send Reply to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger: Telegram Bot Message": {
      "main": [
        [
          {
            "node": "Check: Is YouTube Link?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch YouTube Transcript (via RapidAPI)": {
      "main": [
        [
          {
            "node": "Clean Transcript Symbols",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 内容创作, AI 聊天机器人

需要付费吗?

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

工作流信息
难度等级
中级
节点数量14
分类2
节点类型10
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流