-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from Tishka17/feature/groups
Multiuser chat
- Loading branch information
Showing
38 changed files
with
1,229 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
****************************************** | ||
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. | ||
|
||
Starting shared dialogs | ||
================================= | ||
|
||
When user sends message or other event not attached directly to some dialog, default stack is used. If you start dialogs in that stack, they can be accessed only by that user. So, the default stack in **personal**. | ||
|
||
To send a *shared* dialog from *personal*, you need to use other stacks. It can be ``aiogram_dialog.GROUP_STACK_ID``, other predefined string or starting via ``StartMode.NEW_STACK``. | ||
|
||
.. code-block:: python | ||
bg = dialog_manager.bg(stack_id=GROUP_STACK_ID) | ||
bg.start( | ||
MyStateGroup.MY_STATE, | ||
mode=StartMode.RESET_STACK, | ||
) | ||
If there are different topics in chat, stacks between them are isolated. To start dialog in different topic pass ``thread_id`` as ``.bg()`` argument | ||
|
||
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. | ||
|
||
.. code-block:: python | ||
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 | ||
=========== | ||
|
||
|
||
.. autoclass:: aiogram_dialog.AccessSettings | ||
|
||
|
||
.. autoclass:: aiogram_dialog.api.protocols.StackAccessValidator | ||
:members: is_allowed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
How are messages updated | ||
===================== | ||
=========================== | ||
|
||
ShowMode | ||
******************** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ where = ["src"] | |
|
||
[project] | ||
name = "aiogram_dialog" | ||
version = "2.1.0" | ||
version = "2.2.0a5" | ||
readme = "README.md" | ||
authors = [ | ||
{ name = "Andrey Tikhonov", email = "[email protected]" }, | ||
|
@@ -25,7 +25,7 @@ classifiers = [ | |
"Operating System :: OS Independent", | ||
] | ||
dependencies = [ | ||
'aiogram>=3.0.0', | ||
'aiogram>=3.5.0', | ||
'jinja2', | ||
'cachetools>=4.0.0,<6.0.0', | ||
'magic_filter', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ flake8-print | |
|
||
pytest | ||
pytest-asyncio | ||
pytest-repeat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from dataclasses import dataclass | ||
from typing import Any, List | ||
|
||
|
||
@dataclass | ||
class AccessSettings: | ||
user_ids: List[int] | ||
custom: Any = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
from typing import Union | ||
from dataclasses import dataclass | ||
from typing import Optional, Union | ||
|
||
from aiogram import Bot | ||
from aiogram.types import ( | ||
CallbackQuery, ChatJoinRequest, ChatMemberUpdated, Message, | ||
CallbackQuery, | ||
Chat, | ||
ChatJoinRequest, | ||
ChatMemberUpdated, | ||
Message, | ||
User, | ||
) | ||
|
||
from .update_event import DialogUpdateEvent | ||
|
||
ChatEvent = Union[ | ||
CallbackQuery, Message, DialogUpdateEvent, | ||
ChatMemberUpdated, ChatJoinRequest, | ||
CallbackQuery, | ||
ChatJoinRequest, | ||
ChatMemberUpdated, | ||
DialogUpdateEvent, | ||
Message, | ||
] | ||
|
||
|
||
@dataclass | ||
class EventContext: | ||
bot: Bot | ||
chat: Chat | ||
user: User | ||
thread_id: Optional[int] | ||
business_connection_id: Optional[str] | ||
|
||
|
||
EVENT_CONTEXT_KEY = "aiogd_event_context" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
__all__ = [ | ||
"DialogProtocol", | ||
"BaseDialogManager", "BgManagerFactory", "DialogManager", | ||
"CancelEventProcessing", "DialogProtocol", | ||
"BaseDialogManager", "BgManagerFactory", "DialogManager", "UnsetId", | ||
"MediaIdStorageProtocol", | ||
"MessageManagerProtocol", "MessageNotModified", | ||
"DialogProtocol", "DialogRegistryProtocol", | ||
"StackAccessValidator", | ||
] | ||
|
||
from .dialog import DialogProtocol | ||
from .manager import BaseDialogManager, BgManagerFactory, DialogManager | ||
from .dialog import CancelEventProcessing, DialogProtocol | ||
from .manager import ( | ||
BaseDialogManager, BgManagerFactory, DialogManager, UnsetId, | ||
) | ||
from .media import MediaIdStorageProtocol | ||
from .message_manager import MessageManagerProtocol, MessageNotModified | ||
from .registry import DialogRegistryProtocol | ||
from .stack_access import StackAccessValidator |
Oops, something went wrong.