Skip to main content

Process multiple media files in Telegram with Gemini AI & PostgreSQL database

Workflow preview

Workflow preview
100%
Process multiple media files in Telegram with Gemini AI & PostgreSQL database preview
Open on n8n.io

Important notice

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

1. Workflow Overview

Telegram AI Assistant with Multi File Media Group Handling, Smart File Processing & PostgreSQL Integration AI powered Telegram bot for text, voice, video, documents & media β€” with databas...

Best for

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

Tools used

n8n-nodes-base.telegram, n8n-nodes-base.switch, n8n-nodes-base.if, n8n-nodes-base.postgres, n8n-nodes-base.wait, n8n-nodes-base.set, n8n-nodes-base.code, n8n-nodes-base.postgrestrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by John Alejandro SIlva.

Original n8n.io source

1.1 Workflow description

Title
Process multiple media files in Telegram with Gemini AI & PostgreSQL database
Workflow name
Process multiple media files in Telegram with Gemini AI & PostgreSQL database

πŸ€–πŸ“¨ Telegram AI Assistant with Multi-File Media Group Handling, Smart File Processing & PostgreSQL Integration

> AI-powered Telegram bot for text, voice, video, documents & media β€” with database-driven grouping and Telegram-safe formatting.


πŸ“‹ Description

This n8n template creates a next-generation Telegram AI assistant πŸ§ πŸ’¬ capable of handling text messages, media files, and documents with advanced processing, PostgreSQL integration, and AI-powered responses.

It is designed to solve Telegram’s media group challenge πŸ“¦ β€” when multiple files are sent together, they are stored, processed, and combined into one coherent AI-generated reply.

✨ Key Features

  • πŸ“‚ Multi-file media group management with PostgreSQL:
    • media_group
    • media_queue
    • chat_histories
  • πŸ“‘ Document parsing for CSV, HTML, ICS, JSON, ODS, PDF (with AI fallback), RTF, TXT, XML, and spreadsheets.
  • 🎀 Voice & video transcription for AI analysis.
  • πŸ–ΌοΈ Image, audio, and video description for richer AI context.
  • πŸ›‘οΈ Telegram-safe MarkdownV2 formatting with auto-splitting for messages over 4096 chars.
  • ⚠️ Error fallback for unsupported file types.

πŸ’‘ Acknowledgment

A huge thank you to Ezema Gingsley Chibuzo πŸ™Œ for the inspiration of the first version of this workflow:
Create a Multi-Modal Telegram Support Bot with GPT-4 and Supabase RAG
Your pioneering work laid the foundation for this improved, database-powered multi-modal assistant πŸš€


🏷 Tags

telegram ai-assistant postgresql multi-file media-group
file-processing voice-transcription document-parser pdf-extraction
markdown-formatting n8n-template


πŸ’Ό Use Case

Use this template if you need an AI-powered Telegram bot that can:

  • πŸ“¦ Handle multiple files sent in a single message (albums, multiple PDFs, etc.).
  • 🧾 Extract & analyze content from many file formats.
  • πŸŽ™οΈ Transcribe voice and video messages.
  • πŸ—‚οΈ Maintain chat memory for contextual AI answers.
  • πŸ›‘οΈ Avoid Telegram formatting errors and length limit issues.

This workflow automates the full chain: Receive β†’ Process β†’ AI Analysis β†’ Telegram-safe Reply.


πŸ’¬ Example User Interactions

  • πŸ“„ Multiple PDFs with a caption β†’ AI extracts and summarizes all PDFs in one combined reply.
  • 🎀 Voice message β†’ AI transcribes and replies with a contextual answer.
  • πŸ“Š CSV or spreadsheet file β†’ AI parses and summarizes the data.
  • πŸ–ΌοΈ Multiple images β†’ AI describes each image and replies in a single message.

πŸ”‘ Required Credentials

  • Telegram Bot API (Bot Token)
  • PostgreSQL (Connection credentials)
  • AI Provider API (OpenAI, Google Gemini, or compatible LLM)

βš™οΈ Setup Instructions

  1. πŸ—„οΈ Create the PostgreSQL tables (Gray section SQL):
    • media_group
    • media_queue
    • chat_histories
  2. πŸ”Œ Configure the Telegram Trigger with your bot token.
  3. πŸ€– Connect your AI provider credentials.
  4. πŸ—‚οΈ Set up PostgreSQL credentials in the database nodes.
  5. ▢️ Deploy the workflow in n8n.
  6. 🎯 Start sending messages and files to your bot.

πŸ“Œ Extra Notes

  • βœ… Green section ensures only one trigger per media group.
  • πŸ“Œ Yellow section guarantees captions and files are stored in the correct sequence.
  • ✨ Purple section formats AI output to be Telegram-safe and split if needed.
  • 🧠 AI prompt is not fixed, allowing full customization.

πŸ’‘ Need Assistance?

If you’d like help customizing or extending this workflow, feel free to reach out:

πŸ“§ Email: [email protected]
πŸ”— LinkedIn: John Alejandro Silva RodrΓ­guez

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 - Download Voice Message

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 2 - Send a text message1

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 3 - Input Message Router1

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

Block 4 - Media_group?2

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 5 - Captions?1

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 6 - Media_group?3

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 7 - Insert documents in media_group

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

Block 8 - Insert documents in media_group1

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

Block 9 - Wait

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

Block 10 - Insert media_queue with captions (Trigger)

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

Block 11 - Insert media_queue (Trigger)

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

Block 12 - Get_file_and_captions

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

Block 13 - get_message (text)

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

Block 14 - Get_only_file

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

Block 15 - unified_variables

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

Block 16 - Wait for all the files

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

Block 17 - Get all files from group_id

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

Block 18 - Media_queue Trigger

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

Block 19 - get_chat_id

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

Block 20 - When clicking β€˜Execute workflow’

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

Block 21 - Create Tables

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

Block 22 - AI Agent1

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

Block 23 - Group Similar Documents

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

Block 24 - Download CSV

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

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

3. Summary Table

Workflow Process multiple media files in Telegram with Gemini AI & PostgreSQL database
Complexity advanced
Nodes 102
Categories Support Chatbot, Multimodal AI
Author John Alejandro SIlva
Published 15 Aug 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/7455/7455.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 Process multiple media files in Telegram with Gemini AI & PostgreSQL database do?

Telegram AI Assistant with Multi File Media Group Handling, Smart File Processing & PostgreSQL Integration AI powered Telegram bot for text, voice, video, documents & media β€” with databas...

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, Multimodal AI use case.