public async Task InitializeAndAuthenticateClientAsync() { await ConnectAsync(); if (!IsUserAuthorized) { try { Console.WriteLine($"We've sent a code with an activation code to yout phone {ConfigurationManager.PhoneNumber}."); AuthSentCode codeRequest = await _client.SendCode(ConfigurationManager.PhoneNumber, VerificationCodeDeliveryType.NumericCodeViaTelegram); ConfigurationManager.PhoneCodeHash = codeRequest.phoneCodeHash; Console.WriteLine("Code: "); var code = Console.ReadLine(); await _client.SignIn(ConfigurationManager.PhoneNumber, ConfigurationManager.PhoneCodeHash, code); Debug.WriteLine($"User login. Current user is {_client.AuthenticatedUser.firstName} {_client.AuthenticatedUser.lastName}"); } catch (FloodWaitException ex) { await Task.Delay(ex.TimeToWait); await InitializeAndAuthenticateClientAsync(); } } }
public async Task RequestForOTPAsync(string registeredMobileNumber) { try { if (!Client.IsUserAuthorized()) { Hash = await Client.SendCode(registeredMobileNumber, VerificationCodeDeliveryType.NumericCodeViaTelegram); } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
public override void OnResponse(BinaryReader reader) { sentCode = TLObject.Read <AuthSentCode>(reader); }