Reputation: 21
I am trying to create a bot in my group to help me track the group users who have invited other users into the group.
I have disabled the privacy mode so the bot can receive all messages in a group chat. However, it seems to be that update.message
only gets messages supplied by other users but not service messages like Alice has added Bob into the group
Is there any way that I can get these service messages as well?
Thanks for helping!
Upvotes: 1
Views: 2613
Reputation: 780
I suppose you are using python-telegram-bot
library.
You can add a handler with a specific filter to listen to service messages:
from telegram.ext import MessageHandler, Filters
def callback_func(bot, update):
# here you receive a list of new members (User Objects) in a single service message
new_members = update.message.new_chat_members
# do your stuff here:
for member in new_members:
print(member.username)
def main():
...
dispatcher.add_handler(MessageHandler(Filters.status_update.new_chat_members, callback_func)
There are several more service message types your bot may receive using the Filters
module, check them out here.
Upvotes: 1