@sugansociety/gallagherrich 4.16.8

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 (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +1024 -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 +102 -0
  10. package/lib/cli.mjs +105 -0
  11. package/lib/composer.js +583 -0
  12. package/lib/context.js +1280 -0
  13. package/lib/core/helpers/args.js +59 -0
  14. package/lib/core/helpers/check.js +57 -0
  15. package/lib/core/helpers/compact.js +18 -0
  16. package/lib/core/helpers/deunionize.js +14 -0
  17. package/lib/core/helpers/formatting.js +92 -0
  18. package/lib/core/helpers/util.js +51 -0
  19. package/lib/core/network/client.js +321 -0
  20. package/lib/core/network/error.js +22 -0
  21. package/lib/core/network/multipart-stream.js +62 -0
  22. package/lib/core/network/polling.js +88 -0
  23. package/lib/core/network/webhook.js +55 -0
  24. package/lib/core/types/rich-message.js +288 -0
  25. package/lib/core/types/typegram.js +29 -0
  26. package/lib/filters.js +70 -0
  27. package/lib/filters.js.map +1 -0
  28. package/lib/format.js +39 -0
  29. package/lib/format.js.map +1 -0
  30. package/lib/future.js +167 -0
  31. package/lib/future.js.map +1 -0
  32. package/lib/index.js +50 -0
  33. package/lib/input.js +62 -0
  34. package/lib/markup.js +112 -0
  35. package/lib/markup.js.map +1 -0
  36. package/lib/middleware.js +3 -0
  37. package/lib/reactions.js +85 -0
  38. package/lib/router.js +47 -0
  39. package/lib/scenes/base.js +40 -0
  40. package/lib/scenes/context.js +105 -0
  41. package/lib/scenes/index.js +22 -0
  42. package/lib/scenes/stage.js +50 -0
  43. package/lib/scenes/wizard/context.js +32 -0
  44. package/lib/scenes/wizard/index.js +46 -0
  45. package/lib/scenes.js +18 -0
  46. package/lib/scenes.js.map +1 -0
  47. package/lib/session.js +167 -0
  48. package/lib/session.js.map +1 -0
  49. package/lib/telegraf.js +273 -0
  50. package/lib/telegram-types.js +7 -0
  51. package/lib/telegram.js +1270 -0
  52. package/lib/types.js +3 -0
  53. package/lib/types.js.map +1 -0
  54. package/lib/utils.js +6 -0
  55. package/lib/utils.js.map +1 -0
  56. package/markup.d.ts +1 -0
  57. package/markup.js +1 -0
  58. package/package.json +136 -0
  59. package/scenes.d.ts +1 -0
  60. package/scenes.js +1 -0
  61. package/session.d.ts +1 -0
  62. package/session.js +1 -0
  63. package/src/button.ts +182 -0
  64. package/src/composer.ts +1008 -0
  65. package/src/context.ts +1747 -0
  66. package/src/core/helpers/args.ts +63 -0
  67. package/src/core/helpers/check.ts +71 -0
  68. package/src/core/helpers/compact.ts +18 -0
  69. package/src/core/helpers/deunionize.ts +26 -0
  70. package/src/core/helpers/formatting.ts +119 -0
  71. package/src/core/helpers/util.ts +96 -0
  72. package/src/core/network/client.ts +396 -0
  73. package/src/core/network/error.ts +29 -0
  74. package/src/core/network/multipart-stream.ts +45 -0
  75. package/src/core/network/polling.ts +94 -0
  76. package/src/core/network/webhook.ts +58 -0
  77. package/src/core/types/rich-message.ts +375 -0
  78. package/src/core/types/typegram.ts +55 -0
  79. package/src/filters.ts +109 -0
  80. package/src/format.ts +110 -0
  81. package/src/future.ts +231 -0
  82. package/src/index.ts +18 -0
  83. package/src/input.ts +59 -0
  84. package/src/markup.ts +142 -0
  85. package/src/middleware.ts +24 -0
  86. package/src/reactions.ts +118 -0
  87. package/src/router.ts +55 -0
  88. package/src/scenes/base.ts +52 -0
  89. package/src/scenes/context.ts +136 -0
  90. package/src/scenes/index.ts +21 -0
  91. package/src/scenes/stage.ts +71 -0
  92. package/src/scenes/wizard/context.ts +58 -0
  93. package/src/scenes/wizard/index.ts +63 -0
  94. package/src/scenes.ts +1 -0
  95. package/src/session.ts +204 -0
  96. package/src/telegraf.ts +380 -0
  97. package/src/telegram-types.ts +256 -0
  98. package/src/telegram.ts +1676 -0
  99. package/src/types.ts +2 -0
  100. package/src/utils.ts +1 -0
  101. package/types.d.ts +1 -0
  102. package/types.js +1 -0
  103. package/typings/button.d.ts +36 -0
  104. package/typings/button.d.ts.map +1 -0
  105. package/typings/composer.d.ts +227 -0
  106. package/typings/composer.d.ts.map +1 -0
  107. package/typings/context.d.ts +699 -0
  108. package/typings/context.d.ts.map +1 -0
  109. package/typings/core/helpers/args.d.ts +11 -0
  110. package/typings/core/helpers/args.d.ts.map +1 -0
  111. package/typings/core/helpers/check.d.ts +56 -0
  112. package/typings/core/helpers/check.d.ts.map +1 -0
  113. package/typings/core/helpers/compact.d.ts +4 -0
  114. package/typings/core/helpers/compact.d.ts.map +1 -0
  115. package/typings/core/helpers/deunionize.d.ts +18 -0
  116. package/typings/core/helpers/deunionize.d.ts.map +1 -0
  117. package/typings/core/helpers/formatting.d.ts +30 -0
  118. package/typings/core/helpers/formatting.d.ts.map +1 -0
  119. package/typings/core/helpers/util.d.ts +27 -0
  120. package/typings/core/helpers/util.d.ts.map +1 -0
  121. package/typings/core/network/client.d.ts +55 -0
  122. package/typings/core/network/client.d.ts.map +1 -0
  123. package/typings/core/network/error.d.ts +16 -0
  124. package/typings/core/network/error.d.ts.map +1 -0
  125. package/typings/core/network/multipart-stream.d.ts +20 -0
  126. package/typings/core/network/multipart-stream.d.ts.map +1 -0
  127. package/typings/core/network/polling.d.ts +16 -0
  128. package/typings/core/network/polling.d.ts.map +1 -0
  129. package/typings/core/network/webhook.d.ts +7 -0
  130. package/typings/core/network/webhook.d.ts.map +1 -0
  131. package/typings/core/types/rich-message.d.ts +144 -0
  132. package/typings/core/types/rich-message.d.ts.map +1 -0
  133. package/typings/core/types/typegram.d.ts +46 -0
  134. package/typings/core/types/typegram.d.ts.map +1 -0
  135. package/typings/filters.d.ts +18 -0
  136. package/typings/filters.d.ts.map +1 -0
  137. package/typings/format.d.ts +22 -0
  138. package/typings/format.d.ts.map +1 -0
  139. package/typings/future.d.ts +12 -0
  140. package/typings/future.d.ts.map +1 -0
  141. package/typings/index.d.ts +16 -0
  142. package/typings/index.d.ts.map +1 -0
  143. package/typings/input.d.ts +59 -0
  144. package/typings/input.d.ts.map +1 -0
  145. package/typings/markup.d.ts +27 -0
  146. package/typings/markup.d.ts.map +1 -0
  147. package/typings/middleware.d.ts +8 -0
  148. package/typings/middleware.d.ts.map +1 -0
  149. package/typings/reactions.d.ts +32 -0
  150. package/typings/reactions.d.ts.map +1 -0
  151. package/typings/router.d.ts +21 -0
  152. package/typings/router.d.ts.map +1 -0
  153. package/typings/scenes/base.d.ts +22 -0
  154. package/typings/scenes/base.d.ts.map +1 -0
  155. package/typings/scenes/context.d.ts +36 -0
  156. package/typings/scenes/context.d.ts.map +1 -0
  157. package/typings/scenes/index.d.ts +11 -0
  158. package/typings/scenes/index.d.ts.map +1 -0
  159. package/typings/scenes/stage.d.ts +24 -0
  160. package/typings/scenes/stage.d.ts.map +1 -0
  161. package/typings/scenes/wizard/context.d.ts +29 -0
  162. package/typings/scenes/wizard/context.d.ts.map +1 -0
  163. package/typings/scenes/wizard/index.d.ts +16 -0
  164. package/typings/scenes/wizard/index.d.ts.map +1 -0
  165. package/typings/scenes.d.ts +2 -0
  166. package/typings/scenes.d.ts.map +1 -0
  167. package/typings/session.d.ts +55 -0
  168. package/typings/session.d.ts.map +1 -0
  169. package/typings/telegraf.d.ts +119 -0
  170. package/typings/telegraf.d.ts.map +1 -0
  171. package/typings/telegram-types.d.ts +141 -0
  172. package/typings/telegram-types.d.ts.map +1 -0
  173. package/typings/telegram.d.ts +694 -0
  174. package/typings/telegram.d.ts.map +1 -0
  175. package/typings/types.d.ts +3 -0
  176. package/typings/types.d.ts.map +1 -0
  177. package/typings/utils.d.ts +2 -0
  178. package/typings/utils.d.ts.map +1 -0
  179. package/utils.d.ts +1 -0
  180. package/utils.js +1 -0
@@ -0,0 +1,375 @@
1
+ /**
2
+ * Telegram Bot API 10.1 — Rich Messages
3
+ * https://core.telegram.org/bots/api#june-11-2026
4
+ */
5
+
6
+ // ---------------------------------------------------------------------------
7
+ // Core types
8
+ // ---------------------------------------------------------------------------
9
+
10
+ /**
11
+ * Rich formatted message received from Telegram.
12
+ * The `blocks` array is rendered server-side; to send, use InputRichMessage.
13
+ */
14
+ export interface RichMessage {
15
+ blocks: object[]
16
+ is_rtl?: boolean
17
+ }
18
+
19
+ /**
20
+ * Describes a rich message to send.
21
+ * Exactly ONE of `html` or `markdown` must be specified.
22
+ */
23
+ export interface InputRichMessage {
24
+ html?: string
25
+ markdown?: string
26
+ is_rtl?: boolean
27
+ skip_entity_detection?: boolean
28
+ }
29
+
30
+ /** Can be used as InputMessageContent in inline, guest, and Web App queries. */
31
+ export interface InputRichMessageContent {
32
+ rich_message: InputRichMessage
33
+ }
34
+
35
+ // ---------------------------------------------------------------------------
36
+ // HTML Builder
37
+ // ---------------------------------------------------------------------------
38
+
39
+ /**
40
+ * Fluent builder for Rich Messages using HTML format.
41
+ *
42
+ * @example
43
+ * const msg = new RichHTMLBuilder()
44
+ * .heading(1, 'Title')
45
+ * .paragraph(RichHTMLBuilder.bold('Hello') + ' world')
46
+ * .build()
47
+ */
48
+ export class RichHTMLBuilder {
49
+ private readonly _parts: string[] = []
50
+
51
+ // ── Inline static helpers ──────────────────────────────────────────────
52
+
53
+ static bold(t: string) { return `<b>${t}</b>` }
54
+ static italic(t: string) { return `<i>${t}</i>` }
55
+ static underline(t: string) { return `<u>${t}</u>` }
56
+ static strikethrough(t: string) { return `<s>${t}</s>` }
57
+ static spoiler(t: string) { return `<tg-spoiler>${t}</tg-spoiler>` }
58
+ static code(t: string) { return `<code>${t}</code>` }
59
+ static marked(t: string) { return `<mark>${t}</mark>` }
60
+ static sub(t: string) { return `<sub>${t}</sub>` }
61
+ static sup(t: string) { return `<sup>${t}</sup>` }
62
+ static url(href: string, text: string) { return `<a href="${href}">${text}</a>` }
63
+ static email(email: string, text?: string) { return `<a href="mailto:${email}">${text ?? email}</a>` }
64
+ static phone(phone: string, text?: string) { return `<a href="tel:${phone}">${text ?? phone}</a>` }
65
+ static mention(userId: number, text: string) { return `<a href="tg://user?id=${userId}">${text}</a>` }
66
+ static customEmoji(emojiId: string, fallback: string) { return `<tg-emoji emoji-id="${emojiId}">${fallback}</tg-emoji>` }
67
+ static time(unix: number, format: string, text: string) { return `<tg-time unix="${unix}" format="${format}">${text}</tg-time>` }
68
+ static inlineMath(expression: string) { return `$${expression}$` }
69
+ static anchor(name: string) { return `<a name="${name}"></a>` }
70
+ static anchorLink(name: string, text: string) { return `<a href="#${name}">${text}</a>` }
71
+ static ref(id: string, text: string) { return `<a href="#${id}">${text}</a>` }
72
+
73
+ // ── Block methods ──────────────────────────────────────────────────────
74
+
75
+ heading(level: 1 | 2 | 3 | 4 | 5 | 6, html: string) {
76
+ this._parts.push(`<h${level}>${html}</h${level}>`)
77
+ return this
78
+ }
79
+
80
+ paragraph(html: string) {
81
+ this._parts.push(`<p>${html}</p>`)
82
+ return this
83
+ }
84
+
85
+ pre(code: string, language?: string) {
86
+ this._parts.push(
87
+ language
88
+ ? `<pre><code class="language-${language}">${code}</code></pre>`
89
+ : `<pre>${code}</pre>`
90
+ )
91
+ return this
92
+ }
93
+
94
+ footer(html: string) {
95
+ this._parts.push(`<footer>${html}</footer>`)
96
+ return this
97
+ }
98
+
99
+ divider() {
100
+ this._parts.push('<hr/>')
101
+ return this
102
+ }
103
+
104
+ ul(...items: string[]) {
105
+ this._parts.push(`<ul>${items.map((i) => `<li>${i}</li>`).join('')}</ul>`)
106
+ return this
107
+ }
108
+
109
+ ol(...items: string[]) {
110
+ this._parts.push(`<ol>${items.map((i) => `<li>${i}</li>`).join('')}</ol>`)
111
+ return this
112
+ }
113
+
114
+ taskList(...items: Array<{ text: string; checked?: boolean }>) {
115
+ const lis = items.map(
116
+ (i) => `<li><input type="checkbox"${i.checked ? ' checked' : ''}>${i.text}</li>`
117
+ )
118
+ this._parts.push(`<ul>${lis.join('')}</ul>`)
119
+ return this
120
+ }
121
+
122
+ blockQuote(html: string) {
123
+ this._parts.push(`<blockquote>${html}</blockquote>`)
124
+ return this
125
+ }
126
+
127
+ pullQuote(html: string, cite?: string) {
128
+ this._parts.push(`<aside>${html}${cite ? `<cite>${cite}</cite>` : ''}</aside>`)
129
+ return this
130
+ }
131
+
132
+ photo(src: string, caption?: string, spoiler?: boolean) {
133
+ const img = `<img src="${src}"${spoiler ? ' tg-spoiler' : ''}/>`
134
+ this._parts.push(caption ? `<figure>${img}<figcaption>${caption}</figcaption></figure>` : img)
135
+ return this
136
+ }
137
+
138
+ video(src: string, caption?: string, spoiler?: boolean) {
139
+ const vid = `<video src="${src}"${spoiler ? ' tg-spoiler' : ''}></video>`
140
+ this._parts.push(caption ? `<figure>${vid}<figcaption>${caption}</figcaption></figure>` : vid)
141
+ return this
142
+ }
143
+
144
+ audio(src: string, caption?: string) {
145
+ const aud = `<audio src="${src}"></audio>`
146
+ this._parts.push(caption ? `<figure>${aud}<figcaption>${caption}</figcaption></figure>` : aud)
147
+ return this
148
+ }
149
+
150
+ map(lat: number, long: number, zoom?: number, caption?: string) {
151
+ const tag = `<tg-map lat="${lat}" long="${long}"${zoom != null ? ` zoom="${zoom}"` : ''}/>`
152
+ this._parts.push(caption ? `<figure>${tag}<figcaption>${caption}</figcaption></figure>` : tag)
153
+ return this
154
+ }
155
+
156
+ collage(...media: string[]) {
157
+ this._parts.push(`<tg-collage>${media.join('')}</tg-collage>`)
158
+ return this
159
+ }
160
+
161
+ slideshow(...media: string[]) {
162
+ this._parts.push(`<tg-slideshow>${media.join('')}</tg-slideshow>`)
163
+ return this
164
+ }
165
+
166
+ table(
167
+ rows: string[][],
168
+ options?: { bordered?: boolean; striped?: boolean; hasHeader?: boolean }
169
+ ) {
170
+ const attrs = [options?.bordered && 'bordered', options?.striped && 'striped']
171
+ .filter(Boolean)
172
+ .join(' ')
173
+ const [header, ...body] = rows
174
+ const headHtml = options?.hasHeader && header
175
+ ? `<tr>${header.map((c) => `<th>${c}</th>`).join('')}</tr>`
176
+ : ''
177
+ const bodyRows = (options?.hasHeader ? body : rows)
178
+ .map((r) => `<tr>${r.map((c) => `<td>${c}</td>`).join('')}</tr>`)
179
+ .join('')
180
+ this._parts.push(`<table${attrs ? ` ${attrs}` : ''}>${headHtml}${bodyRows}</table>`)
181
+ return this
182
+ }
183
+
184
+ details(summary: string, content: string, open?: boolean) {
185
+ this._parts.push(
186
+ `<details${open ? ' open' : ''}><summary>${summary}</summary>${content}</details>`
187
+ )
188
+ return this
189
+ }
190
+
191
+ mathBlock(expression: string) {
192
+ this._parts.push(`<tg-math-block>${expression}</tg-math-block>`)
193
+ return this
194
+ }
195
+
196
+ thinking(html: string) {
197
+ this._parts.push(`<tg-thinking>${html}</tg-thinking>`)
198
+ return this
199
+ }
200
+
201
+ referenceDefinition(id: string, html: string) {
202
+ this._parts.push(`<tg-reference name="${id}">${html}</tg-reference>`)
203
+ return this
204
+ }
205
+
206
+ raw(html: string) {
207
+ this._parts.push(html)
208
+ return this
209
+ }
210
+
211
+ build(options?: Pick<InputRichMessage, 'is_rtl' | 'skip_entity_detection'>): InputRichMessage {
212
+ return { html: this._parts.join('\n'), ...options }
213
+ }
214
+ }
215
+
216
+ // ---------------------------------------------------------------------------
217
+ // Markdown Builder
218
+ // ---------------------------------------------------------------------------
219
+
220
+ /**
221
+ * Fluent builder for Rich Messages using Markdown format.
222
+ *
223
+ * @example
224
+ * const msg = new RichMarkdownBuilder()
225
+ * .heading(1, 'Title')
226
+ * .paragraph(RichMarkdownBuilder.bold('Hello') + ' world')
227
+ * .build()
228
+ */
229
+ export class RichMarkdownBuilder {
230
+ private readonly _parts: string[] = []
231
+
232
+ // ── Inline static helpers ──────────────────────────────────────────────
233
+
234
+ static bold(t: string) { return `**${t}**` }
235
+ static italic(t: string) { return `*${t}*` }
236
+ static underline(t: string) { return `<u>${t}</u>` }
237
+ static strikethrough(t: string) { return `~~${t}~~` }
238
+ static spoiler(t: string) { return `||${t}||` }
239
+ static code(t: string) { return `\`${t}\`` }
240
+ static marked(t: string) { return `==${t}==` }
241
+ static sub(t: string) { return `<sub>${t}</sub>` }
242
+ static sup(t: string) { return `<sup>${t}</sup>` }
243
+ static url(href: string, text: string) { return `[${text}](${href})` }
244
+ static email(email: string, text?: string) { return `[${text ?? email}](mailto:${email})` }
245
+ static phone(phone: string, text?: string) { return `[${text ?? phone}](tel:${phone})` }
246
+ static mention(userId: number, text: string) { return `[${text}](tg://user?id=${userId})` }
247
+ static customEmoji(emojiId: string, fallback: string) { return `![${fallback}](tg://emoji?id=${emojiId})` }
248
+ static time(unix: number, format: string) { return `![](tg://time?unix=${unix}&format=${format})` }
249
+ static inlineMath(expression: string) { return `$${expression}$` }
250
+
251
+ // ── Block methods ──────────────────────────────────────────────────────
252
+
253
+ heading(level: 1 | 2 | 3 | 4 | 5 | 6, text: string) {
254
+ this._parts.push(`${'#'.repeat(level)} ${text}`)
255
+ return this
256
+ }
257
+
258
+ paragraph(text: string) {
259
+ this._parts.push(text)
260
+ return this
261
+ }
262
+
263
+ pre(code: string, language?: string) {
264
+ this._parts.push(`\`\`\`${language ?? ''}\n${code}\n\`\`\``)
265
+ return this
266
+ }
267
+
268
+ divider() {
269
+ this._parts.push('---')
270
+ return this
271
+ }
272
+
273
+ ul(...items: string[]) {
274
+ this._parts.push(items.map((i) => `- ${i}`).join('\n'))
275
+ return this
276
+ }
277
+
278
+ ol(...items: string[]) {
279
+ this._parts.push(items.map((i, idx) => `${idx + 1}. ${i}`).join('\n'))
280
+ return this
281
+ }
282
+
283
+ taskList(...items: Array<{ text: string; checked?: boolean }>) {
284
+ this._parts.push(items.map((i) => `- [${i.checked ? 'x' : ' '}] ${i.text}`).join('\n'))
285
+ return this
286
+ }
287
+
288
+ blockQuote(...lines: string[]) {
289
+ this._parts.push(lines.map((l) => `>${l}`).join('\n'))
290
+ return this
291
+ }
292
+
293
+ photo(src: string, caption?: string) {
294
+ this._parts.push(`![](${src}${caption ? ` "${caption}"` : ''})`)
295
+ return this
296
+ }
297
+
298
+ video(src: string, caption?: string) {
299
+ this._parts.push(`![](${src}${caption ? ` "${caption}"` : ''})`)
300
+ return this
301
+ }
302
+
303
+ audio(src: string, caption?: string) {
304
+ this._parts.push(`![](${src}${caption ? ` "${caption}"` : ''})`)
305
+ return this
306
+ }
307
+
308
+ table(headers: string[], rows: string[][], alignment?: Array<'left' | 'center' | 'right'>) {
309
+ const sep = headers.map((_, i) => {
310
+ const a = alignment?.[i]
311
+ if (a === 'center') return ':---:'
312
+ if (a === 'right') return '---:'
313
+ return ':---'
314
+ })
315
+ const lines = [
316
+ `| ${headers.join(' | ')} |`,
317
+ `|${sep.map((s) => s + '-').join('|')}|`,
318
+ ...rows.map((r) => `| ${r.join(' | ')} |`),
319
+ ]
320
+ this._parts.push(lines.join('\n'))
321
+ return this
322
+ }
323
+
324
+ footnoteRef(id: string) { return `[^${id}]` }
325
+
326
+ footnote(id: string, definition: string) {
327
+ this._parts.push(`[^${id}]: ${definition}`)
328
+ return this
329
+ }
330
+
331
+ mathBlock(expression: string) {
332
+ this._parts.push(`$$${expression}$$`)
333
+ return this
334
+ }
335
+
336
+ thinking(text: string) {
337
+ this._parts.push(`<tg-thinking>${text}</tg-thinking>`)
338
+ return this
339
+ }
340
+
341
+ collage(...mediaSrcs: string[]) {
342
+ this._parts.push(
343
+ `<tg-collage>\n${mediaSrcs.map((s) => `![](${s})`).join('\n')}\n</tg-collage>`
344
+ )
345
+ return this
346
+ }
347
+
348
+ slideshow(...mediaSrcs: string[]) {
349
+ this._parts.push(
350
+ `<tg-slideshow>\n${mediaSrcs.map((s) => `![](${s})`).join('\n')}\n</tg-slideshow>`
351
+ )
352
+ return this
353
+ }
354
+
355
+ details(summary: string, content: string, open?: boolean) {
356
+ this._parts.push(
357
+ `<details${open ? ' open' : ''}><summary>${summary}</summary>\n${content}\n</details>`
358
+ )
359
+ return this
360
+ }
361
+
362
+ raw(md: string) {
363
+ this._parts.push(md)
364
+ return this
365
+ }
366
+
367
+ build(options?: Pick<InputRichMessage, 'is_rtl' | 'skip_entity_detection'>): InputRichMessage {
368
+ return { markdown: this._parts.join('\n\n'), ...options }
369
+ }
370
+ }
371
+
372
+ /** Shorthand alias for RichHTMLBuilder */
373
+ export const H = RichHTMLBuilder
374
+ /** Shorthand alias for RichMarkdownBuilder */
375
+ export const MD = RichMarkdownBuilder
@@ -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
+ }
package/src/format.ts ADDED
@@ -0,0 +1,110 @@
1
+ import { User } from '@telegraf/types'
2
+ import {
3
+ FmtString,
4
+ createFmt,
5
+ linkOrMention,
6
+ join as _join,
7
+ } from './core/helpers/formatting'
8
+
9
+ export { FmtString }
10
+
11
+ type Nestable<Kind extends string> = string | number | boolean | FmtString<Kind>
12
+ type Nesting<Kind extends string> = [
13
+ parts: Nestable<Kind> | readonly Nestable<Kind>[],
14
+ ...items: Nestable<Kind>[],
15
+ ]
16
+ type Nests<Is extends string, Kind extends string> = (
17
+ ...args: Nesting<Kind>
18
+ ) => FmtString<Is>
19
+
20
+ // Nests<A, B> means the function will return A, and it can nest B
21
+ // Nests<'fmt', string> means it will nest anything
22
+ // Nests<'code', never> means it will not nest anything
23
+
24
+ // Allowing everything to nest 'fmt' is a necessary evil; it allows to indirectly nest illegal entities
25
+ // Except for 'code' and 'pre', which don't nest anything anyway, so they only deal with strings
26
+
27
+ export const join = _join as Nests<'fmt', string>
28
+
29
+ export const fmt = createFmt() as Nests<'fmt', string>
30
+
31
+ export const bold = createFmt('bold') as Nests<
32
+ 'bold',
33
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
34
+ >
35
+
36
+ export const italic = createFmt('italic') as Nests<
37
+ 'italic',
38
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
39
+ >
40
+
41
+ export const spoiler = createFmt('spoiler') as Nests<
42
+ 'spoiler',
43
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
44
+ >
45
+
46
+ export const strikethrough =
47
+ //
48
+ createFmt('strikethrough') as Nests<
49
+ 'strikethrough',
50
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
51
+ >
52
+
53
+ export const underline =
54
+ //
55
+ createFmt('underline') as Nests<
56
+ 'underline',
57
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
58
+ >
59
+
60
+ export const quote =
61
+ //
62
+ createFmt('blockquote') as Nests<
63
+ 'blockquote',
64
+ | 'fmt'
65
+ | 'bold'
66
+ | 'italic'
67
+ | 'underline'
68
+ | 'strikethrough'
69
+ | 'spoiler'
70
+ | 'code'
71
+ >
72
+
73
+ export const code = createFmt('code') as Nests<'code', never>
74
+
75
+ export const pre = (language: string) =>
76
+ createFmt('pre', { language }) as Nests<'pre', never>
77
+
78
+ export const link = (
79
+ content: Nestable<
80
+ | 'fmt'
81
+ | 'bold'
82
+ | 'italic'
83
+ | 'underline'
84
+ | 'strikethrough'
85
+ | 'spoiler'
86
+ | 'code'
87
+ >,
88
+ url: string
89
+ ) =>
90
+ //
91
+ linkOrMention(content, { type: 'text_link', url }) as FmtString<'text_link'>
92
+
93
+ export const mention = (
94
+ name: Nestable<
95
+ | 'fmt'
96
+ | 'bold'
97
+ | 'italic'
98
+ | 'underline'
99
+ | 'strikethrough'
100
+ | 'spoiler'
101
+ | 'code'
102
+ >,
103
+ user: number | User
104
+ ) =>
105
+ typeof user === 'number'
106
+ ? link(name, 'tg://user?id=' + user)
107
+ : (linkOrMention(name, {
108
+ type: 'text_mention',
109
+ user,
110
+ }) as FmtString<'text_mention'>)