Package: pyrostep
pyrostepYou can implement conversation in your project based on pyrogram very easy withpyrostep.Features:Full type hintSupport step handlingSupport askingChange core settings of pyrogramInstallingpip3install-UpyrostepContenttutorialstep handlingwait for methodpluginsshortcutsconnection packageTutorialUsepyrostep.listen()to start listening on your client:frompyrogramimportClientimportpyrostep# ...client=Client("myaccount")pyrostep.listen(client)[!NOTE]Always usepyrostep.listen()before adding your handlers.After that, we have two ways to make conversation:wait_for methodorstep handlingWait for method⏰ In this way we can usepyrostep.wait_forfunction, that waits for an update (e.g message) from your target.client=Client("myaccount")pyrostep.listen(client)# ...@client.on_message()asyncdefget_name(_,message):awaitmessage.reply("Send your name?")answer=awaitpyrostep.wait_for(message.from_user.id)awaitmessage.reply(f"Your name is{answer.text}")[!TIP]You can specify how long it will wait withtimeoutparameter. see this example:client=Client("myaccount")pyrostep.listen(client)# ...@client.on_message()asyncdefget_name(_,message):awaitmessage.reply("Send your name?")try:answer=awaitpyrostep.wait_for(message.from_user.id,timeout=10)exceptTimeoutError:awaitmessage.reply("Timed out")else:awaitmessage.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 withpyrostep.register_next_step().[!IMPORTANT]In this way we cannot specify a timeout.client=Client("myaccount")pyrostep.listen(client)# ...@client.on_message()asyncdefget_name(_,message):awaitmessage.reply("Send your name?")awaitpyrostep.register_next_step(message.from_user.id,get_age)asyncdefget_age(_,message):awaitmessage.reply("OK, Send your age?")awaitpyrostep.register_next_step(message.from_user.id,say_info,kwargs={"name":message.text})asyncdefsay_info(_,message,name:str=None):awaitmessage.reply(f"Name:{name}- Age:{message.text}")🔗Related functions:unregister_steps(id): remove registered step forid.clear(): remove all registered steps (and cancels all wait_for's).Plugins📁 If you're using plugins in pyrogram, maybe you cannot usepyrostep.listen(), so you can usepyrostep.listening_handlerfunction.How? there's an example:# plugin filefrompyrogramimportClientimportpyrostepClient.on_message()asyncdefstephandler(client,message):awaitpyrostep.listening_handler(client,message)# your other handlers[!WARNING]We didn't test it completely.Shortcuts✂️pyrostephave some shortcuts and shorthands for you.pyrostep.shortcuts.split_list()split_list splites your list.example:>>>frompyrostepimportshortcuts>>>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:>>>frompyrostepimportshortcuts>>>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:>>>frompyrostepimportshortcuts>>>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.
returnsTrueif user is already in channels, returnsFalseotherwise.example:>>>frompyrostepimportshortcuts>>>user_id=56392019>>>channels=[-10279279837,-10823827873,'channel_username']>>>awaitvalidation_channels(app,user_id,channels)Trueconnection packageThis package helps you to changepyrogram connectionsettings.[!NOTE]All of these functions should be used before importing pyrogrampyrostep.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:frompyrostepimportconnectionconnection.connection_max_retries(3)connection.invoke_max_retries(3)connection.session_start_timeout(20)connection.session_max_retries(2)frompyrogramimportClient# code ...