From 62417da6a794bc28f27bb0b461ae6577688a5f03 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 23 Aug 2017 22:55:40 +0300 Subject: [PATCH] Get mention in private chats. --- aiogram/types/chat.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index 7e5ec498..aa6dd95e 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -1,3 +1,4 @@ +from aiogram.utils.markdown import hlink, link from .base import Deserializable from .chat_photo import ChatPhoto from ..utils.helper import Helper, HelperMode, Item @@ -65,6 +66,20 @@ class Chat(Deserializable): return self.full_name return None + @property + def user_url(self): + if self.type != ChatType.PRIVATE: + raise TypeError('This property available only in private chats.') + + return f"tg://user?id={self.id}" + + def get_mention(self, name=None, as_html=False): + if name is None: + name = self.mention + if as_html: + return hlink(name, self.user_url) + return link(name, self.user_url) + async def set_photo(self, photo): return await self.bot.set_chat_photo(self.id, photo)