node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

When the user has replied, the user is still prompted to reply. Why

Open alanhe421 opened this issue 2 years ago • 6 comments

image

Bug Report

I have read:

I am using the latest version of the library.

Expected Behavior

Actual Behavior

Steps to reproduce the Behavior

Don't show reply input after use replied.

image

alanhe421 avatar Jun 05 '22 12:06 alanhe421

Try to move "removeReplyListener" to the first callback function, where your bot sends "You should add repo firstly!..."

ddavlet avatar Jul 02 '22 12:07 ddavlet

https://github.com/alanhg/github-issue-bot/blob/c39269b8b8ba2d19d4bb31cc9754be8a598a4d99/app.js#L98-L98

I think you did not understand the problem, maybe my code block is not clear.

alanhe421 avatar Jul 02 '22 14:07 alanhe421

It would be nice to remove the listener once the user response is received.

// In function async...
let listenerReply;

let contentMessage = await bot.sendMessage(chat_id, text, {
    "reply_markup": {
        "force_reply": true
    }
});

listenerReply = (async (replyHandler) => {
    // More code...

    bot.removeReplyListener(listenerReply);
    await bot.sendMessage(chat_id, "OK", {"reply_markup": {"force_reply": false}})

});

bot.onReplyToMessage(contentMessage.chat.id, contentMessage.message_id, listenerReply);

The next message sent by the bot should set property force_reply in reply_markup to false

IscoV avatar Jul 20 '22 10:07 IscoV

Same here, removeReplyListener does not help!

my code:

 this.bot.onText(/\.*/, async (msg) => {
      this.logger_.debug(`${msg.text} message from @${msg.chat.username} (${msg.chat.id})`)

      // TODO: fix, reply pops up every time user opens telegram
      if (msg.reply_to_message) return;

      const chatId = msg.chat.id;
      const name = msg.chat.first_name;
      const marketplace = await this.findOne_({ chatId });
      if (!marketplace) {
        const greeting = this.i18n.t("telegram.whatsYourKey", { name });
        const keyPrompt = await this.bot.sendMessage(msg.chat.id, greeting, {
          reply_markup: { force_reply: true }
        });
        const replyListenerId = this.bot.onReplyToMessage(msg.chat.id, keyPrompt.message_id, async (msg) => {
          this.bot.removeReplyListener(replyListenerId);
          const key = msg.text;
          const canal = await this.canalService.findById_(key)
          if (!canal) {
            this.bot.sendMessage(chatId, this.i18n.t("telegram.invalidKey", { name }), {
              reply_markup: { force_reply: false }
            });
          } else {
            await this.createOne_({
              canal,
              name: `@${msg.chat.username}`,
              chatId,
              username: msg.chat.username,
              firstName: msg.chat.first_name,
              lastName: msg.chat.last_name,
              canConfirm: true,
            });
            this.bot.sendMessage(chatId, this.i18n.t("telegram.validKey", { name, canal }), {
              reply_markup: { force_reply: false }
            });
          }
        });
        return
      }

The only workaround I have found is to delete the prompt message:

this.bot.deleteMessage(chatId, msg.reply_to_message.message_id);

brooth avatar Oct 15 '22 20:10 brooth

this.bot.deleteMessage

this.bot.deleteMessage worked, thank you.

alanhe421 avatar Jan 15 '23 03:01 alanhe421

❤️

RahimGuerfi avatar Oct 06 '23 16:10 RahimGuerfi