Closed ale24 closed 3 years ago
До версии 1.7.6 (включительно) драйвер не поддерживал другие типы кнопок, отличные от type="text". В версии 1.7.7 расширил поддержку других кнопок из документации:
$botman->hears('vk keyboard', function(BotMan $bot) {
$keyboard = new VKKeyboard();
$keyboard->setInline(false);
$keyboard->setOneTime(false);
$keyboard->addRows(
new VKKeyboardRow([
( new VKKeyboardButton() )
->setColor(VKKeyboardButton::COLOR_PRIMARY)
->setText("Sample text")
->setValue("button1")
]),
new VKKeyboardRow([
( new VKKeyboardButton() )
->setType(VKKeyboardButton::TYPE_OPEN_LINK)
->setLink("https://github.com/")
->setText("Open link")
->setValue("button_open_link")
]),
new VKKeyboardRow([
( new VKKeyboardButton() )
->setType(VKKeyboardButton::TYPE_LOCATION)
->setValue("button_location")
]),
new VKKeyboardRow([
( new VKKeyboardButton() )
->setType(VKKeyboardButton::TYPE_VK_PAY)
->setHash("action=transfer-to-group&group_id=1&aid=10")
->setValue("button_vk_pay")
]),
new VKKeyboardRow([
( new VKKeyboardButton() )
->setType(VKKeyboardButton::TYPE_OPEN_APP)
->setAppID(123456789)
->setOwnerID(-123456789)
->setText("Open app")
->setValue("button_open_app")
]),
new VKKeyboardRow([
( new VKKeyboardButton() )
->setType(VKKeyboardButton::TYPE_CALLBACK)
->setText("Callback button")
->setColor(VKKeyboardButton::COLOR_DEFAULT)
->setValue("button_callback")
])
);
$bot->reply("Native keyboard:", [
"keyboard" => $keyboard->toJSON()
]);
});
благодарю за оперативный апдейт
кому интересно, рабочий вариант для прошлой версии через sendRequest:
$endpoint = "messages.send";
$open_link = [
'action' => [
'type' => 'open_link',
'link' => 'https://vk.com',
'label' => 'test'
]
];
$open_link['action']['payload'] = json_encode($open_link);
$keyboard = [
'one_time' => false,
'buttons' => [
0 => [ 0 => $open_link ]
]
];
// Arguments ("v" and "access_token" are set by driver, no need to define)
$arguments = [
"peer_id" => $bot->getUser()->getId(), // User ID
"message" => 'test', // Sticker ID
"random_id" => rand(10000,100000), // Random ID (required by VK API, to prevent doubling messages)
"keyboard" => json_encode($keyboard)
];
$bot->sendRequest($endpoint, $arguments);
Botman(не студия) | PHP 7.3.11 | "version" => "5.103"
В документации сказано:
Оба способа выставления Type не работают:
Судя по коду драйвер принудительно выставляет цвет, что возможно противоречит той же информации по ссылке от ВК:
Если убрать обязательное требование цвета, то некоторые Type вроде open_app удалось заставить работать, но open_link даже так почему-то не работает: