@enabl3

Как получить картинку от бота telegram?

Всем привет, подскажите пожалуйста, каким образом можно получить картинку, которую пользователь отправил боту, и потом ее же переслать в другую группу?
В общем делаю так:
@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") #то что пойдет юзеру после отправки сообщения

Для текста все отлично прилетает, а для фото прилетает вот что:
<telebot.types.PhotoSize instance at 0x7fe4fef8d368>, <telebot.types.PhotoSize instance at 0x7fe4fef8d3f8>, <telebot.types.PhotoSize instance at 0x7fe4fef8d3b0>, <telebot.types.PhotoSize instance at 0x7fe4fef8d680>

Подскажите что делаю не так?
  • Вопрос задан
  • 7665 просмотров
Решения вопроса 1
@enabl3 Автор вопроса
РЕШЕНО.
Изменил код:
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") #то что пойдет юзеру после отправки сообщения
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы