public async Task <TLSentCode> SendCodeRequestAsync(string phoneNumber) { if (String.IsNullOrWhiteSpace(phoneNumber)) { throw new ArgumentNullException(nameof(phoneNumber)); } var completed = false; TLRequestSendCode request = null; while (!completed) { request = new TLRequestSendCode() { phone_number = phoneNumber, api_id = _apiId, api_hash = _apiHash }; try { await _sender.Send(request); await _sender.Receive(request); completed = true; } catch (PhoneMigrationException ex) { await ReconnectToDcAsync(ex.DC); } } return(request.Response.ToTLSentCode()); }
public async Task <string> SendCodeRequestAsync(string phoneNumber) { var completed = false; TLRequestSendCode request = null; while (!completed) { request = new TLRequestSendCode() { phone_number = phoneNumber, api_id = _apiId, api_hash = _apiHash }; try { await _sender.Send(request); await _sender.Receive(request); completed = true; } catch (InvalidOperationException ex) { if (ex.Message.StartsWith("Your phone number registered to") && ex.Data["dcId"] != null) { await ReconnectToDcAsync((int)ex.Data["dcId"]); } else { throw; } } } return(request.Response.phone_code_hash); }
public async Task <string> SendCodeRequestAsync(string phoneNumber) { if (String.IsNullOrWhiteSpace(phoneNumber)) { throw new ArgumentNullException(nameof(phoneNumber)); } //var completed = false; TLRequestSendCode request = null; //while (!completed) //{ request = new TLRequestSendCode() { phone_number = phoneNumber, api_id = _apiId, api_hash = _apiHash }; //try //{ await SendRpcRequest(request); //await _sender.Receive(request); //completed = true; //} //catch (PhoneMigrationException ex) //{ // await ReconnectToDcAsync(ex.DC); //} //} return(request.Response.phone_code_hash); }
public async Task <string> SendCodeRequestAsync(string phoneNumber) { if (String.IsNullOrWhiteSpace(phoneNumber)) { throw new ArgumentNullException(nameof(phoneNumber)); } var request = new TLRequestSendCode() { PhoneNumber = phoneNumber, ApiId = _apiId, ApiHash = _apiHash }; await RequestWithDcMigration(request); return(request.Response.PhoneCodeHash); }
public async Task <string> SendCodeRequestAsync(string phoneNumber, CancellationToken token = default(CancellationToken)) { if (String.IsNullOrWhiteSpace(phoneNumber)) { throw new ArgumentNullException(nameof(phoneNumber)); } var request = new TLRequestSendCode() { PhoneNumber = phoneNumber, ApiId = apiId, ApiHash = apiHash }; await RequestWithDcMigration(request, token).ConfigureAwait(false); return(request.Response.PhoneCodeHash); }