LinkPreview¶
The LinkPreview widget is used to manage link previews in messages.
Parameters:
url
: ATextWidget
with URL to be used in the link preview. If not provided, the first URL found in the message will be used.is_disabled
: that controls whether the link preview is displayed. IfTrue
, the preview will be disabled.prefer_small_media
: that controls if the media in the link preview should be displayed in a smaller size. Ignored if media size change is not supported.prefer_large_media
: that controls if the media in the link preview should be enlarged. Ignored if media size change is not supported.show_above_text
: that specifies whether the link preview should be displayed above the message text. IfTrue
, link preview be displayed above the message text.
Code example:
from aiogram.filters.state import State, StatesGroup
from aiogram_dialog import Window
from aiogram_dialog.widgets.link_preview import LinkPreview
from aiogram_dialog.widgets.text import Const
class SG(StatesGroup):
MAIN = State()
SECOND = State()
window = Window(
Const("https://nplus1.ru/news/2024/05/23/voyager-1-science-data"),
LinkPreview(is_disabled=True),
state=SG.MAIN,
)
second_window = Window(
Const("some text"),
LinkPreview(
url=Const("https://nplus1.ru/news/2024/05/23/voyager-1-science-data"),
prefer_small_media=True,
show_above_text=True,
),
state=SG.MAIN,
)
- class aiogram_dialog.widgets.link_preview.LinkPreview(url=None, is_disabled=False, prefer_small_media=False, prefer_large_media=False, show_above_text=False, when=None)¶
- Parameters:
url (TextWidget | None)
is_disabled (bool)
prefer_small_media (bool)
prefer_large_media (bool)
show_above_text (bool)
when (str | MagicFilter | Predicate | None)
- __init__(url=None, is_disabled=False, prefer_small_media=False, prefer_large_media=False, show_above_text=False, when=None)¶
- Parameters:
url (TextWidget | None)
is_disabled (bool)
prefer_small_media (bool)
prefer_large_media (bool)
show_above_text (bool)
when (str | MagicFilter | Predicate | None)
- async render_link_preview(data, manager)¶
Create link preview.
- Parameters:
data (dict)
manager (DialogManager)
- Return type:
LinkPreviewOptions | None