From c5b7a365af6686479c682ed024c36d7dae7bcc6f Mon Sep 17 00:00:00 2001 From: ColinShark Date: Mon, 27 Jul 2020 15:30:49 +0200 Subject: [PATCH] Add message.link attribute/property (#442) * Add message.link attribute Adds the functionality to access the message link. Either as `t.me/c/` or `t.me/username` format. * Change message.link logic Property now has a returned type, list is a tuple and we use `utils.get_channel_id` to not rely on str.replace * Update message.py - Prepend https:// like official clients do - Use .format() Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/client/types/messages_and_media/message.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 47606715..f2f6abab 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -251,6 +251,9 @@ class Message(Object, Update): Messages sent from yourself to other chats are outgoing (*outgoing* is True). An exception is made for your own personal chat; messages sent there will be incoming. + link (``str``): + A link to the message, only for groups and channels. + matches (List of regex Matches, *optional*): A list containing all `Match Objects `_ that match the text of this message. Only applicable when using :obj:`Filters.regex `. @@ -670,6 +673,13 @@ class Message(Object, Update): return parsed_message + @property + def link(self) -> str: + if self.chat.type in ("group", "supergroup", "channel") and self.chat.username: + return "https://t.me/{}/{}".format(self.chat.username, self.message_id) + else: + return "https://t.me/c/{}/{}".format(utils.get_channel_id(self.chat.id), self.message_id) + def reply_text( self, text: str,