I’m working with a Telegram bot using the WTelegramClient library and encountering a strange problem. The bot functions perfectly when I run it in debug mode via Visual Studio, but it fails to work when I publish it as a console application.
When in debug mode, everything runs smoothly. I can input the api_id, api_hash, phone_number, and verification_code without any issue. The login process goes through successfully.
However, when I publish the app and execute the file, I receive a FLOOD_WAIT_X error right after entering the phone number. This occurs precisely when Telegram is supposed to send the verification code.
Here is the part of my authentication code:
static async Task Main(string[] args)
{
var telegramClient = new WTelegram.Client();
await telegramClient.LoginUserIfNeeded();
var user = await telegramClient.GetMe();
Console.WriteLine($"Logged in as {user.first_name}");
}
static string ConfigProvider(string setting)
{
switch (setting)
{
case "api_id": return ReadInput("Enter API ID: ");
case "api_hash": return ReadInput("Enter API Hash: ");
case "phone_number": return ReadInput("Enter phone: ");
case "verification_code": return ReadInput("Enter code: ");
default: return null;
}
}
I’ve attempted several approaches such as introducing delays between requests, utilizing environment variables for settings, deploying to various hosting services, and adjusting publish configurations. Yet, the error consistently emerges at the same stage in production mode only.