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

Run a handler for all messages, then another only for commands #32

Open
IlyaBizyaev opened this issue Nov 17, 2024 · 1 comment
Open

Comments

@IlyaBizyaev
Copy link

IlyaBizyaev commented Nov 17, 2024

For a Telegram bot that manages chats, I need to be able to:

  • handle any "common" messages to the chat to perform some moderation;
  • if the message also happens to be a command, then run the corresponding command handler.

Not running chat_handler for command invocations is not an option because it enables malicious actors to hide bad messages under command prefixes.

Is it currently possible to achieve this with dptree? I thought of using filter_async, which would have an added benefit of not running command handlers at all if the message was deleted, but it appears that I would need something like try_filter_async (#26) for proper error handling (Telegram API, database). Also, it this existed, would Teloxide be able to pass errors from the fallible filter to Dispatcher's error_handler?

@IlyaBizyaev
Copy link
Author

For context, I previously used python-telegram-bot's handler groups for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant