From 9fa5b91e587cf8a5722d7b2c660db0c9230d2918 Mon Sep 17 00:00:00 2001 From: coder2020official Date: Sat, 11 Mar 2023 22:58:41 +0400 Subject: [PATCH] Added the method setStickerKeywords for changing the search keywords assigned to a sticker. --- telebot/__init__.py | 17 +++++++++++++++++ telebot/apihelper.py | 8 ++++++++ telebot/async_telebot.py | 17 +++++++++++++++++ telebot/asyncio_helper.py | 8 ++++++++ 4 files changed, 50 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index a102964..0458cc3 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -4564,6 +4564,23 @@ class TeleBot: result = apihelper.get_custom_emoji_stickers(self.token, custom_emoji_ids) return [types.Sticker.de_json(sticker) for sticker in result] + def set_sticker_keywords(self, sticker: str, keywords: List[str]=None) -> bool: + """ + Use this method to change search keywords assigned to a regular or custom emoji sticker. + The sticker must belong to a sticker set created by the bot. + Returns True on success. + + :param sticker: File identifier of the sticker. + :type sticker: :obj:`str` + + :param keywords: A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters + :type keywords: :obj:`list` of :obj:`str` + + :return: On success, True is returned. + :rtype: :obj:`bool` + """ + return apihelper.set_sticker_keywords(self.token, sticker, keywords) + def set_custom_emoji_sticker_set_thumbnail(self, name: str, custom_emoji_id: Optional[str]=None) -> bool: """ diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 8612532..c48df05 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -1620,6 +1620,14 @@ def get_sticker_set(token, name): def get_custom_emoji_stickers(token, custom_emoji_ids): method_url = r'getCustomEmojiStickers' return _make_request(token, method_url, params={'custom_emoji_ids': json.dumps(custom_emoji_ids)}) + +def set_sticker_keywords(token, sticker, keywords=None): + method_url = 'setStickerKeywords' + payload = {'sticker': sticker} + if keywords: + payload['keywords'] = json.dumps(keywords) + return _make_request(token, method_url, params=payload, method='post') + def upload_sticker_file(token, user_id, sticker, sticker_format): method_url = 'uploadStickerFile' diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index b50e987..4e8ecdc 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -5412,6 +5412,23 @@ class AsyncTeleBot: """ result = await asyncio_helper.get_sticker_set(self.token, name) return types.StickerSet.de_json(result) + + async def set_sticker_keywords(self, sticker: str, keywords: List[str]=None) -> bool: + """ + Use this method to change search keywords assigned to a regular or custom emoji sticker. + The sticker must belong to a sticker set created by the bot. + Returns True on success. + + :param sticker: File identifier of the sticker. + :type sticker: :obj:`str` + + :param keywords: A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters + :type keywords: :obj:`list` of :obj:`str` + + :return: On success, True is returned. + :rtype: :obj:`bool` + """ + return await asyncio_helper.set_sticker_keywords(self.token, sticker, keywords) async def get_custom_emoji_stickers(self, custom_emoji_ids: List[str]) -> List[types.Sticker]: """ diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 6268fff..d6f3774 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -1608,6 +1608,14 @@ 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': json.dumps(custom_emoji_ids)}) +async def set_sticker_keywords(token, sticker, keywords=None): + method_url = 'setStickerKeywords' + payload = {'sticker': sticker} + if keywords: + payload['keywords'] = json.dumps(keywords) + + return await _process_request(token, method_url, params=payload, method='post') + async def upload_sticker_file(token, user_id, sticker, sticker_format): method_url = 'uploadStickerFile' payload = {'user_id': user_id, 'sticker_format': sticker_format}