【问题标题】:TLSharp - anybody have example?TLSharp - 有人有例子吗?
【发布时间】:2016-06-17 02:56:22
【问题描述】:

我有一个问题请教;

如何使用 Telegram API 制作类或方法,例如 TLSharp 类中的:https://core.telegram.org/methods? 在 TLSharpTest.cs 我有一些例子,但我不明白如何用 C# 编写 Telegram API :(

如果我想收到消息,我该怎么办?

我从https://github.com/sochix/TLSharp#contributing 中的示例中尝试的curce 但在这种方法中:

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

说:方法必须有返回类型,

为什么?

【问题讨论】:

  • 他们的例子是错误的。构造函数应该是public ExampleRequest(int someParameter)
  • API 通常是一个与 .exe 文件非常相似的 dll 可执行文件。两个 dll 具有相同的库文件集合,但组织方式略有不同。在某些情况下,您使用 .exe 文件而不是 dll,具体取决于构建选项。您甚至可以将 exe 转换为 dll。 microsoft 编译器创建对象,然后将 .obj 组合到可执行文件/库中。 dll 是一个库,而 exe 是包含相同编译对象的可执行文件。
  • @MehdiSafavie 到目前为止你做了什么?

标签: c# telegram


【解决方案1】:

您可以在我的项目中找到实际示例:https://github.com/UnoSD/TgMsgSharp

我使用 TLSharp 来备份 Telegram 消息。您应该创建一个 TelegramClient 实例,连接,请求授权代码,使用该代码创建一个授权,然后您可以调用 TelegramClient 上的所有方法。

请注意,并非您的 Telegram(您的链接)中的所有方法都受支持,可用的方法很少。

【讨论】:

    【解决方案2】:

    阿迦迈赫迪,

    这个例子很有用:

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

    【讨论】:

    • 我仍在努力使用 session.dat 登录
    • 这不行,注意:我有云密码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 2018-02-15
    相关资源
    最近更新 更多