Groups and business chats¶
Warning
Telegram has very strong limitations on amount of operations in groups, so it is not recommended to use interactive menus there
Support of groups, supergroups and business chats is based on usage of additional dialog stacks.
Limiting access¶
To set limitations on who can interact with that dialog, you can pass AccessSettings when starting new dialog. If not access settings are set, they will be copied from last opened dialog in stack.
dialog_manager.start(
MyStateGroup.MY_STATE,
mode=StartMode.RESET_STACK,
access_settings=AccessSettings(user_ids=[123456]),
)
In this example, pre-defined group stack will be used and new dialogs will be available only for user with id 123456. If later user clicks on a specific dialog, stack of that dialog is used, so you won’t need to call .bg()
Currently, only check by user.id is supported, but you bring your own logic implementing StackAccessValidator protocol and passing it so setup_dialogs function.
Handling forbidden interactions¶
If user is not allowed to interact with dialog his event is not routed to dialogs and you can handle it in aiogram. To filter this situation you can rely on aiogd_stack_forbidden key of middleware data.
Classes¶
- class aiogram_dialog.AccessSettings(user_ids: list[int], custom: Any = None)¶
- Parameters:
user_ids (list[int])
custom (Any)
- class aiogram_dialog.api.protocols.StackAccessValidator(*args, **kwargs)¶
- abstractmethod async is_allowed(stack, context, event, data)¶
Check if current user is allowed to interactor with dialog.
- Parameters:
stack (Stack)
context (Context | None)
event (CallbackQuery | ChatJoinRequest | ChatMemberUpdated | DialogUpdateEvent | ErrorEvent | Message)
data (dict)
- Return type:
bool