The Telegram Bot API does not give to your web-hook any reliable information about the order of each item in a media group. https://core.telegram.org/bots/api#message
Suggestions:
If bot is in a private chat, save the incoming file_id
against their media_group_id
. Whenever media_group_id
changes you would have all you need to use. Engage the user in some other way so that you can quickly determine the media_group_id
change and respond quickly from that processing.
If bot is in a group chat, save incoming file_id
against the users id
as well as media_group_id
and similarly monitor changes to media_group_id
and user id
to take action.
When a solution starts getting too complex for my liking, I prefer to go back to the basic reason for my need and perhaps find out that I do not need to do something an API doesn't afford like "Get all uploaded photos by media_group_id
". Maybe I can just process them individually as the updates stream in.
Tip: If the media group has a caption
and you only care about the first media item in the group, then monitoring the media_group_id
and caption
of an incoming message should be sufficient.
if(message.caption != null && message.media_group_id != null){
// first item in new group received
}