@mtkruto/node 0.1.124 → 0.1.125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/0_deps.d.ts +1 -0
- package/esm/0_deps.js +1 -0
- package/esm/1_utilities.d.ts +1 -1
- package/esm/1_utilities.js +1 -1
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/client/1_client_abstract.d.ts +1 -1
- package/esm/client/3_types.d.ts +56 -0
- package/esm/client/5_client.d.ts +17 -1
- package/esm/client/5_client.js +152 -49
- package/esm/connection/0_connection.d.ts +4 -0
- package/esm/connection/0_connection.js +6 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/_db.d.ts +5 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/_db.js +33 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/_util.d.ts +21 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/_util.js +122 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/content_type.d.ts +38 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/content_type.js +60 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/format_media_type.d.ts +16 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/format_media_type.js +61 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/get_charset.d.ts +15 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/get_charset.js +37 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/parse_media_type.d.ts +37 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/parse_media_type.js +122 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/vendor/mime-db.v1.52.0.d.ts +8518 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/vendor/mime-db.v1.52.0.js +8555 -0
- package/esm/storage/0_storage.d.ts +1 -0
- package/esm/storage/1_storage_indexed_db.d.ts +4 -3
- package/esm/storage/1_storage_indexed_db.js +17 -8
- package/esm/storage/1_storage_local_storage.d.ts +2 -2
- package/esm/storage/1_storage_local_storage.js +3 -0
- package/esm/storage/1_storage_memory.d.ts +1 -0
- package/esm/storage/1_storage_memory.js +3 -0
- package/esm/storage/1_storage_session_storage.d.ts +1 -0
- package/esm/storage/1_storage_session_storage.js +3 -0
- package/esm/transport/0_transport.d.ts +1 -1
- package/esm/transport/0_transport.js +0 -6
- package/esm/transport/1_transport_abridged.d.ts +1 -0
- package/esm/transport/1_transport_abridged.js +9 -5
- package/esm/transport/1_transport_intermediate.d.ts +1 -0
- package/esm/transport/1_transport_intermediate.js +8 -4
- package/esm/types/1_chat.d.ts +2 -15
- package/esm/types/1_chat.js +3 -14
- package/esm/types/1_user.js +4 -2
- package/esm/types/3_message.d.ts +2 -2
- package/esm/types/3_message.js +6 -6
- package/esm/utilities/{0_base64.js → 1_base64.js} +2 -1
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -0
- package/script/0_deps.js +3 -1
- package/script/1_utilities.d.ts +1 -1
- package/script/1_utilities.js +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/1_client_abstract.d.ts +1 -1
- package/script/client/3_types.d.ts +56 -0
- package/script/client/5_client.d.ts +17 -1
- package/script/client/5_client.js +151 -48
- package/script/connection/0_connection.d.ts +4 -0
- package/script/connection/0_connection.js +6 -0
- package/script/deps/deno.land/std@0.208.0/media_types/_db.d.ts +5 -0
- package/script/deps/deno.land/std@0.208.0/media_types/_db.js +39 -0
- package/script/deps/deno.land/std@0.208.0/media_types/_util.d.ts +21 -0
- package/script/deps/deno.land/std@0.208.0/media_types/_util.js +132 -0
- package/script/deps/deno.land/std@0.208.0/media_types/content_type.d.ts +38 -0
- package/script/deps/deno.land/std@0.208.0/media_types/content_type.js +64 -0
- package/script/deps/deno.land/std@0.208.0/media_types/format_media_type.d.ts +16 -0
- package/script/deps/deno.land/std@0.208.0/media_types/format_media_type.js +65 -0
- package/script/deps/deno.land/std@0.208.0/media_types/get_charset.d.ts +15 -0
- package/script/deps/deno.land/std@0.208.0/media_types/get_charset.js +41 -0
- package/script/deps/deno.land/std@0.208.0/media_types/parse_media_type.d.ts +37 -0
- package/script/deps/deno.land/std@0.208.0/media_types/parse_media_type.js +126 -0
- package/script/deps/deno.land/std@0.208.0/media_types/vendor/mime-db.v1.52.0.d.ts +8518 -0
- package/script/deps/deno.land/std@0.208.0/media_types/vendor/mime-db.v1.52.0.js +8557 -0
- package/script/storage/0_storage.d.ts +1 -0
- package/script/storage/1_storage_indexed_db.d.ts +4 -3
- package/script/storage/1_storage_indexed_db.js +17 -8
- package/script/storage/1_storage_local_storage.d.ts +2 -2
- package/script/storage/1_storage_local_storage.js +3 -0
- package/script/storage/1_storage_memory.d.ts +1 -0
- package/script/storage/1_storage_memory.js +3 -0
- package/script/storage/1_storage_session_storage.d.ts +1 -0
- package/script/storage/1_storage_session_storage.js +3 -0
- package/script/transport/0_transport.d.ts +1 -1
- package/script/transport/0_transport.js +0 -6
- package/script/transport/1_transport_abridged.d.ts +1 -0
- package/script/transport/1_transport_abridged.js +9 -5
- package/script/transport/1_transport_intermediate.d.ts +1 -0
- package/script/transport/1_transport_intermediate.js +8 -4
- package/script/types/1_chat.d.ts +2 -15
- package/script/types/1_chat.js +3 -14
- package/script/types/1_user.js +4 -2
- package/script/types/3_message.d.ts +2 -2
- package/script/types/3_message.js +6 -6
- package/script/utilities/{0_base64.js → 1_base64.js} +2 -1
- /package/esm/utilities/{0_base64.d.ts → 1_base64.d.ts} +0 -0
- /package/script/utilities/{0_base64.d.ts → 1_base64.d.ts} +0 -0
package/esm/0_deps.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./deps/deno.land/std@0.208.0/assert/mod.js";
|
|
2
2
|
export * as path from "./deps/deno.land/std@0.208.0/path/mod.js";
|
|
3
3
|
export { decodeBase64, encodeBase64 } from "./deps/deno.land/std@0.208.0/encoding/base64.js";
|
|
4
|
+
export { contentType } from "./deps/deno.land/std@0.208.0/media_types/content_type.js";
|
|
4
5
|
export { ctr256, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.3.3/mod.js";
|
|
5
6
|
export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/main/gzip/gzip.js";
|
|
6
7
|
export { Mutex, type MutexInterface } from "async-mutex";
|
package/esm/0_deps.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./deps/deno.land/std@0.208.0/assert/mod.js";
|
|
2
2
|
export * as path from "./deps/deno.land/std@0.208.0/path/mod.js";
|
|
3
3
|
export { decodeBase64, encodeBase64 } from "./deps/deno.land/std@0.208.0/encoding/base64.js";
|
|
4
|
+
export { contentType } from "./deps/deno.land/std@0.208.0/media_types/content_type.js";
|
|
4
5
|
export { ctr256, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.3.3/mod.js";
|
|
5
6
|
export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/main/gzip/gzip.js";
|
|
6
7
|
export { Mutex } from "async-mutex";
|
package/esm/1_utilities.d.ts
CHANGED
package/esm/1_utilities.js
CHANGED
package/esm/4_constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
|
|
|
4
4
|
export declare const PUBLIC_KEYS: PublicKeys;
|
|
5
5
|
export declare const INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 167;
|
|
7
|
-
export declare const APP_VERSION = "MTKruto 0.1.
|
|
7
|
+
export declare const APP_VERSION = "MTKruto 0.1.125";
|
|
8
8
|
export declare const DEVICE_MODEL: string;
|
|
9
9
|
export declare const LANG_CODE: string;
|
|
10
10
|
export declare const LANG_PACK = "";
|
package/esm/4_constants.js
CHANGED
|
@@ -53,7 +53,7 @@ export const PUBLIC_KEYS = Object.freeze([
|
|
|
53
53
|
]);
|
|
54
54
|
export const INITIAL_DC = "2";
|
|
55
55
|
export const LAYER = 167;
|
|
56
|
-
export const APP_VERSION = "MTKruto 0.1.
|
|
56
|
+
export const APP_VERSION = "MTKruto 0.1.125";
|
|
57
57
|
// @ts-ignore: lib
|
|
58
58
|
export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
59
59
|
export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
@@ -17,7 +17,7 @@ export interface ClientAbstractParams {
|
|
|
17
17
|
export declare abstract class ClientAbstract {
|
|
18
18
|
#private;
|
|
19
19
|
protected readonly initialDc: DC;
|
|
20
|
-
protected
|
|
20
|
+
protected transportProvider: TransportProvider;
|
|
21
21
|
protected readonly cdn: boolean;
|
|
22
22
|
protected transport?: ReturnType<TransportProvider>;
|
|
23
23
|
constructor(params?: ClientAbstractParams);
|
package/esm/client/3_types.d.ts
CHANGED
|
@@ -287,6 +287,54 @@ export interface SendPhotoParams {
|
|
|
287
287
|
*/
|
|
288
288
|
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
289
289
|
}
|
|
290
|
+
export interface SendDocumentParams {
|
|
291
|
+
/** The file name to assign. */
|
|
292
|
+
fileName?: string;
|
|
293
|
+
/** The mime type to assign. */
|
|
294
|
+
mimeType?: string;
|
|
295
|
+
/** Size of each upload chunk in bytes. */
|
|
296
|
+
chunkSize?: number;
|
|
297
|
+
/** Upload abort signal. */
|
|
298
|
+
signal?: AbortSignal | null;
|
|
299
|
+
/** The caption of the document. */
|
|
300
|
+
caption?: string;
|
|
301
|
+
/**
|
|
302
|
+
* The caption's entities.
|
|
303
|
+
*/
|
|
304
|
+
captionEntities?: MessageEntity[];
|
|
305
|
+
/**
|
|
306
|
+
* The parse mode to use for the caption. If not provided, the default parse mode will be used.
|
|
307
|
+
*/
|
|
308
|
+
parseMode?: ParseMode;
|
|
309
|
+
/**
|
|
310
|
+
* Whether to mark the document as a spoiler.
|
|
311
|
+
*/
|
|
312
|
+
hasSpoiler?: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Whether to send the message in a silent way without making a sound on the recipients' clients.
|
|
315
|
+
*/
|
|
316
|
+
disableNotification?: boolean;
|
|
317
|
+
/**
|
|
318
|
+
* Whether to protect the contents of the message from copying and forwarding.
|
|
319
|
+
*/
|
|
320
|
+
protectContent?: boolean;
|
|
321
|
+
/**
|
|
322
|
+
* The identifier of a message to reply to.
|
|
323
|
+
*/
|
|
324
|
+
replyToMessageId?: number;
|
|
325
|
+
/**
|
|
326
|
+
* The identifier of a thread to send the message to.
|
|
327
|
+
*/
|
|
328
|
+
messageThreadId?: number;
|
|
329
|
+
/**
|
|
330
|
+
* The identifier of the chat to send the message on behalf of. User-only.
|
|
331
|
+
*/
|
|
332
|
+
sendAs?: ChatID;
|
|
333
|
+
/**
|
|
334
|
+
* The reply markup of the message. Bot-only.
|
|
335
|
+
*/
|
|
336
|
+
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
337
|
+
}
|
|
290
338
|
export type ConnectionState = "notConnected" | "updating" | "ready";
|
|
291
339
|
export type AuthorizationState = {
|
|
292
340
|
authorized: boolean;
|
|
@@ -324,4 +372,12 @@ export type FilterUpdate<Update extends Update_, Type extends keyof Update_, Fie
|
|
|
324
372
|
[Field_ in Field]-?: Field extends keyof TypeType ? NonNullable<TypeType[Field]> : never;
|
|
325
373
|
};
|
|
326
374
|
};
|
|
375
|
+
export interface NetworkStatisticsEntry {
|
|
376
|
+
sent: number;
|
|
377
|
+
received: number;
|
|
378
|
+
}
|
|
379
|
+
export interface NetworkStatistics {
|
|
380
|
+
messages: NetworkStatisticsEntry;
|
|
381
|
+
cdn: NetworkStatisticsEntry;
|
|
382
|
+
}
|
|
327
383
|
export {};
|
package/esm/client/5_client.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { BotCommand, CallbackQuery, ChatAction, ChatID, InlineQuery, InlineQuery
|
|
|
6
6
|
import { Migrate } from "../4_errors.js";
|
|
7
7
|
import { FileSource, With } from "./0_utilities.js";
|
|
8
8
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
9
|
-
import { AnswerCallbackQueryParams, AnswerInlineQueryParams, AuthorizeUserParams, ClientParams, DeleteMessageParams, DeleteMessagesParams, DownloadParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, GetMyCommandsParams, InvokeErrorHandler, ReplyParams, SendMessageParams, SendPhotoParams, SendPollParams, SetMyCommandsParams, Update, UploadParams } from "./3_types.js";
|
|
9
|
+
import { AnswerCallbackQueryParams, AnswerInlineQueryParams, AuthorizeUserParams, ClientParams, DeleteMessageParams, DeleteMessagesParams, DownloadParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, GetMyCommandsParams, InvokeErrorHandler, NetworkStatistics, ReplyParams, SendDocumentParams, SendMessageParams, SendPhotoParams, SendPollParams, SetMyCommandsParams, Update, UploadParams } from "./3_types.js";
|
|
10
10
|
import { Composer, Middleware } from "./4_composer.js";
|
|
11
11
|
declare const getEntity: unique symbol;
|
|
12
12
|
declare const getStickerSetName: unique symbol;
|
|
@@ -43,6 +43,8 @@ export interface Context extends Update {
|
|
|
43
43
|
replyPoll: (question: string, options: [string, string, ...string[]], params?: Omit<SendPollParams, "replyToMessageId"> & ReplyParams) => Promise<With<Message, "poll">>;
|
|
44
44
|
/** Reply the received message with a photo. */
|
|
45
45
|
replyPhoto: (photo: FileSource, params?: Omit<SendPhotoParams, "replyToMessageId"> & ReplyParams) => Promise<With<Message, "photo">>;
|
|
46
|
+
/** Reply the received message with a document. */
|
|
47
|
+
replyDocument: (document: FileSource, params?: Omit<SendDocumentParams, "replyToMessageId"> & ReplyParams) => Promise<With<Message, "document">>;
|
|
46
48
|
/** Delete the received message. */
|
|
47
49
|
delete: () => Promise<void>;
|
|
48
50
|
/** Forward the received message. */
|
|
@@ -378,5 +380,19 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
378
380
|
* @param photo The photo to send.
|
|
379
381
|
*/
|
|
380
382
|
sendPhoto(chatId: ChatID, photo: FileSource, params?: SendPhotoParams): Promise<With<Message, "photo">>;
|
|
383
|
+
/**
|
|
384
|
+
* Send a document.
|
|
385
|
+
*
|
|
386
|
+
* @method
|
|
387
|
+
* @param chatId The chat to send the document to.
|
|
388
|
+
* @param document The document to send.
|
|
389
|
+
*/
|
|
390
|
+
sendDocument(chatId: ChatID, document: FileSource, params?: SendDocumentParams): Promise<With<Message, "document">>;
|
|
391
|
+
/**
|
|
392
|
+
* Get network statistics. This might not always be available.
|
|
393
|
+
*
|
|
394
|
+
* @method
|
|
395
|
+
*/
|
|
396
|
+
getNetworkStatistics(): Promise<NetworkStatistics>;
|
|
381
397
|
}
|
|
382
398
|
export {};
|
package/esm/client/5_client.js
CHANGED
|
@@ -9,8 +9,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo;
|
|
13
|
-
import { debug, gunzip, Mutex } from "../0_deps.js";
|
|
12
|
+
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia;
|
|
13
|
+
import { contentType, debug, gunzip, Mutex } from "../0_deps.js";
|
|
14
14
|
import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mod, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
15
15
|
import { as, functions, getChannelChatId, Message_, MessageContainer, name, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
|
|
16
16
|
import { StorageMemory } from "../3_storage.js";
|
|
@@ -220,6 +220,11 @@ export class Client extends ClientAbstract {
|
|
|
220
220
|
const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
|
|
221
221
|
return this.sendPhoto(effectiveMessage.chat.id, photo, { ...params, replyToMessageId });
|
|
222
222
|
},
|
|
223
|
+
replyDocument: (document, params) => {
|
|
224
|
+
const effectiveMessage = mustGetMsg();
|
|
225
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
|
|
226
|
+
return this.sendDocument(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
|
|
227
|
+
},
|
|
223
228
|
delete: () => {
|
|
224
229
|
const effectiveMessage = mustGetMsg();
|
|
225
230
|
return this.deleteMessage(effectiveMessage.chat.id, effectiveMessage.id);
|
|
@@ -305,6 +310,7 @@ export class Client extends ClientAbstract {
|
|
|
305
310
|
_Client_connectionInited.set(this, false);
|
|
306
311
|
_Client_lastPropagatedAuthorizationState.set(this, null);
|
|
307
312
|
_Client_selfId.set(this, null);
|
|
313
|
+
_Client_pingLoopAbortSignal.set(this, null);
|
|
308
314
|
_Client_pingInterval.set(this, 60 * 1000); // 60 seconds
|
|
309
315
|
_Client_pingLoopStarted.set(this, false);
|
|
310
316
|
_Client_autoStarted.set(this, false);
|
|
@@ -357,16 +363,36 @@ export class Client extends ClientAbstract {
|
|
|
357
363
|
__classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
|
|
358
364
|
__classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
|
|
359
365
|
__classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
|
|
366
|
+
const transportProvider = this.transportProvider;
|
|
367
|
+
this.transportProvider = (params) => {
|
|
368
|
+
const transport = transportProvider(params);
|
|
369
|
+
transport.connection.callback = {
|
|
370
|
+
read: async (count) => {
|
|
371
|
+
const key = params.cdn ? "netstat_cdn_read" : "netstat_messages_read";
|
|
372
|
+
await this.storage.incr([key], count);
|
|
373
|
+
},
|
|
374
|
+
write: async (count) => {
|
|
375
|
+
const key = params.cdn ? "netstat_cdn_write" : "netstat_messages_write";
|
|
376
|
+
await this.storage.incr([key], count);
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
return transport;
|
|
380
|
+
};
|
|
360
381
|
if (params?.defaultHandlers ?? true) {
|
|
361
382
|
this.on("connectionState", ({ connectionState }, next) => {
|
|
362
383
|
drop((async () => {
|
|
363
384
|
if (connectionState == "notConnected") {
|
|
385
|
+
if (!this.transport?.transport.initialized) {
|
|
386
|
+
d("not reconnecting");
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
364
389
|
let delay = 5;
|
|
365
390
|
while (!this.connected) {
|
|
366
391
|
d("reconnecting");
|
|
367
392
|
try {
|
|
368
393
|
await this.connect();
|
|
369
394
|
d("reconnected");
|
|
395
|
+
drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "reconnect"));
|
|
370
396
|
break;
|
|
371
397
|
}
|
|
372
398
|
catch (err) {
|
|
@@ -466,7 +492,7 @@ export class Client extends ClientAbstract {
|
|
|
466
492
|
release();
|
|
467
493
|
}
|
|
468
494
|
}
|
|
469
|
-
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_prefixes = new WeakMap(), _Client_namespaceProxies = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueue = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
495
|
+
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_prefixes = new WeakMap(), _Client_namespaceProxies = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingLoopAbortSignal = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueue = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
470
496
|
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
471
497
|
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), resolve);
|
|
472
498
|
});
|
|
@@ -494,9 +520,10 @@ export class Client extends ClientAbstract {
|
|
|
494
520
|
await this.reconnect(newDc);
|
|
495
521
|
d("migrated to DC%s", newDc);
|
|
496
522
|
}
|
|
497
|
-
disconnect() {
|
|
523
|
+
async disconnect() {
|
|
498
524
|
__classPrivateFieldSet(this, _Client_connectionInited, false, "f");
|
|
499
|
-
|
|
525
|
+
await super.disconnect();
|
|
526
|
+
__classPrivateFieldGet(this, _Client_pingLoopAbortSignal, "f")?.abort();
|
|
500
527
|
}
|
|
501
528
|
/**
|
|
502
529
|
* Calls [initConnection](1) and authorizes the client with one of the following:
|
|
@@ -861,9 +888,15 @@ export class Client extends ClientAbstract {
|
|
|
861
888
|
UNREACHABLE();
|
|
862
889
|
}
|
|
863
890
|
}, _Client_pingLoop = async function _Client_pingLoop() {
|
|
891
|
+
__classPrivateFieldSet(this, _Client_pingLoopAbortSignal, new AbortController(), "f");
|
|
864
892
|
while (this.connected) {
|
|
865
|
-
await new Promise((r) => setTimeout(r, __classPrivateFieldGet(this, _Client_pingInterval, "f")));
|
|
866
893
|
try {
|
|
894
|
+
await new Promise((resolve, reject) => {
|
|
895
|
+
setTimeout(resolve, __classPrivateFieldGet(this, _Client_pingInterval, "f"));
|
|
896
|
+
__classPrivateFieldGet(this, _Client_pingLoopAbortSignal, "f").signal.onabort = () => {
|
|
897
|
+
reject(__classPrivateFieldGet(this, _Client_pingLoopAbortSignal, "f")?.signal.reason);
|
|
898
|
+
};
|
|
899
|
+
});
|
|
867
900
|
await this.invoke(new functions.ping_delay_disconnect({ ping_id: getRandomId(), disconnect_delay: __classPrivateFieldGet(this, _Client_pingInterval, "f") / 1000 + 15 }));
|
|
868
901
|
if (Date.now() - __classPrivateFieldGet(this, _Client_lastUpdates, "f").getTime() >= 15 * 60 * 1000) {
|
|
869
902
|
drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "lastUpdates"));
|
|
@@ -1218,6 +1251,7 @@ export class Client extends ClientAbstract {
|
|
|
1218
1251
|
}
|
|
1219
1252
|
finally {
|
|
1220
1253
|
this.stateChangeHandler(this.connected);
|
|
1254
|
+
__classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
|
|
1221
1255
|
}
|
|
1222
1256
|
}, _Client_recoverChannelUpdateGap = async function _Client_recoverChannelUpdateGap(channelId, source) {
|
|
1223
1257
|
dGapC("recovering channel update gap [%o, %s]", channelId, source);
|
|
@@ -2123,26 +2157,10 @@ export class Client extends ClientAbstract {
|
|
|
2123
2157
|
let media = null;
|
|
2124
2158
|
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
2125
2159
|
if (typeof photo === "string") {
|
|
2126
|
-
|
|
2127
|
-
try {
|
|
2128
|
-
fileId = FileID.decode(photo);
|
|
2129
|
-
}
|
|
2130
|
-
catch (err) {
|
|
2131
|
-
d("fileId: %o", err);
|
|
2132
|
-
}
|
|
2160
|
+
const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, photo, FileType.Photo);
|
|
2133
2161
|
if (fileId != null) {
|
|
2134
|
-
if (fileId.fileType != FileType.Photo) {
|
|
2135
|
-
UNREACHABLE();
|
|
2136
|
-
}
|
|
2137
|
-
if (fileId.params.mediaId == undefined || fileId.params.accessHash == undefined || fileId.params.fileReference == undefined) {
|
|
2138
|
-
UNREACHABLE();
|
|
2139
|
-
}
|
|
2140
2162
|
media = new types.InputMediaPhoto({
|
|
2141
|
-
id: new types.InputPhoto(
|
|
2142
|
-
id: fileId.params.mediaId,
|
|
2143
|
-
access_hash: fileId.params.accessHash,
|
|
2144
|
-
file_reference: fileId.params.fileReference,
|
|
2145
|
-
}),
|
|
2163
|
+
id: new types.InputPhoto(fileId),
|
|
2146
2164
|
spoiler,
|
|
2147
2165
|
});
|
|
2148
2166
|
}
|
|
@@ -2157,33 +2175,70 @@ export class Client extends ClientAbstract {
|
|
|
2157
2175
|
media = new types.InputMediaUploadedPhoto({ file, spoiler });
|
|
2158
2176
|
}
|
|
2159
2177
|
}
|
|
2160
|
-
const
|
|
2161
|
-
const randomId = getRandomId();
|
|
2162
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
2163
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
2164
|
-
const replyToMsgId = params?.replyToMessageId;
|
|
2165
|
-
const topMsgId = params?.messageThreadId;
|
|
2166
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
2167
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
2168
|
-
const caption_ = params?.caption;
|
|
2169
|
-
const parseResult = caption_ !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
2170
|
-
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
2171
|
-
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
2172
|
-
const result = await this.invoke(new functions.messages.sendMedia({
|
|
2173
|
-
peer,
|
|
2174
|
-
random_id: randomId,
|
|
2175
|
-
silent,
|
|
2176
|
-
noforwards,
|
|
2177
|
-
reply_markup: replyMarkup,
|
|
2178
|
-
reply_to: replyToMsgId !== undefined ? new types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId }) : undefined,
|
|
2179
|
-
send_as: sendAs,
|
|
2180
|
-
media,
|
|
2181
|
-
message: caption ?? "",
|
|
2182
|
-
entities: captionEntities,
|
|
2183
|
-
}));
|
|
2184
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2178
|
+
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
|
|
2185
2179
|
return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "photo");
|
|
2186
2180
|
}
|
|
2181
|
+
/**
|
|
2182
|
+
* Send a document.
|
|
2183
|
+
*
|
|
2184
|
+
* @method
|
|
2185
|
+
* @param chatId The chat to send the document to.
|
|
2186
|
+
* @param document The document to send.
|
|
2187
|
+
*/
|
|
2188
|
+
async sendDocument(chatId, document, params) {
|
|
2189
|
+
let media = null;
|
|
2190
|
+
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
2191
|
+
if (typeof document === "string") {
|
|
2192
|
+
const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, document, FileType.Document);
|
|
2193
|
+
if (fileId != null) {
|
|
2194
|
+
media = new types.InputMediaDocument({
|
|
2195
|
+
id: new types.InputDocument(fileId),
|
|
2196
|
+
spoiler,
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
if (media == null) {
|
|
2201
|
+
if (typeof document === "string" && isHttpUrl(document)) {
|
|
2202
|
+
media = new types.InputMediaDocumentExternal({ url: document, spoiler });
|
|
2203
|
+
}
|
|
2204
|
+
else {
|
|
2205
|
+
const [contents, fileName_] = await getFileContents(document);
|
|
2206
|
+
const fileName = params?.fileName ?? fileName_;
|
|
2207
|
+
const mimeType = params?.mimeType ?? contentType(fileName.split(".").slice(-1)[0]) ?? "application/octet-stream";
|
|
2208
|
+
const file = await this.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal });
|
|
2209
|
+
media = new types.InputMediaUploadedDocument({
|
|
2210
|
+
file,
|
|
2211
|
+
spoiler,
|
|
2212
|
+
attributes: [new types.DocumentAttributeFilename({ file_name: fileName })],
|
|
2213
|
+
mime_type: mimeType,
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
|
|
2218
|
+
return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "document");
|
|
2219
|
+
}
|
|
2220
|
+
/**
|
|
2221
|
+
* Get network statistics. This might not always be available.
|
|
2222
|
+
*
|
|
2223
|
+
* @method
|
|
2224
|
+
*/
|
|
2225
|
+
async getNetworkStatistics() {
|
|
2226
|
+
const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
|
|
2227
|
+
this.storage.get(["netstat_messages_read"]),
|
|
2228
|
+
this.storage.get(["netstat_messages_write"]),
|
|
2229
|
+
this.storage.get(["netstat_cdn_read"]),
|
|
2230
|
+
this.storage.get(["netstat_cdn_write"]),
|
|
2231
|
+
]);
|
|
2232
|
+
const messages = {
|
|
2233
|
+
sent: Number(messagesWrite || 0),
|
|
2234
|
+
received: Number(messagesRead || 0),
|
|
2235
|
+
};
|
|
2236
|
+
const cdn = {
|
|
2237
|
+
sent: Number(cdnWrite || 0),
|
|
2238
|
+
received: Number(cdnRead || 0),
|
|
2239
|
+
};
|
|
2240
|
+
return { messages, cdn };
|
|
2241
|
+
}
|
|
2187
2242
|
}
|
|
2188
2243
|
_a = Client, _Client_getMe = async function _Client_getMe() {
|
|
2189
2244
|
if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
|
|
@@ -2318,4 +2373,52 @@ async function _Client_setMyInfo(info) {
|
|
|
2318
2373
|
await this.invoke(new functions.bots.setBotInfo({ bot: new types.InputUserSelf(), ...info }));
|
|
2319
2374
|
}, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
|
|
2320
2375
|
return this.invoke(new functions.bots.getBotInfo({ bot: new types.InputUserSelf(), lang_code: languageCode ?? "" }));
|
|
2376
|
+
}, _Client_resolveFileId = function _Client_resolveFileId(maybeFileId, expectedFileType) {
|
|
2377
|
+
let fileId = null;
|
|
2378
|
+
try {
|
|
2379
|
+
fileId = FileID.decode(maybeFileId);
|
|
2380
|
+
}
|
|
2381
|
+
catch (err) {
|
|
2382
|
+
d("fileId: %o", err);
|
|
2383
|
+
}
|
|
2384
|
+
if (fileId != null) {
|
|
2385
|
+
if (fileId.fileType != expectedFileType) {
|
|
2386
|
+
UNREACHABLE();
|
|
2387
|
+
}
|
|
2388
|
+
if (fileId.params.mediaId == undefined || fileId.params.accessHash == undefined || fileId.params.fileReference == undefined) {
|
|
2389
|
+
UNREACHABLE();
|
|
2390
|
+
}
|
|
2391
|
+
return {
|
|
2392
|
+
id: fileId.params.mediaId,
|
|
2393
|
+
access_hash: fileId.params.accessHash,
|
|
2394
|
+
file_reference: fileId.params.fileReference,
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
return null;
|
|
2398
|
+
}, _Client_sendMedia = async function _Client_sendMedia(chatId, media, params) {
|
|
2399
|
+
const peer = await this.getInputPeer(chatId);
|
|
2400
|
+
const randomId = getRandomId();
|
|
2401
|
+
const silent = params?.disableNotification ? true : undefined;
|
|
2402
|
+
const noforwards = params?.protectContent ? true : undefined;
|
|
2403
|
+
const replyToMsgId = params?.replyToMessageId;
|
|
2404
|
+
const topMsgId = params?.messageThreadId;
|
|
2405
|
+
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
2406
|
+
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
2407
|
+
const caption_ = params?.caption;
|
|
2408
|
+
const parseResult = caption_ !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
2409
|
+
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
2410
|
+
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
2411
|
+
const result = await this.invoke(new functions.messages.sendMedia({
|
|
2412
|
+
peer,
|
|
2413
|
+
random_id: randomId,
|
|
2414
|
+
silent,
|
|
2415
|
+
noforwards,
|
|
2416
|
+
reply_markup: replyMarkup,
|
|
2417
|
+
reply_to: replyToMsgId !== undefined ? new types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId }) : undefined,
|
|
2418
|
+
send_as: sendAs,
|
|
2419
|
+
media,
|
|
2420
|
+
message: caption ?? "",
|
|
2421
|
+
entities: captionEntities,
|
|
2422
|
+
}));
|
|
2423
|
+
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2321
2424
|
};
|
|
@@ -5,6 +5,10 @@ declare abstract class Foundation {
|
|
|
5
5
|
abstract open(): MaybePromise<void>;
|
|
6
6
|
abstract write(p: Uint8Array): MaybePromise<void>;
|
|
7
7
|
abstract close(): MaybePromise<void>;
|
|
8
|
+
callback?: {
|
|
9
|
+
read(count: number): void;
|
|
10
|
+
write(count: number): void;
|
|
11
|
+
};
|
|
8
12
|
}
|
|
9
13
|
export declare abstract class ConnectionUnframed extends Foundation {
|
|
10
14
|
readonly type: "framed";
|