@mtkruto/node 0.0.990 → 0.0.992
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/1_utilities.d.ts +12 -0
- package/esm/1_utilities.js +12 -0
- package/esm/2_connection.d.ts +2 -0
- package/esm/2_connection.js +2 -0
- package/esm/2_tl.d.ts +10 -0
- package/esm/2_tl.js +10 -0
- package/esm/3_storage.d.ts +6 -0
- package/esm/3_storage.js +6 -0
- package/esm/3_transport.d.ts +4 -0
- package/esm/3_transport.js +4 -0
- package/esm/3_types.d.ts +35 -0
- package/esm/3_types.js +35 -0
- package/esm/{constants.d.ts → 4_constants.d.ts} +2 -2
- package/esm/{constants.js → 4_constants.js} +1 -1
- package/esm/5_client.d.ts +2 -0
- package/esm/5_client.js +2 -0
- package/esm/client/0_html.d.ts +1 -1
- package/esm/client/0_html.js +1 -1
- package/esm/client/0_message.d.ts +1 -2
- package/esm/client/0_message.js +7 -14
- package/esm/client/0_password.d.ts +2 -2
- package/esm/client/0_password.js +2 -4
- package/esm/client/0_utilities.d.ts +3 -5
- package/esm/client/0_utilities.js +3 -22
- package/esm/client/1_client_abstract.d.ts +2 -2
- package/esm/client/1_client_abstract.js +3 -3
- package/esm/client/2_client_plain.d.ts +3 -3
- package/esm/client/2_client_plain.js +13 -20
- package/esm/client/3_client.d.ts +43 -18
- package/esm/client/3_client.js +107 -46
- package/esm/connection/0_connection.d.ts +1 -1
- package/esm/connection/1_connection_web_socket.js +1 -1
- package/esm/mod.d.ts +7 -21
- package/esm/mod.js +7 -21
- package/esm/storage/0_storage.d.ts +4 -5
- package/esm/storage/0_storage.js +3 -8
- package/esm/storage/0_utilities.js +2 -2
- package/esm/storage/1_storage_local_storage.d.ts +1 -1
- package/esm/storage/1_storage_memory.d.ts +1 -1
- package/esm/storage/1_storage_session_storage.d.ts +1 -1
- package/esm/tl/0_tl_raw_reader.js +1 -1
- package/esm/tl/0_tl_raw_writer.js +1 -1
- package/esm/tl/1_tl_object.js +1 -1
- package/esm/tl/3_deserialize.js +1 -1
- package/esm/tl/3_utilities.d.ts +3 -0
- package/esm/tl/3_utilities.js +20 -0
- package/esm/tl/4_tl_writer.js +1 -1
- package/esm/transport/0_obfuscation.d.ts +2 -2
- package/esm/transport/0_obfuscation.js +1 -2
- package/esm/transport/0_transport.d.ts +1 -2
- package/esm/transport/1_transport_abridged.d.ts +1 -1
- package/esm/transport/1_transport_abridged.js +1 -1
- package/esm/transport/1_transport_intermediate.d.ts +1 -1
- package/esm/transport/1_transport_intermediate.js +1 -1
- package/esm/transport/2_transport_provider.d.ts +1 -1
- package/esm/transport/2_transport_provider.js +1 -1
- package/esm/types/!0_file_id.js +6 -9
- package/esm/types/!0_misc.d.ts +7 -0
- package/esm/types/!0_misc.js +1 -0
- package/esm/types/0_audio.d.ts +3 -3
- package/esm/types/0_audio.js +1 -1
- package/esm/types/0_chat_administrator_rights.d.ts +1 -1
- package/esm/types/0_chat_administrator_rights.js +1 -1
- package/esm/types/0_chat_photo.d.ts +3 -3
- package/esm/types/0_chat_photo.js +1 -1
- package/esm/types/0_color.d.ts +2 -0
- package/esm/types/0_color.js +16 -0
- package/esm/types/0_contact.d.ts +2 -2
- package/esm/types/0_dice.d.ts +1 -1
- package/esm/types/0_force_reply.d.ts +1 -1
- package/esm/types/0_force_reply.js +1 -1
- package/esm/types/0_location.d.ts +1 -1
- package/esm/types/0_location.js +1 -2
- package/esm/types/0_mask_position.d.ts +1 -1
- package/esm/types/0_message_entity.d.ts +5 -5
- package/esm/types/0_message_entity.js +1 -1
- package/esm/types/0_poll_option.d.ts +1 -1
- package/esm/types/0_reply_keyboard_remove.d.ts +1 -1
- package/esm/types/0_reply_keyboard_remove.js +2 -2
- package/esm/types/0_thumbnail.d.ts +2 -2
- package/esm/types/0_thumbnail.js +1 -1
- package/esm/types/0_venue.d.ts +1 -1
- package/esm/types/0_venue.js +1 -2
- package/esm/types/0_voice.d.ts +3 -3
- package/esm/types/0_web_app_info.d.ts +2 -2
- package/esm/types/1_animation.d.ts +3 -3
- package/esm/types/1_animation.js +1 -1
- package/esm/types/1_chat.d.ts +5 -4
- package/esm/types/1_chat.js +8 -9
- package/esm/types/1_document.d.ts +4 -4
- package/esm/types/1_document.js +1 -1
- package/esm/types/1_inline_keyboard_button.d.ts +4 -4
- package/esm/types/1_inline_keyboard_button.js +2 -2
- package/esm/types/1_keyboard_button.d.ts +8 -8
- package/esm/types/1_keyboard_button.js +2 -2
- package/esm/types/1_photo.d.ts +2 -2
- package/esm/types/1_photo.js +1 -1
- package/esm/types/1_poll.d.ts +8 -8
- package/esm/types/1_poll.js +1 -1
- package/esm/types/1_sticker.d.ts +3 -3
- package/esm/types/1_sticker.js +1 -2
- package/esm/types/1_user.d.ts +4 -3
- package/esm/types/1_user.js +4 -4
- package/esm/types/1_video.d.ts +3 -3
- package/esm/types/1_video.js +1 -1
- package/esm/types/1_video_note.d.ts +2 -2
- package/esm/types/1_video_note.js +1 -1
- package/esm/types/2_game.d.ts +3 -3
- package/esm/types/2_game.js +2 -3
- package/esm/types/2_inline_keyboard_markup.d.ts +2 -2
- package/esm/types/2_inline_keyboard_markup.js +1 -1
- package/esm/types/2_inline_query.d.ts +19 -0
- package/esm/types/2_inline_query.js +41 -0
- package/esm/types/2_reply_keyboard_markup.d.ts +2 -2
- package/esm/types/2_reply_keyboard_markup.js +1 -1
- package/esm/types/3_message.d.ts +23 -23
- package/esm/types/3_message.js +19 -18
- package/esm/types/4_callback_query.d.ts +14 -0
- package/esm/types/4_callback_query.js +24 -0
- package/esm/utilities/0_base64.js +1 -1
- package/esm/utilities/0_crypto.js +1 -1
- package/esm/utilities/0_queue.js +1 -1
- package/esm/utilities/1_auth.js +1 -1
- package/package.json +1 -1
- package/script/1_utilities.d.ts +12 -0
- package/script/1_utilities.js +28 -0
- package/script/2_connection.d.ts +2 -0
- package/script/2_connection.js +18 -0
- package/script/2_tl.d.ts +10 -0
- package/script/2_tl.js +40 -0
- package/script/3_storage.d.ts +6 -0
- package/script/3_storage.js +22 -0
- package/script/3_transport.d.ts +4 -0
- package/script/3_transport.js +20 -0
- package/script/3_types.d.ts +35 -0
- package/script/3_types.js +51 -0
- package/script/{constants.d.ts → 4_constants.d.ts} +2 -2
- package/script/{constants.js → 4_constants.js} +1 -1
- package/script/5_client.d.ts +2 -0
- package/script/5_client.js +18 -0
- package/script/client/0_html.d.ts +1 -1
- package/script/client/0_html.js +2 -2
- package/script/client/0_message.d.ts +1 -2
- package/script/client/0_message.js +32 -39
- package/script/client/0_password.d.ts +2 -2
- package/script/client/0_password.js +20 -22
- package/script/client/0_utilities.d.ts +3 -5
- package/script/client/0_utilities.js +24 -68
- package/script/client/1_client_abstract.d.ts +2 -2
- package/script/client/1_client_abstract.js +6 -6
- package/script/client/2_client_plain.d.ts +3 -3
- package/script/client/2_client_plain.js +45 -52
- package/script/client/3_client.d.ts +43 -18
- package/script/client/3_client.js +342 -305
- package/script/connection/0_connection.d.ts +1 -1
- package/script/connection/1_connection_web_socket.js +5 -5
- package/script/mod.d.ts +7 -21
- package/script/mod.js +17 -45
- package/script/storage/0_storage.d.ts +4 -5
- package/script/storage/0_storage.js +11 -39
- package/script/storage/0_utilities.js +6 -6
- package/script/storage/1_storage_local_storage.d.ts +1 -1
- package/script/storage/1_storage_memory.d.ts +1 -1
- package/script/storage/1_storage_session_storage.d.ts +1 -1
- package/script/tl/0_tl_raw_reader.js +6 -6
- package/script/tl/0_tl_raw_writer.js +7 -7
- package/script/tl/1_tl_object.js +3 -3
- package/script/tl/3_deserialize.js +2 -2
- package/script/tl/3_utilities.d.ts +3 -0
- package/script/tl/3_utilities.js +48 -0
- package/script/tl/4_tl_writer.js +2 -2
- package/script/transport/0_obfuscation.d.ts +2 -2
- package/script/transport/0_obfuscation.js +5 -6
- package/script/transport/0_transport.d.ts +1 -2
- package/script/transport/1_transport_abridged.d.ts +1 -1
- package/script/transport/1_transport_abridged.js +3 -3
- package/script/transport/1_transport_intermediate.d.ts +1 -1
- package/script/transport/1_transport_intermediate.js +3 -3
- package/script/transport/2_transport_provider.d.ts +1 -1
- package/script/transport/2_transport_provider.js +2 -2
- package/script/types/!0_file_id.js +24 -27
- package/script/types/!0_misc.d.ts +7 -0
- package/script/types/!0_misc.js +2 -0
- package/script/types/0_audio.d.ts +3 -3
- package/script/types/0_audio.js +2 -25
- package/script/types/0_chat_administrator_rights.d.ts +1 -1
- package/script/types/0_chat_administrator_rights.js +2 -25
- package/script/types/0_chat_photo.d.ts +3 -3
- package/script/types/0_chat_photo.js +2 -25
- package/script/types/0_color.d.ts +2 -0
- package/script/types/{!0_id_color.js → 0_color.js} +10 -10
- package/script/types/0_contact.d.ts +2 -2
- package/script/types/0_dice.d.ts +1 -1
- package/script/types/0_force_reply.d.ts +1 -1
- package/script/types/0_force_reply.js +2 -25
- package/script/types/0_location.d.ts +1 -1
- package/script/types/0_location.js +5 -29
- package/script/types/0_mask_position.d.ts +1 -1
- package/script/types/0_message_entity.d.ts +5 -5
- package/script/types/0_message_entity.js +39 -62
- package/script/types/0_poll_option.d.ts +1 -1
- package/script/types/0_reply_keyboard_remove.d.ts +1 -1
- package/script/types/0_reply_keyboard_remove.js +4 -27
- package/script/types/0_thumbnail.d.ts +2 -2
- package/script/types/0_thumbnail.js +2 -25
- package/script/types/0_venue.d.ts +1 -1
- package/script/types/0_venue.js +2 -26
- package/script/types/0_voice.d.ts +3 -3
- package/script/types/0_web_app_info.d.ts +2 -2
- package/script/types/1_animation.d.ts +3 -3
- package/script/types/1_animation.js +2 -25
- package/script/types/1_chat.d.ts +5 -4
- package/script/types/1_chat.js +20 -44
- package/script/types/1_document.d.ts +4 -4
- package/script/types/1_document.js +2 -25
- package/script/types/1_inline_keyboard_button.d.ts +4 -4
- package/script/types/1_inline_keyboard_button.js +19 -42
- package/script/types/1_keyboard_button.d.ts +8 -8
- package/script/types/1_keyboard_button.js +24 -47
- package/script/types/1_photo.d.ts +2 -2
- package/script/types/1_photo.js +4 -27
- package/script/types/1_poll.d.ts +8 -8
- package/script/types/1_poll.js +2 -2
- package/script/types/1_sticker.d.ts +3 -3
- package/script/types/1_sticker.js +6 -30
- package/script/types/1_user.d.ts +4 -3
- package/script/types/1_user.js +6 -29
- package/script/types/1_video.d.ts +3 -3
- package/script/types/1_video.js +2 -25
- package/script/types/1_video_note.d.ts +2 -2
- package/script/types/1_video_note.js +2 -25
- package/script/types/2_game.d.ts +3 -3
- package/script/types/2_game.js +6 -30
- package/script/types/2_inline_keyboard_markup.d.ts +2 -2
- package/script/types/2_inline_keyboard_markup.js +3 -26
- package/script/types/2_inline_query.d.ts +19 -0
- package/script/types/2_inline_query.js +45 -0
- package/script/types/2_reply_keyboard_markup.d.ts +2 -2
- package/script/types/2_reply_keyboard_markup.js +3 -26
- package/script/types/3_message.d.ts +23 -23
- package/script/types/3_message.js +97 -119
- package/script/types/4_callback_query.d.ts +14 -0
- package/script/types/4_callback_query.js +28 -0
- package/script/utilities/0_base64.js +3 -3
- package/script/utilities/0_crypto.js +3 -3
- package/script/utilities/0_queue.js +2 -2
- package/script/utilities/1_auth.js +5 -5
- package/esm/types/!0_id_color.d.ts +0 -1
- package/esm/types/!0_id_color.js +0 -16
- package/script/types/!0_id_color.d.ts +0 -1
- /package/esm/{deps.d.ts → 0_deps.d.ts} +0 -0
- /package/esm/{deps.js → 0_deps.js} +0 -0
- /package/script/{deps.d.ts → 0_deps.d.ts} +0 -0
- /package/script/{deps.js → 0_deps.js} +0 -0
|
@@ -1,67 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Client = exports.ParseMode = exports.restartAuth = exports.handleMigrationError = exports.getStickerSetName = exports.getEntity = void 0;
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
3
|
+
exports.Client = exports.ParseMode = exports.restartAuth = exports.getMessageWithReply = exports.handleMigrationError = exports.getStickerSetName = exports.getEntity = void 0;
|
|
4
|
+
const _0_deps_js_1 = require("../0_deps.js");
|
|
5
|
+
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
6
|
+
const _2_tl_js_1 = require("../2_tl.js");
|
|
7
|
+
const _3_storage_js_1 = require("../3_storage.js");
|
|
8
|
+
const _3_types_js_1 = require("../3_types.js");
|
|
9
|
+
const _4_constants_js_1 = require("../4_constants.js");
|
|
31
10
|
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
32
|
-
const _0_control_js_1 = require("../utilities/0_control.js");
|
|
33
|
-
const _0_queue_js_1 = require("../utilities/0_queue.js");
|
|
34
|
-
const _0_hash_js_1 = require("../utilities/0_hash.js");
|
|
35
|
-
const _0_tl_raw_reader_js_1 = require("../tl/0_tl_raw_reader.js");
|
|
36
|
-
const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
|
|
37
|
-
const types = __importStar(require("../tl/2_types.js"));
|
|
38
|
-
const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
|
|
39
|
-
const functions = __importStar(require("../tl/3_functions.js"));
|
|
40
|
-
const _5_rpc_result_js_1 = require("../tl/5_rpc_result.js");
|
|
41
|
-
const _6_message_js_1 = require("../tl/6_message.js"); // MTProto API message
|
|
42
|
-
const _7_message_container_js_1 = require("../tl/7_message_container.js");
|
|
43
|
-
const _0_file_id_js_1 = require("../types/!0_file_id.js");
|
|
44
|
-
const _0_reply_keyboard_remove_js_1 = require("../types/0_reply_keyboard_remove.js");
|
|
45
|
-
const _0_message_entity_js_1 = require("../types/0_message_entity.js");
|
|
46
|
-
const _0_force_reply_js_1 = require("../types/0_force_reply.js");
|
|
47
|
-
const _1_user_js_1 = require("../types/1_user.js");
|
|
48
|
-
const _2_inline_keyboard_markup_js_1 = require("../types/2_inline_keyboard_markup.js");
|
|
49
|
-
const _2_reply_keyboard_markup_js_1 = require("../types/2_reply_keyboard_markup.js");
|
|
50
|
-
const _3_message_js_1 = require("../types/3_message.js"); // high-level wrapper for Telegram API's message
|
|
51
|
-
const _1_storage_memory_js_1 = require("../storage/1_storage_memory.js");
|
|
52
11
|
const _0_message_js_1 = require("./0_message.js");
|
|
53
12
|
const _0_password_js_1 = require("./0_password.js");
|
|
54
13
|
const _0_html_js_1 = require("./0_html.js");
|
|
55
14
|
const _2_client_plain_js_1 = require("./2_client_plain.js");
|
|
56
15
|
const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
57
|
-
const d = (0,
|
|
58
|
-
const dGap = (0,
|
|
59
|
-
const dGapC = (0,
|
|
60
|
-
const dAuth = (0,
|
|
61
|
-
const dRecv = (0,
|
|
16
|
+
const d = (0, _0_deps_js_1.debug)("Client");
|
|
17
|
+
const dGap = (0, _0_deps_js_1.debug)("Client/recoverUpdateGap");
|
|
18
|
+
const dGapC = (0, _0_deps_js_1.debug)("Client/recoverChannelUpdateGap");
|
|
19
|
+
const dAuth = (0, _0_deps_js_1.debug)("Client/authorize");
|
|
20
|
+
const dRecv = (0, _0_deps_js_1.debug)("Client/receiveLoop");
|
|
62
21
|
exports.getEntity = Symbol();
|
|
63
22
|
exports.getStickerSetName = Symbol();
|
|
64
23
|
exports.handleMigrationError = Symbol();
|
|
24
|
+
exports.getMessageWithReply = Symbol();
|
|
65
25
|
exports.restartAuth = Symbol();
|
|
66
26
|
var ParseMode;
|
|
67
27
|
(function (ParseMode) {
|
|
@@ -77,7 +37,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
77
37
|
* @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Defaults to empty string (unset).
|
|
78
38
|
* @param params Other parameters.
|
|
79
39
|
*/
|
|
80
|
-
constructor(storage = new
|
|
40
|
+
constructor(storage = new _3_storage_js_1.StorageMemory(), apiId = 0, apiHash = "", params) {
|
|
81
41
|
super(params);
|
|
82
42
|
Object.defineProperty(this, "storage", {
|
|
83
43
|
enumerable: true,
|
|
@@ -107,7 +67,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
107
67
|
enumerable: true,
|
|
108
68
|
configurable: true,
|
|
109
69
|
writable: true,
|
|
110
|
-
value: (0,
|
|
70
|
+
value: (0, _1_utilities_js_1.getRandomBigInt)(8, true, false)
|
|
111
71
|
});
|
|
112
72
|
Object.defineProperty(this, "state", {
|
|
113
73
|
enumerable: true,
|
|
@@ -222,7 +182,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
222
182
|
enumerable: true,
|
|
223
183
|
configurable: true,
|
|
224
184
|
writable: true,
|
|
225
|
-
value: new
|
|
185
|
+
value: new _0_deps_js_1.Mutex()
|
|
226
186
|
});
|
|
227
187
|
Object.defineProperty(this, "connectionInited", {
|
|
228
188
|
enumerable: true,
|
|
@@ -230,6 +190,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
230
190
|
writable: true,
|
|
231
191
|
value: false
|
|
232
192
|
});
|
|
193
|
+
Object.defineProperty(this, "lastPropagatedAuthorizationState", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
configurable: true,
|
|
196
|
+
writable: true,
|
|
197
|
+
value: null
|
|
198
|
+
});
|
|
233
199
|
Object.defineProperty(this, "autoStarted", {
|
|
234
200
|
enumerable: true,
|
|
235
201
|
configurable: true,
|
|
@@ -246,13 +212,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
246
212
|
enumerable: true,
|
|
247
213
|
configurable: true,
|
|
248
214
|
writable: true,
|
|
249
|
-
value: new
|
|
215
|
+
value: new _1_utilities_js_1.Queue("handleUpdate")
|
|
250
216
|
});
|
|
251
217
|
Object.defineProperty(this, "processUpdatesQueue", {
|
|
252
218
|
enumerable: true,
|
|
253
219
|
configurable: true,
|
|
254
220
|
writable: true,
|
|
255
|
-
value: new
|
|
221
|
+
value: new _1_utilities_js_1.Queue("processUpdates")
|
|
256
222
|
});
|
|
257
223
|
Object.defineProperty(this, "handler", {
|
|
258
224
|
enumerable: true,
|
|
@@ -263,12 +229,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
263
229
|
}
|
|
264
230
|
});
|
|
265
231
|
this.parseMode = params?.parseMode ?? ParseMode.None;
|
|
266
|
-
this.appVersion = params?.appVersion ??
|
|
267
|
-
this.deviceModel = params?.deviceModel ??
|
|
268
|
-
this.langCode = params?.langCode ??
|
|
269
|
-
this.langPack = params?.langPack ??
|
|
270
|
-
this.systemLangCode = params?.systemLangCode ??
|
|
271
|
-
this.systemVersion = params?.systemVersion ??
|
|
232
|
+
this.appVersion = params?.appVersion ?? _4_constants_js_1.APP_VERSION;
|
|
233
|
+
this.deviceModel = params?.deviceModel ?? _4_constants_js_1.DEVICE_MODEL;
|
|
234
|
+
this.langCode = params?.langCode ?? _4_constants_js_1.LANG_CODE;
|
|
235
|
+
this.langPack = params?.langPack ?? _4_constants_js_1.LANG_PACK;
|
|
236
|
+
this.systemLangCode = params?.systemLangCode ?? _4_constants_js_1.SYSTEM_LANG_CODE;
|
|
237
|
+
this.systemVersion = params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION;
|
|
272
238
|
this.publicKeys = params?.publicKeys;
|
|
273
239
|
this.autoStart = params?.autoStart ?? true;
|
|
274
240
|
}
|
|
@@ -294,8 +260,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
294
260
|
super.setDc(dc);
|
|
295
261
|
}
|
|
296
262
|
async setAuth(key) {
|
|
297
|
-
const hash = await (0,
|
|
298
|
-
const id = (0,
|
|
263
|
+
const hash = await (0, _1_utilities_js_1.sha1)(key);
|
|
264
|
+
const id = (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false);
|
|
299
265
|
this.auth = { key, id };
|
|
300
266
|
}
|
|
301
267
|
/**
|
|
@@ -304,11 +270,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
304
270
|
* Before establishing the connection, the session is saved.
|
|
305
271
|
*/
|
|
306
272
|
async connect() {
|
|
273
|
+
if (this.connected) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
307
276
|
const release = await this.connectMutex.acquire();
|
|
308
277
|
try {
|
|
309
|
-
if (this.connected) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
278
|
if (!this.storageInited) {
|
|
313
279
|
await this.storage.init();
|
|
314
280
|
this.storageInited = true;
|
|
@@ -339,15 +305,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
339
305
|
await this.storage.setDc(this.initialDc);
|
|
340
306
|
}
|
|
341
307
|
d("encrypted client connected");
|
|
342
|
-
(0,
|
|
343
|
-
(0,
|
|
308
|
+
(0, _1_utilities_js_1.drop)(this.receiveLoop());
|
|
309
|
+
(0, _1_utilities_js_1.drop)(this.pingLoop());
|
|
344
310
|
}
|
|
345
311
|
finally {
|
|
346
312
|
release();
|
|
347
313
|
}
|
|
348
314
|
}
|
|
349
315
|
async fetchState(source) {
|
|
350
|
-
const state = await this.invoke(new functions.UpdatesGetState());
|
|
316
|
+
const state = await this.invoke(new _2_tl_js_1.functions.UpdatesGetState());
|
|
351
317
|
this.updateState = state;
|
|
352
318
|
d("state fetched [%s]", source);
|
|
353
319
|
}
|
|
@@ -362,7 +328,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
362
328
|
d("migrated to DC%s", newDc);
|
|
363
329
|
}
|
|
364
330
|
else {
|
|
365
|
-
(0,
|
|
331
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
366
332
|
}
|
|
367
333
|
}
|
|
368
334
|
disconnect() {
|
|
@@ -371,15 +337,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
371
337
|
}
|
|
372
338
|
async initConnection() {
|
|
373
339
|
if (!this.connectionInited) {
|
|
374
|
-
await this.invoke(new functions.InitConnection({
|
|
340
|
+
await this.invoke(new _2_tl_js_1.functions.InitConnection({
|
|
375
341
|
apiId: this.apiId,
|
|
376
342
|
appVersion: this.appVersion,
|
|
377
343
|
deviceModel: this.deviceModel,
|
|
378
344
|
langCode: this.langCode,
|
|
379
345
|
langPack: this.langPack,
|
|
380
|
-
query: new functions.InvokeWithLayer({
|
|
381
|
-
layer:
|
|
382
|
-
query: new functions.HelpGetConfig(),
|
|
346
|
+
query: new _2_tl_js_1.functions.InvokeWithLayer({
|
|
347
|
+
layer: _4_constants_js_1.LAYER,
|
|
348
|
+
query: new _2_tl_js_1.functions.HelpGetConfig(),
|
|
383
349
|
}),
|
|
384
350
|
systemLangCode: this.systemLangCode,
|
|
385
351
|
systemVersion: this.systemVersion,
|
|
@@ -388,6 +354,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
388
354
|
d("connection inited");
|
|
389
355
|
}
|
|
390
356
|
}
|
|
357
|
+
async propagateAuthorizationState(authorized) {
|
|
358
|
+
if (this.lastPropagatedAuthorizationState != authorized) {
|
|
359
|
+
await this.handler({ authorizationState: { authorized } }, resolve);
|
|
360
|
+
this.lastPropagatedAuthorizationState = authorized;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
391
363
|
/**
|
|
392
364
|
* Calls [initConnection](1) and authorizes the client with one of the following:
|
|
393
365
|
*
|
|
@@ -413,35 +385,36 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
413
385
|
throw new Error("apiHash not set");
|
|
414
386
|
}
|
|
415
387
|
if (typeof params === "undefined") {
|
|
416
|
-
const loginType = (0,
|
|
388
|
+
const loginType = (0, _1_utilities_js_1.mustPromptOneOf)("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
|
|
417
389
|
if (loginType == "b") {
|
|
418
|
-
params = (0,
|
|
390
|
+
params = (0, _1_utilities_js_1.mustPrompt)("Bot token:");
|
|
419
391
|
}
|
|
420
392
|
else {
|
|
421
|
-
params = { phone: () => (0,
|
|
393
|
+
params = { phone: () => (0, _1_utilities_js_1.mustPrompt)("Phone number:"), code: () => (0, _1_utilities_js_1.mustPrompt)("Verification code:"), password: () => (0, _1_utilities_js_1.mustPrompt)("Password:") };
|
|
422
394
|
}
|
|
423
395
|
}
|
|
424
|
-
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
396
|
+
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof _2_tl_js_1.types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
425
397
|
await this.initConnection();
|
|
426
398
|
try {
|
|
427
399
|
await this.fetchState("authorize");
|
|
400
|
+
await this.propagateAuthorizationState(true);
|
|
428
401
|
d("already authorized");
|
|
429
402
|
return;
|
|
430
403
|
}
|
|
431
404
|
catch (err) {
|
|
432
|
-
if (!(err instanceof types.RPCError) || err.errorMessage != "AUTH_KEY_UNREGISTERED") {
|
|
405
|
+
if (!(err instanceof _2_tl_js_1.types.RPCError) || err.errorMessage != "AUTH_KEY_UNREGISTERED") {
|
|
433
406
|
throw err;
|
|
434
407
|
}
|
|
435
408
|
}
|
|
436
409
|
if (typeof params === "string") {
|
|
437
410
|
while (true) {
|
|
438
411
|
try {
|
|
439
|
-
await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
|
|
412
|
+
await this.invoke(new _2_tl_js_1.functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
|
|
440
413
|
await this.storage.setAccountType("bot");
|
|
441
414
|
break;
|
|
442
415
|
}
|
|
443
416
|
catch (err) {
|
|
444
|
-
if (err instanceof types.RPCError) {
|
|
417
|
+
if (err instanceof _2_tl_js_1.types.RPCError) {
|
|
445
418
|
const match = err.errorMessage.match(/MIGRATE_(\d)$/);
|
|
446
419
|
if (match) {
|
|
447
420
|
await this[exports.handleMigrationError](err);
|
|
@@ -458,11 +431,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
458
431
|
}
|
|
459
432
|
}
|
|
460
433
|
dAuth("authorized as bot");
|
|
434
|
+
await this.propagateAuthorizationState(true);
|
|
461
435
|
await this.fetchState("authorize");
|
|
462
436
|
return;
|
|
463
437
|
}
|
|
464
|
-
if (params instanceof types.AuthExportedAuthorization) {
|
|
465
|
-
await this.invoke(new functions.AuthImportAuthorization({ id: params.id, bytes: params.bytes }));
|
|
438
|
+
if (params instanceof _2_tl_js_1.types.AuthExportedAuthorization) {
|
|
439
|
+
await this.invoke(new _2_tl_js_1.functions.AuthImportAuthorization({ id: params.id, bytes: params.bytes }));
|
|
466
440
|
dAuth("authorization imported");
|
|
467
441
|
return;
|
|
468
442
|
}
|
|
@@ -471,17 +445,17 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
471
445
|
while (true) {
|
|
472
446
|
try {
|
|
473
447
|
phone = typeof params.phone === "string" ? params.phone : await params.phone();
|
|
474
|
-
const sendCode = () => this.invoke(new functions.AuthSendCode({
|
|
448
|
+
const sendCode = () => this.invoke(new _2_tl_js_1.functions.AuthSendCode({
|
|
475
449
|
phoneNumber: phone,
|
|
476
450
|
apiId: this.apiId,
|
|
477
451
|
apiHash: this.apiHash,
|
|
478
|
-
settings: new types.CodeSettings(),
|
|
479
|
-
})).then((v) => v[
|
|
452
|
+
settings: new _2_tl_js_1.types.CodeSettings(),
|
|
453
|
+
})).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.AuthSentCode));
|
|
480
454
|
try {
|
|
481
455
|
sentCode = await sendCode();
|
|
482
456
|
}
|
|
483
457
|
catch (err) {
|
|
484
|
-
if (err instanceof types.RPCError) {
|
|
458
|
+
if (err instanceof _2_tl_js_1.types.RPCError) {
|
|
485
459
|
const match = err.errorMessage.match(/MIGRATE_(\d)$/);
|
|
486
460
|
if (match) {
|
|
487
461
|
await this[exports.handleMigrationError](err);
|
|
@@ -499,7 +473,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
499
473
|
break;
|
|
500
474
|
}
|
|
501
475
|
catch (err) {
|
|
502
|
-
if (err instanceof types.RPCError && err.errorMessage == "PHONE_NUMBER_INVALID") {
|
|
476
|
+
if (err instanceof _2_tl_js_1.types.RPCError && err.errorMessage == "PHONE_NUMBER_INVALID") {
|
|
503
477
|
continue;
|
|
504
478
|
}
|
|
505
479
|
else {
|
|
@@ -512,18 +486,19 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
512
486
|
while (true) {
|
|
513
487
|
const code = typeof params.code === "string" ? params.code : await params.code();
|
|
514
488
|
try {
|
|
515
|
-
await this.invoke(new functions.AuthSignIn({
|
|
489
|
+
await this.invoke(new _2_tl_js_1.functions.AuthSignIn({
|
|
516
490
|
phoneNumber: phone,
|
|
517
491
|
phoneCode: code,
|
|
518
492
|
phoneCodeHash: sentCode.phoneCodeHash,
|
|
519
493
|
}));
|
|
520
494
|
await this.storage.setAccountType("user");
|
|
521
495
|
dAuth("authorized as user");
|
|
496
|
+
await this.propagateAuthorizationState(true);
|
|
522
497
|
await this.fetchState("authorize");
|
|
523
498
|
return;
|
|
524
499
|
}
|
|
525
500
|
catch (err_) {
|
|
526
|
-
if (err_ instanceof types.RPCError && err_.errorMessage == "PHONE_CODE_INVALID") {
|
|
501
|
+
if (err_ instanceof _2_tl_js_1.types.RPCError && err_.errorMessage == "PHONE_CODE_INVALID") {
|
|
527
502
|
continue;
|
|
528
503
|
}
|
|
529
504
|
else {
|
|
@@ -532,25 +507,26 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
532
507
|
}
|
|
533
508
|
}
|
|
534
509
|
}
|
|
535
|
-
if (!(err instanceof types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED")) {
|
|
510
|
+
if (!(err instanceof _2_tl_js_1.types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED")) {
|
|
536
511
|
throw err;
|
|
537
512
|
}
|
|
538
513
|
while (true) {
|
|
539
|
-
const ap = await this.invoke(new functions.AccountGetPassword());
|
|
540
|
-
if (!(ap.currentAlgo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow)) {
|
|
514
|
+
const ap = await this.invoke(new _2_tl_js_1.functions.AccountGetPassword());
|
|
515
|
+
if (!(ap.currentAlgo instanceof _2_tl_js_1.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow)) {
|
|
541
516
|
throw new Error(`Handling ${ap.currentAlgo?.constructor.name} not implemented`);
|
|
542
517
|
}
|
|
543
518
|
try {
|
|
544
519
|
const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
|
|
545
520
|
const input = await (0, _0_password_js_1.checkPassword)(password, ap);
|
|
546
|
-
await this.invoke(new functions.AuthCheckPassword({ password: input }));
|
|
521
|
+
await this.invoke(new _2_tl_js_1.functions.AuthCheckPassword({ password: input }));
|
|
547
522
|
await this.storage.setAccountType("user");
|
|
548
523
|
dAuth("authorized as user");
|
|
524
|
+
await this.propagateAuthorizationState(true);
|
|
549
525
|
await this.fetchState("authorize");
|
|
550
526
|
break;
|
|
551
527
|
}
|
|
552
528
|
catch (err) {
|
|
553
|
-
if (err instanceof types.RPCError && err.errorMessage == "PASSWORD_HASH_INVALID") {
|
|
529
|
+
if (err instanceof _2_tl_js_1.types.RPCError && err.errorMessage == "PASSWORD_HASH_INVALID") {
|
|
554
530
|
continue;
|
|
555
531
|
}
|
|
556
532
|
else {
|
|
@@ -568,10 +544,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
568
544
|
try {
|
|
569
545
|
await this.fetchState("authorize");
|
|
570
546
|
d("already authorized");
|
|
547
|
+
await this.propagateAuthorizationState(true);
|
|
571
548
|
return;
|
|
572
549
|
}
|
|
573
550
|
catch (err) {
|
|
574
|
-
if (!(err instanceof types.RPCError) || err.errorMessage != "AUTH_KEY_UNREGISTERED") {
|
|
551
|
+
if (!(err instanceof _2_tl_js_1.types.RPCError) || err.errorMessage != "AUTH_KEY_UNREGISTERED") {
|
|
575
552
|
throw err;
|
|
576
553
|
}
|
|
577
554
|
}
|
|
@@ -583,8 +560,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
583
560
|
}
|
|
584
561
|
while (this.connected) {
|
|
585
562
|
try {
|
|
586
|
-
if (this.toAcknowledge.size >=
|
|
587
|
-
await this.send(new types.MsgsAck({ msgIds: [...this.toAcknowledge] }));
|
|
563
|
+
if (this.toAcknowledge.size >= _4_constants_js_1.ACK_THRESHOLD) {
|
|
564
|
+
await this.send(new _2_tl_js_1.types.MsgsAck({ msgIds: [...this.toAcknowledge] }));
|
|
588
565
|
this.toAcknowledge.clear();
|
|
589
566
|
}
|
|
590
567
|
const buffer = await this.transport.transport.receive();
|
|
@@ -594,25 +571,25 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
594
571
|
}
|
|
595
572
|
catch (err) {
|
|
596
573
|
dRecv("failed to decrypt message: %o", err);
|
|
597
|
-
(0,
|
|
574
|
+
(0, _1_utilities_js_1.drop)(this.recoverUpdateGap("decryption"));
|
|
598
575
|
continue;
|
|
599
576
|
}
|
|
600
|
-
const messages = decrypted instanceof
|
|
577
|
+
const messages = decrypted instanceof _2_tl_js_1.MessageContainer ? decrypted.messages : [decrypted];
|
|
601
578
|
for (const message of messages) {
|
|
602
579
|
let body = message.body;
|
|
603
|
-
if (body instanceof types.GZIPPacked) {
|
|
604
|
-
body = new
|
|
580
|
+
if (body instanceof _2_tl_js_1.types.GZIPPacked) {
|
|
581
|
+
body = new _2_tl_js_1.TLReader((0, _0_deps_js_1.gunzip)(body.packedData)).readObject();
|
|
605
582
|
}
|
|
606
583
|
dRecv("received %s", body.constructor.name);
|
|
607
|
-
if (body instanceof types._TypeUpdates || body instanceof types._TypeUpdate) {
|
|
584
|
+
if (body instanceof _2_tl_js_1.types._TypeUpdates || body instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
608
585
|
this.processUpdatesQueue.add(() => this.processUpdates(body));
|
|
609
586
|
}
|
|
610
|
-
else if (message.body instanceof
|
|
587
|
+
else if (message.body instanceof _2_tl_js_1.RPCResult) {
|
|
611
588
|
let result = message.body.result;
|
|
612
|
-
if (result instanceof types.GZIPPacked) {
|
|
613
|
-
result = new
|
|
589
|
+
if (result instanceof _2_tl_js_1.types.GZIPPacked) {
|
|
590
|
+
result = new _2_tl_js_1.TLReader((0, _0_deps_js_1.gunzip)(result.packedData)).readObject();
|
|
614
591
|
}
|
|
615
|
-
if (result instanceof types.RPCError) {
|
|
592
|
+
if (result instanceof _2_tl_js_1.types.RPCError) {
|
|
616
593
|
dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
|
|
617
594
|
}
|
|
618
595
|
else {
|
|
@@ -622,7 +599,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
622
599
|
const resolvePromise = () => {
|
|
623
600
|
const promise = this.promises.get(messageId);
|
|
624
601
|
if (promise) {
|
|
625
|
-
if (result instanceof types.RPCError) {
|
|
602
|
+
if (result instanceof _2_tl_js_1.types.RPCError) {
|
|
626
603
|
promise.reject(result);
|
|
627
604
|
}
|
|
628
605
|
else {
|
|
@@ -631,7 +608,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
631
608
|
this.promises.delete(messageId);
|
|
632
609
|
}
|
|
633
610
|
};
|
|
634
|
-
if (result instanceof types._TypeUpdates || result instanceof types._TypeUpdate) {
|
|
611
|
+
if (result instanceof _2_tl_js_1.types._TypeUpdates || result instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
635
612
|
this.processUpdatesQueue.add(async () => {
|
|
636
613
|
await this.processUpdates(result);
|
|
637
614
|
resolvePromise();
|
|
@@ -642,14 +619,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
642
619
|
resolvePromise();
|
|
643
620
|
}
|
|
644
621
|
}
|
|
645
|
-
else if (message.body instanceof types.Pong) {
|
|
622
|
+
else if (message.body instanceof _2_tl_js_1.types.Pong) {
|
|
646
623
|
const promise = this.promises.get(message.body.msgId);
|
|
647
624
|
if (promise) {
|
|
648
625
|
promise.resolve(message.body);
|
|
649
626
|
this.promises.delete(message.body.msgId);
|
|
650
627
|
}
|
|
651
628
|
}
|
|
652
|
-
else if (message.body instanceof types.BadServerSalt) {
|
|
629
|
+
else if (message.body instanceof _2_tl_js_1.types.BadServerSalt) {
|
|
653
630
|
d("server salt reassigned");
|
|
654
631
|
this.state.salt = message.body.newServerSalt;
|
|
655
632
|
const promise = this.promises.get(message.body.badMsgId);
|
|
@@ -665,9 +642,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
665
642
|
if (!this.connected) {
|
|
666
643
|
break;
|
|
667
644
|
}
|
|
668
|
-
else if (err instanceof
|
|
645
|
+
else if (err instanceof _2_tl_js_1.TLError) {
|
|
669
646
|
dRecv("failed to deserialize: %o", err);
|
|
670
|
-
(0,
|
|
647
|
+
(0, _1_utilities_js_1.drop)(this.recoverUpdateGap("deserialize"));
|
|
671
648
|
}
|
|
672
649
|
else {
|
|
673
650
|
throw err;
|
|
@@ -678,7 +655,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
678
655
|
async pingLoop() {
|
|
679
656
|
while (this.connected) {
|
|
680
657
|
try {
|
|
681
|
-
await this.invoke(new functions.Ping({ pingId: (0,
|
|
658
|
+
await this.invoke(new _2_tl_js_1.functions.Ping({ pingId: (0, _1_utilities_js_1.getRandomBigInt)(8, true, false) }));
|
|
682
659
|
}
|
|
683
660
|
catch (err) {
|
|
684
661
|
d("ping loop error: %o", err);
|
|
@@ -696,24 +673,33 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
696
673
|
}
|
|
697
674
|
}
|
|
698
675
|
if (!this.auth || !this.transport) {
|
|
699
|
-
(0,
|
|
676
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
700
677
|
}
|
|
701
678
|
let seqNo = this.state.seqNo * 2;
|
|
702
|
-
if (!(function_ instanceof functions.Ping) && !(function_ instanceof types.MsgsAck)) {
|
|
679
|
+
if (!(function_ instanceof _2_tl_js_1.functions.Ping) && !(function_ instanceof _2_tl_js_1.types.MsgsAck)) {
|
|
703
680
|
seqNo++;
|
|
704
681
|
this.state.seqNo++;
|
|
705
682
|
}
|
|
706
683
|
const messageId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
|
|
707
|
-
const message = new
|
|
684
|
+
const message = new _2_tl_js_1.Message(messageId, seqNo, function_);
|
|
708
685
|
await this.transport.transport.send(await (0, _0_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
|
|
709
686
|
d("invoked %s", function_.constructor.name);
|
|
710
687
|
if (noWait) {
|
|
711
688
|
return;
|
|
712
689
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
690
|
+
let result;
|
|
691
|
+
try {
|
|
692
|
+
result = await new Promise((resolve, reject) => {
|
|
693
|
+
this.promises.set(message.id, { resolve, reject });
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
catch (err) {
|
|
697
|
+
if (err instanceof _2_tl_js_1.types.RPCError && err.errorMessage == "AUTH_KEY_UNREGISTERED") {
|
|
698
|
+
await this.propagateAuthorizationState(false);
|
|
699
|
+
}
|
|
700
|
+
throw err;
|
|
701
|
+
}
|
|
702
|
+
if (result instanceof _2_tl_js_1.types.BadServerSalt) {
|
|
717
703
|
return await this.invoke(function_);
|
|
718
704
|
}
|
|
719
705
|
else {
|
|
@@ -728,7 +714,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
728
714
|
}
|
|
729
715
|
async processChats(chats) {
|
|
730
716
|
for (const chat of chats) {
|
|
731
|
-
if (chat instanceof types.Channel && chat.accessHash) {
|
|
717
|
+
if (chat instanceof _2_tl_js_1.types.Channel && chat.accessHash) {
|
|
732
718
|
await this.storage.setEntity(chat);
|
|
733
719
|
await this.storage.setChannelAccessHash(chat.id, chat.accessHash);
|
|
734
720
|
if (chat.username) {
|
|
@@ -738,14 +724,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
738
724
|
await this.storage.updateUsernames("channel", chat.id, chat.usernames.map((v) => v.username));
|
|
739
725
|
}
|
|
740
726
|
}
|
|
741
|
-
else if (chat instanceof types.Chat) {
|
|
727
|
+
else if (chat instanceof _2_tl_js_1.types.Chat) {
|
|
742
728
|
await this.storage.setEntity(chat);
|
|
743
729
|
}
|
|
744
730
|
}
|
|
745
731
|
}
|
|
746
732
|
async processUsers(users) {
|
|
747
733
|
for (const user of users) {
|
|
748
|
-
if (user instanceof types.User && user.accessHash) {
|
|
734
|
+
if (user instanceof _2_tl_js_1.types.User && user.accessHash) {
|
|
749
735
|
await this.storage.setEntity(user);
|
|
750
736
|
await this.storage.setUserAccessHash(user.id, user.accessHash);
|
|
751
737
|
if (user.username) {
|
|
@@ -761,7 +747,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
761
747
|
const localState = await this.getLocalState();
|
|
762
748
|
if (localState.pts + ptsCount < pts) {
|
|
763
749
|
if (assertNoGap) {
|
|
764
|
-
(0,
|
|
750
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
765
751
|
}
|
|
766
752
|
else {
|
|
767
753
|
await this.recoverUpdateGap("processUpdates");
|
|
@@ -775,7 +761,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
775
761
|
}
|
|
776
762
|
if (localPts + ptsCount < pts) {
|
|
777
763
|
if (assertNoGap) {
|
|
778
|
-
(0,
|
|
764
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
779
765
|
}
|
|
780
766
|
else {
|
|
781
767
|
await this.recoverChannelUpdateGap(channelId, "processUpdates");
|
|
@@ -791,26 +777,26 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
791
777
|
/// [2]: https://core.telegram.org/type/Updates
|
|
792
778
|
/// [3]: https://core.telegram.org/constructor/updatesTooLong
|
|
793
779
|
let updates;
|
|
794
|
-
if (updates_ instanceof types.UpdatesCombined || updates_ instanceof types.Updates) {
|
|
780
|
+
if (updates_ instanceof _2_tl_js_1.types.UpdatesCombined || updates_ instanceof _2_tl_js_1.types.Updates) {
|
|
795
781
|
updates = updates_.updates;
|
|
796
782
|
}
|
|
797
|
-
else if (updates_ instanceof types.UpdateShort) {
|
|
783
|
+
else if (updates_ instanceof _2_tl_js_1.types.UpdateShort) {
|
|
798
784
|
updates = [updates_.update];
|
|
799
785
|
}
|
|
800
|
-
else if (updates_ instanceof types.UpdateShortMessage ||
|
|
801
|
-
updates_ instanceof types.UpdateShortChatMessage ||
|
|
802
|
-
updates_ instanceof types.UpdateShortSentMessage) {
|
|
786
|
+
else if (updates_ instanceof _2_tl_js_1.types.UpdateShortMessage ||
|
|
787
|
+
updates_ instanceof _2_tl_js_1.types.UpdateShortChatMessage ||
|
|
788
|
+
updates_ instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
803
789
|
updates = [updates_];
|
|
804
790
|
}
|
|
805
|
-
else if (updates_ instanceof types.UpdatesTooLong) {
|
|
791
|
+
else if (updates_ instanceof _2_tl_js_1.types.UpdatesTooLong) {
|
|
806
792
|
await this.recoverUpdateGap("updatesTooLong");
|
|
807
793
|
return;
|
|
808
794
|
}
|
|
809
|
-
else if (updates_ instanceof types._TypeUpdate) {
|
|
795
|
+
else if (updates_ instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
810
796
|
updates = [updates_];
|
|
811
797
|
}
|
|
812
798
|
else {
|
|
813
|
-
(0,
|
|
799
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
814
800
|
}
|
|
815
801
|
/// Then, we go through each Update and updateShort*, and see if they are order-sensitive.
|
|
816
802
|
/// If they were, we check the local state to see if it is OK to process them right away.
|
|
@@ -820,7 +806,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
820
806
|
let originalPts = null;
|
|
821
807
|
const channelPtsMap = new Map();
|
|
822
808
|
for (const update of updates) {
|
|
823
|
-
if ((0, _0_utilities_js_1.
|
|
809
|
+
if ((0, _0_utilities_js_1.isPtsUpdate)(update)) {
|
|
824
810
|
if (update.pts == 0) {
|
|
825
811
|
continue;
|
|
826
812
|
}
|
|
@@ -834,12 +820,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
834
820
|
localState.pts = update.pts;
|
|
835
821
|
}
|
|
836
822
|
}
|
|
837
|
-
else if ((0, _0_utilities_js_1.
|
|
823
|
+
else if ((0, _0_utilities_js_1.isChannelPtsUpdate)(update)) {
|
|
838
824
|
if (update.pts == 0) {
|
|
839
825
|
continue;
|
|
840
826
|
}
|
|
841
827
|
const ptsCount = "ptsCount" in update ? update.ptsCount : 1;
|
|
842
|
-
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peerId[
|
|
828
|
+
const channelId = update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage ? update.message.peerId[_2_tl_js_1.as](_2_tl_js_1.types.PeerChannel).channelId : update.channelId;
|
|
843
829
|
await this.checkChannelGap(channelId, update.pts, ptsCount, assertNoGap);
|
|
844
830
|
let currentPts = channelPtsMap.get(channelId);
|
|
845
831
|
if (currentPts === undefined) {
|
|
@@ -863,41 +849,41 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
863
849
|
}
|
|
864
850
|
}
|
|
865
851
|
/// We process the updates when we are sure there is no gap.
|
|
866
|
-
if (updates_ instanceof types.Updates || updates_ instanceof types.UpdatesCombined) {
|
|
852
|
+
if (updates_ instanceof _2_tl_js_1.types.Updates || updates_ instanceof _2_tl_js_1.types.UpdatesCombined) {
|
|
867
853
|
await this.processChats(updates_.chats);
|
|
868
854
|
await this.processUsers(updates_.users);
|
|
869
855
|
await this.setUpdateStateDate(updates_.date);
|
|
870
856
|
}
|
|
871
|
-
else if (updates_ instanceof types.UpdateShort) {
|
|
857
|
+
else if (updates_ instanceof _2_tl_js_1.types.UpdateShort) {
|
|
872
858
|
await this.setUpdateStateDate(updates_.date);
|
|
873
859
|
}
|
|
874
860
|
const updatesToHandle = new Array();
|
|
875
861
|
for (const update of updates) {
|
|
876
|
-
if (update instanceof types.UpdateShortMessage ||
|
|
877
|
-
update instanceof types.UpdateShortChatMessage ||
|
|
878
|
-
update instanceof types.UpdateShortSentMessage) {
|
|
862
|
+
if (update instanceof _2_tl_js_1.types.UpdateShortMessage ||
|
|
863
|
+
update instanceof _2_tl_js_1.types.UpdateShortChatMessage ||
|
|
864
|
+
update instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
879
865
|
await this.setUpdateStateDate(update.date);
|
|
880
866
|
}
|
|
881
|
-
else if (update instanceof types.UpdateChannelTooLong) {
|
|
867
|
+
else if (update instanceof _2_tl_js_1.types.UpdateChannelTooLong) {
|
|
882
868
|
if (update.pts != undefined) {
|
|
883
869
|
await this.storage.setChannelPts(update.channelId, update.pts);
|
|
884
870
|
}
|
|
885
871
|
await this.recoverChannelUpdateGap(update.channelId, "updateChannelTooLong");
|
|
886
872
|
}
|
|
887
|
-
else if (update instanceof types.UpdateUserName) {
|
|
873
|
+
else if (update instanceof _2_tl_js_1.types.UpdateUserName) {
|
|
888
874
|
await this.storage.updateUsernames("user", update.userId, update.usernames.map((v) => v.username));
|
|
889
875
|
}
|
|
890
|
-
else if (update instanceof types.UpdatePtsChanged) {
|
|
876
|
+
else if (update instanceof _2_tl_js_1.types.UpdatePtsChanged) {
|
|
891
877
|
await this.fetchState("updatePtsChanged");
|
|
892
878
|
if (this.updateState) {
|
|
893
879
|
await this.storage.setState(this.updateState);
|
|
894
880
|
}
|
|
895
881
|
else {
|
|
896
|
-
(0,
|
|
882
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
897
883
|
}
|
|
898
884
|
}
|
|
899
885
|
/// If there were any Update, they will be passed to the update handling queue.
|
|
900
|
-
if (update instanceof types._TypeUpdate) {
|
|
886
|
+
if (update instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
901
887
|
updatesToHandle.push(update);
|
|
902
888
|
}
|
|
903
889
|
}
|
|
@@ -926,7 +912,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
926
912
|
await this.storage.setState(localState);
|
|
927
913
|
}
|
|
928
914
|
else {
|
|
929
|
-
(0,
|
|
915
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
930
916
|
}
|
|
931
917
|
}
|
|
932
918
|
}
|
|
@@ -938,41 +924,41 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
938
924
|
try {
|
|
939
925
|
let state = await this.getLocalState();
|
|
940
926
|
while (true) {
|
|
941
|
-
const difference = await this.invoke(new functions.UpdatesGetDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 }));
|
|
942
|
-
if (difference instanceof types.UpdatesDifference || difference instanceof types.UpdatesDifferenceSlice) {
|
|
927
|
+
const difference = await this.invoke(new _2_tl_js_1.functions.UpdatesGetDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 }));
|
|
928
|
+
if (difference instanceof _2_tl_js_1.types.UpdatesDifference || difference instanceof _2_tl_js_1.types.UpdatesDifferenceSlice) {
|
|
943
929
|
await this.processChats(difference.chats);
|
|
944
930
|
await this.processUsers(difference.users);
|
|
945
931
|
for (const message of difference.newMessages) {
|
|
946
|
-
await this.processUpdates(new types.UpdateNewMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
932
|
+
await this.processUpdates(new _2_tl_js_1.types.UpdateNewMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
947
933
|
}
|
|
948
934
|
for (const update of difference.otherUpdates) {
|
|
949
935
|
await this.processUpdates(update, true);
|
|
950
936
|
}
|
|
951
|
-
if (difference instanceof types.UpdatesDifference) {
|
|
937
|
+
if (difference instanceof _2_tl_js_1.types.UpdatesDifference) {
|
|
952
938
|
await this.storage.setState(difference.state);
|
|
953
939
|
dGap("recovered from update gap");
|
|
954
940
|
break;
|
|
955
941
|
}
|
|
956
|
-
else if (difference instanceof types.UpdatesDifferenceSlice) {
|
|
942
|
+
else if (difference instanceof _2_tl_js_1.types.UpdatesDifferenceSlice) {
|
|
957
943
|
state = difference.intermediateState;
|
|
958
944
|
}
|
|
959
945
|
else {
|
|
960
|
-
(0,
|
|
946
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
961
947
|
}
|
|
962
948
|
}
|
|
963
|
-
else if (difference instanceof types.UpdatesDifferenceTooLong) {
|
|
949
|
+
else if (difference instanceof _2_tl_js_1.types.UpdatesDifferenceTooLong) {
|
|
964
950
|
// TODO: we actually do now
|
|
965
951
|
// stored messages should be invalidated in case we store messages in the future
|
|
966
952
|
state.pts = difference.pts;
|
|
967
953
|
dGap("received differenceTooLong");
|
|
968
954
|
}
|
|
969
|
-
else if (difference instanceof types.UpdatesDifferenceEmpty) {
|
|
955
|
+
else if (difference instanceof _2_tl_js_1.types.UpdatesDifferenceEmpty) {
|
|
970
956
|
await this.setUpdateStateDate(difference.date);
|
|
971
957
|
dGap("there was no update gap");
|
|
972
958
|
break;
|
|
973
959
|
}
|
|
974
960
|
else {
|
|
975
|
-
(0,
|
|
961
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
976
962
|
}
|
|
977
963
|
}
|
|
978
964
|
}
|
|
@@ -985,18 +971,18 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
985
971
|
const pts_ = await this.storage.getChannelPts(channelId);
|
|
986
972
|
let pts = pts_ == null ? 1 : pts_;
|
|
987
973
|
while (true) {
|
|
988
|
-
const { accessHash } = await this.getInputPeer(
|
|
989
|
-
const difference = await this.invoke(new functions.UpdatesGetChannelDifference({
|
|
974
|
+
const { accessHash } = await this.getInputPeer(_4_constants_js_1.ZERO_CHANNEL_ID + -Number(channelId)).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerChannel));
|
|
975
|
+
const difference = await this.invoke(new _2_tl_js_1.functions.UpdatesGetChannelDifference({
|
|
990
976
|
pts,
|
|
991
|
-
channel: new types.InputChannel({ channelId, accessHash: accessHash }),
|
|
992
|
-
filter: new types.ChannelMessagesFilterEmpty(),
|
|
993
|
-
limit: await this.storage.getAccountType() == "user" ?
|
|
977
|
+
channel: new _2_tl_js_1.types.InputChannel({ channelId, accessHash: accessHash }),
|
|
978
|
+
filter: new _2_tl_js_1.types.ChannelMessagesFilterEmpty(),
|
|
979
|
+
limit: await this.storage.getAccountType() == "user" ? _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_USER : _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_BOT,
|
|
994
980
|
}));
|
|
995
|
-
if (difference instanceof types.UpdatesChannelDifference) {
|
|
981
|
+
if (difference instanceof _2_tl_js_1.types.UpdatesChannelDifference) {
|
|
996
982
|
await this.processChats(difference.chats);
|
|
997
983
|
await this.processUsers(difference.users);
|
|
998
984
|
for (const message of difference.newMessages) {
|
|
999
|
-
await this.processUpdates(new types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
985
|
+
await this.processUpdates(new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
1000
986
|
}
|
|
1001
987
|
for (const update of difference.otherUpdates) {
|
|
1002
988
|
await this.processUpdates(update, true);
|
|
@@ -1005,30 +991,51 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1005
991
|
dGapC("recovered from update gap [%o, %s]", channelId, source);
|
|
1006
992
|
break;
|
|
1007
993
|
}
|
|
1008
|
-
else if (difference instanceof types.UpdatesChannelDifferenceTooLong) {
|
|
994
|
+
else if (difference instanceof _2_tl_js_1.types.UpdatesChannelDifferenceTooLong) {
|
|
1009
995
|
// invalidate messages
|
|
1010
996
|
dGapC("received channelDifferenceTooLong");
|
|
1011
997
|
await this.processChats(difference.chats);
|
|
1012
998
|
await this.processUsers(difference.users);
|
|
1013
999
|
for (const message of difference.messages) {
|
|
1014
|
-
await this.processUpdates(new types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
1000
|
+
await this.processUpdates(new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
1015
1001
|
}
|
|
1016
|
-
const pts_ = difference.dialog[
|
|
1002
|
+
const pts_ = difference.dialog[_2_tl_js_1.as](_2_tl_js_1.types.Dialog).pts;
|
|
1017
1003
|
if (pts_ != undefined) {
|
|
1018
1004
|
pts = pts_;
|
|
1019
1005
|
}
|
|
1020
1006
|
else {
|
|
1021
|
-
(0,
|
|
1007
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1022
1008
|
}
|
|
1023
1009
|
dGapC("processed channelDifferenceTooLong");
|
|
1024
1010
|
}
|
|
1025
|
-
else if (difference instanceof types.UpdatesChannelDifferenceEmpty) {
|
|
1011
|
+
else if (difference instanceof _2_tl_js_1.types.UpdatesChannelDifferenceEmpty) {
|
|
1026
1012
|
dGapC("there was no update gap");
|
|
1027
1013
|
break;
|
|
1028
1014
|
}
|
|
1029
1015
|
}
|
|
1030
1016
|
}
|
|
1017
|
+
async getUserAccessHash(userId) {
|
|
1018
|
+
const users = await this.invoke(new _2_tl_js_1.functions.UsersGetUsers({ id: [new _2_tl_js_1.types.InputUser({ userId, accessHash: 0n })] }));
|
|
1019
|
+
return users[0][_2_tl_js_1.as](_2_tl_js_1.types.User).accessHash ?? 0n;
|
|
1020
|
+
}
|
|
1021
|
+
async getChannelAccessHash(channelId) {
|
|
1022
|
+
const channels = await this.invoke(new _2_tl_js_1.functions.ChannelsGetChannels({ id: [new _2_tl_js_1.types.InputChannel({ channelId, accessHash: 0n })] }));
|
|
1023
|
+
return channels.chats[0][_2_tl_js_1.as](_2_tl_js_1.types.Channel).accessHash ?? 0n;
|
|
1024
|
+
}
|
|
1031
1025
|
async getInputPeer(id) {
|
|
1026
|
+
const inputPeer = await this.getInputPeerInner(id);
|
|
1027
|
+
if (inputPeer instanceof _2_tl_js_1.types.InputPeerUser || inputPeer instanceof _2_tl_js_1.types.InputPeerChannel && inputPeer.accessHash == 0n && await this.storage.getAccountType() == "bot") {
|
|
1028
|
+
if ("channelId" in inputPeer) {
|
|
1029
|
+
inputPeer.accessHash = await this.getChannelAccessHash(inputPeer.channelId);
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
inputPeer.accessHash = await this.getUserAccessHash(inputPeer.userId);
|
|
1033
|
+
await this.storage.setUserAccessHash(inputPeer.userId, inputPeer.accessHash);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
return inputPeer;
|
|
1037
|
+
}
|
|
1038
|
+
async getInputPeerInner(id) {
|
|
1032
1039
|
if (typeof id === "string") {
|
|
1033
1040
|
if (!id.startsWith("@")) {
|
|
1034
1041
|
throw new Error("Expected username to start with @");
|
|
@@ -1041,7 +1048,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1041
1048
|
let userId = 0n;
|
|
1042
1049
|
let channelId = 0n;
|
|
1043
1050
|
const maybeUsername = await this.storage.getUsername(id);
|
|
1044
|
-
if (maybeUsername != null && Date.now() - maybeUsername[2].getTime() <
|
|
1051
|
+
if (maybeUsername != null && Date.now() - maybeUsername[2].getTime() < _4_constants_js_1.USERNAME_TTL) {
|
|
1045
1052
|
const [type, id] = maybeUsername;
|
|
1046
1053
|
if (type == "user") {
|
|
1047
1054
|
userId = id;
|
|
@@ -1051,113 +1058,117 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1051
1058
|
}
|
|
1052
1059
|
}
|
|
1053
1060
|
else {
|
|
1054
|
-
const resolved = await this.invoke(new functions.ContactsResolveUsername({ username: id }));
|
|
1061
|
+
const resolved = await this.invoke(new _2_tl_js_1.functions.ContactsResolveUsername({ username: id }));
|
|
1055
1062
|
await this.processChats(resolved.chats);
|
|
1056
1063
|
await this.processUsers(resolved.users);
|
|
1057
|
-
if (resolved.peer instanceof types.PeerUser) {
|
|
1064
|
+
if (resolved.peer instanceof _2_tl_js_1.types.PeerUser) {
|
|
1058
1065
|
userId = resolved.peer.userId;
|
|
1059
1066
|
}
|
|
1060
|
-
else if (resolved.peer instanceof types.PeerChannel) {
|
|
1067
|
+
else if (resolved.peer instanceof _2_tl_js_1.types.PeerChannel) {
|
|
1061
1068
|
channelId = resolved.peer.channelId;
|
|
1062
1069
|
}
|
|
1063
1070
|
else {
|
|
1064
|
-
(0,
|
|
1071
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1065
1072
|
}
|
|
1066
1073
|
}
|
|
1067
1074
|
if (userId) {
|
|
1068
1075
|
const accessHash = await this.storage.getUserAccessHash(userId);
|
|
1069
|
-
return new types.InputPeerUser({ userId, accessHash: accessHash ?? 0n });
|
|
1076
|
+
return new _2_tl_js_1.types.InputPeerUser({ userId, accessHash: accessHash ?? 0n });
|
|
1070
1077
|
}
|
|
1071
1078
|
else if (channelId) {
|
|
1072
1079
|
const accessHash = await this.storage.getChannelAccessHash(channelId);
|
|
1073
|
-
return new types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
|
|
1080
|
+
return new _2_tl_js_1.types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
|
|
1074
1081
|
}
|
|
1075
1082
|
else {
|
|
1076
|
-
(0,
|
|
1083
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1077
1084
|
}
|
|
1078
1085
|
}
|
|
1079
1086
|
}
|
|
1080
1087
|
else if (id > 0) {
|
|
1081
1088
|
const id_ = BigInt(id);
|
|
1082
1089
|
const accessHash = await this.storage.getUserAccessHash(id_);
|
|
1083
|
-
return new types.InputPeerUser({ userId: id_, accessHash: accessHash ?? 0n });
|
|
1090
|
+
return new _2_tl_js_1.types.InputPeerUser({ userId: id_, accessHash: accessHash ?? 0n });
|
|
1084
1091
|
}
|
|
1085
|
-
else if (-
|
|
1086
|
-
return new types.InputPeerChat({ chatId: BigInt(Math.abs(id)) });
|
|
1092
|
+
else if (-_4_constants_js_1.MAX_CHAT_ID <= id) {
|
|
1093
|
+
return new _2_tl_js_1.types.InputPeerChat({ chatId: BigInt(Math.abs(id)) });
|
|
1087
1094
|
}
|
|
1088
|
-
else if (
|
|
1089
|
-
const id_ = BigInt(Math.abs(id -
|
|
1095
|
+
else if (_4_constants_js_1.ZERO_CHANNEL_ID - _4_constants_js_1.MAX_CHANNEL_ID <= id && id != _4_constants_js_1.ZERO_CHANNEL_ID) {
|
|
1096
|
+
const id_ = BigInt(Math.abs(id - _4_constants_js_1.ZERO_CHANNEL_ID));
|
|
1090
1097
|
const accessHash = await this.storage.getChannelAccessHash(id_);
|
|
1091
|
-
return new types.InputPeerChannel({ channelId: id_, accessHash: accessHash ?? 0n });
|
|
1098
|
+
return new _2_tl_js_1.types.InputPeerChannel({ channelId: id_, accessHash: accessHash ?? 0n });
|
|
1092
1099
|
}
|
|
1093
1100
|
else {
|
|
1094
1101
|
throw new Error("ID format unknown or not implemented");
|
|
1095
1102
|
}
|
|
1096
1103
|
}
|
|
1097
1104
|
[exports.getEntity](peer) {
|
|
1098
|
-
const type = peer instanceof types.PeerUser ? "user" : peer instanceof types.PeerChat ? "chat" : peer instanceof types.PeerChannel ? "channel" : (0,
|
|
1099
|
-
const id = peer instanceof types.PeerUser ? peer.userId : peer instanceof types.PeerChat ? peer.chatId : peer instanceof types.PeerChannel ? peer.channelId : (0,
|
|
1105
|
+
const type = peer instanceof _2_tl_js_1.types.PeerUser ? "user" : peer instanceof _2_tl_js_1.types.PeerChat ? "chat" : peer instanceof _2_tl_js_1.types.PeerChannel ? "channel" : (0, _1_utilities_js_1.UNREACHABLE)();
|
|
1106
|
+
const id = peer instanceof _2_tl_js_1.types.PeerUser ? peer.userId : peer instanceof _2_tl_js_1.types.PeerChat ? peer.chatId : peer instanceof _2_tl_js_1.types.PeerChannel ? peer.channelId : (0, _1_utilities_js_1.UNREACHABLE)();
|
|
1100
1107
|
return this.storage.getEntity(type, id);
|
|
1101
1108
|
}
|
|
1102
1109
|
async processResult(result) {
|
|
1103
|
-
if (result instanceof types.MessagesDialogs ||
|
|
1104
|
-
result instanceof types.MessagesDialogsSlice ||
|
|
1105
|
-
result instanceof types.MessagesMessages ||
|
|
1106
|
-
result instanceof types.MessagesMessagesSlice ||
|
|
1107
|
-
result instanceof types.MessagesChannelMessages ||
|
|
1108
|
-
result instanceof types.MessagesChatFull ||
|
|
1109
|
-
result instanceof types.ContactsFound ||
|
|
1110
|
-
result instanceof types.AccountPrivacyRules ||
|
|
1111
|
-
result instanceof types.ContactsResolvedPeer ||
|
|
1112
|
-
result instanceof types.ChannelsChannelParticipants ||
|
|
1113
|
-
result instanceof types.ChannelsChannelParticipant ||
|
|
1114
|
-
result instanceof types.MessagesPeerDialogs ||
|
|
1115
|
-
result instanceof types.ContactsTopPeers ||
|
|
1116
|
-
result instanceof types.ChannelsAdminLogResults ||
|
|
1117
|
-
result instanceof types.HelpRecentMeURLs ||
|
|
1118
|
-
result instanceof types.MessagesInactiveChats ||
|
|
1119
|
-
result instanceof types.HelpPromoData ||
|
|
1120
|
-
result instanceof types.MessagesMessageViews ||
|
|
1121
|
-
result instanceof types.MessagesDiscussionMessage ||
|
|
1122
|
-
result instanceof types.PhoneGroupCall ||
|
|
1123
|
-
result instanceof types.PhoneGroupParticipants ||
|
|
1124
|
-
result instanceof types.PhoneJoinAsPeers ||
|
|
1125
|
-
result instanceof types.MessagesSponsoredMessages ||
|
|
1126
|
-
result instanceof types.MessagesSearchResultsCalendar ||
|
|
1127
|
-
result instanceof types.ChannelsSendAsPeers ||
|
|
1128
|
-
result instanceof types.UsersUserFull ||
|
|
1129
|
-
result instanceof types.MessagesPeerSettings ||
|
|
1130
|
-
result instanceof types.MessagesMessageReactionsList ||
|
|
1131
|
-
result instanceof types.MessagesForumTopics ||
|
|
1132
|
-
result instanceof types.AccountAutoSaveSettings ||
|
|
1133
|
-
result instanceof types.ChatlistsExportedInvites ||
|
|
1134
|
-
result instanceof types.ChatlistsChatlistInviteAlready ||
|
|
1135
|
-
result instanceof types.ChatlistsChatlistInvite ||
|
|
1136
|
-
result instanceof types.ChatlistsChatlistUpdates
|
|
1110
|
+
if (result instanceof _2_tl_js_1.types.MessagesDialogs ||
|
|
1111
|
+
result instanceof _2_tl_js_1.types.MessagesDialogsSlice ||
|
|
1112
|
+
result instanceof _2_tl_js_1.types.MessagesMessages ||
|
|
1113
|
+
result instanceof _2_tl_js_1.types.MessagesMessagesSlice ||
|
|
1114
|
+
result instanceof _2_tl_js_1.types.MessagesChannelMessages ||
|
|
1115
|
+
result instanceof _2_tl_js_1.types.MessagesChatFull ||
|
|
1116
|
+
result instanceof _2_tl_js_1.types.ContactsFound ||
|
|
1117
|
+
result instanceof _2_tl_js_1.types.AccountPrivacyRules ||
|
|
1118
|
+
result instanceof _2_tl_js_1.types.ContactsResolvedPeer ||
|
|
1119
|
+
result instanceof _2_tl_js_1.types.ChannelsChannelParticipants ||
|
|
1120
|
+
result instanceof _2_tl_js_1.types.ChannelsChannelParticipant ||
|
|
1121
|
+
result instanceof _2_tl_js_1.types.MessagesPeerDialogs ||
|
|
1122
|
+
result instanceof _2_tl_js_1.types.ContactsTopPeers ||
|
|
1123
|
+
result instanceof _2_tl_js_1.types.ChannelsAdminLogResults ||
|
|
1124
|
+
result instanceof _2_tl_js_1.types.HelpRecentMeURLs ||
|
|
1125
|
+
result instanceof _2_tl_js_1.types.MessagesInactiveChats ||
|
|
1126
|
+
result instanceof _2_tl_js_1.types.HelpPromoData ||
|
|
1127
|
+
result instanceof _2_tl_js_1.types.MessagesMessageViews ||
|
|
1128
|
+
result instanceof _2_tl_js_1.types.MessagesDiscussionMessage ||
|
|
1129
|
+
result instanceof _2_tl_js_1.types.PhoneGroupCall ||
|
|
1130
|
+
result instanceof _2_tl_js_1.types.PhoneGroupParticipants ||
|
|
1131
|
+
result instanceof _2_tl_js_1.types.PhoneJoinAsPeers ||
|
|
1132
|
+
result instanceof _2_tl_js_1.types.MessagesSponsoredMessages ||
|
|
1133
|
+
result instanceof _2_tl_js_1.types.MessagesSearchResultsCalendar ||
|
|
1134
|
+
result instanceof _2_tl_js_1.types.ChannelsSendAsPeers ||
|
|
1135
|
+
result instanceof _2_tl_js_1.types.UsersUserFull ||
|
|
1136
|
+
result instanceof _2_tl_js_1.types.MessagesPeerSettings ||
|
|
1137
|
+
result instanceof _2_tl_js_1.types.MessagesMessageReactionsList ||
|
|
1138
|
+
result instanceof _2_tl_js_1.types.MessagesForumTopics ||
|
|
1139
|
+
result instanceof _2_tl_js_1.types.AccountAutoSaveSettings ||
|
|
1140
|
+
result instanceof _2_tl_js_1.types.ChatlistsExportedInvites ||
|
|
1141
|
+
result instanceof _2_tl_js_1.types.ChatlistsChatlistInviteAlready ||
|
|
1142
|
+
result instanceof _2_tl_js_1.types.ChatlistsChatlistInvite ||
|
|
1143
|
+
result instanceof _2_tl_js_1.types.ChatlistsChatlistUpdates ||
|
|
1144
|
+
result instanceof _2_tl_js_1.types.MessagesChats ||
|
|
1145
|
+
result instanceof _2_tl_js_1.types.MessagesChatsSlice) {
|
|
1137
1146
|
await this.processChats(result.chats);
|
|
1138
|
-
|
|
1147
|
+
if ("users" in result) {
|
|
1148
|
+
await this.processUsers(result.users);
|
|
1149
|
+
}
|
|
1139
1150
|
}
|
|
1140
|
-
if (result instanceof types.MessagesMessages) {
|
|
1151
|
+
if (result instanceof _2_tl_js_1.types.MessagesMessages) {
|
|
1141
1152
|
for (const message of result.messages) {
|
|
1142
|
-
if (message instanceof types.Message || message instanceof types.MessageService) {
|
|
1143
|
-
await this.storage.setMessage((0,
|
|
1153
|
+
if (message instanceof _2_tl_js_1.types.Message || message instanceof _2_tl_js_1.types.MessageService) {
|
|
1154
|
+
await this.storage.setMessage((0, _2_tl_js_1.peerToChatId)(message.peerId), message.id, message);
|
|
1144
1155
|
}
|
|
1145
1156
|
}
|
|
1146
1157
|
}
|
|
1147
1158
|
}
|
|
1148
1159
|
async updatesToMessages(chatId, updates) {
|
|
1149
1160
|
const messages = new Array();
|
|
1150
|
-
if (updates instanceof types.Updates) {
|
|
1161
|
+
if (updates instanceof _2_tl_js_1.types.Updates) {
|
|
1151
1162
|
for (const update of updates.updates) {
|
|
1152
|
-
if (update instanceof types.UpdateNewMessage) {
|
|
1153
|
-
messages.push(await (0,
|
|
1163
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage) {
|
|
1164
|
+
messages.push(await (0, _3_types_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this)));
|
|
1154
1165
|
}
|
|
1155
|
-
else if (update instanceof types.UpdateNewChannelMessage) {
|
|
1156
|
-
messages.push(await (0,
|
|
1166
|
+
else if (update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
|
|
1167
|
+
messages.push(await (0, _3_types_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this)));
|
|
1157
1168
|
}
|
|
1158
1169
|
}
|
|
1159
1170
|
}
|
|
1160
|
-
else if (updates instanceof types.UpdateShortSentMessage || updates instanceof types.UpdateShortSentMessage) {
|
|
1171
|
+
else if (updates instanceof _2_tl_js_1.types.UpdateShortSentMessage || updates instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
1161
1172
|
const message = await this.getMessage(chatId, updates.id);
|
|
1162
1173
|
if (message != null) {
|
|
1163
1174
|
messages.push(message);
|
|
@@ -1188,26 +1199,26 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1188
1199
|
let replyMarkup = undefined;
|
|
1189
1200
|
if (params?.replyMarkup) {
|
|
1190
1201
|
if ("inlineKeyboard" in params.replyMarkup) {
|
|
1191
|
-
replyMarkup = await (0,
|
|
1192
|
-
const inputPeer = await this.getInputPeer(v).then((v) => v[
|
|
1193
|
-
return new types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
1202
|
+
replyMarkup = await (0, _3_types_js_1.inlineKeyboardMarkupToTlObject)(params.replyMarkup, async (v) => {
|
|
1203
|
+
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
1204
|
+
return new _2_tl_js_1.types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
1194
1205
|
});
|
|
1195
1206
|
}
|
|
1196
1207
|
else if ("keyboard" in params.replyMarkup) {
|
|
1197
|
-
replyMarkup = (0,
|
|
1208
|
+
replyMarkup = (0, _3_types_js_1.replyKeyboardMarkupToTlObject)(params.replyMarkup);
|
|
1198
1209
|
}
|
|
1199
1210
|
else if ("removeKeyboard" in params.replyMarkup) {
|
|
1200
|
-
replyMarkup = (0,
|
|
1211
|
+
replyMarkup = (0, _3_types_js_1.replyKeyboardRemoveToTlObject)(params.replyMarkup);
|
|
1201
1212
|
}
|
|
1202
1213
|
else if ("forceReply" in params.replyMarkup) {
|
|
1203
|
-
replyMarkup = (0,
|
|
1214
|
+
replyMarkup = (0, _3_types_js_1.forceReplyToTlObject)(params.replyMarkup);
|
|
1204
1215
|
}
|
|
1205
1216
|
else {
|
|
1206
1217
|
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
1207
1218
|
}
|
|
1208
1219
|
}
|
|
1209
1220
|
const peer = await this.getInputPeer(chatId);
|
|
1210
|
-
const randomId = (0,
|
|
1221
|
+
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
1211
1222
|
const message = text;
|
|
1212
1223
|
const noWebpage = params?.disableWebPagePreview ? true : undefined;
|
|
1213
1224
|
const silent = params?.disableNotification ? true : undefined;
|
|
@@ -1215,15 +1226,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1215
1226
|
const replyToMsgId = params?.replyToMessageId;
|
|
1216
1227
|
const topMsgId = params?.messageThreadId;
|
|
1217
1228
|
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
|
|
1218
|
-
const entities = entities_?.length > 0 ? entities_.map((v) => (0,
|
|
1219
|
-
const result = await this.invoke(new functions.MessagesSendMessage({
|
|
1229
|
+
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
|
|
1230
|
+
const result = await this.invoke(new _2_tl_js_1.functions.MessagesSendMessage({
|
|
1220
1231
|
peer,
|
|
1221
1232
|
randomId,
|
|
1222
1233
|
message,
|
|
1223
1234
|
noWebpage,
|
|
1224
1235
|
silent,
|
|
1225
1236
|
noforwards,
|
|
1226
|
-
replyTo: replyToMsgId !== undefined ? new types.InputReplyToMessage({ replyToMsgId, topMsgId }) : undefined,
|
|
1237
|
+
replyTo: replyToMsgId !== undefined ? new _2_tl_js_1.types.InputReplyToMessage({ replyToMsgId, topMsgId }) : undefined,
|
|
1227
1238
|
sendAs,
|
|
1228
1239
|
entities,
|
|
1229
1240
|
replyMarkup,
|
|
@@ -1254,19 +1265,19 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1254
1265
|
let replyMarkup = undefined;
|
|
1255
1266
|
if (params?.replyMarkup) {
|
|
1256
1267
|
if ("inlineKeyboard" in params.replyMarkup) {
|
|
1257
|
-
replyMarkup = await (0,
|
|
1258
|
-
const inputPeer = await this.getInputPeer(v).then((v) => v[
|
|
1259
|
-
return new types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
1268
|
+
replyMarkup = await (0, _3_types_js_1.inlineKeyboardMarkupToTlObject)(params.replyMarkup, async (v) => {
|
|
1269
|
+
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
1270
|
+
return new _2_tl_js_1.types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
1260
1271
|
});
|
|
1261
1272
|
}
|
|
1262
1273
|
else if ("keyboard" in params.replyMarkup) {
|
|
1263
|
-
replyMarkup = (0,
|
|
1274
|
+
replyMarkup = (0, _3_types_js_1.replyKeyboardMarkupToTlObject)(params.replyMarkup);
|
|
1264
1275
|
}
|
|
1265
1276
|
else if ("removeKeyboard" in params.replyMarkup) {
|
|
1266
|
-
replyMarkup = (0,
|
|
1277
|
+
replyMarkup = (0, _3_types_js_1.replyKeyboardRemoveToTlObject)(params.replyMarkup);
|
|
1267
1278
|
}
|
|
1268
1279
|
else if ("forceReply" in params.replyMarkup) {
|
|
1269
|
-
replyMarkup = (0,
|
|
1280
|
+
replyMarkup = (0, _3_types_js_1.forceReplyToTlObject)(params.replyMarkup);
|
|
1270
1281
|
}
|
|
1271
1282
|
else {
|
|
1272
1283
|
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
@@ -1274,21 +1285,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1274
1285
|
}
|
|
1275
1286
|
const id = messageId;
|
|
1276
1287
|
const peer = await this.getInputPeer(chatId);
|
|
1277
|
-
const entities = entities_?.length > 0 ? entities_.map((v) => (0,
|
|
1288
|
+
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
|
|
1278
1289
|
const message = text;
|
|
1279
1290
|
const noWebpage = params?.disableWebPagePreview ? true : undefined;
|
|
1280
|
-
await this.invoke(new functions.MessagesEditMessage({ id, peer, entities, message, noWebpage, replyMarkup }));
|
|
1291
|
+
await this.invoke(new _2_tl_js_1.functions.MessagesEditMessage({ id, peer, entities, message, noWebpage, replyMarkup }));
|
|
1281
1292
|
}
|
|
1282
|
-
|
|
1283
|
-
* Retrieve multiple messages.
|
|
1284
|
-
*
|
|
1285
|
-
* @param chatId The identifier of the chat to retrieve the messages from.
|
|
1286
|
-
* @param messageIds The identifiers of the messages to retrieve.
|
|
1287
|
-
*/
|
|
1288
|
-
async getMessages(chatId_, messageIds) {
|
|
1293
|
+
async getMessagesInner(chatId_, messageIds) {
|
|
1289
1294
|
const peer = await this.getInputPeer(chatId_);
|
|
1290
1295
|
let messages_ = new Array();
|
|
1291
|
-
const chatId = (0,
|
|
1296
|
+
const chatId = (0, _2_tl_js_1.peerToChatId)(peer);
|
|
1292
1297
|
let shouldFetch = false;
|
|
1293
1298
|
for (const messageId of messageIds) {
|
|
1294
1299
|
const message = await this.storage.getMessage(chatId, messageId);
|
|
@@ -1302,24 +1307,39 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1302
1307
|
}
|
|
1303
1308
|
}
|
|
1304
1309
|
if (shouldFetch) {
|
|
1305
|
-
if (peer instanceof types.InputPeerChannel) {
|
|
1306
|
-
messages_ = await this.invoke(new functions.ChannelsGetMessages({
|
|
1307
|
-
channel: new types.InputChannel({ channelId: peer.channelId, accessHash: peer.accessHash }),
|
|
1308
|
-
id: messageIds.map((v) => new types.InputMessageID({ id: v })),
|
|
1309
|
-
})).then((v) => v[
|
|
1310
|
+
if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
|
|
1311
|
+
messages_ = await this.invoke(new _2_tl_js_1.functions.ChannelsGetMessages({
|
|
1312
|
+
channel: new _2_tl_js_1.types.InputChannel({ channelId: peer.channelId, accessHash: peer.accessHash }),
|
|
1313
|
+
id: messageIds.map((v) => new _2_tl_js_1.types.InputMessageID({ id: v })),
|
|
1314
|
+
})).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.MessagesChannelMessages).messages);
|
|
1310
1315
|
}
|
|
1311
1316
|
else {
|
|
1312
|
-
messages_ = await this.invoke(new functions.MessagesGetMessages({
|
|
1313
|
-
id: messageIds.map((v) => new types.InputMessageID({ id: v })),
|
|
1314
|
-
})).then((v) => v[
|
|
1317
|
+
messages_ = await this.invoke(new _2_tl_js_1.functions.MessagesGetMessages({
|
|
1318
|
+
id: messageIds.map((v) => new _2_tl_js_1.types.InputMessageID({ id: v })),
|
|
1319
|
+
})).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.MessagesMessages).messages);
|
|
1315
1320
|
}
|
|
1316
1321
|
}
|
|
1317
1322
|
const messages = new Array();
|
|
1318
1323
|
for (const message_ of messages_) {
|
|
1319
|
-
|
|
1324
|
+
const message = await (0, _3_types_js_1.constructMessage)(message_, this[exports.getEntity].bind(this), null, this[exports.getStickerSetName].bind(this));
|
|
1325
|
+
const isReplyToMessage = message_ instanceof _2_tl_js_1.types.Message && message_.replyTo instanceof _2_tl_js_1.types.MessageReplyHeader;
|
|
1326
|
+
messages.push({ message, isReplyToMessage });
|
|
1320
1327
|
}
|
|
1321
1328
|
return messages;
|
|
1322
1329
|
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Retrieve multiple messages.
|
|
1332
|
+
*
|
|
1333
|
+
* @param chatId The identifier of the chat to retrieve the messages from.
|
|
1334
|
+
* @param messageIds The identifiers of the messages to retrieve.
|
|
1335
|
+
*/
|
|
1336
|
+
async getMessages(chatId_, messageIds) {
|
|
1337
|
+
return await this.getMessagesInner(chatId_, messageIds).then((v) => v.map((v) => v.message));
|
|
1338
|
+
}
|
|
1339
|
+
async [exports.getMessageWithReply](chatId, messageId) {
|
|
1340
|
+
const messages = await this.getMessagesInner(chatId, [messageId]);
|
|
1341
|
+
return messages[0]?.message ?? null;
|
|
1342
|
+
}
|
|
1323
1343
|
/**
|
|
1324
1344
|
* Retrieve a single message.
|
|
1325
1345
|
*
|
|
@@ -1333,8 +1353,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1333
1353
|
async *downloadInner(location, dcId) {
|
|
1334
1354
|
let client = null;
|
|
1335
1355
|
if (dcId != undefined && dcId != this.dcId) {
|
|
1336
|
-
const exportedAuth = await this.invoke(new functions.AuthExportAuthorization({ dcId }));
|
|
1337
|
-
client = new Client(new
|
|
1356
|
+
const exportedAuth = await this.invoke(new _2_tl_js_1.functions.AuthExportAuthorization({ dcId }));
|
|
1357
|
+
client = new Client(new _3_storage_js_1.StorageMemory(), this.apiId, this.apiHash, {
|
|
1338
1358
|
transportProvider: this.transportProvider,
|
|
1339
1359
|
appVersion: this.appVersion,
|
|
1340
1360
|
deviceModel: this.deviceModel,
|
|
@@ -1355,8 +1375,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1355
1375
|
const limit = 1024 * 1024;
|
|
1356
1376
|
let offset = 0n;
|
|
1357
1377
|
while (true) {
|
|
1358
|
-
const file = await (client ?? this).invoke(new functions.UploadGetFile({ location, offset, limit }));
|
|
1359
|
-
if (file instanceof types.UploadFile) {
|
|
1378
|
+
const file = await (client ?? this).invoke(new _2_tl_js_1.functions.UploadGetFile({ location, offset, limit }));
|
|
1379
|
+
if (file instanceof _2_tl_js_1.types.UploadFile) {
|
|
1360
1380
|
yield file.bytes;
|
|
1361
1381
|
if (file.bytes.length < limit) {
|
|
1362
1382
|
break;
|
|
@@ -1366,7 +1386,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1366
1386
|
}
|
|
1367
1387
|
}
|
|
1368
1388
|
else {
|
|
1369
|
-
(0,
|
|
1389
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1370
1390
|
}
|
|
1371
1391
|
}
|
|
1372
1392
|
}
|
|
@@ -1376,19 +1396,19 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1376
1396
|
* @param fileId The identifier of the file to download.
|
|
1377
1397
|
*/
|
|
1378
1398
|
async download(fileId) {
|
|
1379
|
-
const fileId_ =
|
|
1399
|
+
const fileId_ = _3_types_js_1.FileID.decode(fileId);
|
|
1380
1400
|
switch (fileId_.fileType) {
|
|
1381
|
-
case
|
|
1382
|
-
const big = fileId_.params.thumbnailSource ==
|
|
1401
|
+
case _3_types_js_1.FileType.ChatPhoto: {
|
|
1402
|
+
const big = fileId_.params.thumbnailSource == _3_types_js_1.ThumbnailSource.ChatPhotoBig;
|
|
1383
1403
|
const peer = await this.getInputPeer(fileId_.params.chatId);
|
|
1384
|
-
const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId_.params.mediaId });
|
|
1404
|
+
const location = new _2_tl_js_1.types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId_.params.mediaId });
|
|
1385
1405
|
return this.downloadInner(location);
|
|
1386
1406
|
}
|
|
1387
|
-
case
|
|
1407
|
+
case _3_types_js_1.FileType.Photo: {
|
|
1388
1408
|
if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
|
|
1389
|
-
(0,
|
|
1409
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1390
1410
|
}
|
|
1391
|
-
const location = new types.InputPhotoFileLocation({
|
|
1411
|
+
const location = new _2_tl_js_1.types.InputPhotoFileLocation({
|
|
1392
1412
|
id: fileId_.params.mediaId,
|
|
1393
1413
|
accessHash: fileId_.params.accessHash,
|
|
1394
1414
|
fileReference: fileId_.params.fileReference,
|
|
@@ -1397,17 +1417,17 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1397
1417
|
return this.downloadInner(location);
|
|
1398
1418
|
}
|
|
1399
1419
|
default:
|
|
1400
|
-
(0,
|
|
1420
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1401
1421
|
}
|
|
1402
1422
|
}
|
|
1403
1423
|
async [exports.getStickerSetName](inputStickerSet, hash = 0) {
|
|
1404
1424
|
const maybeStickerSetName = await this.storage.getStickerSetName(inputStickerSet.id, inputStickerSet.accessHash);
|
|
1405
|
-
if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() <
|
|
1425
|
+
if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < _4_constants_js_1.STICKER_SET_NAME_TTL) {
|
|
1406
1426
|
return maybeStickerSetName[0];
|
|
1407
1427
|
}
|
|
1408
1428
|
else {
|
|
1409
|
-
const stickerSet = await this.invoke(new functions.MessagesGetStickerSet({ stickerset: inputStickerSet, hash }));
|
|
1410
|
-
const name = stickerSet[
|
|
1429
|
+
const stickerSet = await this.invoke(new _2_tl_js_1.functions.MessagesGetStickerSet({ stickerset: inputStickerSet, hash }));
|
|
1430
|
+
const name = stickerSet[_2_tl_js_1.as](_2_tl_js_1.types.MessagesStickerSet).set.shortName;
|
|
1411
1431
|
await this.storage.updateStickerSetName(inputStickerSet.id, inputStickerSet.accessHash, name);
|
|
1412
1432
|
return name;
|
|
1413
1433
|
}
|
|
@@ -1420,11 +1440,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1420
1440
|
* @param messageIds The identifiers of the messages to forward.
|
|
1421
1441
|
*/
|
|
1422
1442
|
async forwardMessages(from, to, messageIds, params) {
|
|
1423
|
-
const result = await this.invoke(new functions.MessagesForwardMessages({
|
|
1443
|
+
const result = await this.invoke(new _2_tl_js_1.functions.MessagesForwardMessages({
|
|
1424
1444
|
fromPeer: await this.getInputPeer(from),
|
|
1425
1445
|
toPeer: await this.getInputPeer(to),
|
|
1426
1446
|
id: messageIds,
|
|
1427
|
-
randomId: messageIds.map(() => (0,
|
|
1447
|
+
randomId: messageIds.map(() => (0, _1_utilities_js_1.getRandomId)()),
|
|
1428
1448
|
silent: params?.disableNotification || undefined,
|
|
1429
1449
|
topMsgId: params?.messageThreadId,
|
|
1430
1450
|
noforwards: params?.disableNotification || undefined,
|
|
@@ -1448,35 +1468,35 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1448
1468
|
* Get information on the currently authorized user.
|
|
1449
1469
|
*/
|
|
1450
1470
|
async getMe() {
|
|
1451
|
-
const users = await this.invoke(new functions.UsersGetUsers({ id: [new types.InputUserSelf()] }));
|
|
1471
|
+
const users = await this.invoke(new _2_tl_js_1.functions.UsersGetUsers({ id: [new _2_tl_js_1.types.InputUserSelf()] }));
|
|
1452
1472
|
if (users.length < 1) {
|
|
1453
|
-
(0,
|
|
1473
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1454
1474
|
}
|
|
1455
|
-
return (0,
|
|
1475
|
+
return (0, _3_types_js_1.constructUser)(users[0][_2_tl_js_1.as](_2_tl_js_1.types.User));
|
|
1456
1476
|
}
|
|
1457
1477
|
// TODO: log errors
|
|
1458
1478
|
async handleUpdate(update) {
|
|
1459
|
-
if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateNewChannelMessage) {
|
|
1460
|
-
if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
|
|
1461
|
-
await this.storage.setMessage((0,
|
|
1479
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
|
|
1480
|
+
if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
|
|
1481
|
+
await this.storage.setMessage((0, _2_tl_js_1.peerToChatId)(update.message.peerId), update.message.id, update.message);
|
|
1462
1482
|
}
|
|
1463
1483
|
}
|
|
1464
|
-
if (update instanceof types.UpdateNewMessage ||
|
|
1465
|
-
update instanceof types.UpdateNewChannelMessage ||
|
|
1466
|
-
update instanceof types.UpdateEditMessage ||
|
|
1467
|
-
update instanceof types.UpdateEditChannelMessage) {
|
|
1468
|
-
const key = update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
1469
|
-
const message = await (0,
|
|
1484
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage ||
|
|
1485
|
+
update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ||
|
|
1486
|
+
update instanceof _2_tl_js_1.types.UpdateEditMessage ||
|
|
1487
|
+
update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
1488
|
+
const key = update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
1489
|
+
const message = await (0, _3_types_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
|
|
1470
1490
|
await this.handler({ [key]: message }, resolve);
|
|
1471
1491
|
}
|
|
1472
|
-
if (update instanceof types.UpdateDeleteMessages) {
|
|
1492
|
+
if (update instanceof _2_tl_js_1.types.UpdateDeleteMessages) {
|
|
1473
1493
|
const deletedMessages = new Array();
|
|
1474
1494
|
for (const messageId of update.messages) {
|
|
1475
1495
|
const chatId = await this.storage.getMessageChat(messageId);
|
|
1476
1496
|
if (chatId) {
|
|
1477
1497
|
const message = await this.storage.getMessage(chatId, messageId);
|
|
1478
1498
|
if (message != null) {
|
|
1479
|
-
deletedMessages.push(await (0,
|
|
1499
|
+
deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this)));
|
|
1480
1500
|
}
|
|
1481
1501
|
await this.storage.setMessage(chatId, messageId, null);
|
|
1482
1502
|
}
|
|
@@ -1485,13 +1505,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1485
1505
|
await this.handler({ deletedMessages: deletedMessages }, resolve);
|
|
1486
1506
|
}
|
|
1487
1507
|
}
|
|
1488
|
-
else if (update instanceof types.UpdateDeleteChannelMessages) {
|
|
1489
|
-
const chatId = (0,
|
|
1508
|
+
else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
|
|
1509
|
+
const chatId = (0, _2_tl_js_1.getChannelChatId)(update.channelId);
|
|
1490
1510
|
const deletedMessages = new Array();
|
|
1491
1511
|
for (const messageId of update.messages) {
|
|
1492
1512
|
const message = await this.storage.getMessage(chatId, messageId);
|
|
1493
1513
|
if (message) {
|
|
1494
|
-
deletedMessages.push(await (0,
|
|
1514
|
+
deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this)));
|
|
1495
1515
|
}
|
|
1496
1516
|
await this.storage.setMessage(chatId, messageId, null);
|
|
1497
1517
|
}
|
|
@@ -1499,6 +1519,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1499
1519
|
await this.handler({ deletedMessages: deletedMessages }, resolve);
|
|
1500
1520
|
}
|
|
1501
1521
|
}
|
|
1522
|
+
if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
|
|
1523
|
+
await this.handler({ callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[exports.getEntity].bind(this), this[exports.getMessageWithReply].bind(this)) }, resolve);
|
|
1524
|
+
}
|
|
1525
|
+
else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
|
|
1526
|
+
await this.handler({ inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[exports.getEntity].bind(this)) }, resolve);
|
|
1527
|
+
}
|
|
1502
1528
|
}
|
|
1503
1529
|
use(middleware) {
|
|
1504
1530
|
const handler = this.handler;
|
|
@@ -1512,9 +1538,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1512
1538
|
});
|
|
1513
1539
|
};
|
|
1514
1540
|
}
|
|
1515
|
-
on(
|
|
1516
|
-
// deno-lint-ignore no-explicit-any
|
|
1517
|
-
filter, handler) {
|
|
1541
|
+
on(filter, handler) {
|
|
1518
1542
|
const type = typeof filter === "string" ? filter : filter[0];
|
|
1519
1543
|
const keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
1520
1544
|
this.use((update, next) => {
|
|
@@ -1537,6 +1561,19 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1537
1561
|
}
|
|
1538
1562
|
});
|
|
1539
1563
|
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Answer a callback query. Bot-only.
|
|
1566
|
+
*
|
|
1567
|
+
* @param id ID of the callback query to answer.
|
|
1568
|
+
*/
|
|
1569
|
+
async answerCallbackQuery(id, params) {
|
|
1570
|
+
await this.invoke(new _2_tl_js_1.functions.MessagesSetBotCallbackAnswer({
|
|
1571
|
+
queryId: BigInt(id),
|
|
1572
|
+
cacheTime: params?.cacheTime ?? 0,
|
|
1573
|
+
message: params?.text,
|
|
1574
|
+
alert: params?.alert ? true : undefined,
|
|
1575
|
+
}));
|
|
1576
|
+
}
|
|
1540
1577
|
}
|
|
1541
1578
|
exports.Client = Client;
|
|
1542
1579
|
const resolve = () => Promise.resolve();
|