From 8965ac3affaa338a47d378d26a8e57319cb88a99 Mon Sep 17 00:00:00 2001 From: Netkas Date: Thu, 6 Apr 2023 13:54:48 -0400 Subject: [PATCH] Added method `\TgBotLib\Bot > sendSticker()` to send a sticker to a chat. See [sendSticker](https://core.telegram.org/bots/api#sendsticker) for more information. --- CHANGELOG.md | 1 + src/TgBotLib/Bot.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87fed00..bee10a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This update accompanies the release of the [Telegram Bot API 6.6](https://core.t see [setMyShortDescription](https://core.telegram.org/bots/api#setmyshortdescription) for more information. * Added the ability to get the current bot short description in the given language as the class [BotShortDescription](https://core.telegram.org/bots/api#botshortdescription) using the method `\TgBotLib\Bot > getMyShortDescription()` see [getMyShortDescription](https://core.telegram.org/bots/api#getmyshortdescription) for more information. + * Added method `\TgBotLib\Bot > sendSticker()` to send a sticker to a chat. See [sendSticker](https://core.telegram.org/bots/api#sendsticker) for more information. ### Changed * Removed unused `__destruct()` method from `\TgBotLib\Bot` diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index a0d9ec2..ce41921 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -2415,4 +2415,48 @@ ]); return true; } + + /** + * Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. + * On success, the sent Message is returned. + * + * @param int|string $chat_id + * @param string $sticker + * @param array $options + * @return Message + * @throws TelegramException + * @link Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. On success, the sent Message is returned. + * @noinspection PhpUnused + */ + public function sendSticker(int|string $chat_id, string $sticker, array $options=[]): Message + { + if(file_exists($sticker)) + { + return Message::fromArray( + $this->sendFileUpload('sendSticker', 'sticker', $sticker, array_merge([ + 'chat_id' => $chat_id + ], $options)) + ); + } + + $tmp_file = new TempFile(); + file_put_contents($tmp_file, $sticker); + + try + { + $response = Message::fromArray( + $this->sendFileUpload('sendSticker', 'sticker', $tmp_file, array_merge([ + 'chat_id' => $chat_id + ], $options)) + ); + } + catch(TelegramException $e) + { + unset($tmp_file); + throw $e; + } + + unset($tmp_file); + return $response; + } } \ No newline at end of file