teleproto 1.225.4 → 1.227.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Utils.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import bigInt from "big-integer";
2
- import type { ParseInterface } from "./client/messageParse";
3
2
  import { CustomFile } from "./client/uploads";
4
3
  import type { Entity, EntityLike, MessageIDLike } from "./define";
5
4
  import { EntityCache } from "./entityCache";
@@ -151,7 +150,6 @@ export declare function getInputMedia(media: any, { isPhoto, attributes, forceDo
151
150
  */
152
151
  export declare function getAppropriatedPartSize(fileSize: bigInt.BigInteger): 256 | 512 | 128;
153
152
  export declare function getPeer(peer: EntityLike | any): any;
154
- export declare function sanitizeParseMode(mode: string | ParseInterface): ParseInterface;
155
153
  /**
156
154
  Convert the given peer into its marked ID by default.
157
155
 
package/Utils.js CHANGED
@@ -24,7 +24,6 @@ exports.getInputGeo = getInputGeo;
24
24
  exports.getInputMedia = getInputMedia;
25
25
  exports.getAppropriatedPartSize = getAppropriatedPartSize;
26
26
  exports.getPeer = getPeer;
27
- exports.sanitizeParseMode = sanitizeParseMode;
28
27
  exports.getPeerId = getPeerId;
29
28
  exports.resolveId = resolveId;
30
29
  exports.getMessageId = getMessageId;
@@ -43,9 +42,6 @@ exports.resolveBotFileId = resolveBotFileId;
43
42
  exports.packBotFileId = packBotFileId;
44
43
  const big_integer_1 = __importDefault(require("big-integer"));
45
44
  const mime_1 = __importDefault(require("mime"));
46
- const html_1 = require("./extensions/html");
47
- const markdown_1 = require("./extensions/markdown");
48
- const markdownv2_1 = require("./extensions/markdownv2");
49
45
  const Helpers_1 = require("./Helpers");
50
46
  const tl_1 = require("./tl");
51
47
  function getFileInfo(fileLocation) {
@@ -1042,23 +1038,6 @@ function getPeer(peer) {
1042
1038
  catch (e) { }
1043
1039
  _raiseCastFail(peer, "peer");
1044
1040
  }
1045
- function sanitizeParseMode(mode) {
1046
- if (mode === "md" || mode === "markdown") {
1047
- return markdown_1.MarkdownParser;
1048
- }
1049
- if (mode === "md2" || mode === "markdownv2") {
1050
- return markdownv2_1.MarkdownV2Parser;
1051
- }
1052
- if (mode == "html") {
1053
- return html_1.HTMLParser;
1054
- }
1055
- if (typeof mode == "object") {
1056
- if ("parse" in mode && "unparse" in mode) {
1057
- return mode;
1058
- }
1059
- }
1060
- throw new Error(`Invalid parse mode type ${mode}`);
1061
- }
1062
1041
  /**
1063
1042
  Convert the given peer into its marked ID by default.
1064
1043
 
package/Version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.225.4";
1
+ export declare const version = "1.227.1";
package/Version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = "1.225.4";
4
+ exports.version = "1.227.1";
@@ -70,7 +70,7 @@ export declare class TelegramClient extends TelegramBaseClient {
70
70
  *
71
71
  * You can now use the client instance to call other api requests.
72
72
  */
73
- start(authParams: authMethods.UserAuthParams | authMethods.BotAuthParams): Promise<void>;
73
+ start(authParams?: authMethods.UserAuthParams | authMethods.BotAuthParams): Promise<void>;
74
74
  /**
75
75
  * Checks whether the current client is authorized or not. (logged in as a user)
76
76
  * @example
@@ -448,6 +448,8 @@ export declare class TelegramClient extends TelegramBaseClient {
448
448
  * await client.sendMessage("me",{message:"<u> this will be sent as it is</u> ** with no formatting **});
449
449
  */
450
450
  setParseMode(mode: "md" | "md2" | "markdown" | "markdownv2" | "html" | parseMethods.ParseInterface | undefined): void;
451
+ /** @hidden */
452
+ _sanitizeParseMode(mode: string | parseMethods.ParseInterface): parseMethods.ParseInterface;
451
453
  /**
452
454
  * Iterates over the messages for a given chat.
453
455
  * <br/>
@@ -519,6 +521,11 @@ export declare class TelegramClient extends TelegramBaseClient {
519
521
  * ```
520
522
  */
521
523
  getMessages(entity: EntityLike | undefined, getMessagesParams?: Partial<messageMethods.IterMessagesParams>): Promise<import("../Helpers").TotalList<Api.Message>>;
524
+ /** @hidden */
525
+ getCommentData(entity: EntityLike, message: number | Api.Message): Promise<{
526
+ entity: Api.TypeInputPeer;
527
+ replyTo: number;
528
+ }>;
522
529
  /**
523
530
  * Sends a message to the specified user, chat or channel.<br/>
524
531
  * The default parse mode is the same as the official applications (a custom flavour of markdown). **bold**, `code` or __italic__ are available.<br/>
@@ -48,11 +48,12 @@ const chatMethods = __importStar(require("./chats"));
48
48
  const dialogMethods = __importStar(require("./dialogs"));
49
49
  const twoFA = __importStar(require("./2fa"));
50
50
  const tl_1 = require("../tl");
51
- const Utils_1 = require("../Utils");
51
+ const html_1 = require("../extensions/html");
52
+ const markdown_1 = require("../extensions/markdown");
53
+ const markdownv2_1 = require("../extensions/markdownv2");
52
54
  const network_1 = require("../network");
53
55
  const registry_1 = require("../tl/runtime/registry");
54
56
  const updates_1 = require("./updates");
55
- const Logger_1 = require("../extensions/Logger");
56
57
  /**
57
58
  * The TelegramClient uses several methods in different files to provide all the common functionality in a nice interface.</br>
58
59
  * **In short, to create a client you must do:**
@@ -542,12 +543,28 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
542
543
  */
543
544
  setParseMode(mode) {
544
545
  if (mode) {
545
- this._parseMode = (0, Utils_1.sanitizeParseMode)(mode);
546
+ this._parseMode = this._sanitizeParseMode(mode);
546
547
  }
547
548
  else {
548
549
  this._parseMode = undefined;
549
550
  }
550
551
  }
552
+ /** @hidden */
553
+ _sanitizeParseMode(mode) {
554
+ if (mode === "md" || mode === "markdown") {
555
+ return markdown_1.MarkdownParser;
556
+ }
557
+ if (mode === "md2" || mode === "markdownv2") {
558
+ return markdownv2_1.MarkdownV2Parser;
559
+ }
560
+ if (mode == "html") {
561
+ return html_1.HTMLParser;
562
+ }
563
+ if (typeof mode == "object" && "parse" in mode && "unparse" in mode) {
564
+ return mode;
565
+ }
566
+ throw new Error(`Invalid parse mode type ${mode}`);
567
+ }
551
568
  //endregion
552
569
  // region messages
553
570
  /**
@@ -625,6 +642,10 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
625
642
  getMessages(entity, getMessagesParams = {}) {
626
643
  return messageMethods.getMessages(this, entity, getMessagesParams);
627
644
  }
645
+ /** @hidden */
646
+ getCommentData(entity, message) {
647
+ return messageMethods.getCommentData(this, entity, message);
648
+ }
628
649
  /**
629
650
  * Sends a message to the specified user, chat or channel.<br/>
630
651
  * The default parse mode is the same as the official applications (a custom flavour of markdown). **bold**, `code` or __italic__ are available.<br/>
@@ -1155,13 +1176,10 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
1155
1176
  const res = await this.getMe();
1156
1177
  }
1157
1178
  catch (e) {
1158
- this._log.error(`Error while trying to reconnect`);
1179
+ this._log.error(`Error while trying to reconnect`, e);
1159
1180
  if (this._errorHandler) {
1160
1181
  await this._errorHandler(e);
1161
1182
  }
1162
- if (this._log.canSend(Logger_1.LogLevel.ERROR)) {
1163
- console.error(e);
1164
- }
1165
1183
  }
1166
1184
  // Restart update loop if it was stopped during reconnect
1167
1185
  if (!this._loopStarted && !this._destroyed) {
package/client/auth.d.ts CHANGED
@@ -114,7 +114,7 @@ export interface ApiCredentials {
114
114
  apiHash: string;
115
115
  }
116
116
  /** @hidden */
117
- export declare function start(client: TelegramClient, authParams: UserAuthParams | BotAuthParams): Promise<void>;
117
+ export declare function start(client: TelegramClient, authParams?: UserAuthParams | BotAuthParams): Promise<void>;
118
118
  /** @hidden */
119
119
  export declare function checkAuthorization(client: TelegramClient): Promise<boolean>;
120
120
  /** @hidden */
package/client/auth.js CHANGED
@@ -49,6 +49,7 @@ const tl_1 = require("../tl");
49
49
  const utils = __importStar(require("../Utils"));
50
50
  const Helpers_1 = require("../Helpers");
51
51
  const Password_1 = require("../Password");
52
+ const errors_1 = require("../errors");
52
53
  const QR_CODE_TIMEOUT = 30000;
53
54
  // region public methods
54
55
  /** @hidden */
@@ -56,9 +57,23 @@ async function start(client, authParams) {
56
57
  if (!client.connected) {
57
58
  await client.connect();
58
59
  }
59
- if (await client.checkAuthorization()) {
60
+ // Probe authorization inline (instead of checkAuthorization) so we can keep
61
+ // the actual error the server returned — e.g. AuthKeyUnregisteredError or
62
+ // SessionRevokedError on a revoked session — rather than discarding it.
63
+ let authError;
64
+ try {
65
+ await client.invoke(new tl_1.Api.updates.GetState());
60
66
  return;
61
67
  }
68
+ catch (e) {
69
+ authError = e;
70
+ }
71
+ // Not authorized and no way to (re)login: surface the real reason instead
72
+ // of crashing on `"phoneNumber" in undefined` further down in _authFlow.
73
+ if (!authParams ||
74
+ (!("phoneNumber" in authParams) && !("botAuthToken" in authParams))) {
75
+ throw (authError !== null && authError !== void 0 ? authError : new errors_1.UnauthorizedError("Not authorized and no auth parameters were provided to log in.", undefined));
76
+ }
62
77
  const apiCredentials = {
63
78
  apiId: client.apiId,
64
79
  apiHash: client.apiHash,
package/client/dialogs.js CHANGED
@@ -44,7 +44,6 @@ const requestIter_1 = require("../requestIter");
44
44
  const utils = __importStar(require("../Utils"));
45
45
  const dialog_1 = require("../tl/custom/dialog");
46
46
  const big_integer_1 = __importDefault(require("big-integer"));
47
- const Logger_1 = require("../extensions/Logger");
48
47
  const _MAX_CHUNK_SIZE = 100;
49
48
  /**
50
49
  Get the key to get messages from a dialog.
@@ -134,12 +133,8 @@ class _DialogsIter extends requestIter_1.RequestIter {
134
133
  }
135
134
  }
136
135
  catch (e) {
137
- console.log("msg", message);
138
136
  this.client._log.error("Got error while trying to finish init message with id " +
139
- m.id);
140
- if (this.client._log.canSend(Logger_1.LogLevel.ERROR)) {
141
- console.error(e);
142
- }
137
+ m.id, e);
143
138
  if (this.client._errorHandler) {
144
139
  await this.client._errorHandler(e);
145
140
  }
@@ -1,10 +1,6 @@
1
1
  import { Api } from "../tl";
2
2
  import type { EntityLike } from "../define";
3
3
  import type { TelegramClient } from "./TelegramClient";
4
- export type messageEntities = typeof Api.MessageEntityBold | typeof Api.MessageEntityItalic | typeof Api.MessageEntityStrike | typeof Api.MessageEntityCode | typeof Api.MessageEntityPre;
5
- export declare const DEFAULT_DELIMITERS: {
6
- [key: string]: messageEntities;
7
- };
8
4
  export interface ParseInterface {
9
5
  parse: (message: string) => [string, Api.TypeMessageEntity[]];
10
6
  unparse: (text: string, entities: Api.TypeMessageEntity[]) => string;
@@ -36,7 +36,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.DEFAULT_DELIMITERS = void 0;
40
39
  exports._replaceWithMention = _replaceWithMention;
41
40
  exports._parseMessageText = _parseMessageText;
42
41
  exports._getResponseMessage = _getResponseMessage;
@@ -45,13 +44,6 @@ const tl_1 = require("../tl");
45
44
  const utils = __importStar(require("../Utils"));
46
45
  const Helpers_1 = require("../Helpers");
47
46
  const big_integer_1 = __importDefault(require("big-integer"));
48
- exports.DEFAULT_DELIMITERS = {
49
- "**": tl_1.Api.MessageEntityBold,
50
- __: tl_1.Api.MessageEntityItalic,
51
- "~~": tl_1.Api.MessageEntityStrike,
52
- "`": tl_1.Api.MessageEntityCode,
53
- "```": tl_1.Api.MessageEntityPre,
54
- };
55
47
  /** @hidden */
56
48
  async function _replaceWithMention(client, entities, i, user) {
57
49
  try {
@@ -78,7 +70,7 @@ async function _parseMessageText(client, message, parseMode) {
78
70
  parseMode = client.parseMode;
79
71
  }
80
72
  else if (typeof parseMode === "string") {
81
- parseMode = (0, Utils_1.sanitizeParseMode)(parseMode);
73
+ parseMode = client._sanitizeParseMode(parseMode);
82
74
  }
83
75
  const [rawMessage, msgEntities] = parseMode.parse(message);
84
76
  for (let i = msgEntities.length - 1; i >= 0; i--) {
@@ -19,7 +19,6 @@ const FilePool_1 = require("../network/FilePool");
19
19
  const registry_1 = require("../tl/runtime/registry");
20
20
  const TCPMTProxy_1 = require("../network/connection/TCPMTProxy");
21
21
  const async_mutex_1 = require("async-mutex");
22
- const Logger_1 = require("../extensions/Logger");
23
22
  const Deferred_1 = __importDefault(require("../extensions/Deferred"));
24
23
  const UpdateManager_1 = require("./UpdateManager");
25
24
  const API_SENDER_IDLE_TIMEOUT_MS = 30000;
@@ -216,8 +215,8 @@ class TelegramBaseClient {
216
215
  }
217
216
  async disconnect() {
218
217
  await this._disconnect();
219
- await this._filePool.close({ waitMs: FILE_POOL_CLOSE_GRACE_MS });
220
- await this._apiSenderPool.close();
218
+ await this._filePool.purge();
219
+ await this._apiSenderPool.purge();
221
220
  this._teardownUpdateState();
222
221
  }
223
222
  /** @hidden */
@@ -246,6 +245,8 @@ class TelegramBaseClient {
246
245
  async destroy() {
247
246
  this._destroyed = true;
248
247
  await this.disconnect();
248
+ await this._filePool.close({ waitMs: FILE_POOL_CLOSE_GRACE_MS });
249
+ await this._apiSenderPool.close();
249
250
  this._eventBuilders = [];
250
251
  }
251
252
  /** @hidden */
@@ -316,8 +317,8 @@ class TelegramBaseClient {
316
317
  if (this._errorHandler) {
317
318
  await this._errorHandler(err);
318
319
  }
319
- else if (this._log.canSend(Logger_1.LogLevel.ERROR)) {
320
- console.error(err);
320
+ else {
321
+ this._log.error("Error while connecting sender", err);
321
322
  }
322
323
  await (0, Helpers_1.sleep)(1000);
323
324
  await sender.disconnect();
@@ -375,10 +376,8 @@ class TelegramBaseClient {
375
376
  await handler(error);
376
377
  }
377
378
  catch (e) {
378
- if (this._log.canSend(Logger_1.LogLevel.ERROR)) {
379
- e.message = `Error ${e.message} thrown while handling top-level error: ${error.message}`;
380
- console.error(e);
381
- }
379
+ e.message = `Error ${e.message} thrown while handling top-level error: ${error.message}`;
380
+ this._log.error(e.message, e);
382
381
  }
383
382
  };
384
383
  }
package/client/uploads.js CHANGED
@@ -49,7 +49,6 @@ const fs_1 = require("fs");
49
49
  const errors = __importStar(require("../errors"));
50
50
  const utils = __importStar(require("../Utils"));
51
51
  const messageParse_1 = require("./messageParse");
52
- const messages_1 = require("./messages");
53
52
  const big_integer_1 = __importDefault(require("big-integer"));
54
53
  /**
55
54
  * A custom file class compatible with File-like upload shape.<br/>
@@ -377,7 +376,7 @@ async function _sendAlbum(client, entity, { file, caption, formattingEntities, f
377
376
  }
378
377
  }
379
378
  if (commentTo != undefined) {
380
- const discussionData = await (0, messages_1.getCommentData)(client, entity, commentTo);
379
+ const discussionData = await client.getCommentData(entity, commentTo);
381
380
  entity = discussionData.entity;
382
381
  replyTo = discussionData.replyTo;
383
382
  }
@@ -473,7 +472,7 @@ async function sendFile(client, entity, { file, caption, forceDocument = false,
473
472
  }
474
473
  entity = await client.getInputEntity(entity);
475
474
  if (commentTo != undefined) {
476
- const discussionData = await (0, messages_1.getCommentData)(client, entity, commentTo);
475
+ const discussionData = await client.getCommentData(entity, commentTo);
477
476
  entity = discussionData.entity;
478
477
  replyTo = discussionData.replyTo;
479
478
  }
package/client/users.js CHANGED
@@ -54,7 +54,6 @@ const Helpers_1 = require("../Helpers");
54
54
  const errors = __importStar(require("../errors"));
55
55
  const utils = __importStar(require("../Utils"));
56
56
  const big_integer_1 = __importDefault(require("big-integer"));
57
- const Logger_1 = require("../extensions/Logger");
58
57
  const RequestState_1 = require("../network/RequestState");
59
58
  // UserMethods {
60
59
  // region Invoking Telegram request
@@ -425,12 +424,10 @@ async function getInputEntity(client, peer) {
425
424
  return utils.getInputPeer(channels.chats[0]);
426
425
  }
427
426
  catch (e) {
427
+ client._log.error("Error while resolving channel entity", e);
428
428
  if (client._errorHandler) {
429
429
  await client._errorHandler(e);
430
430
  }
431
- if (client._log.canSend(Logger_1.LogLevel.ERROR)) {
432
- console.error(e);
433
- }
434
431
  }
435
432
  }
436
433
  throw new Error(`Could not find the input entity for ${JSON.stringify(peer)}.
@@ -65,15 +65,6 @@ export declare class FloodError extends RPCError {
65
65
  code: number;
66
66
  errorMessage: string;
67
67
  }
68
- /**
69
- * The account is frozen and cannot use this method.
70
- * Clients should call help.getAppConfig to get freeze_since_date,
71
- * freeze_until_date, and freeze_appeal_url.
72
- */
73
- export declare class FrozenError extends RPCError {
74
- code: number;
75
- errorMessage: string;
76
- }
77
68
  /**
78
69
  * An internal server error occurred while a request was being processed
79
70
  * for example, there was a disruption while accessing a database or file
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimedOutError = exports.ServerError = exports.FrozenError = exports.FloodError = exports.AuthKeyError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.InvalidDCError = exports.RPCError = void 0;
3
+ exports.TimedOutError = exports.ServerError = exports.FloodError = exports.AuthKeyError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.InvalidDCError = exports.RPCError = void 0;
4
4
  const ts_custom_error_1 = require("ts-custom-error");
5
5
  class RPCError extends ts_custom_error_1.CustomError {
6
6
  constructor(message, request, code) {
@@ -107,19 +107,6 @@ class FloodError extends RPCError {
107
107
  }
108
108
  }
109
109
  exports.FloodError = FloodError;
110
- /**
111
- * The account is frozen and cannot use this method.
112
- * Clients should call help.getAppConfig to get freeze_since_date,
113
- * freeze_until_date, and freeze_appeal_url.
114
- */
115
- class FrozenError extends RPCError {
116
- constructor() {
117
- super(...arguments);
118
- this.code = 420;
119
- this.errorMessage = "FROZEN";
120
- }
121
- }
122
- exports.FrozenError = FrozenError;
123
110
  /**
124
111
  * An internal server error occurred while a request was being processed
125
112
  * for example, there was a disruption while accessing a database or file