Search code examples
telegramtelegram-bot

Does Telegram download file from url each time I call sendDocument method?


Let's say I use such request to send file to a user in Telegram:

https://api.telegram.org/bot*****/sendDocument?chat_id=0&document=someLongUrl

Then, I will (probably much later) send this file to other users. Will Telegram download this file from remote server every time I send it? If not, how does it determine so quickly that this particular file has already been downloaded, despite the presence of millions of other files on Telegram servers?


Solution

  • If you send (and thus upload) a file through Telegram's Bot API an unique file_id will be created. This is returned by the API and is a valid value for the document parameter on the sendDocument method.

    So if you first send your file by URL, then remember the file_id somewhere, you can keep resending that exact file without Telegram downloading it from the original source.