YaKotikTvoy

CallbackqueryCommand

Jul 9th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.65 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This file is part of the PHP Telegram Bot example-bot package.
  5.  * https://github.com/php-telegram-bot/example-bot/
  6.  *
  7.  * (c) PHP Telegram Bot Team
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12.  
  13. /**
  14.  * Callback query command
  15.  *
  16.  * This command handles all callback queries sent via inline keyboard buttons.
  17.  *
  18.  * @see InlinekeyboardCommand.php
  19.  Команда запроса обратного вызова
  20.  
  21. Эта команда обрабатывает все запросы обратного вызова, отправляемые с помощью интерактивных кнопок клавиатуры.
  22.  
  23. @смотри InlinekeyboardCommand.php
  24.  */
  25.  
  26. namespace Longman\TelegramBot\Commands\SystemCommands;
  27.  
  28. use Longman\TelegramBot\Commands\SystemCommand;
  29. use Longman\TelegramBot\Entities\ServerResponse;
  30. use Longman\TelegramBot\Entities\InlineKeyboard;
  31.  
  32. class CallbackqueryCommand extends SystemCommand
  33. {
  34.     /**
  35.      * @var string
  36.      */
  37.     protected $name = 'callbackquery';
  38.  
  39.     /**
  40.      * @var string
  41.      */
  42.     protected $description = 'Handle the callback query';
  43.  
  44.     /**
  45.      * @var string
  46.      */
  47.     protected $version = '1.2.0';
  48.  
  49.     /**
  50.      * Main command execution
  51.      *
  52.      * @return ServerResponse
  53.      * @throws \Exception
  54.      */
  55.     /*public function execute(): ServerResponse
  56.     {
  57.         // Callback query data can be fetched and handled accordingly.
  58.         // Данные запроса обратного вызова могут быть извлечены и обработаны соответствующим образом.
  59.         $callback_query = $this->getCallbackQuery();
  60.         $callback_data  = $callback_query->getData();
  61.  
  62.         return $callback_query->answer([
  63.             'text'       => 'Content of the callback data: ' . $callback_data,
  64.             'show_alert' => (bool) random_int(0, 1), // Randomly show (or not) as an alert.
  65.             'cache_time' => 5,
  66.         ]);
  67.     }*/
  68.     public function execute(): ServerResponse
  69.     {
  70.         /*spl_autoload_register("my_autoloader");
  71.         // Callback query data can be fetched and handled accordingly.
  72.         // Данные запроса обратного вызова могут быть извлечены и обработаны соответствующим образом.
  73.         $callback_query = $this->getCallbackQuery();
  74.         $callback_data  = $callback_query->getData();
  75.         if($callback_data === 'InlinekeyboardCommand1'){
  76.             $command = new InlinekeyboardCommand1($telegram, $update);
  77.         } elseif($callback_data === 'InlinekeyboardCommand2') {
  78.             $command = new InlinekeyboardCommand2($telegram, $update);
  79.         } elseif($callback_data === 'InlinekeyboardCommand3') {
  80.             $command = new InlinekeyboardCommand3($telegram, $update);
  81.         }
  82.         $command->execute();
  83.         /*return $callback_query->answer([
  84.             'text'       => 'Content of the callback data: ' . $callback_data,
  85.             'show_alert' => (bool) random_int(0, 1), // Randomly show (or not) as an alert.
  86.             'cache_time' => 5,
  87.         ]);*/
  88.         $callback_query = $this->getCallbackQuery();
  89.         $callback_data  = $callback_query->getData();
  90.         if($callback_data == '1'){
  91.             $inline_keyboard = new InlineKeyboard([
  92.                 ['text' => 'Callback', 'callback_data' => '2'],
  93.                 ['text' => 'Callback', 'callback_data' => '2'],
  94.             ], [
  95.                 ['text' => 'Callback', 'callback_data' => '2'],
  96.                 ['text' => 'Callback', 'callback_data' => '2'],
  97.             ]);
  98.         } elseif($callback_data == '2') {
  99.             $inline_keyboard = new InlineKeyboard([
  100.                 ['text' => 'Callback', 'callback_data' => '3'],
  101.                 ['text' => 'Callback', 'callback_data' => '3'],
  102.             ], [
  103.                 ['text' => 'Callback', 'callback_data' => '3'],
  104.                 ['text' => 'Callback', 'callback_data' => '3'],
  105.             ]);
  106.         } elseif($callback_data == '3') {
  107.             $inline_keyboard = new InlineKeyboard([
  108.                 ['text' => 'Callback', 'callback_data' => '4'],
  109.                 ['text' => 'Callback', 'callback_data' => '4'],
  110.             ], [
  111.                 ['text' => 'Callback', 'callback_data' => '4'],
  112.                 ['text' => 'Callback', 'callback_data' => '4'],
  113.             ]);
  114.         }
  115.         //$callback_query->editMessageReplyMarkup($inline_keyboard);
  116.         /*return $callback_query->answer([
  117.             'text'       => 'Content of the callback data: ' . $callback_data,
  118.             'show_alert' => (bool) random_int(0, 1), // Randomly show (or not) as an alert.
  119.             'cache_time' => 5,
  120.             'reply_markup' => $inline_keyboard
  121.         ]);*/
  122.         //return $callback_query->answer();
  123.         return $this->replyToChat($callback_query, [
  124.             'reply_markup' => $inline_keyboard,
  125.         ]);
  126.     }
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment