Skip to content

Commit 4969f61

Browse files
authored
Merge pull request #2496 from coder2020official/botapi-91
Bot API 9.1 changes
2 parents 79f3a50 + 9980e6e commit 4969f61

File tree

6 files changed

+586
-9
lines changed

6 files changed

+586
-9
lines changed

telebot/__init__.py

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,90 @@ def copy_messages(self, chat_id: Union[str, int], from_chat_id: Union[str, int],
21042104
message_thread_id=message_thread_id, protect_content=protect_content, remove_caption=remove_caption)
21052105
return [types.MessageID.de_json(message_id) for message_id in result]
21062106

2107+
def send_checklist(
2108+
self, business_connection_id: str, chat_id: Union[int, str],
2109+
checklist: types.InputChecklist,
2110+
disable_notification: Optional[bool]=None,
2111+
protect_content: Optional[bool]=None,
2112+
message_effect_id: Optional[str]=None,
2113+
reply_parameters: Optional[types.ReplyParameters]=None,
2114+
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Message:
2115+
"""
2116+
Use this method to send a checklist on behalf of a connected business account. On success,
2117+
the sent Message is returned.
2118+
2119+
Telegram documentation: https://core.telegram.org/bots/api#sendchecklist
2120+
2121+
:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent
2122+
:type business_connection_id: :obj:`str`
2123+
2124+
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
2125+
:type chat_id: :obj:`int` or :obj:`str`
2126+
2127+
:param checklist: A JSON-serialized object for the checklist to send
2128+
:type checklist: :class:`telebot.types.InputChecklist`
2129+
2130+
:param disable_notification: Sends the message silently. Users will receive a notification with no sound.
2131+
:type disable_notification: :obj:`bool`
2132+
2133+
:param protect_content: Protects the contents of the sent message from forwarding and saving
2134+
:type protect_content: :obj:`bool`
2135+
2136+
:param message_effect_id: Unique identifier of the message effect to be added to the message; for private chats only
2137+
:type message_effect_id: :obj:`str`
2138+
2139+
:param reply_parameters: Additional parameters for replies to messages
2140+
:type reply_parameters: :class:`telebot.types.ReplyParameters`
2141+
2142+
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard.
2143+
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`
2144+
2145+
:return: On success, the sent Message is returned.
2146+
:rtype: :class:`telebot.types.Message`
2147+
"""
2148+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2149+
protect_content = self.protect_content if (protect_content is None) else protect_content
2150+
2151+
if reply_parameters and (reply_parameters.allow_sending_without_reply is None):
2152+
reply_parameters.allow_sending_without_reply = self.allow_sending_without_reply
2153+
2154+
return types.Message.de_json(
2155+
apihelper.send_checklist(
2156+
self.token, business_connection_id, chat_id, checklist, disable_notification=disable_notification,
2157+
protect_content=protect_content, message_effect_id=message_effect_id,
2158+
reply_parameters=reply_parameters, reply_markup=reply_markup))
2159+
2160+
def edit_message_checklist(
2161+
self, business_connection_id: str, chat_id: Union[int, str],
2162+
message_id: int, checklist: types.InputChecklist,
2163+
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Message:
2164+
"""
2165+
Use this method to edit a checklist on behalf of a connected business account. On success,
2166+
the edited Message is returned.
2167+
2168+
Telegram documentation: https://core.telegram.org/bots/api#editmessagechecklist
2169+
2170+
:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent
2171+
:type business_connection_id: :obj:`str`
2172+
2173+
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
2174+
:type chat_id: :obj:`int` or :obj:`str`
2175+
2176+
:param message_id: Unique identifier for the target message
2177+
:type message_id: :obj:`int`
2178+
2179+
:param checklist: A JSON-serialized object for the new checklist
2180+
:type checklist: :class:`telebot.types.InputChecklist`
2181+
2182+
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard.
2183+
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`
2184+
2185+
:return: On success, the edited Message is returned.
2186+
:rtype: :class:`telebot.types.Message`
2187+
"""
2188+
return types.Message.de_json(
2189+
apihelper.edit_message_checklist(
2190+
self.token, business_connection_id, chat_id, message_id, checklist, reply_markup=reply_markup))
21072191

21082192
def send_dice(
21092193
self, chat_id: Union[int, str],
@@ -5599,7 +5683,7 @@ def send_poll(
55995683
:param question: Poll question, 1-300 characters
56005684
:type question: :obj:`str`
56015685
5602-
:param options: A JSON-serialized list of 2-10 answer options
5686+
:param options: A JSON-serialized list of 2-12 answer options
56035687
:type options: :obj:`list` of :obj:`InputPollOption` | :obj:`list` of :obj:`str`
56045688
56055689
:param is_anonymous: True, if the poll needs to be anonymous, defaults to True
@@ -5818,6 +5902,17 @@ def answer_pre_checkout_query(
58185902
"""
58195903
return apihelper.answer_pre_checkout_query(
58205904
self.token, pre_checkout_query_id, ok, error_message=error_message)
5905+
5906+
def get_my_star_balance(self) -> types.StarAmount:
5907+
"""
5908+
Returns the bot's current Telegram Stars balance. On success, returns a StarAmount object.
5909+
5910+
Telegram documentation: https://core.telegram.org/bots/api#getmystarbalance
5911+
5912+
:return: On success, returns a StarAmount object.
5913+
:rtype: :obj:`types.StarAmount`
5914+
"""
5915+
return types.StarAmount.de_json(apihelper.get_my_star_balance(self.token))
58215916

58225917

58235918
def get_star_transactions(self, offset: Optional[int]=None, limit: Optional[int]=None) -> types.StarTransactions:

telebot/apihelper.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,36 @@ def copy_message(token, chat_id, from_chat_id, message_id, caption=None, parse_m
473473
payload['video_start_timestamp'] = video_start_timestamp
474474
return _make_request(token, method_url, params=payload)
475475

476+
def send_checklist(
477+
token, business_connection_id, chat_id, checklist,
478+
disable_notification=None, protect_content=None, message_effect_id=None,
479+
reply_parameters=None, reply_markup=None
480+
):
481+
method_url = r'sendChecklist'
482+
payload = {'chat_id': chat_id, 'checklist': checklist, 'business_connection_id': business_connection_id}
483+
if disable_notification is not None:
484+
payload['disable_notification'] = disable_notification
485+
if protect_content is not None:
486+
payload['protect_content'] = protect_content
487+
if message_effect_id:
488+
payload['message_effect_id'] = message_effect_id
489+
if reply_parameters:
490+
payload['reply_parameters'] = reply_parameters.to_json()
491+
if reply_markup:
492+
payload['reply_markup'] = _convert_markup(reply_markup)
493+
return _make_request(token, method_url, params=payload)
494+
495+
496+
def edit_message_checklist(
497+
token, business_connection_id, chat_id, message_id, checklist,
498+
reply_markup=None
499+
):
500+
method_url = r'editMessageChecklist'
501+
payload = {'chat_id': chat_id, 'message_id': message_id, 'checklist': checklist, 'business_connection_id': business_connection_id}
502+
if reply_markup:
503+
payload['reply_markup'] = _convert_markup(reply_markup)
504+
return _make_request(token, method_url, params=payload)
505+
476506

477507
def send_dice(
478508
token, chat_id,
@@ -1817,6 +1847,10 @@ def answer_pre_checkout_query(token, pre_checkout_query_id, ok, error_message=No
18171847
payload['error_message'] = error_message
18181848
return _make_request(token, method_url, params=payload)
18191849

1850+
def get_my_star_balance(token):
1851+
method_url = 'getMyStarBalance'
1852+
return _make_request(token, method_url)
1853+
18201854
def get_star_transactions(token, offset=None, limit=None):
18211855
method_url = 'getStarTransactions'
18221856
payload = {}

telebot/async_telebot.py

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3619,6 +3619,91 @@ async def copy_messages(self, chat_id: Union[str, int], from_chat_id: Union[str,
36193619
result = await asyncio_helper.copy_messages(self.token, chat_id, from_chat_id, message_ids, disable_notification, message_thread_id,
36203620
protect_content, remove_caption)
36213621
return [types.MessageID.de_json(message_id) for message_id in result]
3622+
3623+
async def send_checklist(
3624+
self, business_connection_id: str, chat_id: Union[int, str],
3625+
checklist: types.InputChecklist,
3626+
disable_notification: Optional[bool]=None,
3627+
protect_content: Optional[bool]=None,
3628+
message_effect_id: Optional[str]=None,
3629+
reply_parameters: Optional[types.ReplyParameters]=None,
3630+
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Message:
3631+
"""
3632+
Use this method to send a checklist on behalf of a connected business account. On success,
3633+
the sent Message is returned.
3634+
3635+
Telegram documentation: https://core.telegram.org/bots/api#sendchecklist
3636+
3637+
:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent
3638+
:type business_connection_id: :obj:`str`
3639+
3640+
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
3641+
:type chat_id: :obj:`int` or :obj:`str`
3642+
3643+
:param checklist: A JSON-serialized object for the checklist to send
3644+
:type checklist: :class:`telebot.types.InputChecklist`
3645+
3646+
:param disable_notification: Sends the message silently. Users will receive a notification with no sound.
3647+
:type disable_notification: :obj:`bool`
3648+
3649+
:param protect_content: Protects the contents of the sent message from forwarding and saving
3650+
:type protect_content: :obj:`bool`
3651+
3652+
:param message_effect_id: Unique identifier of the message effect to be added to the message; for private chats only
3653+
:type message_effect_id: :obj:`str`
3654+
3655+
:param reply_parameters: Additional parameters for replies to messages
3656+
:type reply_parameters: :class:`telebot.types.ReplyParameters`
3657+
3658+
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard.
3659+
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`
3660+
3661+
:return: On success, the sent Message is returned.
3662+
:rtype: :class:`telebot.types.Message`
3663+
"""
3664+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
3665+
protect_content = self.protect_content if (protect_content is None) else protect_content
3666+
3667+
if reply_parameters and (reply_parameters.allow_sending_without_reply is None):
3668+
reply_parameters.allow_sending_without_reply = self.allow_sending_without_reply
3669+
3670+
return types.Message.de_json(
3671+
await asyncio_helper.send_checklist(
3672+
self.token, business_connection_id, chat_id, checklist, disable_notification=disable_notification,
3673+
protect_content=protect_content, message_effect_id=message_effect_id,
3674+
reply_parameters=reply_parameters, reply_markup=reply_markup))
3675+
3676+
async def edit_message_checklist(
3677+
self, business_connection_id: str, chat_id: Union[int, str],
3678+
message_id: int, checklist: types.InputChecklist,
3679+
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Message:
3680+
"""
3681+
Use this method to edit a checklist on behalf of a connected business account. On success,
3682+
the edited Message is returned.
3683+
3684+
Telegram documentation: https://core.telegram.org/bots/api#editmessagechecklist
3685+
3686+
:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent
3687+
:type business_connection_id: :obj:`str`
3688+
3689+
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
3690+
:type chat_id: :obj:`int` or :obj:`str`
3691+
3692+
:param message_id: Unique identifier for the target message
3693+
:type message_id: :obj:`int`
3694+
3695+
:param checklist: A JSON-serialized object for the new checklist
3696+
:type checklist: :class:`telebot.types.InputChecklist`
3697+
3698+
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard.
3699+
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`
3700+
3701+
:return: On success, the edited Message is returned.
3702+
:rtype: :class:`telebot.types.Message`
3703+
"""
3704+
return types.Message.de_json(
3705+
await asyncio_helper.edit_message_checklist(
3706+
self.token, business_connection_id, chat_id, message_id, checklist, reply_markup=reply_markup))
36223707

36233708
async def send_dice(
36243709
self, chat_id: Union[int, str],
@@ -7256,8 +7341,15 @@ async def answer_pre_checkout_query(
72567341
:rtype: :obj:`bool`
72577342
"""
72587343
return await asyncio_helper.answer_pre_checkout_query(self.token, pre_checkout_query_id, ok, error_message)
7259-
72607344

7345+
7346+
async def get_my_star_balance(self) -> types.StarAmount:
7347+
"""
7348+
A method to get the current Telegram Stars balance of the bot. Requires no parameters.
7349+
On success, returns a StarAmount object.
7350+
"""
7351+
return types.StarAmount.de_json(await asyncio_helper.get_my_star_balance(self.token))
7352+
72617353
async def get_star_transactions(self, offset: Optional[int]=None, limit: Optional[int]=None) -> types.StarTransactions:
72627354
"""
72637355
Returns the bot's Telegram Star transactions in chronological order.

telebot/asyncio_helper.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,35 @@ async def copy_message(token, chat_id, from_chat_id, message_id, caption=None, p
477477
payload['video_start_timestamp'] = video_start_timestamp
478478
return await _process_request(token, method_url, params=payload)
479479

480+
async def send_checklist(
481+
token, business_connection_id, chat_id, checklist,
482+
disable_notification=None, protect_content=None, message_effect_id=None,
483+
reply_parameters=None, reply_markup=None
484+
):
485+
method_url = r'sendChecklist'
486+
payload = {'chat_id': chat_id, 'checklist': checklist, 'business_connection_id': business_connection_id}
487+
if disable_notification is not None:
488+
payload['disable_notification'] = disable_notification
489+
if protect_content is not None:
490+
payload['protect_content'] = protect_content
491+
if message_effect_id:
492+
payload['message_effect_id'] = message_effect_id
493+
if reply_parameters:
494+
payload['reply_parameters'] = reply_parameters.to_json()
495+
if reply_markup:
496+
payload['reply_markup'] = _convert_markup(reply_markup)
497+
return await _process_request(token, method_url, params=payload)
498+
499+
500+
async def edit_message_checklist(
501+
token, business_connection_id, chat_id, message_id, checklist,
502+
reply_markup=None
503+
):
504+
method_url = r'editMessageChecklist'
505+
payload = {'chat_id': chat_id, 'message_id': message_id, 'checklist': checklist, 'business_connection_id': business_connection_id}
506+
if reply_markup:
507+
payload['reply_markup'] = await _convert_markup(reply_markup)
508+
return await _process_request(token, method_url, params=payload)
480509

481510
async def send_dice(
482511
token, chat_id,
@@ -1816,6 +1845,11 @@ async def answer_pre_checkout_query(token, pre_checkout_query_id, ok, error_mess
18161845
payload['error_message'] = error_message
18171846
return await _process_request(token, method_url, params=payload)
18181847

1848+
1849+
async def get_my_star_balance(token):
1850+
method_url = 'getMyStarBalance'
1851+
return await _process_request(token, method_url)
1852+
18191853
async def get_star_transactions(token, offset=None, limit=None):
18201854
method_url = 'getStarTransactions'
18211855
payload = {}

0 commit comments

Comments
 (0)