diff --git a/src/aiogram_dialog/widgets/kbd/__init__.py b/src/aiogram_dialog/widgets/kbd/__init__.py index 07b67b98..ac9cda7e 100644 --- a/src/aiogram_dialog/widgets/kbd/__init__.py +++ b/src/aiogram_dialog/widgets/kbd/__init__.py @@ -29,6 +29,9 @@ "ScrollingGroup", "RequestContact", "RequestLocation", + "RequestChat", + "RequestUser", + "RequestUsers", "Checkbox", "ManagedCheckbox", "Select", @@ -62,7 +65,7 @@ PrevPage, SwitchPage, ) -from .request import RequestContact, RequestLocation +from .request import RequestContact, RequestLocation, RequestChat, RequestUser, RequestUsers from .scrolling_group import ScrollingGroup from .select import ( ManagedMultiselect, diff --git a/src/aiogram_dialog/widgets/kbd/request.py b/src/aiogram_dialog/widgets/kbd/request.py index 026086c6..bd119942 100644 --- a/src/aiogram_dialog/widgets/kbd/request.py +++ b/src/aiogram_dialog/widgets/kbd/request.py @@ -1,26 +1,32 @@ from typing import Callable, Dict, Union -from aiogram.types import KeyboardButton +from aiogram.types import ( + KeyboardButton, + KeyboardButtonRequestChat, + KeyboardButtonRequestUser, + KeyboardButtonRequestUsers, +) from aiogram_dialog.api.internal import RawKeyboard from aiogram_dialog.api.protocols import DialogManager from aiogram_dialog.widgets.text import Text + from .base import Keyboard class RequestContact(Keyboard): def __init__( - self, - text: Text, - when: Union[str, Callable, None] = None, + self, + text: Text, + when: Union[str, Callable, None] = None, ): super().__init__(when=when) self.text = text async def _render_keyboard( - self, - data: Dict, - manager: DialogManager, + self, + data: Dict, + manager: DialogManager, ) -> RawKeyboard: return [ [ @@ -34,17 +40,17 @@ async def _render_keyboard( class RequestLocation(Keyboard): def __init__( - self, - text: Text, - when: Union[str, Callable, None] = None, + self, + text: Text, + when: Union[str, Callable, None] = None, ): super().__init__(when=when) self.text = text async def _render_keyboard( - self, - data: Dict, - manager: DialogManager, + self, + data: Dict, + manager: DialogManager, ) -> RawKeyboard: return [ [ @@ -54,3 +60,81 @@ async def _render_keyboard( ), ], ] + + +class RequestChat(Keyboard): + def __init__( + self, + text: Text, + RequestButton: KeyboardButtonRequestChat, + when: Union[str, Callable, None] = None, + ): + super().__init__(when=when) + self.text = text + self.RequestButton = RequestButton + + async def _render_keyboard( + self, + data: Dict, + manager: DialogManager, + ) -> RawKeyboard: + return [ + [ + KeyboardButton( + text=await self.text.render_text(data, manager), + request_chat=self.RequestButton, + ), + ], + ] + + +class RequestUser(Keyboard): + def __init__( + self, + text: Text, + RequestButton: KeyboardButtonRequestUser, + when: Union[str, Callable, None] = None, + ): + super().__init__(when=when) + self.text = text + self.RequestButton = RequestButton + + async def _render_keyboard( + self, + data: Dict, + manager: DialogManager, + ) -> RawKeyboard: + return [ + [ + KeyboardButton( + text=await self.text.render_text(data, manager), + request_user=self.RequestButton, + ), + ], + ] + + +class RequestUsers(Keyboard): + def __init__( + self, + text: Text, + RequestButton: KeyboardButtonRequestUsers, + when: Union[str, Callable, None] = None, + ): + super().__init__(when=when) + self.text = text + self.RequestButton = RequestButton + + async def _render_keyboard( + self, + data: Dict, + manager: DialogManager, + ) -> RawKeyboard: + return [ + [ + KeyboardButton( + text=await self.text.render_text(data, manager), + request_users=self.RequestButton, + ), + ], + ]