teleproto 1.214.0
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/CryptoFile.d.ts +2 -0
- package/CryptoFile.js +37 -0
- package/Helpers.d.ts +150 -0
- package/Helpers.js +477 -0
- package/LICENSE +23 -0
- package/Password.d.ts +14 -0
- package/Password.js +270 -0
- package/README.md +98 -0
- package/Utils.d.ts +227 -0
- package/Utils.js +1247 -0
- package/Version.d.ts +1 -0
- package/Version.js +4 -0
- package/client/2fa.d.ts +48 -0
- package/client/2fa.js +108 -0
- package/client/TelegramClient.d.ts +1043 -0
- package/client/TelegramClient.js +1181 -0
- package/client/account.d.ts +0 -0
- package/client/account.js +1 -0
- package/client/auth.d.ts +92 -0
- package/client/auth.js +388 -0
- package/client/bots.d.ts +6 -0
- package/client/bots.js +23 -0
- package/client/buttons.d.ts +4 -0
- package/client/buttons.js +86 -0
- package/client/chats.d.ts +45 -0
- package/client/chats.js +350 -0
- package/client/dialogs.d.ts +52 -0
- package/client/dialogs.js +174 -0
- package/client/downloads.d.ts +156 -0
- package/client/downloads.js +614 -0
- package/client/fs.d.ts +1 -0
- package/client/fs.js +17 -0
- package/client/index.d.ts +15 -0
- package/client/index.js +64 -0
- package/client/messageParse.d.ts +17 -0
- package/client/messageParse.js +191 -0
- package/client/messages.d.ts +263 -0
- package/client/messages.js +813 -0
- package/client/os.d.ts +2 -0
- package/client/os.js +37 -0
- package/client/path.d.ts +2 -0
- package/client/path.js +7 -0
- package/client/telegramBaseClient.d.ts +237 -0
- package/client/telegramBaseClient.js +368 -0
- package/client/updates.d.ts +33 -0
- package/client/updates.js +260 -0
- package/client/uploads.d.ts +136 -0
- package/client/uploads.js +514 -0
- package/client/users.d.ts +29 -0
- package/client/users.js +490 -0
- package/crypto/AuthKey.d.ts +19 -0
- package/crypto/AuthKey.js +76 -0
- package/crypto/CTR.d.ts +5 -0
- package/crypto/CTR.js +16 -0
- package/crypto/Factorizator.d.ts +19 -0
- package/crypto/Factorizator.js +74 -0
- package/crypto/IGE.d.ts +11 -0
- package/crypto/IGE.js +115 -0
- package/crypto/RSA.d.ts +14 -0
- package/crypto/RSA.js +70 -0
- package/crypto/converters.d.ts +19 -0
- package/crypto/converters.js +52 -0
- package/crypto/crypto.d.ts +19 -0
- package/crypto/crypto.js +58 -0
- package/crypto/words.d.ts +6 -0
- package/crypto/words.js +47 -0
- package/define.d.ts +77 -0
- package/entityCache.d.ts +7 -0
- package/entityCache.js +79 -0
- package/errors/Common.d.ts +71 -0
- package/errors/Common.js +122 -0
- package/errors/RPCBaseErrors.d.ts +84 -0
- package/errors/RPCBaseErrors.js +134 -0
- package/errors/RPCErrorList.d.ts +37 -0
- package/errors/RPCErrorList.js +117 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +32 -0
- package/events/Album.d.ts +36 -0
- package/events/Album.js +104 -0
- package/events/CallbackQuery.d.ts +73 -0
- package/events/CallbackQuery.js +193 -0
- package/events/DeletedMessage.d.ts +45 -0
- package/events/DeletedMessage.js +63 -0
- package/events/EditedMessage.d.ts +30 -0
- package/events/EditedMessage.js +41 -0
- package/events/NewMessage.d.ts +89 -0
- package/events/NewMessage.js +182 -0
- package/events/Raw.d.ts +29 -0
- package/events/Raw.js +43 -0
- package/events/common.d.ts +66 -0
- package/events/common.js +141 -0
- package/events/index.d.ts +2 -0
- package/events/index.js +8 -0
- package/extensions/AsyncQueue.d.ts +10 -0
- package/extensions/AsyncQueue.js +32 -0
- package/extensions/BinaryReader.d.ts +99 -0
- package/extensions/BinaryReader.js +242 -0
- package/extensions/BinaryWriter.d.ts +6 -0
- package/extensions/BinaryWriter.js +15 -0
- package/extensions/Deferred.d.ts +8 -0
- package/extensions/Deferred.js +16 -0
- package/extensions/Logger.d.ts +54 -0
- package/extensions/Logger.js +128 -0
- package/extensions/MessagePacker.d.ts +21 -0
- package/extensions/MessagePacker.js +154 -0
- package/extensions/PendingState.d.ts +12 -0
- package/extensions/PendingState.js +29 -0
- package/extensions/PromisedNetSockets.d.ts +24 -0
- package/extensions/PromisedNetSockets.js +192 -0
- package/extensions/PromisedWebSockets.d.ts +18 -0
- package/extensions/PromisedWebSockets.js +124 -0
- package/extensions/html.d.ts +5 -0
- package/extensions/html.js +228 -0
- package/extensions/index.d.ts +7 -0
- package/extensions/index.js +17 -0
- package/extensions/markdown.d.ts +5 -0
- package/extensions/markdown.js +76 -0
- package/extensions/markdownv2.d.ts +5 -0
- package/extensions/markdownv2.js +51 -0
- package/extensions/net.d.ts +1 -0
- package/extensions/net.js +17 -0
- package/extensions/socks.d.ts +1 -0
- package/extensions/socks.js +17 -0
- package/index.d.ts +14 -0
- package/index.js +62 -0
- package/inspect.d.ts +1 -0
- package/inspect.js +5 -0
- package/network/Authenticator.d.ts +12 -0
- package/network/Authenticator.js +192 -0
- package/network/MTProtoPlainSender.d.ts +19 -0
- package/network/MTProtoPlainSender.js +74 -0
- package/network/MTProtoSender.d.ts +290 -0
- package/network/MTProtoSender.js +873 -0
- package/network/MTProtoState.d.ts +102 -0
- package/network/MTProtoState.js +267 -0
- package/network/RequestState.d.ts +18 -0
- package/network/RequestState.js +35 -0
- package/network/connection/Connection.d.ts +69 -0
- package/network/connection/Connection.js +162 -0
- package/network/connection/TCPAbridged.d.ts +19 -0
- package/network/connection/TCPAbridged.js +58 -0
- package/network/connection/TCPFull.d.ts +16 -0
- package/network/connection/TCPFull.js +61 -0
- package/network/connection/TCPMTProxy.d.ts +49 -0
- package/network/connection/TCPMTProxy.js +121 -0
- package/network/connection/TCPObfuscated.d.ts +18 -0
- package/network/connection/TCPObfuscated.js +78 -0
- package/network/connection/index.d.ts +4 -0
- package/network/connection/index.js +11 -0
- package/network/index.d.ts +11 -0
- package/network/index.js +23 -0
- package/package.json +50 -0
- package/requestIter.d.ts +24 -0
- package/requestIter.js +109 -0
- package/sessions/Abstract.d.ts +103 -0
- package/sessions/Abstract.js +6 -0
- package/sessions/Memory.d.ts +38 -0
- package/sessions/Memory.js +272 -0
- package/sessions/StoreSession.d.ts +14 -0
- package/sessions/StoreSession.js +77 -0
- package/sessions/StringSession.d.ts +32 -0
- package/sessions/StringSession.js +116 -0
- package/sessions/index.d.ts +4 -0
- package/sessions/index.js +11 -0
- package/sessions/localStorage.d.ts +1 -0
- package/sessions/localStorage.js +4 -0
- package/tl/AllTLObjects.d.ts +3 -0
- package/tl/AllTLObjects.js +17 -0
- package/tl/MTProtoRequest.d.ts +18 -0
- package/tl/MTProtoRequest.js +38 -0
- package/tl/api.d.ts +32488 -0
- package/tl/api.js +507 -0
- package/tl/apiTl.d.ts +2 -0
- package/tl/apiTl.js +2209 -0
- package/tl/core/GZIPPacked.d.ts +15 -0
- package/tl/core/GZIPPacked.js +51 -0
- package/tl/core/MessageContainer.d.ts +12 -0
- package/tl/core/MessageContainer.js +42 -0
- package/tl/core/RPCResult.d.ts +14 -0
- package/tl/core/RPCResult.js +32 -0
- package/tl/core/TLMessage.d.ts +10 -0
- package/tl/core/TLMessage.js +14 -0
- package/tl/core/index.d.ts +6 -0
- package/tl/core/index.js +16 -0
- package/tl/custom/button.d.ts +24 -0
- package/tl/custom/button.js +78 -0
- package/tl/custom/chatGetter.d.ts +29 -0
- package/tl/custom/chatGetter.js +116 -0
- package/tl/custom/dialog.d.ts +30 -0
- package/tl/custom/dialog.js +40 -0
- package/tl/custom/draft.d.ts +21 -0
- package/tl/custom/draft.js +48 -0
- package/tl/custom/file.d.ts +21 -0
- package/tl/custom/file.js +68 -0
- package/tl/custom/forward.d.ts +15 -0
- package/tl/custom/forward.js +47 -0
- package/tl/custom/index.d.ts +1 -0
- package/tl/custom/index.js +5 -0
- package/tl/custom/inlineResult.d.ts +32 -0
- package/tl/custom/inlineResult.js +87 -0
- package/tl/custom/inlineResults.d.ts +20 -0
- package/tl/custom/inlineResults.js +26 -0
- package/tl/custom/message.d.ts +427 -0
- package/tl/custom/message.js +716 -0
- package/tl/custom/messageButton.d.ts +54 -0
- package/tl/custom/messageButton.js +152 -0
- package/tl/custom/senderGetter.d.ts +28 -0
- package/tl/custom/senderGetter.js +55 -0
- package/tl/generateModule.d.ts +1 -0
- package/tl/generateModule.js +17 -0
- package/tl/generationHelpers.d.ts +11 -0
- package/tl/generationHelpers.js +289 -0
- package/tl/index.d.ts +3 -0
- package/tl/index.js +10 -0
- package/tl/patched/index.d.ts +2 -0
- package/tl/patched/index.js +76 -0
- package/tl/schemaTl.d.ts +2 -0
- package/tl/schemaTl.js +64 -0
- package/tl/types-generator/generate.d.ts +1 -0
- package/tl/types-generator/generate.js +84 -0
- package/tl/types-generator/template.d.ts +6 -0
- package/tl/types-generator/template.js +257 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors not related to the Telegram API itself
|
|
3
|
+
*/
|
|
4
|
+
import { Api } from "../tl";
|
|
5
|
+
/**
|
|
6
|
+
* Occurs when a read operation was cancelled.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ReadCancelledError extends Error {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Occurs when a type is not found, for example,
|
|
13
|
+
* when trying to read a TLObject with an invalid constructor code.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TypeNotFoundError extends Error {
|
|
16
|
+
invalidConstructorId: number;
|
|
17
|
+
remaining: Buffer;
|
|
18
|
+
constructor(invalidConstructorId: number, remaining: Buffer);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Occurs when using the TCP full mode and the checksum of a received
|
|
22
|
+
* packet doesn't match the expected checksum.
|
|
23
|
+
*/
|
|
24
|
+
export declare class InvalidChecksumError extends Error {
|
|
25
|
+
private checksum;
|
|
26
|
+
private validChecksum;
|
|
27
|
+
constructor(checksum: number, validChecksum: number);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Occurs when the buffer is invalid, and may contain an HTTP error code.
|
|
31
|
+
* For instance, 404 means "forgotten/broken authorization key", while
|
|
32
|
+
*/
|
|
33
|
+
export declare class InvalidBufferError extends Error {
|
|
34
|
+
code?: number;
|
|
35
|
+
payload: Buffer;
|
|
36
|
+
constructor(payload: Buffer);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generic security error, mostly used when generating a new AuthKey.
|
|
40
|
+
*/
|
|
41
|
+
export declare class SecurityError extends Error {
|
|
42
|
+
constructor(...args: any[]);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Occurs when there's a hash mismatch between the decrypted CDN file
|
|
46
|
+
* and its expected hash.
|
|
47
|
+
*/
|
|
48
|
+
export declare class CdnFileTamperedError extends SecurityError {
|
|
49
|
+
constructor();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Occurs when handling a badMessageNotification
|
|
53
|
+
*/
|
|
54
|
+
export declare class BadMessageError extends Error {
|
|
55
|
+
static ErrorMessages: {
|
|
56
|
+
16: string;
|
|
57
|
+
17: string;
|
|
58
|
+
18: string;
|
|
59
|
+
19: string;
|
|
60
|
+
20: string;
|
|
61
|
+
32: string;
|
|
62
|
+
33: string;
|
|
63
|
+
34: string;
|
|
64
|
+
35: string;
|
|
65
|
+
48: string;
|
|
66
|
+
64: string;
|
|
67
|
+
};
|
|
68
|
+
private code;
|
|
69
|
+
private errorMessage;
|
|
70
|
+
constructor(request: Api.AnyRequest, code: number);
|
|
71
|
+
}
|
package/errors/Common.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Errors not related to the Telegram API itself
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BadMessageError = exports.CdnFileTamperedError = exports.SecurityError = exports.InvalidBufferError = exports.InvalidChecksumError = exports.TypeNotFoundError = exports.ReadCancelledError = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Occurs when a read operation was cancelled.
|
|
9
|
+
*/
|
|
10
|
+
class ReadCancelledError extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("The read operation was cancelled.");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ReadCancelledError = ReadCancelledError;
|
|
16
|
+
/**
|
|
17
|
+
* Occurs when a type is not found, for example,
|
|
18
|
+
* when trying to read a TLObject with an invalid constructor code.
|
|
19
|
+
*/
|
|
20
|
+
class TypeNotFoundError extends Error {
|
|
21
|
+
constructor(invalidConstructorId, remaining) {
|
|
22
|
+
super(`Could not find a matching Constructor ID for the TLObject that was supposed to be
|
|
23
|
+
read with ID ${invalidConstructorId}. Most likely, a TLObject was trying to be read when
|
|
24
|
+
it should not be read. Remaining bytes: ${remaining.length}`);
|
|
25
|
+
if (typeof alert !== "undefined") {
|
|
26
|
+
alert(`Missing MTProto Entity: Please, make sure to add TL definition for ID ${invalidConstructorId}`);
|
|
27
|
+
}
|
|
28
|
+
this.invalidConstructorId = invalidConstructorId;
|
|
29
|
+
this.remaining = remaining;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.TypeNotFoundError = TypeNotFoundError;
|
|
33
|
+
/**
|
|
34
|
+
* Occurs when using the TCP full mode and the checksum of a received
|
|
35
|
+
* packet doesn't match the expected checksum.
|
|
36
|
+
*/
|
|
37
|
+
class InvalidChecksumError extends Error {
|
|
38
|
+
constructor(checksum, validChecksum) {
|
|
39
|
+
super(`Invalid checksum (${checksum} when ${validChecksum} was expected). This packet should be skipped.`);
|
|
40
|
+
this.checksum = checksum;
|
|
41
|
+
this.validChecksum = validChecksum;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.InvalidChecksumError = InvalidChecksumError;
|
|
45
|
+
/**
|
|
46
|
+
* Occurs when the buffer is invalid, and may contain an HTTP error code.
|
|
47
|
+
* For instance, 404 means "forgotten/broken authorization key", while
|
|
48
|
+
*/
|
|
49
|
+
class InvalidBufferError extends Error {
|
|
50
|
+
constructor(payload) {
|
|
51
|
+
let code = undefined;
|
|
52
|
+
if (payload.length === 4) {
|
|
53
|
+
code = -payload.readInt32LE(0);
|
|
54
|
+
super(`Invalid response buffer (HTTP code ${code})`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
super(`Invalid response buffer (too short ${payload})`);
|
|
58
|
+
}
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.payload = payload;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.InvalidBufferError = InvalidBufferError;
|
|
64
|
+
/**
|
|
65
|
+
* Generic security error, mostly used when generating a new AuthKey.
|
|
66
|
+
*/
|
|
67
|
+
class SecurityError extends Error {
|
|
68
|
+
constructor(...args) {
|
|
69
|
+
if (!args.length) {
|
|
70
|
+
args = ["A security check failed."];
|
|
71
|
+
}
|
|
72
|
+
super(...args);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.SecurityError = SecurityError;
|
|
76
|
+
/**
|
|
77
|
+
* Occurs when there's a hash mismatch between the decrypted CDN file
|
|
78
|
+
* and its expected hash.
|
|
79
|
+
*/
|
|
80
|
+
class CdnFileTamperedError extends SecurityError {
|
|
81
|
+
constructor() {
|
|
82
|
+
super("The CDN file has been altered and its download cancelled.");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.CdnFileTamperedError = CdnFileTamperedError;
|
|
86
|
+
/**
|
|
87
|
+
* Occurs when handling a badMessageNotification
|
|
88
|
+
*/
|
|
89
|
+
class BadMessageError extends Error {
|
|
90
|
+
constructor(request, code) {
|
|
91
|
+
let errorMessage = BadMessageError.ErrorMessages[code] ||
|
|
92
|
+
`Unknown error code (this should not happen): ${code}.`;
|
|
93
|
+
errorMessage += ` Caused by ${request.className}`;
|
|
94
|
+
super(errorMessage);
|
|
95
|
+
this.errorMessage = errorMessage;
|
|
96
|
+
this.code = code;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.BadMessageError = BadMessageError;
|
|
100
|
+
BadMessageError.ErrorMessages = {
|
|
101
|
+
16: "msg_id too low (most likely, client time is wrong it would be worthwhile to " +
|
|
102
|
+
"synchronize it using msg_id notifications and re-send the original message " +
|
|
103
|
+
"with the “correct” msg_id or wrap it in a container with a new msg_id if the " +
|
|
104
|
+
"original message had waited too long on the client to be transmitted).",
|
|
105
|
+
17: "msg_id too high (similar to the previous case, the client time has to be " +
|
|
106
|
+
"synchronized, and the message re-sent with the correct msg_id).",
|
|
107
|
+
18: "Incorrect two lower order msg_id bits (the server expects client message msg_id " +
|
|
108
|
+
"to be divisible by 4).",
|
|
109
|
+
19: "Container msg_id is the same as msg_id of a previously received message " +
|
|
110
|
+
"(this must never happen).",
|
|
111
|
+
20: "Message too old, and it cannot be verified whether the server has received a " +
|
|
112
|
+
"message with this msg_id or not.",
|
|
113
|
+
32: "msg_seqno too low (the server has already received a message with a lower " +
|
|
114
|
+
"msg_id but with either a higher or an equal and odd seqno).",
|
|
115
|
+
33: "msg_seqno too high (similarly, there is a message with a higher msg_id but with " +
|
|
116
|
+
"either a lower or an equal and odd seqno).",
|
|
117
|
+
34: "An even msg_seqno expected (irrelevant message), but odd received.",
|
|
118
|
+
35: "Odd msg_seqno expected (relevant message), but even received.",
|
|
119
|
+
48: "Incorrect server salt (in this case, the bad_server_salt response is received with " +
|
|
120
|
+
"the correct salt, and the message is to be re-sent with it).",
|
|
121
|
+
64: "Invalid container.",
|
|
122
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all Remote Procedure Call errors.
|
|
3
|
+
*/
|
|
4
|
+
import { Api } from "../tl";
|
|
5
|
+
import { CustomError } from "ts-custom-error";
|
|
6
|
+
export declare class RPCError extends CustomError {
|
|
7
|
+
code: number | undefined;
|
|
8
|
+
errorMessage: string;
|
|
9
|
+
constructor(message: string, request: Api.AnyRequest, code?: number);
|
|
10
|
+
static _fmtRequest(request: Api.AnyRequest): string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The request must be repeated, but directed to a different data center.
|
|
14
|
+
*/
|
|
15
|
+
export declare class InvalidDCError extends RPCError {
|
|
16
|
+
constructor(message: string, request: Api.AnyRequest, code?: number);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The query contains errors. In the event that a request was created
|
|
20
|
+
* using a form and contains user generated data, the user should be
|
|
21
|
+
* notified that the data must be corrected before the query is repeated.
|
|
22
|
+
*/
|
|
23
|
+
export declare class BadRequestError extends RPCError {
|
|
24
|
+
code: number;
|
|
25
|
+
errorMessage: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* There was an unauthorized attempt to use functionality available only
|
|
29
|
+
* to authorized users.
|
|
30
|
+
*/
|
|
31
|
+
export declare class UnauthorizedError extends RPCError {
|
|
32
|
+
code: number;
|
|
33
|
+
errorMessage: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Privacy violation. For example, an attempt to write a message to
|
|
37
|
+
* someone who has blacklisted the current user.
|
|
38
|
+
*/
|
|
39
|
+
export declare class ForbiddenError extends RPCError {
|
|
40
|
+
code: number;
|
|
41
|
+
errorMessage: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An attempt to invoke a non-existent object, such as a method.
|
|
45
|
+
*/
|
|
46
|
+
export declare class NotFoundError extends RPCError {
|
|
47
|
+
code: number;
|
|
48
|
+
errorMessage: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Errors related to invalid authorization key, like
|
|
52
|
+
* AUTH_KEY_DUPLICATED which can cause the connection to fail.
|
|
53
|
+
*/
|
|
54
|
+
export declare class AuthKeyError extends RPCError {
|
|
55
|
+
code: number;
|
|
56
|
+
errorMessage: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The maximum allowed number of attempts to invoke the given method
|
|
60
|
+
* with the given input parameters has been exceeded. For example, in an
|
|
61
|
+
* attempt to request a large number of text messages (SMS) for the same
|
|
62
|
+
* phone number.
|
|
63
|
+
*/
|
|
64
|
+
export declare class FloodError extends RPCError {
|
|
65
|
+
code: number;
|
|
66
|
+
errorMessage: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* An internal server error occurred while a request was being processed
|
|
70
|
+
* for example, there was a disruption while accessing a database or file
|
|
71
|
+
* storage
|
|
72
|
+
*/
|
|
73
|
+
export declare class ServerError extends RPCError {
|
|
74
|
+
code: number;
|
|
75
|
+
errorMessage: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Clicking the inline buttons of bots that never (or take to long to)
|
|
79
|
+
* call ``answerCallbackQuery`` will result in this "special" RPCError.
|
|
80
|
+
*/
|
|
81
|
+
export declare class TimedOutError extends RPCError {
|
|
82
|
+
code: number;
|
|
83
|
+
errorMessage: string;
|
|
84
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimedOutError = exports.ServerError = exports.FloodError = exports.AuthKeyError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.InvalidDCError = exports.RPCError = void 0;
|
|
4
|
+
const ts_custom_error_1 = require("ts-custom-error");
|
|
5
|
+
class RPCError extends ts_custom_error_1.CustomError {
|
|
6
|
+
constructor(message, request, code) {
|
|
7
|
+
super("{0}: {1}{2}"
|
|
8
|
+
.replace("{0}", (code === null || code === void 0 ? void 0 : code.toString()) || "")
|
|
9
|
+
.replace("{1}", message || "")
|
|
10
|
+
.replace("{2}", RPCError._fmtRequest(request)));
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.errorMessage = message;
|
|
13
|
+
}
|
|
14
|
+
static _fmtRequest(request) {
|
|
15
|
+
// TODO fix this
|
|
16
|
+
if (request) {
|
|
17
|
+
return ` (caused by ${request.className})`;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.RPCError = RPCError;
|
|
25
|
+
/**
|
|
26
|
+
* The request must be repeated, but directed to a different data center.
|
|
27
|
+
*/
|
|
28
|
+
class InvalidDCError extends RPCError {
|
|
29
|
+
constructor(message, request, code) {
|
|
30
|
+
super(message, request, code);
|
|
31
|
+
this.code = code || 303;
|
|
32
|
+
this.errorMessage = message || "ERROR_SEE_OTHER";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.InvalidDCError = InvalidDCError;
|
|
36
|
+
/**
|
|
37
|
+
* The query contains errors. In the event that a request was created
|
|
38
|
+
* using a form and contains user generated data, the user should be
|
|
39
|
+
* notified that the data must be corrected before the query is repeated.
|
|
40
|
+
*/
|
|
41
|
+
class BadRequestError extends RPCError {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.code = 400;
|
|
45
|
+
this.errorMessage = "BAD_REQUEST";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.BadRequestError = BadRequestError;
|
|
49
|
+
/**
|
|
50
|
+
* There was an unauthorized attempt to use functionality available only
|
|
51
|
+
* to authorized users.
|
|
52
|
+
*/
|
|
53
|
+
class UnauthorizedError extends RPCError {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
this.code = 401;
|
|
57
|
+
this.errorMessage = "UNAUTHORIZED";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
61
|
+
/**
|
|
62
|
+
* Privacy violation. For example, an attempt to write a message to
|
|
63
|
+
* someone who has blacklisted the current user.
|
|
64
|
+
*/
|
|
65
|
+
class ForbiddenError extends RPCError {
|
|
66
|
+
constructor() {
|
|
67
|
+
super(...arguments);
|
|
68
|
+
this.code = 403;
|
|
69
|
+
this.errorMessage = "FORBIDDEN";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ForbiddenError = ForbiddenError;
|
|
73
|
+
/**
|
|
74
|
+
* An attempt to invoke a non-existent object, such as a method.
|
|
75
|
+
*/
|
|
76
|
+
class NotFoundError extends RPCError {
|
|
77
|
+
constructor() {
|
|
78
|
+
super(...arguments);
|
|
79
|
+
this.code = 404;
|
|
80
|
+
this.errorMessage = "NOT_FOUND";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.NotFoundError = NotFoundError;
|
|
84
|
+
/**
|
|
85
|
+
* Errors related to invalid authorization key, like
|
|
86
|
+
* AUTH_KEY_DUPLICATED which can cause the connection to fail.
|
|
87
|
+
*/
|
|
88
|
+
class AuthKeyError extends RPCError {
|
|
89
|
+
constructor() {
|
|
90
|
+
super(...arguments);
|
|
91
|
+
this.code = 406;
|
|
92
|
+
this.errorMessage = "AUTH_KEY";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.AuthKeyError = AuthKeyError;
|
|
96
|
+
/**
|
|
97
|
+
* The maximum allowed number of attempts to invoke the given method
|
|
98
|
+
* with the given input parameters has been exceeded. For example, in an
|
|
99
|
+
* attempt to request a large number of text messages (SMS) for the same
|
|
100
|
+
* phone number.
|
|
101
|
+
*/
|
|
102
|
+
class FloodError extends RPCError {
|
|
103
|
+
constructor() {
|
|
104
|
+
super(...arguments);
|
|
105
|
+
this.code = 420;
|
|
106
|
+
this.errorMessage = "FLOOD";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.FloodError = FloodError;
|
|
110
|
+
/**
|
|
111
|
+
* An internal server error occurred while a request was being processed
|
|
112
|
+
* for example, there was a disruption while accessing a database or file
|
|
113
|
+
* storage
|
|
114
|
+
*/
|
|
115
|
+
class ServerError extends RPCError {
|
|
116
|
+
constructor() {
|
|
117
|
+
super(...arguments);
|
|
118
|
+
this.code = 500; // Also witnessed as -500
|
|
119
|
+
this.errorMessage = "INTERNAL";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.ServerError = ServerError;
|
|
123
|
+
/**
|
|
124
|
+
* Clicking the inline buttons of bots that never (or take to long to)
|
|
125
|
+
* call ``answerCallbackQuery`` will result in this "special" RPCError.
|
|
126
|
+
*/
|
|
127
|
+
class TimedOutError extends RPCError {
|
|
128
|
+
constructor() {
|
|
129
|
+
super(...arguments);
|
|
130
|
+
this.code = 503; // Only witnessed as -503
|
|
131
|
+
this.errorMessage = "Timeout";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.TimedOutError = TimedOutError;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { InvalidDCError, FloodError, BadRequestError } from "./RPCBaseErrors";
|
|
2
|
+
export declare class UserMigrateError extends InvalidDCError {
|
|
3
|
+
newDc: number;
|
|
4
|
+
constructor(args: any);
|
|
5
|
+
}
|
|
6
|
+
export declare class PhoneMigrateError extends InvalidDCError {
|
|
7
|
+
newDc: number;
|
|
8
|
+
constructor(args: any);
|
|
9
|
+
}
|
|
10
|
+
export declare class SlowModeWaitError extends FloodError {
|
|
11
|
+
seconds: number;
|
|
12
|
+
constructor(args: any);
|
|
13
|
+
}
|
|
14
|
+
export declare class FloodWaitError extends FloodError {
|
|
15
|
+
seconds: number;
|
|
16
|
+
constructor(args: any);
|
|
17
|
+
}
|
|
18
|
+
export declare class FloodTestPhoneWaitError extends FloodError {
|
|
19
|
+
seconds: number;
|
|
20
|
+
constructor(args: any);
|
|
21
|
+
}
|
|
22
|
+
export declare class FileMigrateError extends InvalidDCError {
|
|
23
|
+
newDc: number;
|
|
24
|
+
constructor(args: any);
|
|
25
|
+
}
|
|
26
|
+
export declare class NetworkMigrateError extends InvalidDCError {
|
|
27
|
+
newDc: number;
|
|
28
|
+
constructor(args: any);
|
|
29
|
+
}
|
|
30
|
+
export declare class EmailUnconfirmedError extends BadRequestError {
|
|
31
|
+
codeLength: number;
|
|
32
|
+
constructor(args: any);
|
|
33
|
+
}
|
|
34
|
+
export declare class MsgWaitError extends FloodError {
|
|
35
|
+
constructor(args: any);
|
|
36
|
+
}
|
|
37
|
+
export declare const rpcErrorRe: Map<RegExp, any>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rpcErrorRe = exports.MsgWaitError = exports.EmailUnconfirmedError = exports.NetworkMigrateError = exports.FileMigrateError = exports.FloodTestPhoneWaitError = exports.FloodWaitError = exports.SlowModeWaitError = exports.PhoneMigrateError = exports.UserMigrateError = void 0;
|
|
4
|
+
const RPCBaseErrors_1 = require("./RPCBaseErrors");
|
|
5
|
+
class UserMigrateError extends RPCBaseErrors_1.InvalidDCError {
|
|
6
|
+
constructor(args) {
|
|
7
|
+
const newDc = Number(args.capture || 0);
|
|
8
|
+
super(`The user whose identity is being used to execute queries is associated with DC ${newDc}` +
|
|
9
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request), args.request);
|
|
10
|
+
this.message =
|
|
11
|
+
`The user whose identity is being used to execute queries is associated with DC ${newDc}` +
|
|
12
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request);
|
|
13
|
+
this.newDc = newDc;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.UserMigrateError = UserMigrateError;
|
|
17
|
+
class PhoneMigrateError extends RPCBaseErrors_1.InvalidDCError {
|
|
18
|
+
constructor(args) {
|
|
19
|
+
const newDc = Number(args.capture || 0);
|
|
20
|
+
super(`The phone number a user is trying to use for authorization is associated with DC ${newDc}` +
|
|
21
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request), args.request);
|
|
22
|
+
this.message =
|
|
23
|
+
`The phone number a user is trying to use for authorization is associated with DC ${newDc}` +
|
|
24
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request);
|
|
25
|
+
this.newDc = newDc;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.PhoneMigrateError = PhoneMigrateError;
|
|
29
|
+
class SlowModeWaitError extends RPCBaseErrors_1.FloodError {
|
|
30
|
+
constructor(args) {
|
|
31
|
+
const seconds = Number(args.capture || 0);
|
|
32
|
+
super(`A wait of ${seconds} seconds is required before sending another message in this chat` +
|
|
33
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request), args.request);
|
|
34
|
+
this.message =
|
|
35
|
+
`A wait of ${seconds} seconds is required before sending another message in this chat` +
|
|
36
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request);
|
|
37
|
+
this.seconds = seconds;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.SlowModeWaitError = SlowModeWaitError;
|
|
41
|
+
class FloodWaitError extends RPCBaseErrors_1.FloodError {
|
|
42
|
+
constructor(args) {
|
|
43
|
+
const seconds = Number(args.capture || 0);
|
|
44
|
+
super(`A wait of ${seconds} seconds is required` +
|
|
45
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request), args.request);
|
|
46
|
+
this.message =
|
|
47
|
+
`A wait of ${seconds} seconds is required` +
|
|
48
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request);
|
|
49
|
+
this.seconds = seconds;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.FloodWaitError = FloodWaitError;
|
|
53
|
+
class FloodTestPhoneWaitError extends RPCBaseErrors_1.FloodError {
|
|
54
|
+
constructor(args) {
|
|
55
|
+
const seconds = Number(args.capture || 0);
|
|
56
|
+
super(`A wait of ${seconds} seconds is required in the test servers` +
|
|
57
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request), args.request);
|
|
58
|
+
this.message =
|
|
59
|
+
`A wait of ${seconds} seconds is required in the test servers` +
|
|
60
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request);
|
|
61
|
+
this.seconds = seconds;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.FloodTestPhoneWaitError = FloodTestPhoneWaitError;
|
|
65
|
+
class FileMigrateError extends RPCBaseErrors_1.InvalidDCError {
|
|
66
|
+
constructor(args) {
|
|
67
|
+
const newDc = Number(args.capture || 0);
|
|
68
|
+
super(`The file to be accessed is currently stored in DC ${newDc}` +
|
|
69
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request), args.request);
|
|
70
|
+
this.message =
|
|
71
|
+
`The file to be accessed is currently stored in DC ${newDc}` +
|
|
72
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request);
|
|
73
|
+
this.newDc = newDc;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.FileMigrateError = FileMigrateError;
|
|
77
|
+
class NetworkMigrateError extends RPCBaseErrors_1.InvalidDCError {
|
|
78
|
+
constructor(args) {
|
|
79
|
+
const newDc = Number(args.capture || 0);
|
|
80
|
+
super(`The source IP address is associated with DC ${newDc}` +
|
|
81
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request), args.request);
|
|
82
|
+
this.message =
|
|
83
|
+
`The source IP address is associated with DC ${newDc}` +
|
|
84
|
+
RPCBaseErrors_1.RPCError._fmtRequest(args.request);
|
|
85
|
+
this.newDc = newDc;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.NetworkMigrateError = NetworkMigrateError;
|
|
89
|
+
class EmailUnconfirmedError extends RPCBaseErrors_1.BadRequestError {
|
|
90
|
+
constructor(args) {
|
|
91
|
+
const codeLength = Number(args.capture || 0);
|
|
92
|
+
super(`Email unconfirmed, the length of the code must be ${codeLength}${RPCBaseErrors_1.RPCError._fmtRequest(args.request)}`, args.request, 400);
|
|
93
|
+
// eslint-disable-next-line max-len
|
|
94
|
+
this.message = `Email unconfirmed, the length of the code must be ${codeLength}${RPCBaseErrors_1.RPCError._fmtRequest(args.request)}`;
|
|
95
|
+
this.codeLength = codeLength;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.EmailUnconfirmedError = EmailUnconfirmedError;
|
|
99
|
+
class MsgWaitError extends RPCBaseErrors_1.FloodError {
|
|
100
|
+
constructor(args) {
|
|
101
|
+
super(`Message failed to be sent.${RPCBaseErrors_1.RPCError._fmtRequest(args.request)}`, args.request);
|
|
102
|
+
this.message = `Message failed to be sent.${RPCBaseErrors_1.RPCError._fmtRequest(args.request)}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.MsgWaitError = MsgWaitError;
|
|
106
|
+
exports.rpcErrorRe = new Map([
|
|
107
|
+
[/FILE_MIGRATE_(\d+)/, FileMigrateError],
|
|
108
|
+
[/FLOOD_TEST_PHONE_WAIT_(\d+)/, FloodTestPhoneWaitError],
|
|
109
|
+
[/FLOOD_WAIT_(\d+)/, FloodWaitError],
|
|
110
|
+
[/FLOOD_PREMIUM_WAIT_(\d+)/, FloodWaitError],
|
|
111
|
+
[/MSG_WAIT_(.*)/, MsgWaitError],
|
|
112
|
+
[/PHONE_MIGRATE_(\d+)/, PhoneMigrateError],
|
|
113
|
+
[/SLOWMODE_WAIT_(\d+)/, SlowModeWaitError],
|
|
114
|
+
[/USER_MIGRATE_(\d+)/, UserMigrateError],
|
|
115
|
+
[/NETWORK_MIGRATE_(\d+)/, NetworkMigrateError],
|
|
116
|
+
[/EMAIL_UNCONFIRMED_(\d+)/, EmailUnconfirmedError],
|
|
117
|
+
]);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a Telegram's RPC Error to a Python error.
|
|
3
|
+
* @param rpcError the RPCError instance
|
|
4
|
+
* @param request the request that caused this error
|
|
5
|
+
* @constructor the RPCError as a Python exception that represents this error
|
|
6
|
+
*/
|
|
7
|
+
import { Api } from "../tl";
|
|
8
|
+
export declare function RPCMessageToError(rpcError: Api.RpcError, request: Api.AnyRequest): any;
|
|
9
|
+
export * from "./Common";
|
|
10
|
+
export * from "./RPCBaseErrors";
|
|
11
|
+
export * from "./RPCErrorList";
|
package/errors/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.RPCMessageToError = RPCMessageToError;
|
|
18
|
+
const RPCBaseErrors_1 = require("./RPCBaseErrors");
|
|
19
|
+
const RPCErrorList_1 = require("./RPCErrorList");
|
|
20
|
+
function RPCMessageToError(rpcError, request) {
|
|
21
|
+
for (const [msgRegex, Cls] of RPCErrorList_1.rpcErrorRe) {
|
|
22
|
+
const m = rpcError.errorMessage.match(msgRegex);
|
|
23
|
+
if (m) {
|
|
24
|
+
const capture = m.length === 2 ? parseInt(m[1]) : null;
|
|
25
|
+
return new Cls({ request: request, capture: capture });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return new RPCBaseErrors_1.RPCError(rpcError.errorMessage, request, rpcError.errorCode);
|
|
29
|
+
}
|
|
30
|
+
__exportStar(require("./Common"), exports);
|
|
31
|
+
__exportStar(require("./RPCBaseErrors"), exports);
|
|
32
|
+
__exportStar(require("./RPCErrorList"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DefaultEventInterface, EventBuilder, EventCommon } from "./common";
|
|
2
|
+
import { Entity } from "../define";
|
|
3
|
+
import { Api } from "../tl";
|
|
4
|
+
import { TelegramClient } from "..";
|
|
5
|
+
/**
|
|
6
|
+
* Occurs whenever an album (multiple grouped messages with media) arrive.
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Albums are basically a list of messages. so event is a list
|
|
10
|
+
* async function listenForAlbums(event: AlbumEvent) {
|
|
11
|
+
* const messages = event.messages;
|
|
12
|
+
* for (const message of messages){
|
|
13
|
+
* console.log("Caption is",message.text);
|
|
14
|
+
* console.log("Message id is",message.id);
|
|
15
|
+
* console.log("Chat id is",message.chatId);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* // adds an event handler for new messages
|
|
19
|
+
* client.addEventHandler(listenForAlbums, new Album({}));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class Album extends EventBuilder {
|
|
23
|
+
func?: {
|
|
24
|
+
(event: Album): boolean;
|
|
25
|
+
};
|
|
26
|
+
constructor(albumParams: DefaultEventInterface);
|
|
27
|
+
build(update: Api.TypeUpdate, dispatch?: CallableFunction): any;
|
|
28
|
+
}
|
|
29
|
+
export declare class AlbumEvent extends EventCommon {
|
|
30
|
+
messages: Api.Message[];
|
|
31
|
+
originalUpdates: (Api.TypeUpdate & {
|
|
32
|
+
_entities?: Map<string, Entity>;
|
|
33
|
+
})[];
|
|
34
|
+
constructor(messages: Api.Message[], originalUpdates: Api.TypeUpdate[]);
|
|
35
|
+
_setClient(client: TelegramClient): void;
|
|
36
|
+
}
|