Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Генерируем кнопки
- * @param {Object} buttons - список кнопок, например:
- * [[{"action": "Назад", "text":"Назад"}, {"action": "Вперед", "text":"Вперед"}],
- * @param {bool} one_time
- */
- exports.generateKeyboard = function(buttons, one_time = true) {
- let keyboard = {
- "one_time": one_time,
- "buttons": []
- }
- for (let line in buttons) {
- keyboard["buttons"][line] = [];
- for (let index in buttons[line]) {
- const data = buttons[line][index];
- keyboard["buttons"][line][index] = {
- "action": {
- "type": "text",
- "payload": "{",
- "label": `${data["text"]}`
- },
- "color": "positive"
- }
- for (let property in data) {
- if (['action', 'page'].indexOf(property) > -1) keyboard['buttons'][line][index]['action'] += `"${property}": "${data[property]}"`
- }
- keyboard['buttons'][line][index]['action'] += "}"
- }
- }
- return keyboard;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement