In the process of researching the aiogram 3 library, the question arose:
let's assume that we have a telegram bot, after creating the Dispatcher object, we added data to the workflow_data dictionary:
dp = Dispatcher()
dp.workflow_data.update({
'bt': bot,
'cfg': config,
'test': 1
})
then we start the bot with dp.start_pooling(bot)
the bot has a user called admin, his id is entered in the project's configuration file. in the project we have the handlers package in which we have:
admin.py - all handlers for admin, these handlers use admin_router
user.py - - all the handlers for non-admin users, these handlers use user_router
so, in the project we have two Routers: admin_router and user_router
at the same time, in the project for each type of user (admin, user) we have the corresponding filters.
let's assume that in admin.py we have a handler for the command:
@admin_router.message(Command("test"))
async def admin_test(message: Message):
********
I try in the admin_test function to change the value for the 'test' key in workflow_data as follows:
@admin_router.message(Command("test"))
async def admin_test(message: Message):
admin_router.parent_router.workflow_data["test"] = 1000
await message.answer("****")
the value changes only locally, within this handler.
if, however, I try to access the value for the 'test' key in workflow_data from another handler, for example in a handler from user.py
@user_router.message()
async def user_echo(message: Message, test):
print(user_router.parent_router.workflow_data["test"] )
I get the value = 1, which means nothing has changed globally.
QUESTION: how can I globally change the value for the 'test' key in workflow_data?
can someboby help me please to solve or ..