tgbotlib/src/TgBotLib/Objects/MenuButton/MenuButtonWebApp.php

62 lines
1.6 KiB
PHP
Raw Normal View History

2023-02-14 17:35:16 -05:00
<?php
2023-02-13 21:46:57 -05:00
2023-02-14 17:35:16 -05:00
2024-10-02 00:18:12 -04:00
namespace TgBotLib\Objects\MenuButton;
2023-02-13 21:46:57 -05:00
use TgBotLib\Interfaces\ObjectTypeInterface;
2024-10-02 00:18:12 -04:00
use TgBotLib\Objects\MenuButton;
use TgBotLib\Objects\WebAppInfo;
2023-02-13 21:46:57 -05:00
2024-10-04 00:45:09 -04:00
class MenuButtonWebApp extends MenuButton implements ObjectTypeInterface
2023-02-13 21:46:57 -05:00
{
2024-10-04 00:45:09 -04:00
private string $text;
private WebAppInfo $web_app;
2023-02-13 21:46:57 -05:00
/**
* Text on the button
*
* @return string
*/
public function getText(): string
{
return $this->text;
}
/**
* Description of the Web App that will be launched when the user presses the button. The Web App will be able
* to send an arbitrary message on behalf of the user using the method answerWebAppQuery.
*
* @see https://core.telegram.org/bots/api#answerwebappquery
* @return WebAppInfo
*/
public function getWebApp(): WebAppInfo
{
return $this->web_app;
}
/**
2024-10-04 00:45:09 -04:00
* @inheritDoc
2023-02-13 21:46:57 -05:00
*/
public function toArray(): array
{
return [
2024-10-04 00:45:09 -04:00
'type' => $this->type->value,
2023-02-13 21:46:57 -05:00
'text' => $this->text,
2024-10-04 00:45:09 -04:00
'web_app' => $this->web_app?->toArray()
2023-02-13 21:46:57 -05:00
];
}
/**
2024-10-04 00:45:09 -04:00
* @inheritDoc
2023-02-13 21:46:57 -05:00
*/
2024-10-04 00:45:09 -04:00
public static function fromArray(?array $data): MenuButtonWebApp
2023-02-13 21:46:57 -05:00
{
$object = new self();
2023-02-14 17:35:16 -05:00
$object->type = $data['type'] ?? null;
$object->text = $data['text'] ?? null;
2024-10-04 00:45:09 -04:00
$object->web_app = isset($data['web_app']) ? WebAppInfo::fromArray($data['web_app'] ?? []) : null;
2023-02-13 21:46:57 -05:00
return $object;
}
}