Answer the question
In order to leave comments, you need to log in
Vkontakte bot, buttons and nodejs?
Hello everyone, I use the node-vk-bot-api library, but it is not supported. The
buttons that can be used there are buttons with the text type, but VK is being updated and the location, vkpay, open_app
buttons have appeared. The buttons are declared as follows:
let keyboard_toster = Markup.keyboard([
[
Markup.button('Первая кнопка', 'positive')
],
[
Markup.button('Вторая кнопка', 'negative')
]
])
const KEYBOARD_COLUMNS_MAX = 4;
class Markup {
keyboard(buttons, options = { columns: KEYBOARD_COLUMNS_MAX }) {
this.__keyboard = {
buttons: Array.isArray(buttons[0])
? buttons
: buttons.reduce((array, label) => {
const button = Markup.button(label);
const buttons = array.length ? array[array.length - 1] : array[0];
if (buttons && buttons.length < options.columns) {
buttons.push(button);
} else {
array.push([button]);
}
return array;
}, []),
};
return this;
}
oneTime(value = true) {
this.__keyboard.one_time = value;
return this;
}
toJSON() {
return JSON.stringify(this.__keyboard);
}
static keyboard(keyboard, options) {
return new Markup().keyboard(keyboard, options);
}
static button(label, color = 'default', payload = { button: label }) {
if (typeof label === 'object') {
return label;
}
return {
action: {
type: 'text',
payload: JSON.stringify(payload),
label,
},
color,
};
}
}
module.exports = Markup;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question