8
n8n 中文网amn8n.com

开发完成 - 通过Telegram与PDF聊天

高级

这是一个Document Extraction, AI RAG领域的自动化工作流,包含 25 个节点。主要使用 If, Code, Limit, Telegram, StopAndError 等节点。 使用Google Gemini和Pinecone在Telegram上自动化'与PDF聊天'机器人

前置要求
  • Telegram Bot Token
  • Google Gemini API Key
  • Pinecone API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "ibBeVW3tpY92HUpA",
  "meta": {
    "instanceId": "1a54c41d9050a8f1fa6f74ca858828ad9fb97b9fafa3e9760e576171c531a787",
    "templateCredsSetupCompleted": true
  },
  "name": "开发完成 - 通过 Telegram 与 PDF 聊天",
  "tags": [
    {
      "id": "0BJmSFs6EfUsyTWo",
      "name": "AI Internal",
      "createdAt": "2025-10-13T09:18:40.187Z",
      "updatedAt": "2025-10-13T09:18:40.187Z"
    }
  ],
  "nodes": [
    {
      "id": "c2e95dd8-961b-42d0-89cd-c31e810da2e8",
      "name": "默认数据加载器",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1584,
        944
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1
    },
    {
      "id": "4ed51c5d-23e5-4836-ad13-1a5fb48a0317",
      "name": "递归字符文本分割器",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        1648,
        1104
      ],
      "parameters": {
        "options": {},
        "chunkSize": 3000,
        "chunkOverlap": 200
      },
      "typeVersion": 1
    },
    {
      "id": "61db0aad-53de-4655-af01-7389c603137f",
      "name": "停止与错误处理",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        1936,
        1664
      ],
      "parameters": {
        "errorMessage": "An error occurred"
      },
      "typeVersion": 1
    },
    {
      "id": "b525eb52-d03f-4b1c-83c1-54855c4f2701",
      "name": "问答链",
      "type": "@n8n/n8n-nodes-langchain.chainRetrievalQa",
      "position": [
        1008,
        1488
      ],
      "parameters": {
        "text": "=**INSTRUCTIONS:**\nYou are an expert RAG system. Answer the user's question ONLY using the provided context.\n\n1.  **Format Mode:** Your response MUST be formatted for Telegram's **HTML Parse Mode**.\n2.  **Formatting:**\n    * Use the bold tag (<b>) for all titles and key benefits.\n    * **CRITICAL LINE BREAK RULE:** For all line breaks, lists, and spacing, use the **newline character (\\n)** instead of any HTML tags like <br/> or <br>.\n    * Ensure the list is clearly structured with a single newline after each key item.\n\n**CONTEXT:** (The retrieved information follows here)\nSearch the database with the retriever for information for the answer\n\n**USER QUESTION:**\n{{ $json.message.text }}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.3
    },
    {
      "id": "666d4966-aa07-4b39-9f9f-6101f6f70b27",
      "name": "向量存储检索器",
      "type": "@n8n/n8n-nodes-langchain.retrieverVectorStore",
      "position": [
        1072,
        1680
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2ea5294f-def8-43d6-84ca-5f4bbb4b8b4a",
      "name": "Pinecone 向量存储1",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        992,
        1872
      ],
      "parameters": {
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "telegram",
          "cachedResultName": "telegram"
        }
      },
      "credentials": {
        "pineconeApi": {
          "id": "Your_Pinecone_Credential_ID",
          "name": "PineconeApi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d9e88d5c-096b-4a8f-8f17-fb8d1887c95f",
      "name": "检查是否为文档",
      "type": "n8n-nodes-base.if",
      "position": [
        288,
        1344
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8839993b-9fe7-4e1e-a1cc-fe5de6b0bb62",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.message.document }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "18c639ce-3517-4f1f-b02a-a40ba4f1e14b",
      "name": "更改为 application/pdf",
      "type": "n8n-nodes-base.code",
      "position": [
        1072,
        1072
      ],
      "parameters": {
        "jsCode": "// Função para modificar os metadados do arquivo binário\nfunction modifyBinaryMetadata(items) {\n for (const item of items) {\n if (item.binary && item.binary.data) {\n // Modifica o tipo MIME\n item.binary.data.mimeType = 'application/pdf';\n \n // Garante que o nome do arquivo termine com .pdf\n if (!item.binary.data.fileName.toLowerCase().endsWith('.pdf')) {\n item.binary.data.fileName += '.pdf';\n }\n \n // Atualiza o contentType no fileType (se existir)\n if (item.binary.data.fileType) {\n item.binary.data.fileType.contentType = 'application/pdf';\n }\n }\n }\n return items;\n}\n\n// Aplica a modificação e retorna os itens atualizados\nreturn modifyBinaryMetadata($input.all());"
      },
      "typeVersion": 2
    },
    {
      "id": "9abd0d30-8bfd-4a9c-94a7-ddfe919f22df",
      "name": "Telegram 获取文件",
      "type": "n8n-nodes-base.telegram",
      "position": [
        752,
        1072
      ],
      "webhookId": "911eeb6b-d6c2-4d35-9433-24b7ec4886ef",
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "Your_Telegram_Credential_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f9af0cdd-7ea3-4e97-b53f-b65fdf4e9355",
      "name": "Telegram 响应",
      "type": "n8n-nodes-base.telegram",
      "onError": "continueErrorOutput",
      "position": [
        1552,
        1488
      ],
      "webhookId": "a5b324f8-649f-4a3a-b26f-57cd0eb341ec",
      "parameters": {
        "text": "={{ $json.response.text }}",
        "chatId": "={{ $('Telegram Message Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "Your_Telegram_Credential_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "048f9df4-1d15-4dcf-b853-52fe376434a0",
      "name": "关于数据库的 Telegram 响应",
      "type": "n8n-nodes-base.telegram",
      "onError": "continueErrorOutput",
      "position": [
        2176,
        768
      ],
      "webhookId": "52437171-bdad-408c-bced-5ffec75b851d",
      "parameters": {
        "text": "={{ $json.metadata.pdf.totalPages }} pages saved on Pinecone",
        "chatId": "={{ $('Telegram Message Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "Your_Telegram_Credential_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "36017ee3-5c44-469b-aad7-6a44faa57d32",
      "name": "停止并错误1",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        2448,
        864
      ],
      "parameters": {
        "errorMessage": "An error occurred."
      },
      "typeVersion": 1
    },
    {
      "id": "68b2dc90-c4a5-436f-9c17-e811974f333b",
      "name": "Pinecone 向量存储",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        1488,
        768
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "telegram",
          "cachedResultName": "telegram"
        }
      },
      "credentials": {
        "pineconeApi": {
          "id": "Your_Pinecone_Credential_ID",
          "name": "PineconeApi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fa712022-84c5-4c6d-aff1-dd71f73a7c20",
      "name": "限制为 1",
      "type": "n8n-nodes-base.limit",
      "position": [
        1904,
        768
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "71e24d0d-1e70-4c59-acf8-c7b73b5d33c5",
      "name": "嵌入 Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        1456,
        992
      ],
      "parameters": {
        "modelName": "models/gemini-embedding-001"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "Your_Gemini_Credential_ID",
          "name": "Your Google Gemini Credential Name"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0e7c375a-1aaa-459f-b8c2-13659f71320a",
      "name": "嵌入 Google Gemini1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        1024,
        2016
      ],
      "parameters": {
        "modelName": "models/gemini-embedding-001"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "Your_Gemini_Credential_ID",
          "name": "Your Google Gemini Credential Name"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "77d57e70-ef74-49eb-9019-6103a09ae391",
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        880,
        1696
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "Your_Gemini_Credential_ID",
          "name": "Your Google Gemini Credential Name"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "92162e34-98e9-44ce-89a2-3ae058133a2d",
      "name": "Telegram 消息触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -80,
        1344
      ],
      "webhookId": "b178f034-9997-4832-9bb4-a43c3015506e",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "Your_Telegram_Credential_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "01da8891-6cb5-444e-8848-b34ee5af095c",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        1056
      ],
      "parameters": {
        "color": 5,
        "width": 368,
        "height": 272,
        "content": "## 1. **触发器与路由器**"
      },
      "typeVersion": 1
    },
    {
      "id": "246059a8-fbc0-4f33-8cfd-7b33c87c7c02",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        1056
      ],
      "parameters": {
        "color": 6,
        "width": 384,
        "height": 256,
        "content": "## 2. **路由节点**"
      },
      "typeVersion": 1
    },
    {
      "id": "6e03fbfc-58e6-4cd5-9ce9-82b0942a85e2",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1824,
        944
      ],
      "parameters": {
        "width": 336,
        "height": 272,
        "content": "## 5. **文本分割器**"
      },
      "typeVersion": 1
    },
    {
      "id": "dd26c4da-207a-4b8e-90a4-4d2db8f1c529",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1408,
        544
      ],
      "parameters": {
        "color": 3,
        "width": 368,
        "height": 336,
        "content": "## 4. **嵌入(索引)**"
      },
      "typeVersion": 1
    },
    {
      "id": "ed22ea85-0803-4926-b118-fb4100bbf937",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        1776
      ],
      "parameters": {
        "color": 2,
        "width": 368,
        "height": 256,
        "content": "## 6. **向量存储:索引**"
      },
      "typeVersion": 1
    },
    {
      "id": "a8cada20-ac48-4c8b-ab0f-de9b56d7d4a2",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        1232
      ],
      "parameters": {
        "color": 3,
        "width": 416,
        "height": 368,
        "content": "## 7. **核心 RAG 引擎**"
      },
      "typeVersion": 1
    },
    {
      "id": "2688705d-3dae-4235-84b0-8b880bf4cdeb",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        1264
      ],
      "parameters": {
        "color": 4,
        "width": 432,
        "height": 336,
        "content": "## 8. **最终 Telegram 响应**"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "40963e46-0c2a-4887-9aaf-b9fafff20ab6",
  "connections": {
    "Limit to 1": {
      "main": [
        [
          {
            "node": "Telegram Response about Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Response": {
      "main": [
        [],
        [
          {
            "node": "Stop and Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram get File": {
      "main": [
        [
          {
            "node": "Change to application/pdf",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store": {
      "main": [
        [
          {
            "node": "Limit to 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If is a document": {
      "main": [
        [
          {
            "node": "Telegram get File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Question and Answer Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store1": {
      "ai_vectorStore": [
        [
          {
            "node": "Vector Store Retriever",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "Vector Store Retriever": {
      "ai_retriever": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "ai_retriever",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Message Trigger": {
      "main": [
        [
          {
            "node": "Check If is a document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Change to application/pdf": {
      "main": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini1": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Question and Answer Chain": {
      "main": [
        [
          {
            "node": "Telegram Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Response about Database": {
      "main": [
        [],
        [
          {
            "node": "Stop and Error1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 文档提取, AI RAG 检索增强

需要付费吗?

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

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

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

作者
Intuz

Intuz

@intuz

Workflow automation can help automate your routine activities and help saves $$$, as well as hours of time. As a boutique tech consulting company, Intuz help businesses with custom AI/ML, AI Workflow Automations, and software development. Automate your business workflow for: Sales Marketing Accounting Finance Operations E-Commerce Customer Support Admin & Backoffice Logistics & Supply Chain

外部链接
在 n8n.io 查看

分享此工作流