Skip to content

Format messages

@gramio/format is built-in GramIO package. You can also use it outside of this framework because it is framework-agnostic.

See also API Reference.

Format

Template literal that helps construct message entities for text formatting.

Use if you want to strip all of the indentation from the beginning of each line. (like common-tags#stripindents or dedent)

NOTE: for format with arrays use it with join helper

ts
format
`some text`;
// or
format
`${
bold
`Hmm...`} ${
link
(
"GramIO", "https://github.com/gramiojs/gramio" )}?`;

Let's send something...

ts
bot
.
api
.
sendMessage
({
chat_id
: 12321,
text
:
format
`${
bold
`Hi!`}
Can ${
italic
("you")} help ${
spoiler
`me`}?
Can you give me a ${
link
("star", "https://github.com/gramiojs/gramio")}?`,
});

format

FormatSaveIndents

Template literal that helps construct message entities for text formatting.

Use if you want to save all of the indentation.

NOTE: for format with arrays use it with join helper

ts
bot
.
api
.
sendMessage
({
chat_id
: 12321,
text
:
formatSaveIndents
`${
bold
`Hi!`}
Can ${
italic
("you")} help ${
spoiler
`me`}?
Can you give me a ${
link
("star", "https://github.com/gramiojs/gramio")}?`,
});

format-save-indents

Entities

Bold

Format text as bold. Cannot be combined with code and pre.

ts
format
`Format text as ${
bold
`bold`}`;

bold example

Italic

Format text as italic. Cannot be combined with code and pre.

ts
format
`Format text as ${
italic
`italic`}`;

italic example

Underline

Format text as underline. Cannot be combined with code and pre.

ts
format
`Format text as ${
underline
`underline`}`;

underline example

Strikethrough

Format text as strikethrough. Cannot be combined with code and pre.

ts
format
`Format text as ${
strikethrough
`strikethrough`}`;

strikethrough example

Spoiler

Format text as

spoiler
. Cannot be combined with code and pre.

ts
format
`Format text as ${
spoiler
`spoiler`}`;

spoiler example

Blockquote

Format text as blockquote. Cannot be nested.

ts
format
`Format text as ${
blockquote
`blockquote`}`;

blockquote example

Expandable blockquote

Format text as expandable blockquote. Cannot be nested.

ts
format
`Format text as ${
expandableBlockquote
(
loremIpsum
({
count
: 20 }))}`;

expandable blockquote example

Code

Format text as code. Convenient for copied items. Cannot be combined with any other format.

ts
format
`Format text as ${
code
`code`}`;

code example

Pre

Format text as pre. Cannot be combined with any other format. (Supported languages)

ts
format
`Format text as ${
pre
`pre`}`;
// or with language
format
`Format text as ${
pre
(`console.log("pre with language")`, "js")}`;

pre example

Format text as link. Cannot be combined with code and pre.

ts
format
`Format text as ${
link
("link", "https://github.com/gramiojs/gramio")}`;

link example

Mention

Format text as mention. Cannot be combined with code and pre.

ts
format
`format text as ${
mention
("mention", {
id
: 12312312,
is_bot
: false,
first_name
: "GramIO",
})}`;

mention example

🄲 🅄 🅂 🅃 🄾 🄼 ㅤ🄴 🄼 🄾 🄹 🄸

Insert custom emoji by their id.

ts
format
`text with emoji - ${
customEmoji
("⚔️", "5222106016283378623")}`;

WARNING

Custom emoji entities can only be used by bots that purchased additional usernames on Fragment.

Helpers

Join

Helper for great work with formattable arrays. ([].join break styling)

Separator by default is ,

ts
format
`${
join
(["test", "other"], (
x
) =>
format
`${
bold
(
x
)}`, "\n")}`;