How to read messages from Telegram group with bot?

2019-08-02 19:45发布

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!

3条回答
姐就是有狂的资本
2楼-- · 2019-08-02 19:57

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

查看更多
家丑人穷心不美
3楼-- · 2019-08-02 19:58

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

You can refer to here for more details.

查看更多
淡お忘
4楼-- · 2019-08-02 20:18

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'])
查看更多
登录 后发表回答