mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added always_private argument to url() method
There are some cases when you want to be sure that your link will work regardless of chat username. This change makes it so you can force creation of private link
This commit is contained in:
parent
5eecec7c25
commit
462524a1e5
1 changed files with 6 additions and 5 deletions
|
|
@ -228,22 +228,23 @@ class Message(base.TelegramObject):
|
|||
return self.parse_entities()
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
def url(self, always_private=False) -> str:
|
||||
"""
|
||||
Get URL for the message
|
||||
|
||||
:param always_private: Force generate a private URL even when username is available
|
||||
:return: str
|
||||
"""
|
||||
if ChatType.is_private(self.chat):
|
||||
raise TypeError('Invalid chat type!')
|
||||
|
||||
url = 'https://t.me/'
|
||||
if self.chat.username:
|
||||
# Generates public link
|
||||
url += f'{self.chat.username}/'
|
||||
else:
|
||||
if not self.chat.username or always_private:
|
||||
# Generates private link available for chat members
|
||||
url += f'c/{self.chat.shifted_id}/'
|
||||
else:
|
||||
# Generates public link
|
||||
url += f'{self.chat.username}/'
|
||||
url += f'{self.message_id}'
|
||||
|
||||
return url
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue