Use a switch to determine how many photos in a telegram message

Hi,
I have a telegram watch updates module. When I post a message with a photo in telegram, I can get 3 or 4 photos in different resolutions :
image
I want to use a switch to determine if I have 4 or 3 photos.
I tried that :


But it does not work.
How can I detect if I have 3 or 4 photos?
Thanks

Hello,

You could probably use the length() function on the Photo Array to determine how many you have.

Or, if you pass the “Photo” array into an Array Aggregator, one of the results will be a count of the number of elements that were aggregated.

2 Likes

Hi, thanks for your answer.
Using the length function is interesting, but could you be more specific?
In which kind of module should I use it, and how would be the syntax ?
Thx

Check out the array functions tab when you’re creating a set variable module for example. Array functions have great docs and length() is one of them.

2 Likes

Hello,

In this instance I don’t believe Switch is the right module to use.
If you would like to determine the number of photos, you’d simply wrap the Photo array in a length() function, something like this:

length({{9. Message.Photo[]}})

You can use this in any module that accepts mappings as input, such as Set Variable.
The result would simply be a number like 3 or 4.

For example, if my output looks like this (similar to yours):
image

Then, in my Set Variables module I have a function like this:
image

Which results in:
image

What you do ultimately depends on your goal.
If your goal is to simply figure out how many photos, then this is all you would need.

If you need to do something with each of the photos, that’s a different set of functions for that.

Hope this helps!

3 Likes