大家好,我想使用http://api.telegram.org/botTOKEN/sendDocument?document=http://my_path&chat_id
这样的漫游器发送文件,但它不支持.txt .docx .....和其他格式.....请提供任何帮助
答案 0 :(得分:0)
根据https://core.telegram.org/bots/api#sending-files
通过URL发送在sendDocument中,当前仅通过URL发送 用于 gif , pdf 和 zip 文件。
您可以尝试使用这种方法
使用multipart / form-data以文件通常的方式发布文件 通过浏览器上传。照片最大大小为10 MB,照片最大大小为50 MB 其他文件。
此answer可能会给您一些有关如何做到这一点的想法。
使用某人的图书馆来了解图书馆的运作方式也是一个好主意。
例如,我使用this repo中的longman/telegram-bot
。 Request类中有encodeFile
个方法。
方法如下:
public static function encodeFile($file)
{
$fp = fopen($file, 'rb');
if ($fp === false) {
throw new TelegramException('Cannot open "' . $file . '" for reading');
}
return $fp;
}
这意味着带有fopen
参数的简单'rb'
方法足以转换文件。