2

I want to delete the messages in group but the bot only deletes the last few messages, about the last ten minutes.
I'm using message_id decreasing for doing that

$lastMessageID = --$result ['message']['message_id'];
        for ($i=0; $i <$n ; $i++) { 
            $content = array('chat_id' => $chat_id, 'message_id' => $lastMessageID);
            $telegram->deleteMessage($content);
            $lastMessageID--;
        }   

I have checked the return value of deleting command and everything is fine I receive the {"ok":1,"result":1} and of course for some messages it has the "message to delete not found" and it goes on but suddenly it just stops with no error. for example the last return value is {"ok":1,"result":1} or in some cases {ok:1}and no more messages will be deleted.
and I have considered following issues:

  1. A message can only be deleted if it was sent less than 48 hours ago.
  2. The bot is an administrator of group for a year
  3. The bot has all the permissions
Amir
  • 523
  • 1
  • 5
  • 24

1 Answers1

-1

As it's already mentioned on the official doc https://core.telegram.org/bots/api#deleteMessage page of Telegram that A message can only be deleted if it was sent less than 48 hours ago.

OMi Shah
  • 5,768
  • 3
  • 25
  • 34
  • I have mentioned in the question that I have considered this. – Amir Aug 06 '20 at 17:44
  • @Amir, if you know about that then what's the point now, brother? – OMi Shah Aug 06 '20 at 17:46
  • yeah that's my question why is this happening? I have mentioned that the bots is deleting only messages sent about the last ten minutes before, instead of the 48 hours – Amir Aug 06 '20 at 17:51
  • I think because you're making API calls so fast. You should consider adding some delay before each request. Also, don't use decrementing value logic, instead, get the list of all messages using the appropriate API endpoint and pass an existing message ID rather than passing vague/unexisting message ID. – OMi Shah Aug 06 '20 at 17:55