I've created a simple .NET 6 console application to do a user actions on my telegram account. api_id, api_hash created and I used a simple Config function to create the client and then called: client.LoginUserIfNeeded() as in below sample code:
WTelegram.Client client = new WTelegram.Client(Config);
var myself = await client.LoginUserIfNeeded();
Console.WriteLine($"We are logged-in as {myself} (id {myself.id})");
and the config function:
static string Config(string what)
{
switch (what)
{
case "api_id": return "123456";
case "api_hash": return "abcdefghij121232323";
case "phone_number": return "+96650123456";
case "verification_code": Console.Write("Code: ");
return Console.ReadLine();
case "first_name": return "first_name"; // if sign-up is required
case "last_name": return "last_name"; // if sign-up is required
case "password": return "secret!"; // if user has enabled 2FA
default: return null; // let WTelegramClient decide the default config
}
}
All worked just fine, a file named: WTelegram.session was created and all is good and I was able to receive (on telegram client on my mobile) a code for verification.
But the problem is that when I delete the file (or moved it somewhere else) and tried to run the console app again, the application is stuck as the prompt: Code: and No telegram verification code was received.
Any hints on that.
I've also tried to run the console application using another phone number (completely different telegram account with different api_id and api_hash) and cleaned all bin/obj files but still its not working and no telegram verification code is received on the telegram client (even a different phone).
Now the strange thing, if I got back the WTelegram.session file again (the one that was created when the application first run and was successful), the console app is running fine and a telegram verification code is received on my mobile telegram client.
Appreciate the help.
A verification code can only be obtained via an official client, so you have to have a Telegram client already connected to those phone numbers you're trying to connect to.
Since 18 Feb 2023, Telegram no longer send verification code by SMS when trying to connect with 3rd-party libraries like WTelegramClient