Hello sir.
I am studying about telegram bot through nodejs.
I want to delete message from bot self with 'deleteMessage' function.
It needs 2 arguments. one is 'chatId' another is 'msgId'
if there are source for example,
bot.onText(/\/test/, (msg, match) => {
function sendtext(){
bot.sendMessage(msg.chat.id, 'This message will be delete!');
bot.deleteMessage(msg.chat.id, msg.message_id);
}
setTimeout(sendtext, 3000);
});
it delete message that typed '/test' from user. but want to delete message that 'This message will be delete!' from bot
how can i delete message from bot self?
how can i know bot's message_id?
plz help me.
I found it myself.
Thanks!
bot.telegram.sendMessage(chat_id, message).then((m) => {
bot.telegram.deleteMessage(chat_id, m.message_id)
})
When you send a message, node return a msg object same as updates:
bot.sendMessage(msg.chat.id, "Rip").then(function (result) {
console.log(result); // sent message object
bot.deleteMessage(msg.chat.id, result.message_id); //then delete
});
Example for this result object:
{ message_id: 17461156,
from:
{ id: 236880746,
is_bot: true,
first_name: 'Test bot',
username: 'testbot' },
chat:
{ id: 20471035,
first_name: 'Name',
username: 'Username',
type: 'private' },
date: 1538729169,
text: 'Rip' }
resolved #656
Most helpful comment
I found it myself.
Thanks!