Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversation support #720

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Mahesh0253
Copy link
Contributor

@Mahesh0253 Mahesh0253 commented Jul 12, 2021

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.

@AndrielFR
Copy link

Credits to @usernein for pyromod when?

@Eikosa
Copy link

Eikosa commented Nov 30, 2022

when will this be added?

@alekssamos
Copy link

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

@Mahesh0253
Copy link
Contributor Author

Mahesh0253 commented May 21, 2023

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

@Eikosa
Copy link

Eikosa commented May 21, 2023

filter can also be added

Comment on lines +3628 to +3633
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.

self,
text: str,
quote: bool = None,
parse_mode: Optional[str] = object,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
parse_mode: Optional[str] = object,
parse_mode: Optional["enums.ParseMode"] = None,

quote = self.chat.type != "private"

if reply_to_message_id is None and quote:
reply_to_message_id = self.message_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reply_to_message_id = self.message_id
reply_to_message_id = self.id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants