[英]sending message by user id in c# bot
i'm trying to send message to People user name for example my friends username is @... but no thing happend no Error and no send can i use this library ? 我正在尝试向People用户名发送消息,例如我的朋友用户名是@ ...但是没有事情发生没有错误,没有发送我可以使用这个库吗? or just with tlsharp?
或者只是用tlsharp? how can i found apiid and hashid for my bot?
我如何为我的机器人找到apiid和hashid?
using Telegram.Bot; 使用Telegram.Bot;
and 和
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");
}
}
you cant send message to user by user Name.telegram bot API only accept user Id. 您无法通过用户Name.telegram bot API向用户发送消息只接受用户ID。 (except channels).
(渠道除外)。
When you try to send messages to users you must know their chatID (chatID is a long number which is unique for every user in telegram and never changes while username can be changed) or you must have stored their chatIDs in a database or a file or ... 当您尝试向用户发送消息时,您必须知道他们的chatID (chatID是一个长号,对于电报中的每个用户都是唯一的,并且在用户名可以更改时永远不会更改),或者您必须将他们的chatID存储在数据库或文件中或...
This means a user must have sent at least one message to your bot before this includes the /start command . 这意味着用户必须在包含/ start命令之前向您的机器人发送至少一条消息 。 Then your bot can find out their chatID and using that chatID, you can send whatever you want to that user unless he/she has blocked your bot by pressing Delete and Stop button when trying to delete the conversation between him/her and your bot.
然后您的机器人可以找到他们的chatID并使用该chatID,您可以向该用户发送您想要的任何内容,除非他/她在尝试删除他/她与您的机器人之间的对话时按下删除和停止按钮来阻止您的机器人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.