3

I would like to connect a simple telegram bot to read messages from a group, (where I'm not admin). I already added the bot to the group, but it doesn't work.

Here is the code I have in Python:

import telepot
from pprint import pprint
import time
from telepot.loop import MessageLoop

key = "MY API"

bot = telepot.Bot(key)

def handle(msg):
   pprint(msg)

bot.message_loop(handle)

while 1:
   time.sleep(10)

If I open the chat (of the bot) and write a message, everything works well. But when someone send a message in a group (where I added the bot), even if the bot is in that group, nothing happen. What I'm doing wrong? Do I miss something?

Thanks a lot for the help!

Sean Wei
  • 7,433
  • 1
  • 19
  • 39
Lord
  • 153
  • 1
  • 4
  • 15

3 Answers3

4

You need to change /setprivacy to Disable, or you can only receive command (starts with /).

You can refer to here for more details.

Sean Wei
  • 7,433
  • 1
  • 19
  • 39
  • Thanks for your answer. I already did that, but it doesn't work. – Lord Aug 25 '17 at 21:39
  • Did you re-add your bot to group? – Sean Wei Aug 25 '17 at 21:52
  • Yes yes, but somehow it doesn't work properly. If I add it in a new group (created by me), I can read everything, but if I add it in another group (where I'm not admin), I can't read messages, only information like "users x joined the group". Do you think is related to the permission of that group? – Lord Aug 26 '17 at 10:41
  • 1
    works for me, thank you! Note: you can also set this option via the botfather. Also, if you try to delete group messages, make bot admin with priviledge to delete messages. – Kevin O. Feb 17 '22 at 15:57
2

Your telegram bot should be the admin of group to be able to read messages of the group.

Emad Armoun
  • 1,625
  • 2
  • 19
  • 32
1

This is an example in Telepot framework. You can do something like this in your favorite framework.

def handle(msg):
    if msg['chat']['id'] == -1001136714808:
        print(msg['text'])
Alireza Afzal Aghaei
  • 1,184
  • 10
  • 27