Skip to content

Commit

Permalink
Add .get_url() method
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Olegt0rr authored May 22, 2018
1 parent 2281afe commit b109523
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aiogram/types/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ def get_mention(self, name=None, as_html=False):
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):
"""
Expand Down

0 comments on commit b109523

Please sign in to comment.