From ccd910938b53b684501da48abe10ffcd609135ab Mon Sep 17 00:00:00 2001 From: Netkas Date: Thu, 6 Apr 2023 13:33:29 -0400 Subject: [PATCH] Added the ability to get the current bot description in the given language as the class [BotDescription](https://core.telegram.org/bots/api#botdescription) using the method `\TgBotLib\Bot > getMyDescription()` --- CHANGELOG.md | 2 + src/TgBotLib/Bot.php | 17 ++++++ .../Objects/Telegram/BotDescription.php | 53 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/TgBotLib/Objects/Telegram/BotDescription.php diff --git a/CHANGELOG.md b/CHANGELOG.md index cf02355..60e6463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added the ability to set different bot descriptions for different user languages using the method `\TgBotLib\Bot > setMyDescription()` + * Added the ability to get the current bot description in the given language as the class [BotDescription](https://core.telegram.org/bots/api#botdescription) + using the method `\TgBotLib\Bot > getMyDescription()` ### Changed * Removed unused `__destruct()` method from `\TgBotLib\Bot` diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index b5487ef..d31f7af 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -16,6 +16,7 @@ use TgBotLib\Interfaces\EventInterface; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\BotCommandScope; + use TgBotLib\Objects\Telegram\BotDescription; use TgBotLib\Objects\Telegram\Chat; use TgBotLib\Objects\Telegram\ChatAdministratorRights; use TgBotLib\Objects\Telegram\ChatInviteLink; @@ -2156,6 +2157,22 @@ return true; } + /** + * Use this method to get the current bot description for the given user language. + * Returns BotDescription on success. + * + * @param string|null $language_code + * @param array $options + * @return BotDescription + * @throws TelegramException + */ + public function getMyDescription(?string $language_code=null, array $options=[]): BotDescription + { + return BotDescription::fromArray($this->sendRequest('getMyDescription', array_merge([ + 'language_code' => $language_code + ], $options))); + } + /** * Use this method to change the bot's menu button in a private chat, or the default menu button. * Returns True on success. diff --git a/src/TgBotLib/Objects/Telegram/BotDescription.php b/src/TgBotLib/Objects/Telegram/BotDescription.php new file mode 100644 index 0000000..80cce1f --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/BotDescription.php @@ -0,0 +1,53 @@ +description; + } + + /** + * Returns an array representation of the object + * + * @return string[] + */ + public function toArray(): array + { + return [ + 'description' => $this->description, + ]; + } + + /** + * Constructs object from an array representation + * + * @param array $data + * @return BotDescription + */ + public static function fromArray(array $data): self + { + $object = new self(); + + $object->description = $data['description']; + + return $object; + } + + } \ No newline at end of file