N
N
Neolq2021-09-08 22:19:20
Node.js
Neolq, 2021-09-08 22:19:20

How to change the message sent by telegram bot?

Bot on node-telegram-bot-api. You need to change the message already sent by the bot. How to implement it?

bot.on('message', async (msg) => {
   const text = msg.text.toLowerCase()
   const chatId = msg.chat.id

   const message = 'TEXT'

   if (text.match('123')) {
      setTimeout(() => {
         bot.sendMessage(chatId, message)

         setTimeout(() => {
            bot.editMessageText(`${message} (edit)`, {
               chat_id = chatId,
               
            })
         }, 500)
         //
      }, 500)
   }
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2021-09-08
@Neolq

bot.on('message', async (msg) => {
  const text = msg.text.toLowerCase()
  const chatId = msg.chat.id
  const message = 'TEXT'
  if (text.match('123')) {
     setTimeout(() => {
        bot.sendMessage(chatId, message)
        .then(msgData=>{
          let count = 0;
          const timerId = setInterval(() => {
              count+=Math.floor(Math.random()*10);
              if(count>100){
                count=100;
                clearInterval(timerId);
              }
              bot.editMessageText(`${message} (edit) ${count}%`, 
              {
                chat_id: msgData.chat.id,
                message_id: msgData.message_id
              });
          }, 500)
        })
     }, 500)
  }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question