@mtkruto/node 0.148.0 → 0.151.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/esm/3_types.d.ts +4 -0
  2. package/esm/3_types.d.ts.map +1 -1
  3. package/esm/3_types.js +4 -0
  4. package/esm/client/0_params.d.ts +18 -4
  5. package/esm/client/0_params.d.ts.map +1 -1
  6. package/esm/client/0_utilities.d.ts +1 -1
  7. package/esm/client/0_utilities.d.ts.map +1 -1
  8. package/esm/client/1_client_generic.d.ts +34 -6
  9. package/esm/client/1_client_generic.d.ts.map +1 -1
  10. package/esm/client/2_file_manager.d.ts.map +1 -1
  11. package/esm/client/2_file_manager.js +20 -0
  12. package/esm/client/3_filters.d.ts.map +1 -1
  13. package/esm/client/3_filters.js +4 -1
  14. package/esm/client/3_message_manager.d.ts +5 -2
  15. package/esm/client/3_message_manager.d.ts.map +1 -1
  16. package/esm/client/3_message_manager.js +326 -76
  17. package/esm/client/4_context.d.ts.map +1 -1
  18. package/esm/client/4_context.js +5 -1
  19. package/esm/client/6_client.d.ts +34 -6
  20. package/esm/client/6_client.d.ts.map +1 -1
  21. package/esm/client/6_client.js +43 -5
  22. package/esm/client/6_client_dispatcher.d.ts +34 -6
  23. package/esm/client/6_client_dispatcher.d.ts.map +1 -1
  24. package/esm/client/6_client_dispatcher.js +38 -4
  25. package/esm/tl/1_telegram_api.d.ts +120 -29
  26. package/esm/tl/1_telegram_api.d.ts.map +1 -1
  27. package/esm/tl/1_telegram_api.js +124 -26
  28. package/esm/types/0_message_counters.d.ts +1 -1
  29. package/esm/types/0_message_counters.d.ts.map +1 -1
  30. package/esm/types/0_upload_progress.d.ts +2 -0
  31. package/esm/types/0_upload_progress.d.ts.map +1 -1
  32. package/esm/types/1_chat_p.d.ts +2 -0
  33. package/esm/types/1_chat_p.d.ts.map +1 -1
  34. package/esm/types/1_chat_p.js +3 -2
  35. package/esm/types/1_input_poll_media.d.ts +128 -0
  36. package/esm/types/1_input_poll_media.d.ts.map +1 -0
  37. package/esm/types/1_input_poll_media.js +20 -0
  38. package/esm/types/2_message_entity.d.ts +16 -0
  39. package/esm/types/2_message_entity.d.ts.map +1 -1
  40. package/esm/types/2_message_entity.js +51 -45
  41. package/esm/types/3_checklist_item.d.ts +1 -1
  42. package/esm/types/3_checklist_item.d.ts.map +1 -1
  43. package/esm/types/3_input_poll_option.d.ts +3 -0
  44. package/esm/types/3_input_poll_option.d.ts.map +1 -1
  45. package/esm/types/3_message_reactions.d.ts +1 -1
  46. package/esm/types/3_message_reactions.d.ts.map +1 -1
  47. package/esm/types/3_rich_text_component.d.ts +268 -0
  48. package/esm/types/3_rich_text_component.d.ts.map +1 -0
  49. package/esm/types/3_rich_text_component.js +161 -0
  50. package/esm/types/4_gift.d.ts +1 -1
  51. package/esm/types/4_page_block.d.ts +479 -0
  52. package/esm/types/4_page_block.d.ts.map +1 -0
  53. package/esm/types/4_page_block.js +552 -0
  54. package/esm/types/4_poll.d.ts +1 -1
  55. package/esm/types/4_poll.d.ts.map +1 -1
  56. package/esm/types/4_reply_to.d.ts +4 -0
  57. package/esm/types/4_reply_to.d.ts.map +1 -1
  58. package/esm/types/5_input_rich_text.d.ts +38 -0
  59. package/esm/types/5_input_rich_text.d.ts.map +1 -0
  60. package/esm/types/5_input_rich_text.js +20 -0
  61. package/esm/types/6_message.d.ts +22 -1
  62. package/esm/types/6_message.d.ts.map +1 -1
  63. package/esm/types/6_message.js +30 -0
  64. package/esm/utilities/0_misc.d.ts +1 -0
  65. package/esm/utilities/0_misc.d.ts.map +1 -1
  66. package/esm/utilities/0_misc.js +1 -0
  67. package/package.json +1 -1
  68. package/script/3_types.d.ts +4 -0
  69. package/script/3_types.d.ts.map +1 -1
  70. package/script/3_types.js +4 -0
  71. package/script/client/0_params.d.ts +18 -4
  72. package/script/client/0_params.d.ts.map +1 -1
  73. package/script/client/0_utilities.d.ts +1 -1
  74. package/script/client/0_utilities.d.ts.map +1 -1
  75. package/script/client/1_client_generic.d.ts +34 -6
  76. package/script/client/1_client_generic.d.ts.map +1 -1
  77. package/script/client/2_file_manager.d.ts.map +1 -1
  78. package/script/client/2_file_manager.js +20 -0
  79. package/script/client/3_filters.d.ts.map +1 -1
  80. package/script/client/3_filters.js +4 -1
  81. package/script/client/3_message_manager.d.ts +5 -2
  82. package/script/client/3_message_manager.d.ts.map +1 -1
  83. package/script/client/3_message_manager.js +325 -75
  84. package/script/client/4_context.d.ts.map +1 -1
  85. package/script/client/4_context.js +5 -1
  86. package/script/client/6_client.d.ts +34 -6
  87. package/script/client/6_client.d.ts.map +1 -1
  88. package/script/client/6_client.js +42 -4
  89. package/script/client/6_client_dispatcher.d.ts +34 -6
  90. package/script/client/6_client_dispatcher.d.ts.map +1 -1
  91. package/script/client/6_client_dispatcher.js +38 -4
  92. package/script/tl/1_telegram_api.d.ts +120 -29
  93. package/script/tl/1_telegram_api.d.ts.map +1 -1
  94. package/script/tl/1_telegram_api.js +124 -26
  95. package/script/types/0_message_counters.d.ts +1 -1
  96. package/script/types/0_message_counters.d.ts.map +1 -1
  97. package/script/types/0_upload_progress.d.ts +2 -0
  98. package/script/types/0_upload_progress.d.ts.map +1 -1
  99. package/script/types/1_chat_p.d.ts +2 -0
  100. package/script/types/1_chat_p.d.ts.map +1 -1
  101. package/script/types/1_chat_p.js +3 -2
  102. package/script/types/1_input_poll_media.d.ts +128 -0
  103. package/script/types/1_input_poll_media.d.ts.map +1 -0
  104. package/script/types/1_input_poll_media.js +21 -0
  105. package/script/types/2_message_entity.d.ts +16 -0
  106. package/script/types/2_message_entity.d.ts.map +1 -1
  107. package/script/types/2_message_entity.js +53 -45
  108. package/script/types/3_checklist_item.d.ts +1 -1
  109. package/script/types/3_checklist_item.d.ts.map +1 -1
  110. package/script/types/3_input_poll_option.d.ts +3 -0
  111. package/script/types/3_input_poll_option.d.ts.map +1 -1
  112. package/script/types/3_message_reactions.d.ts +1 -1
  113. package/script/types/3_message_reactions.d.ts.map +1 -1
  114. package/script/types/3_rich_text_component.d.ts +268 -0
  115. package/script/types/3_rich_text_component.d.ts.map +1 -0
  116. package/script/types/3_rich_text_component.js +165 -0
  117. package/script/types/4_gift.d.ts +1 -1
  118. package/script/types/4_page_block.d.ts +479 -0
  119. package/script/types/4_page_block.d.ts.map +1 -0
  120. package/script/types/4_page_block.js +569 -0
  121. package/script/types/4_poll.d.ts +1 -1
  122. package/script/types/4_poll.d.ts.map +1 -1
  123. package/script/types/4_reply_to.d.ts +4 -0
  124. package/script/types/4_reply_to.d.ts.map +1 -1
  125. package/script/types/5_input_rich_text.d.ts +38 -0
  126. package/script/types/5_input_rich_text.d.ts.map +1 -0
  127. package/script/types/5_input_rich_text.js +21 -0
  128. package/script/types/6_message.d.ts +22 -1
  129. package/script/types/6_message.d.ts.map +1 -1
  130. package/script/types/6_message.js +30 -0
  131. package/script/utilities/0_misc.d.ts +1 -0
  132. package/script/utilities/0_misc.d.ts.map +1 -1
  133. package/script/utilities/0_misc.js +2 -1
@@ -0,0 +1,552 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2026 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ import { unreachable } from "../0_deps.js";
21
+ import { cleanObject } from "../1_utilities.js";
22
+ import { Api } from "../2_tl.js";
23
+ import { deserializeFileId, FileType, serializeFileId } from "./_file_id.js";
24
+ import { constructLocation } from "./0_location.js";
25
+ import { constructChatP } from "./1_chat_p.js";
26
+ import { constructPhoto } from "./1_photo.js";
27
+ import { constructRichTextComponent, richTextComponentToTlObject } from "./3_rich_text_component.js";
28
+ export function constructPageBlockListItem(pli, photos, documents) {
29
+ switch (pli._) {
30
+ case "pageListItemText":
31
+ return { type: "text", isCheckbox: !!pli.checkbox, isChecked: !!pli.checked, text: constructRichTextComponent(pli.text, photos) };
32
+ case "pageListItemBlocks":
33
+ return { type: "blockList", isCheckbox: !!pli.checkbox, isChecked: !!pli.checked, blocks: pli.blocks.map((v) => constructPageBlock(v, photos, documents)) };
34
+ }
35
+ }
36
+ export function pageBlockListItemToTlObject(pbli) {
37
+ switch (pbli.type) {
38
+ case "text":
39
+ return { _: "pageListItemText", checkbox: pbli.isCheckbox || undefined, checked: pbli.isChecked || undefined, text: richTextComponentToTlObject(pbli.text) };
40
+ case "blockList":
41
+ return { _: "pageListItemBlocks", checkbox: pbli.isCheckbox || undefined, checked: pbli.isChecked || undefined, blocks: pbli.blocks.map(pageBlockToTlObject) };
42
+ }
43
+ }
44
+ export function constructPageBlockCaption(pc, photos) {
45
+ return {
46
+ text: constructRichTextComponent(pc.text, photos),
47
+ credit: constructRichTextComponent(pc.credit, photos),
48
+ };
49
+ }
50
+ export function pageBlockCaptionToTlObject(pbc) {
51
+ return {
52
+ _: "pageCaption",
53
+ text: richTextComponentToTlObject(pbc.text),
54
+ credit: richTextComponentToTlObject(pbc.credit),
55
+ };
56
+ }
57
+ export function constructPageBlockTableCell(ptc, photos) {
58
+ return cleanObject({
59
+ isHeader: !!ptc.header,
60
+ isCenterAligned: !!ptc.align_center,
61
+ isRightAligned: !!ptc.align_right,
62
+ isMiddleVerticallyAligned: !!ptc.valign_middle,
63
+ isBottomVerticallyAligned: !!ptc.valign_bottom,
64
+ text: ptc.text ? constructRichTextComponent(ptc.text, photos) : undefined,
65
+ colspan: ptc.colspan,
66
+ rowspan: ptc.rowspan,
67
+ });
68
+ }
69
+ export function pageBlockTableCellToTlObject(pbtc) {
70
+ return {
71
+ _: "pageTableCell",
72
+ header: pbtc.isHeader || undefined,
73
+ align_center: pbtc.isCenterAligned || undefined,
74
+ align_right: pbtc.isRightAligned || undefined,
75
+ valign_middle: pbtc.isMiddleVerticallyAligned || undefined,
76
+ valign_bottom: pbtc.isBottomVerticallyAligned || undefined,
77
+ text: pbtc.text ? richTextComponentToTlObject(pbtc.text) : undefined,
78
+ colspan: pbtc.colspan,
79
+ rowspan: pbtc.rowspan,
80
+ };
81
+ }
82
+ export function constructPageBlockTableRow(ptr, photos) {
83
+ return {
84
+ cells: ptr.cells.map((v) => constructPageBlockTableCell(v, photos)),
85
+ };
86
+ }
87
+ export function pageBlockTableRowToTlObject(pbtr) {
88
+ return {
89
+ _: "pageTableRow",
90
+ cells: pbtr.cells.map(pageBlockTableCellToTlObject),
91
+ };
92
+ }
93
+ export function constructPageBlockOrderedListItem(ploi, photos, documents) {
94
+ switch (ploi._) {
95
+ case "pageListOrderedItemText":
96
+ return cleanObject({ type: "text", isCheckbox: !!ploi.checkbox, isChecked: !!ploi.checked, number: ploi.num, value: ploi.value, itemType: ploi.type, text: constructRichTextComponent(ploi.text, photos) });
97
+ case "pageListOrderedItemBlocks":
98
+ return cleanObject({ type: "blockList", isCheckbox: !!ploi.checkbox, isChecked: !!ploi.checked, number: ploi.num, value: ploi.value, itemType: ploi.type, blocks: ploi.blocks.map((v) => constructPageBlock(v, photos, documents)) });
99
+ }
100
+ unreachable();
101
+ }
102
+ export function pageBlockOrderedListItemToTlObject(pboli) {
103
+ switch (pboli.type) {
104
+ case "text":
105
+ return { _: "pageListOrderedItemText", checkbox: pboli.isCheckbox || undefined, checked: pboli.isCheckbox || undefined, text: richTextComponentToTlObject(pboli.text), num: pboli.number, type: pboli.itemType, value: pboli.value };
106
+ case "blockList":
107
+ return { _: "pageListOrderedItemBlocks", checkbox: pboli.isCheckbox || undefined, checked: pboli.isCheckbox || undefined, blocks: pboli.blocks.map(pageBlockToTlObject), num: pboli.number, type: pboli.itemType, value: pboli.value };
108
+ }
109
+ }
110
+ export function constructPageBlockRelatedArticle(pra) {
111
+ return cleanObject({
112
+ url: pra.url,
113
+ linkPreviewId: String(pra.webpage_id),
114
+ title: pra.title,
115
+ description: pra.description,
116
+ photoId: pra.photo_id ? String(pra.photo_id) : undefined,
117
+ author: pra.author,
118
+ date: pra.published_date,
119
+ });
120
+ }
121
+ export function pageBlockRelatedArticleToTlObject(pbra) {
122
+ return { _: "pageRelatedArticle", url: pbra.url, webpage_id: BigInt(pbra.linkPreviewId), title: pbra.title, description: pbra.description, photo_id: pbra.photoId ? BigInt(pbra.photoId) : undefined, author: pbra.author, published_date: pbra.date };
123
+ }
124
+ export function constructPageBlock(pb, photos, documents) {
125
+ switch (pb._) {
126
+ case "pageBlockUnsupported":
127
+ return { type: "unsupported" };
128
+ case "pageBlockTitle":
129
+ return { type: "title", text: constructRichTextComponent(pb.text, photos) };
130
+ case "pageBlockSubtitle":
131
+ return { type: "subtitle", text: constructRichTextComponent(pb.text, photos) };
132
+ case "pageBlockAuthorDate":
133
+ return { type: "authorDate", author: constructRichTextComponent(pb.author, photos), date: pb.published_date };
134
+ case "pageBlockHeader":
135
+ return { type: "header", text: constructRichTextComponent(pb.text, photos) };
136
+ case "pageBlockSubheader":
137
+ return { type: "subheader", text: constructRichTextComponent(pb.text, photos) };
138
+ case "pageBlockParagraph":
139
+ return { type: "paragraph", text: constructRichTextComponent(pb.text, photos) };
140
+ case "pageBlockPreformatted":
141
+ return cleanObject({ type: "pre", text: constructRichTextComponent(pb.text, photos), language: pb.language || undefined });
142
+ case "pageBlockFooter":
143
+ return { type: "footer", text: constructRichTextComponent(pb.text, photos) };
144
+ case "pageBlockDivider":
145
+ return { type: "divider" };
146
+ case "pageBlockAnchor":
147
+ return { type: "anchor", name: pb.name };
148
+ case "pageBlockList":
149
+ return { type: "list", items: pb.items.map((v) => constructPageBlockListItem(v, photos, documents)) };
150
+ case "pageBlockBlockquote":
151
+ return { type: "blockQuote", text: constructRichTextComponent(pb.text, photos), caption: constructRichTextComponent(pb.caption, photos) };
152
+ case "pageBlockPullquote":
153
+ return { type: "blockQuote", text: constructRichTextComponent(pb.text, photos), caption: constructRichTextComponent(pb.caption, photos) };
154
+ case "pageBlockPhoto": {
155
+ const fileId = constructPhoto(Api.as("photo", photos.find((v) => v.id === pb.photo_id))).fileId;
156
+ return cleanObject({ type: "photo", fileId, caption: constructPageBlockCaption(pb.caption, photos), isSpoiler: !!pb.spoiler, linkPreviewId: pb.webpage_id ? String(pb.webpage_id) : undefined, url: pb.url });
157
+ }
158
+ case "pageBlockVideo": {
159
+ const document = Api.as("document", documents.find((v) => v.id === pb.video_id));
160
+ const isAnimated = !!document.attributes.find((v) => Api.is("documentAttributeAnimated", v));
161
+ const fileId = {
162
+ type: FileType.Video,
163
+ dcId: document.dc_id,
164
+ location: { type: "common", id: document.id, accessHash: document.access_hash },
165
+ fileReference: document.file_reference,
166
+ };
167
+ return { type: isAnimated ? "animation" : "video", fileId: serializeFileId(fileId), caption: constructPageBlockCaption(pb.caption, photos), isSpoiler: !!pb.spoiler, isAutoplay: !!pb.autoplay, isLoop: !!pb.loop };
168
+ }
169
+ case "pageBlockCover":
170
+ return { type: "cover", cover: constructPageBlock(pb.cover, photos, documents) };
171
+ case "pageBlockEmbed":
172
+ return cleanObject({ type: "embed", caption: constructPageBlockCaption(pb.caption, photos), isFullWidth: !!pb.full_width, isScrollingAllowed: !!pb.allow_scrolling, width: pb.w, height: pb.h, html: pb.html, url: pb.url, posterPhotoId: pb.poster_photo_id ? String(pb.poster_photo_id) : undefined });
173
+ case "pageBlockEmbedPost":
174
+ return cleanObject({ type: "embedPost", caption: constructPageBlockCaption(pb.caption, photos), author: pb.author, authorPhotoId: String(pb.author_photo_id), blocks: pb.blocks.map((v) => constructPageBlock(v, photos, documents)), date: pb.date, linkPreviewId: String(pb.webpage_id), url: pb.url });
175
+ case "pageBlockCollage":
176
+ return cleanObject({ type: "collage", caption: constructPageBlockCaption(pb.caption, photos), items: pb.items.map((v) => constructPageBlock(v, photos, documents)) });
177
+ case "pageBlockSlideshow":
178
+ return cleanObject({ type: "slideshow", caption: constructPageBlockCaption(pb.caption, photos), items: pb.items.map((v) => constructPageBlock(v, photos, documents)) });
179
+ case "pageBlockChannel":
180
+ return cleanObject({ type: "channel", chat: constructChatP(pb.channel) });
181
+ case "pageBlockAudio": {
182
+ const document = Api.as("document", documents.find((v) => v.id === pb.audio_id));
183
+ const audioAttribute = document.attributes.find((v) => Api.is("documentAttributeAudio", v));
184
+ if (!audioAttribute) {
185
+ unreachable();
186
+ }
187
+ const fileId = {
188
+ type: FileType.Video,
189
+ dcId: document.dc_id,
190
+ location: { type: "common", id: document.id, accessHash: document.access_hash },
191
+ fileReference: document.file_reference,
192
+ };
193
+ return cleanObject({ type: audioAttribute.voice ? "voice" : "audio", fileId: serializeFileId(fileId), caption: constructPageBlockCaption(pb.caption, photos) });
194
+ }
195
+ case "pageBlockKicker":
196
+ return cleanObject({ type: "kicker", text: constructRichTextComponent(pb.text, photos) });
197
+ case "pageBlockTable":
198
+ return cleanObject({ type: "table", isBordered: !!pb.bordered, isStriped: !!pb.striped, title: constructRichTextComponent(pb.title, photos), rows: pb.rows.map((v) => constructPageBlockTableRow(v, photos)) });
199
+ case "pageBlockOrderedList":
200
+ return cleanObject({
201
+ type: "orderedList",
202
+ isReversed: !!pb.reversed,
203
+ items: pb.items.map((v) => constructPageBlockOrderedListItem(v, photos, documents)),
204
+ itemsType: pb.type,
205
+ start: pb.start,
206
+ });
207
+ case "pageBlockDetails":
208
+ return { type: "details", isOpen: !!pb.open, title: constructRichTextComponent(pb.title, photos), blocks: pb.blocks.map((v) => constructPageBlock(v, photos, documents)) };
209
+ case "pageBlockRelatedArticles":
210
+ return {
211
+ type: "relatedArticles",
212
+ title: constructRichTextComponent(pb.title, photos),
213
+ articles: pb.articles.map(constructPageBlockRelatedArticle),
214
+ };
215
+ case "pageBlockMap":
216
+ return {
217
+ type: "map",
218
+ caption: constructPageBlockCaption(pb.caption, photos),
219
+ width: pb.w,
220
+ height: pb.h,
221
+ zoom: pb.zoom,
222
+ location: constructLocation(Api.as("geoPoint", pb.geo)),
223
+ };
224
+ case "pageBlockHeading1":
225
+ return { type: "heading1", text: constructRichTextComponent(pb.text, photos) };
226
+ case "pageBlockHeading2":
227
+ return { type: "heading2", text: constructRichTextComponent(pb.text, photos) };
228
+ case "pageBlockHeading3":
229
+ return { type: "heading3", text: constructRichTextComponent(pb.text, photos) };
230
+ case "pageBlockHeading4":
231
+ return { type: "heading4", text: constructRichTextComponent(pb.text, photos) };
232
+ case "pageBlockHeading5":
233
+ return { type: "heading5", text: constructRichTextComponent(pb.text, photos) };
234
+ case "pageBlockHeading6":
235
+ return { type: "heading6", text: constructRichTextComponent(pb.text, photos) };
236
+ case "pageBlockMath":
237
+ return { type: "math", code: pb.source };
238
+ case "pageBlockThinking":
239
+ return { type: "thinking", text: constructRichTextComponent(pb.text, photos) };
240
+ case "inputPageBlockMap":
241
+ unreachable();
242
+ break;
243
+ case "pageBlockBlockquoteBlocks":
244
+ return { type: "blockQuoteBlocks", blocks: pb.blocks.map((v) => constructPageBlock(v, photos, documents)), caption: constructRichTextComponent(pb.caption, photos) };
245
+ }
246
+ unreachable();
247
+ }
248
+ export function pageBlockToTlObject(pb) {
249
+ switch (pb.type) {
250
+ case "unsupported":
251
+ return { _: "pageBlockUnsupported" };
252
+ case "title":
253
+ return { _: "pageBlockTitle", text: richTextComponentToTlObject(pb.text) };
254
+ case "subtitle":
255
+ return { _: "pageBlockSubtitle", text: richTextComponentToTlObject(pb.text) };
256
+ case "authorDate":
257
+ return { _: "pageBlockAuthorDate", author: richTextComponentToTlObject(pb.author), published_date: pb.date };
258
+ case "header":
259
+ return { _: "pageBlockHeader", text: richTextComponentToTlObject(pb.text) };
260
+ case "subheader":
261
+ return { _: "pageBlockSubheader", text: richTextComponentToTlObject(pb.text) };
262
+ case "paragraph":
263
+ return { _: "pageBlockParagraph", text: richTextComponentToTlObject(pb.text) };
264
+ case "pre":
265
+ return { _: "pageBlockPreformatted", text: richTextComponentToTlObject(pb.text), language: pb.language ?? "" };
266
+ case "footer":
267
+ return { _: "pageBlockFooter", text: richTextComponentToTlObject(pb.text) };
268
+ case "divider":
269
+ return { _: "pageBlockDivider" };
270
+ case "anchor":
271
+ return { _: "pageBlockAnchor", name: pb.name };
272
+ case "list":
273
+ return { _: "pageBlockList", items: pb.items.map(pageBlockListItemToTlObject) };
274
+ case "blockQuote":
275
+ return { _: "pageBlockBlockquote", text: richTextComponentToTlObject(pb.text), caption: richTextComponentToTlObject(pb.caption) };
276
+ case "pullQuote":
277
+ return { _: "pageBlockPullquote", text: richTextComponentToTlObject(pb.text), caption: richTextComponentToTlObject(pb.caption) };
278
+ case "photo": {
279
+ const location = deserializeFileId(pb.fileId).location;
280
+ if (!("id" in location)) {
281
+ unreachable();
282
+ }
283
+ return { _: "pageBlockPhoto", photo_id: location.id, caption: pageBlockCaptionToTlObject(pb.caption), spoiler: pb.isSpoiler || undefined, url: pb.url, webpage_id: pb.linkPreviewId ? BigInt(pb.linkPreviewId) : undefined };
284
+ }
285
+ case "video":
286
+ case "animation": {
287
+ const location = deserializeFileId(pb.fileId).location;
288
+ if (!("id" in location)) {
289
+ unreachable();
290
+ }
291
+ return { _: "pageBlockVideo", video_id: location.id, caption: pageBlockCaptionToTlObject(pb.caption), spoiler: pb.isSpoiler || undefined, autoplay: pb.isAutoplay || undefined, loop: pb.isLoop || undefined };
292
+ }
293
+ case "cover":
294
+ return { _: "pageBlockCover", cover: pageBlockToTlObject(pb.cover) };
295
+ case "embed":
296
+ return { _: "pageBlockEmbed", caption: pageBlockCaptionToTlObject(pb.caption), allow_scrolling: pb.isScrollingAllowed || undefined, full_width: pb.isFullWidth || undefined, w: pb.width, h: pb.height, html: pb.html, url: pb.url, poster_photo_id: pb.posterPhotoId ? BigInt(pb.posterPhotoId) : undefined };
297
+ case "embedPost":
298
+ return { _: "pageBlockEmbedPost", caption: pageBlockCaptionToTlObject(pb.caption), url: pb.url, author: pb.author, author_photo_id: BigInt(pb.authorPhotoId), blocks: pb.blocks.map(pageBlockToTlObject), date: pb.date, webpage_id: BigInt(pb.linkPreviewId) };
299
+ case "collage":
300
+ return { _: "pageBlockCollage", caption: pageBlockCaptionToTlObject(pb.caption), items: pb.items.map(pageBlockToTlObject) };
301
+ case "slideshow":
302
+ return { _: "pageBlockSlideshow", caption: pageBlockCaptionToTlObject(pb.caption), items: pb.items.map(pageBlockToTlObject) };
303
+ case "channel":
304
+ unreachable();
305
+ break;
306
+ case "audio":
307
+ case "voice": {
308
+ const location = deserializeFileId(pb.fileId).location;
309
+ if (!("id" in location)) {
310
+ unreachable();
311
+ }
312
+ return { _: "pageBlockAudio", audio_id: location.id, caption: pageBlockCaptionToTlObject(pb.caption) };
313
+ }
314
+ case "kicker":
315
+ return { _: "pageBlockKicker", text: richTextComponentToTlObject(pb.text) };
316
+ case "math":
317
+ return { _: "pageBlockMath", source: pb.code };
318
+ case "table":
319
+ return { _: "pageBlockTable", title: richTextComponentToTlObject(pb.title), rows: pb.rows.map(pageBlockTableRowToTlObject), bordered: pb.isBordered || undefined, striped: pb.isStriped || undefined };
320
+ case "orderedList":
321
+ return { _: "pageBlockOrderedList", items: pb.items.map(pageBlockOrderedListItemToTlObject), reversed: pb.isReversed || undefined, start: pb.start, type: pb.itemsType };
322
+ case "details":
323
+ return { _: "pageBlockDetails", title: richTextComponentToTlObject(pb.title), blocks: pb.blocks.map(pageBlockToTlObject), open: pb.isOpen || undefined };
324
+ case "relatedArticles":
325
+ return { _: "pageBlockRelatedArticles", title: richTextComponentToTlObject(pb.title), articles: pb.articles.map(pageBlockRelatedArticleToTlObject) };
326
+ case "map":
327
+ return { _: "inputPageBlockMap", geo: { _: "inputGeoPoint", lat: pb.location.latitude, long: pb.location.longitude, accuracy_radius: pb.location.horizontalAccuracy }, caption: pageBlockCaptionToTlObject(pb.caption), w: pb.width, h: pb.height, zoom: pb.zoom };
328
+ case "heading1":
329
+ return { _: "pageBlockHeading1", text: richTextComponentToTlObject(pb.text) };
330
+ case "heading2":
331
+ return { _: "pageBlockHeading2", text: richTextComponentToTlObject(pb.text) };
332
+ case "heading3":
333
+ return { _: "pageBlockHeading3", text: richTextComponentToTlObject(pb.text) };
334
+ case "heading4":
335
+ return { _: "pageBlockHeading4", text: richTextComponentToTlObject(pb.text) };
336
+ case "heading5":
337
+ return { _: "pageBlockHeading5", text: richTextComponentToTlObject(pb.text) };
338
+ case "heading6":
339
+ return { _: "pageBlockHeading6", text: richTextComponentToTlObject(pb.text) };
340
+ case "thinking":
341
+ return { _: "pageBlockThinking", text: richTextComponentToTlObject(pb.text) };
342
+ case "blockQuoteBlocks":
343
+ return { _: "pageBlockBlockquoteBlocks", caption: richTextComponentToTlObject(pb.caption), blocks: pb.blocks.map(pageBlockToTlObject) };
344
+ }
345
+ unreachable();
346
+ }
347
+ export function collectMediaFileIds(pageBlocks) {
348
+ const fileIds = new Array();
349
+ for (const m of collectPageBlockMedia(pageBlocks)) {
350
+ fileIds.push({ type: m.type, fileId: m.fileId });
351
+ }
352
+ for (const photo of collectRichTextComponentPhoto(collectRichTextComponents(pageBlocks))) {
353
+ fileIds.push({ type: "photo", fileId: photo.fileId });
354
+ }
355
+ return fileIds;
356
+ }
357
+ function collectRichTextComponentPhoto(components) {
358
+ const photos = new Array();
359
+ for (const component of components) {
360
+ for (const c of flattenRichTextComponent(component)) {
361
+ if (c.type === "photo") {
362
+ photos.push(c);
363
+ }
364
+ }
365
+ }
366
+ return photos;
367
+ }
368
+ function flattenRichTextComponent(component) {
369
+ const items = new Array();
370
+ switch (component.type) {
371
+ case "anchor":
372
+ case "dateTime":
373
+ case "bold":
374
+ case "italic":
375
+ case "underline":
376
+ case "strikethrough":
377
+ case "fixed":
378
+ case "link":
379
+ case "emailLink":
380
+ case "subscript":
381
+ case "superscript":
382
+ case "marked":
383
+ case "phoneNumberLink":
384
+ case "spoiler":
385
+ case "mention":
386
+ case "hashtag":
387
+ case "botCommand":
388
+ case "cashtag":
389
+ case "url":
390
+ case "email":
391
+ case "phoneNumber":
392
+ case "bankCard":
393
+ case "textMention":
394
+ for (const item of flattenRichTextComponent(component.text)) {
395
+ items.push(item);
396
+ }
397
+ break;
398
+ case "concatenate":
399
+ for (const c of component.components) {
400
+ for (const i of flattenRichTextComponent(c)) {
401
+ items.push(i);
402
+ }
403
+ }
404
+ }
405
+ return items;
406
+ }
407
+ function collectRichTextComponents(pageBlocks) {
408
+ const components = new Array();
409
+ for (const pb of pageBlocks) {
410
+ switch (pb.type) {
411
+ case "title":
412
+ case "subtitle":
413
+ case "header":
414
+ case "subheader":
415
+ case "paragraph":
416
+ case "pre":
417
+ case "footer":
418
+ case "kicker":
419
+ case "heading1":
420
+ case "heading2":
421
+ case "heading3":
422
+ case "heading4":
423
+ case "heading5":
424
+ case "heading6":
425
+ case "thinking":
426
+ components.push(pb.text);
427
+ break;
428
+ case "authorDate":
429
+ components.push(pb.author);
430
+ break;
431
+ case "list":
432
+ case "orderedList":
433
+ for (const item of pb.items) {
434
+ if (item.type === "text") {
435
+ components.push(item.text);
436
+ }
437
+ else {
438
+ for (const c of collectRichTextComponents(item.blocks)) {
439
+ components.push(c);
440
+ }
441
+ }
442
+ }
443
+ break;
444
+ case "blockQuote":
445
+ case "pullQuote":
446
+ components.push(pb.text);
447
+ components.push(pb.caption);
448
+ break;
449
+ case "photo":
450
+ case "video":
451
+ case "embed":
452
+ case "audio":
453
+ case "map":
454
+ components.push(pb.caption.text);
455
+ components.push(pb.caption.credit);
456
+ break;
457
+ case "cover":
458
+ for (const c of collectRichTextComponents([pb.cover])) {
459
+ components.push(c);
460
+ }
461
+ break;
462
+ case "collage":
463
+ case "slideshow":
464
+ components.push(pb.caption.text);
465
+ components.push(pb.caption.credit);
466
+ for (const c of collectRichTextComponents(pb.items)) {
467
+ components.push(c);
468
+ }
469
+ break;
470
+ case "embedPost":
471
+ components.push(pb.caption.text);
472
+ components.push(pb.caption.credit);
473
+ for (const c of collectRichTextComponents(pb.blocks)) {
474
+ components.push(c);
475
+ }
476
+ break;
477
+ case "math":
478
+ break;
479
+ case "table":
480
+ components.push(pb.title);
481
+ for (const row of pb.rows) {
482
+ for (const cell of row.cells) {
483
+ if (cell.text) {
484
+ components.push(cell.text);
485
+ }
486
+ }
487
+ }
488
+ break;
489
+ case "details":
490
+ components.push(pb.title);
491
+ for (const c of collectRichTextComponents(pb.blocks)) {
492
+ components.push(c);
493
+ }
494
+ break;
495
+ case "blockQuoteBlocks":
496
+ components.push(pb.caption);
497
+ for (const c of collectRichTextComponents(pb.blocks)) {
498
+ components.push(c);
499
+ }
500
+ break;
501
+ }
502
+ }
503
+ return components;
504
+ }
505
+ function collectPageBlockMedia(pageBlocks) {
506
+ const media = new Array();
507
+ for (const pb of pageBlocks) {
508
+ if (pb.type === "photo" || pb.type === "video" || pb.type === "audio" || pb.type === "voice" || pb.type === "animation") {
509
+ media.push(pb);
510
+ }
511
+ else {
512
+ switch (pb.type) {
513
+ case "list":
514
+ for (const item of pb.items) {
515
+ if (item.type === "blockList") {
516
+ for (const m of collectPageBlockMedia(item.blocks)) {
517
+ media.push(m);
518
+ }
519
+ }
520
+ }
521
+ break;
522
+ case "embedPost":
523
+ for (const m of collectPageBlockMedia(pb.blocks)) {
524
+ media.push(m);
525
+ }
526
+ break;
527
+ case "collage":
528
+ case "slideshow":
529
+ for (const m of collectPageBlockMedia(pb.items)) {
530
+ media.push(m);
531
+ }
532
+ break;
533
+ case "orderedList":
534
+ for (const item of pb.items) {
535
+ if (item.type === "blockList") {
536
+ for (const m of collectPageBlockMedia(item.blocks)) {
537
+ media.push(m);
538
+ }
539
+ }
540
+ }
541
+ break;
542
+ case "details":
543
+ case "blockQuoteBlocks":
544
+ for (const m of collectPageBlockMedia(pb.blocks)) {
545
+ media.push(m);
546
+ }
547
+ break;
548
+ }
549
+ }
550
+ }
551
+ return media;
552
+ }
@@ -40,7 +40,7 @@ export interface Poll {
40
40
  type: "regular" | "quiz";
41
41
  /** Whether the poll allows multiple answers. */
42
42
  allowMultipleAnswers?: boolean;
43
- /** The indexes of correct options. */
43
+ /** The indexes of the correct options. */
44
44
  correctOptionIndexes?: number[];
45
45
  /** A text that is shown to the user when the poll is answered. */
46
46
  explanation?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"4_poll.d.ts","sourceRoot":"","sources":["../../src/types/4_poll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE1E,cAAc;AACd,MAAM,WAAW,IAAI;IACnB,kCAAkC;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,gBAAgB,EAAE,aAAa,EAAE,CAAC;IAClC,0BAA0B;IAC1B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC;IACxB,kCAAkC;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,qCAAqC;IACrC,WAAW,EAAE,OAAO,CAAC;IACrB,4BAA4B;IAC5B,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IACzB,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,sCAAsC;IACtC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,mBAAmB,CAAC,EAAE,aAAa,EAAE,CAAC;IACtC,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAqBhE"}
1
+ {"version":3,"file":"4_poll.d.ts","sourceRoot":"","sources":["../../src/types/4_poll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE1E,cAAc;AACd,MAAM,WAAW,IAAI;IACnB,kCAAkC;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,gBAAgB,EAAE,aAAa,EAAE,CAAC;IAClC,0BAA0B;IAC1B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC;IACxB,kCAAkC;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,qCAAqC;IACrC,WAAW,EAAE,OAAO,CAAC;IACrB,4BAA4B;IAC5B,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IACzB,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,0CAA0C;IAC1C,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,mBAAmB,CAAC,EAAE,aAAa,EAAE,CAAC;IACtC,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAqBhE"}
@@ -26,6 +26,10 @@ export interface ReplyToMessage {
26
26
  messageId: number;
27
27
  /** A quoted part of the message that is being replied to. */
28
28
  quote?: ReplyQuote;
29
+ /** The identifier of a poll option to reply to. */
30
+ pollOptionId?: number;
31
+ /** The identifier of a checklist item to reply to. */
32
+ checklistItemId?: number;
29
33
  }
30
34
  /**
31
35
  * Information on a story that a message is replying to.
@@ -1 +1 @@
1
- {"version":3,"file":"4_reply_to.d.ts","sourceRoot":"","sources":["../../src/types/4_reply_to.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,oEAAoE;AACpE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,wDAAwD;IACxD,MAAM,EAAE,EAAE,CAAC;IACX,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,oDAAoD;AACpD,MAAM,MAAM,OAAO,GAAG,cAAc,GAAG,YAAY,CAAC"}
1
+ {"version":3,"file":"4_reply_to.d.ts","sourceRoot":"","sources":["../../src/types/4_reply_to.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,oEAAoE;AACpE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,wDAAwD;IACxD,MAAM,EAAE,EAAE,CAAC;IACX,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,oDAAoD;AACpD,MAAM,MAAM,OAAO,GAAG,cAAc,GAAG,YAAY,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2026 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ import type { PageBlock } from "./4_page_block.js";
21
+ /** @unlisted */
22
+ export interface InputRichTextBlocks {
23
+ type: "blocks";
24
+ blocks: PageBlock[];
25
+ }
26
+ /** @unlisted */
27
+ export interface InputRichTextMarkdown {
28
+ type: "markdown";
29
+ markdown: string;
30
+ }
31
+ /** @unlisted */
32
+ export interface InputRichTextHtml {
33
+ type: "html";
34
+ html: string;
35
+ }
36
+ /** Any type of input rich text. */
37
+ export type InputRichText = InputRichTextBlocks | InputRichTextMarkdown | InputRichTextHtml;
38
+ //# sourceMappingURL=5_input_rich_text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"5_input_rich_text.d.ts","sourceRoot":"","sources":["../../src/types/5_input_rich_text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AAED,gBAAgB;AAChB,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,gBAAgB;AAChB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,qBAAqB,GAAG,iBAAiB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2026 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ export {};