让电报机器人在文档发送到群聊时做出反应

Let telegram bot react while a document is sent to a group chat

我希望我的机器人在检测到聊天中发送文档时发送消息。
我添加了一个带有文档过滤器的消息处理程序。
该代码适用于直接与机器人聊天,
但如果我将机器人添加到一个组中, 我在群里发了文档,bot没反应

密码是:

def test(bot, update):
    bot.sendMessage(update.message.chat_id, text='OK!')
    print "OK"

def main():
    token = 'xxxxxxyyyyy'
    updater = Updater(token, workers=10)

    dp = updater.dispatcher

    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))
    dp.add_handler(MessageHandler([Filters.document], test))

    updater.start_polling(timeout=10)
    updater.idle()

群发文件为什么没有反应? 谢谢!

如果代码在私人聊天中工作但在群组中不工作(不接收发送的消息),原因是你没有在 BotFather.

中设置 /setprivacy

Go to BotFather and disable /setprivacy for your bot. In this state, your bot will receive all messages not just does start with slash(/) in GROUPS.