. * * @author Amir Hossein Jafari * @copyright 2016-2023 Amir Hossein Jafari * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * @link https://docs.madelineproto.xyz MadelineProto documentation */ namespace danog\MadelineProto\EventHandler; use JsonSerializable; use ReflectionClass; use ReflectionProperty; use danog\MadelineProto\MTProto; use danog\MadelineProto\EventHandler\Media\Document; use danog\MadelineProto\EventHandler\Media\Photo; /** * Represents information about a [named bot web app](https://core.telegram.org/api/bots/webapps#named-bot-web-apps). */ 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, /** @var bool Whether the web app was never used by the user, and confirmation must be asked from the user before opening it. */ public readonly ?bool $inactive = null, /** @var bool The bot is asking permission to send messages to the user: if the user agrees, set the write_allowed flag when invoking [messages.requestAppWebView](https://docs.madelineproto.xyz/API_docs/methods/messages.requestAppWebView.html). */ public readonly ?bool $requestWriteAccess = null, /** @var bool */ public readonly ?bool $hasSettings = null, ) { $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; } }