Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty work with state #1388

Open
dop3file opened this issue Jan 2, 2024 · 4 comments
Open

Pretty work with state #1388

dop3file opened this issue Jan 2, 2024 · 4 comments
Labels
enhancement Make it better!

Comments

@dop3file
Copy link

dop3file commented Jan 2, 2024

aiogram version

3.x

Problem

I've been writing telegram bots on aiogram for quite some time.
I like everything, but I don’t really like working with states. You have to write a lot of typical code.
You must describe the state model, and then write handlers for each item.
I believe that this can be implemented a little more convenient for developers

Possible solution

I believe that it is possible to write a wrapper over the existing state system that can process a state in one line

Alternatives

I know about state scenes in 3.x, but I want something a little different

Code example

# For example:
# We init model with data types and other additional information(custom validators for users answers and other)
class Form(StatesGroup):
    name: str = State(custom_validator) # custom validator is a link to a function that returns a validator of the user's response
    age: int = State(custom_validator)


@form_router.message(CommandStart())
async def command_start(message: Message, state: FSMContext) -> None:
    name = await Form.name.process_state()
    await message.answer(f"Your name is {name}")

# After we work with user input value without typical code and boring work with states.

Additional information

If I'm wrong on some issues, please correct me, this is my first micro contribution to open source, sorry if something is wrong

@dop3file dop3file added the enhancement Make it better! label Jan 2, 2024
@JrooTJunior
Copy link
Member

Just look at the Scenes documentation: https://docs.aiogram.dev/en/dev-3.x/dispatcher/finite_state_machine/scene.html
Also check at the examples directory in the repository

We already have simplified mechanism to work with states - Scenes.

@JrooTJunior
Copy link
Member

Oh, i see "alternative" section in your message, i dont think so this is a god idea (from the architecture side)

@dop3file
Copy link
Author

dop3file commented Jan 2, 2024

Oh, i see "alternative" section in your message, i dont think so this is a god idea (from the architecture side)

Yes, this may not be the best idea from the point of view of the architecture of the framework, but from the point of view of usability, there are many conveniences in this.
Can I try to develop this functionality and send it as a PR?
I can encapsulate this logic in a separate module, I think other core functionality will not suffer because of this

@JrooTJunior
Copy link
Member

Of course! You can do whatever you want and create pull requests to this repository, useful ideas can be merged into library

Welcome to open-source project :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Make it better!
Projects
None yet
Development

No branches or pull requests

2 participants