@lskjs/bots-base
Version:
LSK.js plugin for @lskjs/bots module for telegram, slack, discord, whatsapp, twitter, instagram and vk bots creation
78 lines (76 loc) • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.createKeyboard = exports.createButtons = void 0;
var _telegraf = require("telegraf");
// @ts-ignore
var createButtons = function createButtons(button, keyboardType) {
if (!button) return [];
if (Array.isArray(button)) return button.map(function (b) {
return createButtons(b, keyboardType);
});
var type;
var value;
var text;
if (typeof button === 'string') {
type = 'text';
text = button;
} else {
var title;
var _button$type = button.type;
type = _button$type === void 0 ? 'text' : _button$type;
value = button.value;
title = button.title;
text = button.text;
if (!text && title) text = title;
}
if (!value) value = text;
if (keyboardType === 'inline' && type === 'text') type = 'callback';
if (type === 'text') {
return _telegraf.Markup.button.text(text);
}
if (type === 'callback') {
return _telegraf.Markup.button.callback(text, value);
}
if (type === 'url') {
return _telegraf.Markup.button.url(text, value);
}
if (type === 'poll') {
return _telegraf.Markup.button.pollRequest(text, value);
}
if (type === 'location') {
return _telegraf.Markup.button.locationRequest(text);
}
if (type === 'contact') {
return _telegraf.Markup.button.contactRequest(text);
}
if (type === 'chat') {
return _telegraf.Markup.button.switchToChat(text, value);
}
if (type === 'currentChat') {
return _telegraf.Markup.button.switchToCurrentChat(text, value);
}
if (type === 'login') {
return _telegraf.Markup.button.login(text, value);
}
if (type === 'pay') {
return _telegraf.Markup.button.pay(text);
}
if (type === 'game') {
return _telegraf.Markup.button.game(text);
}
};
exports.createButtons = createButtons;
var createKeyboard = function createKeyboard(keyboard) {
var layout = keyboard.layout || keyboard.buttons;
var buttons = createButtons(layout, keyboard.type);
if (keyboard.type === 'inline') {
return _telegraf.Markup.inlineKeyboard(buttons);
}
return _telegraf.Markup.keyboard(buttons);
};
exports.createKeyboard = createKeyboard;
var _default = createKeyboard;
exports["default"] = _default;
//# sourceMappingURL=createKeyboard.js.map