@icanseeuanywhere/telekaf 4.16.4 → 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/lib/context.js +5 -3
- package/lib/core/types/rich-message.js +251 -66
- package/lib/telegram.js +6 -2
- package/package.json +1 -1
- package/src/context.ts +10 -2
- package/src/core/types/rich-message.ts +290 -389
- package/src/telegram-types.ts +11 -5
- package/src/telegram.ts +7 -2
- package/typings/context.d.ts +4 -2
- package/typings/context.d.ts.map +1 -1
- package/typings/core/types/rich-message.d.ts +129 -280
- package/typings/core/types/rich-message.d.ts.map +1 -1
- package/typings/telegram-types.d.ts +12 -5
- package/typings/telegram-types.d.ts.map +1 -1
- package/typings/telegram.d.ts +5 -2
- package/typings/telegram.d.ts.map +1 -1
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
|
|
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.
|
|
7
|
+
exports.MD = exports.H = exports.RichMarkdownBuilder = exports.RichHTMLBuilder = void 0;
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
|
-
//
|
|
9
|
+
// HTML Builder
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
|
-
|
|
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.
|
|
14
|
-
this._references = [];
|
|
22
|
+
this._parts = [];
|
|
15
23
|
}
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
this.
|
|
49
|
+
paragraph(html) {
|
|
50
|
+
this._parts.push(`<p>${html}</p>`);
|
|
22
51
|
return this;
|
|
23
52
|
}
|
|
24
|
-
|
|
25
|
-
this.
|
|
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.
|
|
64
|
+
this._parts.push('<hr/>');
|
|
30
65
|
return this;
|
|
31
66
|
}
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
45
|
-
this.
|
|
108
|
+
collage(...media) {
|
|
109
|
+
this._parts.push(`<tg-collage>${media.join('')}</tg-collage>`);
|
|
46
110
|
return this;
|
|
47
111
|
}
|
|
48
|
-
|
|
49
|
-
this.
|
|
112
|
+
slideshow(...media) {
|
|
113
|
+
this._parts.push(`<tg-slideshow>${media.join('')}</tg-slideshow>`);
|
|
50
114
|
return this;
|
|
51
115
|
}
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
this.
|
|
130
|
+
details(summary, content, open) {
|
|
131
|
+
this._parts.push(`<details${open ? ' open' : ''}><summary>${summary}</summary>${content}</details>`);
|
|
58
132
|
return this;
|
|
59
133
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this
|
|
63
|
-
return id;
|
|
134
|
+
mathBlock(expression) {
|
|
135
|
+
this._parts.push(`<tg-math-block>${expression}</tg-math-block>`);
|
|
136
|
+
return this;
|
|
64
137
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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.
|
|
154
|
+
exports.RichHTMLBuilder = RichHTMLBuilder;
|
|
73
155
|
// ---------------------------------------------------------------------------
|
|
74
|
-
//
|
|
156
|
+
// Markdown Builder
|
|
75
157
|
// ---------------------------------------------------------------------------
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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 ``; }
|
|
186
|
+
static time(unix, format) { return ``; }
|
|
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(``);
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
video(src, caption) {
|
|
226
|
+
this._parts.push(``);
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
audio(src, caption) {
|
|
230
|
+
this._parts.push(``);
|
|
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) => ``).join('\n')}\n</tg-collage>`);
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
slideshow(...mediaSrcs) {
|
|
268
|
+
this._parts.push(`<tg-slideshow>\n${mediaSrcs.map((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
|
|
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
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
|
|
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(
|
|
1399
|
+
return this.telegram.sendRichMessageDraft(
|
|
1400
|
+
this.chat.id as number,
|
|
1401
|
+
draftId,
|
|
1402
|
+
richMessage,
|
|
1403
|
+
extra
|
|
1404
|
+
)
|
|
1397
1405
|
}
|
|
1398
1406
|
|
|
1399
1407
|
/**
|