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

1 year ago
  1. <?php
  2. /**
  3. * This file is part of the PHP Telegram Bot example-bot package.
  4. * https://github.com/php-telegram-bot/example-bot/
  5. *
  6. * (c) PHP Telegram Bot Team
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. /**
  12. * Callback query command
  13. *
  14. * This command handles all callback queries sent via inline keyboard buttons.
  15. *
  16. * @see InlinekeyboardCommand.php
  17. */
  18. namespace Longman\TelegramBot\Commands\SystemCommands;
  19. use Longman\TelegramBot\Commands\SystemCommand;
  20. use Longman\TelegramBot\Entities\ServerResponse;
  21. class CallbackqueryCommand extends SystemCommand
  22. {
  23. /**
  24. * @var string
  25. */
  26. protected $name = 'callbackquery';
  27. /**
  28. * @var string
  29. */
  30. protected $description = 'Handle the callback query';
  31. /**
  32. * @var string
  33. */
  34. protected $version = '1.2.0';
  35. /**
  36. * Main command execution
  37. *
  38. * @return ServerResponse
  39. * @throws \Exception
  40. */
  41. public function execute(): ServerResponse
  42. {
  43. // Callback query data can be fetched and handled accordingly.
  44. $callback_query = $this->getCallbackQuery();
  45. $callback_data = $callback_query->getData();
  46. return $callback_query->answer([
  47. 'text' => 'Content of the callback data: ' . $callback_data,
  48. 'show_alert' => (bool) random_int(0, 1), // Randomly show (or not) as an alert.
  49. 'cache_time' => 5,
  50. ]);
  51. }
  52. }