Здравствуйте, проблема заключается в том что не получается отловить нажатие на кнопку.
Использую библиотеку :
php-telegram-bot
Имеется код:
CategoryCommand.phpnamespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\InlineKeyboard;
use Longman\TelegramBot\Entities\InlineKeyboardButton;
use Longman\TelegramBot\Request;
class CategoryCommand extends UserCommand
{
protected $name = 'category';
protected $description = 'Choose a category, inline.';
protected $usage = '/category';
protected $version = '1.0.0';
public static $categories = [
'apple' => 'Yay, an apple!',
'orange' => 'Sweetness...',
'cherry' => 'A cherry on top.',
];
public function execute()
{
$keyboard_buttons = [];
foreach (self::$categories as $key => $value) {
$keyboard_buttons[] = new InlineKeyboardButton([
'text' => ucfirst($key),
'callback_data' => 'category_' . $key,
]);
}
$data = [
'chat_id' => $this->getMessage()->getChat()->getId(),
'text' => 'Choose a category:',
'reply_markup' => new InlineKeyboard($keyboard_buttons),
];
return Request::sendMessage($data);
}
}
CallbackqueryCommand.phpnamespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\AdminCommands\CategoryCommand;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
class CallbackqueryCommand extends SystemCommand
{
protected $name = 'callbackquery';
protected $description = 'Reply to callback query';
protected $version = '1.0.0';
public function execute()
{
$update = $this->getUpdate();
$callback_query = $update->getCallbackQuery();
$callback_data = $callback_query->getData();
if (strpos($callback_data, 'category_') !== 0) {
return Request::emptyResponse();
}
// Get the real category from the callback_data.
$category = substr($callback_data, strlen('category_'));
return Request::editMessageText([
'chat_id' => $callback_query->getMessage()->getChat()->getId(),
'message_id' => $callback_query->getMessage()->getMessageId(),
'text' => CategoryCommand::$categories[$category],
]);
}
}
так вот, при попытке нажать на кнопку появляется прогресс гифка на кнопке и не происходит никаких действий.
Может кто подсказать как заставить ее функционировать?
В логах отображается нажатие вот так:
{"update_id":397554859, "callback_query":{"id":"1855119156716195348","from":{"id":431928587,"first_name":"\u0412\u0438\u0442\u0430\u043b\u0438\u0439","last_name":"\u0425\u0432\u0430\u043d","language_code":"ru-RU"},"message":{"message_id":690,"from":{"id":443120385,"first_name":"Tuvi Sender","username":"testMnpBot"},"chat":{"id":431928587,"first_name":"\u0412\u0438\u0442\u0430\u043b\u0438\u0439","last_name":"\u0425\u0432\u0430\u043d","type":"private"},"date":1502430139,"text":"Choose a category:"},"chat_instance":"1654208307583307370","data":"category_orange"}}
{"update_id":397554860, "callback_query":{"id":"1855119158318881607","from":{"id":431928587,"first_name":"\u0412\u0438\u0442\u0430\u043b\u0438\u0439","last_name":"\u0425\u0432\u0430\u043d","language_code":"ru-RU"},"message":{"message_id":690,"from":{"id":443120385,"first_name":"Tuvi Sender","username":"testMnpBot"},"chat":{"id":431928587,"first_name":"\u0412\u0438\u0442\u0430\u043b\u0438\u0439","last_name":"\u0425\u0432\u0430\u043d","type":"private"},"date":1502430139,"text":"Choose a category:"},"chat_instance":"1654208307583307370","data":"category_cherry"}}
{"update_id":397554855, "callback_query":{"id":"1855119158385125754","from":{"id":431928587,"first_name":"\u0412\u0438\u0442\u0430\u043b\u0438\u0439","last_name":"\u0425\u0432\u0430\u043d","language_code":"ru-RU"},"message":{"message_id":690,"from":{"id":443120385,"first_name":"Tuvi Sender","username":"testMnpBot"},"chat":{"id":431928587,"first_name":"\u0412\u0438\u0442\u0430\u043b\u0438\u0439","last_name":"\u0425\u0432\u0430\u043d","type":"private"},"date":1502430139,"text":"Choose a category:"},"chat_instance":"1654208307583307370","data":"category_apple"}}