0
votes

I want my bot to send a message when it detect documents is sent in a chat.

The code works for chat to the bot directly, but if I add the bot into a group, the bot has no response if I sent a document in the group.

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);
}

Why the bot has no response when I send a file in a group? Thanks!

1
What library you are using to handle TL bot? - Buddhika Chathuranga
the lasted update via nuget - nuget.org/packages/Telebot. - richard1994x

1 Answers

0
votes

You have to things:

  • Check Privacy mode on your your bot, by BotFather, Turn it off
  • Your code will print on console ONLY, It won't send in chats, do like code below to send in chats:
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);
    }
}

What is Privacy mode

Your bot in privacy mode only can read:

  1. Replys to its messages
  2. All commands (any word starts with / like /help, /settings etc.)
  3. Bot Mentions (like @MyBot etc.)
  4. Service Messages (like Chat Members Added, Chat Title Changed, etc.)

This will make sure from your bot users that you bot is not listen to there chats.

The bots that has Privacy mode It will show: has no access to messages

Turn it off