FormattedString
Represents the formatted string after parsing. This class provides a unified interface for working with formatted text that can be used as both message text and caption content in Telegram Bot API calls.
Implements
Constructors
FormattedString(rawText: string, rawEntities?: MessageEntity[]);Creates a new Formatted instance.
Properties
rawEntities
rawEntities: MessageEntity[];The entities backing this FormattedString.
rawText
rawText: string;The plain text content
Methods
caption (getter)
get caption();
Gets the caption text. This is an alias for the raw text content. Used when this FormattedString is used as caption content.
text (getter)
get text();
Gets the plain text content. This is an alias for the raw text content. Used when this FormattedString is used as message text.
title (getter)
get title();
Gets the title. Alias for rawText. Used when this FormattedString is used as title.
text_entities (getter)
get text_entities();
Gets the text_entities. Alias for rawEntities. Used when this FormattedString is used as text with text_entities.
title_entities (getter)
get title_entities();
Gets the title_entities. Alias for rawEntities. Used when this FormattedString is used as title_entities.
caption_entities (getter)
get caption_entities();
Gets the caption entities. This is an alias for the raw entities. Used when this FormattedString is used as caption content.
entities (getter)
get entities();
Gets the message entities. This is an alias for the raw entities. Used when this FormattedString is used as message text.
toString
toString();
Returns the string representation of this Formatted object
b
b();
Combines this FormattedString with a bold formatted string
bold
bold();
Combines this FormattedString with a bold formatted string
i
i();
Combines this FormattedString with an italic formatted string
italic
italic();
Combines this FormattedString with an italic formatted string
s
s();
Combines this FormattedString with a strikethrough formatted string
strikethrough
strikethrough();
Combines this FormattedString with a strikethrough formatted string
u
u();
Combines this FormattedString with an underline formatted string
underline
underline();
Combines this FormattedString with an underline formatted string
a
a();
Combines this FormattedString with a link formatted string
link
link();
Combines this FormattedString with a link formatted string
code
code();
Combines this FormattedString with a code formatted string
pre
pre();
Combines this FormattedString with a pre formatted string (code block)
spoiler
spoiler();
Combines this FormattedString with a spoiler formatted string
blockquote
blockquote();
Combines this FormattedString with a blockquote formatted string
expandableBlockquote
expandableBlockquote();
Combines this FormattedString with an expandable blockquote formatted string
mentionUser
mentionUser();
Combines this FormattedString with a user mention formatted string
customEmoji
customEmoji();
emoji
emoji();
Combines this FormattedString with an emoji formatted string using custom emoji
time
time();
Combines this FormattedString with a date_time formatted string
linkMessage
linkMessage();
Combines this FormattedString with a message link formatted string
plain
plain();
Combines this FormattedString with plain text
split
split();
Splits this FormattedString into an array of FormattedStrings using a separator
splitByText
splitByText();
Splits this FormattedString into an array of FormattedStrings using a separator, ignoring inequalities in rawEntities. Only uses rawText to determine if this is a valid position to split.
slice
slice();
Returns a copy of a portion of this FormattedString
_findMatches
_findMatches();
Protected method that finds pattern matches within this FormattedString.
find
find();
Finds the first occurrence of a FormattedString pattern within this FormattedString that matches both the raw text and raw entities exactly.
findAll
findAll();
Finds all occurrences of a FormattedString pattern within this FormattedString that match both the raw text and raw entities exactly.
replaceMatches
replaceMatches();
Protected method to replace matches at given offsets with a replacement.
replace
replace();
Returns a new FormattedString with the first occurrence of pattern replaced by replacement. Both the raw text and raw entities must match exactly for replacement to occur.
replaceAll
replaceAll();
Returns a new FormattedString with all occurrences of pattern replaced by replacement. Both the raw text and raw entities must match exactly for replacement to occur.
concat
concat();
Concatenates this FormattedString with one or more other FormattedStrings
startsWith
startsWith();
Checks whether this FormattedString starts with the specified pattern. Both the raw text and raw entities must match exactly.
endsWith
endsWith();
Checks whether this FormattedString ends with the specified pattern. Both the raw text and raw entities must match exactly.
Static Methods
b
b();
Creates a bold formatted string
bold
bold();
Creates a bold formatted string
i
i();
Creates an italic formatted string
italic
italic();
Creates an italic formatted string
s
s();
Creates a strikethrough formatted string
strikethrough
strikethrough();
Creates a strikethrough formatted string
u
u();
Creates an underline formatted string
underline
underline();
Creates an underline formatted string
a
a();
Creates a link formatted string
link
link();
Creates a link formatted string
code
code();
Creates a code formatted string
pre
pre();
Creates a pre formatted string (code block)
spoiler
spoiler();
Creates a spoiler formatted string
blockquote
blockquote();
Creates a blockquote formatted string
expandableBlockquote
expandableBlockquote();
Creates an expandable blockquote formatted string
mentionUser
mentionUser();
Creates a user mention formatted string
customEmoji
customEmoji();
emoji
emoji();
Creates an emoji formatted string using custom emoji
time
time();
Creates a date_time formatted string
linkMessage
linkMessage();
Creates a message link formatted string
join
join();
Joins an array of formatted strings or plain text into a single FormattedString
_split
_split();
Internal method that implements the shared splitting logic for both split and splitByText methods
split
split();
Splits a FormattedString into an array of FormattedStrings using a separator
splitByText
splitByText();
Splits a FormattedString into an array of FormattedStrings using a separator, ignoring inequalities in rawEntities. Only uses rawText to determine if this is a valid position to split.
startsWith
startsWith();
Static method to check whether a FormattedString starts with the specified pattern. Both the raw text and raw entities must match exactly.
endsWith
endsWith();
Static method to check whether a FormattedString ends with the specified pattern. Both the raw text and raw entities must match exactly.