MessageEntity

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

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[source]

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[source]

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

Type:

int

length[source]

Length of the entity in UTF-16 code units.

Type:

int

url[source]

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

Type:

str

user[source]

Optional. For TEXT_MENTION only, the mentioned user.

Type:

telegram.User

language[source]

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

Type:

str

custom_emoji_id[source]

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

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][source]

A list of all available message entity types.

Type:

List[str]

BLOCKQUOTE = 'blockquote'[source]

telegram.constants.MessageEntityType.BLOCKQUOTE

New in version 20.8.

BOLD = 'bold'[source]

telegram.constants.MessageEntityType.BOLD

BOT_COMMAND = 'bot_command'[source]

telegram.constants.MessageEntityType.BOT_COMMAND

CASHTAG = 'cashtag'[source]

telegram.constants.MessageEntityType.CASHTAG

CODE = 'code'[source]

telegram.constants.MessageEntityType.CODE

CUSTOM_EMOJI = 'custom_emoji'[source]

telegram.constants.MessageEntityType.CUSTOM_EMOJI

New in version 20.0.

EMAIL = 'email'[source]

telegram.constants.MessageEntityType.EMAIL

HASHTAG = 'hashtag'[source]

telegram.constants.MessageEntityType.HASHTAG

ITALIC = 'italic'[source]

telegram.constants.MessageEntityType.ITALIC

MENTION = 'mention'[source]

telegram.constants.MessageEntityType.MENTION

PHONE_NUMBER = 'phone_number'[source]

telegram.constants.MessageEntityType.PHONE_NUMBER

PRE = 'pre'[source]

telegram.constants.MessageEntityType.PRE

SPOILER = 'spoiler'[source]

telegram.constants.MessageEntityType.SPOILER

New in version 13.10.

STRIKETHROUGH = 'strikethrough'[source]

telegram.constants.MessageEntityType.STRIKETHROUGH

telegram.constants.MessageEntityType.TEXT_LINK

TEXT_MENTION = 'text_mention'[source]

telegram.constants.MessageEntityType.TEXT_MENTION

UNDERLINE = 'underline'[source]

telegram.constants.MessageEntityType.UNDERLINE

URL = 'url'[source]

telegram.constants.MessageEntityType.URL

classmethod de_json(data, bot)[source]

See telegram.TelegramObject.de_json().