C#从机器人向通道电报发送消息

时间:2020-05-10 10:17:59

标签: c# telegram telegram-bot

i使用一些代码将频道信息设为“ Hello Word”

string urlString = "https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text={2}";
                string apiToken = "1143035780:AAEG5vU5j2_Nc5rLK8B2ORp3ItpYoNicokU";
                string chatId = "@kekcheburekks";
                string text = "Hello world!";
                urlString = String.Format(urlString, apiToken, chatId, text);
                WebRequest request = WebRequest.Create(urlString);
                Stream rs = request.GetResponse().GetResponseStream();
                StreamReader reader = new StreamReader(rs);
                string line = "";
                StringBuilder sb = new StringBuilder();
                while (line != null)
                {
                    line = reader.ReadLine();
                    if (line != null)
                        sb.Append(line);
                }
                string response = sb.ToString();

但是我得到了例外-找不到chatId!

1 个答案:

答案 0 :(得分:0)

我认为问题是当您传递@符号时,请尝试不使用它,就像这样:

string chatId = "kekcheburekks";

不使用@

string chatId = "@kekcheburekks";