E
E
Eugene2018-09-05 14:12:28
JavaScript
Eugene, 2018-09-05 14:12:28

How to submit VK bot keyboard to node.js?

When writing a bot for the VK community, I encountered the need to send the bot's keyboard. To do this, the keyboard JSON object is passed as a string in the keyboard parameter in the messages.send method

vk.messages.send({
user_id: //id получателя
message: //текст сообщения
keyboard: //клавиатура в формате json
});

Keyboard example from documentation:
// клавиатура вида 
// | Red | Green | 
// | White | Blue | 
  keyboard: 
{ 
    "one_time": false, 
    "buttons": [ 
      [{ 
        "action": { 
          "type": "text", 
          "payload": "{\"button\": \"1\"}", 
          "label": "Red" 
        }, 
        "color": "negative" 
      }, 
     { 
        "action": { 
          "type": "text", 
          "payload": "{\"button\": \"2\"}", 
          "label": "Green" 
        }, 
        "color": "positive" 
      }], 
      [{ 
        "action": { 
          "type": "text", 
          "payload": "{\"button\": \"3\"}", 
          "label": "White" 
        }, 
        "color": "default" 
      }, 
     { 
        "action": { 
          "type": "text", 
          "payload": "{\"button\": \"4\"}", 
          "label": "Blue" 
        }, 
        "color": "primary" 
      }] 
    ] 
  }

I am using VK-Promise library. Without the keyboard parameter, messages go as they should. However, when trying to transfer the keyboard, an error 911 "Keyboard format is invalid" occurs, which is strange, because I copied the code from the documentation.
ls_rrc4uQxk.jpg
Mistake:aKbZhmvPj2Y.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2018-09-05
@you_are_enot

You need to use JSON.stringify(keyboard), but vk-io has normal keyboard work :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question