Click here to Skip to main content
15,440,323 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have an application for creating appointment. i want to send message via telegram from my website to some fixed users(they have telegram installed in their mobile phone. ).
i checked this link: https://github.com/zhukov/webogram
API : https://core.telegram.org/api
Other applications using the api : https://telegram.org/apps
and created appconfiguration for telegram.but icanot find a suitable simple example which shows how this api can be used in asp.net .plz help i have done a loat of search .i found webogram which worked in my machine too but i cant find out how they called api . i m a beginner in asp.net. i want to know how api call from my asp.net pages .plz help . i am asked same question before but no one replayed :(.
sorry for my bad English . PLZ help
Posted
Updated 21-Mar-22 11:23am
v2
Comments
Goroh 11-Aug-14 6:13am    
Have you found any solution? I have the same task, it's neccessary to implement sending messages from .net
flykoh 1-May-15 17:08pm    
the API is too complicated there some uncompleted project in GitHub i try for the last three month but i failed

1 solution

Hi
I write this code for sending message to my contacts

first you must install TLSharp from nuget -->
Install-Package TLSharp



public static async void GetMyContacts()
       {
           //get available contacts
           var client = new TelegramClient(ApiId, "ApiHash");
           await client.ConnectAsync();

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

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

               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.lists
                   .Where(x => x.GetType() == typeof(TLUser))
                   .Cast<TLUser>()
                   .FirstOrDefault(x => x.username == "a username from ur contacts in telegram");

               //send message
               await client.SendMessageAsync(new TLInputPeerUser() { user_id = userr.id }, "My Message  :Hi :)");
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900