In Telegram Bot API there's a method "getFile" https://core.telegram.org/bots/api#getfile. I have a bot for testing and have Telegram install on Android. How do I test this method, should I send a file to my bot? If so, then how exactly?
1 Answers
If someone has sent your bot a file (photo, video, document, audio, etc), getFile
returns information which allows your bot to download the file. To test this method, do the following:
Use the Android Telegram app to send your bot a photo.
Open a browser, enter in the address bar
https://api.telegram.org/bot<token>/getUpdates
You should see several
file_id
s in the response. These are thumbnails of the photo.Pick a
file_id
of your choice. Enter in the browser's address barhttps://api.telegram.org/bot<token>/getFile?file_id=<file_id>
Look for
file_path
in the response. It should look something likephoto\/file_22.jpg
. The backslash is only to escape the forward slash, so thefile_path
is actuallyphoto/file_22.jpg
Enter in the address bar
https://api.telegram.org/file/bot<token>/<file_path>
You should see the corresponding thumbnail of the photo.
To download the file programmatically, you may follow the exact same steps as above, or you may use a library such as telepot (Python), which provides a method to download files conveniently, without going through all the above steps.

- 5,639
- 3
- 27
- 35
-
Downloading the image I get a bad quality image instead of the original. Is there a way to get the original image (width/height)? Thanks. – Isky Sep 14 '16 at 13:25
-
1Aren't there many sizes to choose from? Just pick the size you want. – Nick Lee Sep 15 '16 at 09:51
-
How can I do that? Using : https://api.telegram.org/file/bot
/ – Isky Sep 15 '16 at 10:20I can see the image but smaller and bad quality than the original. If i download the image then scale it I get a very bad quality image -
Im using php how can i migrate? Easy? Convert my bot code from php to python? Need change my linux server? – saber tabatabaee yazdi Oct 25 '17 at 03:27
-
1@Mattia telegram client resize them before upload to telegram cdn servers. Before that converts, your users must select orginal upload method instead of optimize method – saber tabatabaee yazdi Oct 25 '17 at 03:29
-
@Mattia for quality, it's because you are downloading the thumbnail. in python you need to use `update.message.photo[-1]['file_id']` instead of `update.message.photo[0]['file_id']` to download the original image. technically the first one is thumbnail the last one is original image in array – amir jj Mar 28 '18 at 06:46