Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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
- Команда запроса обратного вызова
- Эта команда обрабатывает все запросы обратного вызова, отправляемые с помощью интерактивных кнопок клавиатуры.
- @смотри InlinekeyboardCommand.php
- */
- namespace Longman\TelegramBot\Commands\SystemCommands;
- use Longman\TelegramBot\Commands\SystemCommand;
- use Longman\TelegramBot\Entities\ServerResponse;
- use Longman\TelegramBot\Entities\InlineKeyboard;
- 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,
- ]);
- }*/
- public function execute(): ServerResponse
- {
- /*spl_autoload_register("my_autoloader");
- // Callback query data can be fetched and handled accordingly.
- // Данные запроса обратного вызова могут быть извлечены и обработаны соответствующим образом.
- $callback_query = $this->getCallbackQuery();
- $callback_data = $callback_query->getData();
- if($callback_data === 'InlinekeyboardCommand1'){
- $command = new InlinekeyboardCommand1($telegram, $update);
- } elseif($callback_data === 'InlinekeyboardCommand2') {
- $command = new InlinekeyboardCommand2($telegram, $update);
- } elseif($callback_data === 'InlinekeyboardCommand3') {
- $command = new InlinekeyboardCommand3($telegram, $update);
- }
- $command->execute();
- /*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,
- ]);*/
- $callback_query = $this->getCallbackQuery();
- $callback_data = $callback_query->getData();
- if($callback_data == '1'){
- $inline_keyboard = new InlineKeyboard([
- ['text' => 'Callback', 'callback_data' => '2'],
- ['text' => 'Callback', 'callback_data' => '2'],
- ], [
- ['text' => 'Callback', 'callback_data' => '2'],
- ['text' => 'Callback', 'callback_data' => '2'],
- ]);
- } elseif($callback_data == '2') {
- $inline_keyboard = new InlineKeyboard([
- ['text' => 'Callback', 'callback_data' => '3'],
- ['text' => 'Callback', 'callback_data' => '3'],
- ], [
- ['text' => 'Callback', 'callback_data' => '3'],
- ['text' => 'Callback', 'callback_data' => '3'],
- ]);
- } elseif($callback_data == '3') {
- $inline_keyboard = new InlineKeyboard([
- ['text' => 'Callback', 'callback_data' => '4'],
- ['text' => 'Callback', 'callback_data' => '4'],
- ], [
- ['text' => 'Callback', 'callback_data' => '4'],
- ['text' => 'Callback', 'callback_data' => '4'],
- ]);
- }
- $callback_query->editMessageReplyMarkup($inline_keyboard);
- /*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,
- 'reply_markup' => $inline_keyboard
- ]);*/
- return $callback_query->answer();
- /*return $this->replyToChat($callback_query, [
- 'reply_markup' => $inline_keyboard,
- ]);*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment