2

I am using WTelegramClient library with ASP.NET MVC project, to access Telegram API.

Using this code, works good, until verification code received on App.

I am figuring out, how do I enter this code and where in my view page, when initial code is already run with partial configuration details.

Can anyone help me with this?

WTelegram.Client client;
public async Task<ActionResult> Index()
{
    string Config(string what)
    {
        switch (what)
        {
            case "api_id": return "XXX";
            case "api_hash": return "XXXXXX";
            case "phone_number": return "+NUMBER";
            default: return null; 
        }
    }
    client = new WTelegram.Client(Config);
    await client.LoginUserIfNeeded();
    return View();
 }

When above code is run at start with http://localhost:PORT_NUMBER/Home, code runs fine and Telegram sends me a CODE, but now how and where to enter that code, I am not getting idea on this.

Hemal
  • 3,682
  • 1
  • 23
  • 54

1 Answers1

1

As explained in the FAQ the solution is to wait on a ManualResetEventSlim until the user provides the code.

Edit: (Oct 2022) Latest version has a simplified config system that you may prefer

WTelegramClient has a full example on how to do that in an ASP.NET web app.
Take a look there: https://github.com/wiz0u/WTelegramClient/raw/master/Examples/ASPnet_webapp.zip

Wizou
  • 1,336
  • 13
  • 24
  • Thank you for the reply. I have gone through that example. It's with .net core. I am not familiar with that. I am using ASP.NET MVC 5 with Controller action. In that action, I have put simple initial code for client. I am also not familiar with Task. Can you help me with this in ASP.NET MVC 5? – Hemal Apr 16 '22 at 05:37