P
P
PaulMil2020-04-25 20:22:08
In contact with
PaulMil, 2020-04-25 20:22:08

Why is the keyboard not displayed in the chat bot Vkontakte (php)?

It is not possible to display the keyboard in the response message. Here is the function code:

function vk_msg_send_keyboard($peer_id, $text, $button, $btncolor){
  $kboard = array(
    'one_time' => TRUE, 
    'buttons' => array(
      'color' => 'positive', 
      'action'=> array(
        'type' => 'text', 
        'payload' => '{"button": "1"}', 
        'label' => 'Улыбнитесь!')
      )
  );
  $request_params = array(
    'message' => $text, 
    'peer_id' => $peer_id, 
    'keyboard' => json_encode($kboard, JSON_UNESCAPED_UNICODE), 
    'access_token' => TOKEN,
    'v' => '5.87' 
  );
  $get_params = http_build_query($request_params); 
  file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
}

A similar function works without a keyboard, i.e. all parameters are ok.
I would be very grateful for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PaulMil, 2020-04-26
@PaulMil

I figured it out myself. The code above is correct except for one line:
'buttons' => array(array(array(

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question