Open gavrilikhin-d opened 4 months ago
Yes, though it is not documented yet, you can check in /examples/mega
Maybe I do something wrong, but adding:
markup_factory=ReplyKeyboardFactory(
input_field_placeholder=Const("test"),
resize_keyboard=True
)
doesn't do anything
That should convert all buttons in widget to reply buttons and set placeholder text in client input field.
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.`
@m-novitsky are you using CallbackAnswerMiddleware?
@Tishka17 No, I don't use it, but thanks, I understood what needs to be done :)
I am not sure. Probably, you just do not need to call answer
for events processed by dialogs
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
.
Please, share the full traceback
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.
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,
),
I see exactly the call of CallbackAnswerMiddlware.
https://github.com/aiogram/aiogram/blob/dev-3.x/aiogram%2Futils%2Fcallback_answer.py#L174
Yes, I see. Bingo, I found it! Thanks a lot!
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
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.
Is it possible to add ReplyKeyboardMarkup to dialog's window?