pyrogram icon indicating copy to clipboard operation
pyrogram copied to clipboard

Add conversation support

Open Mahesh0253 opened this issue 4 years ago • 5 comments

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.

Mahesh0253 avatar Jul 12 '21 06:07 Mahesh0253

Credits to @usernein for pyromod when?

AndrielFR avatar Aug 22 '21 16:08 AndrielFR

when will this be added?

Eikosa avatar Nov 30 '22 20:11 Eikosa

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}")

alekssamos avatar May 21 '23 14:05 alekssamos

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}")

Mahesh0253 avatar May 21 '23 14:05 Mahesh0253

filter can also be added

Eikosa avatar May 21 '23 14:05 Eikosa