Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Send Message to Telegram From Asp.net Core

$
0
0

Hi,
i use this code to send message to telegram from asp.net core in web , and its worked

but i don't want enter verify code every time when i want send message 
how can i use it without verify code that its send to my phone 

  var client = new TelegramClient(Api Id, "Api Hash");
            await client.ConnectAsync();

            var hash = await client.SendCodeRequestAsync("+9809100000000");
            var code = "72757"; // you can change code in debugger //code will send via telegram to you

            TLUser user = null;
            try
            {
                user = await client.MakeAuthAsync("+9809100000000", hash, code);
            }
            catch (CloudPasswordNeededException ex)
            {
                //if u activate two step verification in telegram
                var password = await client.GetPasswordSetting();
                var password_str = "test";

                user = await client.MakeAuthWithPasswordAsync(password, password_str);
            }

            if (client.IsUserAuthorized())
            {
                //get available contacts
                var result = await client.GetContactsAsync();

                //find recipient in contacts
                var userr = result.Users.ToList()
                    .Where(x => x.GetType() == typeof(TLUser))
                    .Cast<TLUser>()
                    .FirstOrDefault(x => x.Username == "*******");

                //send message


              
                await client.SendMessageAsync(new TLInputPeerUser() { UserId = userr.Id }, "Hello ");
            }




Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>