UNPKG

umbot

Version:

Universal bot(vk, telegram, viber) or skills for Yandex.Alisa, Маруся and sber

75 lines (74 loc) 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VkButton = void 0; const TemplateButtonTypes_1 = require("./TemplateButtonTypes"); const Button_1 = require("../Button"); class VkButton extends TemplateButtonTypes_1.TemplateButtonTypes { static GROUP_NAME = '_group'; getButtons() { const groups = []; const buttons = []; let index = 0; this.buttons.forEach((button) => { if (button.type === null) { if (button.hide === Button_1.Button.B_LINK) { button.type = Button_1.Button.VK_TYPE_LINK; } else { button.type = Button_1.Button.VK_TYPE_TEXT; } } let object = { action: { type: button.type, }, }; if (button.url) { object.action.type = Button_1.Button.VK_TYPE_LINK; object.action.link = button.url; } object.action.label = button.title; if (button.payload) { if (typeof button.payload === 'string') { object.action.payload = button.payload; } else { object.action.payload = { ...button.payload }; } } if (typeof button.payload.color !== 'undefined' && !button.url) { object.color = button.payload.color; } if (button.type === Button_1.Button.VK_TYPE_PAY) { object.hash = button.payload.hash || null; } object = { ...object, ...button.options }; const groupOptions = button.options[VkButton.GROUP_NAME]; if (typeof groupOptions !== 'undefined') { if (typeof object[VkButton.GROUP_NAME] !== 'undefined') { delete object[VkButton.GROUP_NAME]; } if (typeof groups[+groupOptions] !== 'undefined') { buttons[groups[+groupOptions]].push(object); } else { groups[+groupOptions] = index; buttons[index] = [object]; index++; } } else { buttons[index] = object; index++; } if (object.action.payload && typeof object.action.payload !== 'string') { object.action.payload = JSON.stringify(object.action.payload); } }); return { one_time: !!buttons.length, buttons: buttons, }; } } exports.VkButton = VkButton;