Skip to main content

Telegram AI chatbot with document-based answers using OpenAI and PGVector RAG

Workflow preview

Workflow preview
100%
Telegram AI chatbot with document-based answers using OpenAI and PGVector RAG preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

AI Q&A Chatbot Workflow – Build Your Own AI Agent Trained on Private Documents This powerful AI automation add on upgrades your [Telegram Bot Starter Template](https://n8n.io/workflows/2402 tele...

Best for

  • Support Chatbot automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.documentdefaultdataloader, @n8n/n8n-nodes-langchain.embeddingsopenai, n8n-nodes-base.stickynote, n8n-nodes-base.googledrive, n8n-nodes-base.googledrivetrigger, n8n-nodes-base.extractfromfile, n8n-nodes-base.set

Source and attribution

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

Original n8n.io source

1.1 Workflow description

Title
Telegram AI chatbot with document-based answers using OpenAI and PGVector RAG
Workflow name
Telegram AI chatbot with document-based answers using OpenAI and PGVector RAG

🤖 AI Q&A Chatbot Workflow – Build Your Own AI Agent Trained on Private Documents

This powerful AI automation add-on upgrades your Telegram Bot Starter Template by integrating a fully functional AI chatbot and a context-aware AI agent that answers user questions using your internal documents.

Unlike generic bots, this chatbot uses your own data to respond with deeply personalized, context-relevant information — perfect for support, onboarding, internal knowledge access, and client-facing interactions.

It connects to any PostgreSQL database — including Neon.tech, Supabase, or a self-hosted Postgres setup — allowing you to build custom AI-powered FAQ assistants, internal support bots, or knowledge-based customer service tools.


🧠 Why It Works: Contextual Retrieval

The secret is Contextual Retrieval — a powerful technique where your documents are stored in a way that preserves meaning and context. This allows the AI to fetch highly relevant, source-backed responses, eliminating hallucinations and guesswork.

> Data is embedded, chunked, and saved in a vector database (Postgres + PGVector), enabling smart semantic search tailored to your needs.

📖 Learn more about this approach in this article by Anthropic →


✨ Key Features

  • Chat with your internal documents: Uses your content to answer questions with precision
  • Built-in document vectorization: Pre-configured Google Drive ingestion flow (Notion, Airtable, Dropbox available separately)
  • Contextual memory: Past chats stored in PostgreSQL for personalized conversations
  • Plug-and-play architecture: Connect Supabase, OpenAI, custom APIs via n8n’s interface

👤 Who Can Use This Workflow?

  • Entrepreneurs & startups building branded AI chatbots without code
  • Customer support teams automating answers using documentation
  • Ops teams creating internal FAQ bots for onboarding and training
  • No-code developers using n8n to build Telegram bots with AI features

⚙️ Setup Instructions

You'll find step-by-step instructions inside the workflow.

Quick Setup Overview:

  1. Import the workflow into n8n (cloud or self-hosted)
  2. Add your Telegram Bot credentials
  3. Connect your PostgreSQL DB (Neon, Supabase, etc.)
  4. Set up document ingestion from Google Drive
  5. Activate the workflow and start chatting

🧩 Extensibility

This workflow is modular and ready to expand. Build powerful assistants by connecting additional workflows:


🧠 More Smart AI Agents

Explore more AI workflows and agents on my Gumroad →

  • 🌐 Agent: Find in the Internet — fetches live info from the web
  • 📁 Agent: Search Internal Docs — queries Notion, Google Drive, etc.
  • 📦 Agent: Check Order Status — reads status from Airtable or CRM
  • 💰 Agent: Calculate Cost or Quote — builds pricing logic from inputs

📨 Submit your idea here for a custom AI agent →

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 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1

Block 2 - Default Data Loader

Type / Role
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - documentDefaultDataLoader
Config choices
Version 1

Block 3 - Embeddings OpenAI1

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1

Block 4 - Sticky Note1

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

Block 5 - Download File

Type / Role
n8n-nodes-base.googleDrive - googleDrive
Config choices
Version 3

Block 6 - File Created

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

Block 7 - File Updated

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

Block 8 - Extract Document Text

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

Block 9 - Set File ID

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 10 - RAG AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.6

Block 11 - Loop Over Items

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 12 - Recursive Character Text Splitter

Type / Role
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter - textSplitterRecursiveCharacterTextSplitter
Config choices
Version 1

Block 13 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 14 - Create Chunks From Doc

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

Block 15 - Chunks To List

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

Block 16 - Generate Contextual Text

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.4

Block 17 - OpenAI Chat Model3

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 18 - Get Values

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 19 - Postgres PGVector Store

Type / Role
@n8n/n8n-nodes-langchain.vectorStorePGVector - vectorStorePGVector
Config choices
Version 1.1

Block 20 - Delete Old Doc Records

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

Block 21 - When Executed by Another Workflow

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 22 - Docs RAG Tool

Type / Role
@n8n/n8n-nodes-langchain.vectorStorePGVector - vectorStorePGVector
Config choices
Version 1.1

Block 23 - Embeddings

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 24 - Chat Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryPostgresChat - memoryPostgresChat
Config choices
Version 1

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

3. Summary Table

Workflow Telegram AI chatbot with document-based answers using OpenAI and PGVector RAG
Complexity advanced
Nodes 29
Categories Support Chatbot, AI RAG
Author Victor Gold
Published 08 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/4799/4799.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 Telegram AI chatbot with document-based answers using OpenAI and PGVector RAG do?

AI Q&A Chatbot Workflow – Build Your Own AI Agent Trained on Private Documents This powerful AI automation add on upgrades your [Telegram Bot Starter Template](https://n8n.io/workflows/2402 tele...

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 Support Chatbot, AI RAG use case.