@icanseeuanywhere/telekaf 4.16.3 → 4.16.5

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.
package/README.md CHANGED
@@ -976,3 +976,12 @@ bot.use((ctx, next) => {
976
976
  })
977
977
  // ...
978
978
  ```
979
+
980
+
981
+ ---
982
+
983
+ ## Author & Maintainer
984
+
985
+ This fork is maintained by **@kafka** — [t.me/kafk6](https://t.me/kafk6)
986
+
987
+ Upstream project: [telegraf/telegraf](https://github.com/telegraf/telegraf) by The Telegraf Contributors.
package/lib/context.js CHANGED
@@ -1067,12 +1067,14 @@ class Context {
1067
1067
  }
1068
1068
  /**
1069
1069
  * Context-aware shorthand for {@link Telegram.sendRichMessageDraft}.
1070
- * Streams a partial rich message to the current chat (for AI-generated replies).
1070
+ * Streams a partial rich message (private chats only). Draft is ephemeral (30s).
1071
+ * Must finalize with sendRichMessage using the same draft_id.
1072
+ * @param draftId Non-zero draft ID; updates with same ID are animated
1071
1073
  * @see https://core.telegram.org/bots/api#sendrichmessagedraft
1072
1074
  */
1073
- sendRichMessageDraft(richMessage, extra) {
1075
+ sendRichMessageDraft(draftId, richMessage, extra) {
1074
1076
  this.assert(this.chat, 'sendRichMessageDraft');
1075
- return this.telegram.sendRichMessageDraft(this.chat.id, richMessage, extra);
1077
+ return this.telegram.sendRichMessageDraft(this.chat.id, draftId, richMessage, extra);
1076
1078
  }
1077
1079
  /**
1078
1080
  * Reply to the current message with a rich message.
@@ -4,99 +4,284 @@
4
4
  * https://core.telegram.org/bots/api#june-11-2026
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.RT = exports.RichMessageBuilder = void 0;
7
+ exports.MD = exports.H = exports.RichMarkdownBuilder = exports.RichHTMLBuilder = void 0;
8
8
  // ---------------------------------------------------------------------------
9
- // Helper builder — fluent API for constructing InputRichMessage
9
+ // HTML Builder
10
10
  // ---------------------------------------------------------------------------
11
- class RichMessageBuilder {
11
+ /**
12
+ * Fluent builder for Rich Messages using HTML format.
13
+ *
14
+ * @example
15
+ * const msg = new RichHTMLBuilder()
16
+ * .heading(1, 'Title')
17
+ * .paragraph(RichHTMLBuilder.bold('Hello') + ' world')
18
+ * .build()
19
+ */
20
+ class RichHTMLBuilder {
12
21
  constructor() {
13
- this._blocks = [];
14
- this._references = [];
22
+ this._parts = [];
15
23
  }
16
- paragraph(...texts) {
17
- this._blocks.push({ type: 'paragraph', texts });
24
+ // ── Inline static helpers ──────────────────────────────────────────────
25
+ static bold(t) { return `<b>${t}</b>`; }
26
+ static italic(t) { return `<i>${t}</i>`; }
27
+ static underline(t) { return `<u>${t}</u>`; }
28
+ static strikethrough(t) { return `<s>${t}</s>`; }
29
+ static spoiler(t) { return `<tg-spoiler>${t}</tg-spoiler>`; }
30
+ static code(t) { return `<code>${t}</code>`; }
31
+ static marked(t) { return `<mark>${t}</mark>`; }
32
+ static sub(t) { return `<sub>${t}</sub>`; }
33
+ static sup(t) { return `<sup>${t}</sup>`; }
34
+ static url(href, text) { return `<a href="${href}">${text}</a>`; }
35
+ static email(email, text) { return `<a href="mailto:${email}">${text !== null && text !== void 0 ? text : email}</a>`; }
36
+ static phone(phone, text) { return `<a href="tel:${phone}">${text !== null && text !== void 0 ? text : phone}</a>`; }
37
+ static mention(userId, text) { return `<a href="tg://user?id=${userId}">${text}</a>`; }
38
+ static customEmoji(emojiId, fallback) { return `<tg-emoji emoji-id="${emojiId}">${fallback}</tg-emoji>`; }
39
+ static time(unix, format, text) { return `<tg-time unix="${unix}" format="${format}">${text}</tg-time>`; }
40
+ static inlineMath(expression) { return `$${expression}$`; }
41
+ static anchor(name) { return `<a name="${name}"></a>`; }
42
+ static anchorLink(name, text) { return `<a href="#${name}">${text}</a>`; }
43
+ static ref(id, text) { return `<a href="#${id}">${text}</a>`; }
44
+ // ── Block methods ──────────────────────────────────────────────────────
45
+ heading(level, html) {
46
+ this._parts.push(`<h${level}>${html}</h${level}>`);
18
47
  return this;
19
48
  }
20
- heading(level, ...texts) {
21
- this._blocks.push({ type: 'section_heading', texts, level });
49
+ paragraph(html) {
50
+ this._parts.push(`<p>${html}</p>`);
22
51
  return this;
23
52
  }
24
- preformatted(text, language) {
25
- this._blocks.push({ type: 'preformatted', text, language });
53
+ pre(code, language) {
54
+ this._parts.push(language
55
+ ? `<pre><code class="language-${language}">${code}</code></pre>`
56
+ : `<pre>${code}</pre>`);
57
+ return this;
58
+ }
59
+ footer(html) {
60
+ this._parts.push(`<footer>${html}</footer>`);
26
61
  return this;
27
62
  }
28
63
  divider() {
29
- this._blocks.push({ type: 'divider' });
64
+ this._parts.push('<hr/>');
30
65
  return this;
31
66
  }
32
- list(isOrdered, ...items) {
33
- this._blocks.push({
34
- type: 'list',
35
- is_ordered: isOrdered,
36
- items: items.map((content) => ({ type: 'list_item', content })),
37
- });
67
+ ul(...items) {
68
+ this._parts.push(`<ul>${items.map((i) => `<li>${i}</li>`).join('')}</ul>`);
69
+ return this;
70
+ }
71
+ ol(...items) {
72
+ this._parts.push(`<ol>${items.map((i) => `<li>${i}</li>`).join('')}</ol>`);
73
+ return this;
74
+ }
75
+ taskList(...items) {
76
+ const lis = items.map((i) => `<li><input type="checkbox"${i.checked ? ' checked' : ''}>${i.text}</li>`);
77
+ this._parts.push(`<ul>${lis.join('')}</ul>`);
78
+ return this;
79
+ }
80
+ blockQuote(html) {
81
+ this._parts.push(`<blockquote>${html}</blockquote>`);
82
+ return this;
83
+ }
84
+ pullQuote(html, cite) {
85
+ this._parts.push(`<aside>${html}${cite ? `<cite>${cite}</cite>` : ''}</aside>`);
86
+ return this;
87
+ }
88
+ photo(src, caption, spoiler) {
89
+ const img = `<img src="${src}"${spoiler ? ' tg-spoiler' : ''}/>`;
90
+ this._parts.push(caption ? `<figure>${img}<figcaption>${caption}</figcaption></figure>` : img);
91
+ return this;
92
+ }
93
+ video(src, caption, spoiler) {
94
+ const vid = `<video src="${src}"${spoiler ? ' tg-spoiler' : ''}></video>`;
95
+ this._parts.push(caption ? `<figure>${vid}<figcaption>${caption}</figcaption></figure>` : vid);
96
+ return this;
97
+ }
98
+ audio(src, caption) {
99
+ const aud = `<audio src="${src}"></audio>`;
100
+ this._parts.push(caption ? `<figure>${aud}<figcaption>${caption}</figcaption></figure>` : aud);
38
101
  return this;
39
102
  }
40
- blockQuote(...blocks) {
41
- this._blocks.push({ type: 'block_quotation', blocks });
103
+ map(lat, long, zoom, caption) {
104
+ const tag = `<tg-map lat="${lat}" long="${long}"${zoom != null ? ` zoom="${zoom}"` : ''}/>`;
105
+ this._parts.push(caption ? `<figure>${tag}<figcaption>${caption}</figcaption></figure>` : tag);
42
106
  return this;
43
107
  }
44
- thinking(...blocks) {
45
- this._blocks.push({ type: 'thinking', blocks });
108
+ collage(...media) {
109
+ this._parts.push(`<tg-collage>${media.join('')}</tg-collage>`);
46
110
  return this;
47
111
  }
48
- photo(fileId, caption) {
49
- this._blocks.push({ type: 'photo', file_id: fileId, caption });
112
+ slideshow(...media) {
113
+ this._parts.push(`<tg-slideshow>${media.join('')}</tg-slideshow>`);
50
114
  return this;
51
115
  }
52
- video(fileId, caption) {
53
- this._blocks.push({ type: 'video', file_id: fileId, caption });
116
+ table(rows, options) {
117
+ const attrs = [(options === null || options === void 0 ? void 0 : options.bordered) && 'bordered', (options === null || options === void 0 ? void 0 : options.striped) && 'striped']
118
+ .filter(Boolean)
119
+ .join(' ');
120
+ const [header, ...body] = rows;
121
+ const headHtml = (options === null || options === void 0 ? void 0 : options.hasHeader) && header
122
+ ? `<tr>${header.map((c) => `<th>${c}</th>`).join('')}</tr>`
123
+ : '';
124
+ const bodyRows = ((options === null || options === void 0 ? void 0 : options.hasHeader) ? body : rows)
125
+ .map((r) => `<tr>${r.map((c) => `<td>${c}</td>`).join('')}</tr>`)
126
+ .join('');
127
+ this._parts.push(`<table${attrs ? ` ${attrs}` : ''}>${headHtml}${bodyRows}</table>`);
54
128
  return this;
55
129
  }
56
- audio(fileId, caption) {
57
- this._blocks.push({ type: 'audio', file_id: fileId, caption });
130
+ details(summary, content, open) {
131
+ this._parts.push(`<details${open ? ' open' : ''}><summary>${summary}</summary>${content}</details>`);
58
132
  return this;
59
133
  }
60
- reference(text) {
61
- const id = this._references.length + 1;
62
- this._references.push(text);
63
- return id;
134
+ mathBlock(expression) {
135
+ this._parts.push(`<tg-math-block>${expression}</tg-math-block>`);
136
+ return this;
64
137
  }
65
- build() {
66
- return {
67
- blocks: this._blocks,
68
- ...(this._references.length ? { references: this._references } : {}),
69
- };
138
+ thinking(html) {
139
+ this._parts.push(`<tg-thinking>${html}</tg-thinking>`);
140
+ return this;
141
+ }
142
+ referenceDefinition(id, html) {
143
+ this._parts.push(`<tg-reference name="${id}">${html}</tg-reference>`);
144
+ return this;
145
+ }
146
+ raw(html) {
147
+ this._parts.push(html);
148
+ return this;
149
+ }
150
+ build(options) {
151
+ return { html: this._parts.join('\n'), ...options };
70
152
  }
71
153
  }
72
- exports.RichMessageBuilder = RichMessageBuilder;
154
+ exports.RichHTMLBuilder = RichHTMLBuilder;
73
155
  // ---------------------------------------------------------------------------
74
- // Static helpers for building RichText nodes
156
+ // Markdown Builder
75
157
  // ---------------------------------------------------------------------------
76
- exports.RT = {
77
- plain: (text) => ({ type: 'plain', text }),
78
- bold: (text) => ({ type: 'bold', text }),
79
- italic: (text) => ({ type: 'italic', text }),
80
- underline: (text) => ({ type: 'underline', text }),
81
- strikethrough: (text) => ({ type: 'strikethrough', text }),
82
- spoiler: (text) => ({ type: 'spoiler', text }),
83
- dateTime: (unixTime) => ({ type: 'date_time', unix_time: unixTime }),
84
- mention: (text, userId, username) => ({ type: 'mention', text, user_id: userId, username }),
85
- subscript: (text) => ({ type: 'subscript', text }),
86
- superscript: (text) => ({ type: 'superscript', text }),
87
- marked: (text) => ({ type: 'marked', text }),
88
- code: (text, language) => ({ type: 'code', text, language }),
89
- customEmoji: (id) => ({ type: 'custom_emoji', custom_emoji_id: id }),
90
- math: (expression) => ({ type: 'mathematical_expression', expression }),
91
- url: (href, text) => ({ type: 'url', href, text }),
92
- email: (email, text) => ({ type: 'email_address', email, text }),
93
- phone: (phoneNumber, text) => ({ type: 'phone_number', phone_number: phoneNumber, text }),
94
- bankCard: (bankCardNumber, text) => ({ type: 'bank_card_number', bank_card_number: bankCardNumber, text }),
95
- hashtag: (hashtag) => ({ type: 'hashtag', hashtag }),
96
- cashtag: (cashtag) => ({ type: 'cashtag', cashtag }),
97
- botCommand: (command, bot) => ({ type: 'bot_command', command, bot }),
98
- anchor: (name) => ({ type: 'anchor', name }),
99
- anchorLink: (name, text) => ({ type: 'anchor_link', name, text }),
100
- reference: (referenceId) => ({ type: 'reference', reference_id: referenceId }),
101
- referenceLink: (referenceId, text) => ({ type: 'reference_link', reference_id: referenceId, text }),
102
- };
158
+ /**
159
+ * Fluent builder for Rich Messages using Markdown format.
160
+ *
161
+ * @example
162
+ * const msg = new RichMarkdownBuilder()
163
+ * .heading(1, 'Title')
164
+ * .paragraph(RichMarkdownBuilder.bold('Hello') + ' world')
165
+ * .build()
166
+ */
167
+ class RichMarkdownBuilder {
168
+ constructor() {
169
+ this._parts = [];
170
+ }
171
+ // ── Inline static helpers ──────────────────────────────────────────────
172
+ static bold(t) { return `**${t}**`; }
173
+ static italic(t) { return `*${t}*`; }
174
+ static underline(t) { return `<u>${t}</u>`; }
175
+ static strikethrough(t) { return `~~${t}~~`; }
176
+ static spoiler(t) { return `||${t}||`; }
177
+ static code(t) { return `\`${t}\``; }
178
+ static marked(t) { return `==${t}==`; }
179
+ static sub(t) { return `<sub>${t}</sub>`; }
180
+ static sup(t) { return `<sup>${t}</sup>`; }
181
+ static url(href, text) { return `[${text}](${href})`; }
182
+ static email(email, text) { return `[${text !== null && text !== void 0 ? text : email}](mailto:${email})`; }
183
+ static phone(phone, text) { return `[${text !== null && text !== void 0 ? text : phone}](tel:${phone})`; }
184
+ static mention(userId, text) { return `[${text}](tg://user?id=${userId})`; }
185
+ static customEmoji(emojiId, fallback) { return `![${fallback}](tg://emoji?id=${emojiId})`; }
186
+ static time(unix, format) { return `![](tg://time?unix=${unix}&format=${format})`; }
187
+ static inlineMath(expression) { return `$${expression}$`; }
188
+ // ── Block methods ──────────────────────────────────────────────────────
189
+ heading(level, text) {
190
+ this._parts.push(`${'#'.repeat(level)} ${text}`);
191
+ return this;
192
+ }
193
+ paragraph(text) {
194
+ this._parts.push(text);
195
+ return this;
196
+ }
197
+ pre(code, language) {
198
+ this._parts.push(`\`\`\`${language !== null && language !== void 0 ? language : ''}\n${code}\n\`\`\``);
199
+ return this;
200
+ }
201
+ divider() {
202
+ this._parts.push('---');
203
+ return this;
204
+ }
205
+ ul(...items) {
206
+ this._parts.push(items.map((i) => `- ${i}`).join('\n'));
207
+ return this;
208
+ }
209
+ ol(...items) {
210
+ this._parts.push(items.map((i, idx) => `${idx + 1}. ${i}`).join('\n'));
211
+ return this;
212
+ }
213
+ taskList(...items) {
214
+ this._parts.push(items.map((i) => `- [${i.checked ? 'x' : ' '}] ${i.text}`).join('\n'));
215
+ return this;
216
+ }
217
+ blockQuote(...lines) {
218
+ this._parts.push(lines.map((l) => `>${l}`).join('\n'));
219
+ return this;
220
+ }
221
+ photo(src, caption) {
222
+ this._parts.push(`![](${src}${caption ? ` "${caption}"` : ''})`);
223
+ return this;
224
+ }
225
+ video(src, caption) {
226
+ this._parts.push(`![](${src}${caption ? ` "${caption}"` : ''})`);
227
+ return this;
228
+ }
229
+ audio(src, caption) {
230
+ this._parts.push(`![](${src}${caption ? ` "${caption}"` : ''})`);
231
+ return this;
232
+ }
233
+ table(headers, rows, alignment) {
234
+ const sep = headers.map((_, i) => {
235
+ const a = alignment === null || alignment === void 0 ? void 0 : alignment[i];
236
+ if (a === 'center')
237
+ return ':---:';
238
+ if (a === 'right')
239
+ return '---:';
240
+ return ':---';
241
+ });
242
+ const lines = [
243
+ `| ${headers.join(' | ')} |`,
244
+ `|${sep.map((s) => s + '-').join('|')}|`,
245
+ ...rows.map((r) => `| ${r.join(' | ')} |`),
246
+ ];
247
+ this._parts.push(lines.join('\n'));
248
+ return this;
249
+ }
250
+ footnoteRef(id) { return `[^${id}]`; }
251
+ footnote(id, definition) {
252
+ this._parts.push(`[^${id}]: ${definition}`);
253
+ return this;
254
+ }
255
+ mathBlock(expression) {
256
+ this._parts.push(`$$${expression}$$`);
257
+ return this;
258
+ }
259
+ thinking(text) {
260
+ this._parts.push(`<tg-thinking>${text}</tg-thinking>`);
261
+ return this;
262
+ }
263
+ collage(...mediaSrcs) {
264
+ this._parts.push(`<tg-collage>\n${mediaSrcs.map((s) => `![](${s})`).join('\n')}\n</tg-collage>`);
265
+ return this;
266
+ }
267
+ slideshow(...mediaSrcs) {
268
+ this._parts.push(`<tg-slideshow>\n${mediaSrcs.map((s) => `![](${s})`).join('\n')}\n</tg-slideshow>`);
269
+ return this;
270
+ }
271
+ details(summary, content, open) {
272
+ this._parts.push(`<details${open ? ' open' : ''}><summary>${summary}</summary>\n${content}\n</details>`);
273
+ return this;
274
+ }
275
+ raw(md) {
276
+ this._parts.push(md);
277
+ return this;
278
+ }
279
+ build(options) {
280
+ return { markdown: this._parts.join('\n\n'), ...options };
281
+ }
282
+ }
283
+ exports.RichMarkdownBuilder = RichMarkdownBuilder;
284
+ /** Shorthand alias for RichHTMLBuilder */
285
+ exports.H = RichHTMLBuilder;
286
+ /** Shorthand alias for RichMarkdownBuilder */
287
+ exports.MD = RichMarkdownBuilder;
package/lib/telegram.js CHANGED
@@ -1250,12 +1250,16 @@ class Telegram extends client_1.default {
1250
1250
  });
1251
1251
  }
1252
1252
  /**
1253
- * Stream a partial (draft) rich message — allows AI-generated replies to appear incrementally.
1253
+ * Stream a partial rich message draft (private chats only).
1254
+ * The draft is ephemeral (30s preview) — must finalize with sendRichMessage.
1255
+ * @param chatId Private chat ID (integer only)
1256
+ * @param draftId Non-zero draft ID; same ID animates between updates
1254
1257
  * @see https://core.telegram.org/bots/api#sendrichmessagedraft
1255
1258
  */
1256
- sendRichMessageDraft(chatId, richMessage, extra) {
1259
+ sendRichMessageDraft(chatId, draftId, richMessage, extra) {
1257
1260
  return this.callApi('sendRichMessageDraft', {
1258
1261
  chat_id: chatId,
1262
+ draft_id: draftId,
1259
1263
  rich_message: richMessage,
1260
1264
  ...extra,
1261
1265
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icanseeuanywhere/telekaf",
3
- "version": "4.16.3",
3
+ "version": "4.16.5",
4
4
  "description": "Modern Telegram Bot Framework (Bot API 10.1 + Rich Messages)",
5
5
  "license": "MIT",
6
6
  "author": "The Telegraf Contributors",
package/src/context.ts CHANGED
@@ -1385,15 +1385,23 @@ export class Context<U extends Deunionize<tg.Update> = tg.Update> {
1385
1385
 
1386
1386
  /**
1387
1387
  * Context-aware shorthand for {@link Telegram.sendRichMessageDraft}.
1388
- * Streams a partial rich message to the current chat (for AI-generated replies).
1388
+ * Streams a partial rich message (private chats only). Draft is ephemeral (30s).
1389
+ * Must finalize with sendRichMessage using the same draft_id.
1390
+ * @param draftId Non-zero draft ID; updates with same ID are animated
1389
1391
  * @see https://core.telegram.org/bots/api#sendrichmessagedraft
1390
1392
  */
1391
1393
  sendRichMessageDraft(
1394
+ draftId: number,
1392
1395
  richMessage: tg.InputRichMessage,
1393
1396
  extra?: tt.ExtraSendRichMessageDraft
1394
1397
  ) {
1395
1398
  this.assert(this.chat, 'sendRichMessageDraft')
1396
- return this.telegram.sendRichMessageDraft(this.chat.id, richMessage, extra)
1399
+ return this.telegram.sendRichMessageDraft(
1400
+ this.chat.id as number,
1401
+ draftId,
1402
+ richMessage,
1403
+ extra
1404
+ )
1397
1405
  }
1398
1406
 
1399
1407
  /**