Consider this file with arbitrary content:
diamond.txt
When I browse my telegram application select the above file and send it to one of my contacts they get the file with the same name as above (diamond emoji included).
But when I try to send the same file through bot API they get it shown without diamond emoji. They see:
diamond.txt
I have tried to encode the string as 'utf-8', 'ascii' and even url encode but none works.
The code I use:
import json
import requests
import urllib
def sendoc(token, chid, pathtodoc, caption:str=None, repkey:dict=None):
URL = 'https://api.telegram.org/bot{}/'.format(token) # Telegram bot API url + TOKEN
data = {'chat_id': chid}
data['caption'] = caption
if repkey:
replykey = json.dumps(repkey)
data['reply_markup'] =replykey
files = {'document': (pathtodoc, open(pathtodoc, 'rb'))}
resp = requests.post(URL + 'sendDocument', files = files, data = data)
resp = resp.json()
return resp
token = "your bot token"
chid = -1000923413394 # example chat id
pathtodoc = './diamond.txt'
ret = sendoc(token, chid, pathtodoc)
print(ret)
Please help me to send emoji within filename from Bot api.
UPDATE: I find out that there are many other people experiencing similar issue with sending files with non ascii filename through requests module.