Answer the question
In order to leave comments, you need to log in
How to clear channel history using telegram bot?
Tell me how to clear, for example, every 10 minutes the history of the channel using a bot?
The bot will send messages to the channel every 30 seconds, and it is necessary that the channel be cleared over time. Can it be done?
I usenode-telegram-bot-api
Answer the question
In order to leave comments, you need to log in
I would suggest something like this
let messagesToDelete = [];
telegramBot.sendMessage('some').then((m) => {
messagesToDelete.push({
messageId: m.message_id,
chatId: m.chat.id
});
}).catch(console.error);
function wipeHistory() {
messagesToDelete.forEach(m => {
telegramBot.deleteMessage(m.chatId, m.messageId).then((success) => {
if (success) {
messagesToDelete = messagesToDelete.filter((v) => (v.messageId !== m.message_id && v.chatId !== m.chat.id));
};
}).catch(console.error);
});
};
setInterval(wipeHistory, 60 * 10 * 1000);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question