如何解决PHP Longman电报机器人无法通过Webhooks下载文件
我在Yii2项目中使用的是longman / telegram-bot软件包。
class GenericmessageCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'genericmessage';
/**
* @var string
*/
protected $description = 'Handle generic message';
/**
* @var string
*/
protected $version = '1.0.0';
/**
* Main command execution
*
* @return ServerResponse
*/
public function execute(): ServerResponse
{
$message = $this->getMessage();
if (in_array($message->getType(),['audio','document','photo','video','voice'])) {
$doc = call_user_func([$message,'get' . $message->getType()]);
($message->getType() === 'photo') && $doc = end($doc);
$photoId = $doc->file_id;
$download_path = $this->telegram->getDownloadPath();
$file = Request::getFile(['file_id' => $photoId]);
if ($file->isOk() && Request::downloadFile($file->getResult())) {
return $this->replyToChat(' file is located at: ' . $download_path . '/' . $file->getResult()->getFilePath());
} else {
return $this->replyToChat('Failed to download.');
}
}
}
}
就是这样
当我使用getUpdates
方法https://github.com/php-telegram-bot/core#getupdates-installation时工作正常
但是当我使用WebHooks时它不起作用。即使我从我的机器人程序中得到了相同的答案,它也说“确定”并且“文件位于...”,但是没有这样的文件。
解决方法
由于webhook使用Yii2 Advanced的后端....它将所有文件存储在后端(因为我的webhook在后端查看),但是我在前端搜索它们(因为我很愚蠢)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。