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 description(): null | string
  • Page description

    Usually defined by description or og:description meta tag

    Returns null | string

  • get displayUrl(): string
  • URL to be displayed to the user.

    Usually a normal URL with stripped protocol and garbage.

    Returns string

  • get document(): null | RawDocument
  • Document inside this webpage preview.

    Seems that this is only used for document previews.

    Can be a Photo, Video, Audio, Document.

    Returns null | RawDocument

  • get embedHeight(): number
  • Height of the embed in pixels, 0 if not available.

    Returns number

  • 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 embedWidth(): number
  • Width of the embed in pixels, 0 if not available.

    Returns number

  • get id(): Long
  • Unique ID of the preview

    Returns Long

  • get inputMedia(): TypeInputMedia
  • Input media TL object generated from this object, to be used inside InputMediaLike and TelegramClient.sendMedia.

    WebPage can't provide an input media, since some can only be auto-generated from a link. This getter is only provided to allow using msg.media.inputMedia

    Returns TypeInputMedia

  • get photo(): null | Photo
  • A photo inside this webpage preview.

    Used for most of the preview types.

    Returns null | Photo

  • 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

  • get siteName(): null | string
  • Page title

    Usually defined by og:site_name meta tag or website domain

    Returns null | string

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

    Usually defined by og:title meta tag or <title> tag

    Returns null | string

  • get url(): string
  • Original page URL

    Returns string