A Python library to handle steps in aiogram framework.
Project description
aiostep
aiostep is a powerful extension library for aiogram, designed to simplify and enhance the process of building Telegram bots in Python. It introduces intuitive methods for direct user interactions and streamlined conversation flow management.
Key Features
- Direct Question Handling: Allows the bot to ask users questions and wait for their responses directly within a handler.
- Next Step Registration: Enables the registration of subsequent steps to handle user responses in a sequence.
Installation
To use aiostep in your project, simply install it with the following command:
pip install -U aiostep
Quick Start
Middleware Integration
- To use aiostep, add the Listen middleware to your dispatcher:
from aiogram import Dispatcher
from aiostep import Listen
dp = Dispatcher()
dp.message.outer_middleware(Listen())
- Use wait_for to directly interact with users:
import aiostep
@dp.message(filters.Command("echo"))
async def echo_handler(message: Message):
await message.reply("Please type something:")
try:
response = await aiostep.wait_for(message.from_user.id, timeout=25)
except TimeoutError:
await message.reply('You took too long to answer.')
else:
await message.reply(f"You typed: {response.text}")
- Use register_next_step for complex conversation flows:
import aiostep
@dp.message(filters.CommandStart())
async def start(message: Message):
await message.reply("What is your name?")
await aiostep.register_next_step(message.from_user.id, ask_age)
async def ask_age(msg: Message):
user_name = msg.text
await msg.reply("How old are you?")
await aiostep.register_next_step(msg.from_user.id, confirm_details, kwargs={"name": user_name})
async def confirm_details(msg: Message, name: str = None):
try:
age = int(msg.text)
except ValueError:
await msg.reply("Please send a valid age!")
await register_next_step(msg.from_user.id, confirm_details, kwargs={"name": name})
else:
await msg.reply(f"Your name is {name} and you are {age} years old. Thank you!")
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiostep-0.1.1.tar.gz.
File metadata
- Download URL: aiostep-0.1.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cbff7d88429ff74fc6cdc5e0932e7375a303b882c0ac1d0eb93ee5919f8d61f
|
|
| MD5 |
e89b8d8bf6d84a9d289c299a3d2e09b2
|
|
| BLAKE2b-256 |
ca8f2bcfc0e19415e68b3236be397e9173673c7683cab8ff6ed56858a69f49b5
|
File details
Details for the file aiostep-0.1.1-py3-none-any.whl.
File metadata
- Download URL: aiostep-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
098906ed13870f144dec0792d57866337dc58f5eed21198be4d12f97ab0e48ee
|
|
| MD5 |
d615dc1de106b603683727ef10a86954
|
|
| BLAKE2b-256 |
75a0539d353cbf3c7c26ba20139b3a536c7c9bf85bf9f030117df724144c8548
|