我正在尝试使用python和Telegram Bot API构建Telegram机器人,并且由于Telegram Bot API在我的国家/地区受到审查,因此我发现this脚本被使用Google Apps脚本部署的应用程序绕过。但是问题在于它只发送文本而不发送文件,因此我希望Web应用程序将发送给它的文件重定向到Telegram,这是我的python代码的一部分:
fr = open("result.txt", "rb")
files = {"document": fr}
script_url = 'https://script.google.com/macros/s/AKfycby20pnglgWTp4oV0tDTKuU87XmvkS6EZd-LTuoCmMM3Ge7PbGJ/exec?bot_token=' + token + '&method=sendDocument&args={"chat_id": ' + chat_id + '}'
requests.post(
url=script_url,
files=files
)
所以我正在使用post方法将文件发送到Web应用程序,但是在Web应用程序方面,我不知道如何获取该文件并将其发送到Telegram。
最好只使用代理绕过审查。
如果使用python-telegram-bot,则可以在下面使用此代码:
#put HTTP proxy url here
REQUEST_KWARGS = {'proxy_url': 'http://localhost:62612/'}
updater = Updater(token=TOKEN, use_context=True, request_kwargs=REQUEST_KWARGS)