diff --git a/CHANGELOG.md b/CHANGELOG.md index 33a471c..b4286db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ This update accompanies the release of the [Telegram Bot API 6.6](https://core.t * Added method `\TgBotLib\Bot > addStickerToSet()` to add a new sticker to a set created by the bot. See [addStickerToSet](https://core.telegram.org/bots/api#addstickertoset) for more information. * Added abstract class `\TgBotLib\Abstracts > StickerFormat` to represent a sticker format ("`static`", "`animated`" or "`video`") + * Added method `\TgBotLib\Bot > uploadStickerFile()` to upload a sticker file with a sticker for later use in `createNewStickerSet` and `addStickerToSet` methods (can be used multiple times). + See [uploadStickerFile](https://core.telegram.org/bots/api#uploadstickerfile) for more information. ### Changed * Removed unused `__destruct()` method from `\TgBotLib\Bot` diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index 640197e..01ee53d 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -2526,4 +2526,51 @@ return true; } + + /** + * Use this method to upload a file with a sticker for later use in the createNewStickerSet and addStickerToSet + * methods (the file can be used multiple times). Returns the uploaded File on success. + * + * @param int $user_id User identifier of sticker file owner + * @param string $sticker A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See https://core.telegram.org/stickers for technical requirements. + * @param string $sticker_format Format of the sticker, must be one of “static”, “animated”, “video” + * @return File + * @throws TelegramException + * @see https://core.telegram.org/bots/api#sending-files + * @link https://core.telegram.org/bots/api#uploadstickerfile + * @noinspection PhpUnused + */ + public function uploadStickerFile(int $user_id, string $sticker, string $sticker_format): File + { + if(file_exists($sticker)) + { + return File::fromArray( + $this->sendFileUpload('uploadStickerFile', 'sticker', $sticker, [ + 'user_id' => $user_id, + 'sticker_format' => $sticker_format + ]) + ); + } + + $tmp_file = new TempFile(); + file_put_contents($tmp_file, $sticker); + + try + { + $response = File::fromArray( + $this->sendFileUpload('uploadStickerFile', 'sticker', $tmp_file, [ + 'user_id' => $user_id, + 'sticker_format' => $sticker_format + ]) + ); + } + catch(TelegramException $e) + { + unset($tmp_file); + throw $e; + } + + unset($tmp_file); + return $response; + } } \ No newline at end of file