wiz0u / WTelegramClient

Telegram Client API (MTProto) library written 100% in C# and .NET
https://wiz0u.github.io/WTelegramClient/
MIT License
990 stars 163 forks source link

Checking whether it is possible to connect to the previous session #237

Closed Vals0ray closed 8 months ago

Vals0ray commented 8 months ago

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.

wiz0u commented 8 months ago

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.