Add conversation support
Many developers looking for conversation support in Pyrogram. For that these 3 methods are implemented. (Credit: pyromod)
- wait_for_message
- wait_for_callback_query
- ask - Bound method for Message
# Example of wait_for_message
client.send_message(chat_id, "What is your name?")
reply = client.wait_for_message(chat_id)
client.send_message(chat_id, f"Hello {reply.text}")
# Bound method
reply = message.ask("What is your name?")
client.send_message(chat_id, f"Hello {reply.text}")
# Example of wait_for_callback
client.send_message(chat_id, "Choose any one button", reply_markup=reply_markup)
callback_query = client.wait_for_callback_query(chat_id)
print("Callback data:", callback_query.data)
If this pull request need some improvements, let me know I will improve it or you can make pull request for same.
Credits to @usernein for pyromod when?
when will this be added?
What if the user never responds or the bot is restarted?
reply = message.ask("What is your name?") client.send_message(chat_id, f"Hello {reply.text}")
What if the user never responds or the bot is restarted?
reply = message.ask("What is your name?") client.send_message(chat_id, f"Hello {reply.text}")
It will keep waiting but to avoid that situation you can add timeout parameter.
reply = message.ask("What is your name?", timeout=60) # wait for 1 minute
client.send_message(chat_id, f"Hello {reply.text}")
filter can also be added