How to know count or last of messages in MediaGroup telegram

Viewed 496

I want to attach a button for a media group

  1. To do this, I intercept the message and see if there is the same mediaGroup_id, then I save the file_id to the database

  2. After all messages from this media group have been received, I send them to a group in a separate channel (here is the problem) -> how can I determine that this is the last message from the media group, I had a stupid idea to create a job with a delay of several seconds, enough time to receive the entire media group, and then send the entire media group in this job, however, I am worried about the reliability of this method, and for sure it will be buggy if one day I have to use asynchronous

  3. Then, in the main channel, I send a message containing a link to the media group and a button, as I wanted

Is there some way to do this more elegantly?

1 Answers

That actually sounds rather reasonable and in fact I know a bot that does something very similar. The idea why this works, is that TG apparently first uploads all the media files and then sends all messages at once rather then looping over "upload, then send".

Related