WTelegramClient, when and where to enter verification code after initial config run?

774 views Asked by At

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.

1

There are 1 answers

1
Wizou On

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