Use this comprehensive n8n workflow to build a powerful Telegram AI Chatbot leveraging Retrieval-Augmented Generation (RAG). Integrate OpenAI and PGVector for contextual answers from your documents. Find essential n8n templates here.
Download this n8n workflow template and start using it instantly.



















Automation Specialists seeking advanced RAG n8n templates.
Teams needing a custom, document-aware AI assistant.
Developers implementing PostgreSQL vector storage (PGVector).
Users looking for a production-ready RAG architecture in n8n.
This sophisticated n8n workflow solves the challenge of providing highly accurate, document-contextualized responses via an AI chatbot. It is fundamentally split into two processes: Document Ingestion and AI Query Handling.
The ingestion path automatically detects new or updated files in Google Drive (using an n8n trigger), processes them, deletes old vectors, and saves new vector embeddings into a PostgreSQL PGVector store. This ensures the knowledge base is always current.
The AI Query path leverages this RAG knowledge base. When a user sends a message, the n8n agent uses the OpenAI Chat Model, PGVector tools, and chat memory to generate informed, contextual responses, making this a crucial n8n workflow for modern AI applications.
The entire automation is a two-part n8n workflow:
Loop Over Items n8n node handles each file individually.Set File ID node extracts key metadata, which is used by the Delete Old Doc Records (Postgres n8n node) to maintain data hygiene in the PGVector store.Extract Document Text n8n node.Code n8n node (Create Chunks From Doc) prepares the text.OpenAI Chat Model3 and an LLM Chain n8n node.Embeddings OpenAI1 generates vector representations, which are saved into the Postgres PGVector Store, completing the document ingestion part of this n8n workflow.When Executed by Another Workflow n8n trigger (designed to receive user input from an external chat application like Telegram).RAG AI Agent n8n node, which orchestrates the query process.OpenAI Chat Model for reasoning and the Chat Memory (Postgres) n8n node to remember conversation history.Docs RAG Tool (Postgres PGVector Store) as its external knowledge base. The user query is vectorized by the Embeddings n8n node to search for relevant document chunks in the vector store before generating a final, contextual answer.To deploy this RAG n8n template, follow these steps:
File Created and File Updated n8n trigger nodes.Delete Old Doc Records, Postgres PGVector Store, and Chat Memory n8n nodes.OpenAI Chat Model and Embeddings OpenAI n8n nodes.When Executed by Another Workflow n8n trigger must be linked to a separate n8n workflow (e.g., a Telegram Listener) that captures user messages and executes this workflow with the user's input. Google Drive Trigger (File Created/Updated): Acts as the initial n8n trigger, monitoring a specific folder for new or changed documents that should be added to the knowledge base.
Delete Old Doc Records (Postgres): This essential n8n node executes a SQL query to remove existing embeddings associated with an updated file, preventing stale data.
Extract Document Text (n8n node): Converts binary files (downloaded from Google Drive) into plain text for processing and chunking.
Create Chunks From Doc (Code): A custom n8n node script used to format the extracted document text appropriately for the subsequent text splitter.
Postgres PGVector Store (n8n node): Used in two contexts: for writing new vector embeddings during ingestion, and as the RAG Tool to retrieve relevant context during a query. This is central to the RAG n8n workflow design.
Embeddings OpenAI (n8n node): Generates high-dimensional vector embeddings for document chunks and incoming chat queries.
RAG AI Agent (Langchain Agent): The primary n8n node for the chat response. It intelligently decides whether to use the internal language model or consult the external Docs RAG Tool based on the user's question and context.
OpenAI Chat Model (n8n node): Provides the language model capabilities for generation and reasoning within the n8n workflow.
Deploy a powerful Telegram AI chatbot agent using n8n and InfraNodus GraphRAG knowledge bases. This advanced n8n workflow utilizes multiple specialized AI experts for contextual retrieval.

Leverage this powerful n8n workflow to build a custom Telegram AI bot. This template supports both large language model chat and image generation using the NeurochainAI API, complete with robust error handling and prompt management.

Control usage and manage operational costs for your public Telegram AI assistant using this sophisticated n8n workflow. It implements per-user message limits, tracks consumption in Google Sheets, and features a scheduled reset mechanism.

Deploy a powerful n8n workflow to run a Telegram AI chatbot using OpenAI. Supports conversational chat, /start greetings, and DALL-E image generation. Get this n8n template now.

Create a powerful Telegram AI chatbot using this advanced n8n workflow. It supports text and voice inputs (using OpenAI Whisper), utilizes GPT-4o for intelligent responses, and maintains conversation history.

Automation & AI expert with over 7 years of experience in the digital & tech industry. Founder digital design, web & mobile development studio INSAIM.DESIGN. Focusing on startups & tech companies and helping to streamline their processes with AI and automation.







































