From b109523cdad8e31b455d1aa3c8e2ff3dbf7b370b Mon Sep 17 00:00:00 2001 From: Oleg A Date: Wed, 23 May 2018 00:10:34 +0300 Subject: [PATCH] Add .get_url() method Use this method to get chat link. Private chat returns user link. Other chat types return either username link (if they are public) or invite link (if they are private). --- aiogram/types/chat.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index cb8d9af5..495e3ab4 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -64,6 +64,19 @@ class Chat(base.TelegramObject): if as_html: return markdown.hlink(name, self.user_url) return markdown.link(name, self.user_url) + + async def get_url(self): + """ + Use this method to get chat link. + Private chat returns user link. + Other chat types return either username link (if they are public) or invite link (if they are private). + :return: link + :rtype: :obj:`base.String` + """ + if self.type == ChatType.PRIVATE: + return f"tg://user?id={self.id}" + + return f'https://t.me/{self.username}' if self.username else await self.export_invite_link() async def set_photo(self, photo): """