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.

60 lines
1.4 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. * Generic message command
  13. *
  14. * Gets executed when any type of message is sent.
  15. */
  16. namespace Longman\TelegramBot\Commands\SystemCommands;
  17. use Longman\TelegramBot\Commands\SystemCommand;
  18. use Longman\TelegramBot\Commands\UserCommands\PaymentCommand;
  19. use Longman\TelegramBot\Entities\ServerResponse;
  20. use Longman\TelegramBot\Request;
  21. class GenericmessageCommand extends SystemCommand
  22. {
  23. /**
  24. * @var string
  25. */
  26. protected $name = 'genericmessage';
  27. /**
  28. * @var string
  29. */
  30. protected $description = 'Handle generic message';
  31. /**
  32. * @var string
  33. */
  34. protected $version = '0.1.0';
  35. /**
  36. * Main command execution
  37. *
  38. * @return ServerResponse
  39. */
  40. public function execute(): ServerResponse
  41. {
  42. $message = $this->getMessage();
  43. $user_id = $message->getFrom()->getId();
  44. // Handle successful payment
  45. if ($payment = $message->getSuccessfulPayment()) {
  46. return PaymentCommand::handleSuccessfulPayment($payment, $user_id);
  47. }
  48. return Request::emptyResponse();
  49. }
  50. }