Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 96 additions & 1 deletion telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,90 @@ def copy_messages(self, chat_id: Union[str, int], from_chat_id: Union[str, int],
message_thread_id=message_thread_id, protect_content=protect_content, remove_caption=remove_caption)
return [types.MessageID.de_json(message_id) for message_id in result]

def send_checklist(
self, business_connection_id: str, chat_id: Union[int, str],
checklist: types.InputChecklist,
disable_notification: Optional[bool]=None,
protect_content: Optional[bool]=None,
message_effect_id: Optional[str]=None,
reply_parameters: Optional[types.ReplyParameters]=None,
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Message:
"""
Use this method to send a checklist on behalf of a connected business account. On success,
the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendchecklist

:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent
:type business_connection_id: :obj:`str`

:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`

:param checklist: A JSON-serialized object for the checklist to send
:type checklist: :class:`telebot.types.InputChecklist`

:param disable_notification: Sends the message silently. Users will receive a notification with no sound.
:type disable_notification: :obj:`bool`

:param protect_content: Protects the contents of the sent message from forwarding and saving
:type protect_content: :obj:`bool`

:param message_effect_id: Unique identifier of the message effect to be added to the message; for private chats only
:type message_effect_id: :obj:`str`

:param reply_parameters: Additional parameters for replies to messages
:type reply_parameters: :class:`telebot.types.ReplyParameters`

:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard.
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`

:return: On success, the sent Message is returned.
:rtype: :class:`telebot.types.Message`
"""
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
protect_content = self.protect_content if (protect_content is None) else protect_content

if reply_parameters and (reply_parameters.allow_sending_without_reply is None):
reply_parameters.allow_sending_without_reply = self.allow_sending_without_reply

return types.Message.de_json(
apihelper.send_checklist(
self.token, business_connection_id, chat_id, checklist, disable_notification=disable_notification,
protect_content=protect_content, message_effect_id=message_effect_id,
reply_parameters=reply_parameters, reply_markup=reply_markup))

def edit_message_checklist(
self, business_connection_id: str, chat_id: Union[int, str],
message_id: int, checklist: types.InputChecklist,
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Message:
"""
Use this method to edit a checklist on behalf of a connected business account. On success,
the edited Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#editmessagechecklist

:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent
:type business_connection_id: :obj:`str`

:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`

:param message_id: Unique identifier for the target message
:type message_id: :obj:`int`

:param checklist: A JSON-serialized object for the new checklist
:type checklist: :class:`telebot.types.InputChecklist`

:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard.
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`

:return: On success, the edited Message is returned.
:rtype: :class:`telebot.types.Message`
"""
return types.Message.de_json(
apihelper.edit_message_checklist(
self.token, business_connection_id, chat_id, message_id, checklist, reply_markup=reply_markup))

def send_dice(
self, chat_id: Union[int, str],
Expand Down Expand Up @@ -5599,7 +5683,7 @@ def send_poll(
:param question: Poll question, 1-300 characters
:type question: :obj:`str`

:param options: A JSON-serialized list of 2-10 answer options
:param options: A JSON-serialized list of 2-12 answer options
:type options: :obj:`list` of :obj:`InputPollOption` | :obj:`list` of :obj:`str`

:param is_anonymous: True, if the poll needs to be anonymous, defaults to True
Expand Down Expand Up @@ -5818,6 +5902,17 @@ def answer_pre_checkout_query(
"""
return apihelper.answer_pre_checkout_query(
self.token, pre_checkout_query_id, ok, error_message=error_message)

def get_my_star_balance(self) -> types.StarAmount:
"""
Returns the bot's current Telegram Stars balance. On success, returns a StarAmount object.

Telegram documentation: https://core.telegram.org/bots/api#getmystarbalance

:return: On success, returns a StarAmount object.
:rtype: :obj:`types.StarAmount`
"""
return types.StarAmount.de_json(apihelper.get_my_star_balance(self.token))


def get_star_transactions(self, offset: Optional[int]=None, limit: Optional[int]=None) -> types.StarTransactions:
Expand Down
34 changes: 34 additions & 0 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,36 @@ def copy_message(token, chat_id, from_chat_id, message_id, caption=None, parse_m
payload['video_start_timestamp'] = video_start_timestamp
return _make_request(token, method_url, params=payload)

def send_checklist(
token, business_connection_id, chat_id, checklist,
disable_notification=None, protect_content=None, message_effect_id=None,
reply_parameters=None, reply_markup=None
):
method_url = r'sendChecklist'
payload = {'chat_id': chat_id, 'checklist': checklist, 'business_connection_id': business_connection_id}
if disable_notification is not None:
payload['disable_notification'] = disable_notification
if protect_content is not None:
payload['protect_content'] = protect_content
if message_effect_id:
payload['message_effect_id'] = message_effect_id
if reply_parameters:
payload['reply_parameters'] = reply_parameters.to_json()
if reply_markup:
payload['reply_markup'] = _convert_markup(reply_markup)
return _make_request(token, method_url, params=payload)


def edit_message_checklist(
token, business_connection_id, chat_id, message_id, checklist,
reply_markup=None
):
method_url = r'editMessageChecklist'
payload = {'chat_id': chat_id, 'message_id': message_id, 'checklist': checklist, 'business_connection_id': business_connection_id}
if reply_markup:
payload['reply_markup'] = _convert_markup(reply_markup)
return _make_request(token, method_url, params=payload)


def send_dice(
token, chat_id,
Expand Down Expand Up @@ -1817,6 +1847,10 @@ def answer_pre_checkout_query(token, pre_checkout_query_id, ok, error_message=No
payload['error_message'] = error_message
return _make_request(token, method_url, params=payload)

def get_my_star_balance(token):
method_url = 'getMyStarBalance'
return _make_request(token, method_url)

def get_star_transactions(token, offset=None, limit=None):
method_url = 'getStarTransactions'
payload = {}
Expand Down
94 changes: 93 additions & 1 deletion telebot/async_telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3619,6 +3619,91 @@ async def copy_messages(self, chat_id: Union[str, int], from_chat_id: Union[str,
result = await asyncio_helper.copy_messages(self.token, chat_id, from_chat_id, message_ids, disable_notification, message_thread_id,
protect_content, remove_caption)
return [types.MessageID.de_json(message_id) for message_id in result]

async def send_checklist(
self, business_connection_id: str, chat_id: Union[int, str],
checklist: types.InputChecklist,
disable_notification: Optional[bool]=None,
protect_content: Optional[bool]=None,
message_effect_id: Optional[str]=None,
reply_parameters: Optional[types.ReplyParameters]=None,
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Message:
"""
Use this method to send a checklist on behalf of a connected business account. On success,
the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendchecklist

:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent
:type business_connection_id: :obj:`str`

:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`

:param checklist: A JSON-serialized object for the checklist to send
:type checklist: :class:`telebot.types.InputChecklist`

:param disable_notification: Sends the message silently. Users will receive a notification with no sound.
:type disable_notification: :obj:`bool`

:param protect_content: Protects the contents of the sent message from forwarding and saving
:type protect_content: :obj:`bool`

:param message_effect_id: Unique identifier of the message effect to be added to the message; for private chats only
:type message_effect_id: :obj:`str`

:param reply_parameters: Additional parameters for replies to messages
:type reply_parameters: :class:`telebot.types.ReplyParameters`

:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard.
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`

:return: On success, the sent Message is returned.
:rtype: :class:`telebot.types.Message`
"""
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
protect_content = self.protect_content if (protect_content is None) else protect_content

if reply_parameters and (reply_parameters.allow_sending_without_reply is None):
reply_parameters.allow_sending_without_reply = self.allow_sending_without_reply

return types.Message.de_json(
await asyncio_helper.send_checklist(
self.token, business_connection_id, chat_id, checklist, disable_notification=disable_notification,
protect_content=protect_content, message_effect_id=message_effect_id,
reply_parameters=reply_parameters, reply_markup=reply_markup))

async def edit_message_checklist(
self, business_connection_id: str, chat_id: Union[int, str],
message_id: int, checklist: types.InputChecklist,
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Message:
"""
Use this method to edit a checklist on behalf of a connected business account. On success,
the edited Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#editmessagechecklist

:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent
:type business_connection_id: :obj:`str`

:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`

:param message_id: Unique identifier for the target message
:type message_id: :obj:`int`

:param checklist: A JSON-serialized object for the new checklist
:type checklist: :class:`telebot.types.InputChecklist`

:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard.
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup`

:return: On success, the edited Message is returned.
:rtype: :class:`telebot.types.Message`
"""
return types.Message.de_json(
await asyncio_helper.edit_message_checklist(
self.token, business_connection_id, chat_id, message_id, checklist, reply_markup=reply_markup))

async def send_dice(
self, chat_id: Union[int, str],
Expand Down Expand Up @@ -7256,8 +7341,15 @@ async def answer_pre_checkout_query(
:rtype: :obj:`bool`
"""
return await asyncio_helper.answer_pre_checkout_query(self.token, pre_checkout_query_id, ok, error_message)



async def get_my_star_balance(self) -> types.StarAmount:
"""
A method to get the current Telegram Stars balance of the bot. Requires no parameters.
On success, returns a StarAmount object.
"""
return types.StarAmount.de_json(await asyncio_helper.get_my_star_balance(self.token))

async def get_star_transactions(self, offset: Optional[int]=None, limit: Optional[int]=None) -> types.StarTransactions:
"""
Returns the bot's Telegram Star transactions in chronological order.
Expand Down
34 changes: 34 additions & 0 deletions telebot/asyncio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,35 @@ async def copy_message(token, chat_id, from_chat_id, message_id, caption=None, p
payload['video_start_timestamp'] = video_start_timestamp
return await _process_request(token, method_url, params=payload)

async def send_checklist(
token, business_connection_id, chat_id, checklist,
disable_notification=None, protect_content=None, message_effect_id=None,
reply_parameters=None, reply_markup=None
):
method_url = r'sendChecklist'
payload = {'chat_id': chat_id, 'checklist': checklist, 'business_connection_id': business_connection_id}
if disable_notification is not None:
payload['disable_notification'] = disable_notification
if protect_content is not None:
payload['protect_content'] = protect_content
if message_effect_id:
payload['message_effect_id'] = message_effect_id
if reply_parameters:
payload['reply_parameters'] = reply_parameters.to_json()
if reply_markup:
payload['reply_markup'] = _convert_markup(reply_markup)
return await _process_request(token, method_url, params=payload)


async def edit_message_checklist(
token, business_connection_id, chat_id, message_id, checklist,
reply_markup=None
):
method_url = r'editMessageChecklist'
payload = {'chat_id': chat_id, 'message_id': message_id, 'checklist': checklist, 'business_connection_id': business_connection_id}
if reply_markup:
payload['reply_markup'] = await _convert_markup(reply_markup)
return await _process_request(token, method_url, params=payload)

async def send_dice(
token, chat_id,
Expand Down Expand Up @@ -1816,6 +1845,11 @@ async def answer_pre_checkout_query(token, pre_checkout_query_id, ok, error_mess
payload['error_message'] = error_message
return await _process_request(token, method_url, params=payload)


async def get_my_star_balance(token):
method_url = 'getMyStarBalance'
return await _process_request(token, method_url)

async def get_star_transactions(token, offset=None, limit=None):
method_url = 'getStarTransactions'
payload = {}
Expand Down
Loading