首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP Longman电报机器人。无法通过webhooks下载文件

PHP Longman电报机器人。无法通过webhooks下载文件
EN

Stack Overflow用户
提问于 2020-10-08 23:25:55
回答 1查看 168关注 0票数 0

我在我的Yii2项目中使用longman/telegram-bot包。

代码语言:javascript
复制
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时,它不起作用。即使我从我的机器人那里得到了同样的答案...它显示"Ok“和”文件位于...“,但没有这样的文件。

EN

回答 1

Stack Overflow用户

发布于 2020-10-08 23:35:24

这是因为webhook使用了Yii2高级后端...它在后端存储所有文件(因为我的webhook在后端查看),但我在前端搜索它们(因为我很愚蠢)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64265764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档