mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
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:
parent
2281afe2ca
commit
b109523cda
1 changed files with 13 additions and 0 deletions
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue