Regex matching doesn't work with group chats

Viewed 31

I am trying to write a bot that handles messages using regex, this is my code

import telebot

API_KEY = "[my_key]"
bot = telebot.TeleBot(API_KEY)

@bot.message_handler(regexp="fizz")
def msg_func(message):
    bot.reply_to(message,"buzz")

bot.polling()

When I chat privately with the bot i get the correct response

> my name is fizz
Bot:> buzz

But when I add the bot to a telegram group, the bot only handles the command

Me: > my name is fizz
Bot: > [no response]
Me: /fizz
Bot: > buzz

Does somebody know why it behaves like this and how can I fix it?

1 Answers

1. Change privacy settings

This is related to the privacy settings for the group chat. You need to talk BotFather and change the privacy settings for you bot.

  1. /setprivacy
  2. Choose a bot to change the privacy settings
  3. Disable
  4. Add your bot to the group again

After this, you should receive a message from BotFather which returns the new status of the privacy settings. This will allow you to read all group messages sent. Including those without / at the beginning like /fizz.

2. Make your bot group admin

Making your bot admin in the Telegram group will allow access to all of the group messages similar to the changed privacy settings. However, this solution requires your bot to be admin at every Telegram group to work properly.

Related