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

Added the ability to set different bot names for different user languages using the method setMyName.

This commit is contained in:
coder2020official 2023-04-22 18:25:24 +04:00
parent d6f4987197
commit 77e1928628
4 changed files with 63 additions and 0 deletions

View File

@ -3443,6 +3443,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_name(self, name: Optional[str]=None, language_code: Optional[str]=None):
"""
Use this method to change the bot's name. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#setmyname
:param name: Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
:type name: :obj:`str`
:param language_code: Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose
language there is no dedicated name.
:type language_code: :obj:`str`
:return: True on success.
"""
return apihelper.set_my_name(self.token, name, language_code)
def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None):
"""
@ -3450,6 +3468,8 @@ class TeleBot:
the chat with the bot if the chat is empty.
Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#setmydescription
: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`
@ -3467,6 +3487,8 @@ class TeleBot:
Use this method to get the current bot description for the given user language.
Returns BotDescription on success.
Telegram documentation: https://core.telegram.org/bots/api#getmydescription
:param language_code: A two-letter ISO 639-1 language code or an empty string
:type language_code: :obj:`str`
@ -3481,6 +3503,8 @@ class TeleBot:
is sent together with the link when users share the bot.
Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#setmyshortdescription
:param short_description: New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.
:type short_description: :obj:`str`
@ -3498,6 +3522,8 @@ class TeleBot:
Use this method to get the current bot short description for the given user language.
Returns BotShortDescription on success.
Telegram documentation: https://core.telegram.org/bots/api#getmyshortdescription
:param language_code: A two-letter ISO 639-1 language code or an empty string
:type language_code: :obj:`str`

View File

@ -1196,6 +1196,15 @@ def get_my_commands(token, scope=None, language_code=None):
payload['language_code'] = language_code
return _make_request(token, method_url, params=payload)
def set_my_name(token, name=None, language_code=None):
method_url = r'setMyName'
payload = {}
if name is not None:
payload['name'] = name
if language_code is not None:
payload['language_code'] = language_code
return _make_request(token, method_url, params=payload, method='post')
def set_chat_menu_button(token, chat_id=None, menu_button=None):
method_url = r'setChatMenuButton'
payload = {}

View File

@ -4361,6 +4361,24 @@ class AsyncTeleBot:
result = await asyncio_helper.get_my_commands(self.token, scope, language_code)
return [types.BotCommand.de_json(cmd) for cmd in result]
async def set_my_name(self, name: Optional[str]=None, language_code: Optional[str]=None):
"""
Use this method to change the bot's name. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#setmyname
:param name: Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
:type name: :obj:`str`
:param language_code: Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose
language there is no dedicated name.
:type language_code: :obj:`str`
:return: True on success.
"""
return await asyncio_helper.set_my_name(self.token, name, language_code)
async def set_chat_menu_button(self, chat_id: Union[int, str]=None,
menu_button: types.MenuButton=None) -> bool:
"""

View File

@ -1183,6 +1183,16 @@ async def get_my_commands(token, scope=None, language_code=None):
payload['language_code'] = language_code
return await _process_request(token, method_url, params=payload)
async def set_my_name(token, name=None, language_code=None):
method_url = r'setMyName'
payload = {}
if name is not None:
payload['name'] = name
if language_code is not None:
payload['language_code'] = language_code
return await _process_request(token, method_url, params=payload, method='post')
async def set_chat_menu_button(token, chat_id=None, menu_button=None):
method_url = r'setChatMenuButton'
payload = {}