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
format`some text`;
// or
format`${bold`Hmm...`} ${link(
"GramIO",
"https://github.com/gramiojs/gramio"
)}?`;
Let's send something...
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")}?`,
});
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
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")}?`,
});
Entities
Bold
Format text as bold. Cannot be combined with code
and pre
.
format`Format text as ${bold`bold`}`;
Italic
Format text as italic. Cannot be combined with code
and pre
.
format`Format text as ${italic`italic`}`;
Underline
Format text as underline. Cannot be combined with code
and pre
.
format`Format text as ${underline`underline`}`;
Strikethrough
Format text as strikethrough. Cannot be combined with code
and pre
.
format`Format text as ${strikethrough`strikethrough`}`;
Spoiler
Format text as
code
and pre
.format`Format text as ${spoiler`spoiler`}`;
Blockquote
Format text as blockquote. Cannot be nested.
format`Format text as ${blockquote`blockquote`}`;
Expandable blockquote
Format text as expandable blockquote. Cannot be nested.
format`Format text as ${expandableBlockquote(loremIpsum({ count: 20 }))}`;
Code
Format text as code
. Convenient for copied items. Cannot be combined with any other format.
format`Format text as ${code`code`}`;
Pre
Format text as pre
. Cannot be combined with any other format. (Supported languages)
format`Format text as ${pre`pre`}`;
// or with language
format`Format text as ${pre(`console.log("pre with language")`, "js")}`;
Link
Format text as link. Cannot be combined with code
and pre
.
format`Format text as ${link("link", "https://github.com/gramiojs/gramio")}`;
Mention
Format text as mention. Cannot be combined with code
and pre
.
format`format text as ${mention("mention", {
id: 12312312,
is_bot: false,
first_name: "GramIO",
})}`;
🄲 🅄 🅂 🅃 🄾 🄼 ㅤ🄴 🄼 🄾 🄹 🄸
Insert custom emoji by their id.
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 ,
format`${join(["test", "other"], (x) => format`${bold(x)}`, "\n")}`;