nickoala / telepot

Python framework for Telegram Bot API
MIT License
2.42k stars 474 forks source link

Deletting all messages sent by my bot into a chat. #455

Open alebuffoli opened 5 years ago

alebuffoli commented 5 years ago

Hello. I'm trying hard to delete all the messages sent by my bot into a chat. I know that it is not possible to delete the messages sent by the user, so, i want at least delete all the messages sent by my bot.

so far to save a message id sent from my bot I use this code

messages_ids.update({chat_id: lastMessage})

That store in a dictionary the chat ID and all the information about the last messages that the bot sent.

Then, I delete the last message whit this method:

bot.deleteMessage(telepot.message_identifier(messages_ids[chat_id]))

But obviously I can't delete the message sent to a user before I implemented this method. So, to clear the old chats, can I delete in someway all the message sent by my bot?

Or maybe there is a way to get all the messages ids of messages already sent? In this way I'd do a for cycle. But I cannot do a for cycle without the ids because I should check hundred thousand messages for chat and obviously it would be really slow and annoying.

Hopefully there is an easier solution, Thankyou.