forked from LIERLIER/telegram-bot-base
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
61 lines
1.5 KiB
<?php
|
|
|
|
/**
|
|
* This file is part of the PHP Telegram Bot example-bot package.
|
|
* https://github.com/php-telegram-bot/example-bot/
|
|
*
|
|
* (c) PHP Telegram Bot Team
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
/**
|
|
* Callback query command
|
|
*
|
|
* This command handles all callback queries sent via inline keyboard buttons.
|
|
*
|
|
* @see InlinekeyboardCommand.php
|
|
*/
|
|
|
|
namespace Longman\TelegramBot\Commands\SystemCommands;
|
|
|
|
use Longman\TelegramBot\Commands\SystemCommand;
|
|
use Longman\TelegramBot\Entities\ServerResponse;
|
|
|
|
class CallbackqueryCommand extends SystemCommand
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $name = 'callbackquery';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $description = 'Handle the callback query';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $version = '1.2.0';
|
|
|
|
/**
|
|
* Main command execution
|
|
*
|
|
* @return ServerResponse
|
|
* @throws \Exception
|
|
*/
|
|
public function execute(): ServerResponse
|
|
{
|
|
// Callback query data can be fetched and handled accordingly.
|
|
$callback_query = $this->getCallbackQuery();
|
|
$callback_data = $callback_query->getData();
|
|
|
|
return $callback_query->answer([
|
|
'text' => 'Content of the callback data: ' . $callback_data,
|
|
'show_alert' => (bool) random_int(0, 1), // Randomly show (or not) as an alert.
|
|
'cache_time' => 5,
|
|
]);
|
|
}
|
|
}
|