Telegram Media Group Processor with Multimodal AI and Data Tables Cache - n8n Workflow

Use this robust n8n workflow to reliably capture full Telegram media groups (image albums), utilize an n8n Data Table for message queuing and stability, and process the resulting images and text via NanoBanana (Gemini) multimodal AI through the OpenRouter API.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Users managing community Telegram bots that frequently receive photo albums requiring processing or analysis.

  • Developers needing robust asynchronous handling of large media inputs in n8n.

  • Anyone looking for advanced examples of using n8n Data Tables for queuing and flow control.

  • Automation specialists building powerful multimodal AI integrations using n8n templates.

Overview

Handling image albums (media groups) in messaging apps like Telegram can be challenging in real-time automations, as individual messages arrive separately. This advanced n8n workflow solves this by implementing a caching layer using the built-in n8n Data Table.

When a user sends a media group, the Telegram n8n trigger captures each piece, storing it immediately as a 'new' record in the Data Table. A separate, scheduled n8n trigger then periodically checks the queue. It uses complex logic to wait a defined period (7 seconds) to ensure the entire album has arrived before merging all components and submitting the full context (images and caption) to a multimodal AI model (NanoBanana/Gemini via OpenRouter). This approach ensures reliability, even with slow internet connections, making this one of the most stable n8n templates for media processing.

How it Works

The n8n workflow operates in two asynchronous paths:

1. Ingestion and Queueing (Telegram Trigger)


  1. The primary n8n trigger is the Telegram Trigger, which fires upon receiving any message update.

  2. The flow uses an If n8n node to check if the incoming message is part of a media group and contains an image (photo).

  3. If conditions are met, the workflow uses a Filter n8n node (Filter1) to detect if a caption is present. If so, a Send initial notification is immediately sent to the user acknowledging receipt.

  4. The Upsert row(s) n8n node then saves the message details (chatid, messageid, mediagroup, and the full JSON message) into the Data Table with the status 'new'.

2. Processing and AI Generation (Schedule Trigger)


  1. The second path is activated by a Schedule Trigger n8n trigger, configured to run every 5 seconds, checking the processing queue.

  2. The flow first checks If any new records exist in the Data Table using the rowExists operation.

  3. If new records are found, Get new requests retrieves all 'new' messages.

  4. A key step is the delay check: Latest message in mediagroup identifies the timestamp of the last message in a group. The subsequent Filter n8n node ensures that the final message was received at least 7 seconds ago, confirming the album upload is complete.

  5. The Merge n8n node combines all records belonging to the same media group ID.

  6. The records status is updated to 'processing' in the Data Table.

  7. The flow retrieves the full file path for each image using the Get a file Telegram n8n node.

  8. The data is prepared (prepare user messages) into a multimodal input array structure (text and image URLs).

  9. The Summarize n8n node aggregates all prepared image and text inputs for a single group, forming the complete prompt for the AI.

  10. The Call NanoBanana via OpenRouter n8n node sends this multimodal prompt to the Gemini model for processing. The model returns a generated image in Base64 format.

  11. The Base64 output is extracted and converted into binary data using the Convert to File n8n node.

  12. Finally, the generated image is sent back to the user via the Send result message Telegram n8n node, and the Data Table status is updated to 'done' using the final status:done n8n node.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:

1. Import the n8n Workflow


  1. Copy the provided JSON code.

  2. In your n8n interface, click 'New' > 'Import from JSON'. Paste the JSON code to load the n8n templates.

2. Set up Credentials


  1. Telegram API: You need two sets of Telegram credentials, though they use the same bot token. Create a new Telegram Credential, supplying your bot's token (obtained from @BotFather). Ensure the credential is linked to the Telegram Trigger node and the Telegram nodes (Get a file, Send initial notification, etc.).

  2. OpenRouter API: Create an OpenRouter API credential and link it to the Call NanoBanana via OpenRouter n8n node.

3. Configure the Data Table


  1. Go to 'Data Tables' in your n8n instance and create a new Data Table named 'TGmediagroup' (or ensure the node IDs match your created table).

  2. The table schema must include the following string columns, as referenced by the Upsert row(s) n8n node:

- chatid
- messageid
- media
group
- message
- status

4. Update the Telegram Download URL


  1. Locate the prepare user messages n8n node (Set node).

  2. In the expression for the 'img' assignment, you will find a placeholder URL for downloading files: https://api.telegram.org/file/bot/...

  3. Crucially, replace with your actual Telegram bot token to ensure the multimodal AI can access the image files directly.

Node Details


  • Telegram Trigger (n8n trigger): Initiates the ingestion flow whenever a new message is received in the configured Telegram bot, capturing the payload for image album processing.

  • If (Is media group with images?): A core logic n8n node that branches the flow, only proceeding if both mediagroupid and photo data are present in the Telegram update.

  • Data Table (Upsert row(s), Get new requests, status:processing, status:done): Essential n8n nodes for implementing the asynchronous queue. It stores incoming media group messages, retrieves 'new' records, and manages the status lifecycle ('new' -> 'processing' -> 'done'). This is key for robust flow control in this n8n workflow.

  • Schedule Trigger (n8n trigger): This auxiliary n8n trigger is set to run periodically (every 5 seconds) to check the Data Table queue, providing the asynchronous processing heartbeat for the n8n workflow.

  • Summarize (Latest message in mediagroup, Summarize): Used for advanced data manipulation. The first instance finds the latest timestamp in the group for stabilization, and the second aggregates all individual image URLs and the caption text into a single, cohesive payload for the multimodal AI.

  • Filter (Check if latest message has sufficient delay): Ensures a 7-second wait after the last known message in the media group before processing, guaranteeing the entire album is fully uploaded and received before being merged.

  • Merge (Merge): Combines the individual rows from the Data Table back into complete media group sets based on the shared mediagroup ID, allowing the full album to be processed together.

  • HTTP Request (Call NanoBanana via OpenRouter): This critical n8n node handles the multimodal AI processing. It sends the aggregated image and text payload to the OpenRouter API, specifically calling a multimodal model like Gemini-2.5-Flash to generate or process the input, demonstrating a key capability of n8n templates.

  • Convert to File: Transforms the Base64 image output received from the AI service into a usable binary file format, which is required for the Telegram n8n node to send the result.

Related n8n Workflows

Free

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

Featured*