Telegram bots use fileid
to download a file. How can I get this fileid
from Telegram client (My Unofficial version) ? Files in mtproto
have this location class that indicates their address.
File Location Parameters
The problem is I don't know how to generate the fileid
that is appropriate for bots from File Location
class.
UPDATE 1:
I've tried to do some reverse engineering. So, I've found out that there is some relation between File Location
class and FileId
.
It is my File Location
sample address.
0
// This field is only available for secret chats0
// This field is only available for secret chats429640340
(199BCA94 HEX
)-3528741004939935589
(CF0764C08833409B HEX
) // according to TG documentations it should be file CheckSum6005
(1775 HEX
)And this is my according FileID
to the former FileLocation
class that I retrieved it from my Bot:
AgADBAADL6gxG06L8w0nhNO87UW3iZTKmxkABJtAM4jAZAfPdRcAAgI
It is obvious that FileID
value is in Base64
format. So I've decoded it:
0200030400032FA8311B4E8BF30D2784D3BCED45B78994CA9B1900049B403388C06407CF7517000202
Now we can see the FileLocation
values in this hex value:
0200030400032FA8311B4E8BF30D2784D3BCED45B789
94CA9B19 HEX
0004
9B403388C06407CF HEX
7517 Hex
000202
NOTE: the values are stored in Big-Endian
format.
Now we need to decode Unknown
values. I appreciate any effort that helps to decode these values.
From telegram's docs: On success, a File object is returned. 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.
We offer two kinds of APIs for developers. The Bot API allows you to easily create programs that use Telegram messages for an interface. The Telegram API and TDLib allow you to build your own customized Telegram clients.
Here's the TL scheme for bot API file ids: https://github.com/danog/MadelineProto/blob/master/src/danog/MadelineProto/TL_botAPI.tl
I have implemented bot API file id conversion in MadelineProto: you basically have to base64decode the file ids, pass them through an RLE decoder based on null byte, and then decode them using the given TL scheme. See TL/Conversion/BotAPI* to see how MessageMedia objects are converted to a File objects before serialization.
I managed to reverse engineer file ids (I forgot to search here xd) using this special MTProto bot I built using the same lib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With