A library to create forms in aiogram3
Project description
aiogram3-form
A library to create forms in aiogram3
pip install aiogram3-form
Example
import asyncio
from aiogram import Bot, Dispatcher, F, Router, types
from aiogram3_form import Form, FormField
from aiogram.fsm.context import FSMContext
bot = Bot(token="YOUR_TOKEN")
dispatcher = Dispatcher()
router = Router()
dispatcher.include_router(router)
class NameForm(Form, router=router):
first_name: str = FormField(enter_message_text="Enter your first name please")
second_name: str = FormField(
enter_message_text="Enter your second name please",
filter=(F.text.len() > 10) & F.text,
)
age: int = FormField(
enter_message_text="Enter age as integer",
error_message_text="Age should be numeric!",
)
@NameForm.submit()
async def name_form_submit_handler(form: NameForm, event_chat: types.Chat):
# handle form data
# also supports aiogram standart DI (e. g. middlewares, filters, etc)
await form.answer(
f"{form.first_name} {form.second_name} of age {form.age} in chat {event_chat.title}"
)
@router.message(F.text == "/form")
async def form_handler(_, state: FSMContext):
await NameForm.start(bot, state) # start your form
async def main():
await dispatcher.start_polling(bot)
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiogram3_form-0.6.2.tar.gz
(5.1 kB
view details)
Built Distribution
File details
Details for the file aiogram3_form-0.6.2.tar.gz
.
File metadata
- Download URL: aiogram3_form-0.6.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/21.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be9ea100057d501c3c1b6d8bdd696610a14573f41660abeb86d3dc514330d34a |
|
MD5 | 4875c93c0c4a9fdfd89252f57fb29155 |
|
BLAKE2b-256 | 8938d9ebcabea551cbe5c4c277c9245ac7f9ed8d6488b90b67d6b488e3f6fcd1 |
File details
Details for the file aiogram3_form-0.6.2-py3-none-any.whl
.
File metadata
- Download URL: aiogram3_form-0.6.2-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/21.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f150516afe38454aa4750ef88e281010d60ddf5b73171d487966057053ba5d1 |
|
MD5 | 5d0603b62b486b64242daa6d13553796 |
|
BLAKE2b-256 | 619c83b6077cac7b0969fea4ea88dd994ed357a4da26660cf1965ef1c06e3e8c |