SHARE
TWEET

VKAPI Генерация кнопок [TODO]

Gistrec Aug 25th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Генерируем кнопки
  3.  * @param {Object} buttons - список кнопок, например:
  4.  *                 [[{"action": "Назад", "text":"Назад"}, {"action": "Вперед", "text":"Вперед"}],
  5.  * @param {bool} one_time
  6.  */
  7. exports.generateKeyboard = function(buttons, one_time = true) {
  8.     let keyboard = {
  9.         "one_time": one_time,
  10.         "buttons": []
  11.     }
  12.     for (let line in buttons) {
  13.         keyboard["buttons"][line] = [];
  14.         for (let index in buttons[line]) {
  15.             const data = buttons[line][index];
  16.             keyboard["buttons"][line][index] = {
  17.                 "action": {
  18.                     "type": "text",
  19.                     "payload": "{",
  20.                     "label": `${data["text"]}`
  21.                 },
  22.                 "color": "positive"
  23.             }
  24.             for (let property in data) {
  25.                 if (['action', 'page'].indexOf(property) > -1) keyboard['buttons'][line][index]['action'] += `"${property}": "${data[property]}"`
  26.             }
  27.             keyboard['buttons'][line][index]['action'] += "}"
  28.         }
  29.     }
  30.     return keyboard;
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top