From c17773e5d2256e051e2fca0bc1876443a26d3f28 Mon Sep 17 00:00:00 2001 From: Netkas Date: Fri, 7 Apr 2023 01:37:01 -0400 Subject: [PATCH] Added method `\TgBotLib\Bot > createNewStickerSet()` to create a new sticker set owned by a user. See [createNewStickerSet](https://core.telegram.org/bots/api#createnewstickerset) for more information. --- CHANGELOG.md | 1 + src/TgBotLib/Bot.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bee10a1..c15991d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This update accompanies the release of the [Telegram Bot API 6.6](https://core.t * 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. + * Added method `\TgBotLib\Bot > createNewStickerSet()` to create a new sticker set owned by a user. See [createNewStickerSet](https://core.telegram.org/bots/api#createnewstickerset) for more information. ### Changed * Removed unused `__destruct()` method from `\TgBotLib\Bot` diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index ce41921..eccd83b 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -2459,4 +2459,46 @@ unset($tmp_file); return $response; } + + /** + * Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker + * set thus created. Returns True on success. + * + * @param int $user_id User identifier of created sticker set owner + * @param string $name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only English letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in "_by_". is case insensitive. 1-64 characters. + * @param string $title Sticker set title, 1-64 characters + * @param array $stickers A list of 1-50 initial stickers to be added to the sticker set + * @param string $sticker_format Format of stickers in the set, must be one of “static”, “animated”, “video” + * @param array $options Optional parameters + * @return bool + * @throws TelegramException + * @link https://core.telegram.org/bots/api#createnewstickerset + * @noinspection PhpUnused + */ + public function createNewStickerSet(int $user_id, string $name, string $title, array $stickers, string $sticker_format, array $options=[]): bool + { + foreach($stickers as $key => $sticker) + { + if(file_exists($sticker)) + { + $stickers[$key] = new CURLFile($sticker); + } + else + { + $tmp_file = new TempFile(); + file_put_contents($tmp_file, $sticker); + $stickers[$key] = new CURLFile($tmp_file); + } + } + + $this->sendRequest('createNewStickerSet', array_merge([ + 'user_id' => $user_id, + 'name' => $name, + 'title' => $title, + 'stickers' => $stickers, + 'sticker_format' => $sticker_format + ], $options)); + + return true; + } } \ No newline at end of file