diff --git a/aiogram/fsm/context.py b/aiogram/fsm/context.py index 53a8ea46..2bae3607 100644 --- a/aiogram/fsm/context.py +++ b/aiogram/fsm/context.py @@ -20,6 +20,9 @@ class FSMContext: async def get_data(self) -> Dict[str, Any]: return await self.storage.get_data(key=self.key) + async def get_value(self, key: str) -> Any: + return await self.storage.get_value(key=self.key, data_key=key) + async def update_data( self, data: Optional[Dict[str, Any]] = None, **kwargs: Any ) -> Dict[str, Any]: diff --git a/aiogram/fsm/storage/base.py b/aiogram/fsm/storage/base.py index 52cb62f2..ddfcacf3 100644 --- a/aiogram/fsm/storage/base.py +++ b/aiogram/fsm/storage/base.py @@ -64,6 +64,17 @@ class BaseStorage(ABC): """ pass + async def get_value(self, key: StorageKey, data_key: str) -> Any: + """ + Get selected value by key in current data + + :param key: storage key + :param data_key: key of selected data + :return: value of current data by key + """ + current_data = await self.get_data(key=key) + return current_data[data_key] + async def update_data(self, key: StorageKey, data: Dict[str, Any]) -> Dict[str, Any]: """ Update date in the storage for key (like dict.update)