【发布时间】: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