Есть вот такой код:
public function sendMessage($user_id, $message, $keyboard = null) {
if (!is_null($keyboard)) {
return $this->params("messages.send", [
"message" => $message,
"peer_id" => $user_id,
"random_id" => 0,
"keyboard" => $keyboard
]);
}
else {
$this->params("messages.send", [
"message" => $message,
"peer_id" => $user_id,
"random_id" => 0
]);
}
}
public function buttonText($text, $color, $payload) {
$button = [
"action" => [
"type" => "text",
"payload" => '{
"command": '.$payload.'
}',
"label" => $text
],
"color" => $color
];
}
public function getKeyboard($buttons = [], $one_time = false) {
$keyboard = [
"one_time" => $one_time,
"buttons" => [
$buttons
]
];
return json_encode($keyboard, JSON_UNESCAPED_UNICODE);
}
И при создание клавиатуру, её отправки выходит вот такая ошибка:
Keyboard format is invalid: button [0][0] has invalid action
И вот отправка кнопок:
$button1 = $request->buttonText("Кнопка 1", "secondary", "button1");
$button2 = $request->buttonText("Кнопка 2", "secondary", "button2");
$keyboard = $request->getKeyboard([[$button1], [$button2]]);
$request->sendMessage($user_id, "Message", $keyboard);
//$request is a class interpreter, what make a query to vk api