node-telegram-bot-api
node-telegram-bot-api copied to clipboard
When the user has replied, the user is still prompted to reply. Why

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.

Try to move "removeReplyListener" to the first callback function, where your bot sends "You should add repo firstly!..."
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.
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
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);
this.bot.deleteMessage
this.bot.deleteMessage
worked, thank you.
❤️