N
N
Nikita Mikaev2017-04-11 12:16:12
Python
Nikita Mikaev, 2017-04-11 12:16:12

How to send many photos using Telegram Bot Api, Python?

I am writing a bot using PyTelegramBotApi , there was a need to send a lot of photos, preferably in one message (along with text), well, or in several messages. Every time there is an error, does not allow to send. Maybe there is some method in the API that allows you to perform many of the same operations, or is there a way to send a lot of photos?
Thank you very much
Here is the code:
for j in vkarr[2]:
time.sleep(.25)
urllib.request.urlretrieve(j,'temp.jpg')
img=open('temp.jpg','rb')
bot .send_chat_action(message.from_user.id, 'upload_photo') bot.send_photo
(message.from_user.id,img)
img.close()
2017-04-11 12:15:23,893 (apihelper.py:42 WorkerThread2) DEBUG - TeleBot: "The server returned: 'b'{"ok":false,"error_code":400,"description":"Bad Request : IMAGE_PROCESS_FAILED"}''"
2017-04-11 12:15:23,893 (util.py:60 WorkerThread2) DEBUG - TeleBot: "Exception occurred"
2017-04-11 12:15:23,894 (__init__.py:250 MainThread ) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: IMAGE_PROCESS_FAILED"}']"
2017-04-11 12:15:23,894 (__init__.py:257 MainThread) INFO - TeleBot: "Waiting for 0.25 seconds until retry"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
German Khukhalev, 2020-01-31
@ISQman

I solved the issue like this:
bot.send_media_group(chatid,
[InputMediaPhoto(msg.message.photo.file_id),
InputMediaVideo(msg.message.video.file_id)])

X
xdgadd, 2017-04-11
@xdgadd

Telegram Bot API does not provide such mechanisms. If you want to send multiple photos - make a loop.

def send_many(photos, id):
    for p in photos:
        bot.send_photo(id, p)

You can also send links by regular messages, telegram will upload pictures.
To make it look nice, wrap the url in a tag and set parse_mode="HTML":
bot.send_message(id, '<a href="IMG_URL">&#8203;</a>',
                 parse_mode="HTML")

PS Telegram has a limit on the number of messages per minute.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question