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.
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(text: Stringable);
Combines this FormattedString with a bold formatted string
bold
bold(text: Stringable);
Combines this FormattedString with a bold formatted string
i
i(text: Stringable);
Combines this FormattedString with an italic formatted string
italic
italic(text: Stringable);
Combines this FormattedString with an italic formatted string
s
s(text: Stringable);
Combines this FormattedString with a strikethrough formatted string
strikethrough
strikethrough(text: Stringable);
Combines this FormattedString with a strikethrough formatted string
u
u(text: Stringable);
Combines this FormattedString with an underline formatted string
underline
underline(text: Stringable);
Combines this FormattedString with an underline formatted string
a
a(text: Stringable, url: string);
Combines this FormattedString with a link formatted string
link
link(text: Stringable, url: string);
Combines this FormattedString with a link formatted string
code
code(text: Stringable);
Combines this FormattedString with a code formatted string
pre
pre(text: Stringable, language: string);
Combines this FormattedString with a pre formatted string (code block)
spoiler
spoiler(text: Stringable);
Combines this FormattedString with a spoiler formatted string
blockquote
blockquote(text: Stringable);
Combines this FormattedString with a blockquote formatted string
expandableBlockquote
expandableBlockquote(text: Stringable);
Combines this FormattedString with an expandable blockquote formatted string
mentionUser
mentionUser(text: Stringable, userId: number);
Combines this FormattedString with a user mention formatted string
customEmoji
customEmoji(placeholder: Stringable, emoji: string);
Combines this FormattedString with a custom emoji formatted string
linkMessage
linkMessage(
text: Stringable,
chatId: number,
messageId: number,
);
Combines this FormattedString with a message link formatted string
plain
plain(text: string);
Combines this FormattedString with plain text
slice
slice(start?: number, end?: number): FormattedString;
Returns a deep copy of a portion of this FormattedString
find
find(pattern: FormattedString): number;
Finds the first occurrence of a FormattedString pattern within this FormattedString that matches both the raw text and raw entities exactly.
Static Methods
b
b(text: Stringable);
Creates a bold formatted string
bold
bold(text: Stringable);
Creates a bold formatted string
i
i(text: Stringable);
Creates an italic formatted string
italic
italic(text: Stringable);
Creates an italic formatted string
s
s(text: Stringable);
Creates a strikethrough formatted string
strikethrough
strikethrough(text: Stringable);
Creates a strikethrough formatted string
u
u(text: Stringable);
Creates an underline formatted string
underline
underline(text: Stringable);
Creates an underline formatted string
a
a(text: Stringable, url: string);
Creates a link formatted string
link
link(text: Stringable, url: string);
Creates a link formatted string
code
code(text: Stringable);
Creates a code formatted string
pre
pre(text: Stringable, language: string);
Creates a pre formatted string (code block)
spoiler
spoiler(text: Stringable);
Creates a spoiler formatted string
blockquote
blockquote(text: Stringable);
Creates a blockquote formatted string
expandableBlockquote
expandableBlockquote(text: Stringable);
Creates an expandable blockquote formatted string
mentionUser
mentionUser(text: Stringable, userId: number);
Creates a user mention formatted string
customEmoji
customEmoji(placeholder: Stringable, emoji: string);
Creates a custom emoji formatted string
linkMessage
linkMessage(
text: Stringable,
chatId: number,
messageId: number,
);
Creates a message link formatted string
join
join(items: (Stringable | TextWithEntities | CaptionWithEntities | string)[], separator?: Stringable | TextWithEntities | CaptionWithEntities | string);
Joins an array of formatted strings or plain text into a single FormattedString