N
N
ninja op op2020-05-20 12:51:17
In contact with
ninja op op, 2020-05-20 12:51:17

INLINE buttons for VK-Bot on NODE.JS?

How to make INLINE buttons using the node-vk-bot library,
note that this is not node-vk-bot-api, but node-vk-bot.

If anyone knows, please write)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-05-20
@loonny

Read the node-vk-bot documentation, the documentation is in Russian. This library does not support sending inline keyboards. You can dig into the source code and tweak it a bit to add this feature. It's ugly, but if you need it to solve a problem, it's acceptable.
Here, I already did it for you. Change the Keyboard.ts code to this:

export enum KeyboardColor {
  PRIMARY = 'primary',
  DEFAULT = 'default',
  NEGATIVE = 'negative',
  POSITIVE = 'positive'
}

/**
 * Класс для создания клавиатуры для бота
 */
export default class Keyboard {
  private obj: any

  constructor(oneTime = false, inline = false) { this.obj = { one_time: oneTime, inline: inline, buttons: [] } }

  addButton(label: string, color: string = KeyboardColor.DEFAULT, payload = null) {
    if (!this.obj.buttons.length) this.obj.buttons.push([])

    let lastRow = this.obj.buttons[this.obj.buttons.length - 1]
    if (lastRow.length === 4) throw new Error('Maximum amount of buttons in one row = 4')

    lastRow.push({ action: { type: 'text', label, payload }, color })

    return this
  }

  addRow() {
    if (this.obj.buttons.length === 10) throw new Error('Maximum amount of rows = 10')
    this.obj.buttons.push([])

    return this
  }

  toString() { return JSON.stringify(this.obj) }
}

The Keyboard constructor will now have 2 parameters instead of 1. The first is oneTime with a default value of false, and the second is inline with a default value of false.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question