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_photo, …) have now a
schedule_dateparameter 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 and
Filters.from_scheduledto filter messages that are sent automatically from the Telegram scheduler.
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_pageattribute 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):
get_user_dc()method. The user DC is now stored as a User attribute
"md"to the possible parse modes for Markdown style.
UserStatustype. A new
statusattribute has been added to User objects among with
next_offline_date. This will make it easier to check for a user status by comparing
user.statusto 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.
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). The
prefixparameter has been renamed to
prefixesfor 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).
__slots__from all Pyrogram types. They were pretty annoying to maintain and were giving little to no benefit.
is_animatedfield to Sticker.
send_animated_sticker()in favour of send_sticker(), which is able to send both static and animated stickers.
can_*permissions back to the ChatMember object.
Chat.descriptionfield 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-devdependency for Termux when installing TgCrypto (contributed by @AlissonLauffer in #301).
members_countattribute 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_reasonhas been renamed to
restrictionsand its type is now a List of Restriction objects instead of just a plain string.
RPCErrorraising an error by itself because of non-optional arguments.
botchat types (which are a kind of private chat).
Fixed forwarded copies having “None” as caption in case of no caption at all.
Message.captionmessing 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).
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
clientparameter 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 via
progress_argsanytime. Most likely you want to pass a
Messageinstance, 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 new
file_refparameter has been added to all methods dealing with media messages as well (send_photo, *_audio, *_document, …).