button using grammy

 


//new way
bot.on("msg::hashtag", async ctx => {
  // Generate a random index between 0 and the length of the array
  var randomIndex = Math.floor(Math.random() * texts.length);
  bot.api.sendMessage(ctx.chat.id, texts[randomIndex], {
    "reply_markup": {
      "force_reply": true,
      "keyboard": [["Sample text", "Second sample"], ["Keyboard"], ["I'm robot"]],
      "resize_keyboard": true,
      "one_time_keyboard": true,
      "remove_keyboard": true
    }
  });
})


//handle button

bot.hears("No. 😈", (ctx) => {
  bot.api.sendMessage(ctx.chat.id, `Welcome dear ${ctx.chat.username}`, {
    reply_markup: new Keyboard()
      .text("button").row()
      .text("I'm not quite sure")
      .text("No. 😈")
      .resized()
  })
});

Post a Comment

0 Comments