From 917077c19aa5690e55aac2b9ce5996b7ae6628a9 Mon Sep 17 00:00:00 2001 From: Netkas Date: Mon, 10 Apr 2023 19:42:14 -0400 Subject: [PATCH] Added method `\TgBotLib\Bot > setStickerSetThumbnail()` to set the thumbnail of a sticker set. See [setStickerSetThumbnail](https://core.telegram.org/bots/api#setstickersetthumbnail) for more information. https://git.n64.cc/nosial/libs/tgbot/-/issues/2 --- CHANGELOG.md | 2 ++ src/TgBotLib/Bot.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88f929e..ddf205f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ This update accompanies the release of the [Telegram Bot API 6.6](https://core.t * Added method `\TgBotLib\Bot > setCustomEmojiStickerSetThumbnail()` to set the thumbnail of a sticker set. See [setCustomEmojiStickerSetThumbnail](https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail) for more information. * Added object `\TgBotLib\Objects\Telegram > StickerSet` to represent a sticker set. + * Added method `\TgBotLib\Bot > setStickerSetThumbnail()` to set the thumbnail of a sticker set. + See [setStickerSetThumbnail](https://core.telegram.org/bots/api#setstickersetthumbnail) for more information. ### Changed * Removed unused `__destruct()` method from `\TgBotLib\Bot` diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index f2f4847..6deb060 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -2593,4 +2593,37 @@ return true; } + + /** + * Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file must + * match the format of the stickers in the set. Returns True on success. + * + * @param string $name Sticker set name + * @param int $user_id User identifier of the sticker set owner + * @param string $thumb A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ยป. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. + * @param array $options Optional parameters + * @return bool + * @throws TelegramException + */ + public function setStickerSetThumbnail(string $name, int $user_id, string $thumb, array $options=[]): bool + { + if(file_exists($thumb)) + { + $thumb = new CURLFile($thumb); + } + else + { + $tmp_file = new TempFile(); + file_put_contents($tmp_file, $thumb); + $thumb = new CURLFile($tmp_file); + } + + $this->sendRequest('setStickerSetThumbnail', array_merge([ + 'name' => $name, + 'user_id' => $user_id, + 'thumb' => $thumb + ], $options)); + + return true; + } } \ No newline at end of file