diff --git a/.github/dev.yml b/.github/dev.yml index e355e5d..2e48a81 100644 --- a/.github/dev.yml +++ b/.github/dev.yml @@ -2,7 +2,7 @@ pr: none trigger: - master -name: 1.7.7-dev.$(Rev:r) +name: 1.8.1-dev.$(Rev:r) pool: vmImage: ubuntu-latest diff --git a/.github/release.yml b/.github/release.yml index 4ff32b6..cdaee87 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -1,7 +1,7 @@ pr: none trigger: none -name: 1.7.$(Rev:r) +name: 1.8.$(Rev:r) pool: vmImage: ubuntu-latest diff --git a/README.md b/README.md index e1483d3..ef0c67c 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ using var client = new WTelegram.Client(Config); There are other configuration items that are queried to your method but returning `null` let WTelegramClient choose a default adequate value. Those shown above are the only ones that have no default values and should be provided by your method. Returning `null` for verification_code or password will show a prompt for console apps, or an error otherwise. +Returning an empty string for verification_code requests resending the code through another method (SMS or Call). Another simple approach is to pass `Environment.GetEnvironmentVariable` as the config callback and define the configuration items as environment variables. Undefined variables get the default `null` behavior. diff --git a/src/Client.cs b/src/Client.cs index d7b39bd..ab7c483 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -1020,13 +1020,26 @@ namespace WTelegram { sentCode = await this.Auth_SendCode(phone_number, _apiId, _apiHash, settings ??= new()); } + resent: + var timeout = DateTime.UtcNow + TimeSpan.FromSeconds(sentCode.timeout); + OnUpdate(sentCode); Helpers.Log(3, $"A verification code has been sent via {sentCode.type.GetType().Name[17..]}"); Auth_AuthorizationBase authorization = null; - //TODO: implement auth.resendCode logic for (int retry = 1; authorization == null; retry++) try { var verification_code = await ConfigAsync("verification_code"); + if (verification_code == "" && sentCode.next_type != 0) + { + var mustWait = timeout - DateTime.UtcNow; + if (mustWait.Ticks > 0) + { + Helpers.Log(3, $"You must wait {(int)(mustWait.TotalSeconds + 0.5)} more seconds before requesting the code to be sent via {sentCode.next_type}"); + continue; + } + sentCode = await this.Auth_ResendCode(phone_number, sentCode.phone_code_hash); + goto resent; + } authorization = await this.Auth_SignIn(phone_number, sentCode.phone_code_hash, verification_code); } catch (RpcException e) when (e.Code == 401 && e.Message == "SESSION_PASSWORD_NEEDED")