@mtkruto/node 0.77.2 → 0.78.1
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/esm/0_errors.d.ts +1 -0
- package/esm/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +5 -0
- package/esm/3_errors.d.ts +6 -0
- package/esm/3_errors.d.ts.map +1 -1
- package/esm/3_errors.js +6 -0
- package/esm/3_types.d.ts +3 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +3 -0
- package/esm/4_constants.d.ts +1 -0
- package/esm/4_constants.d.ts.map +1 -1
- package/esm/4_constants.js +2 -0
- package/esm/5_client.d.ts +6 -1
- package/esm/5_client.d.ts.map +1 -1
- package/esm/5_client.js +6 -1
- package/esm/_dnt.polyfills.d.ts +13 -13
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +11 -11
- package/esm/client/0_worker_request.d.ts +26 -0
- package/esm/client/0_worker_request.d.ts.map +1 -0
- package/esm/client/0_worker_request.js +20 -0
- package/esm/client/0_worker_response.d.ts +39 -0
- package/esm/client/0_worker_response.d.ts.map +1 -0
- package/esm/client/0_worker_response.js +20 -0
- package/esm/client/1_client_generic.d.ts +1602 -0
- package/esm/client/1_client_generic.d.ts.map +1 -0
- package/esm/client/1_client_generic.js +24 -0
- package/esm/client/2_account_manager.d.ts +6 -1
- package/esm/client/2_account_manager.d.ts.map +1 -1
- package/esm/client/2_account_manager.js +84 -0
- package/esm/client/2_context.d.ts +114 -0
- package/esm/client/2_context.d.ts.map +1 -0
- package/esm/client/2_context.js +453 -0
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +13 -6
- package/esm/client/2_sign_in.d.ts +25 -0
- package/esm/client/2_sign_in.d.ts.map +1 -0
- package/esm/client/2_sign_in.js +114 -0
- package/esm/client/{0_filters.d.ts → 3_filters.d.ts} +6 -3
- package/esm/client/3_filters.d.ts.map +1 -0
- package/esm/client/3_filters_test.d.ts.map +1 -0
- package/esm/client/{1_composer.d.ts → 4_composer.d.ts} +12 -11
- package/esm/client/4_composer.d.ts.map +1 -0
- package/esm/client/{1_composer.js → 4_composer.js} +17 -7
- package/esm/client/4_composer_test.d.ts.map +1 -0
- package/esm/client/5_client.d.ts +43 -179
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +141 -595
- package/esm/client/5_client_dispatcher.d.ts +1660 -0
- package/esm/client/5_client_dispatcher.d.ts.map +1 -0
- package/esm/client/5_client_dispatcher.js +2141 -0
- package/esm/client/6_client_worker.d.ts +27 -0
- package/esm/client/6_client_worker.d.ts.map +1 -0
- package/esm/client/6_client_worker.js +51 -0
- package/esm/types/0_bot_token_check_result.d.ts +29 -0
- package/esm/types/0_bot_token_check_result.d.ts.map +1 -0
- package/esm/types/0_bot_token_check_result.js +20 -0
- package/esm/types/0_code_check_result.d.ts +37 -0
- package/esm/types/0_code_check_result.d.ts.map +1 -0
- package/esm/types/0_code_check_result.js +20 -0
- package/esm/types/0_password_check_result.d.ts +33 -0
- package/esm/types/0_password_check_result.d.ts.map +1 -0
- package/esm/types/0_password_check_result.js +20 -0
- package/esm/types/1_chat_p.d.ts.map +1 -1
- package/esm/types/1_chat_p.js +2 -2
- package/esm/types/2_chat.d.ts +3 -3
- package/esm/types/2_chat.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/0_errors.d.ts +1 -0
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +5 -0
- package/script/3_errors.d.ts +6 -0
- package/script/3_errors.d.ts.map +1 -1
- package/script/3_errors.js +11 -3
- package/script/3_types.d.ts +3 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +3 -0
- package/script/4_constants.d.ts +1 -0
- package/script/4_constants.d.ts.map +1 -1
- package/script/4_constants.js +3 -1
- package/script/5_client.d.ts +6 -1
- package/script/5_client.d.ts.map +1 -1
- package/script/5_client.js +6 -1
- package/script/_dnt.polyfills.d.ts +13 -13
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +11 -11
- package/script/client/0_worker_request.d.ts +26 -0
- package/script/client/0_worker_request.d.ts.map +1 -0
- package/script/client/0_worker_request.js +21 -0
- package/script/client/0_worker_response.d.ts +39 -0
- package/script/client/0_worker_response.d.ts.map +1 -0
- package/script/client/0_worker_response.js +21 -0
- package/script/client/1_client_generic.d.ts +1602 -0
- package/script/client/1_client_generic.d.ts.map +1 -0
- package/script/client/1_client_generic.js +28 -0
- package/script/client/2_account_manager.d.ts +6 -1
- package/script/client/2_account_manager.d.ts.map +1 -1
- package/script/client/2_account_manager.js +84 -0
- package/script/client/2_context.d.ts +114 -0
- package/script/client/2_context.d.ts.map +1 -0
- package/script/client/2_context.js +457 -0
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +11 -4
- package/script/client/2_sign_in.d.ts +25 -0
- package/script/client/2_sign_in.d.ts.map +1 -0
- package/script/client/2_sign_in.js +118 -0
- package/script/client/{0_filters.d.ts → 3_filters.d.ts} +6 -3
- package/script/client/3_filters.d.ts.map +1 -0
- package/script/client/3_filters_test.d.ts.map +1 -0
- package/script/client/{1_composer.d.ts → 4_composer.d.ts} +12 -11
- package/script/client/4_composer.d.ts.map +1 -0
- package/script/client/{1_composer.js → 4_composer.js} +17 -7
- package/script/client/4_composer_test.d.ts.map +1 -0
- package/script/client/5_client.d.ts +43 -179
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +140 -594
- package/script/client/5_client_dispatcher.d.ts +1660 -0
- package/script/client/5_client_dispatcher.d.ts.map +1 -0
- package/script/client/5_client_dispatcher.js +2178 -0
- package/script/client/6_client_worker.d.ts +27 -0
- package/script/client/6_client_worker.d.ts.map +1 -0
- package/script/client/6_client_worker.js +55 -0
- package/script/types/0_bot_token_check_result.d.ts +29 -0
- package/script/types/0_bot_token_check_result.d.ts.map +1 -0
- package/script/types/0_bot_token_check_result.js +21 -0
- package/script/types/0_code_check_result.d.ts +37 -0
- package/script/types/0_code_check_result.d.ts.map +1 -0
- package/script/types/0_code_check_result.js +21 -0
- package/script/types/0_password_check_result.d.ts +33 -0
- package/script/types/0_password_check_result.d.ts.map +1 -0
- package/script/types/0_password_check_result.js +21 -0
- package/script/types/1_chat_p.d.ts.map +1 -1
- package/script/types/1_chat_p.js +2 -2
- package/script/types/2_chat.d.ts +3 -3
- package/script/types/2_chat.d.ts.map +1 -1
- package/esm/client/0_filters.d.ts.map +0 -1
- package/esm/client/0_filters_test.d.ts.map +0 -1
- package/esm/client/1_composer.d.ts.map +0 -1
- package/script/client/0_filters.d.ts.map +0 -1
- package/script/client/0_filters_test.d.ts.map +0 -1
- package/script/client/1_composer.d.ts.map +0 -1
- /package/esm/client/{0_filters.js → 3_filters.js} +0 -0
- /package/script/client/{0_filters.js → 3_filters.js} +0 -0
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.Client = exports.handleMigrationError = exports.restartAuth =
|
|
22
|
+
exports.Client = exports.handleMigrationError = exports.restartAuth = void 0;
|
|
23
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
24
24
|
const _0_errors_js_1 = require("../0_errors.js");
|
|
25
25
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
@@ -29,13 +29,10 @@ const _3_transport_js_1 = require("../3_transport.js");
|
|
|
29
29
|
const _3_types_js_1 = require("../3_types.js");
|
|
30
30
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
31
31
|
const _4_errors_js_1 = require("../4_errors.js");
|
|
32
|
-
const _4_errors_js_2 = require("../4_errors.js");
|
|
33
32
|
const _2_telegram_js_1 = require("../tl/2_telegram.js");
|
|
34
33
|
const _0_abortable_loop_js_1 = require("./0_abortable_loop.js");
|
|
35
|
-
const _0_password_js_1 = require("./0_password.js");
|
|
36
34
|
const _0_storage_operations_js_1 = require("./0_storage_operations.js");
|
|
37
35
|
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
38
|
-
const _1_composer_js_1 = require("./1_composer.js");
|
|
39
36
|
const _2_account_manager_js_1 = require("./2_account_manager.js");
|
|
40
37
|
const _2_bot_info_manager_js_1 = require("./2_bot_info_manager.js");
|
|
41
38
|
const _2_business_connection_manager_js_1 = require("./2_business_connection_manager.js");
|
|
@@ -44,6 +41,7 @@ const _2_file_manager_js_1 = require("./2_file_manager.js");
|
|
|
44
41
|
const _2_network_statistics_manager_js_1 = require("./2_network_statistics_manager.js");
|
|
45
42
|
const _2_payment_manager_js_1 = require("./2_payment_manager.js");
|
|
46
43
|
const _2_reaction_manager_js_1 = require("./2_reaction_manager.js");
|
|
44
|
+
const _2_sign_in_js_1 = require("./2_sign_in.js");
|
|
47
45
|
const _2_translations_manager_js_1 = require("./2_translations_manager.js");
|
|
48
46
|
const _2_update_manager_js_1 = require("./2_update_manager.js");
|
|
49
47
|
const _3_client_encrypted_pool_js_1 = require("./3_client_encrypted_pool.js");
|
|
@@ -52,19 +50,18 @@ const _3_video_chat_manager_js_1 = require("./3_video_chat_manager.js");
|
|
|
52
50
|
const _4_callback_query_manager_js_1 = require("./4_callback_query_manager.js");
|
|
53
51
|
const _4_chat_list_manager_js_1 = require("./4_chat_list_manager.js");
|
|
54
52
|
const _4_chat_manager_js_1 = require("./4_chat_manager.js");
|
|
53
|
+
const _4_composer_js_1 = require("./4_composer.js");
|
|
55
54
|
const _4_forum_manager_js_1 = require("./4_forum_manager.js");
|
|
56
55
|
const _4_gift_manager_js_1 = require("./4_gift_manager.js");
|
|
57
56
|
const _4_inline_query_manager_js_1 = require("./4_inline_query_manager.js");
|
|
58
57
|
const _4_link_preview_manager_js_1 = require("./4_link_preview_manager.js");
|
|
59
58
|
const _4_poll_manager_js_1 = require("./4_poll_manager.js");
|
|
60
59
|
const _4_story_manager_js_1 = require("./4_story_manager.js");
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
exports.Composer = Composer;
|
|
60
|
+
var _2_sign_in_js_2 = require("./2_sign_in.js");
|
|
61
|
+
Object.defineProperty(exports, "restartAuth", { enumerable: true, get: function () { return _2_sign_in_js_2.restartAuth; } });
|
|
64
62
|
function skipInvoke() {
|
|
65
63
|
return (_ctx, next) => next();
|
|
66
64
|
}
|
|
67
|
-
exports.restartAuth = Symbol("restartAuth");
|
|
68
65
|
exports.handleMigrationError = Symbol("handleMigrationError");
|
|
69
66
|
// global Client ID counter for logs
|
|
70
67
|
let id = 0;
|
|
@@ -73,7 +70,7 @@ const mustGetPeer = Symbol();
|
|
|
73
70
|
/**
|
|
74
71
|
* An MTKruto client.
|
|
75
72
|
*/
|
|
76
|
-
class Client extends Composer {
|
|
73
|
+
class Client extends _4_composer_js_1.Composer {
|
|
77
74
|
#clients = new Array();
|
|
78
75
|
#downloadPools = {};
|
|
79
76
|
#uploadPools = {};
|
|
@@ -187,9 +184,6 @@ class Client extends Composer {
|
|
|
187
184
|
this.systemVersion = params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION;
|
|
188
185
|
this.#publicKeys = params?.publicKeys;
|
|
189
186
|
this.#outgoingMessages = params?.outgoingMessages ?? false;
|
|
190
|
-
if (params?.prefixes) {
|
|
191
|
-
this.prefixes = params?.prefixes;
|
|
192
|
-
}
|
|
193
187
|
this.#guaranteeUpdateDelivery = params?.guaranteeUpdateDelivery ?? false;
|
|
194
188
|
const L = this.#L = (0, _1_utilities_js_1.getLogger)("Client").client(id++);
|
|
195
189
|
this.#LsignIn = L.branch("signIn");
|
|
@@ -320,432 +314,6 @@ class Client extends Composer {
|
|
|
320
314
|
get disconnected() {
|
|
321
315
|
return this.#client?.disconnected ?? true;
|
|
322
316
|
}
|
|
323
|
-
#constructContext = async (update) => {
|
|
324
|
-
const mustGetMsg = (ctx) => {
|
|
325
|
-
if (ctx.msg !== undefined) {
|
|
326
|
-
return { chatId: ctx.msg.chat.id, messageId: ctx.msg.id, businessConnectionId: ctx.msg.businessConnectionId, senderId: ctx.msg.from?.id, userId: ctx.msg.from?.id };
|
|
327
|
-
}
|
|
328
|
-
const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
|
|
329
|
-
if (reactions !== undefined) {
|
|
330
|
-
return { chatId: reactions.chatId, messageId: reactions.messageId };
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
(0, _0_deps_js_1.unreachable)();
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
const mustGetChatId = (ctx) => {
|
|
337
|
-
if (ctx.chat) {
|
|
338
|
-
return ctx.chat.id;
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
(0, _0_deps_js_1.unreachable)();
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
const mustGetUserId = (ctx) => {
|
|
345
|
-
if (ctx.msg?.from) {
|
|
346
|
-
return ctx.msg.from.id;
|
|
347
|
-
}
|
|
348
|
-
else if ("callbackQuery" in update) {
|
|
349
|
-
return update.callbackQuery.from.id;
|
|
350
|
-
}
|
|
351
|
-
else if ("chosenInlineResult" in update) {
|
|
352
|
-
return update.chosenInlineResult.from.id;
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
(0, _0_deps_js_1.unreachable)();
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
const mustGetInlineMsgId = () => {
|
|
359
|
-
if ("chosenInlineResult" in update) {
|
|
360
|
-
if (update.chosenInlineResult.inlineMessageId) {
|
|
361
|
-
return update.chosenInlineResult.inlineMessageId;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
else if ("callbackQuery" in update) {
|
|
365
|
-
if (update.callbackQuery.inlineMessageId) {
|
|
366
|
-
return update.callbackQuery.inlineMessageId;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
(0, _0_deps_js_1.unreachable)();
|
|
370
|
-
};
|
|
371
|
-
const getReplyTo = (quote, chatId, messageId) => {
|
|
372
|
-
if ("story" in update) {
|
|
373
|
-
return { chatId: update.story.chat.id, storyId: update.story.id };
|
|
374
|
-
}
|
|
375
|
-
const isPrivate = chatId > 0;
|
|
376
|
-
const shouldQuote = quote === undefined ? !isPrivate : quote;
|
|
377
|
-
return shouldQuote ? { messageId } : undefined;
|
|
378
|
-
};
|
|
379
|
-
if (this.#lastGetMe === null && !("connectionState" in update) && (!("authorizationState" in update) || ("authorizationState" in update && update.authorizationState.isAuthorized))) {
|
|
380
|
-
await this.#getMe();
|
|
381
|
-
}
|
|
382
|
-
const context = {
|
|
383
|
-
...update,
|
|
384
|
-
client: this,
|
|
385
|
-
get me() {
|
|
386
|
-
return this.client.#lastGetMe === null ? undefined : this.client.#lastGetMe;
|
|
387
|
-
},
|
|
388
|
-
get msg() {
|
|
389
|
-
return "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "scheduledMessage" in update ? update.scheduledMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
|
|
390
|
-
},
|
|
391
|
-
get chat() {
|
|
392
|
-
return this.msg?.chat ?? ("messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : "chatMember" in update ? update.chatMember.chat : "myChatMember" in update ? update.myChatMember.chat : "joinRequest" in update ? update.joinRequest.chat : "story" in update ? update.story.chat : undefined);
|
|
393
|
-
},
|
|
394
|
-
get from() {
|
|
395
|
-
const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "chatMember" in update ? update.chatMember.from : "myChatMember" in update ? update.myChatMember.from : "messageReactions" in update ? update.messageReactions.user : "preCheckoutQuery" in update ? update.preCheckoutQuery.from : "joinRequest" in update ? update.joinRequest.from : "businessConnection" in update ? update.businessConnection.user : "pollAnswer" in update ? update.pollAnswer.from : this.msg?.from;
|
|
396
|
-
return from;
|
|
397
|
-
},
|
|
398
|
-
toJSON() {
|
|
399
|
-
if ("update" in update) {
|
|
400
|
-
return { update: (0, _2_tl_js_1.toJSON)(update.update) };
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
return update;
|
|
404
|
-
}
|
|
405
|
-
},
|
|
406
|
-
reply(text, params) {
|
|
407
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
408
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
409
|
-
return this.client.sendMessage(chatId, text, { ...params, replyTo, businessConnectionId });
|
|
410
|
-
},
|
|
411
|
-
replyPoll(question, options, params) {
|
|
412
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
413
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
414
|
-
return this.client.sendPoll(chatId, question, options, { ...params, replyTo, businessConnectionId });
|
|
415
|
-
},
|
|
416
|
-
replyPhoto(photo, params) {
|
|
417
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
418
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
419
|
-
return this.client.sendPhoto(chatId, photo, { ...params, replyTo, businessConnectionId });
|
|
420
|
-
},
|
|
421
|
-
replyMediaGroup(media, params) {
|
|
422
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
423
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
424
|
-
return this.client.sendMediaGroup(chatId, media, { ...params, replyTo, businessConnectionId });
|
|
425
|
-
},
|
|
426
|
-
replyInvoice(title, description, payload, currency, prices, params) {
|
|
427
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
428
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
429
|
-
return this.client.sendInvoice(chatId, title, description, payload, currency, prices, { ...params, replyTo, businessConnectionId });
|
|
430
|
-
},
|
|
431
|
-
replyDocument(document, params) {
|
|
432
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
433
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
434
|
-
return this.client.sendDocument(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
435
|
-
},
|
|
436
|
-
replySticker(sticker, params) {
|
|
437
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
438
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
439
|
-
return this.client.sendSticker(chatId, sticker, { ...params, replyTo, businessConnectionId });
|
|
440
|
-
},
|
|
441
|
-
replyContact(firstName, number, params) {
|
|
442
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
443
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
444
|
-
return this.client.sendContact(chatId, firstName, number, { ...params, replyTo, businessConnectionId });
|
|
445
|
-
},
|
|
446
|
-
replyLocation(latitude, longitude, params) {
|
|
447
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
448
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
449
|
-
return this.client.sendLocation(chatId, latitude, longitude, { ...params, replyTo, businessConnectionId });
|
|
450
|
-
},
|
|
451
|
-
replyDice(params) {
|
|
452
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
453
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
454
|
-
return this.client.sendDice(chatId, { ...params, replyTo, businessConnectionId });
|
|
455
|
-
},
|
|
456
|
-
replyVenue(latitude, longitude, title, address, params) {
|
|
457
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
458
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
459
|
-
return this.client.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyTo, businessConnectionId });
|
|
460
|
-
},
|
|
461
|
-
replyVideo(video, params) {
|
|
462
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
463
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
464
|
-
return this.client.sendVideo(chatId, video, { ...params, replyTo, businessConnectionId });
|
|
465
|
-
},
|
|
466
|
-
replyAnimation(document, params) {
|
|
467
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
468
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
469
|
-
return this.client.sendAnimation(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
470
|
-
},
|
|
471
|
-
replyVoice(document, params) {
|
|
472
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
473
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
474
|
-
return this.client.sendVoice(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
475
|
-
},
|
|
476
|
-
replyAudio(document, params) {
|
|
477
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
478
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
479
|
-
return this.client.sendAudio(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
480
|
-
},
|
|
481
|
-
replyVideoNote(videoNote, params) {
|
|
482
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
483
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
484
|
-
return this.client.sendVideoNote(chatId, videoNote, { ...params, replyTo, businessConnectionId });
|
|
485
|
-
},
|
|
486
|
-
delete() {
|
|
487
|
-
const { chatId, messageId } = mustGetMsg(this);
|
|
488
|
-
return this.client.deleteMessage(chatId, messageId);
|
|
489
|
-
},
|
|
490
|
-
forward(to, params) {
|
|
491
|
-
const { chatId, messageId } = mustGetMsg(this);
|
|
492
|
-
return this.client.forwardMessage(chatId, to, messageId, params);
|
|
493
|
-
},
|
|
494
|
-
pin(params) {
|
|
495
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
496
|
-
return this.client.pinMessage(chatId, messageId, { ...params, businessConnectionId });
|
|
497
|
-
},
|
|
498
|
-
unpin() {
|
|
499
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
|
|
500
|
-
return this.client.unpinMessage(chatId, messageId, { businessConnectionId });
|
|
501
|
-
},
|
|
502
|
-
banSender(params) {
|
|
503
|
-
const { chatId, senderId } = mustGetMsg(this);
|
|
504
|
-
if (!senderId) {
|
|
505
|
-
(0, _0_deps_js_1.unreachable)();
|
|
506
|
-
}
|
|
507
|
-
return this.client.banChatMember(chatId, senderId, params);
|
|
508
|
-
},
|
|
509
|
-
kickSender() {
|
|
510
|
-
const { chatId, senderId } = mustGetMsg(this);
|
|
511
|
-
if (!senderId) {
|
|
512
|
-
(0, _0_deps_js_1.unreachable)();
|
|
513
|
-
}
|
|
514
|
-
return this.client.kickChatMember(chatId, senderId);
|
|
515
|
-
},
|
|
516
|
-
setSenderRights(params) {
|
|
517
|
-
const { chatId, senderId } = mustGetMsg(this);
|
|
518
|
-
if (!senderId) {
|
|
519
|
-
(0, _0_deps_js_1.unreachable)();
|
|
520
|
-
}
|
|
521
|
-
return this.client.setChatMemberRights(chatId, senderId, params);
|
|
522
|
-
},
|
|
523
|
-
getChatAdministrators() {
|
|
524
|
-
const chatId = mustGetChatId(this);
|
|
525
|
-
return this.client.getChatAdministrators(chatId);
|
|
526
|
-
},
|
|
527
|
-
react(reactions, params) {
|
|
528
|
-
const { chatId, messageId } = mustGetMsg(this);
|
|
529
|
-
return this.client.setReactions(chatId, messageId, reactions, params);
|
|
530
|
-
},
|
|
531
|
-
answerCallbackQuery(params) {
|
|
532
|
-
if (!("callbackQuery" in update)) {
|
|
533
|
-
(0, _0_deps_js_1.unreachable)();
|
|
534
|
-
}
|
|
535
|
-
return this.client.answerCallbackQuery(update.callbackQuery.id, params);
|
|
536
|
-
},
|
|
537
|
-
answerInlineQuery(results, params) {
|
|
538
|
-
if (!("inlineQuery" in update)) {
|
|
539
|
-
(0, _0_deps_js_1.unreachable)();
|
|
540
|
-
}
|
|
541
|
-
return this.client.answerInlineQuery(update.inlineQuery.id, results, params);
|
|
542
|
-
},
|
|
543
|
-
sendChatAction(chatAction, params) {
|
|
544
|
-
const chatId = mustGetChatId(this);
|
|
545
|
-
return this.client.sendChatAction(chatId, chatAction, params);
|
|
546
|
-
},
|
|
547
|
-
editInlineMessageText(text, params) {
|
|
548
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
549
|
-
return this.client.editInlineMessageText(inlineMessageId, text, params);
|
|
550
|
-
},
|
|
551
|
-
editInlineMessageMedia(media, params) {
|
|
552
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
553
|
-
return this.client.editInlineMessageMedia(inlineMessageId, media, params);
|
|
554
|
-
},
|
|
555
|
-
editInlineMessageCaption(params) {
|
|
556
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
557
|
-
return this.client.editInlineMessageCaption(inlineMessageId, params);
|
|
558
|
-
},
|
|
559
|
-
editInlineMessageLiveLocation(latitude, longitude, params) {
|
|
560
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
561
|
-
return this.client.editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params);
|
|
562
|
-
},
|
|
563
|
-
editInlineMessageReplyMarkup(params) {
|
|
564
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
565
|
-
return this.client.editInlineMessageReplyMarkup(inlineMessageId, params);
|
|
566
|
-
},
|
|
567
|
-
editMessageText(messageId, text, params) {
|
|
568
|
-
const chatId = mustGetChatId(this);
|
|
569
|
-
return this.client.editMessageText(chatId, messageId, text, params);
|
|
570
|
-
},
|
|
571
|
-
editMessageCaption(messageId, params) {
|
|
572
|
-
const chatId = mustGetChatId(this);
|
|
573
|
-
return this.client.editMessageCaption(chatId, messageId, params);
|
|
574
|
-
},
|
|
575
|
-
editMessageMedia(messageId, media, params) {
|
|
576
|
-
const chatId = mustGetChatId(this);
|
|
577
|
-
return this.client.editMessageMedia(chatId, messageId, media, params);
|
|
578
|
-
},
|
|
579
|
-
editMessageLiveLocation(messageId, latitude, longitude, params) {
|
|
580
|
-
const chatId = mustGetChatId(this);
|
|
581
|
-
return this.client.editMessageLiveLocation(chatId, messageId, latitude, longitude, params);
|
|
582
|
-
},
|
|
583
|
-
editMessageReplyMarkup(messageId, params) {
|
|
584
|
-
const chatId = mustGetChatId(this);
|
|
585
|
-
return this.client.editMessageReplyMarkup(chatId, messageId, params);
|
|
586
|
-
},
|
|
587
|
-
getMessage(messageId) {
|
|
588
|
-
const chatId = mustGetChatId(this);
|
|
589
|
-
return this.client.getMessage(chatId, messageId);
|
|
590
|
-
},
|
|
591
|
-
getMessages(messageIds) {
|
|
592
|
-
const chatId = mustGetChatId(this);
|
|
593
|
-
return this.client.getMessages(chatId, messageIds);
|
|
594
|
-
},
|
|
595
|
-
forwardMessage(to, messageId, params) {
|
|
596
|
-
const chatId = mustGetChatId(this);
|
|
597
|
-
return this.client.forwardMessage(chatId, to, messageId, params);
|
|
598
|
-
},
|
|
599
|
-
forwardMessages(to, messageIds, params) {
|
|
600
|
-
const chatId = mustGetChatId(this);
|
|
601
|
-
return this.client.forwardMessages(chatId, to, messageIds, params);
|
|
602
|
-
},
|
|
603
|
-
deleteMessage(messageId, params) {
|
|
604
|
-
const chatId = mustGetChatId(this);
|
|
605
|
-
return this.client.deleteMessage(chatId, messageId, params);
|
|
606
|
-
},
|
|
607
|
-
deleteMessages(messageIds, params) {
|
|
608
|
-
const chatId = mustGetChatId(this);
|
|
609
|
-
return this.client.deleteMessages(chatId, messageIds, params);
|
|
610
|
-
},
|
|
611
|
-
pinMessage(messageId, params) {
|
|
612
|
-
const chatId = mustGetChatId(this);
|
|
613
|
-
return this.client.pinMessage(chatId, messageId, params);
|
|
614
|
-
},
|
|
615
|
-
unpinMessage(messageId) {
|
|
616
|
-
const chatId = mustGetChatId(this);
|
|
617
|
-
return this.client.unpinMessage(chatId, messageId);
|
|
618
|
-
},
|
|
619
|
-
unpinMessages() {
|
|
620
|
-
const chatId = mustGetChatId(this);
|
|
621
|
-
return this.client.unpinMessages(chatId);
|
|
622
|
-
},
|
|
623
|
-
setAvailableReactions(availableReactions) {
|
|
624
|
-
const chatId = mustGetChatId(this);
|
|
625
|
-
return this.client.setAvailableReactions(chatId, availableReactions);
|
|
626
|
-
},
|
|
627
|
-
addReaction(messageId, reaction, params) {
|
|
628
|
-
const chatId = mustGetChatId(this);
|
|
629
|
-
return this.client.addReaction(chatId, messageId, reaction, params);
|
|
630
|
-
},
|
|
631
|
-
removeReaction(messageId, reaction) {
|
|
632
|
-
const chatId = mustGetChatId(this);
|
|
633
|
-
return this.client.removeReaction(chatId, messageId, reaction);
|
|
634
|
-
},
|
|
635
|
-
setReactions(messageId, reactions, params) {
|
|
636
|
-
const chatId = mustGetChatId(this);
|
|
637
|
-
return this.client.setReactions(chatId, messageId, reactions, params);
|
|
638
|
-
},
|
|
639
|
-
read() {
|
|
640
|
-
const { chatId, messageId } = mustGetMsg(this);
|
|
641
|
-
return this.client.readMessages(chatId, messageId);
|
|
642
|
-
},
|
|
643
|
-
setChatPhoto(photo, params) {
|
|
644
|
-
const chatId = mustGetChatId(this);
|
|
645
|
-
return this.client.setChatPhoto(chatId, photo, params);
|
|
646
|
-
},
|
|
647
|
-
deleteChatPhoto() {
|
|
648
|
-
const chatId = mustGetChatId(this);
|
|
649
|
-
return this.client.deleteChatPhoto(chatId);
|
|
650
|
-
},
|
|
651
|
-
banChatMember(memberId, params) {
|
|
652
|
-
const chatId = mustGetChatId(this);
|
|
653
|
-
return this.client.banChatMember(chatId, memberId, params);
|
|
654
|
-
},
|
|
655
|
-
unbanChatMember(memberId) {
|
|
656
|
-
const chatId = mustGetChatId(this);
|
|
657
|
-
return this.client.unbanChatMember(chatId, memberId);
|
|
658
|
-
},
|
|
659
|
-
kickChatMember(memberId) {
|
|
660
|
-
const chatId = mustGetChatId(this);
|
|
661
|
-
return this.client.kickChatMember(chatId, memberId);
|
|
662
|
-
},
|
|
663
|
-
setChatMemberRights(memberId, params) {
|
|
664
|
-
const chatId = mustGetChatId(this);
|
|
665
|
-
return this.client.setChatMemberRights(chatId, memberId, params);
|
|
666
|
-
},
|
|
667
|
-
promoteChatMember(userId, params) {
|
|
668
|
-
const chatId = mustGetChatId(this);
|
|
669
|
-
return this.client.promoteChatMember(chatId, userId, params);
|
|
670
|
-
},
|
|
671
|
-
deleteChatMemberMessages(userId) {
|
|
672
|
-
const chatId = mustGetChatId(this);
|
|
673
|
-
return this.client.deleteChatMemberMessages(chatId, userId);
|
|
674
|
-
},
|
|
675
|
-
searchMessages(params) {
|
|
676
|
-
const chatId = mustGetChatId(this);
|
|
677
|
-
params ??= {};
|
|
678
|
-
params.chatId = chatId;
|
|
679
|
-
return this.client.searchMessages(params);
|
|
680
|
-
},
|
|
681
|
-
setBoostsRequiredToCircumventRestrictions(boosts) {
|
|
682
|
-
const chatId = mustGetChatId(this);
|
|
683
|
-
return this.client.setBoostsRequiredToCircumventRestrictions(chatId, boosts);
|
|
684
|
-
},
|
|
685
|
-
createInviteLink(params) {
|
|
686
|
-
const chatId = mustGetChatId(this);
|
|
687
|
-
return this.client.createInviteLink(chatId, params);
|
|
688
|
-
},
|
|
689
|
-
getCreatedInviteLinks(params) {
|
|
690
|
-
const chatId = mustGetChatId(this);
|
|
691
|
-
return this.client.getCreatedInviteLinks(chatId, params);
|
|
692
|
-
},
|
|
693
|
-
leaveChat() {
|
|
694
|
-
const chatId = mustGetChatId(this);
|
|
695
|
-
return this.client.leaveChat(chatId);
|
|
696
|
-
},
|
|
697
|
-
blockUser() {
|
|
698
|
-
return this.client.blockUser(mustGetUserId(this));
|
|
699
|
-
},
|
|
700
|
-
unblockUser() {
|
|
701
|
-
return this.client.unblockUser(mustGetUserId(this));
|
|
702
|
-
},
|
|
703
|
-
getChatMember(userId) {
|
|
704
|
-
const chatId = mustGetChatId(this);
|
|
705
|
-
return this.client.getChatMember(chatId, userId);
|
|
706
|
-
},
|
|
707
|
-
getChatMembers(params) {
|
|
708
|
-
const chatId = mustGetChatId(this);
|
|
709
|
-
return this.client.getChatMembers(chatId, params);
|
|
710
|
-
},
|
|
711
|
-
setChatStickerSet(setName) {
|
|
712
|
-
const chatId = mustGetChatId(this);
|
|
713
|
-
return this.client.setChatStickerSet(chatId, setName);
|
|
714
|
-
},
|
|
715
|
-
deleteChatStickerSet() {
|
|
716
|
-
const chatId = mustGetChatId(this);
|
|
717
|
-
return this.client.deleteChatStickerSet(chatId);
|
|
718
|
-
},
|
|
719
|
-
getBusinessConnection() {
|
|
720
|
-
const { businessConnectionId } = mustGetMsg(this);
|
|
721
|
-
if (!businessConnectionId) {
|
|
722
|
-
(0, _0_deps_js_1.unreachable)();
|
|
723
|
-
}
|
|
724
|
-
return this.client.getBusinessConnection(businessConnectionId);
|
|
725
|
-
},
|
|
726
|
-
answerPreCheckoutQuery(ok, params) {
|
|
727
|
-
if (!("preCheckoutQuery" in update)) {
|
|
728
|
-
(0, _0_deps_js_1.unreachable)();
|
|
729
|
-
}
|
|
730
|
-
return this.client.answerPreCheckoutQuery(update.preCheckoutQuery.id, ok, params);
|
|
731
|
-
},
|
|
732
|
-
approveJoinRequest() {
|
|
733
|
-
const { chatId, userId } = mustGetMsg(this);
|
|
734
|
-
if (!userId) {
|
|
735
|
-
(0, _0_deps_js_1.unreachable)();
|
|
736
|
-
}
|
|
737
|
-
return this.client.approveJoinRequest(chatId, userId);
|
|
738
|
-
},
|
|
739
|
-
declineJoinRequest() {
|
|
740
|
-
const { chatId, userId } = mustGetMsg(this);
|
|
741
|
-
if (!userId) {
|
|
742
|
-
(0, _0_deps_js_1.unreachable)();
|
|
743
|
-
}
|
|
744
|
-
return this.client.declineJoinRequest(chatId, userId);
|
|
745
|
-
},
|
|
746
|
-
};
|
|
747
|
-
return (0, _1_utilities_js_1.cleanObject)(context);
|
|
748
|
-
};
|
|
749
317
|
#propagateConnectionState(connectionState) {
|
|
750
318
|
this.#queueHandleCtxUpdate({ connectionState });
|
|
751
319
|
this.#lastPropagatedConnectionState = connectionState;
|
|
@@ -909,172 +477,127 @@ class Client extends Composer {
|
|
|
909
477
|
}, (err) => {
|
|
910
478
|
this.#LstorageWriteLoop.error(err);
|
|
911
479
|
});
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
* Notes:
|
|
917
|
-
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
918
|
-
* 3. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
919
|
-
*/
|
|
920
|
-
async signIn(params) {
|
|
480
|
+
async #checkAuthorization() {
|
|
481
|
+
if (this.#lastGetMe) {
|
|
482
|
+
return this.#lastGetMe;
|
|
483
|
+
}
|
|
921
484
|
try {
|
|
922
|
-
await this.#updateManager.fetchState("
|
|
923
|
-
await this.#getMe();
|
|
485
|
+
await this.#updateManager.fetchState("#checkAuthorization");
|
|
486
|
+
const me = await this.#getMe();
|
|
924
487
|
await this.#propagateAuthorizationState(true);
|
|
925
|
-
(0, _1_utilities_js_1.drop)(this.#updateManager.recoverUpdateGap("
|
|
926
|
-
|
|
927
|
-
return;
|
|
488
|
+
(0, _1_utilities_js_1.drop)(this.#updateManager.recoverUpdateGap("#checkAuthorization"));
|
|
489
|
+
return me;
|
|
928
490
|
}
|
|
929
491
|
catch (err) {
|
|
930
492
|
if (!(err instanceof _4_errors_js_1.AuthKeyUnregistered) && !(err instanceof _4_errors_js_1.SessionRevoked)) {
|
|
931
493
|
throw err;
|
|
932
494
|
}
|
|
933
495
|
}
|
|
934
|
-
|
|
935
|
-
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Send a user verification code.
|
|
499
|
+
*
|
|
500
|
+
* @param phoneNumber The phone number to send the code to.
|
|
501
|
+
* @method ac
|
|
502
|
+
*/
|
|
503
|
+
async sendCode(phoneNumber) {
|
|
504
|
+
const me = await this.#checkAuthorization();
|
|
505
|
+
if (me) {
|
|
506
|
+
return;
|
|
936
507
|
}
|
|
937
|
-
|
|
938
|
-
|
|
508
|
+
try {
|
|
509
|
+
await this.#accountManager.sendCode(phoneNumber, this.#apiId, this.#apiHash);
|
|
939
510
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
511
|
+
catch (err) {
|
|
512
|
+
if (err instanceof _4_errors_js_1.Migrate) {
|
|
513
|
+
await this[exports.handleMigrationError](err);
|
|
514
|
+
await this.#accountManager.sendCode(phoneNumber, this.#apiId, this.#apiHash);
|
|
944
515
|
}
|
|
945
516
|
else {
|
|
946
|
-
|
|
517
|
+
throw err;
|
|
947
518
|
}
|
|
948
519
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Check if a code entered by the user was the same as the verification code.
|
|
523
|
+
*
|
|
524
|
+
* @param code A code entered by the user.
|
|
525
|
+
* @method ac
|
|
526
|
+
*/
|
|
527
|
+
async checkCode(code) {
|
|
528
|
+
const result = await this.#accountManager.checkCode(code);
|
|
529
|
+
if (result.type === "signed_in") {
|
|
530
|
+
await this.storage.auth.update((v) => {
|
|
531
|
+
v.userId = result.userId;
|
|
532
|
+
v.isBot = false;
|
|
533
|
+
});
|
|
534
|
+
this.#LsignIn.debug("signed in as user");
|
|
535
|
+
await this.#propagateAuthorizationState(true);
|
|
536
|
+
await this.#updateManager.fetchState("checkCode");
|
|
537
|
+
}
|
|
538
|
+
return result;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Get the user account password's hint.
|
|
542
|
+
*
|
|
543
|
+
* @method ac
|
|
544
|
+
*/
|
|
545
|
+
async getPasswordHint() {
|
|
546
|
+
return await this.#accountManager.getPasswordHint();
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Check whether a password entered by the user is the same as the account's one.
|
|
550
|
+
*
|
|
551
|
+
* @param password The password to check
|
|
552
|
+
* @returns The result of the check.
|
|
553
|
+
*/
|
|
554
|
+
async checkPassword(password) {
|
|
555
|
+
const result = await this.#accountManager.checkPassword(password);
|
|
556
|
+
if (result.type === "signed_in") {
|
|
557
|
+
await this.storage.auth.update((v) => {
|
|
558
|
+
v.userId = result.userId;
|
|
559
|
+
v.isBot = false;
|
|
560
|
+
});
|
|
561
|
+
await this.storage.commit(true);
|
|
562
|
+
this.#LsignIn.debug("signed in as user");
|
|
563
|
+
await this.#propagateAuthorizationState(true);
|
|
564
|
+
await this.#updateManager.fetchState("checkPassword");
|
|
565
|
+
}
|
|
566
|
+
return result;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Check whether a bot token is valid.
|
|
570
|
+
*
|
|
571
|
+
* @param password The password to check
|
|
572
|
+
* @returns The result of the check.
|
|
573
|
+
*/
|
|
574
|
+
async checkBotToken(botToken) {
|
|
575
|
+
const me = await this.#checkAuthorization();
|
|
576
|
+
if (me) {
|
|
577
|
+
return {
|
|
578
|
+
type: "signed_in",
|
|
579
|
+
userId: me.id,
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
while (true) {
|
|
583
|
+
try {
|
|
584
|
+
const result = await this.#accountManager.checkBotToken(botToken, this.#apiId, this.#apiHash);
|
|
585
|
+
if (result.type === "signed_in") {
|
|
954
586
|
await this.storage.auth.update((v) => {
|
|
955
|
-
v.userId =
|
|
587
|
+
v.userId = result.userId;
|
|
956
588
|
v.isBot = true;
|
|
957
589
|
});
|
|
958
590
|
await this.storage.commit(true);
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
if (err instanceof _4_errors_js_1.Migrate) {
|
|
963
|
-
await this[exports.handleMigrationError](err);
|
|
964
|
-
continue;
|
|
965
|
-
}
|
|
966
|
-
else {
|
|
967
|
-
throw err;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
this.#LsignIn.debug("authorized as bot");
|
|
972
|
-
await this.#propagateAuthorizationState(true);
|
|
973
|
-
await this.#updateManager.fetchState("authorize");
|
|
974
|
-
return;
|
|
975
|
-
}
|
|
976
|
-
auth: while (true) {
|
|
977
|
-
try {
|
|
978
|
-
let phone;
|
|
979
|
-
let sentCode;
|
|
980
|
-
while (true) {
|
|
981
|
-
try {
|
|
982
|
-
phone = typeof params.phone === "string" ? params.phone : await params.phone();
|
|
983
|
-
const sendCode = () => this.invoke({
|
|
984
|
-
_: "auth.sendCode",
|
|
985
|
-
phone_number: phone,
|
|
986
|
-
api_id: this.#apiId,
|
|
987
|
-
api_hash: this.#apiHash,
|
|
988
|
-
settings: { _: "codeSettings" },
|
|
989
|
-
}).then((v) => _2_tl_js_1.Api.as("auth.sentCode", v));
|
|
990
|
-
try {
|
|
991
|
-
sentCode = await sendCode();
|
|
992
|
-
}
|
|
993
|
-
catch (err) {
|
|
994
|
-
if (err instanceof _4_errors_js_1.Migrate) {
|
|
995
|
-
await this[exports.handleMigrationError](err);
|
|
996
|
-
sentCode = await sendCode();
|
|
997
|
-
}
|
|
998
|
-
else {
|
|
999
|
-
throw err;
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
break;
|
|
1003
|
-
}
|
|
1004
|
-
catch (err) {
|
|
1005
|
-
if (err instanceof _4_errors_js_1.PhoneNumberInvalid) {
|
|
1006
|
-
continue;
|
|
1007
|
-
}
|
|
1008
|
-
else {
|
|
1009
|
-
throw err;
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
this.#LsignIn.debug("verification code sent");
|
|
1014
|
-
let err;
|
|
1015
|
-
code: while (true) {
|
|
1016
|
-
const code = typeof params.code === "string" ? params.code : await params.code();
|
|
1017
|
-
try {
|
|
1018
|
-
const auth = await this.invoke({
|
|
1019
|
-
_: "auth.signIn",
|
|
1020
|
-
phone_number: phone,
|
|
1021
|
-
phone_code: code,
|
|
1022
|
-
phone_code_hash: sentCode.phone_code_hash,
|
|
1023
|
-
});
|
|
1024
|
-
await this.storage.auth.update((v) => {
|
|
1025
|
-
v.userId = Number(_2_tl_js_1.Api.as("auth.authorization", auth).user.id);
|
|
1026
|
-
v.isBot = false;
|
|
1027
|
-
});
|
|
1028
|
-
this.#LsignIn.debug("signed in as user");
|
|
1029
|
-
await this.#propagateAuthorizationState(true);
|
|
1030
|
-
await this.#updateManager.fetchState("signIn");
|
|
1031
|
-
return;
|
|
1032
|
-
}
|
|
1033
|
-
catch (err_) {
|
|
1034
|
-
if (err_ instanceof _4_errors_js_2.PhoneCodeInvalid) {
|
|
1035
|
-
continue code;
|
|
1036
|
-
}
|
|
1037
|
-
else {
|
|
1038
|
-
err = err_;
|
|
1039
|
-
break code;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
if (!(err instanceof _4_errors_js_1.SessionPasswordNeeded)) {
|
|
1044
|
-
throw err;
|
|
1045
|
-
}
|
|
1046
|
-
password: while (true) {
|
|
1047
|
-
const ap = await this.invoke({ _: "account.getPassword" });
|
|
1048
|
-
if (!(_2_tl_js_1.Api.is("passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow", ap.current_algo))) {
|
|
1049
|
-
throw new Error(`Handling ${ap.current_algo?._} not implemented`);
|
|
1050
|
-
}
|
|
1051
|
-
try {
|
|
1052
|
-
const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
|
|
1053
|
-
const input = await (0, _0_password_js_1.checkPassword)(password, ap);
|
|
1054
|
-
const auth = await this.invoke({ _: "auth.checkPassword", password: input });
|
|
1055
|
-
await this.storage.auth.update((v) => {
|
|
1056
|
-
v.userId = Number(_2_tl_js_1.Api.as("auth.authorization", auth).user.id);
|
|
1057
|
-
v.isBot = false;
|
|
1058
|
-
});
|
|
1059
|
-
await this.storage.commit(true);
|
|
1060
|
-
this.#LsignIn.debug("signed in as user");
|
|
1061
|
-
await this.#propagateAuthorizationState(true);
|
|
1062
|
-
await this.#updateManager.fetchState("signIn");
|
|
1063
|
-
return;
|
|
1064
|
-
}
|
|
1065
|
-
catch (err) {
|
|
1066
|
-
if (err instanceof _4_errors_js_1.PasswordHashInvalid) {
|
|
1067
|
-
continue password;
|
|
1068
|
-
}
|
|
1069
|
-
else {
|
|
1070
|
-
throw err;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
591
|
+
this.#LsignIn.debug("signed in as bot");
|
|
592
|
+
await this.#propagateAuthorizationState(true);
|
|
593
|
+
await this.#updateManager.fetchState("checkBotToken");
|
|
1073
594
|
}
|
|
595
|
+
return result;
|
|
1074
596
|
}
|
|
1075
597
|
catch (err) {
|
|
1076
|
-
if (err
|
|
1077
|
-
|
|
598
|
+
if (err instanceof _4_errors_js_1.Migrate) {
|
|
599
|
+
await this[exports.handleMigrationError](err);
|
|
600
|
+
continue;
|
|
1078
601
|
}
|
|
1079
602
|
else {
|
|
1080
603
|
throw err;
|
|
@@ -1082,6 +605,17 @@ class Client extends Composer {
|
|
|
1082
605
|
}
|
|
1083
606
|
}
|
|
1084
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Signs in using the provided parameters if not already signed in.
|
|
610
|
+
* If no parameters are provided, the credentials will be prompted in runtime.
|
|
611
|
+
*
|
|
612
|
+
* Notes:
|
|
613
|
+
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
614
|
+
* 3. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
615
|
+
*/
|
|
616
|
+
async signIn(params) {
|
|
617
|
+
await (0, _2_sign_in_js_1.signIn)(this, this.#LsignIn, params);
|
|
618
|
+
}
|
|
1085
619
|
async signOut() {
|
|
1086
620
|
try {
|
|
1087
621
|
await Promise.all([
|
|
@@ -1473,7 +1007,7 @@ class Client extends Composer {
|
|
|
1473
1007
|
return;
|
|
1474
1008
|
}
|
|
1475
1009
|
try {
|
|
1476
|
-
await this.
|
|
1010
|
+
await this.handleUpdate(this, update);
|
|
1477
1011
|
}
|
|
1478
1012
|
catch (err) {
|
|
1479
1013
|
this.#L.error("Failed to handle update:", err);
|
|
@@ -1589,11 +1123,22 @@ class Client extends Composer {
|
|
|
1589
1123
|
return this.#lastGetMe;
|
|
1590
1124
|
}
|
|
1591
1125
|
else {
|
|
1592
|
-
const user = await this
|
|
1126
|
+
const user = await this.#getMeInner();
|
|
1593
1127
|
this.#lastGetMe = user;
|
|
1594
1128
|
return user;
|
|
1595
1129
|
}
|
|
1596
1130
|
}
|
|
1131
|
+
async #getMeInner() {
|
|
1132
|
+
let chatP = (await this[getPeer]({ _: "peerUser", user_id: BigInt(await this.#getSelfId()) }))?.[0] ?? null;
|
|
1133
|
+
if (chatP === null) {
|
|
1134
|
+
const users = await this.invoke({ _: "users.getUsers", id: [{ _: "inputUserSelf" }] });
|
|
1135
|
+
chatP = (0, _3_types_js_1.constructChatP)(_2_tl_js_1.Api.as("user", users[0]));
|
|
1136
|
+
await this.storage.setIsPremium(chatP.isPremium);
|
|
1137
|
+
}
|
|
1138
|
+
const user = (0, _3_types_js_1.constructUser2)(chatP);
|
|
1139
|
+
this.#lastGetMe = user;
|
|
1140
|
+
return user;
|
|
1141
|
+
}
|
|
1597
1142
|
#previouslyConnected = false;
|
|
1598
1143
|
#lastConnectionState = false;
|
|
1599
1144
|
#onConnectionStateChange(connected) {
|
|
@@ -1618,15 +1163,16 @@ class Client extends Composer {
|
|
|
1618
1163
|
* @returns Information on the currently authorized user.
|
|
1619
1164
|
*/
|
|
1620
1165
|
async getMe() {
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1166
|
+
if (this.#lastGetMe === null) {
|
|
1167
|
+
const me = await this.#checkAuthorization();
|
|
1168
|
+
if (!me) {
|
|
1169
|
+
throw new _0_errors_js_1.InputError("Not signed in.");
|
|
1170
|
+
}
|
|
1171
|
+
else {
|
|
1172
|
+
return me;
|
|
1173
|
+
}
|
|
1626
1174
|
}
|
|
1627
|
-
|
|
1628
|
-
this.#lastGetMe = user;
|
|
1629
|
-
return user;
|
|
1175
|
+
return await this.#getMeInner();
|
|
1630
1176
|
}
|
|
1631
1177
|
/**
|
|
1632
1178
|
* Show a username in the current account, a bot account, a supergroup, or a channel's profile. User-only.
|
|
@@ -2380,7 +1926,7 @@ class Client extends Composer {
|
|
|
2380
1926
|
* @method fs
|
|
2381
1927
|
* @param fileId The identifier of a file.
|
|
2382
1928
|
* @example ```ts
|
|
2383
|
-
* const chunk = await client.
|
|
1929
|
+
* const chunk = await client.downloadChunk(fileId, { chunkSize: 256 * 1024 });
|
|
2384
1930
|
* ```
|
|
2385
1931
|
* @returns The downloaded chunk.
|
|
2386
1932
|
* @cache file
|