-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Added methods to quickly reply to a message with Markdown or HTML #725
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Sticker, TelegramObject, | ||
| User, Video, Voice, Venue, MessageEntity, Game, Invoice, SuccessfulPayment, | ||
| VideoNote) | ||
| from telegram import ParseMode | ||
| from telegram.utils.deprecate import warn_deprecate_obj | ||
| from telegram.utils.helpers import escape_html, escape_markdown, to_timestamp, from_timestamp | ||
|
|
||
|
|
@@ -305,6 +306,40 @@ def reply_text(self, *args, **kwargs): | |
| self._quote(kwargs) | ||
| return self.bot.send_message(self.chat_id, *args, **kwargs) | ||
|
|
||
| def reply_markdown(self, *args, **kwargs): | ||
| """ | ||
| Shortcut for ``bot.sendMessage(update.message.chat_id, parse_mode=ParseMode.MARKDOWN, *args, **kwargs)`` | ||
| Sends a message with markdown formatting. | ||
|
|
||
| Keyword Args: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Args: (without keyword) |
||
| quote (Optional[bool]): If set to ``True``, the message is sent as an actual reply to | ||
| this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent continuing line with two indents. |
||
| will be ignored. Default: ``True`` in group chats and ``False`` in private chats. | ||
| """ | ||
|
|
||
| kwargs['parse_mode'] = ParseMode.MARKDOWN | ||
|
|
||
| self._quote(kwargs) | ||
|
|
||
| return self.bot.sendMessage(self.chat_id, *args, **kwargs) | ||
|
|
||
| def reply_html(self, *args, **kwargs): | ||
| """ | ||
| Shortcut for ``bot.sendMessage(update.message.chat_id, parse_mode=ParseMode.HTML, *args, **kwargs)`` | ||
| Sends a message with HTML formatting. | ||
|
|
||
| Keyword Args: | ||
| quote (Optional[bool]): If set to ``True``, the message is sent as an actual reply to | ||
| this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter | ||
| will be ignored. Default: ``True`` in group chats and ``False`` in private chats. | ||
| """ | ||
|
|
||
| kwargs['parse_mode'] = ParseMode.HTML | ||
|
|
||
| self._quote(kwargs) | ||
|
|
||
| return self.bot.sendMessage(self.chat_id, *args, **kwargs) | ||
|
|
||
| def reply_photo(self, *args, **kwargs): | ||
| """ | ||
| Shortcut for ``bot.send_photo(update.message.chat_id, *args, **kwargs)`` | ||
|
|
@@ -510,6 +545,48 @@ def edit_text(self, *args, **kwargs): | |
| return self.bot.edit_message_text( | ||
| chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs) | ||
|
|
||
| def edit_markdown(self, *args, **kwargs): | ||
| """ | ||
| Shortcut for | ||
|
|
||
| >>> bot.editMessageText(chat_id=message.chat_id, | ||
| ... message_id=message.message_id, | ||
| ... parse_mode=ParseMode.MARKDOWN, | ||
| ... *args, **kwargs) | ||
|
|
||
| Note: | ||
| You can only edit messages that the bot sent itself, | ||
| therefore this method can only be used on the | ||
| return value of the ``bot.send_*`` family of methods. | ||
|
|
||
| """ | ||
|
|
||
| kwargs['parse_mode'] = ParseMode.MARKDOWN | ||
|
|
||
| return self.bot.edit_message_text( | ||
| chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs) | ||
|
|
||
| def edit_html(self, *args, **kwargs): | ||
| """ | ||
| Shortcut for | ||
|
|
||
| >>> bot.editMessageText(chat_id=message.chat_id, | ||
| ... message_id=message.message_id, | ||
| ... parse_mode=ParseMode.HTML | ||
| ... *args, **kwargs) | ||
|
|
||
| Note: | ||
| You can only edit messages that the bot sent itself, | ||
| therefore this method can only be used on the | ||
| return value of the ``bot.send_*`` family of methods. | ||
|
|
||
| """ | ||
|
|
||
| kwargs['parse_mode'] = ParseMode.HTML | ||
|
|
||
| return self.bot.edit_message_text( | ||
| chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs) | ||
|
|
||
| def edit_caption(self, *args, **kwargs): | ||
| """ | ||
| Shortcut for | ||
|
|
@@ -610,7 +687,7 @@ def parse_entities(self, types=None): | |
| return { | ||
| entity: self.parse_entity(entity) | ||
| for entity in self.entities if entity.type in types | ||
| } | ||
| } | ||
|
|
||
| @property | ||
| def text_html(self): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to: