TGTGInsighttelegram intelligenceLIVE / telegram public index
← python-telegram-bot
python-telegram-bot avatar

TGINSIGHT POST

Post #102

@pythontelegrambotchannel

python-telegram-bot

Views11,500Post view count
PostedJun 606/06/2021, 10:41 AM
Post content

Post content

We've just released v13.6. Thank you to everyone who contributed to this release. As usual, upgrade using pip install -U python-telegram-bot. This release brings a few major improvements and structural changes, so prepare for a long changelog! 1️⃣ We added __slots__ to (almost) all classes. Head here for detailed info about slots. TL;DR: At least in CPython slots can reduce memory usage and improve performance by fixing which attributes an objects has. ⚠️ For backward compatibility we made sure that code like update.message.my_custom_attribute = 42 will continue to work. However, as adding custom attributes to predefined objects is bad practice anyway, this will raise warnings and we will remove support for this at some point, maybe already in v14. 2️⃣ With the introduction of python-telegram-bot-raw we've already made an effort to make a clear distinction between the raw API implementation and the powerful extensions offered by PTB. This release takes this development one step further by introducing a new class telegram.ext.ExtBot, which is a subclass of telegram.Bot. Functionality that extends the pure bot methods will be implemented in this class from now on. In this light, we also deprecated passing Defaults to telegram.Bot. If you want to use Defaults, please use ExtBot from now on. ℹ️ This may sound more severe than it is. If you just use Updater(TOKEN) to set up your bot, you will likely not notice this change at all. 3️⃣ We introduced a mechanism that allows you to specify the type of the context argument of the callbacks as well as the types of user/chat/bot_data. To get an idea how this works, please head to the docs of ContextTypes and have a look at the new example. 4️⃣ Everyone who's working with inline buttons and callback_data probably felt limited by the 64 characters limit at some point. Fear no more! This update brings a mechanism that allows you to pass arbitrary objects as callback data. This is done by giving each callback_data an unique ID, passing that ID to Telegram and inserting the callback_data again, when a button is received. This also ties in with persistence (see below). ℹ️ Because this is a rather advanced feature which might bring some pitfalls, please be sure to check out the wiki page as well as the example on the topic. 5️⃣ There are two updates to the persistence setup to be mentioned. Firstly, we added methods BasePersistence.get/update_callback_data and a corresponding store_callback_data argument, which defaults to False for now. Moreover, we have added methods BasePersistence.refresh_user/chat/bot_data, which will be called for each incoming update (but by default just pass). E.g. if your bot gets data from an external database, this allows you to keep the data up to date. Both the builtin PicklePersistence and DictPersistence handle get/update_callback_data, but pass on refresh_user/chat/bot_data. Finally, this release adds Filters.attachment and a pattern argument to ChosenInlineResultHandler. We know that this is a lot to take in, but we hope that the new features make your life easier and help you built more awesome bots. For the full list of changes and improvements, please see below. New Features: • Arbitrary callback_data (#1844) • Add ContextTypes & BasePersistence.refresh_user/chat/bot_data (#2262) • Add Filters.attachment (#2528) • Add pattern Argument to ChosenInlineResultHandler (#2517) Major Changes: • Add __slots__ (#2345) Minor changes, CI improvements, Doc fixes and Type hinting: • Doc Fixes (#2495, #2510 by Bas ten Berge) • Add max_connections Parameter to Updater.start_webhook (#2547 by GauthamramRavichandran) • Fix for Promise.done_callback (#2544) • Improve Code Quality (#2536, #2454) • Increase Test Coverage of CallbackQueryHandler (#2520) • Stabilize CI (#2522, #2537, #2541) • Fix send_phone_number_to_provider argument for Bot.send_invoice (#2527 by nkrivenko) • Handle Classes as Input for BasePersistence.replace/insert_bot (#2523) • Bump Tornado Version and Remove Workaround from #2067 (#2494)