skip to Main Content

i have one question please;

how i can make Class or Method with Telegram API like :https://core.telegram.org/methods from TLSharp Class ?
in the TLSharpTest.cs i have some example , but i can’t understand how i can write Telegram API in C# 🙁

if i want receive message , what i do ?

of curce i try from Example in https://github.com/sochix/TLSharp#contributing
but in this method :

public InitConnectionRequest(int someParameter)
{
_someParameter = someParameter;
}

say : Method must have a return type ,

why ?

2

Answers


  1. You can find practical examples in my project: https://github.com/UnoSD/TgMsgSharp

    I have used TLSharp to backup Telegram messages. You should create an instance of TelegramClient, connect, request the auth code, create an auth with the code and then you can invoke all the methods on the TelegramClient.

    Beware that not all the methods from your Telegram (you link) are supported, there are just few available.

    Login or Signup to reply.
  2. Agha Mehdi,

    This example is very useful:

    using TeleSharp.TL;
    using TLSharp;
    using TLSharp.Core;
    
    namespace TelegramSend
     {
    
        public partial class Form1 : Form
        {
          public Form1()
         {
             InitializeComponent();
         }
    
    
        TelegramClient client;
    
        private async void button1_Click(object sender, EventArgs e)
        {
            client = new TelegramClient(<your api_id>,  <your api_key>);
            await client.ConnectAsync();
        }
    
        string hash;
    
        private async void button2_Click(object sender, EventArgs e)
        {
            hash = await client.SendCodeRequestAsync(textBox1.Text);
            //var code = "<code_from_telegram>"; // you can change code in debugger
    
    
        }
    
        private async void button3_Click(object sender, EventArgs e)
        {
            var user = await client.MakeAuthAsync(textBox1.Text, hash, textBox2.Text);
        }
    
        private async void button4_Click(object sender, EventArgs e)
        {
    
            //get available contacts
            var result = await client.GetContactsAsync();
    
            //find recipient in contacts
            var user = result.users.lists
                .Where(x => x.GetType() == typeof(TLUser))
                .Cast<TLUser>()
                .Where(x => x.first_name == "ZRX");
            if (user.ToList().Count != 0)
            {
                foreach (var u in user)
                {
                    if (u.phone.Contains("3965604"))
                    {
                        //send message
                        await client.SendMessageAsync(new TLInputPeerUser() { user_id = u.id }, textBox3.Text);
                    }
                }
            }
    
        }
     }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search