-1

Does anyone have an Example for WTelegramClient using ASP.NET Webforms.

I have tried the following now I am getting FLOOD_WAIT_X errors with all the running and debugging.

The Telegram details are entered into textbox's on the form. On Pageload the Login is attempted without verification code. When the login attempt fails after postback the user enters the verification code and then a Callback is used to re attempt the login.


public WTelegram.Client _client
        {
            get
            {
                if (Session["WTelegramClient"] == null)
                {
                    Session["WTelegramClient"] = new WTelegram.Client(Config);
                }
                return Session["WTelegramClient"] as WTelegram.Client;
            }
            set { Session["WTelegramClient"] = value; }
        }

        public TL.User TelegramUser { get; private set; }

        private string VerificationCode;

       
        private async Task DoLogin()
        {
            try
            {
                TelegramUser = await _client.LoginUserIfNeeded();
            }
            catch (Exception ex)
            {
                MessageLabel.Text = ex.Message;
                return;
            }


            if (TelegramUser != null)
            {
                MessageLabel.Text = String.Format("Connected as : {0} {1}", TelegramUser.first_name, TelegramUser.last_name);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterAsyncTask(new PageAsyncTask(DoLogin));
        }


        string Config(string what)
        {
                switch (what)
                {
                    case "api_id": return api_id.Text;
                    case "api_hash": return api_hash.Text;
                    case "phone_number": return phone_number.Text;
                    case "verification_code": return String.IsNullOrWhiteSpace(VerificationCode) ? null : VerificationCode;
                    default: return null;                  // let WTelegramClient decide the default config
                }
        }

1 Answers1

0

See the example ASP.NET webapp provided in WTelegram examples repository

Wizou
  • 1,336
  • 13
  • 24