AI Document Assistant via Telegram with Gemini and Supabase - n8n Workflow

Deploy a custom AI Document Q&A chatbot on Telegram using this powerful n8n workflow. Integrates Google Gemini, Supabase vector storage, and advanced RAG capabilities. Explore n8n templates for AI.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users needing a private, centralized knowledge base accessible via a messaging app.
Technical users and developers looking for advanced n8n templates integrating LangChain agents and vector databases.
Businesses aiming to automate document information retrieval (RAG).
Anyone interested in leveraging Google Gemini's embedding and chat models within a custom n8n workflow.

Overview

This automation solves the problem of siloed document data by transforming your PDF files into a searchable knowledge base accessible via Telegram. The core of this system is a powerful n8n workflow that uses a Telegram Trigger to initiate one of two scenarios: either processing a document for ingestion or answering a user's conversational query.

When a PDF is uploaded, the n8n node structure handles downloading the file, extracting text, generating vector embeddings using the Google Gemini model, and securely storing them in a Supabase vector store. When a question is asked, the system performs Retrieval-Augmented Generation (RAG) by fetching the most relevant document chunks from Supabase before generating a final, contextually rich answer using the Gemini Chat Model. This seamless integration showcases the power of building advanced AI assistants using n8n and its specialized AI n8n nodes.

How it Works

The entire process is controlled by a single n8n workflow, starting with the Telegram Trigger n8n node:


  1. Trigger & Routing: The Telegram Trigger fires upon receiving any message. A Command Router n8n node inspects the incoming payload to determine if it contains a document (PDF upload) or text (chat message).

  2. Document Ingestion Flow (PDF Upload):

The file is downloaded using a Telegram n8n node.
Extract from File extracts text content from the PDF.
The text is split into manageable chunks using the Recursive Character Text Splitter n8n node.
Embeddings Google Gemini generates high-dimensional vectors for each chunk.
Supabase - Save Embeddings stores these vectors and the corresponding text chunks into the userknowledgebase table in your Supabase instance.

  1. Chat Interaction Flow (Text Message):

The user message is passed to the AI Agent n8n node, which maintains conversation history via the Simple Memory n8n node.
The Agent determines if it needs external data. It can use the Answer questions with a vector store tool (RAG via Supabase/Gemini) for document-specific questions or the OpenWeatherMap tool for real-time weather data.
The core logic uses the Google Gemini Chat Model for reasoning and response generation.

  1. Response Formatting: The resulting LLM text flows through a Code n8n node (Handle formatting and split). This critical step cleans up HTML formatting (as LLMs often generate unsupported tags) and splits the potentially long response into multiple messages to adhere to Telegram's 4096-character limit. The final messages are delivered via the Telegram n8n node.

Installation Guide

To deploy this specialized n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and import it directly into your n8n instance via the 'Workflows' > 'New' > 'Import from JSON' option. Activate the workflow.

  2. Set up Credentials: This n8n template requires connections to four external services. Create the necessary credentials within n8n:

Telegram API: Needed for the n8n trigger and all reply nodes.
Google Gemini: Required for both the Google Gemini Chat Model and the Embeddings Google Gemini n8n node.
Supabase: Needed for the vector store operations (insertion and retrieval).
OpenWeatherMap: (Optional) For the weather tool.

  1. Configure Supabase: You must enable the pgvector extension and run the provided SQL script to create the userknowledgebase table and the matchdocuments function. Ensure the table name userknowledge_base is correctly configured in the Supabase Vector Store n8n node and the Supabase - Save Embeddings n8n node.

Node Details

Telegram Trigger (n8n trigger): Starts the n8n workflow upon receiving a Telegram message (text or document).
Command Router (Switch): Directs the flow based on whether the input is a file (document) or a chat message (text).
AI Agent (Langchain Agent n8n node): The brain of the chat flow. Uses the Gemini model and orchestrates the use of specialized tools based on the user's query.
Simple Memory (Langchain Memory n8n node): Stores conversation history linked to the user's ID (sessionKey) to maintain context in the n8n workflow.
Answer questions with a vector store (Langchain Tool n8n node): The RAG tool. Used by the AI Agent to query the Supabase knowledge base for relevant document snippets.
Supabase Vector Store (n8n node): Configured for retrieval, enabling similarity search against the userknowledgebase table.
Embeddings Google Gemini (n8n node): Generates 768-dimension vectors for document chunks during the ingestion process.
Extract from File (n8n node): Specifically configured to extract text from the PDF file downloaded from Telegram.
Recursive Character Text Splitter (n8n node): Optimally breaks down large documents into smaller, meaningful chunks before embedding.
Handle formatting and split (Code n8n node): A custom Python script that post-processes the AI's output, removing unsupported Telegram HTML tags, escaping characters, and splitting the final message into chunks to ensure successful delivery via the Telegram n8n node.

Related n8n Workflows

Free

Nodes: 19 Nodes
Updated: December 26 2025
View all
Created by

A Senior Software Engineer with over 14 years of experience, I'm a coding enthusiast passionate about building scalable full-stack and backend cloud solutions.

Featured*