问题描述
我希望我的机器人在聊天中检测到文档发送时发送一条消息。
该代码可直接与机器人聊天, 但是如果我将漫游器添加到一个组中,则如果我在该组中发送了文档,该漫游器将没有响应。
static void Main(string[] args)
{
bot.OnMessage += Bot_OnMessage;
bot.OnMessageEdited += Bot_OnMessage;
bot.StartReceiving();
}
private static void Bot_OnMessage(object sender,Telegram.Bot.Args.MessageEventArgs e)
{
Console.WriteLine(e.Message.Type);
}
当我成组发送文件时,为什么机器人没有响应?谢谢!
解决方法
您必须要做的事情:
- 通过Privacy mode在您的漫游器上检查BotFather,将其关闭
- 您的代码仅会在控制台上打印,不会发送聊天记录,请像下面的代码那样发送聊天记录:
static void Main(string[] args)
{
bot.OnMessage += Bot_OnMessage;
bot.OnMessageEdited += Bot_OnMessage;
bot.StartReceiving();
}
private static async void Bot_OnMessage(object sender,Telegram.Bot.Args.MessageEventArgs e)
{
Console.WriteLine(e.Message.Type);
if (e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Document)
{
// Send in chat
await bot.SendTextMessageAsync(e.Message.Chat,"*This is a document!*",ParseMode.Markdown);
}
}
什么是隐私模式
您的漫游器只能在隐私模式下阅读:
- 回复其邮件
- 所有命令(任何单词都以
/
开头,例如/ help,/ settings等) - 自动提及(例如@MyBot等)
- 服务消息(例如添加聊天成员,更改聊天标题等)
这将确保您的漫游器用户不听其聊天。
具有隐私模式的机器人将显示: 无法访问消息
将其关闭