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

ReplyKeyboardMarkup support #418

Open
gavrilikhin-d opened this issue Jul 23, 2024 · 15 comments
Open

ReplyKeyboardMarkup support #418

gavrilikhin-d opened this issue Jul 23, 2024 · 15 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation question Further information is requested

Comments

@gavrilikhin-d
Copy link

Is it possible to add ReplyKeyboardMarkup to dialog's window?

@Tishka17
Copy link
Owner

Yes, though it is not documented yet, you can check in /examples/mega

@gavrilikhin-d
Copy link
Author

Maybe I do something wrong, but adding:

        markup_factory=ReplyKeyboardFactory(
            input_field_placeholder=Const("test"),
            resize_keyboard=True
        )

doesn't do anything

@Tishka17
Copy link
Owner

That should convert all buttons in widget to reply buttons and set placeholder text in client input field.

@Tishka17 Tishka17 added the question Further information is requested label Jul 29, 2024
@Tishka17 Tishka17 added the documentation Improvements or additions to documentation label Aug 16, 2024
@m-novitsky
Copy link

One more thing. If we convert all widget buttons to reply buttons, then when we click on a button, it works as it should. But an exception is thrown in the bot log:
`...

File ".../.venv/lib/python3.12/site-packages/aiogram/utils/callback_answer.py", line 206, in answer
return event.answer(
^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/aiogram_dialog/api/internal/fake_data.py", line 16, in answer
raise ValueError(
ValueError: This callback query is generated from ReplyButton click. Support of .answer() call is impossible.`

@Tishka17
Copy link
Owner

Tishka17 commented Sep 5, 2024

@m-novitsky are you using CallbackAnswerMiddleware?

@m-novitsky
Copy link

@Tishka17 No, I don't use it, but thanks, I understood what needs to be done :)

@Tishka17
Copy link
Owner

Tishka17 commented Sep 5, 2024

I am not sure. Probably, you just do not need to call answer for events processed by dialogs

@m-novitsky
Copy link

I don't even call an answer. In my case, I just have 2 buttons: calling the mini-app and Cancel. An exception is thrown when clicking Cancel.

@Tishka17
Copy link
Owner

Tishka17 commented Sep 5, 2024

Please, share the full traceback

@m-novitsky
Copy link

ValueError: This callback query is generated from ReplyButton click. Support of `.answer()` call is impossible.
Traceback (most recent call last):
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/dispatcher.py", line 309, in _process_update
    response = await self.feed_update(bot, update, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/dispatcher.py", line 158, in feed_update
    response = await self.update.wrap_outer_middleware(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/middlewares/error.py", line 25, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/middlewares/user_context.py", line 56, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/fsm/middleware.py", line 42, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "bot/middlewares/logging.py", line 203, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "bot/middlewares/database.py", line 24, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "bot/middlewares/db_user.py", line 38, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram_dialog/manager/manager_middleware.py", line 77, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/event/telegram.py", line 121, in trigger
    return await wrapped_inner(event, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/event/handler.py", line 43, in call
    return await wrapped()
           ^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/dispatcher.py", line 276, in _listen_update
    return await self.propagate_event(update_type=update_type, event=event, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 142, in propagate_event
    return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "bot/middlewares/throttling.py", line 33, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/utils/i18n/middleware.py", line 74, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram_dialog/context/intent_middleware.py", line 128, in process_message
    return await router.propagate_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 142, in propagate_event
    return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/utils/i18n/middleware.py", line 74, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram_dialog/context/intent_middleware.py", line 186, in process_callback_query
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram_dialog/manager/manager_middleware.py", line 77, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 137, in _wrapped
    return await self._propagate_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 170, in _propagate_event
    response = await router.propagate_event(update_type=update_type, event=event, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 142, in propagate_event
    return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 137, in _wrapped
    return await self._propagate_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 170, in _propagate_event
    response = await router.propagate_event(update_type=update_type, event=event, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 142, in propagate_event
    return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 137, in _wrapped
    return await self._propagate_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 162, in _propagate_event
    response = await observer.trigger(event, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/dispatcher/event/telegram.py", line 121, in trigger
    return await wrapped_inner(event, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/utils/callback_answer.py", line 174, in __call__
    await self.answer(event, callback_answer)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram/utils/callback_answer.py", line 206, in answer
    return event.answer(
           ^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/aiogram_dialog/api/internal/fake_data.py", line 16, in answer
    raise ValueError(
ValueError: This callback query is generated from ReplyButton click. Support of `.answer()` call is impossible.

@m-novitsky
Copy link

Part of code:

 Window(
        Format(_("Start mini app to input init data")),
        MessageInput(parse_data, content_types=[types.ContentType.WEB_APP_DATA]),
        WebApp(
            text=Format(_("Init Data")),
            url=Format(settings.WEB_APP_URL + "?locale={current_locale}"),  # type: ignore[operator]
        ),
        Cancel(Format(_("Finish")), on_click=False),
        state=BgDialogSG.init_data,
        markup_factory=ReplyKeyboardFactory(
            resize_keyboard=True,
            one_time_keyboard=False,
        ),
        getter=get_data,
    ),

@Tishka17
Copy link
Owner

Tishka17 commented Sep 6, 2024

I see exactly the call of CallbackAnswerMiddlware.

https://github.com/aiogram/aiogram/blob/dev-3.x/aiogram%2Futils%2Fcallback_answer.py#L174

@m-novitsky
Copy link

Yes, I see.
Bingo, I found it!
Thanks a lot!

@Tishka17
Copy link
Owner

Tishka17 commented Sep 6, 2024

I guess I can implement some workaround for that, but simplest way for you now is to register that middleware not on dispatcher, but only on routers with normal handlers

@Tishka17 Tishka17 added the bug Something isn't working label Sep 6, 2024
@m-novitsky
Copy link

Yes, I think this is the right way. But in my case, this middleware is not needed at all. So the issue is resolved, thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants