![](/img/trans.png)
[英]Debugging C# Bot in VS 2019 issue - no response in Bot after sending Bot a message through MS Teams
[英]sending message by user id in c# bot
我正在尝试向People用户名发送消息,例如我的朋友用户名是@ ...但是没有事情发生没有错误,没有发送我可以使用这个库吗? 或者只是用tlsharp? 我如何为我的机器人找到apiid和hashid?
使用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");
}
}
您无法通过用户Name.telegram bot API向用户发送消息只接受用户ID。 (渠道除外)。
当您尝试向用户发送消息时,您必须知道他们的chatID (chatID是一个长号,对于电报中的每个用户都是唯一的,并且在用户名可以更改时永远不会更改),或者您必须将他们的chatID存储在数据库或文件中或...
这意味着用户必须在包含/ start命令之前向您的机器人发送至少一条消息 。 然后您的机器人可以找到他们的chatID并使用该chatID,您可以向该用户发送您想要的任何内容,除非他/她在尝试删除他/她与您的机器人之间的对话时按下删除和停止按钮来阻止您的机器人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.