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-1.0.1.tar.gz
(5.2 kB
view details)
Built Distribution
File details
Details for the file aiogram3_form-1.0.1.tar.gz
.
File metadata
- Download URL: aiogram3_form-1.0.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3d32b7ad0d2aa2a3daaa97c878326e131a1f77a1457123c97ab8bd6bd93b3cd |
|
MD5 | b0e0107f32cb6d3f4f1be631b3799d0c |
|
BLAKE2b-256 | 3c1be87bafd7d46e63fef03b39141b846afff56556d06b9a860cfcd4aefb58b8 |
File details
Details for the file aiogram3_form-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: aiogram3_form-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c2bbcb22245128313a83341a1501b8bb6f26ee0525f28dc8ffdd69ca345c455 |
|
MD5 | 451b7d0658613fd5b8a171badadea7d1 |
|
BLAKE2b-256 | 018cca699732742a5b93fa3e0459d92f6ee8362b21823577cfc5e05be12fdfd2 |