Process Multiple Media Files in Telegram with Gemini AI & PostgreSQL Database
VerifiedProcesses Telegram media groups with Gemini AI and PostgreSQL storage.
What this workflow does
This n8n workflow ingests multi-file Telegram messages, stores them in Postgres for grouping, and uses Google Gemini to produce a single coherent response.
It is intended for developers and teams building Telegram bots that require reliable media handling, database-backed context, and AI-generated replies.
Who is this for?
Telegram bot developers, AI product teams, and support/content teams that manage media-heavy conversations and need structured storage of chat history.
What problem it solves
Telegram sends media groups as separate updates, making it hard to process multiple files together and maintain context; without database memory, AI responses lose continuity across sessions.
What it automates
Customer support media intake
Users send photos of receipts or documents in one message; the workflow groups them, runs Gemini analysis, stores results in Postgres, and replies with a single formatted answer.
Content moderation queue
Moderators forward batches of images or videos; the bot processes the entire group with Gemini, logs decisions in PostgreSQL, and returns a summary without hitting Telegram message limits.
Research assistant archive
Researchers drop multiple PDFs and voice notes; files are combined into one Gemini prompt, chat memory is saved per user in Postgres, and a clean HTML-formatted report is returned.
How the workflow works
The 8 nodes in this automation, in order.
- 1Postgrespostgres
- 2Telegramtelegram
- 3Codecode
- 4HTMLhtml
- 5AI Agent@n8n/n8n-nodes-langchain.agent
- 6Google Gemini Chat Model@n8n/n8n-nodes-langchain.lmChatGoogleGemini
- 7Postgres Chat Memory@n8n/n8n-nodes-langchain.memoryPostgresChat
- 8Google Gemini@n8n/n8n-nodes-langchain.googleGemini
Apps & integrations used
How to set up Process Multiple Media Files in Telegram with Gemini AI & PostgreSQL Database
- 1Import the JSON workflow into n8n
- 2Add Telegram Bot API credentials and connect the Telegram trigger node
- 3Create a Postgres database and add credentials to the Postgres and Postgres Chat Memory nodes
- 4Add Google Gemini API key to the Google Gemini Chat Model and AI Agent nodes
- 5Activate the workflow and send a test media group to your Telegram bot
- 6Verify that grouped files appear as one record in the Postgres table
How to customize this workflow
- →Replace Google Gemini with another supported chat model node
- →Add an HTML node to change response formatting or add buttons
- →Extend Postgres schema to store additional metadata fields
- →Insert a filter node to skip certain file types before the AI Agent
Process Multiple Media Files in Telegram with Gemini AI & PostgreSQL Database: pros & cons
Pros
- +Solves Telegram media-group splitting automatically
- +Uses Postgres for persistent per-user chat memory
- +Returns Telegram-safe formatted replies via HTML node
- +Combines multiple files into a single coherent Gemini response
Cons
- –Requires separate API keys for Telegram and Gemini
- –Postgres setup needed for memory feature to work
- –Intermediate complexity due to multiple AI and DB nodes
Frequently asked questions
It receives text, voice, video, documents and media groups via Telegram, groups files together, processes them with Gemini AI, stores conversation history in Postgres, and returns a single formatted reply.
User reviews
Verified reviews from the community shape this listing's rating.
Loading reviews…