How to get all results from Telegram multiple photo upload

How to get all node executions into one

I have a telegram bot where I upload photos for processing my openai image analyzer. It works perfectly but when uploading multiple images each image creates a separate execution of the subsiquent nodes. In this case I end up getting a telegram response for each image that is uploaded.

I want to have the final step to return the results of all the images being processed. I’ve attemped adding in a code node to do this. I’m also adding the results into a supabase table and I’ve tried to retreive all the results and repond with that. This works but I still get a supabase query and respons for each photo.

From what I can tell the issue is that the entire workflow is independetly triggered from telegram for each image. For this reason it seems there is no way to know when all the images have been processed.

Telegram passes some json data with the message and includes a media_group_id and then an array of “photo”. When I look at my executions there are always four photos listed regardless of how many I send in which looks like this with four items listed in the photo array.

“media_group_id”: “13988859518461737”,
“photo”: [
{
“file_id”: “AgACAgEAAxkBAAMXaDiCt4drHz_gM8nGpo7W4PzN0oMAAoutMRv75cBF_2_h7P_syq4BAAMCAANzAAM2BA”,
“file_unique_id”: “AQADi60xG_vlwEV4”,
“file_size”: 822,
“width”: 51,
“height”: 90
},

If this listed the correct number of items one could look how many items are in supabase and compair to the number of photos in the message and then trigger the final result when they match. But this seems to be a problem from Telegram.

I’m wondering if anyone has any workaround ideas or alternative approches.

Please share your workflow

Information on your n8n setup

  • n8nVersion: 1.94.1
  • platform: docker (self-hosted)
  • nodeJsVersion: 20.19.2
  • database: sqlite
  • executionMode: regular
  • concurrency: -1
  • license: enterprise (production)

I’m not an expert, but for what I understand each image trigger your workflow.
I dont have the solution, but m’y first guess could be to find a way to store all images, with something like a timer that will wait that all images are stored in your google drive and a way to store all fileIDs

Yes, I agree with this. the issue seems to be knowing how many images are in the orginal message. This looks like it could be a bug with Telegram. I suppose a hack would be to trigger to trigger a separate workflow with a timer and assuming it never take more than 15 seconds to process a bunch of images it could then just repond after that amout of time. Even with this though the other workflow will be triggered for each image. I can’t seem to work out a way to know when the last telegram workflow is finished.

If the first timer (like 2 sec) don’t have any pictures to download, the workflow continue. A timer loop with something like a timeout ?
I already figured out that the telegram trigger, when activated for test, read the last unread message automaticaly.

I ran into something similar while setting up auto-photo uploads from Telegram to a digital picture frame using n8n. What worked for me was using a Set node after the Telegram node to loop through the media_group_id items. That way, I could grab each photo separately and send them where they need to go without missing any. Just needed to handle the array properly in the Function node.