Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

message_handler: Processes the first two media together when sent simultaneously (type: media_group_id) #2391

Open
tandat132 opened this issue Aug 31, 2024 · 4 comments
Labels

Comments

@tandat132
Copy link

tandat132 commented Aug 31, 2024

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using?
    4.22.1
  2. What OS are you using?
    windows
  3. What version of python are you using?
    3.11.9

The first two media files are processed together, leading to the same output or action being applied to both.
Code:

i = 1
@bot.message_handler(func=lambda message: True)
def handle_message(message):
     global i
     print(i)
     print(message)
     i = i+1

Result:

1
1
message
message
2
message
3
message
...
@coder2020official
Copy link
Collaborator

Hi. This behaviour is not due to library but API.

The only solution I can offer is implementing a logic yourself.
Examples:

  • timeframe in which all photos are gathered
  • "done" callback button
  • ...etc

@Badiboy
Copy link
Collaborator

Badiboy commented Sep 18, 2024

@coder2020official Frankly speaking, receiving gallery is a real pain. I suppose when (if) we have time it may be useful to make some joint handler for media gallery, that will allow to receive gallery itself. I did not make long thinking on it, but it may be useful.

@coder2020official
Copy link
Collaborator

Yes, I will take a look at this at some point.

@All-The-Foxes
Copy link

All-The-Foxes commented Nov 17, 2024

A group can be any file, not just photos. I have media group handling built into my bots and I have never experienced this issue. You cannot just 'catch' a media group at the handler level. Uploads take time and the user might have a slow connection or the files could be big. So if you try and handle them immediately you will split the media group 100% of the time as all uploads are not sent together but instead are sent one at a time as they finish.

Even if you did catch the pieces, they then have to be turned into InputMedia objects in order to be sent as a group of something, and keyword arguments like captions, protections, and effects need to be built for the objects as well as keyword arguments for the group itself. And then it needs to be sent as a group. This cannot be done with a handler. It is up to the user to implement this.

In addition, there is no way to know if a media group contains 2 things, 6 things, or 10 things. You can't check that. You have to make an assumption. Then there's silly things like certain InputMedia types cannot be grouped together and certain types cannot accept a caption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants