Skip to main content

Create a RAG Telegram bot using Google Drive, PostgreSQL, and local Ollama

Workflow preview

Workflow preview
100%
Create a RAG Telegram bot using Google Drive, PostgreSQL, and local Ollama preview
Open on n8n.io

1. Workflow Overview

Who's it for This template is for developers, teams, and automation enthusiasts who want a private, PIN protected Telegram chatbot that answers questions from their own documents — without relying ...

Best for

  • Internal Wiki automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.stickynote, n8n-nodes-base.webhook, n8n-nodes-base.postgres, n8n-nodes-base.code, n8n-nodes-base.if, n8n-nodes-base.telegram, n8n-nodes-base.httprequest, n8n-nodes-base.googledrivetrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Ali HAIDER.

Original n8n.io source

1.1 Workflow description

Title
Create a RAG Telegram bot using Google Drive, PostgreSQL, and local Ollama
Workflow name
Create a RAG Telegram bot using Google Drive, PostgreSQL, and local Ollama

Who's it for

This template is for developers, teams, and automation enthusiasts who want a private, PIN-protected Telegram chatbot that answers questions from their own documents — without relying on external AI APIs. Ideal for internal knowledge bases, private document search, or anyone running a local LLM stack with Ollama.

How it works / What it does

The workflow has two flows running in parallel:

Document Ingestion: Monitors a Google Drive folder for new files. When a file is added, it is downloaded, split into 500-character chunks (with 50-character overlap), embedded using Ollama's nomic-embed-text model, and stored in a PostgreSQL database with pgvector. Telegram Bot: Accepts messages from users. New users are registered and prompted for a PIN code. Once verified, users can ask any question in plain text. The question is embedded, the top 5 most similar document chunks are retrieved via cosine similarity, and qwen2.5:7b generates a context-aware answer which is sent back to the user. All queries are logged.

How to set up

Enable the pgvector extension in PostgreSQL and create the 4 required tables — full SQL is included in the workflow's sticky notes Install Ollama and pull the required models: ollama pull nomic-embed-text and ollama pull qwen2.5:7b Add your credentials in n8n: Telegram Bot token (from @BotFather), PostgreSQL connection, and Google Drive OAuth2 Open the Google Drive Trigger node and select the folder you want to monitor In the Register New User node, replace YOUR_PIN_CODE with your chosen access PIN Activate the workflow and send a message to your Telegram bot

Requirements

Ollama running locally (accessible at http://host.docker.internal:11434 if using Docker) PostgreSQL with pgvector extension (Supabase free tier works) Telegram Bot token from @BotFather Google Drive account

How to customize the workflow

Change the LLM model: Replace qwen2.5:7b in the Build Prompt node with any Ollama-supported model Change the embedding model: Replace nomic-embed-text in Embed Query and Embed Chunk nodes (update vector dimension in the DB schema accordingly) Adjust chunk size: Modify chunkSize and overlap values in the Split Into Chunks node Change top-K results: Edit the .slice(0, 5) in Build Prompt to return more or fewer context chunks Customize the system prompt: Edit the system message in Build Prompt to change the bot's persona or restrict its scope.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - ⚙️ Setup Instructions

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 2 - 📌 Change Default PIN

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 3 - 📌 Set Your Folder

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Telegram Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 2

Block 5 - Get User

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.5

Block 6 - User State Router

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 7 - Is New User?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2

Block 8 - Register New User

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.5

Block 9 - Send PIN Request

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 10 - Is Verified?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2

Block 11 - Has Text?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2

Block 12 - No Text Message

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 13 - Embed Query

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 14 - Format Query Embedding

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 15 - Search Documents

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.5

Block 16 - Build Prompt

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 17 - Ask LLM

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 18 - Send Answer

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 19 - Log Query

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.5

Block 20 - PIN Correct?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2

Block 21 - Mark User Verified

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.5

Block 22 - Send Welcome

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 23 - Wrong PIN Message

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 24 - Google Drive Trigger

Type / Role
n8n-nodes-base.googleDriveTrigger - googleDriveTrigger
Config choices
Version 1

Showing the first 24 of 35 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Create a RAG Telegram bot using Google Drive, PostgreSQL, and local Ollama
Complexity advanced
Nodes 35
Categories Internal Wiki, AI RAG
Author Ali HAIDER
Published 13 Apr 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/15031/15031.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Create a RAG Telegram bot using Google Drive, PostgreSQL, and local Ollama do?

Who's it for This template is for developers, teams, and automation enthusiasts who want a private, PIN protected Telegram chatbot that answers questions from their own documents — without relying ...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Internal Wiki, AI RAG use case.