82

My telegram bot receives messages sent by user to my bot in private chats but not receives messages sent by users in group chats. Any options/api for getting group chat messages also,.

6 Answers 6

132

Talk to @botfather and disable the privacy mode.

5
  • 31
    take into account that you have to set it off before adding to chat. Otherwise you have to remove it and add it again
    – Artiom
    Commented Nov 7, 2016 at 11:53
  • 4
    That is not really true, you can do it before, after, during... whenever you want.
    – apascualb
    Commented Aug 1, 2017 at 15:15
  • 13
    I'm not sure, but kicking the bot and adding it back solved my problem. Took me hours= =. you have to set it off before adding to chat
    – SCaffrey
    Commented Mar 22, 2018 at 16:14
  • 2
    Another note is that the bot MUST be an admin on that group, regardless of the privacy settings. Otherwise, it will NOT be able to read any of the group messages.
    – Binar Web
    Commented Jun 1, 2019 at 15:52
  • 7
    No, either the bot needs to be an admin OR privacy mode needs to be disabled. Commented Jun 11, 2019 at 7:23
97

Sequence within a BotFather chat:

You: /setprivacy

BotFather: Choose a bot to change group messages settings.

You: @your_name_bot

BotFather: 'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username.

'Disable' - your bot will receive all messages that people send to groups.

Current status is: ENABLED

You: Disable

BotFather: Success! The new status is: DISABLED. /help

2
  • 1
    I've spent like 2 hours trying to figure this out. Thanks bud! Commented Feb 27, 2018 at 8:49
  • 16
    I want to make an addition. I have noticed that if you give your bot the administrative rights in the group, than it has ability to see all messages, regardless of /setprivacy setting.
    – Gooman
    Commented Apr 20, 2018 at 18:50
10

By default A Bot will receive only messages addressed to it by any user directly via posting by /command@YourBot any message you send. After that it vill be available via getUpdates API call. In browser it will be:

https://api.telegram.org/botToken/getupdates

Find the related message in output JSON and grab chatId. It will allow you to answer back with:

https://api.telegram.org/botToken/sendmessage?chat_id=123456788&text=My Answer
4
  • I'm getting {"ok":false,"error_code":401,"description":"Unauthorized"} when I call getupdates
    – Enrique
    Commented Dec 25, 2019 at 12:50
  • OK, that's because it requires offset and limit parameters
    – Enrique
    Commented Dec 25, 2019 at 23:18
  • try this https: //api.telegram.org/bot{token}/sendMessage?chat_id=<chat_id>&text=<Enter your text here>
    – fperez
    Commented Jan 13, 2023 at 15:31
  • This is the solution for whoever is privacy concern. I explained it with more details here: stackoverflow.com/a/78436037/1198404
    – chelder
    Commented May 6 at 10:36
5

Make your bot as an admin in your group.

1
  • If we 'Disable' privacy, your bot will receive all messages that people send to groups. If you want to avoid that: keep privacy Enable and make the bot admin (it works with the least admin permissions). Then, mention the bot eg @my_bot_name is the solution I found.
    – chelder
    Commented May 4 at 10:20
3

You can access all avaliable settings from all of your bots by sending /mybots to Botfather. Choose the bot, then Bot Settings and Group Privacy. If its disable (default), you can tap on Turn off.

Now its possible to receive the chat history using GetUpdates. This can be done via HTTP API or the frameworks. For example, in C# (.NET Core) like this:

var bot = new TelegramBotClient(ApiToken);
var updates = bot.GetUpdatesAsync().Result;
foreach(var update in updates) {
    Console.WriteLine($"{update.ChannelPost.Date} {update.ChannelPost.Text}");
}

But keep in mind that this feature has some kind of perfect forward secrecy implemented. So you only get messages that were send after group privacy is disabled. As a result, the GetUpdates result is empty until some post was made.

3

if you added your bot before disable the privacy mode, you should remove the bot from the group and add it again

Not the answer you're looking for? Browse other questions tagged or ask your own question.