how to specify if the message was from group or private in python telegram bot

Question:

Here is my code:

# 1st method
if chat.type == 'supergroup':
   # Check if the bot's name was mentioned in the message
   # if bot_name in message_text:
   # Generate a response to the question
   response_text = generate_response(message_text)
   update.message.reply_text(response_text)

elif chat.type == 'private':
   # Generate a response to the question
   response_text = generate_response(message_text)
   update.message.reply_text(response_text)

The 'private' is working fine if the message was sent in private chat but if it was send from the group the bot was not able to pick the message. The bot was also in the group.

I tried:

# 2nd method
if chat.id < 0:
# 3rd method
if message.chat.type in ["group", "supergroup"]:

to know if the message coming from the group but no luck.
Only the private one is working.

Asked By: Richard Vega

||

Answers:

By default, bots don’t see all messages that are written in group chats. Please have a look at this FAQ entry in the official Telegram docs for more info.

Answered By: CallMeStag

You can check if chat id differs from user id

Answered By: A.A