Skip to main content

A state handling extension for Pyrogram

Project description

Pyrostates

A state handling extension for Pyrogram

from pyrogram import Client, filters
from pyrostates import at_state, set_state, del_state

app = Client("my_account")


@app.on_message(at_state(None) & filters.private & filters.text)
async def home_state(_, message):
    await message.reply("Hello, I'm the conversation bot. What is your name?")
    set_state(message, "NAME")


@app.on_message(at_state("NAME") & filters.private & filters.text)
async def name_state(_, message):
    name = message.text
    await message.reply(f"Nice to meet you, {name}! How old are you?")
    set_state(message, "AGE")


@app.on_message(at_state("AGE") & filters.private & filters.text)
async def age_state(_, message):
    age = message.text
    await message.reply(f"You are {age} years old, good for you! Have a nice day!")
    del_state(message)


app.run()

Pyrostates is a ready, easy and elegant extension for the Pyrogram framework. It enables you to handle the states of your users in the most simple, efficient and reliable way.

Installing

pip3 install pyrostates

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

pyrostates-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

Pyrostates-0.1.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

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