Skip to content

API 4.5 #1849

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

Closed
wants to merge 2 commits into from
Closed

API 4.5 #1849

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ make the development of bots easy and straightforward. These classes are contain
Telegram API support
====================

All types and methods of the Telegram Bot API **4.1** are supported.
All types and methods of the Telegram Bot API **4.5** are supported.

==========
Installing
Expand Down
40 changes: 40 additions & 0 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,44 @@ def set_chat_permissions(self, chat_id, permissions, timeout=None, **kwargs):

return result

@log
def set_chat_administrator_custom_title(self,
chat_id,
user_id,
custom_title,
timeout=None,
**kwargs):
"""
Use this method to set a custom title for administrators promoted by the bot in a
supergroup. The bot must be an administrator for this to work. Returns True on success.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of
the target supergroup (in the format `@supergroupusername`).
user_id (:obj:`int`): Unique identifier of the target administrator.
custom_title (:obj:`str`) New custom title for the administrator. It must be a string
with len 0-16 characters, emoji are not allowed.
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).
**kwargs (:obj:`dict`): Arbitrary keyword arguments

Returns:
:obj:`bool`: Returns True on success.

Raises:
:class:`telegram.TelegramError`

"""
url = '{0}/setChatAdministratorCustomTitle'.format(self.base_url)

data = {'chat_id': chat_id, 'user_id': user_id, 'custom_title': custom_title}
data.update(kwargs)

result = self._request.post(url, data, timeout=timeout)

return result

@log
def export_chat_invite_link(self, chat_id, timeout=None, **kwargs):
"""
Expand Down Expand Up @@ -3655,6 +3693,8 @@ def __reduce__(self):
"""Alias for :attr:`promote_chat_member`"""
setChatPermissions = set_chat_permissions
"""Alias for :attr:`set_chat_permissions`"""
setChatAdministratorCustomTitle = set_chat_administrator_custom_title
"""Alias for :attr:`set_chat_administrator_custom_title`"""
exportChatInviteLink = export_chat_invite_link
"""Alias for :attr:`export_chat_invite_link`"""
setChatPhoto = set_chat_photo
Expand Down
17 changes: 17 additions & 0 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Chat(TelegramObject):
Returned only in get_chat.
permissions (:class:`telegram.ChatPermission`): Optional. Default chat member permissions,
for groups and supergroups. Returned only in getChat.
slow_mode_delay (:obj:`int`): Optional. For supergroups, the minimum allowed delay between
consecutive messages sent by each unpriviledged user. Returned only in getChat.
sticker_set_name (:obj:`str`): Optional. For supergroups, name of Group sticker set.
can_set_sticker_set (:obj:`bool`): Optional. ``True``, if the bot can change group the
sticker set.
Expand All @@ -65,6 +67,8 @@ class Chat(TelegramObject):
Returned only in get_chat.
permissions (:class:`telegram.ChatPermission`): Optional. Default chat member permissions,
for groups and supergroups. Returned only in getChat.
slow_mode_delay (:obj:`int`, optional): For supergroups, the minimum allowed delay between
consecutive messages sent by each unpriviledged user. Returned only in getChat.
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
sticker_set_name (:obj:`str`, optional): For supergroups, name of Group sticker set.
Returned only in get_chat.
Expand Down Expand Up @@ -98,6 +102,7 @@ def __init__(self,
permissions=None,
sticker_set_name=None,
can_set_sticker_set=None,
slow_mode_delay=None,
**kwargs):
# Required
self.id = int(id)
Expand All @@ -114,6 +119,7 @@ def __init__(self,
self.invite_link = invite_link
self.pinned_message = pinned_message
self.permissions = permissions
self.slow_mode_delay = slow_mode_delay
self.sticker_set_name = sticker_set_name
self.can_set_sticker_set = can_set_sticker_set

Expand Down Expand Up @@ -240,6 +246,17 @@ def set_permissions(self, *args, **kwargs):
"""
return self.bot.set_chat_permissions(self.id, *args, **kwargs)

def set_administrator_custom_title(self, *args, **kwargs):
"""Shortcut for::

bot.set_chat_administrator_custom_title(update.message.chat.id, *args, **kwargs)

Returns:
:obj:`bool`: If the action was sent successfully.

"""
return self.bot.set_chat_administrator_custom_title(self.id, *args, **kwargs)

def send_message(self, *args, **kwargs):
"""Shortcut for::

Expand Down
6 changes: 5 additions & 1 deletion telegram/chatmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ChatMember(TelegramObject):
Attributes:
user (:class:`telegram.User`): Information about the user.
status (:obj:`str`): The member's status in the chat.
custom_title (:obj:`str`): Optional. Custom title for owner and administrators.
until_date (:class:`datetime.datetime`): Optional. Date when restrictions will be lifted
for this user.
can_be_edited (:obj:`bool`): Optional. If the bot is allowed to edit administrator
Expand Down Expand Up @@ -62,6 +63,8 @@ class ChatMember(TelegramObject):
user (:class:`telegram.User`): Information about the user.
status (:obj:`str`): The member's status in the chat. Can be 'creator', 'administrator',
'member', 'restricted', 'left' or 'kicked'.
custom_title (:obj:`str`, optional): Owner and administrators only.
Custom title for this user.
until_date (:class:`datetime.datetime`, optional): Restricted and kicked only. Date when
restrictions will be lifted for this user.
can_be_edited (:obj:`bool`, optional): Administrators only. True, if the bot is allowed to
Expand Down Expand Up @@ -118,10 +121,11 @@ def __init__(self, user, status, until_date=None, can_be_edited=None,
can_restrict_members=None, can_pin_messages=None,
can_promote_members=None, can_send_messages=None,
can_send_media_messages=None, can_send_polls=None, can_send_other_messages=None,
can_add_web_page_previews=None, is_member=None, **kwargs):
can_add_web_page_previews=None, is_member=None, custom_title=None, **kwargs):
# Required
self.user = user
self.status = status
self.custom_title = custom_title
self.until_date = until_date
self.can_be_edited = can_be_edited
self.can_change_info = can_change_info
Expand Down
14 changes: 11 additions & 3 deletions telegram/files/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class Animation(TelegramObject):
"""This object represents an animation file to be displayed in the message containing a game.

Attributes:
file_id (:obj:`str`): Unique file identifier.
file_id (:obj:`str`): File identifier.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
width (:obj:`int`): Video width as defined by sender.
height (:obj:`int`): Video height as defined by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
Expand All @@ -37,7 +40,10 @@ class Animation(TelegramObject):
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.

Args:
file_id (:obj:`str`): Unique file identifier.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
width (:obj:`int`): Video width as defined by sender.
height (:obj:`int`): Video height as defined by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
Expand All @@ -52,6 +58,7 @@ class Animation(TelegramObject):

def __init__(self,
file_id,
file_unique_id,
width,
height,
duration,
Expand All @@ -63,6 +70,7 @@ def __init__(self,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
self.width = int(width)
self.height = int(height)
self.duration = duration
Expand All @@ -73,7 +81,7 @@ def __init__(self,
self.file_size = file_size
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
12 changes: 10 additions & 2 deletions telegram/files/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Audio(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
duration (:obj:`int`): Duration of the audio in seconds.
performer (:obj:`str`): Optional. Performer of the audio as defined by sender or by audio
tags.
Expand All @@ -37,7 +40,10 @@ class Audio(TelegramObject):
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.

Args:
file_id (:obj:`str`): Unique identifier for this file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
duration (:obj:`int`): Duration of the audio in seconds as defined by sender.
performer (:obj:`str`, optional): Performer of the audio as defined by sender or by audio
tags.
Expand All @@ -53,6 +59,7 @@ class Audio(TelegramObject):

def __init__(self,
file_id,
file_unique_id,
duration,
performer=None,
title=None,
Expand All @@ -63,6 +70,7 @@ def __init__(self,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
self.duration = int(duration)
# Optionals
self.performer = performer
Expand All @@ -72,7 +80,7 @@ def __init__(self,
self.thumb = thumb
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
38 changes: 31 additions & 7 deletions telegram/files/chatphoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,48 @@ class ChatPhoto(TelegramObject):

Attributes:
small_file_id (:obj:`str`): File identifier of small (160x160) chat photo.
This file_id can be used only for photo download and only for as long
as the photo is not changed.
small_file_unique_id (:obj:`str`): Unique file identifier of small (160x160) chat photo,
which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
big_file_id (:obj:`str`): File identifier of big (640x640) chat photo.

This file_id can be used only for photo download and only for as long as
the photo is not changed.
big_file_unique_id (:obj:`str`): Unique file identifier of big (640x640) chat photo,
which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
Args:
small_file_id (:obj:`str`): File identifier of small (160x160) chat photo. This file_id can
be used only for photo download and only for as long as the photo is not changed.
big_file_id (:obj:`str`): File identifier of big (640x640) chat photo. This file_id can be
used only for photo download and only for as long as the photo is not changed.
small_file_id (:obj:`str`): Unique file identifier of small (160x160) chat photo. This
file_id can be used only for photo download and only for as long
as the photo is not changed.
small_file_unique_id (:obj:`str`): Unique file identifier of small (160x160) chat photo,
which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
big_file_id (:obj:`str`): Unique file identifier of big (640x640) chat photo. This file_id
can be used only for photo download and only for as long as the photo is not changed.
big_file_unique_id (:obj:`str`): Unique file identifier of big (640x640) chat photo,
which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""

def __init__(self, small_file_id, big_file_id, bot=None, **kwargs):
def __init__(self,
small_file_id,
small_file_unique_id,
big_file_id,
big_file_unique_id,
bot=None, **kwargs):
self.small_file_id = small_file_id
self.small_file_unique_id = small_file_unique_id
self.big_file_id = big_file_id
self.big_file_unique_id = big_file_unique_id

self.bot = bot

self._id_attrs = (self.small_file_id, self.big_file_id)
self._id_attrs = (self.small_file_unique_id, self.big_file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
12 changes: 10 additions & 2 deletions telegram/files/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ class Document(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique file identifier.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
thumb (:class:`telegram.PhotoSize`): Optional. Document thumbnail.
file_name (:obj:`str`): Original filename.
mime_type (:obj:`str`): Optional. MIME type of the file.
file_size (:obj:`int`): Optional. File size.
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.

Args:
file_id (:obj:`str`): Unique file identifier
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
thumb (:class:`telegram.PhotoSize`, optional): Document thumbnail as defined by sender.
file_name (:obj:`str`, optional): Original filename as defined by sender.
mime_type (:obj:`str`, optional): MIME type of the file as defined by sender.
Expand All @@ -46,6 +52,7 @@ class Document(TelegramObject):

def __init__(self,
file_id,
file_unique_id,
thumb=None,
file_name=None,
mime_type=None,
Expand All @@ -54,14 +61,15 @@ def __init__(self,
**kwargs):
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
# Optionals
self.thumb = thumb
self.file_name = file_name
self.mime_type = mime_type
self.file_size = file_size
self.bot = bot

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
21 changes: 16 additions & 5 deletions telegram/files/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ class File(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique identifier for this file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
file_size (:obj:`str`): Optional. File size.
file_path (:obj:`str`): Optional. File path. Use :attr:`download` to get the file.

Args:
file_id (:obj:`str`): Unique identifier for this file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique and the same over time and
for different bots file identifier.
file_size (:obj:`int`, optional): Optional. File size, if known.
file_path (:obj:`str`, optional): File path. Use :attr:`download` to get the file.
bot (:obj:`telegram.Bot`, optional): Bot to use with shortcut method.
Expand All @@ -54,18 +60,23 @@ class File(TelegramObject):

"""

def __init__(self, file_id, bot=None, file_size=None, file_path=None, **kwargs):
def __init__(self,
file_id,
file_unique_id,
bot=None,
file_size=None,
file_path=None,
**kwargs):
# Required
self.file_id = str(file_id)

self.file_unique_id = str(file_unique_id)
# Optionals
self.file_size = file_size
self.file_path = file_path

self.bot = bot
self._credentials = None

self._id_attrs = (self.file_id,)
self._id_attrs = (self.file_unique_id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
Loading