umbot
Version:
Universal bot(vk, telegram, viber) or skills for Yandex.Alisa, Маруся and sber
68 lines (67 loc) • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = void 0;
const mmApp_1 = require("../../mmApp");
const Text_1 = require("../../utils/standard/Text");
class Button {
static B_LINK = false;
static B_BTN = true;
static VK_COLOR_PRIMARY = 'primary';
static VK_COLOR_SECONDARY = 'secondary';
static VK_COLOR_NEGATIVE = 'negative';
static VK_COLOR_POSITIVE = 'positive';
static VK_TYPE_TEXT = 'text';
static VK_TYPE_LINK = 'open_link';
static VK_TYPE_LOCATION = 'location';
static VK_TYPE_PAY = 'vkpay';
static VK_TYPE_APPS = 'open_app';
type;
title;
url;
payload;
hide;
options;
constructor(title = null, url = null, payload = [], hide = Button.B_LINK, options = {}) {
this.type = null;
this.title = title;
this.url = url;
this.payload = payload;
this.hide = hide;
this.options = options;
this._init(title, url, payload, hide, options);
}
static _getUrlSeparator(url) {
return url.includes('?') ? '&' : '?';
}
_init(title, url, payload, hide, options = {}) {
if (title || title === '') {
this.title = title;
if (url && Text_1.Text.isUrl(url)) {
if (mmApp_1.mmApp.params.utm_text === null) {
if (!url.includes('utm_source')) {
url += `${Button._getUrlSeparator(url)}utm_source=umBot&utm_medium=cpc&utm_campaign=phone`;
}
}
else if (mmApp_1.mmApp.params.utm_text) {
url += Button._getUrlSeparator(url) + mmApp_1.mmApp.params.utm_text;
}
}
else {
url = null;
}
this.url = url;
this.payload = payload;
this.hide = hide;
this.options = options;
return true;
}
return false;
}
initLink(title, url = '', payload = null, options = {}) {
return this._init(title, url, payload, Button.B_LINK, options);
}
initBtn(title, url = '', payload = null, options = {}) {
return this._init(title, url, payload, Button.B_BTN, options);
}
}
exports.Button = Button;