Be notified of new releases
Create your free GitHub account today to subscribe to this repository for new releases and build software alongside 31 million developers.Sign up
- Smart Plugins revamp: you can now specify exactly which plugins to include or exclude and in which exact order to load each of them.
no_updatesClient parameter. Pass
Truein order to completely disable incoming updates from Telegram. Useful in batch programs, for example, when you want to broadcast a message to many users and have no need to handle incoming messages or other updates whatsoever.
takeoutClient parameter. Pass
Truein order to use a special takeout session instead of a normal one. Useful for exporting your Telegram data; methods invoked inside a takeout session (such as get_history, download_media, ...) are less prone to throw FloodWait exceptions.
- Message and caption texts are now automatically casted to
str. This makes possible to send objects that implement a string representation without having to manually cast, for example:
app.send_message(chat_id, 123456)sends "123456" (int) text message as string.
message.reply(message)replies with the message (Message) itself.
- Filters.me, useful for filtering messages coming from you yourself. Does the same as
- close_poll method for closing (stopping) polls.
- New convenience methods to make iterating through entities such as history messages, dialogs and chat members easier: iter_history, iter_dialogs, iter_chat_members.
- Game, GameHighScore and GameHighScores types for messages dealing with games,
game_high_scoreattributes inside Message as well as Filters.game, Filters.game_score filters and send_game, set_game_score, get_game_high_scores methods.
- It's now possible to recover the account while logging in, in case you forget your cloud password.
- Client's arguments
last_namecan now be callback functions.
- Filters.regex now works on captions too.
- New Filters.media_group for filtering photos or videos being part of an album.
- New stop_transmission method useful to stop uploads and downloads.
- New restart convenience method to automatically stop and start the Client.
- The ChatMember type has been extended with extra attributes:
- New Voice Calls page in documentation. Thanks to @bakatrouble for the working proof-of-concept.
- A way to continue propagating the same update to the next handler within the same group with .continue_propagation() update's bound-method.
- A bunch of new common Telegram errors regarding takeout sessions and poll messages.
- Polls in Layer 91 were reporting a wrong id and in some cases they were also flagged as "closed" when they were in fact not. This is due to a small issue in the TL schema (which will eventually get fixed in the next Layer update by Telegram itself). Nevertheless, from now on Pyrogram will be able to generate the correct code even in case such issues happen again. Relevant commit: c7b1d6f
- kick_chat_members and get_dialogs docstrings were reporting a wrong return type.
developinstallation for pip. Thanks @bakatrouble for the hint!
- All raw updates that were not part of those for which a parser was implemented were being discarded and never passed to raw update handlers. #211
reversedparameter has been renamed to
reversebecause it was colliding with the built-in "reversed" function.
Notice: Python 3.5.2 is bugged and breaks with Pyrogram.
More info at https://t.me/PyrogramChat/49171
- A way to stop propagating the same update on the next handler group(s) in the dispatching phase with .stop_propagation() update's bound-method.
- New documentation page: https://docs.pyrogram.ml/resources/MoreOnUpdates
Happy New Year 2019!
This last update of the year turns out to be the biggest ever made, featuring quite important internal changes – which worth mentioning – as well as lots of new additions. More updates will come in the future, such as the work-in-progress inline mode. Keep Pyrogramming!
Under the Hood
- Refactored types: Pyrogram types have been rewritten from scratch using cleaner code which increases maintainability and readability and also allows future extensibility with ease.
- Type hints: Pyrogram type and method parameters are now type hinted. This means that, with smart IDEs, whenever you try to access any Pyrogram object field you will be hinted about all the available options.
- API schema updated to Layer 91.
- Normal bots (created by BotFather) are now able to send messages to all the users who contacted them in the past anytime just by their IDs. Bots can also send messages to group chats and channels they are members of without having to manually kick and re-add them again. Thanks Manuel and TDLib devs in PyrogramLounge for suggesting this was possible!
- Normal bots are now able to edit and delete their own messages via Message's bound methods .edit() and .delete().
- New Message.web_page attribute for messages sent with web page previews. Note that support for web pages is still basic; a simple boolean is set in case the message contains a web page preview. In future versions this attribute could turn into a full web page object that contains more details. (contributed by @zeroone2numeral2 in #166).
- New Filters.web_page to filter messages containing web page previews (contributed by @zeroone2numeral2 in #166).
- New Filters.via_bot to filter messages coming from inline bots.
- Client.start() and Client.stop() will now return the Client instance itself to make chaining possible.
- Sticker packs are now automatically cached once they are retrieved for the first time. This change increases Message parsing performance a lot in case there are many stickers in a chat coming from the same pack.
- First name of users/bots is now shown when logging in the first time.
- It is now possible to recover password-protected accounts at login time (only if a password recovery e-mail was previously set) Thanks @hoolihoolihooli for testing with me in PyrogramChat.
- New Poll and PollOption objects which represent the new native polls in Telegram among with send_poll, vote_poll and retract_vote methods to interact with polls and Filters.poll to filter messages containing polls.
- Pin/unpin_chat_message method has been updated to work on basic groups and users' own private chats as well (previously working on channels and supergroups only).
hide_viaargument for send_inline_bot_result used to hide via @bot captions (currently doesn't work as official clients or the server itself seem to ignore this).
- get_history is now able to return Messages in reversed (natural) order with the new
reversedparameters set to True (contributed by @YoilyL in #94).
- New get_chat_preview method, which can be used to get the preview of a chat you haven't joined yet by its invite link; the new ChatPreview object will be returned. get_chat has been modified as well to accept invite links of already joined chats. All other methods, such as send_message, still need the chat_id as integer to work in private groups and channels (you can take that from get_chat's result).
- Many new common Telegram errors have been added.
- Three new documentation sections: Test Servers, Advanced Usage and Changelog.
futurebranch is now gone, all changes have been merged into the default
developbranch, meaning this update contains all of them!
- The raw update handler was handling parsed updates (contributed by @Jafte in #159).
- Videos sent inside an album were ignoring the custom thumbnails.
- download_media was not working properly in case of empty progress_args.
- A download progress callback was always reporting 0 as current bytes in case of downloads from file ids.
- Fixed a critical bug which caused random errors because of dicts not keeping keys order for Python <3.6.
- Yet another subtle update that changes how current callback queries work: CallbackQuery.data type is now
str, because of Telegram API actually allowing clients to send arbitrary bytes; forcing the decoding to turn bytes data into strings could lead to errors.
- get_dialogs now expects an
offset_dateas integer instead of a Dialog chunk as offset.
- Pyrogram now uses TCPAbridgedO protocol by default. TCPAbridgedO is an Obfuscated packet-level protocol that helps bypass some DPI and thus allowing Pyrogram to work fine even in case your ISP is trying to block Telegram.
- The Dispatcher has been reworked and optimized for better performance.
- Message.mentioned field and Filters.mentioned filter useful for handling messages that contain mentions to you (contributed by @Furoin in #154).
- Filters.chat and Filters.user can now accept "me" and "self" as arguments, thus enabling an easy way to filter yourself and your own chat (contributed by @Furoin in #155 and #157).
- Message.download() bound method missing arguments are now added to match Client.download_media() (contributed by @VANKINEENITAWRUN in #156).
- Message.edit() bound method to make message edits less verbose code-wise.
- MESSAGE_DELETE_FORBIDDEN error.
- Message.empty field to tell empty (deleted or non-existent) messages apart.
- Message.service field and a more efficient Filters.service to tell service messages apart.
- Message.media field and a more efficient Filters.media to tell media messages apart.
- Decorators of different Client instances can now be stacked on top of the same callback function. E.g.:
... @app1.on_message(...) @app2.on_message(...) @app3.on_message(...) def on_message(client, message): ...
- Fixed a rare
MESSAGE_IDS_EMPTYerror raised in case of a message replying to another was pinned and the replied message was deleted at the same time.
AttributeError: 'ChannelForbidden' object has no attribute 'restriction_reason'.
UnicodeDecodeErrorraised by invalid UTF-8 data inside inline buttons callback data.
ChatMember.total_countnot being available when fetching members from supergroups and channels.
InlineKeyboardButton.callback_datatype is now
strin order to fix the bug above.
- A smart and lightweight Plugin System to seamlessly write and share pluggable Pyrogram components with minimal boilerplate code.
- User.status field, UserStatus type and UserStatusHandler handler (with its own on_user_status decorator) for handling user status updates that arrive each time your contacts go online or offline.
- User.restriction_reason and Chat.restriction_reason fields used to store the restriction reason of Bots, Supergroups and Channels.
- Examples are now dedicated to the public domain under the CC0 1.0 Universal license and have also been updated using new methods and features.
- set_user_profile_photo method for uploading new user profile photos.
- You can now specify more than one prefix in Filters.command by passing a list of them.
- It is now possible to use those "special" IPv4 proxies that only allow IPv6 connections to Telegram:
Pyrogram Proxy Telegram [IPv4] <---> [IPv4] -X- [IPv4] [IPv6] -X- [IPv6] <---> [IPv6]
- Fixed handler groups that broke in case one of the registered handler raised an unhandled exception. Now, only the single handler will stop and Pyrogram will continue with the next handlers.
- Fixed an annoying CHANNEL_PRIVATE error that flooded the console (not really a bug).
- Fixed bots that weren't able to get other bot's messages in case of users mentioning them in groups.
- Lots of other bug fixes and minor improvements to both code and documentation.
- API scheme updated to Layer 82.
- Client instances can now be used in a context manager with the
from pyrogram import Client with Client("my_account") as app: app.send_message("pyrogram", "hi")
- You can now use your IPv6 network stack. Set
ipv6=Truewhen creating a Client.
- Easily create custom filters with the new Filters.create() method.
- You can delete your own profile photos with the method delete_profile_photos().
- Added support for retrieving chat members and channel subscribers: use get_chat_members() to get the members list of a chat and get_chat_member() (note the missing "s" at the end) to get information about a single member of a chat.
- Added support for editing the media content of messages: added the method edit_message_media() and new types InputMediaAnimation, InputMediaAudio, and InputMediaDocument.
- Added the .download() bound method to the Message object.
- Added new attributes to the User object: is_self, is_contact, is_mutual_contact and is_deleted to describe a user in a more detailed fashion.
- Added the Dialog type along with its method get_dialogs() to retrieve a user dialogs list.
- Added support for pinned messages in channels and supergroups: use the method pin_chat_message() to pin a message and the method unpin_chat_message() to remove the previously pinned message.
- Added support for editing group and channel settings. Added four methods for editing title, description and photo of a chat: set_chat_title(), set_chat_description(), set_chat_photo(), delete_chat_photo().
- Added the critical 406 - Not Acceptable class error: AUTH_KEY_DUPLICATED. Make sure you don't use the same session in more than one client at the same time to avoid receiving it; the server doesn't allow this usage, and so doesn't Pyrogram.
- Added a new Photo type containing the photo id and all available PhotoSize's. All references to the plain List of PhotoSize are replaced by this object; for example, Message.photo.
- Added vCard support when sharing contacts: added the field vcard to the Contact object and the parameter vcard to the send_contact() method.
- Added support for Foursquare venues: added the new field foursquare_type to the Venue object and the parameter foursquare_type to the send_venue() method.
- Added two new MessageEntity types: cashtag and phone_number.
- Added the field animation to the Message object.
- Added the method send_animation(), which can be used instead of send_document() to send animations, specifying their duration, width and height.
- Added support for attaching custom thumbnails to uploaded files. For animations, audios, videos and video notes, which are less than 10 MB in size, thumbnails are generated automatically server side.
- Added the field thumb to the Audio object to contain the thumbnail of the album cover to which the music file belongs (contributed by @zeroone2numeral2 in #111 ).
- The method download_media() will now raise ValueError in case of non-media messages instead of returning silently.
- Removed the possibility to send messages to private chats using t.me/joinchat/ links directly. You have to resolve the invite link into a valid id and use that instead. For now you need to use messages.CheckChatInvite raw function.
- Rename any GIF object reference to Animation.
- Telegram API scheme has been updated to Layer 81.
- Pyrogram will now display Telegram's terms of service when you sign-in (only if not previously accepted) and will automatically accept them as soon as you successfully authorize yourself.
- The new DeletedMessagesHandler allows you to listen for deleted messages on private chats, groups and channels (contributed by @vitalibr in #91).
- Use the new DisconnectHandler to register a function that will be called in case of disconnections.
- The new request_callback_answer() method lets you get the answer of a callback query (this is more widely known as clicking an inline button on a bot message).
- The Message type receives four new convenience bound methods: reply(), forward(), delete() and click(). You can use them as shortcut methods instead of send_message(), forward_messages(), delete_messages() and request_callback_answer().
- Filters.command() can now accept both empty and multi-character prefixes. It's now also possible to make case-sensitive commands with
- Two new filters: Filters.reply_keyboard and Filters.inline_keyboard to filter basic and inline keyboards respectively.
- Use the new run() method to automatically start and idle a client. This is a simple convenience method, for more control over your Clients you can still use start(), idle() and stop().
- Four new methods for chat administration have been added: kick_chat_member(), unban_chat_member(), restrict_chat_member, promote_chat_member().
- You can now customize your Clients by setting
lang_codefor a finer grained control over what you want to be displayed in your session detailed info and what language you want Telegram to speak you in.
- The phone_code_callback function must now accept a single positional argument (phone_number).
Notable Bug Fixes
This new feature makes possible to reuse right away text and caption messages with entities (such as bold, italic, ...). The text or caption field itself of a Message will now contain the marked up text in both HTML and Markdown syntax. Use
message.text.markdowndirectly as text argument when you send a new message (the same applies to
message.captionfor media messages).
Description Result Styled text bold, italic,
bold, italic, code
**bold**, __italic__, `code`
<b>bold</b>, <i>italic</i>, <code>code</code>
Note: Markdown uses the same syntax as Telegram Desktop and other mobile apps.
Note: In case there is no entity, the fields will still contain the same non-marked up text.
- You can now choose your
config.inifile location (and its name too) by using the new
config_fileparameter when creating a Client. Thanks @xates for the contribution!
- New get_chat() method to get detailed information about a chat (private, group, supergroup or channel).
- New get_history() method to get the message history of a chat (private, group, supergroup or channel).
- New send_gif() method to send GIF files.
- Two new types: Messages and GIF.
- New Filters.bot to filter messages coming from bots and Filters.gif to filter GIF messages.
- The get_me() method will now return a User object.
- The progress_args parameter has been added to download_media() as well.
- The get_inline_bot_results() method will now raise a
TimeoutErrorin case a bot fails to answer within 10 seconds.
- The export_chat_invite_link() method will now always generate a new invite link and the
newparameter has been removed. To get a previously generated link you can use get_chat() instead.
- The get_inline_bot_results() method will not accept a location tuple anymore, two distinct parameters are used instead: latitude and longitude.