How is it possible to send a document in telegram in python with an other filename that "document"? I'm using the Python3. "doc" is a clear text i want to send as txt file.
url = baseurl + token + '/sendDocument'
dict = {'chat_id':chat_id}
r = requests.post(url, params=dict, files={'document':doc})
The received file is named "document", without a file extension. When I rewrite the files to
files={'document.txt':doc}
the Telegram replies
{"ok":false,"error_code":400,"description":"Bad Request: there is no document in the request"}
Does anyone know how to set a file name for the file?
According to the API page, you cannot do that. You must use predefined names for such types of API methods (document, photo, audio, etc.).
And even if you could - you won't be able to use your custom name to find your files because Telegram bot API uses its own file_id identifier for this purpose.
As a workaround you may store file_id—your_custom_document.txt relation on your backend and use file_id to communicate with Telegram servers.
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