-
Notifications
You must be signed in to change notification settings - Fork 5.7k
v13 #1982
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
v13 #1982
Conversation
2a9a5b0
to
1fdc197
Compare
b3e9be1
to
b7e635b
Compare
API Keyword ArgumentsPre-v12 the Bot methods accepted arbitrarty keyword argument via the bot.send_message(..., custom_kwarg=42) need to be changed to bot.send_message(..., api_kwargs={'custom_kwarg': 42}) As PTB is currently up to date wtih the Telegram API, this shouldn't affect your code in the most cases. If it does, it means that you had a typo somewhere. |
JobQueue RefactoredPreviously, PTB implemented the scheduling of tasks in the But what does this mean for you in detail? If you're scheduling tasts vanilla style as e.g. context.job_queue.run_once(callback, when) you will only have to change the handling of timezones, or even nothing at all. In fact, everything covered in this wiki article will work unchanged expect for timezones. So before bothering to read on, just try to run you bot - it most cases it will still work. However, there are some more advanced things, that changed. Handling of timezonesThe Changes in advanced schedulingLeveraging the APScheduler library brings both some perks in terms of new features as well as some breaking changes. Please keep in mind:
That said, here are the perks and changes: New features
ChangesMost importantly, the There are some other minor changes, most of which will most likely not affect you. For details, please see the documentation of Setting up a
|
Update wiki:
Storing BotsAs of v13, persistence will try to replace Persistence of BotsStoring
In most cases, this won't directly affect you. Note however, that changing the used bot token may lead to e.g. *Okay, almost all, For the limitations, see |
Rich Comparisonv13 adds rich comparison to more Telegram objects. This means that e.g. Special note on
|
1e29c1a
to
7867b9b
Compare
Deprecation of
|
Update WikiThis part on custom filters must be updated. Refactoring of FiltersIn order to reduce confusion over the arguments of the
both inheriting from If you have custom filters inheriting from |
dcf7328
to
ad30a8f
Compare
Deprecation of old handler APIThe context-based API introduced in v12 is now the default, i.e. the |
Dropping support for Python 3.5As Python 3.5 reaches/reached its end of life on ~2020-09-13, v13 drops support for Python 3.5. More precisely, some Python 3.6+-only features are introduced, making PTB incompitable with Python 3.5 as of v13. |
be9e5d1
to
3993250
Compare
Defaults.tzinfoUpdate example in wiki: import pytz
import datetime as dtm
from telegram import ParseMode
from telegram.ext import Updater, MessageHandler, Filters, Defaults
def job(context):
chat_id = context.job.context
local_now = dtm.datetime.now(context.bot.defaults.tzinfo)
utc_now = dtm.datetime.utcnow()
text = 'Running job at {} in timezone {}, which equals {} UTC.'.format(
local_now, context.bot.defaults.tzinfo, utc_now
)
context.bot.send_message(chat_id=chat_id, text=text)
def echo(update, context):
# Send with default parse mode
update.message.reply_text('<b>{}</b>'.format(update.message.text))
# Override default parse mode locally
update.message.reply_text('*{}*'.format(update.message.text), parse_mode=ParseMode.MARKDOWN)
update.message.reply_text('*{}*'.format(update.message.text), parse_mode=None)
# Schedule job
context.job_queue.run_once(job, dtm.datetime.now() + dtm.timedelta(seconds=1),
context=update.effective_chat.id)
def main():
"""Instantiate a Defaults object"""
defaults = Defaults(parse_mode=ParseMode.HTML, tzinfo=pytz.timezone('Europe/Berlin'))
"""Start the bot."""
updater = Updater("TOKEN", use_context=True, defaults=defaults)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on non command text message - echo the message on Telegram
dp.add_handler(MessageHandler(Filters.text & ~Filters.command, echo))
# Start the Bot
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main() |
3247477
to
b7293a4
Compare
Deprecation of
|
9252b0f
to
bce39cc
Compare
pytest fail is unrelated and codecov was expected. ready for merge 🕺 |
* Unify kwargs handling in Bot methods * Remove Request.get, make api_kwargs an explicit argument, move note to head of Bot class * Fix test_official * Update get_file methods
* First go on refactoring JobQueue * Temporarily enable tests for the v13 branch * Work on tests * Temporarily enable tests for the v13 branch * Increase coverage * Remove JobQueue.tick() * Address review * Temporarily enable tests for the v13 branch * Address review * Dispatch errors * Fix handling of job_kwargs * Remove possibility to pass a Bot to JobQueue
* Refactor persistence of bots * Use BP.set_bot in Dispatcher * Add documentation
* Make most objects comparable * ID attrs for PollAnswer * fix test_game * fix test_userprofilephotos * update for API 4.7 * Warn on meaningless comparisons * Update for API 4.8 * Address review * Get started on docs, update Message._id_attrs * Change PollOption & InputLocation * Some more changes * Even more changes
* Refactor handling of `default_quote` * Make it a breaking change * Pickle a bots defaults * Temporarily enable tests for the v13 branch * Temporarily enable tests for the v13 branch * Refactor handling of kwargs in Bot methods (#1924) * Unify kwargs handling in Bot methods * Remove Request.get, make api_kwargs an explicit argument, move note to head of Bot class * Fix test_official * Update get_file methods * Refactor JobQueue (#1981) * First go on refactoring JobQueue * Temporarily enable tests for the v13 branch * Work on tests * Temporarily enable tests for the v13 branch * Increase coverage * Remove JobQueue.tick() * Address review * Temporarily enable tests for the v13 branch * Address review * Dispatch errors * Fix handling of job_kwargs * Remove possibility to pass a Bot to JobQueue * Refactor persistence of Bot instances (#1994) * Refactor persistence of bots * User BP.set_bot in Dispatcher * Temporarily enable tests for the v13 branch * Add documentation * Add warning to Updater for passing both defaults and bot * Address review * Fix test
* Refactor handling of message vs update filters * address review
For the moment I'm just here so that PRs to v13 can be properly checked by Codacy and Codecov.
When v13 is ready, I can be merged. For now, comment here to gather info for the coming v13 transition guide.
The PRs merged into v13: