Skip to content

Commit

Permalink
API 6.2 (#3203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Poolitzer committed Sep 4, 2022
1 parent d0c1a95 commit dca596d
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 36 deletions.
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-6.1-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.2-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions

Expand Down Expand Up @@ -112,7 +112,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 **6.1** are supported.
All types and methods of the Telegram Bot API **6.2** 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-6.1-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.2-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 **6.1** are supported.
All types and methods of the Telegram Bot API **6.2** are supported.

==========
Installing
Expand Down
2 changes: 2 additions & 0 deletions docs/requirements-docs.txt
@@ -1,4 +1,6 @@
sphinx==3.5.4
# sphinx breaks because it relies on an removed param from jinja2, so pinning to old version
Jinja2<3.1
sphinx-pypi-upload
# When bumping this, make sure to rebuild the dark-mode CSS
# More instructions at source/_static/dark.css
Expand Down
51 changes: 48 additions & 3 deletions telegram/bot.py
Expand Up @@ -2429,8 +2429,8 @@ def get_file(
if result.get('file_path') and not is_local_file( # type: ignore[union-attr]
result['file_path'] # type: ignore[index]
):
result['file_path'] = '{}/{}'.format( # type: ignore[index]
self.base_file_url, result['file_path'] # type: ignore[index]
result['file_path'] = ( # type: ignore[index]
f"{self.base_file_url}/" f"{result['file_path']}" # type: ignore[index]
)

return File.de_json(result, self) # type: ignore[return-value, arg-type]
Expand Down Expand Up @@ -4813,6 +4813,37 @@ def get_sticker_set(

return StickerSet.de_json(result, self) # type: ignore[return-value, arg-type]

@log
def get_custom_emoji_stickers(
self,
custom_emoji_ids: List[str],
*,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> List[Sticker]:
"""
Use this method to get information about emoji stickers by their identifiers.
.. versionadded:: 13.14
Args:
custom_emoji_ids (List[:obj:`str`]): List of custom emoji identifiers.
At most 200 custom emoji identifiers can be specified.
Keyword Args:
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during
creation of the connection pool).
api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
Telegram API.
Returns:
List[:class:`telegram.Sticker`]
Raises:
:class:`telegram.error.TelegramError`
"""
data: JSONDict = {"custom_emoji_ids": custom_emoji_ids}
result = self._post("getCustomEmojiStickers", data, timeout=timeout, api_kwargs=api_kwargs)
return Sticker.de_list(result, self) # type: ignore[return-value, arg-type]

@log
def upload_sticker_file(
self,
Expand Down Expand Up @@ -4871,6 +4902,7 @@ def create_new_sticker_set(
tgs_sticker: FileInput = None,
api_kwargs: JSONDict = None,
webm_sticker: FileInput = None,
sticker_type: str = None,
) -> bool:
"""
Use this method to create new sticker set owned by a user.
Expand All @@ -4887,6 +4919,10 @@ def create_new_sticker_set(
The png_sticker and tgs_sticker argument can be either a file_id, an URL or a file from
disk ``open(filename, 'rb')``
.. versionchanged:: 13.14
The parameter ``contains_masks`` has been depreciated as of Bot API 6.2.
Use ``sticker_type`` instead.
Args:
user_id (:obj:`int`): User identifier of created sticker set owner.
name (:obj:`str`): Short name of sticker set, to be used in t.me/addstickers/ URLs
Expand Down Expand Up @@ -4924,6 +4960,12 @@ def create_new_sticker_set(
should be created.
mask_position (:class:`telegram.MaskPosition`, optional): Position where the mask
should be placed on faces.
sticker_type (:obj:`str`, optional): Type of stickers in the set, pass
:attr:`telegram.Sticker.REGULAR` or :attr:`telegram.Sticker.MASK`. Custom emoji
sticker sets can't be created via the Bot API at the moment. By default, a
regular sticker set is created.
.. versionadded:: 13.14
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during
creation of the connection pool).
Expand Down Expand Up @@ -4951,7 +4993,8 @@ def create_new_sticker_set(
# We need to_json() instead of to_dict() here, because we're sending a media
# message here, which isn't json dumped by utils.request
data['mask_position'] = mask_position.to_json()

if sticker_type is not None:
data['sticker_type'] = sticker_type
result = self._post('createNewStickerSet', data, timeout=timeout, api_kwargs=api_kwargs)

return result # type: ignore[return-value]
Expand Down Expand Up @@ -6206,6 +6249,8 @@ def __hash__(self) -> int:
"""Alias for :meth:`unpin_all_chat_messages`"""
getStickerSet = get_sticker_set
"""Alias for :meth:`get_sticker_set`"""
getCustomEmojiStickers = get_custom_emoji_stickers
"""Alias for :meth:`get_custom_emoji_stickers`"""
uploadStickerFile = upload_sticker_file
"""Alias for :meth:`upload_sticker_file`"""
createNewStickerSet = create_new_sticker_set
Expand Down
13 changes: 13 additions & 0 deletions telegram/chat.py
Expand Up @@ -126,6 +126,11 @@ class Chat(TelegramObject):
:meth:`telegram.Bot.get_chat`.
.. versionadded:: 13.13
has_restricted_voice_and_video_messages (:obj:`bool`, optional): :obj:`True`, if the
privacy settings of the other party restrict sending voice and video note messages
in the private chat. Returned only in :meth:`telegram.Bot.get_chat`.
.. versionadded:: 13.14
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Attributes:
Expand Down Expand Up @@ -180,6 +185,11 @@ class Chat(TelegramObject):
:meth:`telegram.Bot.get_chat`.
.. versionadded:: 13.13
has_restricted_voice_and_video_messages (:obj:`bool`): Optional. :obj:`True`, if the
privacy settings of the other party restrict sending voice and video note messages
in the private chat. Returned only in :meth:`telegram.Bot.get_chat`.
.. versionadded:: 13.14
"""

__slots__ = (
Expand Down Expand Up @@ -207,6 +217,7 @@ class Chat(TelegramObject):
'has_private_forwards',
'join_to_send_messages',
'join_by_request',
'has_restricted_voice_and_video_messages',
'_id_attrs',
)

Expand Down Expand Up @@ -249,6 +260,7 @@ def __init__(
has_protected_content: bool = None,
join_to_send_messages: bool = None,
join_by_request: bool = None,
has_restricted_voice_and_video_messages: bool = None,
**_kwargs: Any,
):
# Required
Expand Down Expand Up @@ -279,6 +291,7 @@ def __init__(
self.location = location
self.join_to_send_messages = join_to_send_messages
self.join_by_request = join_by_request
self.has_restricted_voice_and_video_messages = has_restricted_voice_and_video_messages

self.bot = bot
self._id_attrs = (self.id,)
Expand Down
26 changes: 24 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`): `6.1`. Telegram Bot API version supported by this
BOT_API_VERSION (:obj:`str`): `6.2`. 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 @@ -144,6 +144,9 @@
MESSAGEENTITY_SPOILER (:obj:`str`): ``'spoiler'``
.. versionadded:: 13.10
MESSAGEENTITY_CUSTOM_EMOJI (:obj:`str`): ``'custom_emoji'``
.. versionadded:: 13.14
MESSAGEENTITY_ALL_TYPES (List[:obj:`str`]): List of all the types of message entity.
:class:`telegram.ParseMode`:
Expand All @@ -160,6 +163,19 @@
POLL_QUIZ (:obj:`str`): ``'quiz'``
MAX_POLL_QUESTION_LENGTH (:obj:`int`): 300
MAX_POLL_OPTION_LENGTH (:obj:`int`): 100
:class:`telegram.Sticker`:
Attributes:
STICKER_REGULAR (:obj:`str`)= ``'regular'``
.. versionadded:: 13.14
STICKER_MASK (:obj:`str`) = ``'mask'``
.. versionadded:: 13.14
STICKER_CUSTOM_EMOJI (:obj:`str`) = ``'custom_emoji'``
.. versionadded:: 13.14
:class:`telegram.MaskPosition`:
Expand Down Expand Up @@ -247,7 +263,7 @@
"""
from typing import List

BOT_API_VERSION: str = '6.1'
BOT_API_VERSION: str = '6.2'
MAX_MESSAGE_LENGTH: int = 4096
MAX_CAPTION_LENGTH: int = 1024
ANONYMOUS_ADMIN_ID: int = 1087968824
Expand Down Expand Up @@ -325,6 +341,7 @@
MESSAGEENTITY_UNDERLINE: str = 'underline'
MESSAGEENTITY_STRIKETHROUGH: str = 'strikethrough'
MESSAGEENTITY_SPOILER: str = 'spoiler'
MESSAGEENTITY_CUSTOM_EMOJI: str = 'custom_emoji'
MESSAGEENTITY_ALL_TYPES: List[str] = [
MESSAGEENTITY_MENTION,
MESSAGEENTITY_HASHTAG,
Expand All @@ -342,6 +359,7 @@
MESSAGEENTITY_UNDERLINE,
MESSAGEENTITY_STRIKETHROUGH,
MESSAGEENTITY_SPOILER,
MESSAGEENTITY_CUSTOM_EMOJI,
]

PARSEMODE_MARKDOWN: str = 'Markdown'
Expand All @@ -353,6 +371,10 @@
MAX_POLL_QUESTION_LENGTH: int = 300
MAX_POLL_OPTION_LENGTH: int = 100

STICKER_REGULAR: str = "regular"
STICKER_MASK: str = "mask"
STICKER_CUSTOM_EMOJI: str = "custom_emoji"

STICKER_FOREHEAD: str = 'forehead'
STICKER_EYES: str = 'eyes'
STICKER_MOUTH: str = 'mouth'
Expand Down
2 changes: 1 addition & 1 deletion telegram/error.py
Expand Up @@ -56,7 +56,7 @@ def __init__(self, message: str):
self.message = msg

def __str__(self) -> str:
return '%s' % self.message
return f'{self.message}'

def __reduce__(self) -> Tuple[type, Tuple[str]]:
return self.__class__, (self.message,)
Expand Down

0 comments on commit dca596d

Please sign in to comment.