S
S
Stepan2019-12-19 23:30:02
API
Stepan, 2019-12-19 23:30:02

How to generate a VK keyboard?

There is a VK keyboard, which is generated as follows:

var btn =Keyboard.builder()
      .textButton({
        label: 'Баланс',
        payload: {
          command: 'bal'
        }
      })
      .row()
      .textButton({
        label: 'хочу + 100р',
        payload: {
          command: 'add_100'
        }
      })
      .row()
      .textButton({
        label: 'хочу - 100р',
        payload: {
          command: 'withdrow_100'
        },
color: Keyboard.PRIMARY_COLOR
      })
      .textButton({
        label: 'Профиль',
        payload: {command: 'profile'},
color: Keyboard.PRIMARY_COLOR
      });

I thought about it and realized that it is possible to make a function that simplifies this. At the input, it receives an array of the following form:
var button1 = ["Баланс","bal",Keyboard.PRIMARY_COLOR];
var button2 = ["Баланс2","bal2",Keyboard.PRIMARY_COLOR];
var button3 = ["Баланс3","bal3",Keyboard.PRIMARY_COLOR];
var btn=some_function();

That is, it is comparable to the code:
var btn =Keyboard.builder()
      .textButton({
        label: 'Баланс',
        payload: {
          command: 'bal1'
        },
color: Keyboard.PRIMARY_COLOR
      })
      .textButton({
        label: 'Баланс2',
        payload: {
          command: 'bal2'
        },
color: Keyboard.PRIMARY_COLOR
      })
      .row()
      .textButton({
        label: 'Баланс2',
        payload: {command: 'bal3'},
color: Keyboard.PRIMARY_COLOR
      });

But I don’t understand how to do this at all ((Tell me where to dig? Or maybe you can tell part of the function

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question