Setting multiple states for a user on aiogram 3.x?

898 views Asked by At

I am working on Telegram Bot, using aiogram 3.1.1 and its FSM. I did define UserState, that can have two states

class UserState(StatesGroup):
    Processing = State()
    Dialogue = State()

This is the way how i filter users, that are currently waiting for an answer from bot or have the dialogue mode enabled.

And it works fine. But i encounter an issue, when i want to have another independent StatesGroup for users. For example:

class ModeState(StatesGroup): 
    Voice = State() 
    Text = State() 

Using this i want to filter if the user wants to receive answers from bot via text message or via voice message. Those StatesGroups are meant to be independent, meaning that the user can have "Voice" and "Dialogue" states at once.

I did try giving a person either "Voice" or "Text" status at the start of the conversation by asking him a question via the /start command. Then the user could choose if he wants a dialogue mode or not (should the bot set "Dialogue" state). For filtering this i've built two functions, they went smth like:

@text_msg_router.message(ModeState.Text)
async def text_message_handler(message: Message, state: FSMContext):

and

@text_msg_router.message(UserState.Dialogue, ModeState.Text)
async def text_message_handler(message: Message, state: FSMContext):

The problem is - the second function does not seem to be working properly. It seems like a user in aiogram FSM can only have one state a time, even if multiple states are in different StateGroups.

So did i get something wrong? And if, sadly, i am right - what are the common solutions for this task?

0

There are 0 answers