yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.35k stars 1.52k forks source link

im getting the callback query data but the bot wont respond to user after he clicks on the button #1095

Open x1337x1 opened 1 year ago

x1337x1 commented 1 year ago

Question im using inline keyboard and and im displaying the buttons without any issue, also im can see the callbackquery data in my console but i want to replay to user after he clicks on the button which is something i couldnt do

my code:

         // Assuming you have access to the `bot` and `chatId` variables

// Define the callback query handler
bot.on("callback_query", async (query) => {
  const { data } = query; // Extract the callback data

  // Check if the callback data matches the expected value
  if (data === "Data") {
    // Send a reply message
    await bot.telegram.sendMessage(chatId, "Thank you for clicking the button!");
  }
});

// Send the initial message with the button
if (Object.keys(buttonReplay).length > 0 && buttonReplay.actionButtons) {
  const inlineKeyboard = buttonReplay.actionButtons.map((button) => ({
    text: button.name,
    callback_data:  "Data",
  }));

  await bot.telegram.sendMessage(chatId, buttonReplay.buttonsMsg, {
    reply_markup: {
      inline_keyboard: [inlineKeyboard],
    },
  });
}