2

How can I just remove the bot.on () in order to rerun the bot.onText ()? Because if I do bot.removeListener ('message') it also removes the bot.onText ()

       bot.onText(/\/login/, (msg) => {

                  bot.on('message', (msg) => {
                        //do some stuff
                        bot.removeListener('message');
                  });

       });

1 Answers1

0

Second argument, should be a function of your listener. F.e.:

let handler = (msg) => {
  let chatId = getChatId(msg);
  bot.sendMessage(chatId, "Login");
  bot.removeListener("message", handler);
};

bot.onText(/\/login/, msg => {
  bot.on("message", handler);

  bot.on("message", msg => {
    let chatId = getChatId(msg);
    bot.sendMessage(chatId, "Another listener");
  });
});

As you can see, the first time both listeners work, on the second attempt to enter something, only the second listener works.

enter image description here