@icanseeuanywhere/telekaf 4.16.3

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 (172) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +978 -0
  3. package/filters.d.ts +1 -0
  4. package/filters.js +1 -0
  5. package/format.d.ts +1 -0
  6. package/format.js +1 -0
  7. package/future.d.ts +1 -0
  8. package/future.js +1 -0
  9. package/lib/button.js +101 -0
  10. package/lib/cli.mjs +105 -0
  11. package/lib/composer.js +582 -0
  12. package/lib/context.js +1277 -0
  13. package/lib/core/helpers/args.js +58 -0
  14. package/lib/core/helpers/check.js +56 -0
  15. package/lib/core/helpers/compact.js +17 -0
  16. package/lib/core/helpers/deunionize.js +13 -0
  17. package/lib/core/helpers/formatting.js +91 -0
  18. package/lib/core/helpers/util.js +50 -0
  19. package/lib/core/network/client.js +320 -0
  20. package/lib/core/network/error.js +21 -0
  21. package/lib/core/network/multipart-stream.js +61 -0
  22. package/lib/core/network/polling.js +87 -0
  23. package/lib/core/network/webhook.js +54 -0
  24. package/lib/core/types/rich-message.js +102 -0
  25. package/lib/core/types/typegram.js +28 -0
  26. package/lib/filters.js +69 -0
  27. package/lib/format.js +38 -0
  28. package/lib/future.js +166 -0
  29. package/lib/index.js +49 -0
  30. package/lib/input.js +61 -0
  31. package/lib/markup.js +111 -0
  32. package/lib/middleware.js +2 -0
  33. package/lib/reactions.js +84 -0
  34. package/lib/router.js +46 -0
  35. package/lib/scenes/base.js +39 -0
  36. package/lib/scenes/context.js +104 -0
  37. package/lib/scenes/index.js +21 -0
  38. package/lib/scenes/stage.js +49 -0
  39. package/lib/scenes/wizard/context.js +31 -0
  40. package/lib/scenes/wizard/index.js +45 -0
  41. package/lib/scenes.js +17 -0
  42. package/lib/session.js +166 -0
  43. package/lib/telegraf.js +246 -0
  44. package/lib/telegram-types.js +6 -0
  45. package/lib/telegram.js +1265 -0
  46. package/lib/types.js +2 -0
  47. package/lib/utils.js +5 -0
  48. package/markup.d.ts +1 -0
  49. package/markup.js +1 -0
  50. package/package.json +138 -0
  51. package/scenes.d.ts +1 -0
  52. package/scenes.js +1 -0
  53. package/session.d.ts +1 -0
  54. package/session.js +1 -0
  55. package/src/button.ts +182 -0
  56. package/src/composer.ts +1008 -0
  57. package/src/context.ts +1739 -0
  58. package/src/core/helpers/args.ts +63 -0
  59. package/src/core/helpers/check.ts +71 -0
  60. package/src/core/helpers/compact.ts +18 -0
  61. package/src/core/helpers/deunionize.ts +26 -0
  62. package/src/core/helpers/formatting.ts +119 -0
  63. package/src/core/helpers/util.ts +96 -0
  64. package/src/core/network/client.ts +396 -0
  65. package/src/core/network/error.ts +29 -0
  66. package/src/core/network/multipart-stream.ts +45 -0
  67. package/src/core/network/polling.ts +94 -0
  68. package/src/core/network/webhook.ts +58 -0
  69. package/src/core/types/rich-message.ts +474 -0
  70. package/src/core/types/typegram.ts +55 -0
  71. package/src/filters.ts +109 -0
  72. package/src/format.ts +110 -0
  73. package/src/future.ts +231 -0
  74. package/src/index.ts +18 -0
  75. package/src/input.ts +59 -0
  76. package/src/markup.ts +142 -0
  77. package/src/middleware.ts +24 -0
  78. package/src/reactions.ts +118 -0
  79. package/src/router.ts +55 -0
  80. package/src/scenes/base.ts +52 -0
  81. package/src/scenes/context.ts +136 -0
  82. package/src/scenes/index.ts +21 -0
  83. package/src/scenes/stage.ts +71 -0
  84. package/src/scenes/wizard/context.ts +58 -0
  85. package/src/scenes/wizard/index.ts +63 -0
  86. package/src/scenes.ts +1 -0
  87. package/src/session.ts +204 -0
  88. package/src/telegraf.ts +354 -0
  89. package/src/telegram-types.ts +250 -0
  90. package/src/telegram.ts +1671 -0
  91. package/src/types.ts +2 -0
  92. package/src/utils.ts +1 -0
  93. package/types.d.ts +1 -0
  94. package/types.js +1 -0
  95. package/typings/button.d.ts +36 -0
  96. package/typings/button.d.ts.map +1 -0
  97. package/typings/composer.d.ts +227 -0
  98. package/typings/composer.d.ts.map +1 -0
  99. package/typings/context.d.ts +693 -0
  100. package/typings/context.d.ts.map +1 -0
  101. package/typings/core/helpers/args.d.ts +11 -0
  102. package/typings/core/helpers/args.d.ts.map +1 -0
  103. package/typings/core/helpers/check.d.ts +56 -0
  104. package/typings/core/helpers/check.d.ts.map +1 -0
  105. package/typings/core/helpers/compact.d.ts +4 -0
  106. package/typings/core/helpers/compact.d.ts.map +1 -0
  107. package/typings/core/helpers/deunionize.d.ts +18 -0
  108. package/typings/core/helpers/deunionize.d.ts.map +1 -0
  109. package/typings/core/helpers/formatting.d.ts +30 -0
  110. package/typings/core/helpers/formatting.d.ts.map +1 -0
  111. package/typings/core/helpers/util.d.ts +27 -0
  112. package/typings/core/helpers/util.d.ts.map +1 -0
  113. package/typings/core/network/client.d.ts +55 -0
  114. package/typings/core/network/client.d.ts.map +1 -0
  115. package/typings/core/network/error.d.ts +16 -0
  116. package/typings/core/network/error.d.ts.map +1 -0
  117. package/typings/core/network/multipart-stream.d.ts +19 -0
  118. package/typings/core/network/multipart-stream.d.ts.map +1 -0
  119. package/typings/core/network/polling.d.ts +16 -0
  120. package/typings/core/network/polling.d.ts.map +1 -0
  121. package/typings/core/network/webhook.d.ts +7 -0
  122. package/typings/core/network/webhook.d.ts.map +1 -0
  123. package/typings/core/types/rich-message.d.ts +295 -0
  124. package/typings/core/types/rich-message.d.ts.map +1 -0
  125. package/typings/core/types/typegram.d.ts +45 -0
  126. package/typings/core/types/typegram.d.ts.map +1 -0
  127. package/typings/filters.d.ts +18 -0
  128. package/typings/filters.d.ts.map +1 -0
  129. package/typings/format.d.ts +22 -0
  130. package/typings/format.d.ts.map +1 -0
  131. package/typings/future.d.ts +12 -0
  132. package/typings/future.d.ts.map +1 -0
  133. package/typings/index.d.ts +16 -0
  134. package/typings/index.d.ts.map +1 -0
  135. package/typings/input.d.ts +55 -0
  136. package/typings/input.d.ts.map +1 -0
  137. package/typings/markup.d.ts +27 -0
  138. package/typings/markup.d.ts.map +1 -0
  139. package/typings/middleware.d.ts +8 -0
  140. package/typings/middleware.d.ts.map +1 -0
  141. package/typings/reactions.d.ts +32 -0
  142. package/typings/reactions.d.ts.map +1 -0
  143. package/typings/router.d.ts +21 -0
  144. package/typings/router.d.ts.map +1 -0
  145. package/typings/scenes/base.d.ts +22 -0
  146. package/typings/scenes/base.d.ts.map +1 -0
  147. package/typings/scenes/context.d.ts +36 -0
  148. package/typings/scenes/context.d.ts.map +1 -0
  149. package/typings/scenes/index.d.ts +11 -0
  150. package/typings/scenes/index.d.ts.map +1 -0
  151. package/typings/scenes/stage.d.ts +24 -0
  152. package/typings/scenes/stage.d.ts.map +1 -0
  153. package/typings/scenes/wizard/context.d.ts +29 -0
  154. package/typings/scenes/wizard/context.d.ts.map +1 -0
  155. package/typings/scenes/wizard/index.d.ts +16 -0
  156. package/typings/scenes/wizard/index.d.ts.map +1 -0
  157. package/typings/scenes.d.ts +2 -0
  158. package/typings/scenes.d.ts.map +1 -0
  159. package/typings/session.d.ts +55 -0
  160. package/typings/session.d.ts.map +1 -0
  161. package/typings/telegraf.d.ts +117 -0
  162. package/typings/telegraf.d.ts.map +1 -0
  163. package/typings/telegram-types.d.ts +134 -0
  164. package/typings/telegram-types.d.ts.map +1 -0
  165. package/typings/telegram.d.ts +691 -0
  166. package/typings/telegram.d.ts.map +1 -0
  167. package/typings/types.d.ts +3 -0
  168. package/typings/types.d.ts.map +1 -0
  169. package/typings/utils.d.ts +2 -0
  170. package/typings/utils.d.ts.map +1 -0
  171. package/utils.d.ts +1 -0
  172. package/utils.js +1 -0
@@ -0,0 +1,474 @@
1
+ /**
2
+ * Telegram Bot API 10.1 — Rich Messages
3
+ * https://core.telegram.org/bots/api#june-11-2026
4
+ */
5
+
6
+ // ---------------------------------------------------------------------------
7
+ // RichText — inline text elements
8
+ // ---------------------------------------------------------------------------
9
+
10
+ export interface RichTextPlain {
11
+ type: 'plain'
12
+ text: string
13
+ }
14
+
15
+ export interface RichTextBold {
16
+ type: 'bold'
17
+ text: RichText
18
+ }
19
+
20
+ export interface RichTextItalic {
21
+ type: 'italic'
22
+ text: RichText
23
+ }
24
+
25
+ export interface RichTextUnderline {
26
+ type: 'underline'
27
+ text: RichText
28
+ }
29
+
30
+ export interface RichTextStrikethrough {
31
+ type: 'strikethrough'
32
+ text: RichText
33
+ }
34
+
35
+ export interface RichTextSpoiler {
36
+ type: 'spoiler'
37
+ text: RichText
38
+ }
39
+
40
+ export interface RichTextDateTime {
41
+ type: 'date_time'
42
+ unix_time: number
43
+ }
44
+
45
+ export interface RichTextMention {
46
+ type: 'mention'
47
+ text: RichText
48
+ user_id?: number
49
+ username?: string
50
+ }
51
+
52
+ export interface RichTextSubscript {
53
+ type: 'subscript'
54
+ text: RichText
55
+ }
56
+
57
+ export interface RichTextSuperscript {
58
+ type: 'superscript'
59
+ text: RichText
60
+ }
61
+
62
+ export interface RichTextMarked {
63
+ type: 'marked'
64
+ text: RichText
65
+ }
66
+
67
+ export interface RichTextCode {
68
+ type: 'code'
69
+ text: RichText
70
+ language?: string
71
+ }
72
+
73
+ export interface RichTextCustomEmoji {
74
+ type: 'custom_emoji'
75
+ custom_emoji_id: string
76
+ }
77
+
78
+ export interface RichTextMathematicalExpression {
79
+ type: 'mathematical_expression'
80
+ expression: string
81
+ }
82
+
83
+ export interface RichTextUrl {
84
+ type: 'url'
85
+ href: string
86
+ text: RichText
87
+ }
88
+
89
+ export interface RichTextEmailAddress {
90
+ type: 'email_address'
91
+ email: string
92
+ text?: RichText
93
+ }
94
+
95
+ export interface RichTextPhoneNumber {
96
+ type: 'phone_number'
97
+ phone_number: string
98
+ text?: RichText
99
+ }
100
+
101
+ export interface RichTextBankCardNumber {
102
+ type: 'bank_card_number'
103
+ bank_card_number: string
104
+ text?: RichText
105
+ }
106
+
107
+ export interface RichTextHashtag {
108
+ type: 'hashtag'
109
+ hashtag: string
110
+ }
111
+
112
+ export interface RichTextCashtag {
113
+ type: 'cashtag'
114
+ cashtag: string
115
+ }
116
+
117
+ export interface RichTextBotCommand {
118
+ type: 'bot_command'
119
+ command: string
120
+ bot?: string
121
+ }
122
+
123
+ export interface RichTextAnchor {
124
+ type: 'anchor'
125
+ name: string
126
+ }
127
+
128
+ export interface RichTextAnchorLink {
129
+ type: 'anchor_link'
130
+ name: string
131
+ text: RichText
132
+ }
133
+
134
+ export interface RichTextReference {
135
+ type: 'reference'
136
+ reference_id: number
137
+ }
138
+
139
+ export interface RichTextReferenceLink {
140
+ type: 'reference_link'
141
+ reference_id: number
142
+ text: RichText
143
+ }
144
+
145
+ /** Union of all inline rich text element types. */
146
+ export type RichText =
147
+ | RichTextPlain
148
+ | RichTextBold
149
+ | RichTextItalic
150
+ | RichTextUnderline
151
+ | RichTextStrikethrough
152
+ | RichTextSpoiler
153
+ | RichTextDateTime
154
+ | RichTextMention
155
+ | RichTextSubscript
156
+ | RichTextSuperscript
157
+ | RichTextMarked
158
+ | RichTextCode
159
+ | RichTextCustomEmoji
160
+ | RichTextMathematicalExpression
161
+ | RichTextUrl
162
+ | RichTextEmailAddress
163
+ | RichTextPhoneNumber
164
+ | RichTextBankCardNumber
165
+ | RichTextHashtag
166
+ | RichTextCashtag
167
+ | RichTextBotCommand
168
+ | RichTextAnchor
169
+ | RichTextAnchorLink
170
+ | RichTextReference
171
+ | RichTextReferenceLink
172
+
173
+ // ---------------------------------------------------------------------------
174
+ // RichBlock — block-level elements
175
+ // ---------------------------------------------------------------------------
176
+
177
+ /** Caption attached to a media block. */
178
+ export interface RichBlockCaption {
179
+ type: 'caption'
180
+ texts: RichText[]
181
+ }
182
+
183
+ /** A single cell inside a RichBlockTable. */
184
+ export interface RichBlockTableCell {
185
+ type: 'table_cell'
186
+ content: RichBlock[]
187
+ colspan?: number
188
+ rowspan?: number
189
+ is_header?: boolean
190
+ align?: 'left' | 'center' | 'right'
191
+ }
192
+
193
+ /** A single item inside a RichBlockList. */
194
+ export interface RichBlockListItem {
195
+ type: 'list_item'
196
+ content: RichBlock[]
197
+ }
198
+
199
+ export interface RichBlockParagraph {
200
+ type: 'paragraph'
201
+ texts: RichText[]
202
+ }
203
+
204
+ export interface RichBlockSectionHeading {
205
+ type: 'section_heading'
206
+ texts: RichText[]
207
+ level: 1 | 2 | 3 | 4 | 5 | 6
208
+ }
209
+
210
+ export interface RichBlockPreformatted {
211
+ type: 'preformatted'
212
+ text: string
213
+ language?: string
214
+ }
215
+
216
+ export interface RichBlockFooter {
217
+ type: 'footer'
218
+ texts: RichText[]
219
+ }
220
+
221
+ export interface RichBlockDivider {
222
+ type: 'divider'
223
+ }
224
+
225
+ export interface RichBlockMathematicalExpression {
226
+ type: 'mathematical_expression'
227
+ expression: string
228
+ }
229
+
230
+ export interface RichBlockAnchor {
231
+ type: 'anchor'
232
+ name: string
233
+ }
234
+
235
+ export interface RichBlockList {
236
+ type: 'list'
237
+ is_ordered: boolean
238
+ items: RichBlockListItem[]
239
+ }
240
+
241
+ export interface RichBlockBlockQuotation {
242
+ type: 'block_quotation'
243
+ blocks: RichBlock[]
244
+ }
245
+
246
+ export interface RichBlockPullQuotation {
247
+ type: 'pull_quotation'
248
+ blocks: RichBlock[]
249
+ caption?: RichBlockCaption
250
+ }
251
+
252
+ export interface RichBlockCollage {
253
+ type: 'collage'
254
+ media: (RichBlockPhoto | RichBlockVideo | RichBlockAnimation)[]
255
+ caption?: RichBlockCaption
256
+ }
257
+
258
+ export interface RichBlockSlideshow {
259
+ type: 'slideshow'
260
+ media: (RichBlockPhoto | RichBlockVideo | RichBlockAnimation)[]
261
+ caption?: RichBlockCaption
262
+ }
263
+
264
+ export interface RichBlockTable {
265
+ type: 'table'
266
+ cells: RichBlockTableCell[][]
267
+ is_bordered?: boolean
268
+ is_striped?: boolean
269
+ }
270
+
271
+ export interface RichBlockDetails {
272
+ type: 'details'
273
+ header: RichText[]
274
+ blocks: RichBlock[]
275
+ }
276
+
277
+ export interface RichBlockMap {
278
+ type: 'map'
279
+ latitude: number
280
+ longitude: number
281
+ zoom?: number
282
+ caption?: RichBlockCaption
283
+ }
284
+
285
+ export interface RichBlockAnimation {
286
+ type: 'animation'
287
+ file_id: string
288
+ caption?: RichBlockCaption
289
+ }
290
+
291
+ export interface RichBlockAudio {
292
+ type: 'audio'
293
+ file_id: string
294
+ caption?: RichBlockCaption
295
+ }
296
+
297
+ export interface RichBlockPhoto {
298
+ type: 'photo'
299
+ file_id: string
300
+ caption?: RichBlockCaption
301
+ }
302
+
303
+ export interface RichBlockVideo {
304
+ type: 'video'
305
+ file_id: string
306
+ caption?: RichBlockCaption
307
+ }
308
+
309
+ export interface RichBlockVoiceNote {
310
+ type: 'voice_note'
311
+ file_id: string
312
+ caption?: RichBlockCaption
313
+ }
314
+
315
+ export interface RichBlockThinking {
316
+ type: 'thinking'
317
+ blocks: RichBlock[]
318
+ }
319
+
320
+ /** Union of all block-level rich message element types. */
321
+ export type RichBlock =
322
+ | RichBlockParagraph
323
+ | RichBlockSectionHeading
324
+ | RichBlockPreformatted
325
+ | RichBlockFooter
326
+ | RichBlockDivider
327
+ | RichBlockMathematicalExpression
328
+ | RichBlockAnchor
329
+ | RichBlockList
330
+ | RichBlockBlockQuotation
331
+ | RichBlockPullQuotation
332
+ | RichBlockCollage
333
+ | RichBlockSlideshow
334
+ | RichBlockTable
335
+ | RichBlockDetails
336
+ | RichBlockMap
337
+ | RichBlockAnimation
338
+ | RichBlockAudio
339
+ | RichBlockPhoto
340
+ | RichBlockVideo
341
+ | RichBlockVoiceNote
342
+ | RichBlockThinking
343
+ | RichBlockCaption
344
+ | RichBlockTableCell
345
+ | RichBlockListItem
346
+
347
+ // ---------------------------------------------------------------------------
348
+ // RichMessage — top-level message container
349
+ // ---------------------------------------------------------------------------
350
+
351
+ /** A rich formatted message received from Telegram. */
352
+ export interface RichMessage {
353
+ blocks: RichBlock[]
354
+ references?: RichText[]
355
+ }
356
+
357
+ /** Describes a rich message to send via sendRichMessage / sendRichMessageDraft. */
358
+ export interface InputRichMessage {
359
+ blocks: RichBlock[]
360
+ references?: RichText[]
361
+ }
362
+
363
+ /** Can be used as InputMessageContent in inline, guest, and Web App queries. */
364
+ export interface InputRichMessageContent {
365
+ rich_message: InputRichMessage
366
+ }
367
+
368
+ // ---------------------------------------------------------------------------
369
+ // Helper builder — fluent API for constructing InputRichMessage
370
+ // ---------------------------------------------------------------------------
371
+
372
+ export class RichMessageBuilder {
373
+ private readonly _blocks: RichBlock[] = []
374
+ private readonly _references: RichText[] = []
375
+
376
+ paragraph(...texts: RichText[]) {
377
+ this._blocks.push({ type: 'paragraph', texts })
378
+ return this
379
+ }
380
+
381
+ heading(level: 1 | 2 | 3 | 4 | 5 | 6, ...texts: RichText[]) {
382
+ this._blocks.push({ type: 'section_heading', texts, level })
383
+ return this
384
+ }
385
+
386
+ preformatted(text: string, language?: string) {
387
+ this._blocks.push({ type: 'preformatted', text, language })
388
+ return this
389
+ }
390
+
391
+ divider() {
392
+ this._blocks.push({ type: 'divider' })
393
+ return this
394
+ }
395
+
396
+ list(isOrdered: boolean, ...items: RichBlock[][]) {
397
+ this._blocks.push({
398
+ type: 'list',
399
+ is_ordered: isOrdered,
400
+ items: items.map((content) => ({ type: 'list_item', content })),
401
+ })
402
+ return this
403
+ }
404
+
405
+ blockQuote(...blocks: RichBlock[]) {
406
+ this._blocks.push({ type: 'block_quotation', blocks })
407
+ return this
408
+ }
409
+
410
+ thinking(...blocks: RichBlock[]) {
411
+ this._blocks.push({ type: 'thinking', blocks })
412
+ return this
413
+ }
414
+
415
+ photo(fileId: string, caption?: RichBlockCaption) {
416
+ this._blocks.push({ type: 'photo', file_id: fileId, caption })
417
+ return this
418
+ }
419
+
420
+ video(fileId: string, caption?: RichBlockCaption) {
421
+ this._blocks.push({ type: 'video', file_id: fileId, caption })
422
+ return this
423
+ }
424
+
425
+ audio(fileId: string, caption?: RichBlockCaption) {
426
+ this._blocks.push({ type: 'audio', file_id: fileId, caption })
427
+ return this
428
+ }
429
+
430
+ reference(text: RichText) {
431
+ const id = this._references.length + 1
432
+ this._references.push(text)
433
+ return id
434
+ }
435
+
436
+ build(): InputRichMessage {
437
+ return {
438
+ blocks: this._blocks,
439
+ ...(this._references.length ? { references: this._references } : {}),
440
+ }
441
+ }
442
+ }
443
+
444
+ // ---------------------------------------------------------------------------
445
+ // Static helpers for building RichText nodes
446
+ // ---------------------------------------------------------------------------
447
+
448
+ export const RT = {
449
+ plain: (text: string): RichTextPlain => ({ type: 'plain', text }),
450
+ bold: (text: RichText): RichTextBold => ({ type: 'bold', text }),
451
+ italic: (text: RichText): RichTextItalic => ({ type: 'italic', text }),
452
+ underline: (text: RichText): RichTextUnderline => ({ type: 'underline', text }),
453
+ strikethrough: (text: RichText): RichTextStrikethrough => ({ type: 'strikethrough', text }),
454
+ spoiler: (text: RichText): RichTextSpoiler => ({ type: 'spoiler', text }),
455
+ dateTime: (unixTime: number): RichTextDateTime => ({ type: 'date_time', unix_time: unixTime }),
456
+ mention: (text: RichText, userId?: number, username?: string): RichTextMention => ({ type: 'mention', text, user_id: userId, username }),
457
+ subscript: (text: RichText): RichTextSubscript => ({ type: 'subscript', text }),
458
+ superscript: (text: RichText): RichTextSuperscript => ({ type: 'superscript', text }),
459
+ marked: (text: RichText): RichTextMarked => ({ type: 'marked', text }),
460
+ code: (text: RichText, language?: string): RichTextCode => ({ type: 'code', text, language }),
461
+ customEmoji: (id: string): RichTextCustomEmoji => ({ type: 'custom_emoji', custom_emoji_id: id }),
462
+ math: (expression: string): RichTextMathematicalExpression => ({ type: 'mathematical_expression', expression }),
463
+ url: (href: string, text: RichText): RichTextUrl => ({ type: 'url', href, text }),
464
+ email: (email: string, text?: RichText): RichTextEmailAddress => ({ type: 'email_address', email, text }),
465
+ phone: (phoneNumber: string, text?: RichText): RichTextPhoneNumber => ({ type: 'phone_number', phone_number: phoneNumber, text }),
466
+ bankCard: (bankCardNumber: string, text?: RichText): RichTextBankCardNumber => ({ type: 'bank_card_number', bank_card_number: bankCardNumber, text }),
467
+ hashtag: (hashtag: string): RichTextHashtag => ({ type: 'hashtag', hashtag }),
468
+ cashtag: (cashtag: string): RichTextCashtag => ({ type: 'cashtag', cashtag }),
469
+ botCommand: (command: string, bot?: string): RichTextBotCommand => ({ type: 'bot_command', command, bot }),
470
+ anchor: (name: string): RichTextAnchor => ({ type: 'anchor', name }),
471
+ anchorLink: (name: string, text: RichText): RichTextAnchorLink => ({ type: 'anchor_link', name, text }),
472
+ reference: (referenceId: number): RichTextReference => ({ type: 'reference', reference_id: referenceId }),
473
+ referenceLink: (referenceId: number, text: RichText): RichTextReferenceLink => ({ type: 'reference_link', reference_id: referenceId, text }),
474
+ } as const
@@ -0,0 +1,55 @@
1
+ import * as Typegram from '@telegraf/types'
2
+ export * from './rich-message'
3
+
4
+ // internal type provisions
5
+ export * from '@telegraf/types/api'
6
+ export * from '@telegraf/types/inline'
7
+ export * from '@telegraf/types/manage'
8
+ export * from '@telegraf/types/markup'
9
+ export * from '@telegraf/types/message'
10
+ export * from '@telegraf/types/methods'
11
+ export * from '@telegraf/types/passport'
12
+ export * from '@telegraf/types/payment'
13
+ export * from '@telegraf/types/settings'
14
+ export * from '@telegraf/types/update'
15
+
16
+ // telegraf input file definition
17
+ interface InputFileByPath {
18
+ source: string
19
+ filename?: string
20
+ }
21
+ interface InputFileByReadableStream {
22
+ source: NodeJS.ReadableStream
23
+ filename?: string
24
+ }
25
+ interface InputFileByBuffer {
26
+ source: Buffer
27
+ filename?: string
28
+ }
29
+ interface InputFileByURL {
30
+ url: string
31
+ filename?: string
32
+ }
33
+ export type InputFile =
34
+ | InputFileByPath
35
+ | InputFileByReadableStream
36
+ | InputFileByBuffer
37
+ | InputFileByURL
38
+
39
+ export type Telegram = Typegram.ApiMethods<InputFile>
40
+
41
+ export type Opts<M extends keyof Telegram> = Typegram.Opts<InputFile>[M]
42
+ export type InputMedia = Typegram.InputMedia<InputFile>
43
+ export type InputMediaPhoto = Typegram.InputMediaPhoto<InputFile>
44
+ export type InputMediaVideo = Typegram.InputMediaVideo<InputFile>
45
+ export type InputMediaAnimation = Typegram.InputMediaAnimation<InputFile>
46
+ export type InputMediaAudio = Typegram.InputMediaAudio<InputFile>
47
+ export type InputMediaDocument = Typegram.InputMediaDocument<InputFile>
48
+
49
+ // tiny helper types
50
+ export type ChatAction = Opts<'sendChatAction'>['action']
51
+
52
+ /**
53
+ * Sending video notes by a URL is currently unsupported
54
+ */
55
+ export type InputFileVideoNote = Exclude<InputFile, InputFileByURL>
package/src/filters.ts ADDED
@@ -0,0 +1,109 @@
1
+ import type {
2
+ CallbackQuery,
3
+ CommonMessageBundle,
4
+ Message,
5
+ Update,
6
+ } from '@telegraf/types'
7
+ import { DistinctKeys, KeyedDistinct, Guarded } from './core/helpers/util'
8
+
9
+ export type Filter<U extends Update> = (update: Update) => update is U
10
+
11
+ export { Guarded }
12
+
13
+ export type AllGuarded<Fs extends Filter<Update>[]> = Fs extends [
14
+ infer A,
15
+ ...infer B,
16
+ ]
17
+ ? B extends []
18
+ ? Guarded<A>
19
+ : // TS doesn't know otherwise that B is Filter[]
20
+ B extends Filter<Update>[]
21
+ ? Guarded<A> & AllGuarded<B>
22
+ : never
23
+ : never
24
+
25
+ export const message =
26
+ <Ks extends DistinctKeys<Message>[]>(...keys: Ks) =>
27
+ (
28
+ update: Update
29
+ ): update is Update.MessageUpdate<KeyedDistinct<Message, Ks[number]>> => {
30
+ if (!('message' in update)) return false
31
+ for (const key of keys) {
32
+ if (!(key in update.message)) return false
33
+ }
34
+ return true
35
+ }
36
+
37
+ export const editedMessage =
38
+ <Ks extends DistinctKeys<CommonMessageBundle>[]>(...keys: Ks) =>
39
+ (
40
+ update: Update
41
+ ): update is Update.EditedMessageUpdate<
42
+ KeyedDistinct<CommonMessageBundle, Ks[number]>
43
+ > => {
44
+ if (!('edited_message' in update)) return false
45
+ for (const key of keys) {
46
+ if (!(key in update.edited_message)) return false
47
+ }
48
+ return true
49
+ }
50
+
51
+ export const channelPost =
52
+ <Ks extends DistinctKeys<Message>[]>(...keys: Ks) =>
53
+ (
54
+ update: Update
55
+ ): update is Update.ChannelPostUpdate<KeyedDistinct<Message, Ks[number]>> => {
56
+ if (!('channel_post' in update)) return false
57
+ for (const key of keys) {
58
+ if (!(key in update.channel_post)) return false
59
+ }
60
+ return true
61
+ }
62
+
63
+ export const editedChannelPost =
64
+ <Ks extends DistinctKeys<CommonMessageBundle>[]>(...keys: Ks) =>
65
+ (
66
+ update: Update
67
+ ): update is Update.EditedChannelPostUpdate<
68
+ KeyedDistinct<CommonMessageBundle, Ks[number]>
69
+ > => {
70
+ if (!('edited_channel_post' in update)) return false
71
+ for (const key of keys) {
72
+ if (!(key in update.edited_channel_post)) return false
73
+ }
74
+ return true
75
+ }
76
+
77
+ export const callbackQuery =
78
+ <Ks extends DistinctKeys<CallbackQuery>[]>(...keys: Ks) =>
79
+ (
80
+ update: Update
81
+ ): update is Update.CallbackQueryUpdate<
82
+ KeyedDistinct<CallbackQuery, Ks[number]>
83
+ > => {
84
+ if (!('callback_query' in update)) return false
85
+ for (const key of keys) {
86
+ if (!(key in update.callback_query)) return false
87
+ }
88
+ return true
89
+ }
90
+
91
+ /** Any of the provided filters must match */
92
+ export const anyOf =
93
+ <Us extends Update[]>(
94
+ ...filters: {
95
+ [UIdx in keyof Us]: Filter<Us[UIdx]>
96
+ }
97
+ ) =>
98
+ (update: Update): update is Us[number] => {
99
+ for (const filter of filters) if (filter(update)) return true
100
+ return false
101
+ }
102
+
103
+ /** All of the provided filters must match */
104
+ export const allOf =
105
+ <U extends Update, Fs extends Filter<U>[]>(...filters: Fs) =>
106
+ (update: Update): update is AllGuarded<Fs> => {
107
+ for (const filter of filters) if (!filter(update)) return false
108
+ return true
109
+ }