PHP Longman telegram bot. Can't download files via webhooks

598 views Asked by At

I'm using longman/telegram-bot package at my Yii2 project.

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.');
            }
        }
    }
}

Just like that

It working fine when I'm using getUpdates method https://github.com/php-telegram-bot/core#getupdates-installation

But it doesn't work when I use WebHooks. Even though I get the same answer from my bot... It says "Ok" and "file is located at...", but there is no such file.

1

There are 1 answers

1
Wizard On

that because of webhook using backend of Yii2 advanced.... it stores all files at backend (because my webhook looking on backend), but i searching them at frontend (bacause i'm stupid).