Telegram-RAG-Chatbot mit PDF-Dokumenten und Google Drive-Backup
Dies ist ein Internal Wiki, AI RAG-Bereich Automatisierungsworkflow mit 24 Nodes. Hauptsächlich werden If, Code, Telegram, FormTrigger, GoogleDrive und andere Nodes verwendet. Retrieval-basierten Chatbot mit Telegram, OpenAI und Google Drive PDF-Backups bauen
- •Telegram Bot Token
- •Google Drive API-Anmeldedaten
- •OpenAI API Key
Verwendete Nodes (24)
Kategorie
{
"id": "bsT84L413PRtrNtZ",
"meta": {
"instanceId": "4a2e6764ba7a6bc9890d9225f4b21d570ce88fc9bd57549c89057fcee58fed0f",
"templateId": "5010",
"templateCredsSetupCompleted": true
},
"name": "Telegram RAG Chatbot with PDF Document & Google Drive Backup",
"tags": [
{
"id": "ow6eIe95VK6fRkyw",
"name": "Chatbot",
"createdAt": "2025-08-05T06:23:11.231Z",
"updatedAt": "2025-08-05T06:23:11.231Z"
},
{
"id": "JFZdpFVd2h3ZDZ7n",
"name": "RAG",
"createdAt": "2025-08-05T06:23:26.538Z",
"updatedAt": "2025-08-05T06:23:26.538Z"
},
{
"id": "84SlSTthTSHRbFGM",
"name": "Telegram",
"createdAt": "2025-08-05T06:23:21.764Z",
"updatedAt": "2025-08-05T06:23:21.764Z"
}
],
"nodes": [
{
"id": "26d63e24-2592-41f9-9b4b-edab81e99f21",
"name": "Embeddings OpenAI",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
1760,
720
],
"parameters": {
"options": {}
},
"credentials": {
"openAiApi": {
"id": "PPSwAKeLQYgAPobT",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "3a69c8a7-bf95-4de2-84b0-ae2cc3d2e4e7",
"name": "Standard-Datenlader",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
1232,
1112
],
"parameters": {
"options": {},
"dataType": "binary"
},
"typeVersion": 1.1
},
{
"id": "0f4185ea-d7a9-44a9-a824-98f9dc2c2a5d",
"name": "Daten in Store einfügen",
"type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
"position": [
1136,
888
],
"parameters": {
"mode": "insert",
"memoryKey": {
"__rl": true,
"mode": "list",
"value": "vector_store_key",
"cachedResultName": "vector_store_key"
}
},
"typeVersion": 1.2
},
{
"id": "ce86b41b-7e1b-458f-ab13-d6b187854ae8",
"name": "Abfrage-Daten-Tool",
"type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
"position": [
1664,
512
],
"parameters": {
"mode": "retrieve-as-tool",
"toolName": "knowledge_base",
"memoryKey": {
"__rl": true,
"mode": "list",
"value": "vector_store_key"
},
"toolDescription": "Use this knowledge base to answer questions from the user"
},
"typeVersion": 1.2
},
{
"id": "d43cf585-4192-4f53-9532-4677923289ba",
"name": "OpenAI Chat-Modell",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
1536,
512
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "PPSwAKeLQYgAPobT",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "8d4c68cf-64d1-4b3a-bb19-2f003303c1df",
"name": "Notiz3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1920,
688
],
"parameters": {
"color": 4,
"width": 320,
"height": 224,
"content": "### Embeddings\n\nThe Insert and Retrieve operation use the same embedding node.\n\nThis is to ensure that they are using the **exact same embeddings and settings**.\n\nDifferent embeddings might not work at all, or have unintended consequences.\n"
},
"typeVersion": 1
},
{
"id": "d4227342-0a19-420e-b088-2e37186ad074",
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"position": [
912,
696
],
"webhookId": "aac0aa6a-c86e-4b4d-8f81-daacfd20f2c8",
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "paNoPvnV5Wzt4Lhv",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "7470655a-650a-48ca-98e0-b248cf99d18e",
"name": "Ist Textnachricht?",
"type": "n8n-nodes-base.if",
"position": [
1224,
696
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "2439fbb6-c093-4b33-aabd-db08ebfd53b2",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "fda67b3b-9844-40e4-aa53-252d2e36e667",
"name": "Antwort an Benutzer senden",
"type": "n8n-nodes-base.telegram",
"position": [
2064,
496
],
"webhookId": "bead9b9b-6410-4fe7-a36c-05bd069e3a02",
"parameters": {
"text": "={{ $json.output }}",
"chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "paNoPvnV5Wzt4Lhv",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "62ae0117-0d2c-47dd-a772-7c4cd70885ec",
"name": "Nicht unterstützter Nachrichtentyp",
"type": "n8n-nodes-base.telegram",
"position": [
1688,
896
],
"webhookId": "724418e9-e7ef-4aa2-8722-028683cadb2f",
"parameters": {
"text": "Sorry, I can’t read files or images right now. Just send me your question about uploaded document, and I’ll help you answer it!",
"chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "paNoPvnV5Wzt4Lhv",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "0039537b-558c-4fe8-9716-f8aa13676f4a",
"name": "Telegram Dokumentenabfrage-Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1552,
288
],
"parameters": {
"text": "={{ $json.message.text }}",
"options": {
"systemMessage": "The output should not exceed 3000 characters after entities parsing."
},
"promptType": "define"
},
"typeVersion": 2
},
{
"id": "0608a9d7-db7b-4a18-b8fb-26b936da919a",
"name": "Notiz6",
"type": "n8n-nodes-base.stickyNote",
"position": [
1104,
512
],
"parameters": {
"width": 272,
"height": 144,
"content": "### 2. Is Text Message? \n**Description**: Checks whether the incoming Telegram message is a text message. If not, the workflow routes to an \"unsupported message type\" handler."
},
"typeVersion": 1
},
{
"id": "40c8b84f-ed8a-4fdc-b04c-d778a2fdea0e",
"name": "Notiz5",
"type": "n8n-nodes-base.stickyNote",
"position": [
544,
688
],
"parameters": {
"width": 304,
"height": 128,
"content": "### 1. 📩 Telegram Trigger \n**Description**: Listens for incoming messages from the user via the connected Telegram bot. This is the entry point of the workflow."
},
"typeVersion": 1
},
{
"id": "91077637-5e75-4bb2-8419-235420bc5a96",
"name": "Code",
"type": "n8n-nodes-base.code",
"position": [
1224,
1288
],
"parameters": {
"jsCode": "const data = $input.item.json;\nconst binaryData = $input.item.binary;\n\nlet output = [];\n\nObject.keys(binaryData)\n .filter(label => label.startsWith(\"CV_\"))\n .forEach(label => {\n output.push({\n json: data,\n binary: { data: binaryData[label] }\n });\n });\n\nreturn output;"
},
"typeVersion": 2
},
{
"id": "83ed351e-90e8-458f-a01b-73001ef1800f",
"name": "PDF-Dokument hier hochladen",
"type": "n8n-nodes-base.formTrigger",
"position": [
912,
1140
],
"webhookId": "82848bc4-5ea2-4e5a-8bb6-3c09b94a8c5d",
"parameters": {
"options": {},
"formTitle": "Upload your data to test RAG",
"formFields": {
"values": [
{
"fieldType": "file",
"fieldLabel": "Upload your file(s)",
"requiredField": true,
"acceptFileTypes": ".pdf"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "79a7f8b5-7af2-479c-883c-a4e02ce4bee8",
"name": "Dokument(e) in Google Drive sichern",
"type": "n8n-nodes-base.googleDrive",
"position": [
1688,
1288
],
"parameters": {
"name": "=document-{{ $now.toFormat(\"yyyyLLdd-HHmmss\") }}-{{$binary.data.fileName}}",
"driveId": {
"__rl": true,
"mode": "list",
"value": "My Drive",
"cachedResultUrl": "https://drive.google.com/drive/my-drive",
"cachedResultName": "My Drive"
},
"options": {},
"folderId": {
"__rl": true,
"mode": "list",
"value": "1ObNNVJFR2vcKqP8p-ZnX_eaZy4gBHgha",
"cachedResultUrl": "https://drive.google.com/drive/folders/1ObNNVJFR2vcKqP8p-ZnX_eaZy4gBHgha",
"cachedResultName": "SmartIT"
}
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "fC471es5gk5Mm900",
"name": "Google Drive account"
}
},
"typeVersion": 3
},
{
"id": "c8f73ac1-eb95-4fa0-a1d8-8b6f5befe885",
"name": "Notiz",
"type": "n8n-nodes-base.stickyNote",
"position": [
-752,
-96
],
"parameters": {
"color": 7,
"width": 1264,
"height": 1856,
"content": "# 📚 Telegram RAG Chatbot with PDF Document & Google Drive Backup\n- An upgraded Retrieval-Augmented Generation (RAG) chatbot built in **n8n** that lets users ask questions via Telegram and receive accurate answers from uploaded PDFs. It embeds documents using OpenAI and backs them up to Google Drive.\n\n## 👤 Who’s it for\n\nPerfect for:\n- Knowledge workers who want instant access to private documents\n- Support teams needing searchable SOPs and guides\n- Educators enabling course material Q&A for students\n- Individuals automating personal document search + cloud backup\n\n## ⚙️ How it works / What it does\n\n### 💬 Telegram Chat Handling\n1. **User sends a message** \n Triggered by the Telegram bot, the workflow checks if the message is text.\n\n2. **Text message → OpenAI RAG Agent** \n If the message is text, it's passed to a GPT-powered document agent. \n This agent:\n - Retrieves relevant info from embedded documents using semantic search\n - Returns a context-aware answer to the user\n\n3. **Send answer back** \n The bot sends the generated response back to the Telegram user.\n\n4. **Non-text input fallback** \n If the message is not text, the bot replies with a polite unsupported message.\n\n### 📄 PDF Upload and Embedding\n1. **User uploads PDFs manually** \n A manual trigger starts the embedding flow.\n\n2. **Default Data Loader** \n Reads and chunks the PDF(s) into text segments.\n\n3. **Insert to Vector Store (Embedding)** \n Text chunks are embedded using OpenAI and saved for retrieval.\n\n4. **Backup to Google Drive** \n The original PDF is uploaded to Google Drive for safekeeping.\n\n## 🛠️ How to set up\n\n1. **Telegram Bot**\n - Create via [BotFather](https://t.me/botfather)\n - Connect it to the Telegram Trigger node\n\n2. **OpenAI**\n - Use your OpenAI API key\n - Connect the Embeddings and Chat Model nodes (GPT-3.5/4)\n - Ensure both embedding and querying use the same Embedding node\n\n3. **Google Drive**\n - Set up credentials in n8n for your Google account\n - Connect the “Backup to Google Drive” node\n\n4. **PDF Ingestion**\n - Use the “Upload your PDF here” trigger\n - Connect it to the loader, embedder, and backup flow\n\n## ✅ Requirements\n\n- Telegram bot token\n- OpenAI API key (GPT + Embeddings)\n- n8n instance (self-hosted or cloud)\n- Google Drive integration\n- PDF files to upload\n\n## 🧩 How to customize the workflow\n\n| Feature | How to Customize |\n|-------------------------------|-------------------------------------------------------------------|\n| Auto-ingest from folders | Add Google Drive/Dropbox watchers for new PDFs |\n| Add file upload via Telegram | Extend Telegram bot to receive PDFs and run the embedding flow |\n| Track user questions | Log Telegram usernames and questions to a database |\n| Summarize documents | Add summarization step on upload |\n| Add Markdown or HTML support | Format replies for better Telegram rendering |\n\nBuilt with 💬 Telegram + 📄 PDF + 🧠 OpenAI Embeddings + ☁️ Google Drive + ⚡ n8n"
},
"typeVersion": 1
},
{
"id": "8ecf58dd-5beb-4f78-bd09-1238f25c623a",
"name": "Notiz1",
"type": "n8n-nodes-base.stickyNote",
"position": [
704,
1360
],
"parameters": {
"width": 464,
"height": 80,
"content": "### 1. Upload Your PDF Document Here \n- A manual execution trigger for uploading and processing PDF documents into the knowledge base."
},
"typeVersion": 1
},
{
"id": "2aefbbd3-1234-4843-bf34-430b229faa1f",
"name": "Notiz2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1872,
1296
],
"parameters": {
"width": 432,
"height": 80,
"content": "### 2.1 Backup Documents to Google Drive \n- Uploads a copy of the original PDF file to a connected Google Drive folder for safekeeping and future reference."
},
"typeVersion": 1
},
{
"id": "88a087f2-8656-4e82-b384-efdaf51ec021",
"name": "Notiz4",
"type": "n8n-nodes-base.stickyNote",
"position": [
1424,
176
],
"parameters": {
"width": 560,
"height": 96,
"content": "### 3. Telegram Document Query Agent (GPT with RAG) \n- Sends the user’s text message to OpenAI’s Chat Model. Uses embeddings to retrieve relevant document chunks and generate a context-aware response using Retrieval-Augmented Generation."
},
"typeVersion": 1
},
{
"id": "38627375-43c0-47ad-87ab-a3ef94093c28",
"name": "Notiz7",
"type": "n8n-nodes-base.stickyNote",
"position": [
1360,
1120
],
"parameters": {
"color": 4,
"width": 496,
"height": 96,
"content": "### Default Data Loader \nExtracts and chunks text from the uploaded PDF documents to prepare them for semantic embedding."
},
"typeVersion": 1
},
{
"id": "8b2e116c-003f-4eb7-9cf1-30ac4cbd87d3",
"name": "Notiz9",
"type": "n8n-nodes-base.stickyNote",
"position": [
688,
896
],
"parameters": {
"width": 352,
"height": 112,
"content": "### 2.2 Insert Data to Store (Embeddings) \nConverts document chunks into vector embeddings using OpenAI and inserts them into the vector store for future retrieval."
},
"typeVersion": 1
},
{
"id": "2abc9178-add2-4d8e-b395-cc9713ed4a2e",
"name": "Notiz10",
"type": "n8n-nodes-base.stickyNote",
"position": [
2432,
480
],
"parameters": {
"width": 540,
"height": 580,
"content": ""
},
"typeVersion": 1
},
{
"id": "1de83861-0a7d-4e0c-9ceb-beacbe84749b",
"name": "Notiz8",
"type": "n8n-nodes-base.stickyNote",
"position": [
2432,
1088
],
"parameters": {
"width": 544,
"height": 80,
"content": "Sample document: https://ptgmedia.pearsoncmg.com/images/9780138203283/samplepages/9780138203283_Sample.pdf"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {},
"versionId": "50ae16d0-7565-4f29-8f21-d769face925a",
"connections": {
"91077637-5e75-4bb2-8419-235420bc5a96": {
"main": [
[
{
"node": "79a7f8b5-7af2-479c-883c-a4e02ce4bee8",
"type": "main",
"index": 0
}
]
]
},
"ce86b41b-7e1b-458f-ab13-d6b187854ae8": {
"ai_tool": [
[
{
"node": "0039537b-558c-4fe8-9716-f8aa13676f4a",
"type": "ai_tool",
"index": 0
}
]
]
},
"7470655a-650a-48ca-98e0-b248cf99d18e": {
"main": [
[
{
"node": "0039537b-558c-4fe8-9716-f8aa13676f4a",
"type": "main",
"index": 0
}
],
[
{
"node": "62ae0117-0d2c-47dd-a772-7c4cd70885ec",
"type": "main",
"index": 0
}
]
]
},
"d4227342-0a19-420e-b088-2e37186ad074": {
"main": [
[
{
"node": "7470655a-650a-48ca-98e0-b248cf99d18e",
"type": "main",
"index": 0
}
]
]
},
"26d63e24-2592-41f9-9b4b-edab81e99f21": {
"ai_embedding": [
[
{
"node": "0f4185ea-d7a9-44a9-a824-98f9dc2c2a5d",
"type": "ai_embedding",
"index": 0
},
{
"node": "ce86b41b-7e1b-458f-ab13-d6b187854ae8",
"type": "ai_embedding",
"index": 0
}
]
]
},
"d43cf585-4192-4f53-9532-4677923289ba": {
"ai_languageModel": [
[
{
"node": "0039537b-558c-4fe8-9716-f8aa13676f4a",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"3a69c8a7-bf95-4de2-84b0-ae2cc3d2e4e7": {
"ai_document": [
[
{
"node": "0f4185ea-d7a9-44a9-a824-98f9dc2c2a5d",
"type": "ai_document",
"index": 0
}
]
]
},
"0f4185ea-d7a9-44a9-a824-98f9dc2c2a5d": {
"main": [
[]
]
},
"fda67b3b-9844-40e4-aa53-252d2e36e667": {
"main": [
[]
]
},
"0039537b-558c-4fe8-9716-f8aa13676f4a": {
"main": [
[
{
"node": "fda67b3b-9844-40e4-aa53-252d2e36e667",
"type": "main",
"index": 0
}
]
]
},
"83ed351e-90e8-458f-a01b-73001ef1800f": {
"main": [
[
{
"node": "0f4185ea-d7a9-44a9-a824-98f9dc2c2a5d",
"type": "main",
"index": 0
},
{
"node": "91077637-5e75-4bb2-8419-235420bc5a96",
"type": "main",
"index": 0
}
]
]
}
}
}Wie verwende ich diesen Workflow?
Kopieren Sie den obigen JSON-Code, erstellen Sie einen neuen Workflow in Ihrer n8n-Instanz und wählen Sie "Aus JSON importieren". Fügen Sie die Konfiguration ein und passen Sie die Anmeldedaten nach Bedarf an.
Für welche Szenarien ist dieser Workflow geeignet?
Experte - Internes Wiki, KI RAG
Ist es kostenpflichtig?
Dieser Workflow ist völlig kostenlos. Beachten Sie jedoch, dass Drittanbieterdienste (wie OpenAI API), die im Workflow verwendet werden, möglicherweise kostenpflichtig sind.
Verwandte Workflows
Trung Tran
@trungtranEmpowering small and medium businesses with smart automation and practical AI, no big tech team required. Reach out: lets@automatewith.me
Diesen Workflow teilen