Exemple #1
0
        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());
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }