Pyrogram v0.16.0#
Layer 105, Decomposed start() and Much More#
New Features and Enhancements#
Starting this version, support for Python 3.4 (EOL since March 16, 2019) has been dropped. The minimum requirement is now Python 3.5.3, but we suggest always using the latest Python version available, if possible.
The Telegram API schema has been updated to Layer 105.
Added support for scheduled messages. All applicable methods (
send_message
,send_photo
, …) have now aschedule_date
parameter used to schedule messages to be sent in a date in the future. Two filters have been added as well:Filters.scheduled
, to filter outgoing messages that are scheduled andFilters.from_scheduled
to filter messages that are sent automatically from the Telegram scheduler.Added the attribute
title
(rank) to ChatMember objects and the method set_administrator_title().The start() method has been finally decomposed into many reusable methods: connect(), disconnect(), initialize(), terminate(), send_code(), resend_code(), sign_in(), sign_up(), get_password_hint(), check_password(), send_recovery_code(), recover_password() and accept_terms_of_service(). You can use these methods individually to customize the authorization/registration flow much more easily.
You can now log-in with a bot token using the terminal prompt. Just paste a bot token and let Pyrogram authorize the bot automatically; once the session is created you don’t need to keep the bot token around anymore.
Added log_out() method. Use it to log out your account from Telegram and delete the *.session file.
All available Pyrogram API methods in the documentation are now coupled with examples to give you an idea of how they are used.
Added WebPage type for web page previews. The
web_page
attribute of a Message will now point to a WebPage object instead of a boolean (contributed by @mendelmaleh in #268).Added bound methods (contributed by @kalmengr in #274, #275, 278 and #279):
Removed
get_user_dc()
method. The user DC is now stored as a User attributedc_id
.Added
"md"
to the possible parse modes for Markdown style.Removed
UserStatus
type. A newstatus
attribute has been added to User objects among withlast_online_date
andnext_offline_date
. This will make it easier to check for a user status by comparinguser.status
to strings such as “online”, “offline”, “last_week”, …The text parser will now log warnings instead of raising exceptions in case of unclosed tags.
Added set_parse_mode() method to set a global parse mode (client instance-wide). This is useful to save you from setting the parse mode on every method call, in case you want to use something else than the default.
send_media_group() is now able to send media from URLs.
Added new methods: add_chat_members(), create_group(), create_channel(), create_supergroup(), delete_channel() and delete_supergroup().
Added
is_gallery
parameter to to answer_inline_query() and InlineQuery.answer().Added new inline query result types: InlineQueryResultPhoto and InlineQueryResultAnimation.
The command filter has been reworked to allow multiple words arguments inside quotes. For example:
/start "this is one argument"
will produce this Message.command list:["start", "this is one argument"]
(contributed by @mendelmaleh in #292). Theprefix
parameter has been renamed toprefixes
for consistency with the other parameters names.Added a new section to docs: scheduling (contributed by @MrNaif2018 in #283).
Added support for bot_token inside config.ini file (contributed by @trenoduro in #296).
Added a better support for unparsing nested entities (both for HTML and Markdown) (contributed by @Midblyte in #297).
Added Chat.export_invite_link() bound method (contributed by @ColinTheShark in #300) and get_common_chats() method (contributed by @ColinTheShark in #303).
Removed
__slots__
from all Pyrogram types. They were pretty annoying to maintain and were giving little to no benefit.Added
is_animated
field to Sticker.Removed
send_animated_sticker()
in favour of send_sticker(), which is able to send both static and animated stickers.Renamed
restrict_chat
to set_chat_permissions().Moved all
can_*
permissions back to the ChatMember object.Updated restrict_chat_member() to accept a single ChatPermissions argument.
Added
Chat.description
field to basic chats.Added FAQ about “database is locked” error.
Added smarter auth import to deal with race conditions by multiple sessions: The time window in which export+import executes was narrowed down and a retry mechanism (up to three times) was added as well.
Removed the mention in the documentation of
python-dev
dependency for Termux when installing TgCrypto (contributed by @AlissonLauffer in #301).Added missing
members_count
attribute in Chat objects.Added get_nearby_chats() method to get the nearby chats given a location expressed in latitude and longitude coordinates.
Added new Restriction object and made User and Chat object use it. The User and Chat
restriction_reason
has been renamed torestrictions
and its type is now a List of Restriction objects instead of just a plain string.
Bug Fixes#
Fixed
RPCError
raising an error by itself because of non-optional arguments.Fixed
Filters.private
not filteringbot
chat types (which are a kind of private chat).Fixed forwarded copies having “None” as caption in case of no caption at all.
Fixed
Message.text
andMessage.caption
messing up in case of web page previews.Fixed dispatcher raising exceptions in case filter checks failed (contributed by @mendelmaleh in #293).
Fixed Message.click() not working because of wrong default arguments.
Fixed VACUUM failing in Python 3.6.0 (exactly this version).
Breaking Changes#
Removed support for callback functions for Client arguments like phone_number, phone_code, password, … in favour of a simpler and sequential authorization flow.
Reworked idle(): the method is now static and will only do what it is supposed to do, idling; it won’t stop the client anymore when idling ends. For this reason, you now have to call
app.stop()
yourself after it.The upload/download progress callback will not accept the
client
parameter anymore because is often redundant. This means that only (current, total) arguments will be passed by default. If you need a client reference, you can pass it viaprogress_args
anytime. Most likely you want to pass aMessage
instance, instead, and use bound methods to make API calls in a more convenient way.All Photo-like file id formats have changed to be compatible with the ones offered by the Bot API. This, unfortunately, means that all previous file ids can’t be used anymore.
To correctly download, re-send, edit or forward as copy a media message, you must now pass a valid and up to date
file_ref
(file reference) you can get from a media object (Photo, Audio, Document, …). The inevitable downside (because this is how Telegram wants it to work now) is that once a file reference expires (usually after 24h, but could happen anytime) you have to manually fetch the original message again with get_messages and the context (a pair of chat_id + message_id) in order to get a refreshed file reference. A newfile_ref
parameter has been added to all methods dealing with media messages as well (send_photo, *_audio, *_document, …).