@mtkruto/node 0.0.993 → 0.0.994

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.
Files changed (43) hide show
  1. package/esm/4_constants.d.ts +1 -1
  2. package/esm/4_constants.js +1 -1
  3. package/esm/5_client.d.ts +2 -1
  4. package/esm/5_client.js +2 -1
  5. package/esm/client/0_message.d.ts +3 -3
  6. package/esm/client/0_message.js +3 -3
  7. package/esm/client/0_utilities.d.ts +2 -0
  8. package/esm/client/0_utilities.js +1 -0
  9. package/esm/client/3_types.d.ts +221 -0
  10. package/esm/client/3_types.js +1 -0
  11. package/esm/client/4_composer.d.ts +13 -0
  12. package/esm/client/4_composer.js +80 -0
  13. package/esm/client/5_client.d.ts +207 -0
  14. package/esm/client/{3_client.js → 5_client.js} +92 -153
  15. package/esm/mod.d.ts +1 -1
  16. package/esm/mod.js +1 -1
  17. package/esm/tl/6_message.d.ts +2 -2
  18. package/esm/tl/6_message.js +2 -2
  19. package/esm/tl/7_message_container.d.ts +3 -3
  20. package/esm/tl/7_message_container.js +2 -2
  21. package/package.json +1 -1
  22. package/script/4_constants.d.ts +1 -1
  23. package/script/4_constants.js +1 -1
  24. package/script/5_client.d.ts +2 -1
  25. package/script/5_client.js +4 -1
  26. package/script/client/0_message.d.ts +3 -3
  27. package/script/client/0_message.js +2 -2
  28. package/script/client/0_utilities.d.ts +2 -0
  29. package/script/client/0_utilities.js +3 -1
  30. package/script/client/3_types.d.ts +221 -0
  31. package/script/client/3_types.js +2 -0
  32. package/script/client/4_composer.d.ts +13 -0
  33. package/script/client/4_composer.js +85 -0
  34. package/script/client/5_client.d.ts +207 -0
  35. package/script/client/{3_client.js → 5_client.js} +91 -151
  36. package/script/mod.d.ts +1 -1
  37. package/script/mod.js +2 -14
  38. package/script/tl/6_message.d.ts +2 -2
  39. package/script/tl/6_message.js +4 -4
  40. package/script/tl/7_message_container.d.ts +3 -3
  41. package/script/tl/7_message_container.js +1 -1
  42. package/esm/client/3_client.d.ts +0 -414
  43. package/script/client/3_client.d.ts +0 -414
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.0.993";
8
+ export declare const APP_VERSION = "MTKruto 0.0.994";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
54
54
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
55
55
  export const INITIAL_DC = "2-test";
56
56
  export const LAYER = 161;
57
- export const APP_VERSION = "MTKruto 0.0.993";
57
+ export const APP_VERSION = "MTKruto 0.0.994";
58
58
  // @ts-ignore: lib
59
59
  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;
60
60
  export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
package/esm/5_client.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./client/2_client_plain.js";
2
- export * from "./client/3_client.js";
2
+ export { Composer } from "./client/4_composer.js";
3
+ export * from "./client/5_client.js";
package/esm/5_client.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./client/2_client_plain.js";
2
- export * from "./client/3_client.js";
2
+ export { Composer } from "./client/4_composer.js";
3
+ export * from "./client/5_client.js";
@@ -1,9 +1,9 @@
1
- import { Message, MessageContainer } from "../2_tl.js";
1
+ import { Message_, MessageContainer } from "../2_tl.js";
2
2
  export declare function getMessageId(lastMsgId: bigint): bigint;
3
3
  export declare function packUnencryptedMessage(data: Uint8Array, messageId: bigint): Uint8Array;
4
4
  export declare function unpackUnencryptedMessage(buffer: Uint8Array): {
5
5
  messageId: bigint;
6
6
  message: Uint8Array;
7
7
  };
8
- export declare function encryptMessage(message: Message, authKey: Uint8Array, authKeyId: bigint, salt: bigint, sessionId: bigint): Promise<Uint8Array>;
9
- export declare function decryptMessage(buffer: Uint8Array, authKey: Uint8Array, authKeyId: bigint, _sessionId: bigint): Promise<Message | MessageContainer>;
8
+ export declare function encryptMessage(message: Message_, authKey: Uint8Array, authKeyId: bigint, salt: bigint, sessionId: bigint): Promise<Uint8Array>;
9
+ export declare function decryptMessage(buffer: Uint8Array, authKey: Uint8Array, authKeyId: bigint, _sessionId: bigint): Promise<Message_ | MessageContainer>;
@@ -1,6 +1,6 @@
1
1
  import { assertEquals, ige256Decrypt, ige256Encrypt } from "../0_deps.js";
2
2
  import { bufferFromBigInt, concat, sha256 } from "../1_utilities.js";
3
- import { id, Message, MessageContainer, RPCResult, serialize, TLReader, TLWriter } from "../2_tl.js";
3
+ import { id, Message_, MessageContainer, RPCResult, serialize, TLReader, TLWriter } from "../2_tl.js";
4
4
  export function getMessageId(lastMsgId) {
5
5
  const now = new Date().getTime() / 1000 + 0;
6
6
  const nanoseconds = Math.floor((now - Math.floor(now)) * 1e9);
@@ -80,10 +80,10 @@ export async function decryptMessage(buffer, authKey, authKeyId, _sessionId) {
80
80
  }
81
81
  else if (cid == RPCResult[id]) {
82
82
  const body = RPCResult.deserialize(plainReader.buffer);
83
- return new Message(mid, seqno, body);
83
+ return new Message_(mid, seqno, body);
84
84
  }
85
85
  else {
86
86
  const body = plainReader.readObject(cid);
87
- return new Message(mid, seqno, body);
87
+ return new Message_(mid, seqno, body);
88
88
  }
89
89
  }
@@ -1,3 +1,5 @@
1
1
  import { types } from "../2_tl.js";
2
+ export declare const resolve: () => Promise<void>;
3
+ export type With<T, K extends keyof T> = T & Required<Pick<T, K>>;
2
4
  export declare function isPtsUpdate(v: types.TypeUpdate | types.TypeUpdates): v is types.UpdateShortMessage | types.UpdateShortChatMessage | types.UpdateShortSentMessage | types.UpdateNewMessage | types.UpdateDeleteMessages | types.UpdateReadHistoryInbox | types.UpdateReadHistoryOutbox | types.UpdatePinnedChannelMessages | types.UpdatePinnedMessages | types.UpdateFolderPeers | types.UpdateChannelWebPage | types.UpdateEditMessage | types.UpdateReadMessagesContents | types.UpdateWebPage;
3
5
  export declare function isChannelPtsUpdate(v: types.TypeUpdate | types.TypeUpdates): v is types.UpdateNewChannelMessage | types.UpdateEditChannelMessage | types.UpdateDeleteChannelMessages | types.UpdateReadChannelInbox;
@@ -1,4 +1,5 @@
1
1
  import { types } from "../2_tl.js";
2
+ export const resolve = () => Promise.resolve();
2
3
  export function isPtsUpdate(v) {
3
4
  return v instanceof types.UpdateShortMessage ||
4
5
  v instanceof types.UpdateShortChatMessage ||
@@ -0,0 +1,221 @@
1
+ import { MaybePromise } from "../1_utilities.js";
2
+ import { CallbackQuery, ForceReply, InlineKeyboardMarkup, InlineQuery, Message, MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove } from "../3_types.js";
3
+ import { With } from "./0_utilities.js";
4
+ import { ClientPlainParams } from "./2_client_plain.js";
5
+ export type ParseMode = "html" | "none";
6
+ export interface ClientParams extends ClientPlainParams {
7
+ /**
8
+ * A parse mode to use when the `parseMode` parameter is not specified when sending or editing messages. Defauls to `ParseMode.None`.
9
+ */
10
+ parseMode?: ParseMode;
11
+ /**
12
+ * The app_version parameter to be passed to initConnection when calling `authorize`. It is recommended that this parameter is changed if users are authorized. Defaults to "MTKruto" followed by this version of MTKruto.
13
+ */
14
+ appVersion?: string;
15
+ /**
16
+ * The device_version parameter to be passed to initConnection when calling `authorize`. The default varies by the current runtime.
17
+ */
18
+ deviceModel?: string;
19
+ /**
20
+ * The lang_code parameter to be passed to initConnection when calling `authorize`. Defaults to the runtime's language or `"en"`.
21
+ */
22
+ langCode?: string;
23
+ /**
24
+ * The lang_pack parameter to be passed to initConnection when calling `authorize`. Defaults to an empty string.
25
+ */
26
+ langPack?: string;
27
+ /**
28
+ * The system_lang_cde parameter to be passed to initConnection when calling `authorize`. Defaults to the runtime's language or `"en"`.
29
+ */
30
+ systemLangCode?: string;
31
+ /**
32
+ * The system_version parameter to be passed to initConnection when calling `authorize`. The default varies by the current runtime.
33
+ */
34
+ systemVersion?: string;
35
+ /**
36
+ * Whether to automatically call `start` with no parameters in the first `invoke` call. Defaults to `true`.
37
+ */
38
+ autoStart?: boolean;
39
+ }
40
+ export interface AnswerCallbackQueryParams {
41
+ /** Text of the answer */
42
+ text?: string;
43
+ /** Pass true to show an alert to the user instead of a toast notification */
44
+ alert?: boolean;
45
+ /** URL to be opened */
46
+ url?: string;
47
+ /** Time during which the result of the query can be cached, in seconds */
48
+ cacheTime?: number;
49
+ }
50
+ export interface AuthorizeUserParams<S = string> {
51
+ phone: S | (() => MaybePromise<S>);
52
+ code: S | (() => MaybePromise<S>);
53
+ password: S | ((hint: string | null) => MaybePromise<S>);
54
+ }
55
+ /**
56
+ * A chat identifier as provided by MTKruto or a string starting with a @ that is followed by a username.
57
+ */
58
+ export type ChatID = number | string;
59
+ export interface SendMessagesParams {
60
+ /**
61
+ * The parse mode to use. If not provided, the default parse mode will be used.
62
+ */
63
+ parseMode?: ParseMode;
64
+ /**
65
+ * The message's entities.
66
+ */
67
+ entities?: MessageEntity[];
68
+ /**
69
+ * Whether to disable web page previews in the message that is to be sent.
70
+ */
71
+ disableWebPagePreview?: boolean;
72
+ /**
73
+ * Whether to send the message in a silent way without making a sound on the recipients' clients.
74
+ */
75
+ disableNotification?: boolean;
76
+ /**
77
+ * Whether to protect the contents of the message from copying and forwarding.
78
+ */
79
+ protectContent?: boolean;
80
+ /**
81
+ * The identifier of a message to reply to.
82
+ */
83
+ replyToMessageId?: number;
84
+ /**
85
+ * The identifier of a thread to send the message to.
86
+ */
87
+ messageThreadId?: number;
88
+ /**
89
+ * The identifier of the chat to send the message on behalf of. User-only.
90
+ */
91
+ sendAs?: ChatID;
92
+ /**
93
+ * The reply markup of the message. Bot-only.
94
+ */
95
+ replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
96
+ }
97
+ export interface EditMessageParams {
98
+ /**
99
+ * The parse mode to use. If not provided, the default parse mode will be used.
100
+ */
101
+ parseMode?: ParseMode;
102
+ /**
103
+ * The message's entities.
104
+ */
105
+ entities?: MessageEntity[];
106
+ /**
107
+ * Whether to disable web page previews in the message that is to be edited.
108
+ */
109
+ disableWebPagePreview?: boolean;
110
+ /**
111
+ * The reply markup of the message. Bot-only.
112
+ */
113
+ replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
114
+ }
115
+ export interface ForwardMessagesParams {
116
+ messageThreadId?: number;
117
+ /**
118
+ * Whether to forward the message in a silent way without making a sound on the recipients' clients.
119
+ */
120
+ disableNotification?: boolean;
121
+ /**
122
+ * Whether to protect the contents of the forwarded message from copying and forwarding.
123
+ */
124
+ protectContent?: boolean;
125
+ /**
126
+ * The identifier of the chat to forward the message on behalf of. User-only.
127
+ */
128
+ sendAs?: ChatID;
129
+ /**
130
+ * Whether to not include the original sender of the message that is going to be forwarded.
131
+ */
132
+ dropSenderName?: boolean;
133
+ /**
134
+ * Whether to not include the original caption of the message that is going to be forwarded.
135
+ */
136
+ dropCaption?: boolean;
137
+ }
138
+ export interface SendPollParams {
139
+ /**
140
+ * True, if the poll needs to be anonymous, defaults to True */
141
+ isAnonymous?: boolean;
142
+ /**
143
+ * The type of the poll. Defaults to regular. */
144
+ type?: "quiz" | "regular";
145
+ /**
146
+ * True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False */
147
+ allowMultipleAnswers?: boolean;
148
+ /**
149
+ * Index of the correct option. Required for quizzes. */
150
+ correctOptionIndex?: number;
151
+ /**
152
+ * Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing */
153
+ explanation?: string;
154
+ /**
155
+ * The parse mode to use for the explanation. If not provided, the default parse mode will be used.
156
+ */
157
+ explanationParseMode?: ParseMode;
158
+ /**
159
+ * The explanation's entities.
160
+ */
161
+ explanationEntities?: MessageEntity[];
162
+ /**
163
+ * Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.
164
+ */
165
+ openPeriod?: number;
166
+ /**
167
+ * Point in time when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
168
+ */
169
+ closeDate?: Date;
170
+ /**
171
+ * Pass True if the poll needs to be immediately closed. This can be useful for poll preview.
172
+ */
173
+ isClosed?: boolean;
174
+ /**
175
+ * Whether to send the message in a silent way without making a sound on the recipients' clients.
176
+ */
177
+ disableNotification?: boolean;
178
+ /**
179
+ * The identifier of a message to reply to.
180
+ */
181
+ replyToMessageId?: number;
182
+ /**
183
+ * The identifier of a thread to send the message to.
184
+ */
185
+ messageThreadId?: number;
186
+ /**
187
+ * The identifier of the chat to send the message on behalf of. User-only.
188
+ */
189
+ sendAs?: ChatID;
190
+ /**
191
+ * The reply markup of the message. Bot-only.
192
+ */
193
+ replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
194
+ /**
195
+ * Whether to protect the contents of the message from copying and forwarding.
196
+ */
197
+ protectContent?: boolean;
198
+ }
199
+ export type ConnectionState = "not-connected" | "updating" | "ready";
200
+ export type AuthorizationState = {
201
+ authorized: boolean;
202
+ };
203
+ export type FilterableUpdates = "message" | "editedMessage" | "callbackQuery";
204
+ export interface Update {
205
+ message?: Message;
206
+ editedMessage?: Message;
207
+ connectionState?: ConnectionState;
208
+ authorizationState?: AuthorizationState;
209
+ deletedMessages?: [Message, ...Message[]];
210
+ callbackQuery?: CallbackQuery;
211
+ inlineQuery?: InlineQuery;
212
+ }
213
+ export type NextFn = () => Promise<void>;
214
+ export interface HandlerObj<U extends Partial<Update> = Partial<Update>> {
215
+ handle(update: U, next: NextFn): MaybePromise<void>;
216
+ }
217
+ export type HandlerFn<U extends Partial<Update> = Partial<Update>> = HandlerObj<U>["handle"];
218
+ export type Handler<U extends Partial<Update> = Partial<Update>> = HandlerObj<U> | HandlerFn<U>;
219
+ export type FilterUpdate<U extends Update, T extends keyof U, F extends keyof NonNullable<U[T]>> = With<U, T> & Pick<{
220
+ [P in T]-?: With<NonNullable<U[T]>, F>;
221
+ }, T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { MaybePromise } from "../1_utilities.js";
2
+ import { FilterableUpdates, FilterUpdate, Handler, HandlerFn, HandlerObj, Update } from "./3_types.js";
3
+ export declare function call(handler: Handler): HandlerFn;
4
+ export declare class Composer<U extends Update = Update> implements HandlerObj<U> {
5
+ constructor(...handlers: Handler<U>[]);
6
+ get handle(): HandlerFn;
7
+ private _handle;
8
+ use(...handlers: Handler<U>[]): this;
9
+ branch(predicate: (upd: U) => MaybePromise<boolean>, trueHandler: Handler<U>, falseHandler: Handler<U>): this;
10
+ filter<D extends U>(predicate: (ctx: U) => ctx is D, ...middleware: Handler<D>[]): Composer<D>;
11
+ filter(predicate: (ctx: U) => MaybePromise<boolean>, ...middleware: Handler<U>[]): Composer<U>;
12
+ on<T extends keyof U, F extends keyof NonNullable<U[T]>>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...handlers: Handler<FilterUpdate<U, T, F>>[]): Composer<FilterUpdate<U, T, F>>;
13
+ }
@@ -0,0 +1,80 @@
1
+ import { resolve } from "./0_utilities.js";
2
+ export function call(handler) {
3
+ if ("handle" in handler) {
4
+ return handler.handle;
5
+ }
6
+ else {
7
+ return handler;
8
+ }
9
+ }
10
+ function concat(what, with_) {
11
+ return async (upd, next) => {
12
+ let called = false;
13
+ await call(what)(upd, async () => {
14
+ if (called)
15
+ return;
16
+ called = true;
17
+ await call(with_)(upd, next);
18
+ });
19
+ };
20
+ }
21
+ function reduce(...handlers) {
22
+ return handlers.reduce((a, b) => concat(a, b));
23
+ }
24
+ export class Composer {
25
+ constructor(...handlers) {
26
+ Object.defineProperty(this, "_handle", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: resolve
31
+ });
32
+ this.use(...handlers);
33
+ }
34
+ get handle() {
35
+ return this._handle;
36
+ }
37
+ use(...handlers) {
38
+ const handle = this.handle;
39
+ this._handle = concat(handle, reduce(...handlers));
40
+ return this;
41
+ }
42
+ branch(predicate, trueHandler, falseHandler) {
43
+ return this.use(async (upd, next) => {
44
+ if (await predicate(upd)) {
45
+ await call(trueHandler)(upd, next);
46
+ }
47
+ else {
48
+ await call(falseHandler)(upd, next);
49
+ }
50
+ });
51
+ }
52
+ filter(predicate, ...middleware) {
53
+ const composer = new Composer(...middleware);
54
+ this.branch(predicate, composer, resolve);
55
+ return composer;
56
+ }
57
+ on(filter, ...handlers) {
58
+ // deno-lint-ignore ban-ts-comment
59
+ // @ts-ignore
60
+ const type = typeof filter === "string" ? filter : filter[0];
61
+ const keys = Array.isArray(filter) ? filter.slice(1) : [];
62
+ return this.filter((update) => {
63
+ if (type in update) {
64
+ if (keys.length > 0) {
65
+ for (const key of keys) {
66
+ // deno-lint-ignore ban-ts-comment
67
+ // @ts-ignore
68
+ if (!(key in update[type])) {
69
+ return false;
70
+ }
71
+ }
72
+ }
73
+ return true;
74
+ }
75
+ else {
76
+ return false;
77
+ }
78
+ }, ...handlers);
79
+ }
80
+ }
@@ -0,0 +1,207 @@
1
+ import { functions, ReadObject, types } from "../2_tl.js";
2
+ import { Storage } from "../3_storage.js";
3
+ import { DC } from "../3_transport.js";
4
+ import { Message } from "../3_types.js";
5
+ import { With } from "./0_utilities.js";
6
+ import { ClientAbstract } from "./1_client_abstract.js";
7
+ import { AnswerCallbackQueryParams, AuthorizeUserParams, ChatID, ClientParams, EditMessageParams, ForwardMessagesParams, Handler, ParseMode, SendMessagesParams, SendPollParams } from "./3_types.js";
8
+ export declare const getEntity: unique symbol;
9
+ export declare const getStickerSetName: unique symbol;
10
+ export declare const handleMigrationError: unique symbol;
11
+ export declare const getMessageWithReply: unique symbol;
12
+ export declare const restartAuth: unique symbol;
13
+ export declare class Client extends ClientAbstract {
14
+ readonly storage: Storage;
15
+ readonly apiId: number | null;
16
+ readonly apiHash: string | null;
17
+ private auth;
18
+ private sessionId;
19
+ private state;
20
+ private promises;
21
+ private toAcknowledge;
22
+ private updateState?;
23
+ readonly parseMode: ParseMode;
24
+ readonly appVersion: string;
25
+ readonly deviceModel: string;
26
+ readonly langCode: string;
27
+ readonly langPack: string;
28
+ readonly systemLangCode: string;
29
+ readonly systemVersion: string;
30
+ private readonly publicKeys?;
31
+ private readonly autoStart;
32
+ /**
33
+ * Constructs the client.
34
+ *
35
+ * @param storage The storage provider to use. Defaults to memory storage.
36
+ * @param apiId App's API ID from [my.telegram.org](https://my.telegram.org/apps). Defaults to 0 (unset).
37
+ * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Defaults to empty string (unset).
38
+ * @param params Other parameters.
39
+ */
40
+ constructor(storage?: Storage, apiId?: number | null, apiHash?: string | null, params?: ClientParams);
41
+ private propagateConnectionState;
42
+ private lastPropagatedConnectionState;
43
+ protected stateChangeHandler: (connected: boolean) => void;
44
+ private storageInited;
45
+ /**
46
+ * Sets the DC and resets the auth key stored in the session provider
47
+ * if the stored DC was not the same as the `dc` parameter.
48
+ *
49
+ * @param dc The DC to change to.
50
+ */
51
+ setDc(dc: DC): Promise<void>;
52
+ private setAuth;
53
+ private connectMutex;
54
+ /**
55
+ * Loads the session if `setDc` was not called, initializes and connnects
56
+ * a `ClientPlain` to generate auth key if there was none, and connects the client.
57
+ * Before establishing the connection, the session is saved.
58
+ */
59
+ connect(): Promise<void>;
60
+ private assertUser;
61
+ private assertBot;
62
+ private fetchState;
63
+ [handleMigrationError](err: types.RPCError): Promise<void>;
64
+ private connectionInited;
65
+ disconnect(): Promise<void>;
66
+ private initConnection;
67
+ private lastPropagatedAuthorizationState;
68
+ private propagateAuthorizationState;
69
+ /**
70
+ * Calls [initConnection](1) and authorizes the client with one of the following:
71
+ *
72
+ * - Bot token (`string`)
73
+ * - Exported authorization (`types.AuthExportedAuthorization`)
74
+ * - User authorization handlers (`AuthorizeUserParams`)
75
+ *
76
+ * if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](2).
77
+ *
78
+ * Notes:
79
+ * 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
80
+ * 2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
81
+ * 3. The parameters passed to the [initConnection][1] call can be configured with the last parameter of the constructor.
82
+ *
83
+ * [1]: https://core.telegram.org/method/initConnection
84
+ * [2]: https://core.telegram.org/method/updates.getState
85
+ */
86
+ authorize(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
87
+ /**
88
+ * Same as calling `.connect()` followed by `.authorize(params)`.
89
+ */
90
+ start(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
91
+ private receiveLoop;
92
+ private pingLoop;
93
+ private autoStarted;
94
+ private lastMsgId;
95
+ /**
96
+ * Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
97
+ * to be connected.
98
+ *
99
+ * @param function_ The function to invoke.
100
+ */
101
+ invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<T extends functions.Function<unknown> ? T["__R"] : void>;
102
+ invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T, noWait: true): Promise<void>;
103
+ /**
104
+ * Alias for `invoke` with its second parameter being `true`.
105
+ */
106
+ send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
107
+ private processChats;
108
+ private processUsers;
109
+ private handleUpdateQueue;
110
+ private processUpdatesQueue;
111
+ private checkGap;
112
+ private checkChannelGap;
113
+ private processUpdates;
114
+ private setUpdateStateDate;
115
+ private getLocalState;
116
+ private recoverUpdateGap;
117
+ private recoverChannelUpdateGap;
118
+ private getUserAccessHash;
119
+ private getChannelAccessHash;
120
+ getInputPeer(id: ChatID): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
121
+ private getInputPeerInner;
122
+ [getEntity](peer: types.PeerUser): Promise<types.User | null>;
123
+ [getEntity](peer: types.PeerChat): Promise<types.Chat | null>;
124
+ [getEntity](peer: types.PeerChannel): Promise<types.Channel | null>;
125
+ processResult(result: ReadObject): Promise<void>;
126
+ private updatesToMessages;
127
+ private resolveSendAs;
128
+ /**
129
+ * Send a text message.
130
+ *
131
+ * @param chatId The chat to send the message to.
132
+ * @param text The message's text.
133
+ */
134
+ sendMessage(chatId: ChatID, text: string, params?: SendMessagesParams): Promise<With<Message, "text">>;
135
+ private parseText;
136
+ /**
137
+ * Edit a message's text.
138
+ *
139
+ * @param chatId The chat where the message is.
140
+ * @param messageId The ID of the message.
141
+ * @param text The new text of the message.
142
+ */
143
+ editMessageText(chatId: ChatID, messageId: number, text: string, params?: EditMessageParams): Promise<void>;
144
+ private getMessagesInner;
145
+ /**
146
+ * Retrieve multiple messages.
147
+ *
148
+ * @param chatId The identifier of the chat to retrieve the messages from.
149
+ * @param messageIds The identifiers of the messages to retrieve.
150
+ */
151
+ getMessages(chatId_: ChatID, messageIds: number[]): Promise<Omit<Message, "replyToMessage">[]>;
152
+ [getMessageWithReply](chatId: ChatID, messageId: number): Promise<Message | null>;
153
+ /**
154
+ * Retrieve a single message.
155
+ *
156
+ * @param chatId The identifier of the chat to retrieve the message from.
157
+ * @param messageId The identifier of the message to retrieve.
158
+ */
159
+ getMessage(chatId: ChatID, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>;
160
+ private downloadInner;
161
+ /**
162
+ * Download a file.
163
+ *
164
+ * @param fileId The identifier of the file to download.
165
+ */
166
+ download(fileId: string): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
167
+ [getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
168
+ /**
169
+ * Forward multiple messages.
170
+ *
171
+ * @param from The identifier of the chat to forward the messages from.
172
+ * @param to The identifier of the chat to forward the messages to.
173
+ * @param messageIds The identifiers of the messages to forward.
174
+ */
175
+ forwardMessages(from: ChatID, to: ChatID, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
176
+ /**
177
+ * Forward a single message.
178
+ *
179
+ * @param from The identifier of the chat to forward the message from.
180
+ * @param to The identifier of the chat to forward the message to.
181
+ * @param messageId The identifier of the message to forward.
182
+ */
183
+ forwardMessage(from: ChatID, to: ChatID, messageId: number, params?: ForwardMessagesParams): Promise<Message>;
184
+ /**
185
+ * Get information on the currently authorized user.
186
+ */
187
+ getMe(): Promise<import("../3_types.js").User>;
188
+ private handleUpdate;
189
+ private _handler;
190
+ set handler(handler: Handler);
191
+ /**
192
+ * Answer a callback query. Bot-only.
193
+ *
194
+ * @param id ID of the callback query to answer.
195
+ */
196
+ answerCallbackQuery(id: string, params?: AnswerCallbackQueryParams): Promise<void>;
197
+ private constructReplyMarkup;
198
+ private static assertMsgHas;
199
+ /**
200
+ * Send a poll.
201
+ *
202
+ * @param chatId The chat to send the poll to.
203
+ * @param question The poll's question.
204
+ * @param options The poll's options.
205
+ */
206
+ sendPoll(chatId: ChatID, question: string, options: [string, string, ...string[]], params?: SendPollParams): Promise<With<Message, "poll">>;
207
+ }