Added impementation of "prefallbacks" list.#2764
Added impementation of "prefallbacks" list.#2764david-shiko wants to merge 2 commits intopython-telegram-bot:v14from david-shiko:patch-1
Conversation
Imagine you have such CH:
```
ch = tg_ext.ConversationHandler(
entry_points=[
tg_ext.CommandHandler("start", callback=lambda *args, **kwargs: 0)],
states={
0: [
tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"),
callback=lambda *args, **kwargs: 1)],
1: [
tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"),
callback=lambda *args, **kwargs: 2)],
2: [
tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"),
callback=lambda *args, **kwargs: -1)],
},
fallbacks=[
tg_ext.CommandHandler("cancel", callback=lambda *args, **kwargs: -1),
])
```
Here you should apply `& ~Filter` for every handler in `states` to prevent catching a `cancel` command.
But it can be easily avoided by adding list of handlers that should to trigger before any another update.
Forget default value (`[]`) for `prefallbacks`
|
Hi. Thanks for this interesting proposal! We'll definitely have a closer look at it - however, that might take a while (The recent API update has priority and we're slowly working on the large v14 project). In the meantime, you can make your life a bit easier by defining a filter shortcut e.g. as |
|
Yeah, I thought about |
yes, I've noticed ;) The crucial part would be to integrate them into |
5c26c91 to
74c4270
Compare
Imagine you have such CH:
Here you should apply
& ~Filterfor every handler instatesto prevent catching acancelcommand.But it can be easily avoided by adding list of handlers that should to trigger before any another update.
Please look at this implementation of "prefallbacks". This is directly from my personal code, I have used it for a while and no encountered with errors.