Hide navigation sidebar
Hide table of contents sidebar
PTB has undergone significant changes in v20. Please read the documentation carefully and also check out the transition guide in the wiki.
Back to top
Toggle table of contents sidebar

# MessageEntity

class telegram.MessageEntity(type, offset, length, url=None, user=None, language=None, custom_emoji_id=None, *, api_kwargs=None)

  Bases: `telegram.TelegramObject`

  This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.

  Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their `type`, `offset` and `length` are equal.

  Parameters:

    - type (`str`) –

      Type of the entity. Can be `MENTION` (@username), `HASHTAG` (#hashtag), `CASHTAG` ($USD), `BOT_COMMAND` (/start@jobs_bot), `URL` (https://telegram.org), `EMAIL` (do-not-reply@telegram.org), `PHONE_NUMBER` (+1-212-555-0123), `BOLD` (bold text), `ITALIC` (italic text), `UNDERLINE` (underlined text), `STRIKETHROUGH`, `SPOILER` (spoiler message), `BLOCKQUOTE` (block quotation), `CODE` (monowidth string), `PRE` (monowidth block), `TEXT_LINK` (for clickable text URLs), `TEXT_MENTION` (for users without usernames), `CUSTOM_EMOJI` (for inline custom emoji stickers).

      New in version 20.0: Added inline custom emoji

      New in version 20.8: Added block quotation

    - offset (`int`) – Offset in UTF-16 code units to the start of the entity.

    - length (`int`) – Length of the entity in UTF-16 code units.

    - url (`str`, optional) – For `TEXT_LINK` only, url that will be opened after user taps on the text.

    - user (`telegram.User`, optional) – For `TEXT_MENTION` only, the mentioned user.

    - language (`str`, optional) – For `PRE` only, the programming language of the entity text.

    - custom_emoji_id (`str`, optional) –

      For `CUSTOM_EMOJI` only, unique identifier of the custom emoji. Use `telegram.Bot.get_custom_emoji_stickers()` to get full information about the sticker.

      New in version 20.0.

  type

    Type of the entity. Can be `MENTION` (@username), `HASHTAG` (#hashtag), `CASHTAG` ($USD), `BOT_COMMAND` (/start@jobs_bot), `URL` (https://telegram.org), `EMAIL` (do-not-reply@telegram.org), `PHONE_NUMBER` (+1-212-555-0123), `BOLD` (bold text), `ITALIC` (italic text), `UNDERLINE` (underlined text), `STRIKETHROUGH`, `SPOILER` (spoiler message), `BLOCKQUOTE` (block quotation), `CODE` (monowidth string), `PRE` (monowidth block), `TEXT_LINK` (for clickable text URLs), `TEXT_MENTION` (for users without usernames), `CUSTOM_EMOJI` (for inline custom emoji stickers).

    New in version 20.0: Added inline custom emoji

    New in version 20.8: Added block quotation

    Type:

      `str`

  offset

    Offset in UTF-16 code units to the start of the entity.

    Type:

      `int`

  length

    Length of the entity in UTF-16 code units.

    Type:

      `int`

  url

    Optional. For `TEXT_LINK` only, url that will be opened after user taps on the text.

    Type:

      `str`

  user

    Optional. For `TEXT_MENTION` only, the mentioned user.

    Type:

      `telegram.User`

  language

    Optional. For `PRE` only, the programming language of the entity text.

    Type:

      `str`

  custom_emoji_id

    Optional. For `CUSTOM_EMOJI` only, unique identifier of the custom emoji. Use `telegram.Bot.get_custom_emoji_stickers()` to get full information about the sticker.

    New in version 20.0.

    Type:

      `str`

  Use In

  - `telegram.Bot.copy_message()`

  - `telegram.Bot.edit_message_caption()`

  - `telegram.Bot.edit_message_text()`

  - `telegram.Bot.send_animation()`

  - `telegram.Bot.send_audio()`

  - `telegram.Bot.send_document()`

  - `telegram.Bot.send_media_group()`

  - `telegram.Bot.send_message()`

  - `telegram.Bot.send_photo()`

  - `telegram.Bot.send_poll()`

  - `telegram.Bot.send_video()`

  - `telegram.Bot.send_voice()`

  Available In

  - `telegram.Game.text_entities`

  - `telegram.InlineQueryResultAudio.caption_entities`

  - `telegram.InlineQueryResultCachedAudio.caption_entities`

  - `telegram.InlineQueryResultCachedDocument.caption_entities`

  - `telegram.InlineQueryResultCachedGif.caption_entities`

  - `telegram.InlineQueryResultCachedMpeg4Gif.caption_entities`

  - `telegram.InlineQueryResultCachedPhoto.caption_entities`

  - `telegram.InlineQueryResultCachedVideo.caption_entities`

  - `telegram.InlineQueryResultCachedVoice.caption_entities`

  - `telegram.InlineQueryResultDocument.caption_entities`

  - `telegram.InlineQueryResultGif.caption_entities`

  - `telegram.InlineQueryResultMpeg4Gif.caption_entities`

  - `telegram.InlineQueryResultPhoto.caption_entities`

  - `telegram.InlineQueryResultVideo.caption_entities`

  - `telegram.InlineQueryResultVoice.caption_entities`

  - `telegram.InputMedia.caption_entities`

  - `telegram.InputMediaAnimation.caption_entities`

  - `telegram.InputMediaAudio.caption_entities`

  - `telegram.InputMediaDocument.caption_entities`

  - `telegram.InputMediaPhoto.caption_entities`

  - `telegram.InputMediaVideo.caption_entities`

  - `telegram.InputTextMessageContent.entities`

  - `telegram.Message.caption_entities`

  - `telegram.Message.entities`

  - `telegram.Poll.explanation_entities`

  ALL_TYPES = [MessageEntityType.MENTION, MessageEntityType.HASHTAG, MessageEntityType.CASHTAG, MessageEntityType.PHONE_NUMBER, MessageEntityType.BOT_COMMAND, MessageEntityType.URL, MessageEntityType.EMAIL, MessageEntityType.BOLD, MessageEntityType.ITALIC, MessageEntityType.CODE, MessageEntityType.PRE, MessageEntityType.TEXT_LINK, MessageEntityType.TEXT_MENTION, MessageEntityType.UNDERLINE, MessageEntityType.STRIKETHROUGH, MessageEntityType.SPOILER, MessageEntityType.CUSTOM_EMOJI, MessageEntityType.BLOCKQUOTE]

    A list of all available message entity types.

    Type:

      List[`str`]

  BLOCKQUOTE = 'blockquote'

    `telegram.constants.MessageEntityType.BLOCKQUOTE`

    New in version 20.8.

  BOLD = 'bold'

    `telegram.constants.MessageEntityType.BOLD`

  BOT_COMMAND = 'bot_command'

    `telegram.constants.MessageEntityType.BOT_COMMAND`

  CASHTAG = 'cashtag'

    `telegram.constants.MessageEntityType.CASHTAG`

  CODE = 'code'

    `telegram.constants.MessageEntityType.CODE`

  CUSTOM_EMOJI = 'custom_emoji'

    `telegram.constants.MessageEntityType.CUSTOM_EMOJI`

    New in version 20.0.

  EMAIL = 'email'

    `telegram.constants.MessageEntityType.EMAIL`

  HASHTAG = 'hashtag'

    `telegram.constants.MessageEntityType.HASHTAG`

  ITALIC = 'italic'

    `telegram.constants.MessageEntityType.ITALIC`

  MENTION = 'mention'

    `telegram.constants.MessageEntityType.MENTION`

  PHONE_NUMBER = 'phone_number'

    `telegram.constants.MessageEntityType.PHONE_NUMBER`

  PRE = 'pre'

    `telegram.constants.MessageEntityType.PRE`

  SPOILER = 'spoiler'

    `telegram.constants.MessageEntityType.SPOILER`

    New in version 13.10.

  STRIKETHROUGH = 'strikethrough'

    `telegram.constants.MessageEntityType.STRIKETHROUGH`

  TEXT_LINK = 'text_link'

    `telegram.constants.MessageEntityType.TEXT_LINK`

  TEXT_MENTION = 'text_mention'

    `telegram.constants.MessageEntityType.TEXT_MENTION`

  UNDERLINE = 'underline'

    `telegram.constants.MessageEntityType.UNDERLINE`

  URL = 'url'

    `telegram.constants.MessageEntityType.URL`

  classmethod de_json(data, bot)

    See `telegram.TelegramObject.de_json()`.