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).
This commit is contained in:
Oleg A 2018-05-23 00:10:34 +03:00 committed by GitHub
parent 2281afe2ca
commit b109523cda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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):
"""