Skip to content

GramIO API Reference / @gramio/format/dist

@gramio/format/dist

Variables

blockquote()

const blockquote: {(str): FormattableString; (strings, ...values): FormattableString; }

Defined in: format/index.d.ts:103

Format text as blockquote. Cannot be nested.

Call Signature

(str): FormattableString

Parameters
ParameterType
strStringable
Returns

FormattableString

Call Signature

(strings, ...values): FormattableString

Parameters
ParameterType
stringsTemplateStringsArray
...valuesStringable[]
Returns

FormattableString

Example

ts
blockquote`test`
format`test ${blockquote(bold("GramIO"))}`
format`Format text as ${blockquote`blockquote`}`;

blockquote


bold()

const bold: {(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
ParameterType
strStringable
Returns

FormattableString

Call Signature

(strings, ...values): FormattableString

Parameters
ParameterType
stringsTemplateStringsArray
...valuesStringable[]
Returns

FormattableString

Example

ts
bold`test`
format`test ${bold(italic("GramIO"))}`
format`Format text as ${bold`bold`}`;

bold


code()

const code: {(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
ParameterType
strStringable
Returns

FormattableString

Call Signature

(strings, ...values): FormattableString

Parameters
ParameterType
stringsTemplateStringsArray
...valuesStringable[]
Returns

FormattableString

Example

ts
code`test`
format`test ${code("copy it")}`
format`Format text as ${code`code`}`;

code


customEmoji()

const customEmoji: (str, custom_emoji_id) => FormattableString

Defined in: format/index.d.ts:182

Insert custom emoji by their id.

Parameters

ParameterType
strStringable | null | undefined
custom_emoji_idstring

Returns

FormattableString

Example

ts
customEmoji("⚔️", "5222106016283378623")
format`test ${customEmoji("⚔️", "5222106016283378623")}`

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


dateTime()

const dateTime: (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

ParameterTypeDescription
strStringable | null | undefinedThe display text (shown as-is when date_time_format is empty)
unix_timenumberUnix timestamp associated with the entity
date_time_format?stringOptional format string matching `r

Returns

FormattableString

Example

ts
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")}`

dateTime


expandableBlockquote()

const expandableBlockquote: {(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
ParameterType
strStringable
Returns

FormattableString

Call Signature

(strings, ...values): FormattableString

Parameters
ParameterType
stringsTemplateStringsArray
...valuesStringable[]
Returns

FormattableString

Example

ts
blockquote`test`
format`test ${expandableBlockquote(bold("GramIO"))}`
format`Format text as ${expandableBlockquote`blockquote`}`;

blockquote


FormattableMap

const FormattableMap: 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()

const italic: {(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
ParameterType
strStringable
Returns

FormattableString

Call Signature

(strings, ...values): FormattableString

Parameters
ParameterType
stringsTemplateStringsArray
...valuesStringable[]
Returns

FormattableString

Example

ts
italic`test`
format`test ${italic(bold("GramIO"))}`
format`Format text as ${italic`italic`}`;

italic


const link: (str, url) => FormattableString

Defined in: format/index.d.ts:161

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

Parameters

ParameterType
strStringable | null | undefined
urlstring

Returns

FormattableString

Example

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

link


mention()

const mention: (str, user) => FormattableString

Defined in: format/index.d.ts:171

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

Parameters

ParameterType
strStringable | null | undefined
userTelegramUser

Returns

FormattableString

Example

ts
mention("friend", { id: 228, is_bot: false, first_name: "GramIO"})
format`test ${mention("friend", { id: 228, is_bot: false, first_name: "GramIO"})}`

mention


pre()

const pre: (str, language?) => FormattableString

Defined in: format/index.d.ts:150

Format text as pre. Cannot be combined with any other format.

Parameters

ParameterType
strStringable | null | undefined
language?string

Returns

FormattableString

Example

ts
pre`test`
format`test ${pre(`console.log("GramIO")`, "js")}`

pre with language result is

js
console.log("GramIO")

Supported languages

pre


spoiler()

const spoiler: {(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
ParameterType
strStringable
Returns

FormattableString

Call Signature

(strings, ...values): FormattableString

Parameters
ParameterType
stringsTemplateStringsArray
...valuesStringable[]
Returns

FormattableString

Example

ts
spoiler`test`
format`test ${spoiler(bold("GramIO"))}`
format`Format text as ${spoiler`spoiler`}`;

spoiler


strikethrough()

const strikethrough: {(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
ParameterType
strStringable
Returns

FormattableString

Call Signature

(strings, ...values): FormattableString

Parameters
ParameterType
stringsTemplateStringsArray
...valuesStringable[]
Returns

FormattableString

Example

ts
strikethrough`test`
format`test ${strikethrough(bold("GramIO"))}`
format`Format text as ${strikethrough`strikethrough`}`;


underline()

const underline: {(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
ParameterType
strStringable
Returns

FormattableString

Call Signature

(strings, ...values): FormattableString

Parameters
ParameterType
stringsTemplateStringsArray
...valuesStringable[]
Returns

FormattableString

Example

ts
underline`test`
format`test ${underline(bold("GramIO"))}`
format`Format text as ${underline`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.

Documentation

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 -

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

Parameters

ParameterType
stringPartsTemplateStringsArray
...stringsStringable[]

Returns

FormattableString

Example

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()

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 -

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

Parameters

ParameterType
stringPartsTemplateStringsArray
...stringsStringable[]

Returns

FormattableString

Example

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")}?`
})

formatSaveIndents


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
ParameterType
array(false | Stringable)[]
separator?string
Returns

FormattableString

Example
ts
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
ParameterType
arrayT[]
iterator(item, index) => false | Stringable
separator?string
Returns

FormattableString

Example
ts
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