Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var lastMessage;
  2.  
  3. bot.on('/start', msg => {
  4.  
  5.     const markup = updateKeyboard('apples');
  6.  
  7.     return bot.sendMessage(
  8.         msg.from.id, 'This is a editMessageReplyMarkup example. So, apples or oranges?', {markup}
  9.     ).then(re => {
  10.         // Start updating message
  11.         lastMessage = [msg.from.id, re.result.message_id];
  12.     });
  13.  
  14. });
  15.  
  16. // On button callback
  17. bot.on('callbackQuery', msg => {
  18.  
  19.     // Send confirm
  20.     bot.answerCallbackQuery(msg.id);
  21.  
  22.     if (!lastMessage) return bot.sendMessage(msg.from.id, 'Type /start');
  23.  
  24.     const data = msg.data;
  25.     const [chatId, messageId] = lastMessage;
  26.     const replyMarkup = updateKeyboard(data);
  27.  
  28.     // Edit message markup
  29.     return bot.editMessageReplyMarkup(msg.chat.id, msg.id, {replyMarkup});
  30.  
  31. });
  32.  
  33. bot.start();
  34.  
  35. // Returns keyboard markup
  36. function updateKeyboard(fruit) {
  37.  
  38.     let apples = 'apples';
  39.     let oranges = 'oranges';
  40.  
  41.     if (fruit == 'apples') {
  42.         apples = `==> ${ apples } <==`;
  43.     } else {
  44.         oranges = `==> ${ oranges } <==`;
  45.     }
  46.  
  47.     return bot.inlineKeyboard([
  48.         [
  49.             bot.inlineButton(apples, {callback: 'apples'}),
  50.             bot.inlineButton(oranges, {callback: 'oranges'})
  51.         ]
  52.     ]);
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement