Multiple images in telegram

Describe the issue/error/question

Hi,

I’m creating a workflow that sends input files to telegram. In case of images I can have multiple input. I know that I can set multiple files to send in UI. But how to deal when I don’t know how many files will appear in input and I need to send them as album in single message?
Kindly advise if there is a way to do this without creating multiple telegram nodes that will only have different number of preset Media files?

Thank you in advance.

Hi @kygechuk, welcome to the community :tada:

I assume you are using the Send Photo operation of the Telegram node here? A possible approach would be first take all binary items you have and split them into individual items using a snippet like this one in a Function node before your Telegram node:

The Telegram node should then run for each individual item (and thus sending all photos one by one, regardless of how many there are in total).

1 Like

Dear MutedJam,

Thank you very much for your reply!

OMG! This link to code snippets is AWESOME! I was as a blindman seeking at google for pieces of information like this :slight_smile:

Yes, you’re right I’m asking about Telegram node. But how node will understand how many individual items I pass to it if I need to preset all of them manually in the node? And if I just split and get 2 or 5 or 7 and node will send them as separate images, not as an album of items.

Thank you!

1 Like

Almost all n8n nodes will run once for each input item (the exceptions would be listed here). The example snippet (in the Split binary data into individual items section on the linked page) will take all binary elements on the first item and will convert them into individual items, each with a single binary property named data.

Meaning if you pass a single item with 5 binary files to the Telegram node, it would only once (and only send the one binary data element you have specified). But if you pass 5 items with 1 binary data element each to the Telegram node, it would run 5 times (sending one binary data element on each run, so all 5 in total).

This is assuming you are using binary data in the node (which is my understanding from reading your description):
image

I hope this makes sense! If this doesn’t quite apply to your case, could you share the example data the Telegram node receives in your workflow as well as the workflow itself?

1 Like

Hi,

Let me show simple example.

Here is the code where I have 2 different inputs. In one case I have 1 image to send in another - 2. And Telegram node fails because in has no input for 2nd image in 2nd item.

My question was - how to hande situation when I don’t know how many files to send I have from input?

And other problem - their type - they can be images or videos. So even I create 10 telegram nodes for sending 1-10 images, and another 10 nodes to send 1-10 videos, I’ll face a problem with items that have both images and videos in a random order,

I see, so you don’t have the actual files in n8n but instead have URLs you want to share in Telegram? And these URLs would come through as an array in a single attachments field for each of your items?

My suggestion would be an approach like this: Convert each individual string in your attachments arrays into individual items. Afterwards you have exactly one photo per item and can set up the Telegram node to handle only one attachment. Here is an example built on top of the workflow you have shared:

Example Workflow
1 Like

Thank you for you. I understand the solution and use it in couple of other workflows. But in my case i need to have 2 messages to be sent for 2 inputs, not 3:) Because media group just looks much better than 10 separate messages in Telegram :slight_smile:

Probably I’ll have to use old good http request to telegram API and prepare data to be sent in POST.

Thank you very much for your willing to help!