Skip to content

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

@IlyaBizyaev

Description

@IlyaBizyaev

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions