Skip to content
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

Message.wait_for_click and Client.listen will never return the expected CallbackQuery #31

Open
WhaleFell opened this issue Sep 10, 2023 · 3 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@WhaleFell
Copy link
Contributor

message.wait_for_click() Even though clicking the button triggers the callback, it never makes him return. Unless a timeout triggers an error.

The same occurs in message.chat.listen when listener_type=ListenerTypes.CALLBACK_QUERY expects to receive a callback from the user pressing a button.

I had a feeling this was an issue and wondered if it could be reproduced on your end.

thanks for the reply. 😃

image

@usernein
Copy link
Owner

Hello there! This issue in specific puzzled me!

At first was unable to reproduce the error with either pyromod v2 or v3. Message.wait_for_click always worked for me:





I had the feeling the the problem was client.listen being unable to process the callback query. Then i realized it depends on CallbackQueryHandler to be executed and it won't execute if you don't have any callback_query handler on your code.

It means that if you don't have any @Client.on_callback_query on your code, pyromod won't be able to intercept the CallbackQuery updates and consequently won't deliver them to Message.wait_for_click.

And i actually tested it: i tried removing all my callback_query handlers from the code and Bingo!: wait_for_click stopped working.

Solution

It will work again if you add at least one callback_query handler on your code. It does not even need to handle the CallbackQuery, it should just exist. For instance, you can add the following code into your plugins and it will make wait_for_click work as normal:

@Client.on_callback_query(filters.regex('wont ever match'))
async def on_callback():
    pass

I don't see this as a bug by the way, it's more like a pyromod inconvenient requirement which may be improved at the future. But this totally must be documented. Thanks for reporting that!

@usernein usernein changed the title message.wait_for_click() Even though clicking the button triggers the callback, it never makes him return. Unless a timeout triggers an error. Message.wait_for_click and Client.listen will never return the expected CallbackQuery Oct 30, 2023
@usernein usernein added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 30, 2023
@jusidama18
Copy link
Contributor

@usernein i'm not using any Client.on_callback_query and it still works fine

@covein
Copy link

covein commented Jan 1, 2024

Hello there! This issue in specific puzzled me!

At first was unable to reproduce the error with either pyromod v2 or v3. Message.wait_for_click always worked for me:

I had the feeling the the problem was client.listen being unable to process the callback query. Then i realized it depends on CallbackQueryHandler to be executed and it won't execute if you don't have any callback_query handler on your code.

It means that if you don't have any @Client.on_callback_query on your code, pyromod won't be able to intercept the CallbackQuery updates and consequently won't deliver them to Message.wait_for_click.

And i actually tested it: i tried removing all my callback_query handlers from the code and Bingo!: wait_for_click stopped working.

Solution

It will work again if you add at least one callback_query handler on your code. It does not even need to handle the CallbackQuery, it should just exist. For instance, you can add the following code into your plugins and it will make wait_for_click work as normal:

@Client.on_callback_query(filters.regex('wont ever match'))
async def on_callback():
    pass

I don't see this as a bug by the way, it's more like a pyromod inconvenient requirement which may be improved at the future. But this totally must be documented. Thanks for reporting that!

Thanks! This solves my problem too!

BTW, does the new project Hydrogram still has the wait_for_click function?
I want to transfer the hydrogram ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants