Td Api Text Entity Type - OTR/Kotlin-Telegram-Client GitHub Wiki
TdApi.TextEntityType
Class Description
Represents entities contained in the text. Entities can be nested, but must not mutually intersect with each other. Pre
, Code
and PreCode
entities can't contain other entities. Bold
, Italic
, Underline
and Strikethrough
entities can contain and to be contained in all other entities. All other entities can't contain each other.
Only *MentionName
, *PreCode
and *TextUrl
has public properties, other subclasses are just empty classes.
TdApi.TextEntityTypeMentionName
Class A text shows instead of a raw mention of the user (e.g., when the user has no username).
Property
userId
: Long - Identifier of the mentioned user.
Reference
TdApi.TextEntityTypeMentionName
TdApi.TextEntityTypePreCode
Class Text that must be formatted as if inside pre, and code HTML tags.
Property
language
: String - Programming language of the code; as defined by the sender.
Reference
TdApi.TextEntityTypeTextUrl
Class A text description shown instead of a raw URL.
Property
url
: String - HTTP or tg:// URL to be opened when the link is clicked.
Reference
Other subclasses are:
-
TdApi.TextEntityTypeBold
- represents a bold text. -
TdApi.TextEntityTypeBotCommand
- represents a bot command, beginning with "/". This shouldn't be highlighted if there are no bots in the chat. -
TdApi.TextEntityTypeCashtag
- represents a cashtag text, beginning with "$" and consisting of capital english letters (i.e. "$USD"). -
TdApi.TextEntityTypeCode
- represents a text that must be formatted as if inside a code HTML tag. -
TdApi.TextEntityTypeEmailAddress
- represents an email address. -
TdApi.TextEntityTypeHashtag
- represents a hashtag text, beginning with "#". -
TdApi.TextEntityTypeItalic
- represents an italic text. -
TdApi.TextEntityTypeMention
- represents a mention of a user by their username. -
TdApi.TextEntityTypePhoneNumber
- represents a phone number. -
TdApi.TextEntityTypePre
- represents a text that must be formatted as if inside a pre HTML tag. -
TdApi.TextEntityTypeStrikethrough
- represents a strikethrough text. -
TdApi.TextEntityTypeUnderline
- represents an underlined text. -
TdApi.TextEntityTypeUrl
- represents an HTTP URL.
Example
/**
* Entities contained in the text.
* Entities can be nested, but must not mutually intersect with each other.
* Pre, Code and PreCode entities can't contain other entities.
* Bold, Italic, Underline and Strikethrough entities can contain
* and to be contained in all other entities.
* All other entities can't contain each other.
*/
fun someFunThatGetsFormattedText(formattedText: TdApi.FormattedText) {
val entities: Array<TdApi.TextEntity> = formattedText.entities
for (entity in entities) {
// Length of the entity, in UTF-16 code units.
val entityLength: Int = entity.length
// Offset of the entity in UTF-16 code units.
val entityOffset: Int = entity.offset
// Type of the entity.
val entityType: TdApi.TextEntityType = entity.type
when (entityType) {
is TdApi.TextEntityTypeMentionName -> {
val userId: Long = entityType.userId
}
is TdApi.TextEntityTypePreCode -> {
val language: String = entityType.language
}
is TdApi.TextEntityTypeTextUrl -> {
val url: String = entityType.url
}
// Other types such as Italic, Bold, Underline, Strikethrough
// has no public properties, so at least you could get their class name
is TdApi.TextEntityTypeBold -> {
val typeName: String = entityType.javaClass.simpleName
.removePrefix("TextEntityType")
println("This text entity has $typeName style")
}
}
}
}