Skip to main content

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

  1. 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())
  1. 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}")
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiostep-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiostep-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

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

Hashes for aiostep-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4cbff7d88429ff74fc6cdc5e0932e7375a303b882c0ac1d0eb93ee5919f8d61f
MD5 e89b8d8bf6d84a9d289c299a3d2e09b2
BLAKE2b-256 ca8f2bcfc0e19415e68b3236be397e9173673c7683cab8ff6ed56858a69f49b5

See more details on using hashes here.

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

Hashes for aiostep-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 098906ed13870f144dec0792d57866337dc58f5eed21198be4d12f97ab0e48ee
MD5 d615dc1de106b603683727ef10a86954
BLAKE2b-256 75a0539d353cbf3c7c26ba20139b3a536c7c9bf85bf9f030117df724144c8548

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page