AutomationFlowsAI & RAG › Build a Retrieval-based Chatbot with Telegram, Openai and Google Drive PDF…

Build a Retrieval-based Chatbot with Telegram, Openai and Google Drive PDF…

Original n8n title: Build a Retrieval-based Chatbot with Telegram, Openai and Google Drive PDF Backup

ByTrung Tran @trungtran on n8n.io

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.

Event trigger★★★★☆ complexityAI-powered24 nodesOpenAI EmbeddingsDocument Default Data LoaderIn-Memory Vector StoreOpenAI ChatTelegram TriggerTelegramAgentForm Trigger
AI & RAG Trigger: Event Nodes: 24 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #6994 — we link there as the canonical source.

This workflow follows the Agent → Documentdefaultdataloader recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "bsT84L413PRtrNtZ",
  "meta": {
    "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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3a69c8a7-bf95-4de2-84b0-ae2cc3d2e4e7",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1232,
        1112
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1.1
    },
    {
      "id": "0f4185ea-d7a9-44a9-a824-98f9dc2c2a5d",
      "name": "Insert Data to Store",
      "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": "Query Data 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 Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1536,
        512
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8d4c68cf-64d1-4b3a-bb19-2f003303c1df",
      "name": "Sticky Note3",
      "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
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7470655a-650a-48ca-98e0-b248cf99d18e",
      "name": "Is text message?",
      "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": "Send respond to user",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2064,
        496
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "62ae0117-0d2c-47dd-a772-7c4cd70885ec",
      "name": "Un-supported message type",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1688,
        896
      ],
      "parameters": {
        "text": "Sorry, I can\u2019t read files or images right now. Just send me your question about uploaded document, and I\u2019ll help you answer it!",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0039537b-558c-4fe8-9716-f8aa13676f4a",
      "name": "Telegram document query 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": "Sticky Note6",
      "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": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        688
      ],
      "parameters": {
        "width": 304,
        "height": 128,
        "content": "### 1. \ud83d\udce9 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": "Upload your PDF document here",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        912,
        1140
      ],
      "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": "Backup document(s) to Google Drive",
      "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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "c8f73ac1-eb95-4fa0-a1d8-8b6f5befe885",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -96
      ],
      "parameters": {
        "color": 7,
        "width": 1264,
        "height": 1856,
        "content": "# \ud83d\udcda 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## \ud83d\udc64 Who\u2019s 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## \u2699\ufe0f How it works / What it does\n\n### \ud83d\udcac 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 \u2192 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### \ud83d\udcc4 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## \ud83d\udee0\ufe0f 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 \u201cBackup to Google Drive\u201d node\n\n4. **PDF Ingestion**\n   - Use the \u201cUpload your PDF here\u201d trigger\n   - Connect it to the loader, embedder, and backup flow\n\n## \u2705 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## \ud83e\udde9 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 \ud83d\udcac Telegram + \ud83d\udcc4 PDF + \ud83e\udde0 OpenAI Embeddings + \u2601\ufe0f Google Drive + \u26a1 n8n"
      },
      "typeVersion": 1
    },
    {
      "id": "8ecf58dd-5beb-4f78-bd09-1238f25c623a",
      "name": "Sticky Note1",
      "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": "Sticky Note2",
      "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": "Sticky Note4",
      "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\u2019s text message to OpenAI\u2019s 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": "Sticky Note7",
      "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": "Sticky Note9",
      "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": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2432,
        480
      ],
      "parameters": {
        "width": 540,
        "height": 580,
        "content": "![Alt text](https://wisestackai.s3.ap-southeast-1.amazonaws.com/Screenshot+2025-08-05+at+1.18.12%E2%80%AFPM.png \"Optional title text\")"
      },
      "typeVersion": 1
    },
    {
      "id": "1de83861-0a7d-4e0c-9ceb-beacbe84749b",
      "name": "Sticky Note8",
      "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,
  "settings": {},
  "versionId": "50ae16d0-7565-4f29-8f21-d769face925a",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Backup document(s) to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query Data Tool": {
      "ai_tool": [
        [
          {
            "node": "Telegram document query agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Is text message?": {
      "main": [
        [
          {
            "node": "Telegram document query agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Un-supported message type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Is text message?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Insert Data to Store",
            "type": "ai_embedding",
            "index": 0
          },
          {
            "node": "Query Data Tool",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Telegram document query agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Insert Data to Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Insert Data to Store": {
      "main": [
        []
      ]
    },
    "Send respond to user": {
      "main": [
        []
      ]
    },
    "Telegram document query agent": {
      "main": [
        [
          {
            "node": "Send respond to user",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload your PDF document here": {
      "main": [
        [
          {
            "node": "Insert Data to Store",
            "type": "main",
            "index": 0
          },
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

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.

Source: https://n8n.io/workflows/6994/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Your AI workforce is ready. Are you?

Google Sheets Tool, Mcp Trigger, Google Drive +29
AI & RAG

This comprehensive workflow bundle is designed as a powerful starter kit, enabling you to build a multi-functional AI assistant on Telegram. It seamlessly integrates AI-powered voice interactions, an

Telegram Trigger, Telegram, OpenAI +19
AI & RAG

This n8n template automatically classifies incoming emails (Sales, Support, Internal, Finance, Promotions) and routes them to a dedicated OpenAI LLM Agent for processing. Depending on the category, th

OpenAI, Gmail, Text Classifier +16
AI & RAG

Auto repost job with RAG is a workflow designed to automatically extract, process, and publish job listings from monitored sources using Google Drive, OpenAI, Supabase, and WordPress. This integration

Google Drive, Supabase Vector Store, OpenAI Embeddings +12
AI & RAG

Unleash the full potential of your HighLevel CRM by adding an intelligent GPT-5 Agent that does more than just follow commands — it understands context, retrieves the right data, and executes actions

High Level Tool, Mcp Trigger, Chat Trigger +21