pyrostep
You can implement conversation in your project based on pyrogram very easy with pyrostep.
Features:
- Full type hint
- Support step handling
- Support asking
- Change core settings of pyrogram
Installing
pip3 install -U pyrostep
Content
Tutorial
Use pyrostep.listen() to start listening on your client:
from pyrogram import Client
import pyrostep
# ...
client = Client("myaccount")
pyrostep.listen(client)
After that, we have two ways to make conversation: wait_for method or step handling
Wait for method
⏰ In this way we can use pyrostep.wait_for function, that waits for an update (e.g message) from your target.
client = Client("myaccount")
pyrostep.listen(client)
# ...
@client.on_message()
async def get_name(_, message):
await message.reply("Send your name?")
answer = await pyrostep.wait_for(message.from_user.id)
await message.reply(f"Your name is {answer.text}")
client = Client("myaccount")
pyrostep.listen(client)
# ...
@client.on_message()
async def get_name(_, message):
await message.reply("Send your name?")
try:
answer = await pyrostep.wait_for(message.from_user.id, timeout=10)
except TimeoutError:
await message.reply("Timed out")
else:
await message.reply(f"Your name is {answer.text}")
🔗 Related functions:
clear(): remove all registered steps (and cancels all wait_for's).
Step handling
🎯 In this way we will use this functions:
pyrostep.register_next_step()
We will specify a function that should process the next update from the target with pyrostep.register_next_step().
client = Client("myaccount")
pyrostep.listen(client)
# ...
@client.on_message()
async def get_name(_, message):
await message.reply("Send your name?")
await pyrostep.register_next_step(
message.from_user.id, get_age
)
async def get_age(_, message):
await message.reply("OK, Send your age?")
await pyrostep.register_next_step(
message.from_user.id,
say_info,
kwargs={"name": message.text}
)
async def say_info(_, message, name: str = None):
await message.reply(f"Name: {name} - Age: {message.text}")
🔗 Related functions:
unregister_steps(id): remove registered step for id.clear(): remove all registered steps (and cancels all wait_for's).
Plugins
📁 If you're using plugins in pyrogram, maybe you cannot use pyrostep.listen(), so you can use pyrostep.listening_handler function.
How? there's an example:
# plugin file
from pyrogram import Client
import pyrostep
Client.on_message()
async def stephandler(client, message):
await pyrostep.listening_handler(client, message)
# your other handlers
Shortcuts
✂️ pyrostep have some shortcuts and shorthands for you.
pyrostep.shortcuts.split_list()
split_list splites your list.
example:
>>> from pyrostep import shortcuts
>>> split_list([1, 2, 3, 4, 5, 6], 2)
[[1, 2], [3, 4], [5, 6]]
>>> split_list([1, 2, 3], 2)
[[1, 2], [3]]
pyrostep.shortcuts.keyboard()
keyboard creates ReplyKeyboardMarkup from your list.
example:
>>> from pyrostep import shortcuts
>>> buttons = [
... [["Top Left"], ["Top Right"]],
... [["Bottom | Request Contact", True, "request_contact"]]
... ]
>>> shortcuts.keyboard(buttons)
ReplyKeyboardMarkup(keyboard=[[KeyboardButton(text='Top Left'), KeyboardButton(text='Top Right')], [KeyboardButton(text='Bottom | Request Contact', request_contact=True)]])
pyrostep.shortcuts.inlinekeyboard()
inlinekeyboard creates InlineKeyboardMarkup from your list.
example:
>>> from pyrostep import shortcuts
>>> buttons = [
... [["Top Left", "data_1"], ["Top Right", "data_2"]],
... [["Bottom", "Your URL", "url"]]
... ]
>>> shortcuts.inlinekeyboard(buttons)
InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text='Top Left', callback_data='data_1'), InlineKeyboardButton(text='Top Right', callback_data='data_2')], [InlineKeyboardButton(text='Bottom', url='Your URL')]])
pyrostep.shortcuts.validation_channels()
validation_channels checks user is already in channels or not.
returns True if user is already in channels, returns False otherwise.
example:
>>> from pyrostep import shortcuts
>>> user_id = 56392019
>>> channels = [-10279279837, -10823827873, 'channel_username']
>>> await validation_channels(app, user_id, channels)
True
connection package
This package helps you to change pyrogram connection settings.
pyrostep.connection.connection_max_retries()
How many times does it try to connect (to proxy or telegram)?
pyrostep.connection.invoke_max_retries()
How many times does it try to invoke a method?
pyrostep.connection.session_start_timeout()
How many seconds to wait for connection?
pyrostep.connection.session_max_retries()
How many times does it try to authenticate?
Example:
from pyrostep import connection
connection.connection_max_retries(3)
connection.invoke_max_retries(3)
connection.session_start_timeout(20)
connection.session_max_retries(2)
from pyrogram import Client
# code ...
Release files for pyrostep 2.11.22
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyrostep-2.11.22.tar.gz | 10.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyrostep-2.11.22-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.8 kB
Release files / pyrostep-2.11.22.tar.gz
| Download URL | pyrostep-2.11.22.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
351548c9494305587558c3daa2d34af30acb05163b78852371437ce5bb268381
|
|
BLAKE2b-256 checksum How to use checksums |
db048d9f98e7629d8b69d66912a21f1c704cc90f99248b4361aceb6effe37262
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.8
|
Release files / pyrostep-2.11.22-py3-none-any.whl
| Download URL | pyrostep-2.11.22-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
728ce31dc1613bc1c4eb17aab2a0ebe758eb7a50591fc903586ca61b635e297e
|
|
BLAKE2b-256 checksum How to use checksums |
c562da33a687e52390cc959aaf48047b832c55e5c0c75125e7d996539b93cb89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.8
|