I
I
Ivan Yakushenko2019-04-28 09:17:18
Python
Ivan Yakushenko, 2019-04-28 09:17:18

How to send only VK API keyboard?

The bot has several different keyboards, for different tasks, but you need the starting one to always be active. If you set the option "one_time": false, call another keyboard, select a function, after which the side keyboard will close, the main one will not open until you enter the keyword that should call it. Without thinking about a solution, I decided to try:

if event.object.text:
                        self.vk_api.messages.send(
                            user_id=event.object.from_id,
                            random_id=random.getrandbits(32),
                            message='',
                            keyboard=open("keyboard/start_keyboard.json", "r", encoding="UTF-8").read()
                        )

But, of course, as expected - an error. You cannot send an empty message.
I need that, regardless of what the user writes to the bot, the main keyboard (start_keyboard.json) is always active and only if certain options are selected, others are opened.
How can such a thing be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stockholm Syndrome, 2019-04-28
@kshnkvn

when the user clicks on the side keyboard, send not an empty message, but some "great choice" and return the old keyboard

A
AlerX, 2019-04-28
@AlerX

Keyboard example

keyboard1234 = {
    "one_time": True,
    "buttons": [
        [{
            "action": {
                "type": "text",
                "payload": "{\"button\": \"1\"}",
                "label": "Кнопка"
            },
            "color": "positive"
        },
            {
                "action": {
                    "type": "text",
                    "payload": "{\"button\": \"2\"}",
                    "label": "Кнопка"
                },
                "color": "positive"
            }]

    ]

The Keyboard has a One_Time parameter, if it is set to True - the keyboard can be used once. And if False it will be active until you send a new keyboard.
Sending just a keyboard will not work, it is sent with a message.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question