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.

64 lines
1.3 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. * User "/echo" command
  13. *
  14. * Simply echo the input back to the user.
  15. */
  16. namespace Longman\TelegramBot\Commands\UserCommands;
  17. use Longman\TelegramBot\Commands\UserCommand;
  18. use Longman\TelegramBot\Entities\ServerResponse;
  19. use Longman\TelegramBot\Exception\TelegramException;
  20. class EchoCommand extends UserCommand
  21. {
  22. /**
  23. * @var string
  24. */
  25. protected $name = 'echo';
  26. /**
  27. * @var string
  28. */
  29. protected $description = 'Show text';
  30. /**
  31. * @var string
  32. */
  33. protected $usage = '/echo <text>';
  34. /**
  35. * @var string
  36. */
  37. protected $version = '1.2.0';
  38. /**
  39. * Main command execution
  40. *
  41. * @return ServerResponse
  42. * @throws TelegramException
  43. */
  44. public function execute(): ServerResponse
  45. {
  46. $message = $this->getMessage();
  47. $text = $message->getText(true);
  48. if ($text === '') {
  49. return $this->replyToChat('Command usage: ' . $this->getUsage());
  50. }
  51. return $this->replyToChat($text);
  52. }
  53. }