Support the request to resend the verification_code through alternate methods.

This commit is contained in:
Wizou 2021-12-13 15:28:06 +01:00
parent 62dad83370
commit 97c6de4cbb
4 changed files with 17 additions and 3 deletions

2
.github/dev.yml vendored
View file

@ -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

2
.github/release.yml vendored
View file

@ -1,7 +1,7 @@
pr: none
trigger: none
name: 1.7.$(Rev:r)
name: 1.8.$(Rev:r)
pool:
vmImage: ubuntu-latest

View file

@ -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.

View file

@ -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")