Skip to content

Commit a1bf961

Browse files
Bump Bot API 6.0(Beta)
1 parent 9652fdb commit a1bf961

6 files changed

Lines changed: 481 additions & 28 deletions

File tree

‎telebot/__init__.py‎

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,7 @@ def promote_chat_member(
17721772
can_promote_members: Optional[bool]=None,
17731773
is_anonymous: Optional[bool]=None,
17741774
can_manage_chat: Optional[bool]=None,
1775+
can_manage_video_chats: Optional[bool]=None,
17751776
can_manage_voice_chats: Optional[bool]=None) -> bool:
17761777
"""
17771778
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator
@@ -1798,15 +1799,20 @@ def promote_chat_member(
17981799
message statistics in channels, see channel members,
17991800
see anonymous administrators in supergroups and ignore slow mode.
18001801
Implied by any other administrator privilege
1801-
:param can_manage_voice_chats: Bool: Pass True, if the administrator can manage voice chats
1802+
:param can_manage_video_chats: Bool: Pass True, if the administrator can manage voice chats
18021803
For now, bots can use this privilege only for passing to other administrators.
1804+
:param can_manage_voice_chats: Deprecated, use can_manage_video_chats.
1805+
18031806
:return: True on success.
18041807
"""
1808+
if can_manage_voice_chats and not can_manage_video_chats is None:
1809+
can_manage_video_chats = can_manage_voice_chats
1810+
18051811
return apihelper.promote_chat_member(
18061812
self.token, chat_id, user_id, can_change_info, can_post_messages,
18071813
can_edit_messages, can_delete_messages, can_invite_users,
18081814
can_restrict_members, can_pin_messages, can_promote_members,
1809-
is_anonymous, can_manage_chat, can_manage_voice_chats)
1815+
is_anonymous, can_manage_chat, can_manage_video_chats)
18101816

18111817
def set_chat_administrator_custom_title(
18121818
self, chat_id: Union[int, str], user_id: int, custom_title: str) -> bool:
@@ -2033,6 +2039,71 @@ def get_my_commands(self, scope: Optional[types.BotCommandScope]=None,
20332039
result = apihelper.get_my_commands(self.token, scope, language_code)
20342040
return [types.BotCommand.de_json(cmd) for cmd in result]
20352041

2042+
def set_chat_menu_button(self, chat_id: Union[int, str]=None,
2043+
menu_button: types.MenuButton=None) -> bool:
2044+
"""
2045+
Use this method to change the bot's menu button in a private chat,
2046+
or the default menu button.
2047+
Returns True on success.
2048+
2049+
Telegram documentation: https://core.telegram.org/bots/api#setchatmenubutton
2050+
2051+
:param chat_id: Unique identifier for the target private chat.
2052+
If not specified, default bot's menu button will be changed
2053+
:param menu_button: A JSON-serialized object for the new bot's menu button. Defaults to MenuButtonDefault
2054+
2055+
"""
2056+
return apihelper.set_chat_menu_button(self.token, chat_id, menu_button)
2057+
2058+
2059+
def get_chat_menu_button(self, chat_id: Union[int, str]=None) -> types.MenuButton:
2060+
"""
2061+
Use this method to get the current value of the bot's menu button
2062+
in a private chat, or the default menu button.
2063+
Returns MenuButton on success.
2064+
2065+
Telegram Documentation: https://core.telegram.org/bots/api#getchatmenubutton
2066+
2067+
:param chat_id: Unique identifier for the target private chat.
2068+
If not specified, default bot's menu button will be returned
2069+
:return: types.MenuButton
2070+
2071+
"""
2072+
return types.MenuButton.de_json(apihelper.get_chat_menu_button(self.token, chat_id))
2073+
2074+
2075+
def set_my_default_administrator_rights(self, rights: types.ChatAdministratorRights=None,
2076+
for_channels: bool=None) -> bool:
2077+
"""
2078+
Use this method to change the default administrator rights requested by the bot
2079+
when it's added as an administrator to groups or channels.
2080+
These rights will be suggested to users, but they are are free to modify
2081+
the list before adding the bot.
2082+
Returns True on success.
2083+
2084+
Telegram documentation: https://core.telegram.org/bots/api#setmydefaultadministratorrights
2085+
2086+
:param rights: A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared.
2087+
:param for_channels: Pass True to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed.
2088+
"""
2089+
2090+
return apihelper.set_my_default_administrator_rights(self.token, rights, for_channels)
2091+
2092+
2093+
def get_my_default_administrator_rights(self, for_channels: bool=None) -> types.ChatAdministratorRights:
2094+
"""
2095+
Use this method to get the current default administrator rights of the bot.
2096+
Returns ChatAdministratorRights on success.
2097+
2098+
Telegram documentation: https://core.telegram.org/bots/api#getmydefaultadministratorrights
2099+
2100+
:param for_channels: Pass True to get the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be returned.
2101+
:return: types.ChatAdministratorRights
2102+
"""
2103+
2104+
return types.ChatAdministratorRights.de_json(apihelper.get_my_default_administrator_rights(self.token, for_channels))
2105+
2106+
20362107
def set_my_commands(self, commands: List[types.BotCommand],
20372108
scope: Optional[types.BotCommandScope]=None,
20382109
language_code: Optional[str]=None) -> bool:
@@ -2684,6 +2755,22 @@ def delete_sticker_from_set(self, sticker: str) -> bool:
26842755
"""
26852756
return apihelper.delete_sticker_from_set(self.token, sticker)
26862757

2758+
def answer_web_app_query(self, web_app_query_id: str, result: types.InlineQueryResultBase) -> types.SentWebAppMessage:
2759+
"""
2760+
Use this method to set the result of an interaction with a Web App and
2761+
send a corresponding message on behalf of the user to the chat from which
2762+
the query originated.
2763+
On success, a SentWebAppMessage object is returned.
2764+
2765+
Telegram Documentation: https://core.telegram.org/bots/api#answerwebappquery
2766+
2767+
:param web_app_query_id: Unique identifier for the query to be answered
2768+
:param result: A JSON-serialized object describing the message to be sent
2769+
:return:
2770+
"""
2771+
2772+
return apihelper.answer_web_app_query(self.token, web_app_query_id, result)
2773+
26872774
def register_for_reply(
26882775
self, message: types.Message, callback: Callable, *args, **kwargs) -> None:
26892776
"""

‎telebot/apihelper.py‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ def promote_chat_member(
971971
token, chat_id, user_id, can_change_info=None, can_post_messages=None,
972972
can_edit_messages=None, can_delete_messages=None, can_invite_users=None,
973973
can_restrict_members=None, can_pin_messages=None, can_promote_members=None,
974-
is_anonymous=None, can_manage_chat=None, can_manage_voice_chats=None):
974+
is_anonymous=None, can_manage_chat=None, can_manage_video_chats=None):
975975
method_url = 'promoteChatMember'
976976
payload = {'chat_id': chat_id, 'user_id': user_id}
977977
if can_change_info is not None:
@@ -994,8 +994,8 @@ def promote_chat_member(
994994
payload['is_anonymous'] = is_anonymous
995995
if can_manage_chat is not None:
996996
payload['can_manage_chat'] = can_manage_chat
997-
if can_manage_voice_chats is not None:
998-
payload['can_manage_voice_chats'] = can_manage_voice_chats
997+
if can_manage_video_chats is not None:
998+
payload['can_manage_video_chats'] = can_manage_video_chats
999999
return _make_request(token, method_url, params=payload, method='post')
10001000

10011001

@@ -1139,6 +1139,43 @@ def get_my_commands(token, scope=None, language_code=None):
11391139
payload['language_code'] = language_code
11401140
return _make_request(token, method_url, params=payload)
11411141

1142+
def set_chat_menu_button(token, chat_id=None, menu_button=None):
1143+
method_url = r'setChatMenuButton'
1144+
payload = {}
1145+
if chat_id:
1146+
payload['chat_id'] = chat_id
1147+
if menu_button:
1148+
payload['menu_button'] = menu_button.to_json()
1149+
1150+
return _make_request(token, method_url, params=payload, method='post')
1151+
1152+
def get_chat_menu_button(token, chat_id=None):
1153+
method_url = r'getChatMenuButton'
1154+
payload = {}
1155+
if chat_id:
1156+
payload['chat_id'] = chat_id
1157+
1158+
return _make_request(token, method_url, params=payload, method='post')
1159+
1160+
1161+
def set_my_default_administrator_rights(token, rights=None, for_channels=None):
1162+
method_url = r'setMyDefaultAdministratorRights'
1163+
payload = {}
1164+
if rights:
1165+
payload['rights'] = rights.to_json()
1166+
if for_channels:
1167+
payload['for_channels'] = for_channels
1168+
1169+
return _make_request(token, method_url, params=payload, method='post')
1170+
1171+
def get_my_default_administrator_rights(token, for_channels=None):
1172+
method_url = r'getMyDefaultAdministratorRights'
1173+
payload = {}
1174+
if for_channels:
1175+
payload['for_channels'] = for_channels
1176+
1177+
return _make_request(token, method_url, params=payload, method='post')
1178+
11421179

11431180
def set_my_commands(token, commands, scope=None, language_code=None):
11441181
method_url = r'setMyCommands'
@@ -1590,6 +1627,11 @@ def delete_sticker_from_set(token, sticker):
15901627
payload = {'sticker': sticker}
15911628
return _make_request(token, method_url, params=payload, method='post')
15921629

1630+
def answer_web_app_query(token, web_app_query_id, result: types.InlineQueryResultBase):
1631+
method_url = 'answerWebAppQuery'
1632+
result = result.to_json()
1633+
payload = {'query_id': web_app_query_id, 'result': result}
1634+
return _make_request(token, method_url, params=payload, method='post')
15931635

15941636
# noinspection PyShadowingBuiltins
15951637
def send_poll(
@@ -1663,6 +1705,7 @@ def _convert_list_json_serializable(results):
16631705
return '[' + ret + ']'
16641706

16651707

1708+
16661709
def _convert_markup(markup):
16671710
if isinstance(markup, types.JsonSerializable):
16681711
return markup.to_json()

‎telebot/async_telebot.py‎

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,22 @@ async def delete_chat_sticker_set(self, chat_id: Union[int, str]) -> bool:
15501550
result = await asyncio_helper.delete_chat_sticker_set(self.token, chat_id)
15511551
return result
15521552

1553+
async def answer_web_app_query(self, web_app_query_id: str, result: types.InlineQueryResultBase) -> types.SentWebAppMessage:
1554+
"""
1555+
Use this method to set the result of an interaction with a Web App and
1556+
send a corresponding message on behalf of the user to the chat from which
1557+
the query originated.
1558+
On success, a SentWebAppMessage object is returned.
1559+
1560+
Telegram Documentation: https://core.telegram.org/bots/api#answerwebappquery
1561+
1562+
:param web_app_query_id: Unique identifier for the query to be answered
1563+
:param result: A JSON-serialized object describing the message to be sent
1564+
:return:
1565+
"""
1566+
1567+
return await asyncio_helper.answer_web_app_query(self.token, web_app_query_id, result)
1568+
15531569
async def get_chat_member(self, chat_id: Union[int, str], user_id: int) -> types.ChatMember:
15541570
"""
15551571
Use this method to get information about a member of a chat. Returns a ChatMember object on success.
@@ -2374,6 +2390,7 @@ async def promote_chat_member(
23742390
can_promote_members: Optional[bool]=None,
23752391
is_anonymous: Optional[bool]=None,
23762392
can_manage_chat: Optional[bool]=None,
2393+
can_manage_video_chats: Optional[bool]=None,
23772394
can_manage_voice_chats: Optional[bool]=None) -> bool:
23782395
"""
23792396
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator
@@ -2400,15 +2417,20 @@ async def promote_chat_member(
24002417
message statistics in channels, see channel members,
24012418
see anonymous administrators in supergroups and ignore slow mode.
24022419
Implied by any other administrator privilege
2403-
:param can_manage_voice_chats: Bool: Pass True, if the administrator can manage voice chats
2420+
:param can_manage_video_chats: Bool: Pass True, if the administrator can manage voice chats
24042421
For now, bots can use this privilege only for passing to other administrators.
2422+
:param can_manage_voice_chats: Deprecated, use can_manage_video_chats
24052423
:return: True on success.
24062424
"""
2425+
2426+
if can_manage_voice_chats and not can_manage_video_chats is None:
2427+
can_manage_video_chats = can_manage_voice_chats
2428+
24072429
return await asyncio_helper.promote_chat_member(
24082430
self.token, chat_id, user_id, can_change_info, can_post_messages,
24092431
can_edit_messages, can_delete_messages, can_invite_users,
24102432
can_restrict_members, can_pin_messages, can_promote_members,
2411-
is_anonymous, can_manage_chat, can_manage_voice_chats)
2433+
is_anonymous, can_manage_chat, can_manage_video_chats)
24122434

24132435
async def set_chat_administrator_custom_title(
24142436
self, chat_id: Union[int, str], user_id: int, custom_title: str) -> bool:
@@ -2635,6 +2657,70 @@ async def get_my_commands(self, scope: Optional[types.BotCommandScope],
26352657
result = await asyncio_helper.get_my_commands(self.token, scope, language_code)
26362658
return [types.BotCommand.de_json(cmd) for cmd in result]
26372659

2660+
async def set_chat_menu_button(self, chat_id: Union[int, str]=None,
2661+
menu_button: types.MenuButton=None) -> bool:
2662+
"""
2663+
Use this method to change the bot's menu button in a private chat,
2664+
or the default menu button.
2665+
Returns True on success.
2666+
2667+
Telegram documentation: https://core.telegram.org/bots/api#setchatmenubutton
2668+
2669+
:param chat_id: Unique identifier for the target private chat.
2670+
If not specified, default bot's menu button will be changed
2671+
:param menu_button: A JSON-serialized object for the new bot's menu button. Defaults to MenuButtonDefault
2672+
2673+
"""
2674+
return await asyncio_helper.set_chat_menu_button(self.token, chat_id, menu_button)
2675+
2676+
2677+
async def get_chat_menu_button(self, chat_id: Union[int, str]=None) -> types.MenuButton:
2678+
"""
2679+
Use this method to get the current value of the bot's menu button
2680+
in a private chat, or the default menu button.
2681+
Returns MenuButton on success.
2682+
2683+
Telegram Documentation: https://core.telegram.org/bots/api#getchatmenubutton
2684+
2685+
:param chat_id: Unique identifier for the target private chat.
2686+
If not specified, default bot's menu button will be returned
2687+
:return: types.MenuButton
2688+
2689+
"""
2690+
return types.MenuButton.de_json(await asyncio_helper.get_chat_menu_button(self.token, chat_id))
2691+
2692+
2693+
async def set_my_default_administrator_rights(self, rights: types.ChatAdministratorRights=None,
2694+
for_channels: bool=None) -> bool:
2695+
"""
2696+
Use this method to change the default administrator rights requested by the bot
2697+
when it's added as an administrator to groups or channels.
2698+
These rights will be suggested to users, but they are are free to modify
2699+
the list before adding the bot.
2700+
Returns True on success.
2701+
2702+
Telegram documentation: https://core.telegram.org/bots/api#setmydefaultadministratorrights
2703+
2704+
:param rights: A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared.
2705+
:param for_channels: Pass True to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed.
2706+
"""
2707+
2708+
return await asyncio_helper.set_my_default_administrator_rights(self.token, rights, for_channels)
2709+
2710+
2711+
async def get_my_default_administrator_rights(self, for_channels: bool=None) -> types.ChatAdministratorRights:
2712+
"""
2713+
Use this method to get the current default administrator rights of the bot.
2714+
Returns ChatAdministratorRights on success.
2715+
2716+
Telegram documentation: https://core.telegram.org/bots/api#getmydefaultadministratorrights
2717+
2718+
:param for_channels: Pass True to get the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be returned.
2719+
:return: types.ChatAdministratorRights
2720+
"""
2721+
2722+
return types.ChatAdministratorRights.de_json(await asyncio_helper.get_my_default_administrator_rights(self.token, for_channels))
2723+
26382724
async def set_my_commands(self, commands: List[types.BotCommand],
26392725
scope: Optional[types.BotCommandScope]=None,
26402726
language_code: Optional[str]=None) -> bool:

0 commit comments

Comments
 (0)