Dynamically send variable groups of media on Telegram with n8n

Hi everyone,

I’m currently working on a workflow for a Telegram bot, and I need some advice on whether my approach is correct and how to simplify things.


What I’m trying to achieve:

  1. My Telegram bot receives groups of media (between 1 and 10 files) composed of a mix of photos and videos. These groups may be compressed or uncompressed.
  2. I save the media_id and media_type for each file in a MySQL database because some files exceed the download limits of Telegram’s API, and I only need to forward these files later using the media_id.
  3. I need to send all the media back as a single media group on Telegram to a user.

Where I’m stuck:

I already know how to handle this when the number of media files is fixed. For example, if I know there will be exactly 3 files, I can configure everything to send them correctly. However, when the number of media files is unknown in advance (1-10 files, mixed types), I get stuck trying to:

  • Dynamically handle the variable number of media files and types.
  • Format and manage everything in an expression inside a single Telegram Send Message node (if that’s even possible), to reduce complexity and avoid adding extra nodes.

What I’ve done so far:

  1. I’m using a Telegram Trigger node to receive the media and process them.
  2. I’m storing the media_id and type (photo or video) in a MySQL database.
  3. I can retrieve the media_id from the database successfully, but I don’t know how to dynamically send these back to Telegram as a media group when the number and types are unknown beforehand.

What I need help with:

  1. Is there a way to dynamically build the list of media (media_id + type) directly in an expression inside a Telegram node?
  2. Is my current approach (saving only the media_id and retrieving it for forwarding) the correct way to handle this, or is there a better method?
  3. I read this Telegram sendMediaGroup can not be used to send album of variable anount of pictures but I’m looking for any kind of workaround and dirty solution to this problem.

I would really appreciate any advice or examples you can share. Thanks again for all the help you’ve already provided—I’ve learned so much from this forum, and I’m loving n8n more and more thanks to your support!

My workflow

Wofklow I use to retrieve all the media ID from a specific user, aggregate them, and send a message to a channel with all those media built as media group

This is the telegram node

and this is the second part of that node configuration in which I tried and failed (after multiple other attempts) to use an expression to tell the node that if there aren’t enough media saved in the database to just send what they have. I know it was not the smartest approach but whatever I tried before to try to send the message regardless to the number of media stored in the database failed.

Information on your n8n setup

  • n8n version: 1.69.2
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: linux

after spending hours testing different solutions I ended up using a different approach.
Instead of using the node “telegram send media group” I’m using a HTTP request to interact directly with the telegram API.

It is working great

image

1 Like