Skip to content

Commit abec3dc

Browse files
authored
Merge pull request #1969 from coder2020official/botapi6.7
Bot API 6.7 - Not much to do, just minor improvements
2 parents 92907ce + ecb5d9b commit abec3dc

File tree

7 files changed

+348
-31
lines changed

7 files changed

+348
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
1111
<p align="center">Both synchronous and asynchronous.</p>
1212

13-
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#march-9-2023">6.6</a>!
13+
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#april-21-2023">6.7</a>!
1414

1515
<h2><a href='https://pytba.readthedocs.io/en/latest/index.html'>Official documentation</a></h2>
1616
<h2><a href='https://pytba.readthedocs.io/ru/latest/index.html'>Official ru documentation</a></h2>

telebot/__init__.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,13 +3443,49 @@ 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)
3464+
3465+
def get_my_name(self, language_code: Optional[str]=None):
3466+
"""
3467+
Use this method to get the current bot name for the given user language.
3468+
Returns BotName on success.
3469+
3470+
Telegram documentation: https://core.telegram.org/bots/api#getmyname
3471+
3472+
:param language_code: Optional. A two-letter ISO 639-1 language code or an empty string
3473+
:type language_code: :obj:`str`
3474+
3475+
:return: :class:`telebot.types.BotName`
3476+
"""
3477+
3478+
result = apihelper.get_my_name(self.token, language_code)
3479+
return types.BotName.de_json(result)
34463480

34473481
def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None):
34483482
"""
34493483
Use this method to change the bot's description, which is shown in
34503484
the chat with the bot if the chat is empty.
34513485
Returns True on success.
34523486
3487+
Telegram documentation: https://core.telegram.org/bots/api#setmydescription
3488+
34533489
:param description: New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
34543490
:type description: :obj:`str`
34553491
@@ -3467,6 +3503,8 @@ def get_my_description(self, language_code: Optional[str]=None):
34673503
Use this method to get the current bot description for the given user language.
34683504
Returns BotDescription on success.
34693505
3506+
Telegram documentation: https://core.telegram.org/bots/api#getmydescription
3507+
34703508
:param language_code: A two-letter ISO 639-1 language code or an empty string
34713509
:type language_code: :obj:`str`
34723510
@@ -3481,6 +3519,8 @@ def set_my_short_description(self, short_description:Optional[str]=None, languag
34813519
is sent together with the link when users share the bot.
34823520
Returns True on success.
34833521
3522+
Telegram documentation: https://core.telegram.org/bots/api#setmyshortdescription
3523+
34843524
: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.
34853525
:type short_description: :obj:`str`
34863526
@@ -3498,6 +3538,8 @@ def get_my_short_description(self, language_code: Optional[str]=None):
34983538
Use this method to get the current bot short description for the given user language.
34993539
Returns BotShortDescription on success.
35003540
3541+
Telegram documentation: https://core.telegram.org/bots/api#getmyshortdescription
3542+
35013543
:param language_code: A two-letter ISO 639-1 language code or an empty string
35023544
:type language_code: :obj:`str`
35033545
@@ -4479,7 +4521,8 @@ def answer_inline_query(
44794521
is_personal: Optional[bool]=None,
44804522
next_offset: Optional[str]=None,
44814523
switch_pm_text: Optional[str]=None,
4482-
switch_pm_parameter: Optional[str]=None) -> bool:
4524+
switch_pm_parameter: Optional[str]=None,
4525+
button: Optional[types.InlineQueryResultsButton]=None) -> bool:
44834526
"""
44844527
Use this method to send answers to an inline query. On success, True is returned.
44854528
No more than 50 results per query are allowed.
@@ -4515,11 +4558,18 @@ def answer_inline_query(
45154558
:param switch_pm_text: Parameter for the start message sent to the bot when user presses the switch button
45164559
:type switch_pm_text: :obj:`str`
45174560
4561+
:param button: A JSON-serialized object describing a button to be shown above inline query results
4562+
:type button: :obj:`types.InlineQueryResultsButton`
4563+
45184564
:return: On success, True is returned.
45194565
:rtype: :obj:`bool`
45204566
"""
4567+
if not button and (switch_pm_text or switch_pm_parameter):
4568+
logger.warning("switch_pm_text and switch_pm_parameter are deprecated for answer_inline_query. Use button instead.")
4569+
button = types.InlineQueryResultsButton(text=switch_pm_text, start_parameter=switch_pm_parameter)
4570+
45214571
return apihelper.answer_inline_query(self.token, inline_query_id, results, cache_time, is_personal, next_offset,
4522-
switch_pm_text, switch_pm_parameter)
4572+
button)
45234573

45244574
def answer_callback_query(
45254575
self, callback_query_id: int,

telebot/apihelper.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,22 @@ 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+
1208+
def get_my_name(token, language_code=None):
1209+
method_url = r'getMyName'
1210+
payload = {}
1211+
if language_code is not None:
1212+
payload['language_code'] = language_code
1213+
return _make_request(token, method_url, params=payload)
1214+
11991215
def set_chat_menu_button(token, chat_id=None, menu_button=None):
12001216
method_url = r'setChatMenuButton'
12011217
payload = {}
@@ -1598,7 +1614,7 @@ def answer_callback_query(token, callback_query_id, text=None, show_alert=None,
15981614

15991615

16001616
def answer_inline_query(token, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None,
1601-
switch_pm_text=None, switch_pm_parameter=None):
1617+
button=None):
16021618
method_url = 'answerInlineQuery'
16031619
payload = {'inline_query_id': inline_query_id, 'results': _convert_list_json_serializable(results)}
16041620
if cache_time is not None:
@@ -1607,10 +1623,8 @@ def answer_inline_query(token, inline_query_id, results, cache_time=None, is_per
16071623
payload['is_personal'] = is_personal
16081624
if next_offset is not None:
16091625
payload['next_offset'] = next_offset
1610-
if switch_pm_text:
1611-
payload['switch_pm_text'] = switch_pm_text
1612-
if switch_pm_parameter:
1613-
payload['switch_pm_parameter'] = switch_pm_parameter
1626+
if button is not None:
1627+
payload["button"] = button.to_json()
16141628
return _make_request(token, method_url, params=payload, method='post')
16151629

16161630

telebot/async_telebot.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4361,6 +4361,40 @@ 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+
4382+
async def get_my_name(self, language_code: Optional[str]=None):
4383+
"""
4384+
Use this method to get the current bot name for the given user language.
4385+
Returns BotName on success.
4386+
4387+
Telegram documentation: https://core.telegram.org/bots/api#getmyname
4388+
4389+
:param language_code: Optional. A two-letter ISO 639-1 language code or an empty string
4390+
:type language_code: :obj:`str`
4391+
4392+
:return: :class:`telebot.types.BotName`
4393+
"""
4394+
4395+
result = await asyncio_helper.get_my_name(self.token, language_code)
4396+
return types.BotName.de_json(result)
4397+
43644398
async def set_chat_menu_button(self, chat_id: Union[int, str]=None,
43654399
menu_button: types.MenuButton=None) -> bool:
43664400
"""
@@ -5337,7 +5371,8 @@ async def answer_inline_query(
53375371
is_personal: Optional[bool]=None,
53385372
next_offset: Optional[str]=None,
53395373
switch_pm_text: Optional[str]=None,
5340-
switch_pm_parameter: Optional[str]=None) -> bool:
5374+
switch_pm_parameter: Optional[str]=None,
5375+
button: Optional[types.InlineQueryResultsButton]=None) -> bool:
53415376
"""
53425377
Use this method to send answers to an inline query. On success, True is returned.
53435378
No more than 50 results per query are allowed.
@@ -5373,11 +5408,18 @@ async def answer_inline_query(
53735408
:param switch_pm_text: Parameter for the start message sent to the bot when user presses the switch button
53745409
:type switch_pm_text: :obj:`str`
53755410
5411+
:param button: A JSON-serialized object describing a button to be shown above inline query results
5412+
:type button: :obj:`types.InlineQueryResultsButton`
5413+
53765414
:return: On success, True is returned.
53775415
:rtype: :obj:`bool`
53785416
"""
5417+
5418+
if not button and (switch_pm_text or switch_pm_parameter):
5419+
logger.warning("switch_pm_text and switch_pm_parameter are deprecated for answer_inline_query. Use button instead.")
5420+
button = types.InlineQueryResultsButton(text=switch_pm_text, start_parameter=switch_pm_parameter)
53795421
return await asyncio_helper.answer_inline_query(self.token, inline_query_id, results, cache_time, is_personal, next_offset,
5380-
switch_pm_text, switch_pm_parameter)
5422+
button)
53815423

53825424
async def answer_callback_query(
53835425
self, callback_query_id: int,

telebot/asyncio_helper.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,23 @@ 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+
1196+
async def get_my_name(token, language_code=None):
1197+
method_url = r'getMyName'
1198+
payload = {}
1199+
if language_code is not None:
1200+
payload['language_code'] = language_code
1201+
return await _process_request(token, method_url, params=payload)
1202+
11861203
async def set_chat_menu_button(token, chat_id=None, menu_button=None):
11871204
method_url = r'setChatMenuButton'
11881205
payload = {}
@@ -1587,7 +1604,7 @@ async def answer_callback_query(token, callback_query_id, text=None, show_alert=
15871604

15881605

15891606
async def answer_inline_query(token, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None,
1590-
switch_pm_text=None, switch_pm_parameter=None):
1607+
button=None):
15911608
method_url = 'answerInlineQuery'
15921609
payload = {'inline_query_id': inline_query_id, 'results': await _convert_list_json_serializable(results)}
15931610
if cache_time is not None:
@@ -1596,10 +1613,10 @@ async def answer_inline_query(token, inline_query_id, results, cache_time=None,
15961613
payload['is_personal'] = is_personal
15971614
if next_offset is not None:
15981615
payload['next_offset'] = next_offset
1599-
if switch_pm_text:
1600-
payload['switch_pm_text'] = switch_pm_text
1601-
if switch_pm_parameter:
1602-
payload['switch_pm_parameter'] = switch_pm_parameter
1616+
if button is not None:
1617+
payload["button"] = button.to_json()
1618+
1619+
16031620
return await _process_request(token, method_url, params=payload, method='post')
16041621

16051622

0 commit comments

Comments
 (0)