Keep WTelegram.Client persistent between user requests?

55 views Asked by At

I have two handler methods in razor pages for:

  1. request telegram code.
  2. send verification code.

How can I keep an instance of Wtelegram Client between requests? I tried JsonSerializer but got below error!

Serialization and deserialization of 'WTelegram.Client+TcpFactory' instances are not supported. Path: $.TcpHandler

public async Task<IActionResult> OnPostCodeAsync()
{
  var wClient = new Client(Config, store);

  HttpContext.Session.SetString(telSession, JsonSerializer.Serialize(wClient));

  Msg = await _wClient.Login(PhoneNumber);
}

public async Task<IActionResult> OnPostVerifyAsync()
{
  var value = HttpContext.Session.GetString(telSession);

  var wClient = JsonSerializer.Deserialize<Client>(value);

  Msg = await wClient.Login(VerificationCode);
}

Or how can I tell WTelegram to continue another sign in process using simple string and int properties?

1

There are 1 answers

0
Wizou On

See the official ASP.NET example showing how to keep a singleton of the client/service while performing the login and further API calls.