1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Added the ability to get the current bot description in the given language as the class BotDescription using the method getMyDescription.

This commit is contained in:
coder2020official 2023-03-11 15:35:00 +04:00
parent c84b771e5a
commit 65dcd67140
5 changed files with 63 additions and 0 deletions

View File

@ -3418,6 +3418,19 @@ class TeleBot:
"""
return apihelper.set_my_description(self.token, description, language_code)
def get_my_description(self, language_code: Optional[str]=None):
"""
Use this method to get the current bot description for the given user language.
Returns BotDescription on success.
:param language_code: A two-letter ISO 639-1 language code or an empty string
:type language_code: :obj:`str`
:return: :class:`telebot.types.BotDescription`
"""
return types.BotDescription.de_json(apihelper.get_my_description(self.token, language_code))
def set_chat_menu_button(self, chat_id: Union[int, str]=None,
menu_button: types.MenuButton=None) -> bool:

View File

@ -1161,6 +1161,13 @@ def set_my_description(token, description=None, language_code=None):
payload['language_code'] = language_code
return _make_request(token, method_url, params=payload, method='post')
def get_my_description(token, language_code=None):
method_url = r'getMyDescription'
payload = {}
if language_code:
payload['language_code'] = language_code
return _make_request(token, method_url, params=payload)
def get_my_commands(token, scope=None, language_code=None):
method_url = r'getMyCommands'
payload = {}

View File

@ -4255,6 +4255,19 @@ class AsyncTeleBot:
"""
return await asyncio_helper.set_my_description(self.token, description, language_code)
async def get_my_description(self, language_code: Optional[str]=None):
"""
Use this method to get the current bot description for the given user language.
Returns BotDescription on success.
:param language_code: A two-letter ISO 639-1 language code or an empty string
:type language_code: :obj:`str`
:return: :class:`telebot.types.BotDescription`
"""
result = await asyncio_helper.get_my_description(self.token, language_code)
return types.BotDescription.de_json(result)
async def get_my_commands(self, scope: Optional[types.BotCommandScope],
language_code: Optional[str]) -> List[types.BotCommand]:

View File

@ -1147,6 +1147,14 @@ async def set_my_description(token, description=None, language_code=None):
payload['language_code'] = language_code
return await _process_request(token, method_url, params=payload, method='post')
async def get_my_description(token, language_code=None):
method_url = r'getMyDescription'
payload = {}
if language_code:
payload['language_code'] = language_code
return await _process_request(token, method_url, params=payload)
async def get_my_commands(token, scope=None, language_code=None):
method_url = r'getMyCommands'
payload = {}

View File

@ -7296,3 +7296,25 @@ class ChatShared(JsonDeserializable):
self.request_id: int = request_id
self.chat_id: int = chat_id
class BotDescription(JsonDeserializable):
"""
This object represents a bot description.
Telegram documentation: https://core.telegram.org/bots/api#botdescription
:param description: Bot description
:type description: :obj:`str`
:return: Instance of the class
:rtype: :class:`telebot.types.BotDescription`
"""
@classmethod
def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)
return cls(**obj)
def __init__(self, description: str) -> None:
self.description: str = description