Answer the question
In order to leave comments, you need to log in
Why doesn't VK show payload without a keyboard?
I can not understand the logic of the bots in VK. The general API documentation says that you can add a payload to any message - just a payload, just a string. At the same time, the documentation about the buttons for the bot says that the payload for the keyboard is necessarily json.
I outlined the following mechanism of work: the user writes to the bot for the first time - the bot sees that the message does not have any payload, which means that you need to issue a standard message and attach a keyboard for interaction. Further, the bot will look at the payload and react differently.
But there is a problem: sometimes the bot, within the framework of some scenario, is forced to ask the user for additional information (by pressing a button) - for example, the user wants to know the status of the order, then the bot, having seen the payload button and determining what the user needs, asks him for the order number. Of course, the keyboard will not help here, the user should just send a message.
The problem is that such a message with an order number for some reason does not have any payload. I tried to send this payload to a message without a keyboard in different ways: just text, and a json string, and so on and so forth. VK accepts almost all values of this parameter, and sends a message to the user without any problems without giving any errors. But the subsequent message from the user comes to my server without the payload parameter.
I can't understand, the problem is that payload should still be used only with the keyboard, or am I somehow sending the request to send a message with payload incorrectly?
And if this payload parameter cannot be used to understand what the user wants, then it turns out that I will have to keep a history of calls to the bot somewhere to understand what the user wants?
If, nevertheless, it is possible to attach a payload to a regular message without a keyboard, then below is the request code to VK to send a message, and what comes through the Callback API from the user in response to such a message with payload, there may be something wrong in the request or do I need to enable the payload transfer somewhere separately?
Request to send message from payload without keyboard:
https://api.vk.com/method/messages.send?peer_id=АЙДИ&message=ТЕКСТ СООБЩЕНИЯ&random_id=26650232&payload=%7B%22command%22%3A%22waiting_order_id%22%7D&access_token=ТОКЕН&v=5.92
array (
'type' => 'message_new',
'object' =>
array (
'date' => 1548940652,
'from_id' => АЙДИ,
'id' => 1236,
'out' => 0,
'peer_id' => ПИР_АЙДИ,
'text' => '150',
'conversation_message_id' => 301,
'fwd_messages' =>
array (
),
'important' => false,
'random_id' => 0,
'attachments' =>
array (
),
'is_hidden' => false,
),
'group_id' => ГРУП_АЙДИ,
'secret' => 'СЕКРЕТ',
)
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