Skip to content

Commit e4dc80f

Browse files
Co-authored-by: poolitzer <25934244+Poolitzer@users.noreply.github.com>
1 parent bc7c422 commit e4dc80f

21 files changed

+1125
-15
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We have a vibrant community of developers helping each other in our `Telegram gr
2020
:target: https://pypi.org/project/python-telegram-bot/
2121
:alt: Supported Python versions
2222

23-
.. image:: https://img.shields.io/badge/Bot%20API-5.3-blue?logo=telegram
23+
.. image:: https://img.shields.io/badge/Bot%20API-5.4-blue?logo=telegram
2424
:target: https://core.telegram.org/bots/api-changelog
2525
:alt: Supported Bot API versions
2626

@@ -111,7 +111,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
111111
Telegram API support
112112
====================
113113

114-
All types and methods of the Telegram Bot API **5.3** are supported.
114+
All types and methods of the Telegram Bot API **5.4** are supported.
115115

116116
==========
117117
Installing

README_RAW.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We have a vibrant community of developers helping each other in our `Telegram gr
2020
:target: https://pypi.org/project/python-telegram-bot-raw/
2121
:alt: Supported Python versions
2222

23-
.. image:: https://img.shields.io/badge/Bot%20API-5.3-blue?logo=telegram
23+
.. image:: https://img.shields.io/badge/Bot%20API-5.4-blue?logo=telegram
2424
:target: https://core.telegram.org/bots/api-changelog
2525
:alt: Supported Bot API versions
2626

@@ -105,7 +105,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
105105
Telegram API support
106106
====================
107107

108-
All types and methods of the Telegram Bot API **5.3** are supported.
108+
All types and methods of the Telegram Bot API **5.4** are supported.
109109

110110
==========
111111
Installing

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ignore_errors = True
6060

6161
# Disable strict optional for telegram objects with class methods
6262
# We don't want to clutter the code with 'if self.bot is None: raise RuntimeError()'
63-
[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]
63+
[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]
6464
strict_optional = False
6565

6666
# type hinting for asyncio in webhookhandler is a bit tricky because it depends on the OS

telegram/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .chat import Chat
2626
from .chatlocation import ChatLocation
2727
from .chatinvitelink import ChatInviteLink
28+
from .chatjoinrequest import ChatJoinRequest
2829
from .chatmember import (
2930
ChatMember,
3031
ChatMemberOwner,
@@ -194,6 +195,7 @@
194195
'Chat',
195196
'ChatAction',
196197
'ChatInviteLink',
198+
'ChatJoinRequest',
197199
'ChatLocation',
198200
'ChatMember',
199201
'ChatMemberOwner',

telegram/bot.py

Lines changed: 129 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,6 +3985,8 @@ def create_chat_invite_link(
39853985
member_limit: int = None,
39863986
timeout: ODVInput[float] = DEFAULT_NONE,
39873987
api_kwargs: JSONDict = None,
3988+
name: str = None,
3989+
creates_join_request: bool = None,
39883990
) -> ChatInviteLink:
39893991
"""
39903992
Use this method to create an additional invite link for a chat. The bot must be an
@@ -4007,6 +4009,14 @@ def create_chat_invite_link(
40074009
the connection pool).
40084010
api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
40094011
Telegram API.
4012+
name (:obj:`str`, optional): Invite link name; 0-32 characters.
4013+
4014+
.. versionadded:: 13.8
4015+
creates_join_request (:obj:`bool`, optional): :obj:`True`, if users joining the chat
4016+
via the link need to be approved by chat administrators.
4017+
If :obj:`True`, ``member_limit`` can't be specified.
4018+
4019+
.. versionadded:: 13.8
40104020
40114021
Returns:
40124022
:class:`telegram.ChatInviteLink`
@@ -4015,6 +4025,11 @@ def create_chat_invite_link(
40154025
:class:`telegram.error.TelegramError`
40164026
40174027
"""
4028+
if creates_join_request and member_limit:
4029+
raise ValueError(
4030+
"If `creates_join_request` is `True`, `member_limit` can't be specified."
4031+
)
4032+
40184033
data: JSONDict = {
40194034
'chat_id': chat_id,
40204035
}
@@ -4029,6 +4044,12 @@ def create_chat_invite_link(
40294044
if member_limit is not None:
40304045
data['member_limit'] = member_limit
40314046

4047+
if name is not None:
4048+
data['name'] = name
4049+
4050+
if creates_join_request is not None:
4051+
data['creates_join_request'] = creates_join_request
4052+
40324053
result = self._post('createChatInviteLink', data, timeout=timeout, api_kwargs=api_kwargs)
40334054

40344055
return ChatInviteLink.de_json(result, self) # type: ignore[return-value, arg-type]
@@ -4042,11 +4063,19 @@ def edit_chat_invite_link(
40424063
member_limit: int = None,
40434064
timeout: ODVInput[float] = DEFAULT_NONE,
40444065
api_kwargs: JSONDict = None,
4066+
name: str = None,
4067+
creates_join_request: bool = None,
40454068
) -> ChatInviteLink:
40464069
"""
40474070
Use this method to edit a non-primary invite link created by the bot. The bot must be an
40484071
administrator in the chat for this to work and must have the appropriate admin rights.
40494072
4073+
Note:
4074+
Though not stated explicitly in the official docs, Telegram changes not only the
4075+
optional parameters that are explicitly passed, but also replaces all other optional
4076+
parameters to the default values. However, since not documented, this behaviour may
4077+
change unbeknown to PTB.
4078+
40504079
.. versionadded:: 13.4
40514080
40524081
Args:
@@ -4064,6 +4093,14 @@ def edit_chat_invite_link(
40644093
the connection pool).
40654094
api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
40664095
Telegram API.
4096+
name (:obj:`str`, optional): Invite link name; 0-32 characters.
4097+
4098+
.. versionadded:: 13.8
4099+
creates_join_request (:obj:`bool`, optional): :obj:`True`, if users joining the chat
4100+
via the link need to be approved by chat administrators.
4101+
If :obj:`True`, ``member_limit`` can't be specified.
4102+
4103+
.. versionadded:: 13.8
40674104
40684105
Returns:
40694106
:class:`telegram.ChatInviteLink`
@@ -4072,6 +4109,11 @@ def edit_chat_invite_link(
40724109
:class:`telegram.error.TelegramError`
40734110
40744111
"""
4112+
if creates_join_request and member_limit:
4113+
raise ValueError(
4114+
"If `creates_join_request` is `True`, `member_limit` can't be specified."
4115+
)
4116+
40754117
data: JSONDict = {'chat_id': chat_id, 'invite_link': invite_link}
40764118

40774119
if expire_date is not None:
@@ -4084,6 +4126,12 @@ def edit_chat_invite_link(
40844126
if member_limit is not None:
40854127
data['member_limit'] = member_limit
40864128

4129+
if name is not None:
4130+
data['name'] = name
4131+
4132+
if creates_join_request is not None:
4133+
data['creates_join_request'] = creates_join_request
4134+
40874135
result = self._post('editChatInviteLink', data, timeout=timeout, api_kwargs=api_kwargs)
40884136

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

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

4177+
@log
4178+
def approve_chat_join_request(
4179+
self,
4180+
chat_id: Union[str, int],
4181+
user_id: int,
4182+
timeout: ODVInput[float] = DEFAULT_NONE,
4183+
api_kwargs: JSONDict = None,
4184+
) -> bool:
4185+
"""Use this method to approve a chat join request.
4186+
4187+
The bot must be an administrator in the chat for this to work and must have the
4188+
:attr:`telegram.ChatPermissions.can_invite_users` administrator right.
4189+
4190+
.. versionadded:: 13.8
4191+
4192+
Args:
4193+
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
4194+
of the target channel (in the format ``@channelusername``).
4195+
user_id (:obj:`int`): Unique identifier of the target user.
4196+
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
4197+
the read timeout from the server (instead of the one specified during creation of
4198+
the connection pool).
4199+
api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
4200+
Telegram API.
4201+
4202+
Returns:
4203+
:obj:`bool`: On success, :obj:`True` is returned.
4204+
4205+
Raises:
4206+
:class:`telegram.error.TelegramError`
4207+
"""
4208+
data: JSONDict = {'chat_id': chat_id, 'user_id': user_id}
4209+
4210+
result = self._post('approveChatJoinRequest', data, timeout=timeout, api_kwargs=api_kwargs)
4211+
4212+
return result # type: ignore[return-value]
4213+
4214+
@log
4215+
def decline_chat_join_request(
4216+
self,
4217+
chat_id: Union[str, int],
4218+
user_id: int,
4219+
timeout: ODVInput[float] = DEFAULT_NONE,
4220+
api_kwargs: JSONDict = None,
4221+
) -> bool:
4222+
"""Use this method to decline a chat join request.
4223+
4224+
The bot must be an administrator in the chat for this to work and must have the
4225+
:attr:`telegram.ChatPermissions.can_invite_users` administrator right.
4226+
4227+
.. versionadded:: 13.8
4228+
4229+
Args:
4230+
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
4231+
of the target channel (in the format ``@channelusername``).
4232+
user_id (:obj:`int`): Unique identifier of the target user.
4233+
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
4234+
the read timeout from the server (instead of the one specified during creation of
4235+
the connection pool).
4236+
api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
4237+
Telegram API.
4238+
4239+
Returns:
4240+
:obj:`bool`: On success, :obj:`True` is returned.
4241+
4242+
Raises:
4243+
:class:`telegram.error.TelegramError`
4244+
"""
4245+
data: JSONDict = {'chat_id': chat_id, 'user_id': user_id}
4246+
4247+
result = self._post('declineChatJoinRequest', data, timeout=timeout, api_kwargs=api_kwargs)
4248+
4249+
return result # type: ignore[return-value]
4250+
41294251
@log
41304252
def set_chat_photo(
41314253
self,
@@ -5436,11 +5558,15 @@ def __hash__(self) -> int:
54365558
exportChatInviteLink = export_chat_invite_link
54375559
"""Alias for :meth:`export_chat_invite_link`"""
54385560
createChatInviteLink = create_chat_invite_link
5439-
"""Alias for :attr:`create_chat_invite_link`"""
5561+
"""Alias for :meth:`create_chat_invite_link`"""
54405562
editChatInviteLink = edit_chat_invite_link
5441-
"""Alias for :attr:`edit_chat_invite_link`"""
5563+
"""Alias for :meth:`edit_chat_invite_link`"""
54425564
revokeChatInviteLink = revoke_chat_invite_link
5443-
"""Alias for :attr:`revoke_chat_invite_link`"""
5565+
"""Alias for :meth:`revoke_chat_invite_link`"""
5566+
approveChatJoinRequest = approve_chat_join_request
5567+
"""Alias for :meth:`approve_chat_join_request`"""
5568+
declineChatJoinRequest = decline_chat_join_request
5569+
"""Alias for :meth:`decline_chat_join_request`"""
54445570
setChatPhoto = set_chat_photo
54455571
"""Alias for :meth:`set_chat_photo`"""
54465572
deleteChatPhoto = delete_chat_photo

telegram/chat.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,8 @@ def create_invite_link(
15241524
member_limit: int = None,
15251525
timeout: ODVInput[float] = DEFAULT_NONE,
15261526
api_kwargs: JSONDict = None,
1527+
name: str = None,
1528+
creates_join_request: bool = None,
15271529
) -> 'ChatInviteLink':
15281530
"""Shortcut for::
15291531
@@ -1534,6 +1536,10 @@ def create_invite_link(
15341536
15351537
.. versionadded:: 13.4
15361538
1539+
.. versionchanged:: 13.8
1540+
Edited signature according to the changes of
1541+
:meth:`telegram.Bot.create_chat_invite_link`.
1542+
15371543
Returns:
15381544
:class:`telegram.ChatInviteLink`
15391545
@@ -1544,6 +1550,8 @@ def create_invite_link(
15441550
member_limit=member_limit,
15451551
timeout=timeout,
15461552
api_kwargs=api_kwargs,
1553+
name=name,
1554+
creates_join_request=creates_join_request,
15471555
)
15481556

15491557
def edit_invite_link(
@@ -1553,6 +1561,8 @@ def edit_invite_link(
15531561
member_limit: int = None,
15541562
timeout: ODVInput[float] = DEFAULT_NONE,
15551563
api_kwargs: JSONDict = None,
1564+
name: str = None,
1565+
creates_join_request: bool = None,
15561566
) -> 'ChatInviteLink':
15571567
"""Shortcut for::
15581568
@@ -1563,6 +1573,9 @@ def edit_invite_link(
15631573
15641574
.. versionadded:: 13.4
15651575
1576+
.. versionchanged:: 13.8
1577+
Edited signature according to the changes of :meth:`telegram.Bot.edit_chat_invite_link`.
1578+
15661579
Returns:
15671580
:class:`telegram.ChatInviteLink`
15681581
@@ -1574,6 +1587,8 @@ def edit_invite_link(
15741587
member_limit=member_limit,
15751588
timeout=timeout,
15761589
api_kwargs=api_kwargs,
1590+
name=name,
1591+
creates_join_request=creates_join_request,
15771592
)
15781593

15791594
def revoke_invite_link(
@@ -1598,3 +1613,49 @@ def revoke_invite_link(
15981613
return self.bot.revoke_chat_invite_link(
15991614
chat_id=self.id, invite_link=invite_link, timeout=timeout, api_kwargs=api_kwargs
16001615
)
1616+
1617+
def approve_join_request(
1618+
self,
1619+
user_id: int,
1620+
timeout: ODVInput[float] = DEFAULT_NONE,
1621+
api_kwargs: JSONDict = None,
1622+
) -> bool:
1623+
"""Shortcut for::
1624+
1625+
bot.approve_chat_join_request(chat_id=update.effective_chat.id, *args, **kwargs)
1626+
1627+
For the documentation of the arguments, please see
1628+
:meth:`telegram.Bot.approve_chat_join_request`.
1629+
1630+
.. versionadded:: 13.8
1631+
1632+
Returns:
1633+
:obj:`bool`: On success, :obj:`True` is returned.
1634+
1635+
"""
1636+
return self.bot.approve_chat_join_request(
1637+
chat_id=self.id, user_id=user_id, timeout=timeout, api_kwargs=api_kwargs
1638+
)
1639+
1640+
def decline_join_request(
1641+
self,
1642+
user_id: int,
1643+
timeout: ODVInput[float] = DEFAULT_NONE,
1644+
api_kwargs: JSONDict = None,
1645+
) -> bool:
1646+
"""Shortcut for::
1647+
1648+
bot.decline_chat_join_request(chat_id=update.effective_chat.id, *args, **kwargs)
1649+
1650+
For the documentation of the arguments, please see
1651+
:meth:`telegram.Bot.decline_chat_join_request`.
1652+
1653+
.. versionadded:: 13.8
1654+
1655+
Returns:
1656+
:obj:`bool`: On success, :obj:`True` is returned.
1657+
1658+
"""
1659+
return self.bot.decline_chat_join_request(
1660+
chat_id=self.id, user_id=user_id, timeout=timeout, api_kwargs=api_kwargs
1661+
)

telegram/chataction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class ChatAction:
5959
"""
6060
UPLOAD_DOCUMENT: ClassVar[str] = constants.CHATACTION_UPLOAD_DOCUMENT
6161
""":const:`telegram.constants.CHATACTION_UPLOAD_DOCUMENT`"""
62+
CHOOSE_STICKER: ClassVar[str] = constants.CHATACTION_CHOOSE_STICKER
63+
""":const:`telegram.constants.CHOOSE_STICKER`
64+
65+
.. versionadded:: 13.8"""
6266
UPLOAD_PHOTO: ClassVar[str] = constants.CHATACTION_UPLOAD_PHOTO
6367
""":const:`telegram.constants.CHATACTION_UPLOAD_PHOTO`"""
6468
UPLOAD_VIDEO: ClassVar[str] = constants.CHATACTION_UPLOAD_VIDEO

0 commit comments

Comments
 (0)
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