A
A
AceFridge2022-01-04 17:08:15
Python
AceFridge, 2022-01-04 17:08:15

How to determine the number of photos in a media group (pytelegrambotapi)?

I'm looking for a way to determine the number of photos in a media group, or a way to determine that a message has been received with the last photo in a media group.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
InternetMaster, 2022-01-04
@InternetMaster

Telegram sends all the photos individually (it doesn't matter if they were sent as a group or individually). Here you need to recalculate the number of message photos received from the user. Or ask the user before sending.

A
AceFridge, 2022-01-05
@AceFridge

the essence of the question is that I need to implement the following logic of work: different users throw off a photo report into one group, indicating in the caption to the photo (message.caption) the number of the object to which the photo report belongs, if there was no signature or it contains an unknown number, then the bot asks for a number, the user responds with the following message, the photo report is written to the database.
With sending 1 photo without a signature and with a signature, everything is implemented and works without problems.
With sending a group of photos without a signature, everything is also OK - when the first photo from the group is received, I write a document to the database by the number of the media group, request the number of the object, then add the number there when the user gives it. Even if a part of the photo arrives somewhere between the first photo and the issuance of a response to the request, then by the group number, the id of the files will still end up in the document in the database.
The whole difficulty with the last possible state of sending: if the user throws a group of photos with a number added to the caption. The problem is that when shooting from a phone, caption can be filled in for the first, second, third photo, if you do this between photographing... you can fill in at least different text for all photos, only the last one will be displayed in the client, and in fact the bot will receive a caption on those photos for which it was filled. If you fill in the caption after completing all the photos, then the caption will come on the last photo, while the bot receives the first message with the media_group_id, but without the caption. When sending from a PC, there is no such problem, you upload a group of photos, fill in the signature, the signature is attached to the first message in the group.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question