tdlib / telegram-bot-api

Telegram Bot API server
https://core.telegram.org/bots
Boost Software License 1.0
3.23k stars 606 forks source link

unable to send high resolution photo via send_photo method of Telgram bot API #85

Closed omerasif57 closed 3 years ago

omerasif57 commented 3 years ago

Using telegram bot api in python, I am sending photo using a file.

  1. First I get the photo from a url.
  2. Save the photo to disk. (Full Resolution)
  3. Read the file and pass it to bot.send_photo
  4. Get the file_id contained in returned Message object and save it.
  5. Next time I send via file_id upon new /command.

First request:

file = open(get_filename(), 'rb')  
msg = context.bot.send_photo(chat_id, file, caption=None)  
fileid = msg.photo[len(msg.photo)-1].file_id

Second and onwards ...

context.bot.send_photo(chat_id, photo=get_fileid(), caption=None)
context.bot.send_message(chat_id, text=EXPLANATION)

Here fileid represent the highest resolution file id available in PhotoSize array.

Here is the file id: AgACAgQAAxkDAAIBMmAK636SiNEGCA8UILZ55gVppXfqAAIytjEbqp1RUJwNFOjmz7N6ZoHuJ10AAwEAAwIAA3cAAwRjBAABHgQ

Problem: I am receiving 1k resolution photo in bot chat. Please advise what I am missing here.

levlam commented 3 years ago

Photos has a lot of sizes for different screen resolutions. Sent photo is resized and comressed. If you want to send original photo as a file without changes, you must use sendDocument for that.

omerasif57 commented 3 years ago

Sent photo is resized and comressed.

Always? regardless of specifying high resolution fileid fileid = msg.photo[len(msg.photo)-1].file_id

PhotoSize array has every available resolution so what is the use case of having all those photo sizes?

omerasif57 commented 3 years ago

you must use sendDocument for that.

Results in Type of file mismatch error

Sending Files:

_Sending by file_id: It is not possible to change the file type when resending by fileid. I.e. a video can't be sent as a photo, a photo can't be sent as a document, etc.

Sending by URL: In sendDocument, sending by URL will currently only work for gif, pdf and zip files.

So, I will have to make two separate calls for photo and document.

levlam commented 3 years ago

Always?

Always.

PhotoSize array has every available resolution so what is the use case of having all those photo sizes?

Photos has a lot of sizes for different screen resolutions.

So, I will have to make two separate calls for photo and document.

What exactly do you want to achieve? If you want to send a high-resolution photo without compression, you must send it as a document. You don't need to send it as a photo.

omerasif57 commented 3 years ago

Right. I got it now. thanks.