8000 CallbackQueryHandler to support filtering game_short_name · Issue #4269 · python-telegram-bot/python-telegram-bot · GitHub
[go: up one dir, main page]

Skip to content

CallbackQueryHandler to support filtering game_short_name #4269

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

Closed
jainamoswal opened this issue May 22, 2024 · 3 comments · Fixed by #4353
Closed

CallbackQueryHandler to support filtering game_short_name #4269

jainamoswal opened this issue May 22, 2024 · 3 comments · Fixed by #4353

Comments

@jainamoswal
Copy link
Contributor
jainamoswal commented May 22, 2024

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

Currently, the CallbackQueryHandler in the library only checks the .data attribute when handling callback queries (ref). This presents a limitation as it doesn't support regex filtering handling clicks on buttons associated with CallbackGame. When a user clicks on a CallbackGame button, the .data attribute is None, causing the CallbackQueryHandler's regex pattern match to fail if it is set.

Describe the solution you'd like

I think changing this line to

callback_data = update.callback_query.data or update.callback_query.game_short_name

would solve this limitation.

Describe alternatives you've considered

Currently I manage to overcome this by handling all callbacks in one handler without pattern match and then using if else with .game_short_name attribute

Additional context

No response

@Poolitzer Poolitzer changed the title CallbackQueryHandler to support Games CallbackQueryHandler to support filtering game_short_name May 22, 2024
@Poolitzer
Copy link
Member
Poolitzer commented May 22, 2024
edited
Loading

Hi I rewrote it a bit to make it more clear its about providing filtering, as you wrote in the end of the issue, a handler without a pattern set handles that update just fine.

I am fine with adding a filter attribute for that in the same function as pattern, I don't think changing the behavior of the argument as you describe is the best way, I would rather see a new argument introduced.

@Bibo-Joshi
Copy link
Member

Hey.

I am fine with adding a filter attribute for that in the same function as pattern, I don't think changing the behavior of the argument as you describe is the best way, I would rather see a new argument introduced.

@Pooolitzer I guess you mean an interface like CQH(pattern=…, game_patterm=…) here? then we would the behavior

  • CQH(pattern=None, game_patterm=None) handles any CQ → backward compatible
  • CQH(pattern=pattern, game_patterm=None) handles only CQs with .data → backward compatible
  • CQH(pattern=None, game_patterm=pattern) handles only CQs with .game_short_name. → still backward compatible since game_pattern defaults to None`
  • CQH(pattern=pattern, game_patterm=game_pattern) handles only CQs with matching .data xor matching .game_short_name → also backward compatible since .data and .game_short_name are mutually exclusive

I vote +0 on this, i.e. I welcome a PR, but don't see a need for the PTB dev team to work on this actively

@jainamoswal
Copy link
Contributor Author

Hey @Bibo-Joshi, I would like to create a PR for this.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0