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

API 5.6 #2835

Merged
merged 8 commits into from Jan 3, 2022
Merged

API 5.6 #2835

Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -20,7 +20,7 @@ We have a vibrant community of developers helping each other in our `Telegram gr
:target: https://pypi.org/project/python-telegram-bot/
:alt: Supported Python versions

.. image:: https://img.shields.io/badge/Bot%20API-5.5-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-5.6-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions

Expand Down Expand Up @@ -111,7 +111,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================

All types and methods of the Telegram Bot API **5.5** are supported.
All types and methods of the Telegram Bot API **5.6** are supported.

==========
Installing
Expand Down
4 changes: 2 additions & 2 deletions README_RAW.rst
Expand Up @@ -20,7 +20,7 @@ We have a vibrant community of developers helping each other in our `Telegram gr
:target: https://pypi.org/project/python-telegram-bot-raw/
:alt: Supported Python versions

.. image:: https://img.shields.io/badge/Bot%20API-5.5-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-5.6-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions

Expand Down Expand Up @@ -105,7 +105,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================

All types and methods of the Telegram Bot API **5.5** are supported.
All types and methods of the Telegram Bot API **5.6** are supported.

==========
Installing
Expand Down
60 changes: 21 additions & 39 deletions telegram/bot.py
Expand Up @@ -306,10 +306,14 @@ def _message(
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
protect_content: bool = None,
) -> Union[bool, Message]:
if reply_to_message_id is not None:
data['reply_to_message_id'] = reply_to_message_id

if protect_content:
data['protect_content'] = protect_content

# We don't check if (DEFAULT_)None here, so that _put is able to insert the defaults
# correctly, if necessary
data['disable_notification'] = disable_notification
Expand Down Expand Up @@ -515,9 +519,6 @@ def send_message(
if entities:
data['entities'] = [me.to_dict() for me in entities]

if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendMessage',
data,
Expand All @@ -527,6 +528,7 @@ def send_message(
allow_sending_without_reply=allow_sending_without_reply,
timeout=timeout,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -630,14 +632,13 @@ def forward_message(
data['from_chat_id'] = from_chat_id
if message_id:
data['message_id'] = message_id
if protect_content:
data['protect_content'] = protect_content
return self._message( # type: ignore[return-value]
'forwardMessage',
data,
disable_notification=disable_notification,
timeout=timeout,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -725,9 +726,6 @@ def send_photo(
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]

if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendPhoto',
data,
Expand All @@ -737,6 +735,7 @@ def send_photo(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -854,8 +853,6 @@ def send_audio(
data['caption_entities'] = [me.to_dict() for me in caption_entities]
if thumb:
data['thumb'] = parse_file_input(thumb, attach=True)
if protect_content:
data['protect_content'] = None

return self._message( # type: ignore[return-value]
'sendAudio',
Expand All @@ -866,6 +863,7 @@ def send_audio(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -971,8 +969,6 @@ def send_document(
data['disable_content_type_detection'] = disable_content_type_detection
if thumb:
data['thumb'] = parse_file_input(thumb, attach=True)
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendDocument',
Expand All @@ -983,6 +979,7 @@ def send_document(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -1044,9 +1041,6 @@ def send_sticker(
"""
data: JSONDict = {'chat_id': chat_id, 'sticker': parse_file_input(sticker, Sticker)}

if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendSticker',
data,
Expand All @@ -1056,6 +1050,7 @@ def send_sticker(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -1178,8 +1173,6 @@ def send_video(
data['height'] = height
if thumb:
data['thumb'] = parse_file_input(thumb, attach=True)
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendVideo',
Expand All @@ -1190,6 +1183,7 @@ def send_video(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -1285,8 +1279,6 @@ def send_video_note(
data['length'] = length
if thumb:
data['thumb'] = parse_file_input(thumb, attach=True)
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendVideoNote',
Expand All @@ -1297,6 +1289,7 @@ def send_video_note(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -1410,8 +1403,6 @@ def send_animation(
data['caption'] = caption
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendAnimation',
Expand All @@ -1422,6 +1413,7 @@ def send_animation(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -1517,9 +1509,6 @@ def send_voice(
if caption_entities:
data['caption_entities'] = [me.to_dict() for me in caption_entities]

if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendVoice',
data,
Expand All @@ -1529,6 +1518,7 @@ def send_voice(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -1688,8 +1678,6 @@ def send_location(
data['heading'] = heading
if proximity_alert_radius:
data['proximity_alert_radius'] = proximity_alert_radius
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendLocation',
Expand All @@ -1700,6 +1688,7 @@ def send_location(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -1947,8 +1936,6 @@ def send_venue(
data['google_place_id'] = google_place_id
if google_place_type:
data['google_place_type'] = google_place_type
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendVenue',
Expand All @@ -1959,6 +1946,7 @@ def send_venue(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -2041,8 +2029,6 @@ def send_contact(
data['last_name'] = last_name
if vcard:
data['vcard'] = vcard
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendContact',
Expand All @@ -2053,6 +2039,7 @@ def send_contact(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -2103,9 +2090,6 @@ def send_game(
"""
data: JSONDict = {'chat_id': chat_id, 'game_short_name': game_short_name}

if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendGame',
data,
Expand All @@ -2115,6 +2099,7 @@ def send_game(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -3771,8 +3756,6 @@ def send_invoice(
data['send_phone_number_to_provider'] = send_phone_number_to_provider
if send_email_to_provider is not None:
data['send_email_to_provider'] = send_email_to_provider
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendInvoice',
Expand All @@ -3783,6 +3766,7 @@ def send_invoice(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -5246,8 +5230,6 @@ def send_poll(
close_date, tzinfo=self.defaults.tzinfo if self.defaults else None
)
data['close_date'] = close_date
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendPoll',
Expand All @@ -5258,6 +5240,7 @@ def send_poll(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down Expand Up @@ -5363,8 +5346,6 @@ def send_dice(

if emoji:
data['emoji'] = emoji
if protect_content:
data['protect_content'] = protect_content

return self._message( # type: ignore[return-value]
'sendDice',
Expand All @@ -5375,6 +5356,7 @@ def send_dice(
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
api_kwargs=api_kwargs,
protect_content=protect_content,
)

@log
Expand Down
7 changes: 5 additions & 2 deletions telegram/constants.py
Expand Up @@ -21,7 +21,7 @@
`Telegram Bots API <https://core.telegram.org/bots/api>`_.

Attributes:
BOT_API_VERSION (:obj:`str`): `5.5`. Telegram Bot API version supported by this
BOT_API_VERSION (:obj:`str`): `5.6`. Telegram Bot API version supported by this
version of `python-telegram-bot`. Also available as ``telegram.bot_api_version``.

.. versionadded:: 13.4
Expand Down Expand Up @@ -141,6 +141,9 @@
MESSAGEENTITY_TEXT_MENTION (:obj:`str`): ``'text_mention'``
MESSAGEENTITY_UNDERLINE (:obj:`str`): ``'underline'``
MESSAGEENTITY_STRIKETHROUGH (:obj:`str`): ``'strikethrough'``
MESSAGEENTITY_SPOILER (:obj:`str`): ``'spoiler'``

.. versionadded:: 13.10
MESSAGEENTITY_ALL_TYPES (List[:obj:`str`]): List of all the types of message entity.

:class:`telegram.ParseMode`:
Expand Down Expand Up @@ -244,7 +247,7 @@
"""
from typing import List

BOT_API_VERSION: str = '5.5'
BOT_API_VERSION: str = '5.6'
MAX_MESSAGE_LENGTH: int = 4096
MAX_CAPTION_LENGTH: int = 1024
ANONYMOUS_ADMIN_ID: int = 1087968824
Expand Down
2 changes: 2 additions & 0 deletions telegram/ext/extbot.py
Expand Up @@ -193,6 +193,7 @@ def _message(
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
protect_content: bool = None,
) -> Union[bool, Message]:
# We override this method to call self._replace_keyboard and self._insert_callback_data.
# This covers most methods that have a reply_markup
Expand All @@ -205,6 +206,7 @@ def _message(
allow_sending_without_reply=allow_sending_without_reply,
timeout=timeout,
api_kwargs=api_kwargs,
protect_content=protect_content,
)
if isinstance(result, Message):
self._insert_callback_data(result)
Expand Down