mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-11 15:48:18 +01:00
78 lines
3.1 KiB
PHP
78 lines
3.1 KiB
PHP
|
<?php declare(strict_types=1);
|
|||
|
|
|||
|
/**
|
|||
|
* This file is part of MadelineProto.
|
|||
|
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|||
|
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|||
|
* See the GNU Affero General Public License for more details.
|
|||
|
* You should have received a copy of the GNU General Public License along with MadelineProto.
|
|||
|
* If not, see <http://www.gnu.org/licenses/>.
|
|||
|
*
|
|||
|
* @author Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
|
|||
|
* @copyright 2016-2023 Amir Hossein Jafari <amirhosseinjafari8228@gmail.com>
|
|||
|
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
|
|||
|
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
|||
|
*/
|
|||
|
|
|||
|
namespace danog\MadelineProto\EventHandler;
|
|||
|
|
|||
|
use danog\MadelineProto\EventHandler\Media\Document;
|
|||
|
use danog\MadelineProto\EventHandler\Media\Photo;
|
|||
|
use danog\MadelineProto\MTProto;
|
|||
|
use JsonSerializable;
|
|||
|
use ReflectionClass;
|
|||
|
use ReflectionProperty;
|
|||
|
|
|||
|
/**
|
|||
|
* Represents information about a named bot web app.
|
|||
|
*/
|
|||
|
final class BotApp implements JsonSerializable
|
|||
|
{
|
|||
|
/** @var int app ID */
|
|||
|
public readonly int $id;
|
|||
|
|
|||
|
/** @var int access hash*/
|
|||
|
public readonly int $accessHash;
|
|||
|
|
|||
|
/** @var string Bot web app short name, used to generate [named bot web app deep links](https://core.telegram.org/api/links#named-bot-web-app-links). */
|
|||
|
public readonly string $name;
|
|||
|
|
|||
|
/** @var string Bot web app title. */
|
|||
|
public readonly string $title;
|
|||
|
|
|||
|
/** @var string Bot web app description. */
|
|||
|
public readonly string $description;
|
|||
|
|
|||
|
/** @var Photo Bot web app photo. */
|
|||
|
public readonly ?Photo $photo;
|
|||
|
|
|||
|
/** @var Document Bot web app animation. */
|
|||
|
public readonly ?Document $document;
|
|||
|
|
|||
|
/** @var int Hash to pass to [messages.getBotApp](https://docs.madelineproto.xyz/API_docs/methods/messages.getBotApp.html), to avoid refetching bot app info if it hasn’t changed. */
|
|||
|
public readonly int $hash;
|
|||
|
|
|||
|
public function __construct(MTProto $API, array $rawBotApp)
|
|||
|
{
|
|||
|
$this->id = $rawBotApp['id'];
|
|||
|
$this->accessHash = $rawBotApp['access_hash'];
|
|||
|
$this->name = $rawBotApp['short_name'];
|
|||
|
$this->title = $rawBotApp['title'];
|
|||
|
$this->description = $rawBotApp['description'];
|
|||
|
$this->hash = $rawBotApp['hash'];
|
|||
|
$this->photo = isset($rawBotApp['photo']) ? $API->wrapMedia($rawBotApp['photo']) : null;
|
|||
|
$this->document = isset($rawBotApp['document']) ? $API->wrapMedia($rawBotApp['document']) : null;
|
|||
|
}
|
|||
|
|
|||
|
/** @internal */
|
|||
|
public function jsonSerialize(): mixed
|
|||
|
{
|
|||
|
$res = ['_' => static::class];
|
|||
|
$refl = new ReflectionClass($this);
|
|||
|
foreach ($refl->getProperties(ReflectionProperty::IS_PUBLIC) as $prop) {
|
|||
|
$res[$prop->getName()] = $prop->getValue($this);
|
|||
|
}
|
|||
|
return $res;
|
|||
|
}
|
|||
|
}
|