Web page preview.

Warning: Documentation of this class also contains my personal research about how Telegram handles different pages and embeds. By no means this should be considered the definitive source of truth, as this is not documented officially, and only consists of my own observations and experiments.

Constructors

Properties

type: "webpage" = ...

Accessors

  • get author(): null | string
  • Page author

    The source for this is unknown, seems to be custom-made for services like Twitter.

    In official apps this seems to be used as a fallback for description.

    Returns null | string

  • get embedType(): null | string
  • Embed type.

    Now this is actually stupid. As per official documentation, embed_type contains «MIME type of the embedded preview, (e.g., text/html or video/mp4)». But in fact every time I encountered it it contained a simple string iframe.

    I couldn't find any usage of this field in official apps either.

    Returns null | string

  • get embedUrl(): null | string
  • The embed URL.

    Based on my research, Telegram only allows embedding pages from a server-side white-list of domains.

    That is, you can't just copy-paste meta tags from YouTube to your own domain and expect Telegram to return a webpage with embed.

    IDK why is that, maybe they are concerned about leaking users' IPs to 3rd parties or something (but why allow embedding in the first place then?)

    Telegram for Android does not show "play" button for webpages without embeds, and instead treats it like a simple photo (why?).

    TDesktop does not support embeds and seems to use type to determine them, and specifically checks for YouTube in siteName to display YouTube icon.

    Returns null | string

  • get previewType(): string
  • Type of the preview, taken directly from TL object

    Officially documented are: article, photo, audio, video, document, profile, app, but also these are encountered: telegram_user, telegram_bot, telegram_channel, telegram_megagroup, telegram_story:

    • telegram_* ones seem to be used for t.me links.
    • article seems to be used for almost all custom pages with og:* tags
    • photo, audio and video seem to be derived from og:type, and the page itself may contain a preview photo and an embed link for the player. This may not correctly represent actual content type: Spotify links are audio, but SoundCloud are video. YouTube links are video, but tweets with video are photo.
    • document seem to be used for files downloadable directly from the URL, like PDFs, audio files, videos, etc. document seem to be present if type is document.
    • profile doesn't seem to be used
    • app doesn't seem to be used

    unknown is returned if no type is returned in the TL object.

    Returns string