balebaazoo 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.en.md +61 -0
- package/README.md +70 -0
- package/dist/index.cjs +1047 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +860 -0
- package/dist/index.d.ts +860 -0
- package/dist/index.js +1015 -0
- package/dist/index.js.map +1 -0
- package/package.json +80 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1047 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var promises = require('fs/promises');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var stream = require('stream');
|
|
7
|
+
|
|
8
|
+
// src/errors.ts
|
|
9
|
+
var BaleError = class extends Error {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
this.name = "BaleError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var BaleAPIError = class extends BaleError {
|
|
16
|
+
errorCode;
|
|
17
|
+
description;
|
|
18
|
+
parameters;
|
|
19
|
+
constructor(errorCode, description, parameters) {
|
|
20
|
+
super(`Bale API error ${errorCode}: ${description}`);
|
|
21
|
+
this.name = "BaleAPIError";
|
|
22
|
+
this.errorCode = errorCode;
|
|
23
|
+
this.description = description;
|
|
24
|
+
this.parameters = parameters;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var BaleNetworkError = class extends BaleError {
|
|
28
|
+
constructor(message, options) {
|
|
29
|
+
super(message, options);
|
|
30
|
+
this.name = "BaleNetworkError";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var InputFile = class _InputFile {
|
|
34
|
+
source;
|
|
35
|
+
filename;
|
|
36
|
+
constructor(source, filename) {
|
|
37
|
+
this.source = source;
|
|
38
|
+
this.filename = filename ?? inferFilename(source);
|
|
39
|
+
}
|
|
40
|
+
static fromPath(path$1, filename) {
|
|
41
|
+
return new _InputFile(fs.createReadStream(path$1), filename ?? path.basename(path$1));
|
|
42
|
+
}
|
|
43
|
+
async toBlob() {
|
|
44
|
+
if (this.source instanceof Blob) {
|
|
45
|
+
return this.source;
|
|
46
|
+
}
|
|
47
|
+
if (typeof this.source === "string") {
|
|
48
|
+
if (this.source.startsWith("http://") || this.source.startsWith("https://")) {
|
|
49
|
+
throw new Error("URL sources cannot be converted to Blob for upload");
|
|
50
|
+
}
|
|
51
|
+
return new Blob([this.source]);
|
|
52
|
+
}
|
|
53
|
+
if (Buffer.isBuffer(this.source) || this.source instanceof Uint8Array) {
|
|
54
|
+
const bytes = Buffer.isBuffer(this.source) ? this.source : Buffer.from(this.source);
|
|
55
|
+
return new Blob([bytes]);
|
|
56
|
+
}
|
|
57
|
+
if (this.source instanceof stream.Readable) {
|
|
58
|
+
const chunks = [];
|
|
59
|
+
for await (const chunk of this.source) {
|
|
60
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
61
|
+
}
|
|
62
|
+
return new Blob(chunks);
|
|
63
|
+
}
|
|
64
|
+
if (this.source instanceof ReadableStream) {
|
|
65
|
+
const reader = this.source.getReader();
|
|
66
|
+
const chunks = [];
|
|
67
|
+
while (true) {
|
|
68
|
+
const { done, value } = await reader.read();
|
|
69
|
+
if (done) break;
|
|
70
|
+
if (value) chunks.push(value);
|
|
71
|
+
}
|
|
72
|
+
return new Blob(chunks);
|
|
73
|
+
}
|
|
74
|
+
throw new Error("Unsupported InputFile source");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
function inferFilename(source) {
|
|
78
|
+
if (typeof source === "string") {
|
|
79
|
+
if (source.includes("/") || source.includes("\\")) {
|
|
80
|
+
return path.basename(source);
|
|
81
|
+
}
|
|
82
|
+
return "file.bin";
|
|
83
|
+
}
|
|
84
|
+
if (source instanceof stream.Readable && "path" in source) {
|
|
85
|
+
const path$1 = source.path;
|
|
86
|
+
if (typeof path$1 === "string") {
|
|
87
|
+
return path.basename(path$1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return "file.bin";
|
|
91
|
+
}
|
|
92
|
+
async function isFilePath(source) {
|
|
93
|
+
if (typeof source !== "string") return false;
|
|
94
|
+
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const info = await promises.stat(source);
|
|
99
|
+
return info.isFile();
|
|
100
|
+
} catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/api/client.ts
|
|
106
|
+
var DEFAULT_API_BASE = "https://tapi.bale.ai";
|
|
107
|
+
var Api = class {
|
|
108
|
+
token;
|
|
109
|
+
baseUrl;
|
|
110
|
+
fetchFn;
|
|
111
|
+
maxRetries;
|
|
112
|
+
retryDelayMs;
|
|
113
|
+
constructor(options) {
|
|
114
|
+
this.token = options.token;
|
|
115
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_API_BASE;
|
|
116
|
+
this.fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
117
|
+
this.maxRetries = options.maxRetries ?? 3;
|
|
118
|
+
this.retryDelayMs = options.retryDelayMs ?? 500;
|
|
119
|
+
}
|
|
120
|
+
get fileBaseUrl() {
|
|
121
|
+
return `${this.baseUrl}/file/bot${this.token}`;
|
|
122
|
+
}
|
|
123
|
+
methodUrl(method) {
|
|
124
|
+
return `${this.baseUrl}/bot${this.token}/${method}`;
|
|
125
|
+
}
|
|
126
|
+
async call(method, params) {
|
|
127
|
+
let attempt = 0;
|
|
128
|
+
while (true) {
|
|
129
|
+
try {
|
|
130
|
+
return await this.invoke(method, params);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error instanceof BaleAPIError && error.errorCode === 429 && attempt < this.maxRetries) {
|
|
133
|
+
const retryAfter = (error.parameters?.retry_after ?? 1) * 1e3;
|
|
134
|
+
await sleep(retryAfter);
|
|
135
|
+
attempt++;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async invoke(method, params) {
|
|
143
|
+
const { body } = await this.prepareBody(params ?? {});
|
|
144
|
+
const headers = {};
|
|
145
|
+
if (!(body instanceof FormData)) {
|
|
146
|
+
headers["Content-Type"] = "application/json";
|
|
147
|
+
}
|
|
148
|
+
return this.request(method, {
|
|
149
|
+
method: "POST",
|
|
150
|
+
headers,
|
|
151
|
+
body: body instanceof FormData ? body : JSON.stringify(body ?? {})
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async downloadFile(filePath) {
|
|
155
|
+
const url = `${this.fileBaseUrl}/${filePath}`;
|
|
156
|
+
const response = await this.fetchWithRetry(url, { method: "GET" });
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
throw new BaleNetworkError(
|
|
159
|
+
`Failed to download file: HTTP ${response.status}`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return response.arrayBuffer();
|
|
163
|
+
}
|
|
164
|
+
async prepareBody(params) {
|
|
165
|
+
const entries = Object.entries(params).filter(([, value]) => value !== void 0);
|
|
166
|
+
const fileEntries = [];
|
|
167
|
+
for (const [key, value] of entries) {
|
|
168
|
+
if (value instanceof InputFile) {
|
|
169
|
+
fileEntries.push([key, value]);
|
|
170
|
+
} else if (typeof value === "string" && await isFilePath(value)) {
|
|
171
|
+
fileEntries.push([key, InputFile.fromPath(value)]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (fileEntries.length === 0) {
|
|
175
|
+
const jsonBody = {};
|
|
176
|
+
for (const [key, value] of entries) {
|
|
177
|
+
jsonBody[key] = serializeValue(value);
|
|
178
|
+
}
|
|
179
|
+
return { body: jsonBody, isMultipart: false };
|
|
180
|
+
}
|
|
181
|
+
const formData = new FormData();
|
|
182
|
+
for (const [key, value] of entries) {
|
|
183
|
+
if (value instanceof InputFile || typeof value === "string" && await isFilePath(value)) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
appendFormValue(formData, key, value);
|
|
187
|
+
}
|
|
188
|
+
for (const [key, file] of fileEntries) {
|
|
189
|
+
const blob = await file.toBlob();
|
|
190
|
+
formData.append(key, blob, file.filename);
|
|
191
|
+
}
|
|
192
|
+
return { body: formData, isMultipart: true };
|
|
193
|
+
}
|
|
194
|
+
async request(method, init) {
|
|
195
|
+
const response = await this.fetchWithRetry(this.methodUrl(method), init);
|
|
196
|
+
const payload = await response.json();
|
|
197
|
+
if (!payload.ok) {
|
|
198
|
+
throw new BaleAPIError(
|
|
199
|
+
payload.error_code ?? response.status,
|
|
200
|
+
payload.description ?? "Unknown API error",
|
|
201
|
+
payload.parameters
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return payload.result;
|
|
205
|
+
}
|
|
206
|
+
async fetchWithRetry(url, init) {
|
|
207
|
+
let attempt = 0;
|
|
208
|
+
let lastError;
|
|
209
|
+
while (attempt <= this.maxRetries) {
|
|
210
|
+
try {
|
|
211
|
+
const response = await this.fetchFn(url, init);
|
|
212
|
+
if (response.status === 429) {
|
|
213
|
+
const retryAfter = Number(response.headers.get("retry-after") ?? "1");
|
|
214
|
+
await sleep(retryAfter * 1e3);
|
|
215
|
+
attempt++;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!response.ok && response.status >= 500 && attempt < this.maxRetries) {
|
|
219
|
+
await sleep(this.retryDelayMs * 2 ** attempt);
|
|
220
|
+
attempt++;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
return response;
|
|
224
|
+
} catch (error) {
|
|
225
|
+
lastError = error;
|
|
226
|
+
if (attempt >= this.maxRetries) {
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
await sleep(this.retryDelayMs * 2 ** attempt);
|
|
230
|
+
attempt++;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
throw new BaleNetworkError(
|
|
234
|
+
`Network request failed after ${this.maxRetries + 1} attempts`,
|
|
235
|
+
{ cause: lastError }
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
getMe() {
|
|
239
|
+
return this.call("getMe");
|
|
240
|
+
}
|
|
241
|
+
getUpdates(params) {
|
|
242
|
+
return this.call("getUpdates", asParams(params));
|
|
243
|
+
}
|
|
244
|
+
setWebhook(params) {
|
|
245
|
+
return this.call("setWebhook", asParams(params));
|
|
246
|
+
}
|
|
247
|
+
deleteWebhook() {
|
|
248
|
+
return this.call("deleteWebhook");
|
|
249
|
+
}
|
|
250
|
+
getWebhookInfo() {
|
|
251
|
+
return this.call("getWebhookInfo");
|
|
252
|
+
}
|
|
253
|
+
sendMessage(params) {
|
|
254
|
+
return this.call("sendMessage", asParams(params));
|
|
255
|
+
}
|
|
256
|
+
forwardMessage(params) {
|
|
257
|
+
return this.call("forwardMessage", asParams(params));
|
|
258
|
+
}
|
|
259
|
+
copyMessage(params) {
|
|
260
|
+
return this.call("copyMessage", asParams(params));
|
|
261
|
+
}
|
|
262
|
+
sendPhoto(params) {
|
|
263
|
+
return this.call("sendPhoto", asParams(params));
|
|
264
|
+
}
|
|
265
|
+
sendAudio(params) {
|
|
266
|
+
return this.call("sendAudio", asParams(params));
|
|
267
|
+
}
|
|
268
|
+
sendDocument(params) {
|
|
269
|
+
return this.call("sendDocument", asParams(params));
|
|
270
|
+
}
|
|
271
|
+
sendVideo(params) {
|
|
272
|
+
return this.call("sendVideo", asParams(params));
|
|
273
|
+
}
|
|
274
|
+
sendAnimation(params) {
|
|
275
|
+
return this.call("sendAnimation", asParams(params));
|
|
276
|
+
}
|
|
277
|
+
sendVoice(params) {
|
|
278
|
+
return this.call("sendVoice", asParams(params));
|
|
279
|
+
}
|
|
280
|
+
sendMediaGroup(params) {
|
|
281
|
+
return this.call("sendMediaGroup", {
|
|
282
|
+
...params,
|
|
283
|
+
media: JSON.stringify(params.media)
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
sendLocation(params) {
|
|
287
|
+
return this.call("sendLocation", asParams(params));
|
|
288
|
+
}
|
|
289
|
+
sendContact(params) {
|
|
290
|
+
return this.call("sendContact", asParams(params));
|
|
291
|
+
}
|
|
292
|
+
sendChatAction(params) {
|
|
293
|
+
return this.call("sendChatAction", asParams(params));
|
|
294
|
+
}
|
|
295
|
+
getFile(params) {
|
|
296
|
+
return this.call("getFile", asParams(params));
|
|
297
|
+
}
|
|
298
|
+
answerCallbackQuery(params) {
|
|
299
|
+
return this.call("answerCallbackQuery", asParams(params));
|
|
300
|
+
}
|
|
301
|
+
askReview(params) {
|
|
302
|
+
return this.call("askReview", asParams(params));
|
|
303
|
+
}
|
|
304
|
+
banChatMember(params) {
|
|
305
|
+
return this.call("banChatMember", asParams(params));
|
|
306
|
+
}
|
|
307
|
+
unbanChatMember(params) {
|
|
308
|
+
return this.call("unbanChatMember", asParams(params));
|
|
309
|
+
}
|
|
310
|
+
promoteChatMember(params) {
|
|
311
|
+
return this.call("promoteChatMember", asParams(params));
|
|
312
|
+
}
|
|
313
|
+
setChatPhoto(params) {
|
|
314
|
+
return this.call("setChatPhoto", asParams(params));
|
|
315
|
+
}
|
|
316
|
+
leaveChat(params) {
|
|
317
|
+
return this.call("leaveChat", asParams(params));
|
|
318
|
+
}
|
|
319
|
+
getChat(params) {
|
|
320
|
+
return this.call("getChat", asParams(params));
|
|
321
|
+
}
|
|
322
|
+
getChatAdministrators(params) {
|
|
323
|
+
return this.call("getChatAdministrators", asParams(params));
|
|
324
|
+
}
|
|
325
|
+
getChatMembersCount(params) {
|
|
326
|
+
return this.call("getChatMembersCount", asParams(params));
|
|
327
|
+
}
|
|
328
|
+
getChatMember(params) {
|
|
329
|
+
return this.call("getChatMember", asParams(params));
|
|
330
|
+
}
|
|
331
|
+
pinChatMessage(params) {
|
|
332
|
+
return this.call("pinChatMessage", asParams(params));
|
|
333
|
+
}
|
|
334
|
+
unPinChatMessage(params) {
|
|
335
|
+
return this.call("unPinChatMessage", asParams(params));
|
|
336
|
+
}
|
|
337
|
+
unpinAllChatMessages(params) {
|
|
338
|
+
return this.call("unpinAllChatMessages", asParams(params));
|
|
339
|
+
}
|
|
340
|
+
setChatTitle(params) {
|
|
341
|
+
return this.call("setChatTitle", asParams(params));
|
|
342
|
+
}
|
|
343
|
+
setChatDescription(params) {
|
|
344
|
+
return this.call("setChatDescription", asParams(params));
|
|
345
|
+
}
|
|
346
|
+
deleteChatPhoto(params) {
|
|
347
|
+
return this.call("deleteChatPhoto", asParams(params));
|
|
348
|
+
}
|
|
349
|
+
createChatInviteLink(params) {
|
|
350
|
+
return this.call("createChatInviteLink", asParams(params));
|
|
351
|
+
}
|
|
352
|
+
revokeChatInviteLink(params) {
|
|
353
|
+
return this.call("revokeChatInviteLink", asParams(params));
|
|
354
|
+
}
|
|
355
|
+
exportChatInviteLink(params) {
|
|
356
|
+
return this.call("exportChatInviteLink", asParams(params));
|
|
357
|
+
}
|
|
358
|
+
editMessageText(params) {
|
|
359
|
+
return this.call("editMessageText", asParams(params));
|
|
360
|
+
}
|
|
361
|
+
editMessageCaption(params) {
|
|
362
|
+
return this.call("editMessageCaption", asParams(params));
|
|
363
|
+
}
|
|
364
|
+
editMessageReplyMarkup(params) {
|
|
365
|
+
return this.call("editMessageReplyMarkup", asParams(params));
|
|
366
|
+
}
|
|
367
|
+
deleteMessage(params) {
|
|
368
|
+
return this.call("deleteMessage", asParams(params));
|
|
369
|
+
}
|
|
370
|
+
uploadStickerFile(params) {
|
|
371
|
+
return this.call("uploadStickerFile", asParams(params));
|
|
372
|
+
}
|
|
373
|
+
createNewStickerSet(params) {
|
|
374
|
+
return this.call("createNewStickerSet", {
|
|
375
|
+
...params,
|
|
376
|
+
sticker: JSON.stringify(params.sticker)
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
addStickerToSet(params) {
|
|
380
|
+
return this.call("addStickerToSet", {
|
|
381
|
+
...params,
|
|
382
|
+
sticker: JSON.stringify(params.sticker)
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
sendInvoice(params) {
|
|
386
|
+
return this.call("sendInvoice", {
|
|
387
|
+
...params,
|
|
388
|
+
prices: JSON.stringify(params.prices)
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
createInvoiceLink(params) {
|
|
392
|
+
return this.call("createInvoiceLink", {
|
|
393
|
+
...params,
|
|
394
|
+
prices: JSON.stringify(params.prices)
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
answerPreCheckoutQuery(params) {
|
|
398
|
+
return this.call("answerPreCheckoutQuery", asParams(params));
|
|
399
|
+
}
|
|
400
|
+
inquireTransaction(params) {
|
|
401
|
+
return this.call("inquireTransaction", asParams(params));
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
function asParams(params) {
|
|
405
|
+
return params;
|
|
406
|
+
}
|
|
407
|
+
function serializeValue(value) {
|
|
408
|
+
if (value === null || value === void 0) {
|
|
409
|
+
return value;
|
|
410
|
+
}
|
|
411
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
412
|
+
return value;
|
|
413
|
+
}
|
|
414
|
+
if (Array.isArray(value) || typeof value === "object") {
|
|
415
|
+
return JSON.stringify(value);
|
|
416
|
+
}
|
|
417
|
+
return value;
|
|
418
|
+
}
|
|
419
|
+
function appendFormValue(formData, key, value) {
|
|
420
|
+
if (value === void 0 || value === null) return;
|
|
421
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
422
|
+
formData.append(key, String(value));
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
formData.append(key, JSON.stringify(value));
|
|
426
|
+
}
|
|
427
|
+
function sleep(ms) {
|
|
428
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/middleware/types.ts
|
|
432
|
+
function isMiddlewareObject(value) {
|
|
433
|
+
return typeof value === "object" && value !== null && "middleware" in value && typeof value.middleware === "function";
|
|
434
|
+
}
|
|
435
|
+
function normalizeMiddleware(middleware) {
|
|
436
|
+
return isMiddlewareObject(middleware) ? middleware.middleware() : middleware;
|
|
437
|
+
}
|
|
438
|
+
async function runMiddleware(middleware, ctx) {
|
|
439
|
+
let index = -1;
|
|
440
|
+
async function dispatch(current) {
|
|
441
|
+
if (current <= index) {
|
|
442
|
+
throw new Error("next() called multiple times");
|
|
443
|
+
}
|
|
444
|
+
index = current;
|
|
445
|
+
const handler = middleware[current];
|
|
446
|
+
if (!handler) return;
|
|
447
|
+
await handler(ctx, () => dispatch(current + 1));
|
|
448
|
+
}
|
|
449
|
+
await dispatch(0);
|
|
450
|
+
}
|
|
451
|
+
function matchUpdate(update) {
|
|
452
|
+
const matches = [];
|
|
453
|
+
if (update.message) {
|
|
454
|
+
matches.push("message");
|
|
455
|
+
if (update.message.text !== void 0) matches.push("message:text");
|
|
456
|
+
if (update.message.photo) matches.push("message:photo");
|
|
457
|
+
if (update.message.document) matches.push("message:document");
|
|
458
|
+
if (update.message.voice) matches.push("message:voice");
|
|
459
|
+
if (update.message.audio) matches.push("message:audio");
|
|
460
|
+
if (update.message.video) matches.push("message:video");
|
|
461
|
+
if (update.message.location) matches.push("message:location");
|
|
462
|
+
if (update.message.contact) matches.push("message:contact");
|
|
463
|
+
if (update.message.sticker) matches.push("message:sticker");
|
|
464
|
+
if (update.message.successful_payment) {
|
|
465
|
+
matches.push("message:successful_payment");
|
|
466
|
+
}
|
|
467
|
+
if (update.message.web_app_data) matches.push("message:web_app_data");
|
|
468
|
+
if (update.message.text?.startsWith("/")) {
|
|
469
|
+
matches.push("message:command");
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (update.edited_message) {
|
|
473
|
+
matches.push("edited_message");
|
|
474
|
+
if (update.edited_message.text !== void 0) {
|
|
475
|
+
matches.push("edited_message:text");
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (update.callback_query) {
|
|
479
|
+
matches.push("callback_query");
|
|
480
|
+
if (update.callback_query.data !== void 0) {
|
|
481
|
+
matches.push("callback_query:data");
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (update.pre_checkout_query) {
|
|
485
|
+
matches.push("pre_checkout_query");
|
|
486
|
+
}
|
|
487
|
+
return matches;
|
|
488
|
+
}
|
|
489
|
+
function extractCommand(text) {
|
|
490
|
+
const match = text.trim().match(/^\/([a-zA-Z0-9_]+)(?:@[\w_]+)?(?:\s+([\s\S]*))?$/);
|
|
491
|
+
if (!match) return null;
|
|
492
|
+
return {
|
|
493
|
+
command: match[1].toLowerCase(),
|
|
494
|
+
args: match[2]?.trim() ?? ""
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// src/filters/query.ts
|
|
499
|
+
function matchesFilter(ctx, filter) {
|
|
500
|
+
const updateMatches = matchUpdate(ctx.update);
|
|
501
|
+
return updateMatches.includes(filter);
|
|
502
|
+
}
|
|
503
|
+
function matchesAnyFilter(ctx, filters) {
|
|
504
|
+
const updateMatches = matchUpdate(ctx.update);
|
|
505
|
+
return filters.some((filter) => updateMatches.includes(filter));
|
|
506
|
+
}
|
|
507
|
+
function matchesChatType(ctx, chatType) {
|
|
508
|
+
const chat = ctx.chat;
|
|
509
|
+
if (!chat) return false;
|
|
510
|
+
const types = Array.isArray(chatType) ? chatType : [chatType];
|
|
511
|
+
return types.includes(chat.type);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// src/composer.ts
|
|
515
|
+
var Composer = class _Composer {
|
|
516
|
+
handler;
|
|
517
|
+
registered = [];
|
|
518
|
+
constructor(...middleware) {
|
|
519
|
+
this.registered.push(...middleware.map(normalizeMiddleware));
|
|
520
|
+
this.handler = async (ctx, next) => {
|
|
521
|
+
await runMiddleware(this.registered, ctx);
|
|
522
|
+
await next();
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
middleware() {
|
|
526
|
+
return this.handler;
|
|
527
|
+
}
|
|
528
|
+
use(...middleware) {
|
|
529
|
+
this.registered.push(...middleware.map(normalizeMiddleware));
|
|
530
|
+
return this;
|
|
531
|
+
}
|
|
532
|
+
on(filter, ...middleware) {
|
|
533
|
+
const filters = Array.isArray(filter) ? filter : [filter];
|
|
534
|
+
return this.filter(
|
|
535
|
+
(ctx) => matchesAnyFilter(ctx, filters),
|
|
536
|
+
...middleware
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
filter(predicate, ...middleware) {
|
|
540
|
+
const composer = new _Composer();
|
|
541
|
+
this.registered.push(async (ctx, next) => {
|
|
542
|
+
const matches = await predicate(ctx);
|
|
543
|
+
if (!matches) {
|
|
544
|
+
await next();
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
await runMiddleware(
|
|
548
|
+
[...composer.registered, async (_ctx, innerNext) => innerNext()],
|
|
549
|
+
ctx
|
|
550
|
+
);
|
|
551
|
+
});
|
|
552
|
+
composer.registered.push(...middleware);
|
|
553
|
+
return this;
|
|
554
|
+
}
|
|
555
|
+
command(command, ...middleware) {
|
|
556
|
+
const commands = new Set(
|
|
557
|
+
(Array.isArray(command) ? command : [command]).map(
|
|
558
|
+
(value) => value.toLowerCase().replace(/^\//, "")
|
|
559
|
+
)
|
|
560
|
+
);
|
|
561
|
+
return this.filter((ctx) => {
|
|
562
|
+
const text = ctx.text;
|
|
563
|
+
if (!text) return false;
|
|
564
|
+
const parsed = extractCommand(text);
|
|
565
|
+
if (!parsed) return false;
|
|
566
|
+
return commands.has(parsed.command);
|
|
567
|
+
}, async (ctx) => {
|
|
568
|
+
const text = ctx.text;
|
|
569
|
+
if (text) {
|
|
570
|
+
const parsed = extractCommand(text);
|
|
571
|
+
if (parsed) {
|
|
572
|
+
Object.defineProperty(ctx, "match", {
|
|
573
|
+
value: [parsed.command, parsed.args],
|
|
574
|
+
writable: true,
|
|
575
|
+
configurable: true
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
await runMiddleware(middleware, ctx);
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
hears(pattern, ...middleware) {
|
|
583
|
+
const regex = typeof pattern === "string" ? new RegExp(`^${escapeRegex(pattern)}$`) : pattern;
|
|
584
|
+
return this.filter((ctx) => {
|
|
585
|
+
const text = ctx.text;
|
|
586
|
+
if (!text) return false;
|
|
587
|
+
return regex.test(text);
|
|
588
|
+
}, async (ctx) => {
|
|
589
|
+
const text = ctx.text;
|
|
590
|
+
if (text) {
|
|
591
|
+
const match = text.match(regex);
|
|
592
|
+
Object.defineProperty(ctx, "match", {
|
|
593
|
+
value: match,
|
|
594
|
+
writable: true,
|
|
595
|
+
configurable: true
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
await runMiddleware(middleware, ctx);
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
chatType(chatType, ...middleware) {
|
|
602
|
+
return this.filter(
|
|
603
|
+
(ctx) => matchesChatType(ctx, chatType),
|
|
604
|
+
...middleware
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
function escapeRegex(value) {
|
|
609
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// src/context.ts
|
|
613
|
+
var Context = class {
|
|
614
|
+
api;
|
|
615
|
+
update;
|
|
616
|
+
botInfo;
|
|
617
|
+
callbackQueryAnswered = false;
|
|
618
|
+
constructor(options) {
|
|
619
|
+
this.api = options.api;
|
|
620
|
+
this.update = options.update;
|
|
621
|
+
this.botInfo = options.botInfo;
|
|
622
|
+
}
|
|
623
|
+
get updateId() {
|
|
624
|
+
return this.update.update_id;
|
|
625
|
+
}
|
|
626
|
+
get message() {
|
|
627
|
+
return this.update.message ?? this.update.edited_message;
|
|
628
|
+
}
|
|
629
|
+
get editedMessage() {
|
|
630
|
+
return this.update.edited_message;
|
|
631
|
+
}
|
|
632
|
+
get callbackQuery() {
|
|
633
|
+
return this.update.callback_query;
|
|
634
|
+
}
|
|
635
|
+
get preCheckoutQuery() {
|
|
636
|
+
return this.update.pre_checkout_query;
|
|
637
|
+
}
|
|
638
|
+
get from() {
|
|
639
|
+
return this.message?.from ?? this.callbackQuery?.from ?? this.preCheckoutQuery?.from;
|
|
640
|
+
}
|
|
641
|
+
get chat() {
|
|
642
|
+
return this.message?.chat ?? this.callbackQuery?.message?.chat;
|
|
643
|
+
}
|
|
644
|
+
get chatId() {
|
|
645
|
+
return this.chat?.id;
|
|
646
|
+
}
|
|
647
|
+
get text() {
|
|
648
|
+
return this.message?.text;
|
|
649
|
+
}
|
|
650
|
+
get match() {
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
set match(value) {
|
|
654
|
+
Object.defineProperty(this, "match", {
|
|
655
|
+
value,
|
|
656
|
+
writable: true,
|
|
657
|
+
configurable: true
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
async reply(text, extra) {
|
|
661
|
+
const chatId = this.requireChatId();
|
|
662
|
+
return this.api.sendMessage({ chat_id: chatId, text, ...extra });
|
|
663
|
+
}
|
|
664
|
+
async replyWithPhoto(photo, extra) {
|
|
665
|
+
const chatId = this.requireChatId();
|
|
666
|
+
return this.api.sendPhoto({ chat_id: chatId, photo, ...extra });
|
|
667
|
+
}
|
|
668
|
+
async replyWithAudio(audio, extra) {
|
|
669
|
+
const chatId = this.requireChatId();
|
|
670
|
+
return this.api.sendAudio({ chat_id: chatId, audio, ...extra });
|
|
671
|
+
}
|
|
672
|
+
async replyWithDocument(document, extra) {
|
|
673
|
+
const chatId = this.requireChatId();
|
|
674
|
+
return this.api.sendDocument({ chat_id: chatId, document, ...extra });
|
|
675
|
+
}
|
|
676
|
+
async replyWithVideo(video, extra) {
|
|
677
|
+
const chatId = this.requireChatId();
|
|
678
|
+
return this.api.sendVideo({ chat_id: chatId, video, ...extra });
|
|
679
|
+
}
|
|
680
|
+
async replyWithAnimation(animation, extra) {
|
|
681
|
+
const chatId = this.requireChatId();
|
|
682
|
+
return this.api.sendAnimation({ chat_id: chatId, animation, ...extra });
|
|
683
|
+
}
|
|
684
|
+
async replyWithVoice(voice, extra) {
|
|
685
|
+
const chatId = this.requireChatId();
|
|
686
|
+
return this.api.sendVoice({ chat_id: chatId, voice, ...extra });
|
|
687
|
+
}
|
|
688
|
+
async replyWithLocation(latitude, longitude, extra) {
|
|
689
|
+
const chatId = this.requireChatId();
|
|
690
|
+
return this.api.sendLocation({
|
|
691
|
+
chat_id: chatId,
|
|
692
|
+
latitude,
|
|
693
|
+
longitude,
|
|
694
|
+
...extra
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
async replyWithContact(phoneNumber, firstName, extra) {
|
|
698
|
+
const chatId = this.requireChatId();
|
|
699
|
+
return this.api.sendContact({
|
|
700
|
+
chat_id: chatId,
|
|
701
|
+
phone_number: phoneNumber,
|
|
702
|
+
first_name: firstName,
|
|
703
|
+
...extra
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
async replyWithInvoice(params) {
|
|
707
|
+
const chatId = this.requireChatId();
|
|
708
|
+
return this.api.sendInvoice({ chat_id: chatId, ...params });
|
|
709
|
+
}
|
|
710
|
+
async sendChatAction(action) {
|
|
711
|
+
const chatId = this.requireChatId();
|
|
712
|
+
return this.api.sendChatAction({ chat_id: chatId, action });
|
|
713
|
+
}
|
|
714
|
+
async answerCallbackQuery(params) {
|
|
715
|
+
const callbackQuery = this.callbackQuery;
|
|
716
|
+
if (!callbackQuery) {
|
|
717
|
+
throw new Error("No callback query in context");
|
|
718
|
+
}
|
|
719
|
+
if (callbackQuery.id.startsWith("1")) {
|
|
720
|
+
console.warn(
|
|
721
|
+
"[balebaazoo] callback_query_id starts with '1' \u2014 client may not support answerCallbackQuery"
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
this.callbackQueryAnswered = true;
|
|
725
|
+
return this.api.answerCallbackQuery({
|
|
726
|
+
callback_query_id: callbackQuery.id,
|
|
727
|
+
...params
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
async answerPreCheckoutQuery(params) {
|
|
731
|
+
const query = this.preCheckoutQuery;
|
|
732
|
+
if (!query) {
|
|
733
|
+
throw new Error("No pre_checkout_query in context");
|
|
734
|
+
}
|
|
735
|
+
return this.api.answerPreCheckoutQuery({
|
|
736
|
+
pre_checkout_query_id: query.id,
|
|
737
|
+
...params
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
async askReview(userId, delaySeconds) {
|
|
741
|
+
return this.api.askReview({ user_id: userId, delay_seconds: delaySeconds });
|
|
742
|
+
}
|
|
743
|
+
async inquireTransaction(params) {
|
|
744
|
+
return this.api.inquireTransaction(params);
|
|
745
|
+
}
|
|
746
|
+
async downloadFile(fileId) {
|
|
747
|
+
const file = await this.api.getFile({ file_id: fileId });
|
|
748
|
+
if (!file.file_path) {
|
|
749
|
+
throw new Error("File path not available");
|
|
750
|
+
}
|
|
751
|
+
return this.api.downloadFile(file.file_path);
|
|
752
|
+
}
|
|
753
|
+
async downloadToBuffer(fileId) {
|
|
754
|
+
const data = await this.downloadFile(fileId);
|
|
755
|
+
return Buffer.from(data);
|
|
756
|
+
}
|
|
757
|
+
requireChatId() {
|
|
758
|
+
const chatId = this.chatId;
|
|
759
|
+
if (chatId === void 0) {
|
|
760
|
+
throw new Error("No chat_id available in context");
|
|
761
|
+
}
|
|
762
|
+
return chatId;
|
|
763
|
+
}
|
|
764
|
+
requireFrom() {
|
|
765
|
+
const from = this.from;
|
|
766
|
+
if (!from) {
|
|
767
|
+
throw new Error("No user available in context");
|
|
768
|
+
}
|
|
769
|
+
return from;
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
|
|
773
|
+
// src/middleware/auto-answer-callback.ts
|
|
774
|
+
function autoAnswerCallback() {
|
|
775
|
+
return async (ctx, next) => {
|
|
776
|
+
try {
|
|
777
|
+
await next();
|
|
778
|
+
} finally {
|
|
779
|
+
if (ctx.callbackQuery && !ctx.callbackQueryAnswered) {
|
|
780
|
+
await ctx.answerCallbackQuery().catch(() => void 0);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
function errorHandler(onError) {
|
|
786
|
+
return async (ctx, next) => {
|
|
787
|
+
try {
|
|
788
|
+
await next();
|
|
789
|
+
} catch (error) {
|
|
790
|
+
await onError(error, ctx);
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// src/runner/polling.ts
|
|
796
|
+
var PollingRunner = class {
|
|
797
|
+
running = false;
|
|
798
|
+
abortController;
|
|
799
|
+
offset = 0;
|
|
800
|
+
async start(bot, options = {}) {
|
|
801
|
+
if (this.running) {
|
|
802
|
+
throw new Error("Polling is already running");
|
|
803
|
+
}
|
|
804
|
+
this.running = true;
|
|
805
|
+
this.abortController = new AbortController();
|
|
806
|
+
const signal = options.signal ?? this.abortController.signal;
|
|
807
|
+
const onError = options.onError ?? ((error) => {
|
|
808
|
+
console.error("[balebaazoo] polling error:", error);
|
|
809
|
+
});
|
|
810
|
+
while (this.running && !signal.aborted) {
|
|
811
|
+
try {
|
|
812
|
+
const updates = await bot.api.getUpdates({
|
|
813
|
+
offset: this.offset,
|
|
814
|
+
limit: options.limit ?? 100,
|
|
815
|
+
timeout: options.timeout ?? 30,
|
|
816
|
+
allowed_updates: options.allowedUpdates
|
|
817
|
+
});
|
|
818
|
+
for (const update of updates) {
|
|
819
|
+
this.offset = update.update_id + 1;
|
|
820
|
+
try {
|
|
821
|
+
await bot.handleUpdate(update);
|
|
822
|
+
} catch (error) {
|
|
823
|
+
onError(error);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
if (updates.length === 0 && signal.aborted) {
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
} catch (error) {
|
|
830
|
+
if (signal.aborted) break;
|
|
831
|
+
onError(error);
|
|
832
|
+
await sleep2(1e3);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
async stop() {
|
|
837
|
+
this.running = false;
|
|
838
|
+
this.abortController?.abort();
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
function sleep2(ms) {
|
|
842
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
843
|
+
}
|
|
844
|
+
async function createWebhookHandler(bot, getUpdate, options = {}) {
|
|
845
|
+
await bot.init();
|
|
846
|
+
const maxBodyBytes = options.maxBodyBytes ?? 1024 * 1024;
|
|
847
|
+
return async (request) => {
|
|
848
|
+
if (request.method !== "POST") {
|
|
849
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
850
|
+
}
|
|
851
|
+
if (options.secretToken) {
|
|
852
|
+
const token = request.headers.get("x-telegram-bot-api-secret-token");
|
|
853
|
+
if (token !== options.secretToken) {
|
|
854
|
+
return new Response("Unauthorized", { status: 401 });
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
try {
|
|
858
|
+
const rawBody = await request.text();
|
|
859
|
+
if (rawBody.length > maxBodyBytes) {
|
|
860
|
+
return new Response("Payload Too Large", { status: 413 });
|
|
861
|
+
}
|
|
862
|
+
const syntheticRequest = new Request(request.url, {
|
|
863
|
+
method: "POST",
|
|
864
|
+
headers: request.headers,
|
|
865
|
+
body: rawBody
|
|
866
|
+
});
|
|
867
|
+
const update = await getUpdate(syntheticRequest);
|
|
868
|
+
await bot.handleUpdate(update);
|
|
869
|
+
return new Response("OK", { status: 200 });
|
|
870
|
+
} catch (error) {
|
|
871
|
+
console.error("[balebaazoo] webhook error:", error);
|
|
872
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
async function webhookFromJson(bot) {
|
|
877
|
+
return createWebhookHandler(bot, async (request) => {
|
|
878
|
+
return await request.json();
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/bot.ts
|
|
883
|
+
var Bot = class extends Composer {
|
|
884
|
+
api;
|
|
885
|
+
botInfo;
|
|
886
|
+
polling = new PollingRunner();
|
|
887
|
+
autoAnswer;
|
|
888
|
+
constructor(token, options = {}) {
|
|
889
|
+
const api = new Api({ token, ...options });
|
|
890
|
+
super();
|
|
891
|
+
this.api = api;
|
|
892
|
+
this.botInfo = options.botInfo;
|
|
893
|
+
this.autoAnswer = options.autoAnswerCallback ?? true;
|
|
894
|
+
if (this.autoAnswer) {
|
|
895
|
+
this.use(autoAnswerCallback());
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
async init() {
|
|
899
|
+
if (!this.botInfo) {
|
|
900
|
+
this.botInfo = await this.api.getMe();
|
|
901
|
+
}
|
|
902
|
+
return this.botInfo;
|
|
903
|
+
}
|
|
904
|
+
async handleUpdate(update) {
|
|
905
|
+
const ctx = this.createContext(update);
|
|
906
|
+
await this.middleware()(ctx, async () => void 0);
|
|
907
|
+
}
|
|
908
|
+
createContext(update) {
|
|
909
|
+
return new Context({
|
|
910
|
+
api: this.api,
|
|
911
|
+
update,
|
|
912
|
+
botInfo: this.botInfo
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
async start(options = {}) {
|
|
916
|
+
await this.init();
|
|
917
|
+
await this.polling.start(this, options);
|
|
918
|
+
}
|
|
919
|
+
async stop() {
|
|
920
|
+
await this.polling.stop();
|
|
921
|
+
}
|
|
922
|
+
webhookCallback() {
|
|
923
|
+
return async (update) => {
|
|
924
|
+
await this.handleUpdate(update);
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
use(...middleware) {
|
|
928
|
+
return super.use(...middleware);
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
// src/formatting/markdown.ts
|
|
933
|
+
var bold = (text) => ` *${text}* `;
|
|
934
|
+
var italic = (text) => ` _${text}_ `;
|
|
935
|
+
var link = (text, url) => `[${text}](${url})`;
|
|
936
|
+
var spoiler = (text, description) => `\`\`\`[${text}]${description}\`\`\``;
|
|
937
|
+
var md = {
|
|
938
|
+
bold,
|
|
939
|
+
italic,
|
|
940
|
+
link,
|
|
941
|
+
spoiler
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
// src/keyboard/inline.ts
|
|
945
|
+
var InlineKeyboard = class {
|
|
946
|
+
inline_keyboard;
|
|
947
|
+
constructor(rows = []) {
|
|
948
|
+
this.inline_keyboard = rows;
|
|
949
|
+
}
|
|
950
|
+
row(...buttons) {
|
|
951
|
+
this.inline_keyboard.push(buttons);
|
|
952
|
+
return this;
|
|
953
|
+
}
|
|
954
|
+
text(text, callbackData) {
|
|
955
|
+
return this.row({ text, callback_data: callbackData });
|
|
956
|
+
}
|
|
957
|
+
url(text, url) {
|
|
958
|
+
return this.row({ text, url });
|
|
959
|
+
}
|
|
960
|
+
webApp(text, webApp) {
|
|
961
|
+
return this.row({ text, web_app: webApp });
|
|
962
|
+
}
|
|
963
|
+
copyText(text, copyText) {
|
|
964
|
+
return this.row({ text, copy_text: copyText });
|
|
965
|
+
}
|
|
966
|
+
toJSON() {
|
|
967
|
+
return { inline_keyboard: this.inline_keyboard };
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
// src/keyboard/reply.ts
|
|
972
|
+
var ReplyKeyboard = class {
|
|
973
|
+
keyboard;
|
|
974
|
+
resize_keyboard;
|
|
975
|
+
one_time_keyboard;
|
|
976
|
+
selective;
|
|
977
|
+
constructor(rows = []) {
|
|
978
|
+
this.keyboard = rows;
|
|
979
|
+
}
|
|
980
|
+
row(...buttons) {
|
|
981
|
+
this.keyboard.push(buttons);
|
|
982
|
+
return this;
|
|
983
|
+
}
|
|
984
|
+
text(text) {
|
|
985
|
+
return this.row({ text });
|
|
986
|
+
}
|
|
987
|
+
webApp(text, webApp) {
|
|
988
|
+
return this.row({ text, web_app: webApp });
|
|
989
|
+
}
|
|
990
|
+
resized(value = true) {
|
|
991
|
+
this.resize_keyboard = value;
|
|
992
|
+
return this;
|
|
993
|
+
}
|
|
994
|
+
oneTime(value = true) {
|
|
995
|
+
this.one_time_keyboard = value;
|
|
996
|
+
return this;
|
|
997
|
+
}
|
|
998
|
+
onlySelective(value = true) {
|
|
999
|
+
this.selective = value;
|
|
1000
|
+
return this;
|
|
1001
|
+
}
|
|
1002
|
+
toJSON() {
|
|
1003
|
+
return {
|
|
1004
|
+
keyboard: this.keyboard,
|
|
1005
|
+
resize_keyboard: this.resize_keyboard,
|
|
1006
|
+
one_time_keyboard: this.one_time_keyboard,
|
|
1007
|
+
selective: this.selective
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
function removeKeyboard() {
|
|
1012
|
+
return { remove_keyboard: true };
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
exports.Api = Api;
|
|
1016
|
+
exports.BaleAPIError = BaleAPIError;
|
|
1017
|
+
exports.BaleError = BaleError;
|
|
1018
|
+
exports.BaleNetworkError = BaleNetworkError;
|
|
1019
|
+
exports.Bot = Bot;
|
|
1020
|
+
exports.Composer = Composer;
|
|
1021
|
+
exports.Context = Context;
|
|
1022
|
+
exports.DEFAULT_API_BASE = DEFAULT_API_BASE;
|
|
1023
|
+
exports.InlineKeyboard = InlineKeyboard;
|
|
1024
|
+
exports.InputFile = InputFile;
|
|
1025
|
+
exports.PollingRunner = PollingRunner;
|
|
1026
|
+
exports.ReplyKeyboard = ReplyKeyboard;
|
|
1027
|
+
exports.autoAnswerCallback = autoAnswerCallback;
|
|
1028
|
+
exports.bold = bold;
|
|
1029
|
+
exports.createWebhookHandler = createWebhookHandler;
|
|
1030
|
+
exports.errorHandler = errorHandler;
|
|
1031
|
+
exports.extractCommand = extractCommand;
|
|
1032
|
+
exports.isFilePath = isFilePath;
|
|
1033
|
+
exports.isMiddlewareObject = isMiddlewareObject;
|
|
1034
|
+
exports.italic = italic;
|
|
1035
|
+
exports.link = link;
|
|
1036
|
+
exports.matchUpdate = matchUpdate;
|
|
1037
|
+
exports.matchesAnyFilter = matchesAnyFilter;
|
|
1038
|
+
exports.matchesChatType = matchesChatType;
|
|
1039
|
+
exports.matchesFilter = matchesFilter;
|
|
1040
|
+
exports.md = md;
|
|
1041
|
+
exports.normalizeMiddleware = normalizeMiddleware;
|
|
1042
|
+
exports.removeKeyboard = removeKeyboard;
|
|
1043
|
+
exports.runMiddleware = runMiddleware;
|
|
1044
|
+
exports.spoiler = spoiler;
|
|
1045
|
+
exports.webhookFromJson = webhookFromJson;
|
|
1046
|
+
//# sourceMappingURL=index.cjs.map
|
|
1047
|
+
//# sourceMappingURL=index.cjs.map
|