開発完了 - PDF と Telegram でチャット
これはDocument Extraction, AI RAG分野の自動化ワークフローで、25個のノードを含みます。主にIf, Code, Limit, Telegram, StopAndErrorなどのノードを使用。 テレグラム上の「PDF チャット」ボットの自動化:Google Gemini、Pinecone
- •Telegram Bot Token
- •Google Gemini API Key
- •Pinecone API Key
使用ノード (25)
カテゴリー
{
"id": "ibBeVW3tpY92HUpA",
"meta": {
"instanceId": "1a54c41d9050a8f1fa6f74ca858828ad9fb97b9fafa3e9760e576171c531a787",
"templateCredsSetupCompleted": true
},
"name": "Development Done - Chat with PDF via Telegram",
"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": "Embeddings 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": "Embeddings 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. **Trigger & Router**\n**Task:** This node is the starting point. It listens for *any* message on the configured Telegram bot.\n\n**Output:**\n- **Text:** User's question (goes to the RAG chain).\n- **Document:** Binary file data (goes to the indexing process).\n\n**Next Stop:** Routes the message to the **\"Check If is a document\"** node."
},
"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. **Router Node**\n**Task:** Determines the message type to route the workflow.\n\n**Condition:** Checks if `{{ $json.message.document }}` **exists**.\n- **TRUE (Top Branch):** A file was uploaded. Proceed to **Indexing** (download the file).\n- **FALSE (Bottom Branch):** It is a plain text question. Proceed to **Querying** (run the RAG Chain)."
},
"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. **Text Splitter**\n**Task:** Breaks the large PDF text into small, manageable chunks for indexing.\n\n**Configuration:**\n- **Chunk Size:** 3000\n- **Chunk Overlap:** 200 (Ensures context overlaps between chunks for better retrieval).\n\n**Purpose:** This configuration is key for **Retrieval-Augmented Generation (RAG)** accuracy."
},
"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. **Embeddings (Indexing)**\n**Task:** Converts the split text chunks into high-dimensional numerical **vectors**.\n\n**Model:** `models/gemini-embedding-001`\n\n**Purpose:** These vectors are what the Pinecone database stores and uses for fast, semantic similarity searches when a user asks a question."
},
"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. **Vector Store: Indexing**\n**Task:** **Inserts** the Gemini embeddings and their associated text content into the configured Pinecone index (`telegram`).\n\n**Mode:** **`insert`**\n\n**Result:** The PDF is now fully indexed and searchable. The workflow then sends a confirmation to the user via **\"Telegram Response about Database\"**."
},
"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. **Core RAG Engine**\n**Task:** Generates the final, context-based answer.\n\n**Connections:**\n- **LLM:** Google Gemini Chat Model (for generation).\n- **Retriever:** Vector Store Retriever (for context lookup).\n\n**CRITICAL PROMPT:** The prompt strictly enforces:\n1. Answer **ONLY** using provided context.\n2. Response must be in **Telegram HTML Parse Mode** (`<b>` and `\\n`)."
},
"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. **Final Telegram Response**\n**Task:** Sends the RAG result back to the user.\n\n**Text Input:** `={{ $json.response.text }}`\n\n**CRITICAL SETTING:**\n- **Parse Mode:** **HTML**\nThis is required to properly display the bold tags (`<b>`) and newline characters (`\\n`) formatted by the Question and Answer Chain."
},
"typeVersion": 1
}
],
"active": true,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "40963e46-0c2a-4887-9aaf-b9fafff20ab6",
"connections": {
"fa712022-84c5-4c6d-aff1-dd71f73a7c20": {
"main": [
[
{
"node": "048f9df4-1d15-4dcf-b853-52fe376434a0",
"type": "main",
"index": 0
}
]
]
},
"f9af0cdd-7ea3-4e97-b53f-b65fdf4e9355": {
"main": [
[],
[
{
"node": "61db0aad-53de-4655-af01-7389c603137f",
"type": "main",
"index": 0
}
]
]
},
"9abd0d30-8bfd-4a9c-94a7-ddfe919f22df": {
"main": [
[
{
"node": "18c639ce-3517-4f1f-b02a-a40ba4f1e14b",
"type": "main",
"index": 0
}
]
]
},
"c2e95dd8-961b-42d0-89cd-c31e810da2e8": {
"ai_document": [
[
{
"node": "68b2dc90-c4a5-436f-9c17-e811974f333b",
"type": "ai_document",
"index": 0
}
]
]
},
"68b2dc90-c4a5-436f-9c17-e811974f333b": {
"main": [
[
{
"node": "fa712022-84c5-4c6d-aff1-dd71f73a7c20",
"type": "main",
"index": 0
}
]
]
},
"d9e88d5c-096b-4a8f-8f17-fb8d1887c95f": {
"main": [
[
{
"node": "9abd0d30-8bfd-4a9c-94a7-ddfe919f22df",
"type": "main",
"index": 0
}
],
[
{
"node": "b525eb52-d03f-4b1c-83c1-54855c4f2701",
"type": "main",
"index": 0
}
]
]
},
"2ea5294f-def8-43d6-84ca-5f4bbb4b8b4a": {
"ai_vectorStore": [
[
{
"node": "666d4966-aa07-4b39-9f9f-6101f6f70b27",
"type": "ai_vectorStore",
"index": 0
}
]
]
},
"666d4966-aa07-4b39-9f9f-6101f6f70b27": {
"ai_retriever": [
[
{
"node": "b525eb52-d03f-4b1c-83c1-54855c4f2701",
"type": "ai_retriever",
"index": 0
}
]
]
},
"71e24d0d-1e70-4c59-acf8-c7b73b5d33c5": {
"ai_embedding": [
[
{
"node": "68b2dc90-c4a5-436f-9c17-e811974f333b",
"type": "ai_embedding",
"index": 0
}
]
]
},
"77d57e70-ef74-49eb-9019-6103a09ae391": {
"ai_languageModel": [
[
{
"node": "b525eb52-d03f-4b1c-83c1-54855c4f2701",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"92162e34-98e9-44ce-89a2-3ae058133a2d": {
"main": [
[
{
"node": "d9e88d5c-096b-4a8f-8f17-fb8d1887c95f",
"type": "main",
"index": 0
}
]
]
},
"18c639ce-3517-4f1f-b02a-a40ba4f1e14b": {
"main": [
[
{
"node": "68b2dc90-c4a5-436f-9c17-e811974f333b",
"type": "main",
"index": 0
}
]
]
},
"0e7c375a-1aaa-459f-b8c2-13659f71320a": {
"ai_embedding": [
[
{
"node": "2ea5294f-def8-43d6-84ca-5f4bbb4b8b4a",
"type": "ai_embedding",
"index": 0
}
]
]
},
"b525eb52-d03f-4b1c-83c1-54855c4f2701": {
"main": [
[
{
"node": "f9af0cdd-7ea3-4e97-b53f-b65fdf4e9355",
"type": "main",
"index": 0
}
]
]
},
"048f9df4-1d15-4dcf-b853-52fe376434a0": {
"main": [
[],
[
{
"node": "36017ee3-5c44-469b-aad7-6a44faa57d32",
"type": "main",
"index": 0
}
]
]
},
"4ed51c5d-23e5-4836-ad13-1a5fb48a0317": {
"ai_textSplitter": [
[
{
"node": "c2e95dd8-961b-42d0-89cd-c31e810da2e8",
"type": "ai_textSplitter",
"index": 0
}
]
]
}
}
}このワークフローの使い方は?
上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。
このワークフローはどんな場面に適していますか?
上級 - 文書抽出, AI RAG検索拡張
有料ですか?
このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。
関連ワークフロー
Intuz
@intuzWorkflow 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
このワークフローを共有