Skip to content

Commit 65f97ed

Browse files
committed
Extend section
1 parent ff6fd96 commit 65f97ed

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

_config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ yarn ${jsr ? "add jsr:" + pkg : "add " + pkg}
240240
<code-group-item title="npm">
241241
242242
\`\`\`shell
243-
${jsr ? "npx jsr i " + pkg : "npm install " + pkg}
243+
${jsr ? "npx jsr add " + pkg : "npm install " + pkg}
244244
\`\`\`
245245
246246
</code-group-item>

src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Its key features include:
3434
9. [Keyboards and Callback Queries](/keyboards-and-callback-queries) {{ "/keyboards-and-callback-queries" |> i }}
3535
10. [Files](/files) {{ "/files" |> i }}
3636
11. [Inline Queries](/inline-queries) {{ "/inline-queries" |> i }}
37-
12. [Formatting Text](/formatting-text) {{ "/formatting-text" |> i }}
37+
12. [Rich Messages and Text Formatting](/rich-messages-and-text-formatting) {{ "/rich-messages-and-text-formatting" |> i }}
3838

3939
### Guides
4040

src/inline-queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Inline Queries
33
parent: /#walkthrough
44
prev: /files
5-
next: /formatting-text
5+
next: /rich-messages-and-text-formatting
66
---
77

88
Inline mode lets users interact with a bot from any chat by typing its username followed by a query. It must first be enabled for the bot through [@BotFather](https://t.me/BotFather).
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Formatting Text
2+
title: Rich Messages and Text Formatting
33
parent: /#walkthrough
44
prev: /inline-queries
55
---
@@ -72,3 +72,43 @@ await client.sendMessage(chatId, text, {
7272
```
7373

7474
Explicit entities are useful when text is assembled dynamically because formatting does not depend on escaping markup characters.
75+
76+
## Entity Builders
77+
78+
The [@mtkruto/fmt](https://jsr.io/@mtkruto/fmt) package provides chainable builders that create text and entities together, keeping their offsets aligned as text is added.
79+
80+
{{ "jsr:@mtkruto/fmt" |> install }}
81+
82+
```ts
83+
import { text } from "@mtkruto/fmt/entities";
84+
85+
const formatted = text("Hello, ")
86+
.bold("world")
87+
.text("! Visit ")
88+
.link("MTKruto", "https://mtkru.to")
89+
.text(".");
90+
91+
await client.sendMessage(chatId, formatted.rawText, {
92+
entities: formatted.toArray(),
93+
});
94+
```
95+
96+
The package also provides builders for secret-chat entities through its `secret-entities` export.
97+
98+
## Rich Messages
99+
100+
Rich messages are built from page blocks and can contain headings, paragraphs, lists, tables, media, and other structured content. Use {{ "sendRichText" |> m }} with an {{ "InputRichText" |> t }} made from blocks, HTML, or Markdown.
101+
102+
The `rich` export of `@mtkruto/fmt` makes it easier to construct blocks and nested text components.
103+
104+
```ts
105+
import { bold, heading1 } from "@mtkruto/fmt/rich";
106+
107+
const blocks = heading1("Release notes")
108+
.paragraph(["Version ", bold("1.0"), " is ready."]);
109+
110+
await client.sendRichText(chatId, {
111+
type: "blocks",
112+
blocks: blocks.toArray(),
113+
});
114+
```

0 commit comments

Comments
 (0)