Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"getFile" method in Telegram Bot API

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?

like image 688
Kemeeda Avatar asked Dec 09 '15 04:12

Kemeeda


People also ask

How do I download a file or photo that was sent to my Telegram Bot?

The file can then be downloaded via the link https://api.telegram.org/file/bot/, where is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again. For the moment, bots can download files of up to 20MB in size.

How can I get Telegram Channel users with Telegram Bot API?

To use MTProto, you need to login to https://my.telegram.org/ with your existing Telegram account and get credentials: api_id and api_hash . Here is a working example of how to use Telethon python library to get list of Telegram channel/group users. It is easy to search channels/users by name/phone/URL with client.


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:

  1. Use the Android Telegram app to send your bot a photo.

  2. Open a browser, enter in the address bar https://api.telegram.org/bot<token>/getUpdates

    You should see several file_ids in the response. These are thumbnails of the photo.

  3. Pick a file_id of your choice. Enter in the browser's address bar https://api.telegram.org/bot<token>/getFile?file_id=<file_id>

    Look for file_path in the response. It should look something like photo\/file_22.jpg. The backslash is only to escape the forward slash, so the file_path is actually photo/file_22.jpg

  4. 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.

like image 116
Nick Lee Avatar answered Oct 16 '22 14:10

Nick Lee