wiz0u/WTelegramClient

Checking whether it is possible to connect to the previous session

Closed this issue · 1 comments

I developing ASP.NET application and I have the next code to get client for each request:

private readonly Client _client;

public TelegramClient()
{
    _client = new Client("", "");
}

public async Task<Client> GetClient(string phoneNumber)
{
    if (string.IsNullOrEmpty(phoneNumber))
    {
        throw new UserFriendlyException("Add phone number first!");
    }

    if (_client.User == null)
    {
        await _client.Login(phoneNumber);
    }

    return _client;
}

Is there way to somehow to check that previous session can be connected (for example when user terminated session)?
The point is that _client.Login() sends verification codes when this is not needed.

Yes. On LoginUserIfNeeded, pass reloginOnFailedResume: false to get an exception if session resume was not possible.

But this is not available with the alternate simplified Login() method.