Node-telegram-bot-api: want to 'deleteMessage' botself

Created on 4 Oct 2018  路  3Comments  路  Source: yagop/node-telegram-bot-api

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.

Most helpful comment

I found it myself.
Thanks!

bot.telegram.sendMessage(chat_id, message).then((m) => {
    bot.telegram.deleteMessage(chat_id, m.message_id)
  })

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dimawebmaker picture dimawebmaker  路  3Comments

sidelux picture sidelux  路  3Comments

kenanchristian picture kenanchristian  路  4Comments

jacopocappelli1989 picture jacopocappelli1989  路  4Comments

mbrammer picture mbrammer  路  3Comments