首页 > 解决方案 > 如何使用 url 在 tetelgram bot 中下载和发送 .exe 文件?

问题描述

我正在使用 java 开发电报机器人。我想寄一些。exe文件通过url,我已经尝试过 SendDocument 类,它不能使用不同的 url,可能电报 SendDocument 不支持 .exe 格式的文件:

SendDocument sender = new SendDocument();
sender.setChatId(chat_id);
sender.setDocument("https://www.psiphon3.com/psiphon3.exe"); // for example

// I have also used the setNewDocument method . no difference !

try {
sendDocument(sender);
} catch (TelegramApiException a) {
e.printStackTrace();
 }

错误是:

Error sending document: [400] Bad Request: wrong file identifier/HTTP URL specified

有人有什么建议吗?是否可以将 .exe 转换为 .zip 然后发送?

标签: javatelegramtelegram-bot

解决方案


目前,Telegram“通过 URL 发送”方法不允许发送可执行文件。
文档说:
“在 sendDocument 中,通过 URL 发送当前仅适用于 gif、pdf 和 zip 文件。” https://core.telegram.org/bots/api#sending-files

将文件下载到 Telegram 服务器后,使用“通过 file_id 发送”。


推荐阅读