Skip to content

Commit 77e1928

Browse files
Added the ability to set different bot names for different user languages using the method setMyName.
1 parent d6f4987 commit 77e1928

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

telebot/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,13 +3443,33 @@ def get_my_commands(self, scope: Optional[types.BotCommandScope]=None,
34433443
"""
34443444
result = apihelper.get_my_commands(self.token, scope, language_code)
34453445
return [types.BotCommand.de_json(cmd) for cmd in result]
3446+
3447+
def set_my_name(self, name: Optional[str]=None, language_code: Optional[str]=None):
3448+
"""
3449+
Use this method to change the bot's name. Returns True on success.
3450+
3451+
Telegram documentation: https://core.telegram.org/bots/api#setmyname
3452+
3453+
:param name: Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
3454+
:type name: :obj:`str`
3455+
3456+
:param language_code: Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose
3457+
language there is no dedicated name.
3458+
:type language_code: :obj:`str`
3459+
3460+
:return: True on success.
3461+
"""
3462+
3463+
return apihelper.set_my_name(self.token, name, language_code)
34463464

34473465
def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None):
34483466
"""
34493467
Use this method to change the bot's description, which is shown in
34503468
the chat with the bot if the chat is empty.
34513469
Returns True on success.
34523470
3471+
Telegram documentation: https://core.telegram.org/bots/api#setmydescription
3472+
34533473
:param description: New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
34543474
:type description: :obj:`str`
34553475
@@ -3467,6 +3487,8 @@ def get_my_description(self, language_code: Optional[str]=None):
34673487
Use this method to get the current bot description for the given user language.
34683488
Returns BotDescription on success.
34693489
3490+
Telegram documentation: https://core.telegram.org/bots/api#getmydescription
3491+
34703492
:param language_code: A two-letter ISO 639-1 language code or an empty string
34713493
:type language_code: :obj:`str`
34723494
@@ -3481,6 +3503,8 @@ def set_my_short_description(self, short_description:Optional[str]=None, languag
34813503
is sent together with the link when users share the bot.
34823504
Returns True on success.
34833505
3506+
Telegram documentation: https://core.telegram.org/bots/api#setmyshortdescription
3507+
34843508
: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.
34853509
:type short_description: :obj:`str`
34863510
@@ -3498,6 +3522,8 @@ def get_my_short_description(self, language_code: Optional[str]=None):
34983522
Use this method to get the current bot short description for the given user language.
34993523
Returns BotShortDescription on success.
35003524
3525+
Telegram documentation: https://core.telegram.org/bots/api#getmyshortdescription
3526+
35013527
:param language_code: A two-letter ISO 639-1 language code or an empty string
35023528
:type language_code: :obj:`str`
35033529

telebot/apihelper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,15 @@ def get_my_commands(token, scope=None, language_code=None):
11961196
payload['language_code'] = language_code
11971197
return _make_request(token, method_url, params=payload)
11981198

1199+
def set_my_name(token, name=None, language_code=None):
1200+
method_url = r'setMyName'
1201+
payload = {}
1202+
if name is not None:
1203+
payload['name'] = name
1204+
if language_code is not None:
1205+
payload['language_code'] = language_code
1206+
return _make_request(token, method_url, params=payload, method='post')
1207+
11991208
def set_chat_menu_button(token, chat_id=None, menu_button=None):
12001209
method_url = r'setChatMenuButton'
12011210
payload = {}

telebot/async_telebot.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4361,6 +4361,24 @@ async def get_my_commands(self, scope: Optional[types.BotCommandScope],
43614361
result = await asyncio_helper.get_my_commands(self.token, scope, language_code)
43624362
return [types.BotCommand.de_json(cmd) for cmd in result]
43634363

4364+
async def set_my_name(self, name: Optional[str]=None, language_code: Optional[str]=None):
4365+
"""
4366+
Use this method to change the bot's name. Returns True on success.
4367+
4368+
Telegram documentation: https://core.telegram.org/bots/api#setmyname
4369+
4370+
:param name: Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
4371+
:type name: :obj:`str`
4372+
4373+
:param language_code: Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose
4374+
language there is no dedicated name.
4375+
:type language_code: :obj:`str`
4376+
4377+
:return: True on success.
4378+
"""
4379+
4380+
return await asyncio_helper.set_my_name(self.token, name, language_code)
4381+
43644382
async def set_chat_menu_button(self, chat_id: Union[int, str]=None,
43654383
menu_button: types.MenuButton=None) -> bool:
43664384
"""

telebot/asyncio_helper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,16 @@ async def get_my_commands(token, scope=None, language_code=None):
11831183
payload['language_code'] = language_code
11841184
return await _process_request(token, method_url, params=payload)
11851185

1186+
1187+
async def set_my_name(token, name=None, language_code=None):
1188+
method_url = r'setMyName'
1189+
payload = {}
1190+
if name is not None:
1191+
payload['name'] = name
1192+
if language_code is not None:
1193+
payload['language_code'] = language_code
1194+
return await _process_request(token, method_url, params=payload, method='post')
1195+
11861196
async def set_chat_menu_button(token, chat_id=None, menu_button=None):
11871197
method_url = r'setChatMenuButton'
11881198
payload = {}

0 commit comments

Comments
 (0)