Skip to content

Instantly share code, notes, and snippets.

@skinnyfads
Forked from MohammadHosseinGhorbani/conversation.py
Created February 10, 2023 04:33
Show Gist options
  • Save skinnyfads/38c28d9c1097b2372f36cb578c259b33 to your computer and use it in GitHub Desktop.
Save skinnyfads/38c28d9c1097b2372f36cb578c259b33 to your computer and use it in GitHub Desktop.
Conversations in pyrogram (no extra package needed)
from pyrogram import Client, filters
app = Client('CONVERSATION_EXAMPLE')
conversations = {}
infos = {}
def conv_filter(conversation_level):
def func(_, __, message):
return conversations.get(message.from_user.id) == conversation_level
return filters.create(func, "ConversationFilter")
@app.on_message(filters.command('start') & filters.private)
async def start(client, message):
await message.reply_text('reply your name')
conversations.update({message.from_user.id: "name"})
infos.update({message.from_user.id: {}})
@app.on_message(conv_filter("name") & filters.private)
async def name_handler(client, message):
await message.reply_text('now send your age')
infos.get(message.from_user.id).update({"name": message.text})
conversations.update({message.from_user.id: 'age'})
@app.on_message(conv_filter("age") & filters.private)
async def age_handler(client, message):
user_infos = infos.get(message.from_user.id)
user_infos.update({"age": message.text})
await message.reply_text(f'your name: {user_infos.get("name")}, your age: {user_infos.get("age")}')
conversations.pop(message.from_user.id)
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment