Skip to content

Api 5.4 #2767

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

Merged
merged 12 commits into from
Nov 8, 2021
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
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.3-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-5.4-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.3** are supported.
All types and methods of the Telegram Bot API **5.4** are supported.

==========
Installing
Expand Down
4 changes: 2 additions & 2 deletions README_RAW.rst
Original file line number Diff line number Diff line change
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.3-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-5.4-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.3** are supported.
All types and methods of the Telegram Bot API **5.4** are supported.

==========
Installing
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ignore_errors = True

# Disable strict optional for telegram objects with class methods
# We don't want to clutter the code with 'if self.bot is None: raise RuntimeError()'
[mypy-telegram.callbackquery,telegram.chat,telegram.message,telegram.user,telegram.files.*,telegram.inline.inlinequery,telegram.payment.precheckoutquery,telegram.payment.shippingquery,telegram.passport.passportdata,telegram.passport.credentials,telegram.passport.passportfile,telegram.ext.filters]
[mypy-telegram.callbackquery,telegram.chat,telegram.message,telegram.user,telegram.files.*,telegram.inline.inlinequery,telegram.payment.precheckoutquery,telegram.payment.shippingquery,telegram.passport.passportdata,telegram.passport.credentials,telegram.passport.passportfile,telegram.ext.filters,telegram.chatjoinrequest]
strict_optional = False

# type hinting for asyncio in webhookhandler is a bit tricky because it depends on the OS
Expand Down
2 changes: 2 additions & 0 deletions telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .chat import Chat
from .chatlocation import ChatLocation
from .chatinvitelink import ChatInviteLink
from .chatjoinrequest import ChatJoinRequest
from .chatmember import (
ChatMember,
ChatMemberOwner,
Expand Down Expand Up @@ -194,6 +195,7 @@
'Chat',
'ChatAction',
'ChatInviteLink',
'ChatJoinRequest',
'ChatLocation',
'ChatMember',
'ChatMemberOwner',
Expand Down
132 changes: 129 additions & 3 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3985,6 +3985,8 @@ def create_chat_invite_link(
member_limit: int = None,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
name: str = None,
creates_join_request: bool = None,
) -> ChatInviteLink:
"""
Use this method to create an additional invite link for a chat. The bot must be an
Expand All @@ -4007,6 +4009,14 @@ def create_chat_invite_link(
the connection pool).
api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
Telegram API.
name (:obj:`str`, optional): Invite link name; 0-32 characters.

.. versionadded:: 13.8
creates_join_request (:obj:`bool`, optional): :obj:`True`, if users joining the chat
via the link need to be approved by chat administrators.
If :obj:`True`, ``member_limit`` can't be specified.

.. versionadded:: 13.8

Returns:
:class:`telegram.ChatInviteLink`
Expand All @@ -4015,6 +4025,11 @@ def create_chat_invite_link(
:class:`telegram.error.TelegramError`

"""
if creates_join_request and member_limit:
raise ValueError(
"If `creates_join_request` is `True`, `member_limit` can't be specified."
)

data: JSONDict = {
'chat_id': chat_id,
}
Expand All @@ -4029,6 +4044,12 @@ def create_chat_invite_link(
if member_limit is not None:
data['member_limit'] = member_limit

if name is not None:
data['name'] = name

if creates_join_request is not None:
data['creates_join_request'] = creates_join_request

result = self._post('createChatInviteLink', data, timeout=timeout, api_kwargs=api_kwargs)

return ChatInviteLink.de_json(result, self) # type: ignore[return-value, arg-type]
Expand All @@ -4042,11 +4063,19 @@ def edit_chat_invite_link(
member_limit: int = None,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
name: str = None,
creates_join_request: bool = None,
) -> ChatInviteLink:
"""
Use this method to edit a non-primary invite link created by the bot. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights.

Note:
Though not stated explicitly in the official docs, Telegram changes not only the
optional parameters that are explicitly passed, but also replaces all other optional
parameters to the default values. However, since not documented, this behaviour may
change unbeknown to PTB.

.. versionadded:: 13.4

Args:
Expand All @@ -4064,6 +4093,14 @@ def edit_chat_invite_link(
the connection pool).
api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
Telegram API.
name (:obj:`str`, optional): Invite link name; 0-32 characters.

.. versionadded:: 13.8
creates_join_request (:obj:`bool`, optional): :obj:`True`, if users joining the chat
via the link need to be approved by chat administrators.
If :obj:`True`, ``member_limit`` can't be specified.

.. versionadded:: 13.8

Returns:
:class:`telegram.ChatInviteLink`
Expand All @@ -4072,6 +4109,11 @@ def edit_chat_invite_link(
:class:`telegram.error.TelegramError`

"""
if creates_join_request and member_limit:
raise ValueError(
"If `creates_join_request` is `True`, `member_limit` can't be specified."
)

data: JSONDict = {'chat_id': chat_id, 'invite_link': invite_link}

if expire_date is not None:
Expand All @@ -4084,6 +4126,12 @@ def edit_chat_invite_link(
if member_limit is not None:
data['member_limit'] = member_limit

if name is not None:
data['name'] = name

if creates_join_request is not None:
data['creates_join_request'] = creates_join_request

result = self._post('editChatInviteLink', data, timeout=timeout, api_kwargs=api_kwargs)

return ChatInviteLink.de_json(result, self) # type: ignore[return-value, arg-type]
Expand Down Expand Up @@ -4126,6 +4174,80 @@ def revoke_chat_invite_link(

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

@log
def approve_chat_join_request(
self,
chat_id: Union[str, int],
user_id: int,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Use this method to approve a chat join request.

The bot must be an administrator in the chat for this to work and must have the
:attr:`telegram.ChatPermissions.can_invite_users` administrator right.

.. versionadded:: 13.8

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target channel (in the format ``@channelusername``).
user_id (:obj:`int`): Unique identifier of the target user.
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:
:obj:`bool`: On success, :obj:`True` is returned.

Raises:
:class:`telegram.error.TelegramError`
"""
data: JSONDict = {'chat_id': chat_id, 'user_id': user_id}

result = self._post('approveChatJoinRequest', data, timeout=timeout, api_kwargs=api_kwargs)

return result # type: ignore[return-value]

@log
def decline_chat_join_request(
self,
chat_id: Union[str, int],
user_id: int,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Use this method to decline a chat join request.

The bot must be an administrator in the chat for this to work and must have the
:attr:`telegram.ChatPermissions.can_invite_users` administrator right.

.. versionadded:: 13.8

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target channel (in the format ``@channelusername``).
user_id (:obj:`int`): Unique identifier of the target user.
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:
:obj:`bool`: On success, :obj:`True` is returned.

Raises:
:class:`telegram.error.TelegramError`
"""
data: JSONDict = {'chat_id': chat_id, 'user_id': user_id}

result = self._post('declineChatJoinRequest', data, timeout=timeout, api_kwargs=api_kwargs)

return result # type: ignore[return-value]

@log
def set_chat_photo(
self,
Expand Down Expand Up @@ -5436,11 +5558,15 @@ def __hash__(self) -> int:
exportChatInviteLink = export_chat_invite_link
"""Alias for :meth:`export_chat_invite_link`"""
createChatInviteLink = create_chat_invite_link
"""Alias for :attr:`create_chat_invite_link`"""
"""Alias for :meth:`create_chat_invite_link`"""
editChatInviteLink = edit_chat_invite_link
"""Alias for :attr:`edit_chat_invite_link`"""
"""Alias for :meth:`edit_chat_invite_link`"""
revokeChatInviteLink = revoke_chat_invite_link
"""Alias for :attr:`revoke_chat_invite_link`"""
"""Alias for :meth:`revoke_chat_invite_link`"""
approveChatJoinRequest = approve_chat_join_request
"""Alias for :meth:`approve_chat_join_request`"""
declineChatJoinRequest = decline_chat_join_request
"""Alias for :meth:`decline_chat_join_request`"""
setChatPhoto = set_chat_photo
"""Alias for :meth:`set_chat_photo`"""
deleteChatPhoto = delete_chat_photo
Expand Down
61 changes: 61 additions & 0 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,8 @@ def create_invite_link(
member_limit: int = None,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
name: str = None,
creates_join_request: bool = None,
) -> 'ChatInviteLink':
"""Shortcut for::

Expand All @@ -1534,6 +1536,10 @@ def create_invite_link(

.. versionadded:: 13.4

.. versionchanged:: 13.8
Edited signature according to the changes of
:meth:`telegram.Bot.create_chat_invite_link`.

Returns:
:class:`telegram.ChatInviteLink`

Expand All @@ -1544,6 +1550,8 @@ def create_invite_link(
member_limit=member_limit,
timeout=timeout,
api_kwargs=api_kwargs,
name=name,
creates_join_request=creates_join_request,
)

def edit_invite_link(
Expand All @@ -1553,6 +1561,8 @@ def edit_invite_link(
member_limit: int = None,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
name: str = None,
creates_join_request: bool = None,
) -> 'ChatInviteLink':
"""Shortcut for::

Expand All @@ -1563,6 +1573,9 @@ def edit_invite_link(

.. versionadded:: 13.4

.. versionchanged:: 13.8
Edited signature according to the changes of :meth:`telegram.Bot.edit_chat_invite_link`.

Returns:
:class:`telegram.ChatInviteLink`

Expand All @@ -1574,6 +1587,8 @@ def edit_invite_link(
member_limit=member_limit,
timeout=timeout,
api_kwargs=api_kwargs,
name=name,
creates_join_request=creates_join_request,
)

def revoke_invite_link(
Expand All @@ -1598,3 +1613,49 @@ def revoke_invite_link(
return self.bot.revoke_chat_invite_link(
chat_id=self.id, invite_link=invite_link, timeout=timeout, api_kwargs=api_kwargs
)

def approve_join_request(
self,
user_id: int,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Shortcut for::

bot.approve_chat_join_request(chat_id=update.effective_chat.id, *args, **kwargs)

For the documentation of the arguments, please see
:meth:`telegram.Bot.approve_chat_join_request`.

.. versionadded:: 13.8

Returns:
:obj:`bool`: On success, :obj:`True` is returned.

"""
return self.bot.approve_chat_join_request(
chat_id=self.id, user_id=user_id, timeout=timeout, api_kwargs=api_kwargs
)

def decline_join_request(
self,
user_id: int,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Shortcut for::

bot.decline_chat_join_request(chat_id=update.effective_chat.id, *args, **kwargs)

For the documentation of the arguments, please see
:meth:`telegram.Bot.decline_chat_join_request`.

.. versionadded:: 13.8

Returns:
:obj:`bool`: On success, :obj:`True` is returned.

"""
return self.bot.decline_chat_join_request(
chat_id=self.id, user_id=user_id, timeout=timeout, api_kwargs=api_kwargs
)
4 changes: 4 additions & 0 deletions telegram/chataction.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class ChatAction:
"""
UPLOAD_DOCUMENT: ClassVar[str] = constants.CHATACTION_UPLOAD_DOCUMENT
""":const:`telegram.constants.CHATACTION_UPLOAD_DOCUMENT`"""
CHOOSE_STICKER: ClassVar[str] = constants.CHATACTION_CHOOSE_STICKER
""":const:`telegram.constants.CHOOSE_STICKER`

.. versionadded:: 13.8"""
UPLOAD_PHOTO: ClassVar[str] = constants.CHATACTION_UPLOAD_PHOTO
""":const:`telegram.constants.CHATACTION_UPLOAD_PHOTO`"""
UPLOAD_VIDEO: ClassVar[str] = constants.CHATACTION_UPLOAD_VIDEO
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy