TLsharp Console发送消息

时间:2017-03-08 06:56:58

标签: c# telegram

我正在尝试使用TLsharp库通过简单的C#控制台应用程序发送电报。我的程序运行,但我没有收到消息。我已经完成了在Telegram网站上创建应用程序的过程,并收到了必要的哈希ID和代码。请协助

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeleSharp.TL;
using TLSharp;
using TLSharp.Core;

   namespace TLsharpTest
    {
       class Program
      {

    const int apiId = 55xxx;
    const int groupId = -167xxxxx;
    const string apiHash = "220xxxxxxxx";
    const string number = "27xxxxxxx";
    static void Main(string[] args)
    {

        var client = new TelegramClient(apiId, apiHash);
        client.ConnectAsync();


        var hash = client.SendCodeRequestAsync(number);
        var code = "55xxx"; // you can change code in debugger
        var user = client.MakeAuthAsync(number, apiHash, code);
        client.SendMessageAsync(new TLInputPeerUser() { user_id = groupId },             "TEST");
        Console.ReadKey();
    }


  }
}

1 个答案:

答案 0 :(得分:0)

您应该让用户的access_hash发送消息。它应该是这样的:

 _client.SendMessageAsync(
                new TLInputPeerUser()
                {
                    user_id = channelUser.Id,
                    access_hash = channelUser.AccessHash
                }