diff --git a/telebot/__init__.py b/telebot/__init__.py index 90a2fcf..e3ea18f 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -4564,7 +4564,7 @@ class TeleBot: result = apihelper.get_custom_emoji_stickers(self.token, custom_emoji_ids) return [types.Sticker.de_json(sticker) for sticker in result] - def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]) -> types.File: + def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, sticker: Optional[types.InputFile]=None, sticker_format: Optional[str]=None) -> types.File: """ Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success. @@ -4574,14 +4574,26 @@ class TeleBot: :param user_id: User identifier of sticker set owner :type user_id: :obj:`int` - :param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, + :param png_sticker: DEPRECATED: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. :type png_sticker: :obj:`filelike object` + :param sticker: A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. + See https://core.telegram.org/stickers for technical requirements. More information on Sending Files » + :type sticker: :class:`telebot.types.InputFile` + + :param sticker_format: One of "static", "animated", "video". + :type sticker_format: :obj:`str` + :return: On success, the sent file is returned. :rtype: :class:`telebot.types.File` """ - result = apihelper.upload_sticker_file(self.token, user_id, png_sticker) + if png_sticker: + logger.warning("png_sticker is deprecated, use sticker instead", DeprecationWarning) + sticker = png_sticker + sticker_format = "static" + + result = apihelper.upload_sticker_file(self.token, user_id, sticker, sticker_format) return types.File.de_json(result) def create_new_sticker_set( diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 0ee636e..9a24a0c 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -1621,10 +1621,10 @@ def get_custom_emoji_stickers(token, custom_emoji_ids): method_url = r'getCustomEmojiStickers' return _make_request(token, method_url, params={'custom_emoji_ids': custom_emoji_ids}) -def upload_sticker_file(token, user_id, png_sticker): +def upload_sticker_file(token, user_id, sticker, sticker_format): method_url = 'uploadStickerFile' - payload = {'user_id': user_id} - files = {'png_sticker': png_sticker} + payload = {'user_id': user_id, 'sticker_format': sticker_format} + files = {'sticker': sticker} return _make_request(token, method_url, params=payload, files=files, method='post') diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 079a9a6..f7766d4 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -5427,7 +5427,7 @@ class AsyncTeleBot: result = await asyncio_helper.get_custom_emoji_stickers(self.token, custom_emoji_ids) return [types.Sticker.de_json(sticker) for sticker in result] - async def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]) -> types.File: + async def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, sticker: Optional[types.InputFile]=None, sticker_format: Optional[str]=None) -> types.File: """ Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success. @@ -5437,14 +5437,26 @@ class AsyncTeleBot: :param user_id: User identifier of sticker set owner :type user_id: :obj:`int` - :param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, + :param png_sticker: DEPRECATED: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. :type png_sticker: :obj:`filelike object` + :param sticker: A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. + See https://core.telegram.org/stickers for technical requirements. More information on Sending Files » + :type sticker: :class:`telebot.types.InputFile` + + :param sticker_format: One of "static", "animated", "video". + :type sticker_format: :obj:`str` + :return: On success, the sent file is returned. :rtype: :class:`telebot.types.File` """ - result = await asyncio_helper.upload_sticker_file(self.token, user_id, png_sticker) + if png_sticker: + logger.warning("png_sticker is deprecated, use sticker instead", DeprecationWarning) + sticker = png_sticker + sticker_format = "static" + + result = await asyncio_helper.upload_sticker_file(self.token, user_id, sticker, sticker_format) return types.File.de_json(result) async def create_new_sticker_set( diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 7c0a80e..d571c93 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -1608,10 +1608,10 @@ async def get_custom_emoji_stickers(token, custom_emoji_ids): method_url = r'getCustomEmojiStickers' return await _process_request(token, method_url, params={'custom_emoji_ids': custom_emoji_ids}) -async def upload_sticker_file(token, user_id, png_sticker): +async def upload_sticker_file(token, user_id, sticker, sticker_format): method_url = 'uploadStickerFile' - payload = {'user_id': user_id} - files = {'png_sticker': png_sticker} + payload = {'user_id': user_id, 'sticker_format': sticker_format} + files = {'sticker': sticker} return await _process_request(token, method_url, params=payload, files=files, method='post')