> For the complete documentation index, see [llms.txt](https://painor.gitbook.io/gramjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://painor.gitbook.io/gramjs/working-with-instant-view-pages/messages.getwebpagepreview.md).

# messages.getWebPagePreview

Get preview of webpage

## Example

{% tabs %}
{% tab title="Javascript" %}

```javascript
const {Api, TelegramClient} = require('telegram');
const {StringSession} = require('telegram/sessions');

const session = new StringSession('');
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
    const result = await client.invoke(new Api.messages.getWebPagePreview({
        message: 'random string here',
        entities: [new Api.MessageEntity({...})],
        }));
    console.log(result); // prints the result
})();
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
import {Api, TelegramClient} from 'telegram';
import {StringSession} from 'telegram/sessions';

const session = new StringSession('');
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
    const result: Api.MessageMedia = await client.invoke(new Api.messages.getWebPagePreview({
        message: 'random string here',
        entities: [new Api.MessageEntity({...})],
        }));
    console.log(result); // prints the result
})();
```

{% endtab %}
{% endtabs %}

## TL schema

```
messageMediaEmpty#3ded6320 = MessageMedia;
messageMediaPhoto#695150d7 flags:# photo:flags.0?Photo ttl_seconds:flags.2?int = MessageMedia;
messageMediaGeo#56e0d474 geo:GeoPoint = MessageMedia;
messageMediaContact#cbf24940 phone_number:string first_name:string last_name:string vcard:string user_id:int = MessageMedia;
messageMediaUnsupported#9f84f49e = MessageMedia;
messageMediaDocument#9cb070d7 flags:# document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia;
messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia;
messageMediaVenue#2ec0533f geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string = MessageMedia;
messageMediaGame#fdb19008 game:Game = MessageMedia;
messageMediaInvoice#84551347 flags:# shipping_address_requested:flags.1?true test:flags.3?true title:string description:string photo:flags.0?WebDocument receipt_msg_id:flags.2?int currency:string total_amount:long start_param:string = MessageMedia;
messageMediaGeoLive#b940c666 flags:# geo:GeoPoint heading:flags.0?int period:int proximity_notification_radius:flags.1?int = MessageMedia;
messageMediaPoll#4bd6e798 poll:Poll results:PollResults = MessageMedia;
messageMediaDice#3f7ee58b value:int emoticon:string = MessageMedia;
---functions---
messages.getWebPagePreview#8b68b0cc flags:# message:string entities:flags.3?Vector<MessageEntity> = MessageMedia;
```

## Parameters

|     Name     | Type                                                                                                                                                                                                 | Description                                                                                             |
| :----------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|   **flags**  | [#](https://core.telegram.org/type/%23)                                                                                                                                                              | Flags, see [TL conditional fields](https://core.telegram.org/mtproto/TL-combinators#conditional-fields) |
|  **message** | [string](https://core.telegram.org/type/string)                                                                                                                                                      | Message from which to extract the preview                                                               |
| **entities** | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields).3?[Vector](https://core.telegram.org/type/Vector%20t) < [MessageEntity](https://core.telegram.org/type/MessageEntity) > | [Message entities for styled text](https://core.telegram.org/api/entities)                              |

## Result

[MessageMedia](https://core.telegram.org/type/MessageMedia)

## Possible errors

| Code | Type           | Description                   |
| :--: | -------------- | ----------------------------- |
|  400 | MESSAGE\_EMPTY | The provided message is empty |

## Can bots use this methd ?

### yes

## Related pages

### [Styled text with message entities](https://core.telegram.org/api/entities)

How to create styled text with message entities
