简体   繁体   English

在c#bot中按用户ID发送消息

[英]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.

相关问题 在 VS 2019 问题中调试 C# Bot - 通过 MS Teams 向 Bot 发送消息后,Bot 中没有响应 - Debugging C# Bot in VS 2019 issue - no response in Bot after sending Bot a message through MS Teams 如何在 c# 中查找电报机器人发送的消息是否已正确发送到通道? - How to find if a the sending message by a telegram bot has been sent to the channel correctly in c#? C#中的连续消息发送 - Continuous Message Sending in C# 如何使用C#在电报Bot上使用组名而不是聊天ID在组中发送消息? - How to send message in the group using group name not a chat id on telegram bot using c#? 在Bot框架C#中自定义验证消息 - Customize validation message in Bot framework C# 如何在 C# 中使用 Discord Bot 发送消息? - How send a message with a Discord Bot in C#? c# 聊天机器人 | 动态重试提示消息 - c# chat bot | RetryPrompt message dynamically 如何将来自用户的消息存储在表存储中? (Microsoft Bot Framework SDK4 & C#) - How to store a message from the user in a table storage? (Microsoft Bot Framework SDK4 & C#) 如何使用 C# 中的 API 从机器人添加组中的电报读取用户发送消息 - how to read user send message from telegram in bot added group using API in C# 使用 C# 从 Bot 框架中的 MS Teams 获取登录用户 Email id - Get logged-In user Email id from MS Teams in Bot framework using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM