GramIO API Reference / @gramio/format/dist
@gramio/format/dist
Variables
blockquote()
constblockquote: {(str):FormattableString; (strings, ...values):FormattableString; }
Defined in: format/index.d.ts:103
Format text as blockquote. Cannot be nested.
Call Signature
(
str):FormattableString
Parameters
| Parameter | Type |
|---|---|
str | Stringable |
Returns
Call Signature
(
strings, ...values):FormattableString
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | Stringable[] |
Returns
Example
blockquote`test`
format`test ${blockquote(bold("GramIO"))}`
format`Format text as ${blockquote`blockquote`}`;
bold()
constbold: {(str):FormattableString; (strings, ...values):FormattableString; }
Defined in: format/index.d.ts:33
Format text as bold. Cannot be combined with code and pre.
Call Signature
(
str):FormattableString
Parameters
| Parameter | Type |
|---|---|
str | Stringable |
Returns
Call Signature
(
strings, ...values):FormattableString
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | Stringable[] |
Returns
Example
bold`test`
format`test ${bold(italic("GramIO"))}`
format`Format text as ${bold`bold`}`;
code()
constcode: {(str):FormattableString; (strings, ...values):FormattableString; }
Defined in: format/index.d.ts:131
Format text as code. Cannot be combined with any other format.
Call Signature
(
str):FormattableString
Parameters
| Parameter | Type |
|---|---|
str | Stringable |
Returns
Call Signature
(
strings, ...values):FormattableString
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | Stringable[] |
Returns
Example
code`test`
format`test ${code("copy it")}`
format`Format text as ${code`code`}`;
customEmoji()
constcustomEmoji: (str,custom_emoji_id) =>FormattableString
Defined in: format/index.d.ts:182
Insert custom emoji by their id.
Parameters
| Parameter | Type |
|---|---|
str | Stringable | null | undefined |
custom_emoji_id | string |
Returns
Example
customEmoji("⚔️", "5222106016283378623")
format`test ${customEmoji("⚔️", "5222106016283378623")}`NOTE: Custom emoji entities can only be used by bots that purchased additional usernames on Fragment. 
dateTime()
constdateTime: (str,unix_time,date_time_format?) =>FormattableString
Defined in: format/index.d.ts:212
Format text as a date/time entity with a Unix timestamp. Telegram renders it in the user's locale and timezone.
Parameters
| Parameter | Type | Description |
|---|---|---|
str | Stringable | null | undefined | The display text (shown as-is when date_time_format is empty) |
unix_time | number | Unix timestamp associated with the entity |
date_time_format? | string | Optional format string matching `r |
Returns
Example
dateTime("soon", 1740787200, "r") // relative: "in 2 days"
dateTime("17.03.22", 1740787200, "d") // short date
dateTime("March 17", 1740787200, "D") // long date
dateTime("22:45", 1740787200, "t") // short time
dateTime("22:45:00", 1740787200, "T") // long time
dateTime("Thu, March 17", 1740787200, "wD") // weekday + long date
dateTime("March 17, 22:45", 1740787200, "Dt") // long date + short time
format`Event starts ${dateTime("March 17 at 22:45", 1740787200, "DT")}`
expandableBlockquote()
constexpandableBlockquote: {(str):FormattableString; (strings, ...values):FormattableString; }
Defined in: format/index.d.ts:117
Format text as expandable blockquote. Cannot be nested.
Call Signature
(
str):FormattableString
Parameters
| Parameter | Type |
|---|---|
str | Stringable |
Returns
Call Signature
(
strings, ...values):FormattableString
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | Stringable[] |
Returns
Example
blockquote`test`
format`test ${expandableBlockquote(bold("GramIO"))}`
format`Format text as ${expandableBlockquote`blockquote`}`;
FormattableMap
constFormattableMap:FormattableMethods
Defined in: format/index.d.ts:14
A set of methods that decompose the FormattableString into a string and an array of entities for further sending to the Telegram Bot API
Codegenerated
italic()
constitalic: {(str):FormattableString; (strings, ...values):FormattableString; }
Defined in: format/index.d.ts:47
Format text as italic. Cannot be combined with code and pre.
Call Signature
(
str):FormattableString
Parameters
| Parameter | Type |
|---|---|
str | Stringable |
Returns
Call Signature
(
strings, ...values):FormattableString
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | Stringable[] |
Returns
Example
italic`test`
format`test ${italic(bold("GramIO"))}`
format`Format text as ${italic`italic`}`;
link()
constlink: (str,url) =>FormattableString
Defined in: format/index.d.ts:161
Format text as link. Cannot be combined with code and pre.
Parameters
| Parameter | Type |
|---|---|
str | Stringable | null | undefined |
url | string |
Returns
Example
link("test", "https://...")
format`test ${bold(link("GramIO", "https://github.com/gramiojs/gramio"))}`
format`Format text as ${link("link", "https://github.com/gramiojs/gramio")}`;
mention()
constmention: (str,user) =>FormattableString
Defined in: format/index.d.ts:171
Format text as mention. Cannot be combined with code and pre.
Parameters
| Parameter | Type |
|---|---|
str | Stringable | null | undefined |
user | TelegramUser |
Returns
Example
mention("friend", { id: 228, is_bot: false, first_name: "GramIO"})
format`test ${mention("friend", { id: 228, is_bot: false, first_name: "GramIO"})}`
pre()
constpre: (str,language?) =>FormattableString
Defined in: format/index.d.ts:150
Format text as pre. Cannot be combined with any other format.
Parameters
| Parameter | Type |
|---|---|
str | Stringable | null | undefined |
language? | string |
Returns
Example
pre`test`
format`test ${pre(`console.log("GramIO")`, "js")}`pre with language result is
console.log("GramIO")
spoiler()
constspoiler: {(str):FormattableString; (strings, ...values):FormattableString; }
Defined in: format/index.d.ts:89
Format text as spoiler. Cannot be combined with code and pre.
Call Signature
(
str):FormattableString
Parameters
| Parameter | Type |
|---|---|
str | Stringable |
Returns
Call Signature
(
strings, ...values):FormattableString
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | Stringable[] |
Returns
Example
spoiler`test`
format`test ${spoiler(bold("GramIO"))}`
format`Format text as ${spoiler`spoiler`}`;
strikethrough()
conststrikethrough: {(str):FormattableString; (strings, ...values):FormattableString; }
Defined in: format/index.d.ts:75
Format text as strikethrough. Cannot be combined with code and pre.
Call Signature
(
str):FormattableString
Parameters
| Parameter | Type |
|---|---|
str | Stringable |
Returns
Call Signature
(
strings, ...values):FormattableString
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | Stringable[] |
Returns
Example
strikethrough`test`
format`test ${strikethrough(bold("GramIO"))}`
format`Format text as ${strikethrough`strikethrough`}`;
underline()
constunderline: {(str):FormattableString; (strings, ...values):FormattableString; }
Defined in: format/index.d.ts:61
Format text as underline. Cannot be combined with code and pre.
Call Signature
(
str):FormattableString
Parameters
| Parameter | Type |
|---|---|
str | Stringable |
Returns
Call Signature
(
strings, ...values):FormattableString
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | Stringable[] |
Returns
Example
underline`test`
format`test ${underline(bold("GramIO"))}`
format`Format text as ${underline`underline`}`;
Functions
format()
format(
stringParts, ...strings):FormattableString
Defined in: format/index.d.ts:249
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.
NOTE: for format with arrays use it with join helper -
format`${join(["test", "other"], (x) => format`${bold(x)}`, "\n")}`Parameters
| Parameter | Type |
|---|---|
stringParts | TemplateStringsArray |
...strings | Stringable[] |
Returns
Example
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()
formatSaveIndents(
stringParts, ...strings):FormattableString
Defined in: format/index.d.ts:275
Template literal that helps construct message entities for text formatting.
[Documentation](https://gramio.dev/formatting/)
Use if you want to save all of the indentation.
NOTE: for format with arrays use it with join helper -
format`${join(["test", "other"], (x) => format`${bold(x)}`, "\n")}`Parameters
| Parameter | Type |
|---|---|
stringParts | TemplateStringsArray |
...strings | Stringable[] |
Returns
Example
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")}?`
})
join()
Call Signature
join(
array,separator?):FormattableString
Defined in: format/index.d.ts:222
Helper for great work with formattable arrays. ([].join break styling) Separator by default is ,
Parameters
| Parameter | Type |
|---|---|
array | (false | Stringable)[] |
separator? | string |
Returns
Example
join([format`hello`, format`world`], "\n")
format`${join(["test", "other"], (x) => format`${bold(x)}`, "\n")}`Call Signature
join<
T>(array,iterator,separator?):FormattableString
Defined in: format/index.d.ts:223
Helper for great work with formattable arrays. ([].join break styling) Separator by default is ,
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
array | T[] |
iterator | (item, index) => false | Stringable |
separator? | string |
Returns
Example
join([format`hello`, format`world`], "\n")
format`${join(["test", "other"], (x) => format`${bold(x)}`, "\n")}`References
FormattableString
Re-exports FormattableString
getFormattable
Re-exports getFormattable
Stringable
Re-exports Stringable