Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot API 7.5 #2311

Merged
merged 7 commits into from
Jun 20, 2024
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
<p align="center">Both synchronous and asynchronous.</p>

## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api-changelog#may-28-2024">7.4</a>!
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#june-18-2024">7.5</a>!

<h2><a href='https://pytba.readthedocs.io/en/latest/index.html'>Official documentation</a></h2>
<h2><a href='https://pytba.readthedocs.io/ru/latest/index.html'>Official ru documentation</a></h2>
Expand Down
76 changes: 63 additions & 13 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3324,6 +3324,7 @@ def edit_message_live_location(
heading: Optional[int]=None,
proximity_alert_radius: Optional[int]=None,
live_period: Optional[int]=None,
business_connection_id: Optional[str]=None
) -> types.Message or bool:
"""
Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly
Expand Down Expand Up @@ -3366,14 +3367,17 @@ def edit_message_live_location(
:param live_period: New period in seconds during which the location can be updated, starting from the message send date. If 0x7FFFFFFF is specified, then the location can be updated forever. Otherwise, the new value must not exceed the current live_period by more than a day, and the live location expiration date must remain within the next 90 days. If not specified, then live_period remains unchanged
:type live_period: :obj:`int`

:param business_connection_id: Identifier of a business connection
:type business_connection_id: :obj:`str`

:return: On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
:rtype: :class:`telebot.types.Message` or bool
"""
return types.Message.de_json(
apihelper.edit_message_live_location(
self.token, latitude, longitude, chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id,
reply_markup=reply_markup, timeout=timeout, horizontal_accuracy=horizontal_accuracy, heading=heading,
proximity_alert_radius=proximity_alert_radius, live_period=live_period)
proximity_alert_radius=proximity_alert_radius, live_period=live_period, business_connection_id=business_connection_id)
)


Expand All @@ -3382,7 +3386,8 @@ def stop_message_live_location(
message_id: Optional[int]=None,
inline_message_id: Optional[str]=None,
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
timeout: Optional[int]=None) -> types.Message or bool:
timeout: Optional[int]=None,
business_connection_id: Optional[str]=None) -> types.Message or bool:
"""
Use this method to stop updating a live location message before live_period expires.
On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
Expand All @@ -3405,13 +3410,16 @@ def stop_message_live_location(
:param timeout: Timeout in seconds for the request.
:type timeout: :obj:`int`

:param business_connection_id: Identifier of a business connection
:type business_connection_id: :obj:`str`

:return: On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
:rtype: :class:`telebot.types.Message` or bool
"""
return types.Message.de_json(
apihelper.stop_message_live_location(
self.token, chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id,
reply_markup=reply_markup, timeout=timeout)
reply_markup=reply_markup, timeout=timeout, business_connection_id=business_connection_id)
)


Expand Down Expand Up @@ -4645,7 +4653,8 @@ def edit_message_text(
entities: Optional[List[types.MessageEntity]]=None,
disable_web_page_preview: Optional[bool]=None, # deprecated, for backward compatibility
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
link_preview_options : Optional[types.LinkPreviewOptions]=None) -> Union[types.Message, bool]:
link_preview_options : Optional[types.LinkPreviewOptions]=None,
business_connection_id: Optional[str]=None) -> Union[types.Message, bool]:
"""
Use this method to edit text and game messages.

Expand Down Expand Up @@ -4678,6 +4687,9 @@ def edit_message_text(
:param link_preview_options: A JSON-serialized object for options used to automatically generate previews for links.
:type link_preview_options: :obj:`LinkPreviewOptions`

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:return: On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
:rtype: :obj:`types.Message` or :obj:`bool`
"""
Expand All @@ -4704,7 +4716,8 @@ def edit_message_text(

result = apihelper.edit_message_text(
self.token, text, chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id,
parse_mode=parse_mode, entities=entities, reply_markup=reply_markup, link_preview_options=link_preview_options)
parse_mode=parse_mode, entities=entities, reply_markup=reply_markup, link_preview_options=link_preview_options,
business_connection_id=business_connection_id)

if type(result) == bool: # if edit inline message return is bool not Message.
return result
Expand All @@ -4715,7 +4728,8 @@ def edit_message_media(
self, media: Any, chat_id: Optional[Union[int, str]]=None,
message_id: Optional[int]=None,
inline_message_id: Optional[str]=None,
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> Union[types.Message, bool]:
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
business_connection_id: Optional[str]=None) -> Union[types.Message, bool]:
"""
Use this method to edit animation, audio, document, photo, or video messages.
If a message is a part of a message album, then it can be edited only to a photo or a video.
Expand All @@ -4738,12 +4752,15 @@ def edit_message_media(
:param reply_markup: A JSON-serialized object for an inline keyboard.
:type reply_markup: :obj:`telebot.types.InlineKeyboardMarkup` or :obj:`ReplyKeyboardMarkup` or :obj:`ReplyKeyboardRemove` or :obj:`ForceReply`

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:return: On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
:rtype: :obj:`types.Message` or :obj:`bool`
"""
result = apihelper.edit_message_media(
self.token, media, chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id,
reply_markup=reply_markup)
reply_markup=reply_markup, business_connection_id=business_connection_id)

if type(result) == bool: # if edit inline message return is bool not Message.
return result
Expand All @@ -4754,7 +4771,8 @@ def edit_message_reply_markup(
self, chat_id: Optional[Union[int, str]]=None,
message_id: Optional[int]=None,
inline_message_id: Optional[str]=None,
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> Union[types.Message, bool]:
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
business_connection_id: Optional[str]=None) -> Union[types.Message, bool]:
"""
Use this method to edit only the reply markup of messages.

Expand All @@ -4772,12 +4790,15 @@ def edit_message_reply_markup(
:param reply_markup: A JSON-serialized object for an inline keyboard.
:type reply_markup: :obj:`InlineKeyboardMarkup` or :obj:`ReplyKeyboardMarkup` or :obj:`ReplyKeyboardRemove` or :obj:`ForceReply`

:param business_connection_id: Unique identifier of the business connection
:type business_connection_id: :obj:`str`

:return: On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
:rtype: :obj:`types.Message` or :obj:`bool`
"""
result = apihelper.edit_message_reply_markup(
self.token, chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id,
reply_markup=reply_markup)
reply_markup=reply_markup, business_connection_id=business_connection_id)

if type(result) == bool:
return result
Expand Down Expand Up @@ -5397,7 +5418,8 @@ def send_poll(

def stop_poll(
self, chat_id: Union[int, str], message_id: int,
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Poll:
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
business_connection_id: Optional[str]=None) -> types.Poll:
"""
Use this method to stop a poll which was sent by the bot. On success, the stopped Poll is returned.

Expand All @@ -5412,11 +5434,14 @@ def stop_poll(
:param reply_markup: A JSON-serialized object for a new message markup.
:type reply_markup: :obj:`InlineKeyboardMarkup`

:param business_connection_id: Identifier of the business connection to use for the poll
:type business_connection_id: :obj:`str`

:return: On success, the stopped Poll is returned.
:rtype: :obj:`types.Poll`
"""
return types.Poll.de_json(
apihelper.stop_poll(self.token, chat_id, message_id, reply_markup=reply_markup)
apihelper.stop_poll(self.token, chat_id, message_id, reply_markup=reply_markup, business_connection_id=business_connection_id)
)


Expand Down Expand Up @@ -5478,6 +5503,27 @@ def answer_pre_checkout_query(
"""
return apihelper.answer_pre_checkout_query(
self.token, pre_checkout_query_id, ok, error_message=error_message)


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. On success, returns a StarTransactions object.

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

:param offset: Number of transactions to skip in the response
:type offset: :obj:`int`

:param limit: The maximum number of transactions to be retrieved. Values between 1-100 are accepted. Defaults to 100.
:type limit: :obj:`int`

:return: On success, returns a StarTransactions object.
:rtype: :obj:`types.StarTransactions`
"""
return types.StarTransactions.de_json(
apihelper.get_star_transactions(self.token, offset=offset, limit=limit)
)


def refund_star_payment(self, user_id: int, telegram_payment_charge_id: str) -> bool:
"""
Expand All @@ -5503,7 +5549,8 @@ def edit_message_caption(
parse_mode: Optional[str]=None,
caption_entities: Optional[List[types.MessageEntity]]=None,
reply_markup: Optional[types.InlineKeyboardMarkup]=None,
show_caption_above_media: Optional[bool]=None) -> Union[types.Message, bool]:
show_caption_above_media: Optional[bool]=None,
business_connection_id: Optional[str]=None) -> Union[types.Message, bool]:
"""
Use this method to edit captions of messages.

Expand Down Expand Up @@ -5533,6 +5580,9 @@ def edit_message_caption(
:param show_caption_above_media: Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.
:type show_caption_above_media: :obj:`bool`

:param business_connection_id: Identifier of the business connection to use for the message
:type business_connection_id: :obj:`str`

:return: On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
:rtype: :obj:`types.Message` | :obj:`bool`
"""
Expand All @@ -5541,7 +5591,7 @@ def edit_message_caption(
result = apihelper.edit_message_caption(
self.token, caption, chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id,
parse_mode=parse_mode, caption_entities=caption_entities, reply_markup=reply_markup,
show_caption_above_media=show_caption_above_media)
show_caption_above_media=show_caption_above_media, business_connection_id=business_connection_id)

if type(result) == bool:
return result
Expand Down
38 changes: 31 additions & 7 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def send_location(

def edit_message_live_location(
token, latitude, longitude, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None,
timeout=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, live_period=None):
timeout=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, live_period=None, business_connection_id=None):
method_url = r'editMessageLiveLocation'
payload = {'latitude': latitude, 'longitude': longitude}
if chat_id:
Expand All @@ -615,12 +615,14 @@ def edit_message_live_location(
payload['reply_markup'] = _convert_markup(reply_markup)
if timeout:
payload['timeout'] = timeout
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload)


def stop_message_live_location(
token, chat_id=None, message_id=None,
inline_message_id=None, reply_markup=None, timeout=None):
inline_message_id=None, reply_markup=None, timeout=None, business_connection_id=None):
method_url = r'stopMessageLiveLocation'
payload = {}
if chat_id:
Expand All @@ -633,6 +635,8 @@ def stop_message_live_location(
payload['reply_markup'] = _convert_markup(reply_markup)
if timeout:
payload['timeout'] = timeout
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload)


Expand Down Expand Up @@ -1379,7 +1383,7 @@ def unpin_all_chat_messages(token, chat_id):
# Updating messages

def edit_message_text(token, text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None,
entities = None, reply_markup=None, link_preview_options=None):
entities = None, reply_markup=None, link_preview_options=None, business_connection_id=None):
method_url = r'editMessageText'
payload = {'text': text}
if chat_id:
Expand All @@ -1396,11 +1400,13 @@ def edit_message_text(token, text, chat_id=None, message_id=None, inline_message
payload['reply_markup'] = _convert_markup(reply_markup)
if link_preview_options is not None:
payload['link_preview_options'] = link_preview_options.to_json()
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload, method='post')


def edit_message_caption(token, caption, chat_id=None, message_id=None, inline_message_id=None,
parse_mode=None, caption_entities=None,reply_markup=None, show_caption_above_media=None):
parse_mode=None, caption_entities=None,reply_markup=None, show_caption_above_media=None, business_connection_id=None):
method_url = r'editMessageCaption'
payload = {'caption': caption}
if chat_id:
Expand All @@ -1417,10 +1423,12 @@ def edit_message_caption(token, caption, chat_id=None, message_id=None, inline_m
payload['reply_markup'] = _convert_markup(reply_markup)
if show_caption_above_media is not None:
payload['show_caption_above_media'] = show_caption_above_media
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload, method='post')


def edit_message_media(token, media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None):
def edit_message_media(token, media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None):
method_url = r'editMessageMedia'
media_json, file = convert_input_media(media)
payload = {'media': media_json}
Expand All @@ -1432,10 +1440,12 @@ def edit_message_media(token, media, chat_id=None, message_id=None, inline_messa
payload['inline_message_id'] = inline_message_id
if reply_markup:
payload['reply_markup'] = _convert_markup(reply_markup)
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload, files=file, method='post' if file else 'get')


def edit_message_reply_markup(token, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None):
def edit_message_reply_markup(token, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None):
method_url = r'editMessageReplyMarkup'
payload = {}
if chat_id:
Expand All @@ -1446,6 +1456,8 @@ def edit_message_reply_markup(token, chat_id=None, message_id=None, inline_messa
payload['inline_message_id'] = inline_message_id
if reply_markup:
payload['reply_markup'] = _convert_markup(reply_markup)
if business_connection_id:
payload['business_connection_id'] = business_connection_id
return _make_request(token, method_url, params=payload, method='post')


Expand Down Expand Up @@ -1667,6 +1679,16 @@ 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_star_transactions(token, offset=None, limit=None):
method_url = 'getStarTransactions'
payload = {}
if offset:
payload['offset'] = offset
if limit:
payload['limit'] = limit
return _make_request(token, method_url, params=payload)


def refund_star_payment(token, user_id, telegram_payment_charge_id):
method_url = 'refundStarPayment'
payload = {'user_id': user_id, 'telegram_payment_charge_id': telegram_payment_charge_id}
Expand Down Expand Up @@ -1975,11 +1997,13 @@ def get_forum_topic_icon_stickers(token):
method_url = r'getForumTopicIconStickers'
return _make_request(token, method_url)

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

def edit_general_forum_topic(token, chat_id, name):
Expand Down
Loading
Loading