【问题标题】:PHP Longman telegram bot. Can't download files via webhooksPHP Longman 电报机器人。无法通过 webhook 下载文件
【发布时间】:2020-10-08 15:25:55
【问题描述】:

我在 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 时它不起作用。即使我从我的机器人那里得到了相同的答案......它说“Ok”和“文件位于......”,但没有这样的文件。

【问题讨论】:

    标签: php yii2 telegram-bot php-telegram-bot telegram-webhook


    【解决方案1】:

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

    【讨论】:

    • 哈哈。好的。如果需要,您可以删除问题和答案
    猜你喜欢
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 2016-02-24
    • 2021-01-21
    • 1970-01-01
    相关资源
    最近更新 更多