Python telegram.MessageEntity.URL Examples
The following are 2
code examples of telegram.MessageEntity.URL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
telegram.MessageEntity
, or try the search function
.
Example #1
Source File: commands.py From forwardscoverbot with GNU Affero General Public License v3.0 | 8 votes |
def disable_web_page_preview(update, context): if not update.message.reply_to_message: text = ("This command permits to remove the web page preview from a message with " "a link.\n\nUse it replying to the message the bot already echoed and you " "want to disable the preview with this command.") update.message.reply_text(text=text) return if not update.message.reply_to_message.text: text = "This message does not have a web page preview" update.message.reply_to_message.reply_text(text=text, quote=True) return entities_list = [MessageEntity.URL, MessageEntity.TEXT_LINK] entities = update.message.reply_to_message.parse_entities(entities_list) if len(entities) == 0: text = "This message does not have a web page preview" update.message.reply_to_message.reply_text(text=text, quote=True) return text = update.message.reply_to_message.text_html update.message.reply_to_message.reply_text( text=text, disable_web_page_preview=True, parse_mode=ParseMode.HTML)
Example #2
Source File: rules_bot.py From rules-bot with GNU Affero General Public License v3.0 | 5 votes |
def github(update: Update, context: CallbackContext): message = update.message or update.edited_message last = 0 thing_matches = [] things = {} # Due to bug in ptb we need to convert entities of type URL to TEXT_LINK for them to be converted to html for entity in message.entities: if entity.type == MessageEntity.URL: entity.type = MessageEntity.TEXT_LINK entity.url = message.parse_entity(entity) for match in GITHUB_PATTERN.finditer(get_text_not_in_entities(message.text_html)): logging.debug(match.groupdict()) owner, repo, number, sha = [match.groupdict()[x] for x in ('owner', 'repo', 'number', 'sha')] if number or sha: thing_matches.append((owner, repo, number, sha)) for thing_match in thing_matches: last = keep_typing(last, update.effective_chat, ChatAction.TYPING) owner, repo, number, sha = thing_match if number: issue = github_issues.get_issue(int(number), owner, repo) things[issue.url] = github_issues.pretty_format_issue(issue) elif sha: commit = github_issues.get_commit(sha, owner, repo) things[commit.url] = github_issues.pretty_format_commit(commit) if things: reply_or_edit(update, context, '\n'.join([f'<a href="{url}">{name}</a>' for url, name in things.items()]))