Simple Solution to Handle Media Groups in Telegram Trigger and Pass File IDs to a Second Workflow

Hi everyone,

I’m facing a challenge with a Telegram trigger in n8n, and I could really use some help finding a simple solution.

Here’s my use case:

  1. I have a Telegram trigger that activates whenever I receive a message.
  2. If the message contains a media group (photos/videos sent as a single message), I need to capture and save the file IDs of all media files in that group.
  3. After this, the workflow calls a second workflow, which includes a Telegram Send Media Group node. This node sends a message with the media files (photos/videos) attached to a predefined Telegram group.

My Struggles

I’m very bad at coding, and while I’ve tried using JavaScript arrays in a Function node to manage the file IDs, I’ve failed miserably. Despite reading documentation and experimenting, I just can’t seem to understand how arrays work.

I’ve successfully managed the flow for single media files by using the Set node in the first workflow to pass the file ID to the second workflow. However, I can’t figure out how to handle media groups where multiple files need to be passed together as an array.

Key Requirements

  • The media group size and type are unknown (it could include 2+ files, a mix of photos and videos).
  • The user sends all media as one message (a single media group).
  • I need to pass all file IDs to the second workflow without storing them in an external database (if possible).
  • I’d prefer a simple and straightforward solution—even if it requires using multiple nodes instead of writing complex code in a single node.

Challenges

  • Identifying and handling media groups within the trigger.
  • Storing and passing an array of file IDs between workflows.
  • Ensuring all file IDs are properly grouped and sent together in the second workflow.

Does anyone have any recommendations for an approach that avoids coding but still gets the job done?

Thanks so much in advance for your help. :blush:

Information on your n8n setup

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

hello @shuui

the media group will trigger the workflow multiple times (one for each media). So you will need external storage to get all the media in one place. Or you can save each response in a local file and read them in the second workflow later

thanks for the answer, but I read somewhere on this forum that I could just store the responses temporary without saving them on files or db and pass those information from workflow to workflow. I just can’t figure out a easy way to do it.

I’m trying not to use arrays and javascript code but I guess I will have to figure out how to write it if I want to avoid using external storage.

You can, but as you stated

I don’t recommend you to go that way :slight_smile:

n8n has a special method $getWorkflowStaticData, but you can easily kill your database and n8n instance by messing with it. A safer and easier option would be to use files

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.