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.4.tar.gz
(5.1 kB
view details)
Built Distribution
File details
Details for the file aiogram3_form-0.6.4.tar.gz
.
File metadata
- Download URL: aiogram3_form-0.6.4.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.6 Darwin/21.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f04e22c66841c6fa3f095d995ed97b3f6ba21846be5bff1ce784c03ecb2c55c |
|
MD5 | b8ae174bca2dcb42f45212dcf9352188 |
|
BLAKE2b-256 | 0bf17221ac0bf871b6146db9788a8537730a52ade413b63123e96458d68e8114 |
File details
Details for the file aiogram3_form-0.6.4-py3-none-any.whl
.
File metadata
- Download URL: aiogram3_form-0.6.4-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.6 Darwin/21.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66a721c9415644a5a0dd79a5e0fe1a5c634b3e043602c413d710213b9ed76f26 |
|
MD5 | 4e87e462133a1fd86597aae4b952dde7 |
|
BLAKE2b-256 | fa98ec0cae439121f38e328dde85bca7abbafc3d628b2400749a6d146303e1d7 |