@mtkruto/node 0.0.835 → 0.0.901
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/client/client.d.ts +23 -3
- package/esm/client/client.js +497 -76
- package/esm/client/client_abstract.d.ts +2 -0
- package/esm/client/client_abstract.js +14 -3
- package/esm/client/client_plain.js +18 -4
- package/esm/constants.d.ts +7 -5
- package/esm/constants.js +10 -6
- package/esm/deps/deno.land/std@0.190.0/encoding/base64.d.ts +11 -0
- package/esm/deps/deno.land/std@0.190.0/encoding/base64.js +140 -0
- package/esm/deps/deno.land/x/q@v0.0.1/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/q@v0.0.1/mod.js +71 -0
- package/esm/deps.d.ts +2 -0
- package/esm/deps.js +2 -0
- package/esm/mod.d.ts +3 -3
- package/esm/mod.js +3 -3
- package/esm/storage/storage.d.ts +18 -0
- package/esm/storage/storage.js +103 -0
- package/esm/tl/1_tl_object.d.ts +0 -1
- package/esm/tl/1_tl_object.js +1 -1
- package/esm/tl/4_tl_writer.d.ts +5 -0
- package/esm/tl/5_rpc_result.d.ts +9 -0
- package/esm/tl/6_message.d.ts +10 -0
- package/esm/tl/{5_message.js → 6_message.js} +2 -2
- package/esm/tl/{6_message_container.d.ts → 7_message_container.d.ts} +1 -1
- package/esm/tl/{6_message_container.js → 7_message_container.js} +2 -2
- package/esm/transport/transport_provider.d.ts +7 -4
- package/esm/transport/transport_provider.js +11 -8
- package/esm/types/3_message.d.ts +5 -1
- package/esm/types/3_message.js +26 -22
- package/esm/utilities/1_message.d.ts +2 -2
- package/esm/utilities/1_message.js +3 -3
- package/esm/utilities/1_password.js +1 -1
- package/package.json +1 -1
- package/script/client/client.d.ts +23 -3
- package/script/client/client.js +497 -76
- package/script/client/client_abstract.d.ts +2 -0
- package/script/client/client_abstract.js +14 -3
- package/script/client/client_plain.js +18 -4
- package/script/constants.d.ts +7 -5
- package/script/constants.js +34 -7
- package/script/deps/deno.land/std@0.190.0/encoding/base64.d.ts +11 -0
- package/script/deps/deno.land/std@0.190.0/encoding/base64.js +145 -0
- package/script/deps/deno.land/x/q@v0.0.1/mod.d.ts +6 -0
- package/script/deps/deno.land/x/q@v0.0.1/mod.js +75 -0
- package/script/deps.d.ts +2 -0
- package/script/deps.js +6 -1
- package/script/mod.d.ts +3 -3
- package/script/mod.js +3 -3
- package/script/storage/storage.d.ts +18 -0
- package/script/storage/storage.js +126 -0
- package/script/tl/1_tl_object.d.ts +0 -1
- package/script/tl/1_tl_object.js +1 -1
- package/script/tl/4_tl_writer.d.ts +5 -0
- package/script/tl/5_rpc_result.d.ts +9 -0
- package/script/tl/6_message.d.ts +10 -0
- package/script/tl/{5_message.js → 6_message.js} +6 -6
- package/script/tl/{6_message_container.d.ts → 7_message_container.d.ts} +1 -1
- package/script/tl/{6_message_container.js → 7_message_container.js} +4 -4
- package/script/transport/transport_provider.d.ts +7 -4
- package/script/transport/transport_provider.js +11 -8
- package/script/types/3_message.d.ts +5 -1
- package/script/types/3_message.js +26 -22
- package/script/utilities/1_message.d.ts +2 -2
- package/script/utilities/1_message.js +9 -9
- package/script/utilities/1_password.js +1 -1
- package/esm/tl/3_tl_writer.d.ts +0 -5
- package/esm/tl/4_rpc_result.d.ts +0 -8
- package/esm/tl/5_message.d.ts +0 -11
- package/script/tl/3_tl_writer.d.ts +0 -5
- package/script/tl/4_rpc_result.d.ts +0 -8
- package/script/tl/5_message.d.ts +0 -11
- /package/esm/tl/{3_tl_writer.js → 4_tl_writer.js} +0 -0
- /package/esm/tl/{4_rpc_result.js → 5_rpc_result.js} +0 -0
- /package/script/tl/{3_tl_writer.js → 4_tl_writer.js} +0 -0
- /package/script/tl/{4_rpc_result.js → 5_rpc_result.js} +0 -0
|
@@ -11,13 +11,16 @@ const dcToNameMap = {
|
|
|
11
11
|
"5": "flora",
|
|
12
12
|
};
|
|
13
13
|
export const defaultTransportProvider = ({ initialDc, wss }) => {
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
return {
|
|
15
|
+
initialDc,
|
|
16
|
+
createTransport: ({ dc, cdn }) => {
|
|
17
|
+
dc ??= initialDc;
|
|
18
|
+
wss ??= typeof location !== "undefined" && location.protocol == "http:" ? false : true;
|
|
19
|
+
const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
|
|
20
|
+
const connection = new ConnectionWebSocket(url);
|
|
21
|
+
const transport = new TransportIntermediate(connection, true);
|
|
22
|
+
const dcId = Number(dc[0]) + (dc.endsWith("-test") ? 10000 : 0) * (cdn ? -1 : 1);
|
|
23
|
+
return { connection, transport, dcId };
|
|
24
|
+
},
|
|
22
25
|
};
|
|
23
26
|
};
|
package/esm/types/3_message.d.ts
CHANGED
|
@@ -19,4 +19,8 @@ export interface Message {
|
|
|
19
19
|
views?: number;
|
|
20
20
|
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
21
21
|
}
|
|
22
|
-
export declare function constructMessage(message_: types.Message,
|
|
22
|
+
export declare function constructMessage(message_: types.Message, getEntity: {
|
|
23
|
+
(peer: types.PeerUser): Promise<types.User | null>;
|
|
24
|
+
(peer: types.PeerChat): Promise<types.Chat | null>;
|
|
25
|
+
(peer: types.PeerChannel): Promise<types.Channel | null>;
|
|
26
|
+
}): Promise<Message>;
|
package/esm/types/3_message.js
CHANGED
|
@@ -8,42 +8,46 @@ import { constructChat } from "./1_chat.js";
|
|
|
8
8
|
import { constructUser } from "./1_user.js";
|
|
9
9
|
import { constructInlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
|
|
10
10
|
import { constructReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
|
|
11
|
-
export function constructMessage(message_,
|
|
11
|
+
export async function constructMessage(message_, getEntity) {
|
|
12
12
|
let chat_ = null;
|
|
13
13
|
if (message_.peerId instanceof types.PeerUser) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const entity = await getEntity(message_.peerId);
|
|
15
|
+
if (entity) {
|
|
16
|
+
chat_ = constructChat(entity);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
UNREACHABLE();
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
else if (message_.peerId instanceof types.PeerChat) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const entity = await getEntity(message_.peerId);
|
|
24
|
+
if (entity) {
|
|
25
|
+
chat_ = constructChat(entity);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
UNREACHABLE();
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
else if (message_.peerId instanceof types.PeerChannel) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const entity = await getEntity(message_.peerId);
|
|
33
|
+
if (entity) {
|
|
34
|
+
chat_ = constructChat(entity);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
UNREACHABLE();
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
|
|
40
|
+
else {
|
|
38
41
|
UNREACHABLE();
|
|
39
42
|
}
|
|
40
43
|
const message = { id: message_.id, chat: chat_, views: message_.views };
|
|
41
44
|
if (message_.fromId instanceof types.PeerUser) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
const entity = await getEntity(message_.fromId);
|
|
46
|
+
if (entity) {
|
|
47
|
+
message.from = constructUser(entity);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
UNREACHABLE();
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
if (message_.message) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Message } from "../tl/
|
|
2
|
-
import { MessageContainer } from "../tl/
|
|
1
|
+
import { Message } from "../tl/6_message.js";
|
|
2
|
+
import { MessageContainer } from "../tl/7_message_container.js";
|
|
3
3
|
export declare function getMessageId(): bigint;
|
|
4
4
|
export declare function packUnencryptedMessage(data: Uint8Array): Uint8Array;
|
|
5
5
|
export declare function unpackUnencryptedMessage(buffer: Uint8Array): {
|
|
@@ -3,9 +3,9 @@ import { TLRawReader } from "../tl/0_tl_raw_reader.js";
|
|
|
3
3
|
import { TLRawWriter } from "../tl/0_tl_raw_writer.js";
|
|
4
4
|
import { id, serialize } from "../tl/1_tl_object.js";
|
|
5
5
|
import { TLReader } from "../tl/3_tl_reader.js";
|
|
6
|
-
import { RPCResult } from "../tl/
|
|
7
|
-
import { Message } from "../tl/
|
|
8
|
-
import { MessageContainer } from "../tl/
|
|
6
|
+
import { RPCResult } from "../tl/5_rpc_result.js";
|
|
7
|
+
import { Message } from "../tl/6_message.js";
|
|
8
|
+
import { MessageContainer } from "../tl/7_message_container.js";
|
|
9
9
|
import { bufferFromBigInt, concat } from "./0_buffer.js";
|
|
10
10
|
import { sha256 } from "./0_hash.js";
|
|
11
11
|
let lastMsgId = 0n;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
2
|
import * as types from "../tl/2_types.js";
|
|
3
3
|
import * as functions from "../tl/3_functions.js";
|
|
4
|
+
import { ReadObject } from "../tl/3_tl_reader.js";
|
|
4
5
|
import { ClientAbstract } from "./client_abstract.js";
|
|
5
6
|
import { Storage } from "../storage/storage.js";
|
|
6
7
|
import { DC, TransportProvider } from "../transport/transport_provider.js";
|
|
@@ -9,6 +10,8 @@ import { ReplyKeyboardRemove } from "../types/0_reply_keyboard_remove.js";
|
|
|
9
10
|
import { ForceReply } from "../types/0_force_reply.js";
|
|
10
11
|
import { ReplyKeyboardMarkup } from "../types/2_reply_keyboard_markup.js";
|
|
11
12
|
import { InlineKeyboardMarkup } from "../types/2_inline_keyboard_markup.js";
|
|
13
|
+
import { Message } from "../types/3_message.js";
|
|
14
|
+
export declare const getEntity: unique symbol;
|
|
12
15
|
export declare const restartAuth: unique symbol;
|
|
13
16
|
export declare enum ParseMode {
|
|
14
17
|
None = "none",
|
|
@@ -19,7 +22,7 @@ export interface AuthorizeUserParams<S = string> {
|
|
|
19
22
|
code: S | (() => MaybePromise<S>);
|
|
20
23
|
password: S | (() => MaybePromise<S>);
|
|
21
24
|
}
|
|
22
|
-
export type
|
|
25
|
+
export type UpdateHandler = null | ((client: Client, update: types.TypeUpdate) => MaybePromise<void>);
|
|
23
26
|
export interface ClientParams {
|
|
24
27
|
/**
|
|
25
28
|
* Default parse mode. Defauls to `ParseMode.None`.
|
|
@@ -63,7 +66,8 @@ export declare class Client extends ClientAbstract {
|
|
|
63
66
|
private state;
|
|
64
67
|
private promises;
|
|
65
68
|
private toAcknowledge;
|
|
66
|
-
|
|
69
|
+
private updateState?;
|
|
70
|
+
updateHandler: UpdateHandler;
|
|
67
71
|
readonly parseMode: ParseMode;
|
|
68
72
|
readonly appVersion: string;
|
|
69
73
|
readonly deviceModel: string;
|
|
@@ -95,6 +99,7 @@ export declare class Client extends ClientAbstract {
|
|
|
95
99
|
* Before establishing the connection, the session is saved.
|
|
96
100
|
*/
|
|
97
101
|
connect(): Promise<void>;
|
|
102
|
+
private fetchState;
|
|
98
103
|
/**
|
|
99
104
|
* Calls [initConnection](1) and authorizes the client with one of the following:
|
|
100
105
|
*
|
|
@@ -113,6 +118,7 @@ export declare class Client extends ClientAbstract {
|
|
|
113
118
|
* [2]: https://core.telegram.org/method/updates.getState
|
|
114
119
|
*/
|
|
115
120
|
authorize(params: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
|
|
121
|
+
private messageProcessQueue;
|
|
116
122
|
private receiveLoop;
|
|
117
123
|
private pingLoop;
|
|
118
124
|
/**
|
|
@@ -129,8 +135,20 @@ export declare class Client extends ClientAbstract {
|
|
|
129
135
|
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
|
|
130
136
|
private processChats;
|
|
131
137
|
private processUsers;
|
|
138
|
+
private updateApplicationMutex;
|
|
139
|
+
private applyUpdateNoGap;
|
|
140
|
+
private applyUpdate;
|
|
132
141
|
private processUpdates;
|
|
142
|
+
private setUpdateStateDate;
|
|
143
|
+
private getLocalState;
|
|
144
|
+
private updateGapRecoveryMutex;
|
|
145
|
+
private recoverUpdateGap;
|
|
146
|
+
private recoverChannelUpdateGap;
|
|
133
147
|
getInputPeer(id: string | number): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
|
|
148
|
+
[getEntity](peer: types.PeerUser): Promise<types.User | null>;
|
|
149
|
+
[getEntity](peer: types.PeerChat): Promise<types.Chat | null>;
|
|
150
|
+
[getEntity](peer: types.PeerChannel): Promise<types.Channel | null>;
|
|
151
|
+
processResult(result: ReadObject): Promise<void>;
|
|
134
152
|
sendMessage(chatId: number | string, text: string, params?: {
|
|
135
153
|
parseMode?: ParseMode;
|
|
136
154
|
entities?: MessageEntity[];
|
|
@@ -141,5 +159,7 @@ export declare class Client extends ClientAbstract {
|
|
|
141
159
|
messageThreadId?: number;
|
|
142
160
|
sendAs?: number | string;
|
|
143
161
|
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
144
|
-
}): Promise<
|
|
162
|
+
}): Promise<Message>;
|
|
163
|
+
getMessages(chatId: number | string, messageIds: number[]): Promise<Message[]>;
|
|
164
|
+
getMessage(chatId: number | string, messageId: number): Promise<Message | null>;
|
|
145
165
|
}
|