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.7 #2881

Merged
merged 3 commits into from Feb 2, 2022
Merged

API 5.7 #2881

Show file tree
Hide file tree
Changes from all 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.6-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-5.7-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.6** are supported.
All types and methods of the Telegram Bot API **5.7** 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.6-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-5.7-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.6** are supported.
All types and methods of the Telegram Bot API **5.7** are supported.

==========
Installing
Expand Down
70 changes: 46 additions & 24 deletions telegram/bot.py
Expand Up @@ -996,7 +996,7 @@ def send_sticker(
protect_content: bool = None,
) -> Message:
"""
Use this method to send static .WEBP or animated .TGS stickers.
Use this method to send static ``.WEBP``, animated ``.TGS``, or video ``.WEBM`` stickers.

Note:
The sticker argument can be either a file_id, an URL or a file from disk
Expand Down Expand Up @@ -4753,7 +4753,7 @@ def upload_sticker_file(
api_kwargs: JSONDict = None,
) -> File:
"""
Use this method to upload a .png file with a sticker for later use in
Use this method to upload a ``.PNG`` file with a sticker for later use in
:meth:`create_new_sticker_set` and :meth:`add_sticker_to_set` methods (can be used multiple
times).

Expand All @@ -4764,9 +4764,8 @@ def upload_sticker_file(
Args:
user_id (:obj:`int`): User identifier of sticker file owner.
png_sticker (:obj:`str` | `filelike object` | :obj:`bytes` | :class:`pathlib.Path`):
Png image with the sticker,
must be up to 512 kilobytes in size, dimensions must not exceed 512px,
and either width or height must be exactly 512px.
**PNG** image with the sticker, must be up to 512 kilobytes in size,
dimensions must not exceed 512px, and either width or height must be exactly 512px.

.. versionchanged:: 13.2
Accept :obj:`bytes` as input.
Expand Down Expand Up @@ -4802,11 +4801,13 @@ def create_new_sticker_set(
timeout: DVInput[float] = DEFAULT_20,
tgs_sticker: FileInput = None,
api_kwargs: JSONDict = None,
webm_sticker: FileInput = None,
) -> bool:
"""
Use this method to create new sticker set owned by a user.
The bot will be able to edit the created sticker set.
You must use exactly one of the fields ``png_sticker`` or ``tgs_sticker``.
You must use exactly one of the fields ``png_sticker``, ``tgs_sticker``, or
``webm_sticker``.

Warning:
As of API 4.7 ``png_sticker`` is an optional argument and therefore the order of the
Expand All @@ -4826,7 +4827,7 @@ def create_new_sticker_set(
1-64 characters.
title (:obj:`str`): Sticker set title, 1-64 characters.
png_sticker (:obj:`str` | `filelike object` | :obj:`bytes` | :class:`pathlib.Path`, \
optional): Png image with the sticker,
optional): **PNG** image with the sticker,
must be up to 512 kilobytes in size, dimensions must not exceed 512px,
and either width or height must be exactly 512px. Pass a file_id as a String to
send a file that already exists on the Telegram servers, pass an HTTP URL as a
Expand All @@ -4836,13 +4837,19 @@ def create_new_sticker_set(
.. versionchanged:: 13.2
Accept :obj:`bytes` as input.
tgs_sticker (:obj:`str` | `filelike object` | :obj:`bytes` | :class:`pathlib.Path`, \
optional): TGS animation with the sticker,
uploaded using multipart/form-data. See
https://core.telegram.org/animated_stickers#technical-requirements for technical
optional): **TGS** animation with the sticker, uploaded using multipart/form-data.
See https://core.telegram.org/stickers#animated-sticker-requirements for technical
requirements.

.. versionchanged:: 13.2
Accept :obj:`bytes` as input.
webm_sticker (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path`,\
optional): **WEBM** video with the sticker, uploaded using multipart/form-data.
See https://core.telegram.org/stickers#video-sticker-requirements for
technical requirements.

.. versionadded:: 13.11

emojis (:obj:`str`): One or more emoji corresponding to the sticker.
contains_masks (:obj:`bool`, optional): Pass :obj:`True`, if a set of mask stickers
should be created.
Expand All @@ -4867,6 +4874,8 @@ def create_new_sticker_set(
data['png_sticker'] = parse_file_input(png_sticker)
if tgs_sticker is not None:
data['tgs_sticker'] = parse_file_input(tgs_sticker)
if webm_sticker is not None:
data['webm_sticker'] = parse_file_input(webm_sticker)
if contains_masks is not None:
data['contains_masks'] = contains_masks
if mask_position is not None:
Expand All @@ -4889,12 +4898,14 @@ def add_sticker_to_set(
timeout: DVInput[float] = DEFAULT_20,
tgs_sticker: FileInput = None,
api_kwargs: JSONDict = None,
webm_sticker: FileInput = None,
) -> bool:
"""
Use this method to add a new sticker to a set created by the bot.
You must use exactly one of the fields ``png_sticker`` or ``tgs_sticker``. Animated
stickers can be added to animated sticker sets and only to them. Animated sticker sets can
have up to 50 stickers. Static sticker sets can have up to 120 stickers.
You **must** use exactly one of the fields ``png_sticker``, ``tgs_sticker`` or
``webm_sticker``. Animated stickers can be added to animated sticker sets and only to them.
Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120
stickers.

Warning:
As of API 4.7 ``png_sticker`` is an optional argument and therefore the order of the
Expand All @@ -4910,7 +4921,7 @@ def add_sticker_to_set(

name (:obj:`str`): Sticker set name.
png_sticker (:obj:`str` | `filelike object` | :obj:`bytes` | :class:`pathlib.Path`, \
optional): PNG image with the sticker,
optional): **PNG** image with the sticker,
must be up to 512 kilobytes in size, dimensions must not exceed 512px,
and either width or height must be exactly 512px. Pass a file_id as a String to
send a file that already exists on the Telegram servers, pass an HTTP URL as a
Expand All @@ -4920,13 +4931,18 @@ def add_sticker_to_set(
.. versionchanged:: 13.2
Accept :obj:`bytes` as input.
tgs_sticker (:obj:`str` | `filelike object` | :obj:`bytes` | :class:`pathlib.Path`, \
optional): TGS animation with the sticker,
uploaded using multipart/form-data. See
https://core.telegram.org/animated_stickers#technical-requirements for technical
optional): **TGS** animation with the sticker, uploaded using multipart/form-data.
See https://core.telegram.org/stickers#animated-sticker-requirements for technical
requirements.

.. versionchanged:: 13.2
Accept :obj:`bytes` as input.
webm_sticker (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path`,\
optional): **WEBM** video with the sticker, uploaded using multipart/form-data.
See https://core.telegram.org/stickers#video-sticker-requirements for
technical requirements.

.. versionadded:: 13.11
emojis (:obj:`str`): One or more emoji corresponding to the sticker.
mask_position (:class:`telegram.MaskPosition`, optional): Position where the mask
should be placed on faces.
Expand All @@ -4949,6 +4965,8 @@ def add_sticker_to_set(
data['png_sticker'] = parse_file_input(png_sticker)
if tgs_sticker is not None:
data['tgs_sticker'] = parse_file_input(tgs_sticker)
if webm_sticker is not None:
data['webm_sticker'] = parse_file_input(webm_sticker)
if mask_position is not None:
# 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
Expand Down Expand Up @@ -5032,7 +5050,8 @@ def set_sticker_set_thumb(
api_kwargs: JSONDict = None,
) -> bool:
"""Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set
for animated sticker sets only.
for animated sticker sets only. Video thumbnails can be set only for video sticker sets
only.

Note:
The thumb can be either a file_id, an URL or a file from disk ``open(filename, 'rb')``
Expand All @@ -5041,14 +5060,17 @@ def set_sticker_set_thumb(
name (:obj:`str`): Sticker set name
user_id (:obj:`int`): User identifier of created sticker set owner.
thumb (:obj:`str` | `filelike object` | :obj:`bytes` | :class:`pathlib.Path`, \
optional): A PNG image with the thumbnail, must
be up to 128 kilobytes in size and have width and height exactly 100px, or a TGS
animation with the thumbnail up to 32 kilobytes in size; see
https://core.telegram.org/animated_stickers#technical-requirements for animated
sticker technical requirements. Pass a file_id as a String to send a file that
optional): A **PNG** image with the thumbnail, must
be up to 128 kilobytes in size and have width and height exactly 100px, or a
**TGS** animation with the thumbnail up to 32 kilobytes in size; see
https://core.telegram.org/stickers#animated-sticker-requirements for animated
sticker technical requirements, or a **WEBM** video with the thumbnail up to 32
kilobytes in size; see
https://core.telegram.org/stickers#video-sticker-requirements for video sticker
technical requirements. Pass a file_id as a String to send a file that
already exists on the Telegram servers, pass an HTTP URL as a String for Telegram
to get a file from the Internet, or upload a new one using multipart/form-data.
Animated sticker set thumbnail can't be uploaded via HTTP URL.
Animated sticker set thumbnails can't be uploaded via HTTP URL.

.. versionchanged:: 13.2
Accept :obj:`bytes` as input.
Expand Down
4 changes: 2 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.6`. Telegram Bot API version supported by this
BOT_API_VERSION (:obj:`str`): `5.7`. 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 @@ -247,7 +247,7 @@
"""
from typing import List

BOT_API_VERSION: str = '5.6'
BOT_API_VERSION: str = '5.7'
MAX_MESSAGE_LENGTH: int = 4096
MAX_CAPTION_LENGTH: int = 1024
ANONYMOUS_ADMIN_ID: int = 1087968824
Expand Down
40 changes: 34 additions & 6 deletions telegram/files/sticker.py
Expand Up @@ -34,6 +34,11 @@ class Sticker(TelegramObject):
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`file_unique_id` is equal.

Note:
As of v13.11 ``is_video`` is a required argument and therefore the order of the
arguments had to be changed. Use keyword arguments to make sure that the arguments are
passed correctly.

Args:
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
Expand All @@ -43,6 +48,9 @@ class Sticker(TelegramObject):
width (:obj:`int`): Sticker width.
height (:obj:`int`): Sticker height.
is_animated (:obj:`bool`): :obj:`True`, if the sticker is animated.
is_video (:obj:`bool`): :obj:`True`, if the sticker is a video sticker.

.. versionadded:: 13.11
thumb (:class:`telegram.PhotoSize`, optional): Sticker thumbnail in the .WEBP or .JPG
format.
emoji (:obj:`str`, optional): Emoji associated with the sticker
Expand All @@ -62,6 +70,9 @@ class Sticker(TelegramObject):
width (:obj:`int`): Sticker width.
height (:obj:`int`): Sticker height.
is_animated (:obj:`bool`): :obj:`True`, if the sticker is animated.
is_video (:obj:`bool`): :obj:`True`, if the sticker is a video sticker.

.. versionadded:: 13.11
thumb (:class:`telegram.PhotoSize`): Optional. Sticker thumbnail in the .webp or .jpg
format.
emoji (:obj:`str`): Optional. Emoji associated with the sticker.
Expand All @@ -78,6 +89,7 @@ class Sticker(TelegramObject):
'width',
'file_id',
'is_animated',
'is_video',
'file_size',
'thumb',
'set_name',
Expand All @@ -95,6 +107,7 @@ def __init__(
width: int,
height: int,
is_animated: bool,
is_video: bool,
thumb: PhotoSize = None,
emoji: str = None,
file_size: int = None,
Expand All @@ -109,6 +122,7 @@ def __init__(
self.width = int(width)
self.height = int(height)
self.is_animated = is_animated
self.is_video = is_video
# Optionals
self.thumb = thumb
self.emoji = emoji
Expand Down Expand Up @@ -155,28 +169,40 @@ class StickerSet(TelegramObject):
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`name` is equal.

Attributes:
Note:
As of v13.11 ``is_video`` is a required argument and therefore the order of the
arguments had to be changed. Use keyword arguments to make sure that the arguments are
passed correctly.

Args:
name (:obj:`str`): Sticker set name.
title (:obj:`str`): Sticker set title.
is_animated (:obj:`bool`): :obj:`True`, if the sticker set contains animated stickers.
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.

.. versionadded:: 13.11
contains_masks (:obj:`bool`): :obj:`True`, if the sticker set contains masks.
stickers (List[:class:`telegram.Sticker`]): List of all set stickers.
thumb (:class:`telegram.PhotoSize`): Optional. Sticker set thumbnail in the .WEBP or .TGS
format.
thumb (:class:`telegram.PhotoSize`, optional): Sticker set thumbnail in the ``.WEBP``,
``.TGS``, or ``.WEBM`` format.

Args:
Attributes:
name (:obj:`str`): Sticker set name.
title (:obj:`str`): Sticker set title.
is_animated (:obj:`bool`): :obj:`True`, if the sticker set contains animated stickers.
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.

.. versionadded:: 13.11
contains_masks (:obj:`bool`): :obj:`True`, if the sticker set contains masks.
stickers (List[:class:`telegram.Sticker`]): List of all set stickers.
thumb (:class:`telegram.PhotoSize`, optional): Sticker set thumbnail in the .WEBP or .TGS
format.
thumb (:class:`telegram.PhotoSize`): Optional. Sticker set thumbnail in the ``.WEBP``,
``.TGS`` or ``.WEBM`` format.

"""

__slots__ = (
'is_animated',
'is_video',
'contains_masks',
'thumb',
'title',
Expand All @@ -192,12 +218,14 @@ def __init__(
is_animated: bool,
contains_masks: bool,
stickers: List[Sticker],
is_video: bool,
thumb: PhotoSize = None,
**_kwargs: Any,
):
self.name = name
self.title = title
self.is_animated = is_animated
self.is_video = is_video
self.contains_masks = contains_masks
self.stickers = stickers
# Optionals
Expand Down
Binary file added tests/data/telegram_video_sticker.webm
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_bot.py
Expand Up @@ -1429,11 +1429,11 @@ def test_get_chat_member(self, bot, channel_id, chat_id):
assert chat_member.user.first_name == 'PTB'
assert chat_member.user.last_name == 'Test user'

@pytest.mark.skip(reason="Not implemented yet.")
@pytest.mark.skip(reason="Not implemented since we need a supergroup with many members")
def test_set_chat_sticker_set(self):
pass

@pytest.mark.skip(reason="Not implemented yet.")
@pytest.mark.skip(reason="Not implemented since we need a supergroup with many members")
def test_delete_chat_sticker_set(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Expand Up @@ -272,7 +272,7 @@ def build_test_message(**kwargs):
test_message.text = None

test_message = build_test_message(
sticker=Sticker('sticker_id', 'unique_id', 50, 50, False)
sticker=Sticker('sticker_id', 'unique_id', 50, 50, False, False)
)
assert helpers.effective_message_type(test_message) == 'sticker'
test_message.sticker = None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_message.py
Expand Up @@ -105,7 +105,7 @@ def message(bot):
)
},
{'photo': [PhotoSize('photo_id', 'unique_id', 50, 50)], 'caption': 'photo_file'},
{'sticker': Sticker('sticker_id', 'unique_id', 50, 50, True)},
{'sticker': Sticker('sticker_id', 'unique_id', 50, 50, True, False)},
{'video': Video('video_id', 'unique_id', 12, 12, 12), 'caption': 'video_file'},
{'voice': Voice('voice_id', 'unique_id', 5)},
{'video_note': VideoNote('video_note_id', 'unique_id', 20, 12)},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_photo.py
Expand Up @@ -473,7 +473,7 @@ def test_equality(self, photo):
b = PhotoSize('', photo.file_unique_id, self.width, self.height)
c = PhotoSize(photo.file_id, photo.file_unique_id, 0, 0)
d = PhotoSize('', '', self.width, self.height)
e = Sticker(photo.file_id, photo.file_unique_id, self.width, self.height, False)
e = Sticker(photo.file_id, photo.file_unique_id, self.width, self.height, False, False)

assert a == b
assert hash(a) == hash(b)
Expand Down