Skip to content

Instantly share code, notes, and snippets.

@alekssamos
Forked from MohammadHosseinGhorbani/conversation.py
Created January 25, 2022 06:34
Show Gist options
  • Save alekssamos/f7d6d15223a5c874443ca5b4a4070db4 to your computer and use it in GitHub Desktop.
Save alekssamos/f7d6d15223a5c874443ca5b4a4070db4 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