LinkPreview

The LinkPreview widget is used to manage link previews in messages.

Parameters:

  • url: A TextWidget 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. If True, 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. If True, 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,
)
Parameters:
  • url (TextWidget | None)

  • is_disabled (bool)

  • prefer_small_media (bool)

  • prefer_large_media (bool)

  • show_above_text (bool)

  • when (str | MagicFilter | Predicate | 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)

Create link preview.

Parameters:
  • data (dict)

  • manager (DialogManager)

Return type:

LinkPreviewOptions | None