1

So, I have a bot and set Privacy to disabled from @botfather, therefore the bot can access the group's messages. When I try to add it to groups, Telegram sends me a notification that the bot, once added to the group, will be able to access the last 100 messages in the group.

How do I implement that in my bot's code? Since the limit is 100 I suppose it has to do with the GetUpdates function, but the bot never returns the messages sent before it was added to the group, no matter what offset value I set (I even tried setting random numbers to see if something would change). This is the relevant code using telepot:

bot = telepot.Bot(token)

def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    #rest of code handling text messages

pprint(bot.getUpdates()) #no differences in results for various parameters passed to function
print("one time operation done\nbeginning loop")
#in theory the bot should get the last 100 messages in the group with getUpdates as a one-time operation and then start the loop

telepot.loop.MessageLoop(bot, handle).run_as_thread() #start loop
while 1:
    time.sleep(10)
  • You can't get the last 100 messages an an update, but if any user in the group reply to any of those 100 messages, your bot will see the replied message details. You also might be able to forward the last 100 messages sent to that chat to any chat that bot have access to. – Ali Padida Nov 12 '20 at 10:04

0 Answers0