NodeJS 电报机器人是不发送回复后,用户点击一个内联键盘回复标记,如何使它重播?

wnvonmuf  于 2024-01-07  发布在  Node.js
关注(0)|答案(1)|浏览(117)

我想重播给用户一个消息,当他点击按钮,我尝试了许多解决方案,但到目前为止没有任何工作,我得到回调_查询数据后,用户点击按钮,但机器人正在重播给他IM使用telecom js库

// Add the callback query event handler
bot.on('callback_query', async (ctx) => {
  const buttonPressed = ctx.callbackQuery.data;

  if (buttonPressed === 'button1') {
    ctx.answerCbQuery('You pressed Button 1!');
    // Perform actions specific to Button 1
  } else if (buttonPressed === 'button2') {
    ctx.answerCbQuery('You pressed Button 2!');
    // Perform actions specific to Button 2
  }
});

// Your existing code
if (Object.keys(buttonReplay).length > 0) {
  for (const button of buttonReplay.actionButtons) {
    const inlineKeyboard = Markup.inlineKeyboard([
      Markup.button.callback("button 1", "button1"),
      Markup.button.callback("button 2", "button2"),
      Markup.button.url("open url", "https://google.com"),
    ]);

    await bot.telegram.sendMessage(chatId, "hi", inlineKeyboard);
  }
}

字符串

xfyts7mz

xfyts7mz1#

取决于telecom js版本,in V4.11 filters was introduced
尝试使用过滤器:

bot.on(callbackQuery("data"), ctx => {

字符串
不过,如果输入不是动态的,也许您应该考虑使用

bot.action('button1', ctx => {

相关问题