Tishka17 / aiogram_dialog

GUI framework on top of aiogram
https://aiogram-dialog.readthedocs.io
Apache License 2.0
664 stars 103 forks source link

Separate callbacks for on_process_result #429

Open Makcal opened 6 days ago

Makcal commented 6 days ago

I have a dialog that can start several different dialogs, but is limited to have one on_process_result() callback. This is why to distinguish these calls I pass start_data in form of {"intent": "enter_name", "input": ...} and my callback looks like:

match start_data["intent"]:
    case "enter_name":
        # process input of the name field
        ...
    case "enter_text":
        # process input of the text field
        ...

This can produce long and complex callbacks. I wonder if there can be a cleaner way to process results. Thinking a while I've come up with two proposals:

  1. Pass a callback directly in a dialog's call:
    await manager.start(PromptSG.main, promt_params, callback=process_name)`
  2. Use a decorator to mark a function as a callback for a particular dialog:
    @dialog.callback_for(PromptDialog)
    def process_name(start_data, result, manager)
    ...
Tishka17 commented 6 days ago

In version 2.2 you can set on process result callback on window. This is not the same, but anyway, it can reduce size of function.

Makcal commented 5 days ago

Yeah, that's not the same, however it would be great to have clear separation for a window, e.g. for buttons that start dialogs