3

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 ?

Mehdi Safavie
  • 41
  • 1
  • 7
  • 1
    Their example is wrong. The constructor should be `public ExampleRequest(int someParameter)`. – piedar Mar 03 '16 at 16:46
  • An API is usually a dll executable that is very similar to an .exe file. Both a dll have the same collection of library files but are organized slightly different. And in some cases you use an .exe file instead of a dll depending on the build options. You can even convert an exe to a dll. The microsoft compiler creates objects and then combines the .obj to executables/libraries. A dll is a library while a exe is a executable containg the same compiled objects. – jdweng Mar 06 '16 at 10:36
  • @MehdiSafavie what have you been able to do so far? – Charles Okwuagwu Mar 09 '16 at 20:32

2 Answers2

3

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);
                }
            }
        }

    }
 }}
Alireza Zojaji
  • 802
  • 2
  • 13
  • 33
0

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.

Stefano d'Antonio
  • 5,874
  • 3
  • 32
  • 45