2017-06-17 60 views
1

我试图发送消息到人民的用户名,例如朋友的用户名是@ ... 但没有事情happend 没有错误 并没有发送 我可以使用这个库? 或只是用tlsharp? 我怎样才能找到我的机器人的apiid和hashid?通过用户ID C#机器人发送消息

使用Telegram.Bot;

public partial class Form1 : Form 
    { 
     Telegram.Bot. TelegramBotClient bot = new TelegramBotClient("token"); 

     Thread a; 
      public Form1() 
     { 
      InitializeComponent(); 
     } 


     public void GetUpdates() 
     { 
      int offset = 0; 
      while (true) 
      { 

       Telegram.Bot.Types.Update[] updates = 
       bot.GetUpdatesAsync(offset).Result; 

       foreach (var update in updates) 
       { 

        offset = update.Id + 1; 
        if (update.Message == null) 
         continue; 

        var from = update.Message.From.FirstName; 
        var text = update.Message.Text; 
        string chatid = update.Message.Chat.Id; 
        string username = update.Message.From.Username; 
        // label1.BeginInvoke(delegate { label1.Text = label1.BeginInvoke(delegate { label1.Text = string.Format("sender:{0}\ntext:{1}\ncatid:{2}", from, text, chatid); }); }); 
        // lblshow.Text = string.Format("sender:{0}\ntext:{1}\ncatid:{2}", from, text, chatid); 
        //label1.Text = string.Format("sender:{0}\ntext:{1}\ncatid:{2}", from, text, chatid); 
        this.BeginInvoke((System.Windows.Forms.MethodInvoker)delegate() {textBox1.Text = string.Format("sender:{0}\ntext:{1}\ncusername:{2}", from, text, username); }); 
        bot.SendTextMessageAsync(chatid, "سلام بر شما"); 
        //is this correct for send to people? 
        bot.SendTextMessageAsync("@Hoda.....", "hi"); 


       } 




      } 

回答

0

你不能由用户Name.telegram机器人API发送消息给用户仅接受用户ID。 (频道除外)。

+0

大卫我需要你的帮助电报机器人相关,所以我可以aksing? – Edit

+0

你好大卫,我在电报里有一个机器人。并在机器人我想要显示医生名称列表和任何用户去机器人选择任何医生的名称和机器人chating的时间将开始博士,所以它是可能的机器人?使用c#。我更担心这项任务。我尝试很多链接找到但没有成功,所以你可以请帮我 – Edit

+0

你好亲爱的@编辑。它与这个话题完全无关。请考虑提出新的问题,以便我们可以帮助你。谢谢。 – David

0

当您尝试向用户发送消息,你必须知道他们的chatID (chatID是一个长期的数量是在电报每个用户独特的,永远不会改变,而用户名可以更改)或者您必须存储在其chatIDs在数据库或文件,或...

这意味着用户必须已将至少一个消息,你的机器人在此之前包括/start命令。然后你的机器人可以找到他们的聊天ID并使用该聊天ID,你可以发送任何你想要的用户,除非他/她已经通过按删除并停止按钮时,他/她已经屏蔽了你的机器人当试图删除他/她和你机器人。

+0

你好,我需要一些消息发送在使用c#的电报机器人组?所以去怎么做呢。我找到了很多链接,但所有的链接都给出了聊天ID。你能帮我么 – Edit