teleproto 1.221.2 → 1.221.3
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 +56 -4
- package/client/TelegramClient.js +61 -0
- package/client/auth.d.ts +101 -4
- package/client/auth.js +178 -3
- package/client/updates.js +4 -1
- package/client/uploads.d.ts +1 -1
- package/client/uploads.js +9 -3
- package/index.d.ts +2 -1
- package/index.js +3 -1
- package/package.json +1 -1
package/Version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.221.
|
|
1
|
+
export declare const version = "1.221.3";
|
package/Version.js
CHANGED
|
@@ -161,10 +161,62 @@ export declare class TelegramClient extends TelegramBaseClient {
|
|
|
161
161
|
* @param reCaptchaCallback - callback to handle reCAPTCHA verification
|
|
162
162
|
* @return the phone code hash and whether it was sent via app
|
|
163
163
|
*/
|
|
164
|
-
sendCode(apiCredentials: authMethods.ApiCredentials, phoneNumber: string, forceSMS?: boolean, reCaptchaCallback?: (siteKey: string) => Promise<string>): Promise<
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
sendCode(apiCredentials: authMethods.ApiCredentials, phoneNumber: string, forceSMS?: boolean, reCaptchaCallback?: (siteKey: string) => Promise<string>): Promise<authMethods.SendCodeResult>;
|
|
165
|
+
/**
|
|
166
|
+
* Sends an email verification code for login setup.
|
|
167
|
+
* This is used when Telegram requires email verification during login.
|
|
168
|
+
* @param phoneNumber - The phone number being used for login
|
|
169
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
170
|
+
* @param email - The email address to verify
|
|
171
|
+
* @returns The email pattern and code length
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const result = await client.sendVerifyEmailCode(
|
|
175
|
+
* "+1234567890",
|
|
176
|
+
* "abc123hash",
|
|
177
|
+
* "user@example.com"
|
|
178
|
+
* );
|
|
179
|
+
* console.log(`Code sent to ${result.emailPattern}, length: ${result.length}`);
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
sendVerifyEmailCode(phoneNumber: string, phoneCodeHash: string, email: string): Promise<authMethods.SentEmailCodeResult>;
|
|
183
|
+
/**
|
|
184
|
+
* Verifies an email address during login setup.
|
|
185
|
+
* @param phoneNumber - The phone number being used for login
|
|
186
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
187
|
+
* @param verification - The verification result (code, Google token, or Apple token)
|
|
188
|
+
* @returns The verified email and the new sent code for phone verification
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* // Verify with email code
|
|
192
|
+
* const result = await client.verifyEmail(
|
|
193
|
+
* "+1234567890",
|
|
194
|
+
* "abc123hash",
|
|
195
|
+
* { type: "code", code: "12345" }
|
|
196
|
+
* );
|
|
197
|
+
*
|
|
198
|
+
* // Or verify with Google Sign-In
|
|
199
|
+
* const result = await client.verifyEmail(
|
|
200
|
+
* "+1234567890",
|
|
201
|
+
* "abc123hash",
|
|
202
|
+
* { type: "google", token: "google-id-token" }
|
|
203
|
+
* );
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
verifyEmail(phoneNumber: string, phoneCodeHash: string, verification: authMethods.EmailVerificationResult): Promise<authMethods.EmailVerifiedLoginResult>;
|
|
207
|
+
/**
|
|
208
|
+
* Resets the login email when the user cannot access their current email.
|
|
209
|
+
* This will cancel the current email verification and allow setting up a new one.
|
|
210
|
+
* @param phoneNumber - The phone number being used for login
|
|
211
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
212
|
+
* @returns The new sent code result
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* // User can't access their email, reset it
|
|
216
|
+
* const newSentCode = await client.resetLoginEmail("+1234567890", "abc123hash");
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
resetLoginEmail(phoneNumber: string, phoneCodeHash: string): Promise<Api.auth.TypeSentCode>;
|
|
168
220
|
/**
|
|
169
221
|
* Uses the 2FA password to sign in the account.<br/>
|
|
170
222
|
* This function should be used after the user has signed in with the code they received.
|
package/client/TelegramClient.js
CHANGED
|
@@ -211,6 +211,67 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
|
|
|
211
211
|
sendCode(apiCredentials, phoneNumber, forceSMS = false, reCaptchaCallback) {
|
|
212
212
|
return authMethods.sendCode(this, apiCredentials, phoneNumber, forceSMS, reCaptchaCallback);
|
|
213
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Sends an email verification code for login setup.
|
|
216
|
+
* This is used when Telegram requires email verification during login.
|
|
217
|
+
* @param phoneNumber - The phone number being used for login
|
|
218
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
219
|
+
* @param email - The email address to verify
|
|
220
|
+
* @returns The email pattern and code length
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* const result = await client.sendVerifyEmailCode(
|
|
224
|
+
* "+1234567890",
|
|
225
|
+
* "abc123hash",
|
|
226
|
+
* "user@example.com"
|
|
227
|
+
* );
|
|
228
|
+
* console.log(`Code sent to ${result.emailPattern}, length: ${result.length}`);
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
sendVerifyEmailCode(phoneNumber, phoneCodeHash, email) {
|
|
232
|
+
return authMethods.sendVerifyEmailCode(this, phoneNumber, phoneCodeHash, email);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Verifies an email address during login setup.
|
|
236
|
+
* @param phoneNumber - The phone number being used for login
|
|
237
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
238
|
+
* @param verification - The verification result (code, Google token, or Apple token)
|
|
239
|
+
* @returns The verified email and the new sent code for phone verification
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* // Verify with email code
|
|
243
|
+
* const result = await client.verifyEmail(
|
|
244
|
+
* "+1234567890",
|
|
245
|
+
* "abc123hash",
|
|
246
|
+
* { type: "code", code: "12345" }
|
|
247
|
+
* );
|
|
248
|
+
*
|
|
249
|
+
* // Or verify with Google Sign-In
|
|
250
|
+
* const result = await client.verifyEmail(
|
|
251
|
+
* "+1234567890",
|
|
252
|
+
* "abc123hash",
|
|
253
|
+
* { type: "google", token: "google-id-token" }
|
|
254
|
+
* );
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
verifyEmail(phoneNumber, phoneCodeHash, verification) {
|
|
258
|
+
return authMethods.verifyEmail(this, phoneNumber, phoneCodeHash, verification);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Resets the login email when the user cannot access their current email.
|
|
262
|
+
* This will cancel the current email verification and allow setting up a new one.
|
|
263
|
+
* @param phoneNumber - The phone number being used for login
|
|
264
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
265
|
+
* @returns The new sent code result
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* // User can't access their email, reset it
|
|
269
|
+
* const newSentCode = await client.resetLoginEmail("+1234567890", "abc123hash");
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
resetLoginEmail(phoneNumber, phoneCodeHash) {
|
|
273
|
+
return authMethods.resetLoginEmail(this, phoneNumber, phoneCodeHash);
|
|
274
|
+
}
|
|
214
275
|
/**
|
|
215
276
|
* Uses the 2FA password to sign in the account.<br/>
|
|
216
277
|
* This function should be used after the user has signed in with the code they received.
|
package/client/auth.d.ts
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { Api } from "../tl";
|
|
2
2
|
import type { TelegramClient } from "./TelegramClient";
|
|
3
|
+
/**
|
|
4
|
+
* Email verification options passed to the email callback.
|
|
5
|
+
*/
|
|
6
|
+
export interface EmailVerificationOptions {
|
|
7
|
+
/** Whether Google Sign-In is allowed for email verification. */
|
|
8
|
+
googleSigninAllowed?: boolean;
|
|
9
|
+
/** Whether Apple Sign-In is allowed for email verification. */
|
|
10
|
+
appleSigninAllowed?: boolean;
|
|
11
|
+
/** The email pattern (masked email) when code was sent to existing email. */
|
|
12
|
+
emailPattern?: string;
|
|
13
|
+
/** The code length when email code is expected. */
|
|
14
|
+
codeLength?: number;
|
|
15
|
+
/** Period in seconds after which the email can be reset. */
|
|
16
|
+
resetAvailablePeriod?: number;
|
|
17
|
+
/** Date when the pending reset will complete. */
|
|
18
|
+
resetPendingDate?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Result from the email callback - can be code, Google token, or Apple token.
|
|
22
|
+
*/
|
|
23
|
+
export type EmailVerificationResult = {
|
|
24
|
+
type: "code";
|
|
25
|
+
code: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "google";
|
|
28
|
+
token: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: "apple";
|
|
31
|
+
token: string;
|
|
32
|
+
};
|
|
3
33
|
/**
|
|
4
34
|
* For when you want to login as a {@link Api.User}<br/>
|
|
5
35
|
* this should handle all needed steps for authorization as a user.<br/>
|
|
@@ -29,6 +59,14 @@ export interface UserAuthParams {
|
|
|
29
59
|
forceSMS?: boolean;
|
|
30
60
|
/** optional callback for handling reCAPTCHA. */
|
|
31
61
|
reCaptchaCallback?: (siteKey: string) => Promise<string>;
|
|
62
|
+
/** callback for email verification when Telegram requires email setup or code.<br/>
|
|
63
|
+
* Called when `auth.SentCodeTypeSetUpEmailRequired` or `auth.SentCodeTypeEmailCode` is received.<br/>
|
|
64
|
+
* For setup: should return email address to use and then handle verification code.<br/>
|
|
65
|
+
* For existing email: should return the verification result (code, Google token, or Apple token). */
|
|
66
|
+
emailVerification?: (options: EmailVerificationOptions) => Promise<EmailVerificationResult>;
|
|
67
|
+
/** callback to get email address when email setup is required.<br/>
|
|
68
|
+
* Called first when `auth.SentCodeTypeSetUpEmailRequired` is received. */
|
|
69
|
+
emailAddress?: () => Promise<string>;
|
|
32
70
|
}
|
|
33
71
|
export interface UserPasswordAuthParams {
|
|
34
72
|
/** optional string or callback that should return the 2FA password if present.<br/>
|
|
@@ -80,16 +118,75 @@ export declare function checkAuthorization(client: TelegramClient): Promise<bool
|
|
|
80
118
|
export declare function signInUser(client: TelegramClient, apiCredentials: ApiCredentials, authParams: UserAuthParams): Promise<Api.TypeUser>;
|
|
81
119
|
/** @hidden */
|
|
82
120
|
export declare function signInUserWithQrCode(client: TelegramClient, apiCredentials: ApiCredentials, authParams: QrCodeAuthParams): Promise<Api.TypeUser>;
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Result from sendCode containing info about how to proceed with verification.
|
|
123
|
+
*/
|
|
124
|
+
export interface SendCodeResult {
|
|
125
|
+
/** The phone code hash needed for sign in. */
|
|
86
126
|
phoneCodeHash: string;
|
|
127
|
+
/** Whether the code was sent via Telegram app (true) or SMS (false). */
|
|
87
128
|
isCodeViaApp: boolean;
|
|
88
|
-
|
|
129
|
+
/** If true, email setup is required before phone code. */
|
|
130
|
+
emailRequired?: boolean;
|
|
131
|
+
/** If true, code was sent to existing email. */
|
|
132
|
+
emailCodeSent?: boolean;
|
|
133
|
+
/** Email verification options when email is involved. */
|
|
134
|
+
emailOptions?: EmailVerificationOptions;
|
|
135
|
+
}
|
|
136
|
+
/** @hidden */
|
|
137
|
+
export declare function sendCode(client: TelegramClient, apiCredentials: ApiCredentials, phoneNumber: string, forceSMS?: boolean, reCaptchaCallback?: (siteKey: string) => Promise<string>): Promise<SendCodeResult>;
|
|
89
138
|
/** @hidden */
|
|
90
139
|
export declare function signInWithPassword(client: TelegramClient, apiCredentials: ApiCredentials, authParams: UserPasswordAuthParams): Promise<Api.TypeUser>;
|
|
91
140
|
/** @hidden */
|
|
92
141
|
export declare function signInBot(client: TelegramClient, apiCredentials: ApiCredentials, authParams: BotAuthParams): Promise<Api.TypeUser>;
|
|
93
142
|
/** @hidden */
|
|
94
143
|
export declare function _authFlow(client: TelegramClient, apiCredentials: ApiCredentials, authParams: UserAuthParams | BotAuthParams): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Result from sendVerifyEmailCode.
|
|
146
|
+
*/
|
|
147
|
+
export interface SentEmailCodeResult {
|
|
148
|
+
/** The masked email pattern where the code was sent. */
|
|
149
|
+
emailPattern: string;
|
|
150
|
+
/** The length of the verification code. */
|
|
151
|
+
length: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sends an email verification code for login setup.
|
|
155
|
+
* @param client - The telegram client
|
|
156
|
+
* @param phoneNumber - The phone number being used for login
|
|
157
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
158
|
+
* @param email - The email address to verify
|
|
159
|
+
* @returns The email pattern and code length
|
|
160
|
+
*/
|
|
161
|
+
/** @hidden */
|
|
162
|
+
export declare function sendVerifyEmailCode(client: TelegramClient, phoneNumber: string, phoneCodeHash: string, email: string): Promise<SentEmailCodeResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Result from verifyEmail for login.
|
|
165
|
+
*/
|
|
166
|
+
export interface EmailVerifiedLoginResult {
|
|
167
|
+
/** The verified email address. */
|
|
168
|
+
email: string;
|
|
169
|
+
/** The new sent code result to continue with phone verification. */
|
|
170
|
+
sentCode: Api.auth.TypeSentCode;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Verifies an email address during login setup.
|
|
174
|
+
* @param client - The telegram client
|
|
175
|
+
* @param phoneNumber - The phone number being used for login
|
|
176
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
177
|
+
* @param verification - The verification (code, Google token, or Apple token)
|
|
178
|
+
* @returns The verified email and the new sent code for phone verification
|
|
179
|
+
*/
|
|
180
|
+
/** @hidden */
|
|
181
|
+
export declare function verifyEmail(client: TelegramClient, phoneNumber: string, phoneCodeHash: string, verification: EmailVerificationResult): Promise<EmailVerifiedLoginResult>;
|
|
182
|
+
/**
|
|
183
|
+
* Resets the login email when the user cannot access their current email.
|
|
184
|
+
* This will cancel the current email verification and allow setting up a new one.
|
|
185
|
+
* @param client - The telegram client
|
|
186
|
+
* @param phoneNumber - The phone number being used for login
|
|
187
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
188
|
+
* @returns The new sent code result
|
|
189
|
+
*/
|
|
190
|
+
/** @hidden */
|
|
191
|
+
export declare function resetLoginEmail(client: TelegramClient, phoneNumber: string, phoneCodeHash: string): Promise<Api.auth.TypeSentCode>;
|
|
95
192
|
export {};
|
package/client/auth.js
CHANGED
|
@@ -41,6 +41,9 @@ exports.sendCode = sendCode;
|
|
|
41
41
|
exports.signInWithPassword = signInWithPassword;
|
|
42
42
|
exports.signInBot = signInBot;
|
|
43
43
|
exports._authFlow = _authFlow;
|
|
44
|
+
exports.sendVerifyEmailCode = sendVerifyEmailCode;
|
|
45
|
+
exports.verifyEmail = verifyEmail;
|
|
46
|
+
exports.resetLoginEmail = resetLoginEmail;
|
|
44
47
|
const tl_1 = require("../tl");
|
|
45
48
|
const utils = __importStar(require("../Utils"));
|
|
46
49
|
const Helpers_1 = require("../Helpers");
|
|
@@ -73,8 +76,8 @@ async function checkAuthorization(client) {
|
|
|
73
76
|
}
|
|
74
77
|
/** @hidden */
|
|
75
78
|
async function signInUser(client, apiCredentials, authParams) {
|
|
76
|
-
let phoneNumber;
|
|
77
|
-
let phoneCodeHash;
|
|
79
|
+
let phoneNumber = "";
|
|
80
|
+
let phoneCodeHash = "";
|
|
78
81
|
let isCodeViaApp = false;
|
|
79
82
|
while (1) {
|
|
80
83
|
try {
|
|
@@ -98,6 +101,45 @@ async function signInUser(client, apiCredentials, authParams) {
|
|
|
98
101
|
if (typeof phoneCodeHash !== "string") {
|
|
99
102
|
throw new Error("Failed to retrieve phone code hash");
|
|
100
103
|
}
|
|
104
|
+
// Handle email verification if required
|
|
105
|
+
if (sendCodeResult.emailRequired) {
|
|
106
|
+
// Email setup is required before phone code
|
|
107
|
+
if (!authParams.emailAddress || !authParams.emailVerification) {
|
|
108
|
+
throw new Error("Email verification required but emailAddress or emailVerification callback not provided");
|
|
109
|
+
}
|
|
110
|
+
// Get email address from user
|
|
111
|
+
const email = await authParams.emailAddress();
|
|
112
|
+
// Send verification code to email
|
|
113
|
+
const emailCodeResult = await sendVerifyEmailCode(client, phoneNumber, phoneCodeHash, email);
|
|
114
|
+
// Get verification from user
|
|
115
|
+
const verification = await authParams.emailVerification(Object.assign(Object.assign({}, sendCodeResult.emailOptions), { emailPattern: emailCodeResult.emailPattern, codeLength: emailCodeResult.length }));
|
|
116
|
+
// Verify email
|
|
117
|
+
const verifyResult = await verifyEmail(client, phoneNumber, phoneCodeHash, verification);
|
|
118
|
+
// Update phone code hash from the new sent code
|
|
119
|
+
if (verifyResult.sentCode instanceof tl_1.Api.auth.SentCode) {
|
|
120
|
+
phoneCodeHash = verifyResult.sentCode.phoneCodeHash;
|
|
121
|
+
isCodeViaApp =
|
|
122
|
+
verifyResult.sentCode.type instanceof
|
|
123
|
+
tl_1.Api.auth.SentCodeTypeApp;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (sendCodeResult.emailCodeSent) {
|
|
127
|
+
// Code was sent to existing email
|
|
128
|
+
if (!authParams.emailVerification) {
|
|
129
|
+
throw new Error("Email code sent but emailVerification callback not provided");
|
|
130
|
+
}
|
|
131
|
+
// Get verification from user for existing email
|
|
132
|
+
const verification = await authParams.emailVerification(sendCodeResult.emailOptions || {});
|
|
133
|
+
// Verify with existing email
|
|
134
|
+
const verifyResult = await verifyEmail(client, phoneNumber, phoneCodeHash, verification);
|
|
135
|
+
// Update phone code hash from the new sent code
|
|
136
|
+
if (verifyResult.sentCode instanceof tl_1.Api.auth.SentCode) {
|
|
137
|
+
phoneCodeHash = verifyResult.sentCode.phoneCodeHash;
|
|
138
|
+
isCodeViaApp =
|
|
139
|
+
verifyResult.sentCode.type instanceof
|
|
140
|
+
tl_1.Api.auth.SentCodeTypeApp;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
101
143
|
break;
|
|
102
144
|
}
|
|
103
145
|
catch (err) {
|
|
@@ -273,7 +315,6 @@ async function signInUserWithQrCode(client, apiCredentials, authParams) {
|
|
|
273
315
|
throw new Error("QR auth failed");
|
|
274
316
|
}
|
|
275
317
|
/** @hidden */
|
|
276
|
-
/** @hidden */
|
|
277
318
|
async function sendCode(client, apiCredentials, phoneNumber, forceSMS = false, reCaptchaCallback) {
|
|
278
319
|
var _a;
|
|
279
320
|
try {
|
|
@@ -310,6 +351,33 @@ async function sendCode(client, apiCredentials, phoneNumber, forceSMS = false, r
|
|
|
310
351
|
isCodeViaApp: false,
|
|
311
352
|
};
|
|
312
353
|
}
|
|
354
|
+
// Handle email verification types
|
|
355
|
+
if (sendResult.type instanceof tl_1.Api.auth.SentCodeTypeSetUpEmailRequired) {
|
|
356
|
+
return {
|
|
357
|
+
phoneCodeHash: sendResult.phoneCodeHash,
|
|
358
|
+
isCodeViaApp: false,
|
|
359
|
+
emailRequired: true,
|
|
360
|
+
emailOptions: {
|
|
361
|
+
googleSigninAllowed: sendResult.type.googleSigninAllowed,
|
|
362
|
+
appleSigninAllowed: sendResult.type.appleSigninAllowed,
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
if (sendResult.type instanceof tl_1.Api.auth.SentCodeTypeEmailCode) {
|
|
367
|
+
return {
|
|
368
|
+
phoneCodeHash: sendResult.phoneCodeHash,
|
|
369
|
+
isCodeViaApp: false,
|
|
370
|
+
emailCodeSent: true,
|
|
371
|
+
emailOptions: {
|
|
372
|
+
googleSigninAllowed: sendResult.type.googleSigninAllowed,
|
|
373
|
+
appleSigninAllowed: sendResult.type.appleSigninAllowed,
|
|
374
|
+
emailPattern: sendResult.type.emailPattern,
|
|
375
|
+
codeLength: sendResult.type.length,
|
|
376
|
+
resetAvailablePeriod: sendResult.type.resetAvailablePeriod,
|
|
377
|
+
resetPendingDate: sendResult.type.resetPendingDate,
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
}
|
|
313
381
|
// If we already sent a SMS, do not resend the phoneCode (hash may be empty)
|
|
314
382
|
if (!forceSMS || sendResult.type instanceof tl_1.Api.auth.SentCodeTypeSms) {
|
|
315
383
|
return {
|
|
@@ -329,6 +397,33 @@ async function sendCode(client, apiCredentials, phoneNumber, forceSMS = false, r
|
|
|
329
397
|
isCodeViaApp: false,
|
|
330
398
|
};
|
|
331
399
|
}
|
|
400
|
+
// Handle email types in resend result as well
|
|
401
|
+
if (resendResult.type instanceof tl_1.Api.auth.SentCodeTypeSetUpEmailRequired) {
|
|
402
|
+
return {
|
|
403
|
+
phoneCodeHash: resendResult.phoneCodeHash,
|
|
404
|
+
isCodeViaApp: false,
|
|
405
|
+
emailRequired: true,
|
|
406
|
+
emailOptions: {
|
|
407
|
+
googleSigninAllowed: resendResult.type.googleSigninAllowed,
|
|
408
|
+
appleSigninAllowed: resendResult.type.appleSigninAllowed,
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
if (resendResult.type instanceof tl_1.Api.auth.SentCodeTypeEmailCode) {
|
|
413
|
+
return {
|
|
414
|
+
phoneCodeHash: resendResult.phoneCodeHash,
|
|
415
|
+
isCodeViaApp: false,
|
|
416
|
+
emailCodeSent: true,
|
|
417
|
+
emailOptions: {
|
|
418
|
+
googleSigninAllowed: resendResult.type.googleSigninAllowed,
|
|
419
|
+
appleSigninAllowed: resendResult.type.appleSigninAllowed,
|
|
420
|
+
emailPattern: resendResult.type.emailPattern,
|
|
421
|
+
codeLength: resendResult.type.length,
|
|
422
|
+
resetAvailablePeriod: resendResult.type.resetAvailablePeriod,
|
|
423
|
+
resetPendingDate: resendResult.type.resetPendingDate,
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
}
|
|
332
427
|
return {
|
|
333
428
|
phoneCodeHash: resendResult.phoneCodeHash,
|
|
334
429
|
isCodeViaApp: resendResult.type instanceof tl_1.Api.auth.SentCodeTypeApp,
|
|
@@ -406,3 +501,83 @@ async function _authFlow(client, apiCredentials, authParams) {
|
|
|
406
501
|
: await client.signInBot(apiCredentials, authParams);
|
|
407
502
|
client._log.info("Signed in successfully as " + utils.getDisplayName(me));
|
|
408
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Sends an email verification code for login setup.
|
|
506
|
+
* @param client - The telegram client
|
|
507
|
+
* @param phoneNumber - The phone number being used for login
|
|
508
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
509
|
+
* @param email - The email address to verify
|
|
510
|
+
* @returns The email pattern and code length
|
|
511
|
+
*/
|
|
512
|
+
/** @hidden */
|
|
513
|
+
async function sendVerifyEmailCode(client, phoneNumber, phoneCodeHash, email) {
|
|
514
|
+
const result = await client.invoke(new tl_1.Api.account.SendVerifyEmailCode({
|
|
515
|
+
purpose: new tl_1.Api.EmailVerifyPurposeLoginSetup({
|
|
516
|
+
phoneNumber,
|
|
517
|
+
phoneCodeHash,
|
|
518
|
+
}),
|
|
519
|
+
email,
|
|
520
|
+
}));
|
|
521
|
+
return {
|
|
522
|
+
emailPattern: result.emailPattern,
|
|
523
|
+
length: result.length,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Verifies an email address during login setup.
|
|
528
|
+
* @param client - The telegram client
|
|
529
|
+
* @param phoneNumber - The phone number being used for login
|
|
530
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
531
|
+
* @param verification - The verification (code, Google token, or Apple token)
|
|
532
|
+
* @returns The verified email and the new sent code for phone verification
|
|
533
|
+
*/
|
|
534
|
+
/** @hidden */
|
|
535
|
+
async function verifyEmail(client, phoneNumber, phoneCodeHash, verification) {
|
|
536
|
+
let emailVerification;
|
|
537
|
+
switch (verification.type) {
|
|
538
|
+
case "code":
|
|
539
|
+
emailVerification = new tl_1.Api.EmailVerificationCode({
|
|
540
|
+
code: verification.code,
|
|
541
|
+
});
|
|
542
|
+
break;
|
|
543
|
+
case "google":
|
|
544
|
+
emailVerification = new tl_1.Api.EmailVerificationGoogle({
|
|
545
|
+
token: verification.token,
|
|
546
|
+
});
|
|
547
|
+
break;
|
|
548
|
+
case "apple":
|
|
549
|
+
emailVerification = new tl_1.Api.EmailVerificationApple({
|
|
550
|
+
token: verification.token,
|
|
551
|
+
});
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
const result = await client.invoke(new tl_1.Api.account.VerifyEmail({
|
|
555
|
+
purpose: new tl_1.Api.EmailVerifyPurposeLoginSetup({
|
|
556
|
+
phoneNumber,
|
|
557
|
+
phoneCodeHash,
|
|
558
|
+
}),
|
|
559
|
+
verification: emailVerification,
|
|
560
|
+
}));
|
|
561
|
+
if (!(result instanceof tl_1.Api.account.EmailVerifiedLogin)) {
|
|
562
|
+
throw new Error("Expected EmailVerifiedLogin but got " + result.className);
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
email: result.email,
|
|
566
|
+
sentCode: result.sentCode,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Resets the login email when the user cannot access their current email.
|
|
571
|
+
* This will cancel the current email verification and allow setting up a new one.
|
|
572
|
+
* @param client - The telegram client
|
|
573
|
+
* @param phoneNumber - The phone number being used for login
|
|
574
|
+
* @param phoneCodeHash - The phone code hash from sendCode
|
|
575
|
+
* @returns The new sent code result
|
|
576
|
+
*/
|
|
577
|
+
/** @hidden */
|
|
578
|
+
async function resetLoginEmail(client, phoneNumber, phoneCodeHash) {
|
|
579
|
+
return await client.invoke(new tl_1.Api.auth.ResetLoginEmail({
|
|
580
|
+
phoneNumber,
|
|
581
|
+
phoneCodeHash,
|
|
582
|
+
}));
|
|
583
|
+
}
|
package/client/updates.js
CHANGED
|
@@ -168,7 +168,7 @@ async function _updateLoop(client) {
|
|
|
168
168
|
let lastPongAt;
|
|
169
169
|
while (!client._destroyed) {
|
|
170
170
|
await (0, Helpers_1.sleep)(PING_INTERVAL, true);
|
|
171
|
-
if (client._destroyed)
|
|
171
|
+
if (client._destroyed || client.disconnected)
|
|
172
172
|
break;
|
|
173
173
|
if (client._sender.isReconnecting || client._isSwitchingDc) {
|
|
174
174
|
lastPongAt = undefined;
|
|
@@ -212,6 +212,9 @@ async function _updateLoop(client) {
|
|
|
212
212
|
console.error(err);
|
|
213
213
|
}
|
|
214
214
|
lastPongAt = undefined;
|
|
215
|
+
if (client.disconnected || client._destroyed) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
215
218
|
if (client._sender.isReconnecting || client._isSwitchingDc) {
|
|
216
219
|
continue;
|
|
217
220
|
}
|
package/client/uploads.d.ts
CHANGED
|
@@ -130,7 +130,7 @@ export declare function _fileToMedia(client: TelegramClient, { file, forceDocume
|
|
|
130
130
|
image?: boolean;
|
|
131
131
|
}>;
|
|
132
132
|
/** @hidden */
|
|
133
|
-
export declare function _sendAlbum(client: TelegramClient, entity: EntityLike, { file, caption, forceDocument, fileSize, clearDraft, progressCallback, replyTo, attributes, thumb, parseMode, voiceNote, videoNote, silent, supportsStreaming, scheduleDate, workers, noforwards, commentTo, topMsgId, }: SendFileInterface): Promise<Api.Message>;
|
|
133
|
+
export declare function _sendAlbum(client: TelegramClient, entity: EntityLike, { file, caption, formattingEntities, forceDocument, fileSize, clearDraft, progressCallback, replyTo, attributes, thumb, parseMode, voiceNote, videoNote, silent, supportsStreaming, scheduleDate, workers, noforwards, commentTo, topMsgId, }: SendFileInterface): Promise<Api.Message>;
|
|
134
134
|
/** @hidden */
|
|
135
135
|
export declare function sendFile(client: TelegramClient, entity: EntityLike, { file, caption, forceDocument, fileSize, clearDraft, progressCallback, replyTo, attributes, thumb, parseMode, formattingEntities, voiceNote, videoNote, buttons, silent, supportsStreaming, scheduleDate, workers, noforwards, commentTo, topMsgId, }: SendFileInterface): Promise<Api.Message>;
|
|
136
136
|
export {};
|
package/client/uploads.js
CHANGED
|
@@ -318,7 +318,7 @@ async function _fileToMedia(client, { file, forceDocument, fileSize, progressCal
|
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
320
|
/** @hidden */
|
|
321
|
-
async function _sendAlbum(client, entity, { file, caption, forceDocument = false, fileSize, clearDraft = false, progressCallback, replyTo, attributes, thumb, parseMode, voiceNote = false, videoNote = false, silent, supportsStreaming = false, scheduleDate, workers = 1, noforwards, commentTo, topMsgId, }) {
|
|
321
|
+
async function _sendAlbum(client, entity, { file, caption, formattingEntities, forceDocument = false, fileSize, clearDraft = false, progressCallback, replyTo, attributes, thumb, parseMode, voiceNote = false, videoNote = false, silent, supportsStreaming = false, scheduleDate, workers = 1, noforwards, commentTo, topMsgId, }) {
|
|
322
322
|
entity = await client.getInputEntity(entity);
|
|
323
323
|
let files = [];
|
|
324
324
|
if (!Array.isArray(file)) {
|
|
@@ -334,8 +334,13 @@ async function _sendAlbum(client, entity, { file, caption, forceDocument = false
|
|
|
334
334
|
caption = [caption];
|
|
335
335
|
}
|
|
336
336
|
const captions = [];
|
|
337
|
-
for (const c of caption) {
|
|
338
|
-
|
|
337
|
+
for (const [i, c] of caption.entries()) {
|
|
338
|
+
if (i === 0 && formattingEntities) {
|
|
339
|
+
captions.push([c || "", formattingEntities]);
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
captions.push(await (0, messageParse_1._parseMessageText)(client, c, parseMode));
|
|
343
|
+
}
|
|
339
344
|
}
|
|
340
345
|
if (commentTo != undefined) {
|
|
341
346
|
const discussionData = await (0, messages_1.getCommentData)(client, entity, commentTo);
|
|
@@ -440,6 +445,7 @@ async function sendFile(client, entity, { file, caption, forceDocument = false,
|
|
|
440
445
|
return await _sendAlbum(client, entity, {
|
|
441
446
|
file: file,
|
|
442
447
|
caption: caption,
|
|
448
|
+
formattingEntities: formattingEntities,
|
|
443
449
|
replyTo: replyTo,
|
|
444
450
|
parseMode: parseMode,
|
|
445
451
|
attributes: attributes,
|
package/index.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ import * as extensions from "./extensions";
|
|
|
11
11
|
import * as helpers from "./Helpers";
|
|
12
12
|
import * as client from "./client";
|
|
13
13
|
import * as password from "./Password";
|
|
14
|
-
|
|
14
|
+
import * as events from "./events";
|
|
15
|
+
export { utils, errors, sessions, extensions, helpers, tl, password, client, events };
|
package/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.client = exports.password = exports.tl = exports.helpers = exports.extensions = exports.sessions = exports.errors = exports.utils = exports.Logger = exports.version = exports.Connection = exports.TelegramClient = exports.Api = void 0;
|
|
36
|
+
exports.events = exports.client = exports.password = exports.tl = exports.helpers = exports.extensions = exports.sessions = exports.errors = exports.utils = exports.Logger = exports.version = exports.Connection = exports.TelegramClient = exports.Api = void 0;
|
|
37
37
|
var tl_1 = require("./tl");
|
|
38
38
|
Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return tl_1.Api; } });
|
|
39
39
|
const tl = __importStar(require("./tl"));
|
|
@@ -60,3 +60,5 @@ const client = __importStar(require("./client"));
|
|
|
60
60
|
exports.client = client;
|
|
61
61
|
const password = __importStar(require("./Password"));
|
|
62
62
|
exports.password = password;
|
|
63
|
+
const events = __importStar(require("./events"));
|
|
64
|
+
exports.events = events;
|