Build an advanced multimodal Telegram chatbot using n8n that processes text, audio, images, videos, and various document types (PDF, CSV, HTML, XLSX). This n8n workflow uses PostgreSQL for state management and Gemini AI for intelligent analysis and chat memory.
Download this n8n workflow template and start using it instantly.
This comprehensive n8n workflow transforms a standard Telegram bot into an advanced multimodal AI assistant. The core challenge solved here is synchronizing and processing messages sent as a media group (multiple files in a single Telegram message), which traditional chatbots struggle with. This n8n workflow uses PostgreSQL as a temporary queue and permanent chat memory store.
It handles a vast range of inputs: simple text messages, voice notes, video clips, and documents like PDF, CSV, and XLSX. It leverages Google Gemini for image, audio, and video analysis, generating a detailed description that is passed to a conversational AI agent. For structured documents, it employs built-in Extract from File functionality within an n8n node to pull data before sending it to the AI for summarization, ensuring rich context for every interaction. This complex flow demonstrates best practices for building robust, stateful applications with n8n.
This n8n workflow operates on two parallel tracks, orchestrated by two different types of n8n trigger nodes:
Telegram Trigger node initiates the flow upon receiving any message. It first sends a 'Typing…' signal. An Input Message Router checks the message type (Text, Voice, Video, Document, etc.).Code node classifies the file extension, routing it through specialized Extract from File nodes. This extraction is converted into a standard data string.mediagroupid (multiple files), the workflow temporarily stores the file description in the mediagroup PostgreSQL table. If this is the first item in the group, it inserts an entry into the mediaqueue table, triggering the second flow.Mediaqueue Trigger node constantly monitors the PostgreSQL mediaqueue table. When a new media group ID is detected, it waits a few seconds (ensuring all parts of the group are received), then queries the mediagroup table to retrieve all individual file descriptions and captions.AI Agent1 node. This LangChain-based n8n node uses the Google Gemini Chat Model and retrieves conversation history from the Postgres Chat Memory node (chathistories table) to maintain context. The AI's final response is passed through a custom Code node that handles MarkdownV2 formatting for Telegram and automatically chunks messages longer than 4096 characters, ensuring delivery integrity. Finally, the response is sent back to the user via the Send a text message1 node.To deploy this powerful n8n template, follow these installation steps:
Postgres Trigger (Media Queue), Postgres Chat Memory, and table creation nodes. Configure the connection details (host, port, user, database).gemini-2.5-pro, gemini-2.5-flash) are available.n8n node) to execute the 'Create Tables' node and initialize the necessary mediagroup, mediaqueue, and chat_histories tables in your PostgreSQL database.n8n workflow.updates: message.n8n trigger. Monitors the mediaqueue table for new media group IDs requiring consolidated processing.manualTrigger to set up the three required database tables for state management and chat history.n8n node that dynamically routes the workflow based on the incoming Telegram message type (Text, Voice, Document, etc.).fileid.n8n node used before Gemini multimodal analysis to manually correct or assign standard MIME types to files, improving AI analysis reliability.n8n node types (Analyze image, Analyze voice message, Analyze document) that leverage Gemini's multimodal capabilities to generate textual descriptions from binary media files.n8n node for parsing structured data from documents like CSV, JSON, ODS, and PDF into consumable text for the AI.n8n node. It integrates the Google Gemini Chat Model and the Postgres Chat Memory to handle complex, contextual conversations.Learn how to build an efficient n8n workflow to handle bulk file uploads from a form, process binary data sequentially using an n8n loop, and save each file. Use this n8n template for advanced file management.

Automate meeting note summarization and task extraction using an n8n workflow with AI (Anthropic/OpenAI) and Notion. Sync transcripts to Google Drive and manage tasks automatically.

Automate local document analysis using an n8n workflow leveraging local AI models like Ollama. This powerful n8n template extracts text, runs an AI Agent, and saves sophisticated reports directly to your disk.

Automate massive parallel processing of prompts using the Azure OpenAI Batch API. This n8n workflow template handles file upload, polling, and result parsing for high-throughput AI tasks.

Automate OCR document ingestion from Google Drive into a Pinecone vector database using an advanced n8n workflow. This n8n template handles complex Arabic text cleaning, metadata extraction, and OpenAI embeddings for building scalable RAG knowledge bases.









































