1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-11 15:48:18 +01:00
MadelineProto/src/EventHandler/BotApp.php

86 lines
3.7 KiB
PHP
Raw Normal View History

2023-09-11 01:17:52 +02:00
<?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;
2023-09-28 18:11:48 +02:00
use danog\MadelineProto\EventHandler\Media\Document;
use danog\MadelineProto\EventHandler\Media\Photo;
use danog\MadelineProto\MTProto;
2023-09-11 01:17:52 +02:00
use JsonSerializable;
use ReflectionClass;
use ReflectionProperty;
/**
2023-09-25 10:50:26 +02:00
* Represents information about a [named bot web app](https://core.telegram.org/api/bots/webapps#named-bot-web-apps).
2023-09-11 01:17:52 +02:00
*/
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 hasnt changed. */
public readonly int $hash;
2023-09-25 10:50:26 +02:00
public function __construct(
MTProto $API,
array $rawBotApp,
2023-09-28 18:11:48 +02:00
/** Whether the web app was never used by the user, and confirmation must be asked from the user before opening it. */
2023-09-25 10:50:26 +02:00
public readonly ?bool $inactive = null,
2023-09-28 18:11:48 +02:00
/** 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). */
2023-09-25 10:50:26 +02:00
public readonly ?bool $requestWriteAccess = null,
public readonly ?bool $hasSettings = null,
2023-09-28 18:11:48 +02:00
) {
2023-09-11 01:17:52 +02:00
$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;
}
}