Answer the question
In order to leave comments, you need to log in
How to accept an album of photos by a telegram bot?
It is necessary that the bot accept and display the file_id of several photos at once. I can accept and process one photo, but if this is an album, then it doesn’t work. If anyone knows how to implement this I would be grateful. I work on aiogram, if there are examples for other libraries, then I will also be happy, I think I can redo
Answer the question
In order to leave comments, you need to log in
There is such a thing when sending a photo - compression. So, if the user chose compression before sending, then it will be a photo (photo), and if compression is not selected, then this is already a document (document)
@bot.message_handler(content_types=['photo'])
def handle_docs_photo(message):
try:
chat_id = message.chat.id
file_info_1 = bot.get_file(message.photo[-1].file_id)
bot.send_message(message.chat.id, file_info_1)
downloaded_file = bot.download_file(file_info_1.file_path)
src = dir + '\\' + file_info_1.file_path.split('/')[-1]
bot.send_message(message.chat.id, src)
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
except Exception as e:
bot.reply_to(message, e)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question