E
E
enabl32018-02-27 13:44:49
Python
enabl3, 2018-02-27 13:44:49

How to get picture from telegram bot?

Hello everyone, can you please tell me how to get the picture that the user sent to the bot, and then send it to another group?
In general, I do this:

@bot.message_handler(content_types=["text", "sticker", "pinned_message", "photo", "audio"])
def echo_msg(message):
    if message.content_type == 'text':
        bot.send_message(chatID, "Запрос от\n*{name} {last}*\n{text}".format(name=message.chat.first_name, last=message.chat.last_name, text=message.text), parse_mode="Markdown") #от кого идет сообщение и его содержание
        bot.send_message(message.chat.id, "*{name}!*\n\nСпасибо за инфу".format(name=message.chat.first_name, last=message.chat.last_name, text=message.text), parse_mode="Markdown") #то что пойдет юзеру после отправки сообщения
    elif message.content_type == 'photo':
        bot.send_message(chatID, "Запрос от\n*{name} {last}*\n{photo}".format(name=message.chat.first_name, last=message.chat.last_name, photo=message.photo), parse_mode="Markdown") #от кого идет сообщение и его содержание
    bot.send_message(message.chat.id, "*{name}!*\n\nСпасибо за инфу".format(name=message.chat.first_name, last=message.chat.last_name, text=message.text), parse_mode="Markdown") #то что пойдет юзеру после отправки сообщения

For text, everything flies fine, but for a photo, this is what flies:
<telebot.types.PhotoSize instance at 0x7fe4fef8d368>, <telebot.types.PhotoSize instance at 0x7fe4fef8d3f8>, <telebot.types.PhotoSize instance at 0x7fe4fef8d3b0>, <telebot.types.PhotoSize instance at 0x7fe4fef8d680>

Tell me what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
enabl3, 2018-02-28
@enabl3

RESOLVED.
Changed the code:

elif message.content_type == 'photo':
        raw = message.photo[2].file_id
        name = raw+".jpg"
        file_info = bot.get_file(raw)
        downloaded_file = bot.download_file(file_info.file_path)
        with open(name,'wb') as new_file:
            new_file.write(downloaded_file)
        img = open(name, 'rb')
        bot.send_message(chatID, "Запрос от\n*{name} {last}*".format(name=message.chat.first_name, last=message.chat.last_name), parse_mode="Markdown") #от кого идет сообщение и его содержание
        bot.send_photo(chatID, img)
        bot.send_message(message.chat.id, "*{name}!*\n\nСпасибо за инфу".format(name=message.chat.first_name, last=message.chat.last_name, text=message.text), parse_mode="Markdown") #то что пойдет юзеру после отправки сообщения

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question