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.

82 lines
1.9 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. * In this group-related context, we can handle new and left group members.
  17. */
  18. namespace Longman\TelegramBot\Commands\SystemCommands;
  19. use Longman\TelegramBot\Commands\SystemCommand;
  20. use Longman\TelegramBot\Entities\ServerResponse;
  21. use Longman\TelegramBot\Exception\TelegramException;
  22. use Longman\TelegramBot\Request;
  23. class GenericmessageCommand extends SystemCommand
  24. {
  25. /**
  26. * @var string
  27. */
  28. protected $name = 'genericmessage';
  29. /**
  30. * @var string
  31. */
  32. protected $description = 'Handle generic message';
  33. /**
  34. * @var string
  35. */
  36. protected $version = '1.0.0';
  37. /**
  38. * Main command execution
  39. *
  40. * @return ServerResponse
  41. * @throws TelegramException
  42. */
  43. public function execute(): ServerResponse
  44. {
  45. $message = $this->getMessage();
  46. // Handle new chat members
  47. if ($message->getNewChatMembers()) {
  48. return $this->getTelegram()->executeCommand('newchatmembers');
  49. }
  50. // Handle left chat members
  51. if ($message->getLeftChatMember()) {
  52. return $this->getTelegram()->executeCommand('leftchatmember');
  53. }
  54. // The chat photo was changed
  55. if ($new_chat_photo = $message->getNewChatPhoto()) {
  56. // Whatever...
  57. }
  58. // The chat title was changed
  59. if ($new_chat_title = $message->getNewChatTitle()) {
  60. // Whatever...
  61. }
  62. // A message has been pinned
  63. if ($pinned_message = $message->getPinnedMessage()) {
  64. // Whatever...
  65. }
  66. return Request::emptyResponse();
  67. }
  68. }