From c84b771e5a41f1b0e7eed82f1f38dfe8e2830e61 Mon Sep 17 00:00:00 2001 From: coder2020official Date: Fri, 10 Mar 2023 21:36:44 +0400 Subject: [PATCH] Added the ability to set different bot descriptions for different user languages using the method setMyDescription. --- telebot/__init__.py | 18 ++++++++++++++++++ telebot/apihelper.py | 9 +++++++++ telebot/async_telebot.py | 18 ++++++++++++++++++ telebot/asyncio_helper.py | 8 ++++++++ 4 files changed, 53 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index f8dd488..0dfaf26 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -3400,6 +3400,24 @@ class TeleBot: """ result = apihelper.get_my_commands(self.token, scope, language_code) return [types.BotCommand.de_json(cmd) for cmd in result] + + def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None): + """ + Use this method to change the bot's description, which is shown in + the chat with the bot if the chat is empty. + Returns True on success. + + :param description: New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language. + :type description: :obj:`str` + + :param language_code: A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for + whose language there is no dedicated description. + :type language_code: :obj:`str` + + :return: True on success. + """ + + return apihelper.set_my_description(self.token, description, language_code) def set_chat_menu_button(self, chat_id: Union[int, str]=None, menu_button: types.MenuButton=None) -> bool: diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 17c3e41..d566966 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -1152,6 +1152,15 @@ def set_chat_title(token, chat_id, title): return _make_request(token, method_url, params=payload, method='post') +def set_my_description(token, description=None, language_code=None): + method_url = r'setMyDescription' + payload = {} + if description: + payload['description'] = description + if language_code: + payload['language_code'] = language_code + return _make_request(token, method_url, params=payload, method='post') + def get_my_commands(token, scope=None, language_code=None): method_url = r'getMyCommands' payload = {} diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index a75398c..da1d4fe 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -4238,6 +4238,24 @@ class AsyncTeleBot: """ return await asyncio_helper.delete_chat_photo(self.token, chat_id) + async def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None): + """ + Use this method to change the bot's description, which is shown in + the chat with the bot if the chat is empty. + Returns True on success. + + :param description: New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language. + :type description: :obj:`str` + + :param language_code: A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for + whose language there is no dedicated description. + :type language_code: :obj:`str` + + :return: True on success. + """ + + return await asyncio_helper.set_my_description(self.token, description, language_code) + async def get_my_commands(self, scope: Optional[types.BotCommandScope], language_code: Optional[str]) -> List[types.BotCommand]: """ diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 04b494f..8ac5501 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -1138,6 +1138,14 @@ async def set_chat_title(token, chat_id, title): payload = {'chat_id': chat_id, 'title': title} return await _process_request(token, method_url, params=payload, method='post') +async def set_my_description(token, description=None, language_code=None): + method_url = r'setMyDescription' + payload = {} + if description: + payload['description'] = description + if language_code: + payload['language_code'] = language_code + return await _process_request(token, method_url, params=payload, method='post') async def get_my_commands(token, scope=None, language_code=None): method_url = r'getMyCommands'