teleproto 1.220.0 → 1.221.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/Version.d.ts +1 -1
- package/Version.js +1 -1
- package/client/TelegramClient.d.ts +2 -1
- package/client/TelegramClient.js +3 -2
- package/client/auth.d.ts +4 -1
- package/client/auth.js +25 -5
- package/client/telegramBaseClient.d.ts +7 -0
- package/client/telegramBaseClient.js +1 -0
- package/client/users.js +20 -0
- package/package.json +1 -1
- package/tl/AllTLObjects.d.ts +1 -1
- package/tl/AllTLObjects.js +1 -1
- package/tl/api.d.ts +33736 -33632
- package/tl/apiTl.js +10 -2
package/Version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.221.1";
|
package/Version.js
CHANGED
|
@@ -158,9 +158,10 @@ export declare class TelegramClient extends TelegramBaseClient {
|
|
|
158
158
|
* @param apiCredentials - credentials to be used.
|
|
159
159
|
* @param phoneNumber - the phone number to send the code to
|
|
160
160
|
* @param forceSMS - whether to send it as an SMS or a normal in app message
|
|
161
|
+
* @param reCaptchaCallback - callback to handle reCAPTCHA verification
|
|
161
162
|
* @return the phone code hash and whether it was sent via app
|
|
162
163
|
*/
|
|
163
|
-
sendCode(apiCredentials: authMethods.ApiCredentials, phoneNumber: string, forceSMS?: boolean): Promise<{
|
|
164
|
+
sendCode(apiCredentials: authMethods.ApiCredentials, phoneNumber: string, forceSMS?: boolean, reCaptchaCallback?: (siteKey: string) => Promise<string>): Promise<{
|
|
164
165
|
phoneCodeHash: string;
|
|
165
166
|
isCodeViaApp: boolean;
|
|
166
167
|
}>;
|
package/client/TelegramClient.js
CHANGED
|
@@ -205,10 +205,11 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
|
|
|
205
205
|
* @param apiCredentials - credentials to be used.
|
|
206
206
|
* @param phoneNumber - the phone number to send the code to
|
|
207
207
|
* @param forceSMS - whether to send it as an SMS or a normal in app message
|
|
208
|
+
* @param reCaptchaCallback - callback to handle reCAPTCHA verification
|
|
208
209
|
* @return the phone code hash and whether it was sent via app
|
|
209
210
|
*/
|
|
210
|
-
sendCode(apiCredentials, phoneNumber, forceSMS = false) {
|
|
211
|
-
return authMethods.sendCode(this, apiCredentials, phoneNumber, forceSMS);
|
|
211
|
+
sendCode(apiCredentials, phoneNumber, forceSMS = false, reCaptchaCallback) {
|
|
212
|
+
return authMethods.sendCode(this, apiCredentials, phoneNumber, forceSMS, reCaptchaCallback);
|
|
212
213
|
}
|
|
213
214
|
/**
|
|
214
215
|
* Uses the 2FA password to sign in the account.<br/>
|
package/client/auth.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface UserAuthParams {
|
|
|
27
27
|
onError: (err: Error) => Promise<boolean> | void;
|
|
28
28
|
/** whether to send the code through SMS or not. */
|
|
29
29
|
forceSMS?: boolean;
|
|
30
|
+
/** optional callback for handling reCAPTCHA. */
|
|
31
|
+
reCaptchaCallback?: (siteKey: string) => Promise<string>;
|
|
30
32
|
}
|
|
31
33
|
export interface UserPasswordAuthParams {
|
|
32
34
|
/** optional string or callback that should return the 2FA password if present.<br/>
|
|
@@ -79,7 +81,8 @@ export declare function signInUser(client: TelegramClient, apiCredentials: ApiCr
|
|
|
79
81
|
/** @hidden */
|
|
80
82
|
export declare function signInUserWithQrCode(client: TelegramClient, apiCredentials: ApiCredentials, authParams: QrCodeAuthParams): Promise<Api.TypeUser>;
|
|
81
83
|
/** @hidden */
|
|
82
|
-
|
|
84
|
+
/** @hidden */
|
|
85
|
+
export declare function sendCode(client: TelegramClient, apiCredentials: ApiCredentials, phoneNumber: string, forceSMS?: boolean, reCaptchaCallback?: (siteKey: string) => Promise<string>): Promise<{
|
|
83
86
|
phoneCodeHash: string;
|
|
84
87
|
isCodeViaApp: boolean;
|
|
85
88
|
}>;
|
package/client/auth.js
CHANGED
|
@@ -92,7 +92,7 @@ async function signInUser(client, apiCredentials, authParams) {
|
|
|
92
92
|
else {
|
|
93
93
|
phoneNumber = authParams.phoneNumber;
|
|
94
94
|
}
|
|
95
|
-
const sendCodeResult = await client.sendCode(apiCredentials, phoneNumber, authParams.forceSMS);
|
|
95
|
+
const sendCodeResult = await client.sendCode(apiCredentials, phoneNumber, authParams.forceSMS, authParams.reCaptchaCallback);
|
|
96
96
|
phoneCodeHash = sendCodeResult.phoneCodeHash;
|
|
97
97
|
isCodeViaApp = sendCodeResult.isCodeViaApp;
|
|
98
98
|
if (typeof phoneCodeHash !== "string") {
|
|
@@ -273,15 +273,35 @@ async function signInUserWithQrCode(client, apiCredentials, authParams) {
|
|
|
273
273
|
throw new Error("QR auth failed");
|
|
274
274
|
}
|
|
275
275
|
/** @hidden */
|
|
276
|
-
|
|
276
|
+
/** @hidden */
|
|
277
|
+
async function sendCode(client, apiCredentials, phoneNumber, forceSMS = false, reCaptchaCallback) {
|
|
278
|
+
var _a;
|
|
277
279
|
try {
|
|
278
280
|
const { apiId, apiHash } = apiCredentials;
|
|
279
|
-
const
|
|
281
|
+
const request = new tl_1.Api.auth.SendCode({
|
|
280
282
|
phoneNumber,
|
|
281
283
|
apiId,
|
|
282
284
|
apiHash,
|
|
283
285
|
settings: new tl_1.Api.CodeSettings({}),
|
|
284
|
-
})
|
|
286
|
+
});
|
|
287
|
+
let sendResult;
|
|
288
|
+
try {
|
|
289
|
+
sendResult = await client.invoke(request);
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
const match = (_a = err.errorMessage) === null || _a === void 0 ? void 0 : _a.match(/RECAPTCHA_CHECK_.*(6Le[-\w]+)/);
|
|
293
|
+
if (match && reCaptchaCallback) {
|
|
294
|
+
const siteKey = match[1];
|
|
295
|
+
const token = await reCaptchaCallback(siteKey);
|
|
296
|
+
sendResult = await client.invoke(new tl_1.Api.InvokeWithReCaptcha({
|
|
297
|
+
token: token,
|
|
298
|
+
query: request,
|
|
299
|
+
}));
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
throw err;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
285
305
|
if (sendResult instanceof tl_1.Api.auth.SentCodeSuccess)
|
|
286
306
|
throw new Error("logged in right after sending the code");
|
|
287
307
|
if (!(sendResult instanceof tl_1.Api.auth.SentCode)) {
|
|
@@ -316,7 +336,7 @@ async function sendCode(client, apiCredentials, phoneNumber, forceSMS = false) {
|
|
|
316
336
|
}
|
|
317
337
|
catch (err) {
|
|
318
338
|
if (err.errorMessage === "AUTH_RESTART") {
|
|
319
|
-
return
|
|
339
|
+
return sendCode(client, apiCredentials, phoneNumber, forceSMS, reCaptchaCallback);
|
|
320
340
|
}
|
|
321
341
|
else {
|
|
322
342
|
throw err;
|
|
@@ -110,6 +110,11 @@ export interface TelegramClientParams {
|
|
|
110
110
|
* What type of network connection to use (Normal Socket (for node) or Websockets (for browsers usually) )
|
|
111
111
|
*/
|
|
112
112
|
networkSocket?: typeof PromisedNetSockets | typeof PromisedWebSockets;
|
|
113
|
+
/**
|
|
114
|
+
* Callback for handling reCAPTCHA verification.
|
|
115
|
+
* It should return the token obtained after solving the CAPTCHA.
|
|
116
|
+
*/
|
|
117
|
+
reCaptchaCallback?: (siteKey: string) => Promise<string>;
|
|
113
118
|
}
|
|
114
119
|
export declare abstract class TelegramBaseClient {
|
|
115
120
|
/** The current teleproto version. */
|
|
@@ -166,6 +171,8 @@ export declare abstract class TelegramBaseClient {
|
|
|
166
171
|
/** @hidden */
|
|
167
172
|
_parseMode?: ParseInterface;
|
|
168
173
|
/** @hidden */
|
|
174
|
+
_reCaptchaCallback?: (siteKey: string) => Promise<string>;
|
|
175
|
+
/** @hidden */
|
|
169
176
|
_ALBUMS: Map<string, [NodeJS.Timeout, Api.TypeUpdate[]]>;
|
|
170
177
|
/** @hidden */
|
|
171
178
|
_exportedSenderPromises: Map<number, Promise<MTProtoSender>>;
|
|
@@ -88,6 +88,7 @@ class TelegramBaseClient {
|
|
|
88
88
|
this._semaphore = new async_mutex_1.Semaphore(clientParams.maxConcurrentDownloads || 1);
|
|
89
89
|
this.testServers = clientParams.testServers || false;
|
|
90
90
|
this.networkSocket = clientParams.networkSocket || extensions_1.PromisedNetSockets;
|
|
91
|
+
this._reCaptchaCallback = clientParams.reCaptchaCallback;
|
|
91
92
|
if (!(clientParams.connection instanceof Function)) {
|
|
92
93
|
throw new Error("Connection should be a class not an instance");
|
|
93
94
|
}
|
package/client/users.js
CHANGED
|
@@ -95,6 +95,26 @@ async function invoke(client, request, dcId, otherSender) {
|
|
|
95
95
|
await state.isReady();
|
|
96
96
|
state.after = undefined;
|
|
97
97
|
}
|
|
98
|
+
else if (e.errorMessage &&
|
|
99
|
+
e.errorMessage.startsWith("RECAPTCHA_CHECK_") &&
|
|
100
|
+
client._reCaptchaCallback) {
|
|
101
|
+
const match = e.errorMessage.match(/RECAPTCHA_CHECK_.*(6Le[-\w]+)/);
|
|
102
|
+
if (match) {
|
|
103
|
+
const siteKey = match[1];
|
|
104
|
+
const token = await client._reCaptchaCallback(siteKey);
|
|
105
|
+
const newRequest = new tl_1.Api.InvokeWithReCaptcha({
|
|
106
|
+
token: token,
|
|
107
|
+
query: request,
|
|
108
|
+
});
|
|
109
|
+
await newRequest.resolve(client, __1.utils);
|
|
110
|
+
state.request = newRequest;
|
|
111
|
+
state.data = newRequest.getBytes();
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
state.finished.resolve();
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
98
118
|
else if (e.message === "CONNECTION_NOT_INITED") {
|
|
99
119
|
await client.disconnect();
|
|
100
120
|
await (0, Helpers_1.sleep)(2000);
|
package/package.json
CHANGED
package/tl/AllTLObjects.d.ts
CHANGED
package/tl/AllTLObjects.js
CHANGED