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

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

Open amiinehachemi opened this issue 2 years ago • 0 comments

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],
    },
  });
}

amiinehachemi avatar Jun 24 '23 15:06 amiinehachemi