2

I just started using Telegraf to make a Telegram bot with node, and the bot uses an inline keyboard for users to select from a given option. But after the user selects one option and gets a response, the user can still click on the other options and get their response.

ctx.reply("Do you want to order the product?", {
        parse_mode: "HTML",
        ...Markup.inlineKeyboard([
          Markup.button.callback("Order", "order"),
          Markup.button.callback("Cancel", "cancel"),
        ]),
      });

I tried to disable it using bot.hears method

bot.hears("order", (ctx) => {
  "removed",
    {
      reply_markup: {
        remove_keyboard: true,
      },
    };
});

bot.hears("cancel", (ctx) => {
  "removed",
    {
      reply_markup: {
        remove_keyboard: true,
      },
    };
});

but the methods don't seem to disable/ remove the options. So is there a way to disable the inline keyboards after one click

boom pow
  • 181
  • 9

1 Answers1

1

Instead of bot.hears, you have to use bot.action. Try this code:

bot.action("order", (ctx) => {
    ctx.editMessageReplyMarkup();
    ctx.editMessageText("removed");
});

bot.action("cancel", (ctx) => {
    ctx.editMessageReplyMarkup();
    ctx.editMessageText("removed");
});

bot.editMessageReplyMarkup function with no arguments will remove the inline keyboard. bot.editMessageText function will edit the message with another text.

I hope this helps :)

Usitha Indeewara
  • 870
  • 3
  • 10
  • 21