diff --git a/src/Client.php b/src/Client.php index fed9569a..8a6b0fb2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -101,6 +101,31 @@ public function preCheckoutQuery(Closure $action) return $this->on(self::getPreCheckoutQueryEvent($action), self::getPreCheckoutQueryChecker()); } + public function poll(Closure $action) + { + return $this->on(self::getPollEvent($action), self::getPollChecker()); + } + + public function pollAnswer(Closure $action) + { + return $this->on(self::getPollAnswerEvent($action), self::getPollAnswerChecker()); + } + + public function myChatMember(Closure $action) + { + return $this->on(self::getMyChatMemberEvent($action), self::getMyChatMemberChecker()); + } + + public function chatMember(Closure $action) + { + return $this->on(self::getChatMemberEvent($action), self::getChatMemberChecker()); + } + + public function chatJoinRequest(Closure $action) + { + return $this->on(self::getChatJoinRequestEvent($action), self::getChatJoinRequestChecker()); + } + /** * Use this method to add an event. * If second closure will return true (or if you are passed null instead of closure), first one will be executed. @@ -287,6 +312,71 @@ protected static function getPreCheckoutQueryEvent(Closure $action) }; } + protected static function getPollEvent(Closure $action) + { + return function (Update $update) use ($action) { + if (!$update->getPoll()) { + return true; + } + + $reflectionAction = new ReflectionFunction($action); + $reflectionAction->invokeArgs([$update->getPoll()]); + return false; + }; + } + + protected static function getPollAnswerEvent(Closure $action) + { + return function (Update $update) use ($action) { + if (!$update->getPollAnswer()) { + return true; + } + + $reflectionAction = new ReflectionFunction($action); + $reflectionAction->invokeArgs([$update->getPollAnswer()]); + return false; + }; + } + + protected static function getMyChatMemberEvent(Closure $action) + { + return function (Update $update) use ($action) { + if (!$update->getChatMemberUpdated()) { + return true; + } + + $reflectionAction = new ReflectionFunction($action); + $reflectionAction->invokeArgs([$update->getChatMemberUpdated()]); + return false; + }; + } + + protected static function getChatMemberEvent(Closure $action) + { + return function (Update $update) use ($action) { + if (!$update->getChatMemberUpdated()) { + return true; + } + + $reflectionAction = new ReflectionFunction($action); + $reflectionAction->invokeArgs([$update->getChatMemberUpdated()]); + return false; + }; + } + + protected static function getChatJoinRequestEvent(Closure $action) + { + return function (Update $update) use ($action) { + if (!$update->getChatJoinRequest()) { + return true; + } + + $reflectionAction = new ReflectionFunction($action); + $reflectionAction->invokeArgs([$update->getChatJoinRequest()]); + return false; + }; + } + /** * Returns check function to handling the command. * @@ -404,6 +494,69 @@ protected static function getPreCheckoutQueryChecker() }; } + /** + * Returns check function to handling the poll. + * + * @return Closure + */ + protected static function getPollChecker() + { + return function (Update $update) { + return !is_null($update->getPoll()); + }; + } + + /** + * Returns check function to handling the poll answers. + * + * @return Closure + */ + protected static function getPollAnswerChecker() + { + return function (Update $update) { + return !is_null($update->getPollAnswer()); + }; + } + + /** + * Returns check function to handling the updated chat member. + * The bot's chat member status was updated in a chat. + * For private chats, this update is received only when the bot is blocked or unblocked by the user. + * @return Closure + */ + protected static function getMyChatMemberChecker() + { + return function (Update $update) { + return !is_null($update->getChatMemberUpdated()); + }; + } + + /** + * Returns check function to handling the updated chat member. + * The bot's chat member status was updated in a chat. + * For private chats, this update is received only when the bot is blocked or unblocked by the user. + * @return Closure + */ + protected static function getChatMemberChecker() + { + return function (Update $update) { + return !is_null($update->getChatMemberUpdated()); + }; + } + + /** + * Returns check function to handling the chat join requests. + * The bot's chat member status was updated in a chat. + * For private chats, this update is received only when the bot is blocked or unblocked by the user. + * @return Closure + */ + protected static function getChatJoinRequestChecker() + { + return function (Update $update) { + return !is_null($update->getChatJoinRequest()); + }; + } + public function __call($name, array $arguments) { if (method_exists($this, $name)) { diff --git a/src/Types/ChatInviteLink.php b/src/Types/ChatInviteLink.php new file mode 100644 index 00000000..adc6c570 --- /dev/null +++ b/src/Types/ChatInviteLink.php @@ -0,0 +1,254 @@ + true, + 'creator' => User::class, + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + 'name' => true, + 'expire_date' => true, + 'member_limit' => true, + 'pending_join_request_count' => true, + ]; + + /** + * The invite link. If the link was created by another chat administrator, + * then the second part of the link will be replaced with “…”. + * + * @var string + */ + protected $invite_link; + + /** + * Creator of the link + * + * @var User + */ + protected $creator; + + /** + * True, if users joining the chat via the link need to be approved by chat administrators + * + * @var boolean + */ + protected $creates_join_request; + + /** + * True, if the link is primary + * + * @var boolean + */ + protected $is_primary; + + /** + * True, if the link is revoked + * + * @var boolean + */ + protected $is_revoked; + + /** + * Optional. Invite link name + * + * @var string + */ + protected $name; + + /** + * Optional. Point in time (Unix timestamp) when the link will expire or has been expired + * + * @var integer + */ + protected $expire_date; + + /** + * @return string + */ + public function getInviteLink() + { + return $this->invite_link; + } + + /** + * @param string $invite_link + */ + public function setInviteLink($invite_link) + { + $this->invite_link = $invite_link; + } + + /** + * @return User + */ + public function getCreator() + { + return $this->creator; + } + + /** + * @param User $creator + */ + public function setCreator($creator) + { + $this->creator = $creator; + } + + /** + * @return bool + */ + public function isCreatesJoinRequest() + { + return $this->creates_join_request; + } + + /** + * @param bool $creates_join_request + */ + public function setCreatesJoinRequest($creates_join_request) + { + $this->creates_join_request = $creates_join_request; + } + + /** + * @return bool + */ + public function isIsPrimary() + { + return $this->is_primary; + } + + /** + * @param bool $is_primary + */ + public function setIsPrimary($is_primary) + { + $this->is_primary = $is_primary; + } + + /** + * @return bool + */ + public function isIsRevoked() + { + return $this->is_revoked; + } + + /** + * @param bool $is_revoked + */ + public function setIsRevoked($is_revoked) + { + $this->is_revoked = $is_revoked; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int + */ + public function getExpireDate() + { + return $this->expire_date; + } + + /** + * @param int $expire_date + */ + public function setExpireDate($expire_date) + { + $this->expire_date = $expire_date; + } + + /** + * @return int + */ + public function getMemberLimit() + { + return $this->member_limit; + } + + /** + * @param int $member_limit + */ + public function setMemberLimit($member_limit) + { + $this->member_limit = $member_limit; + } + + /** + * @return int + */ + public function getPendingJoinRequestCount() + { + return $this->pending_join_request_count; + } + + /** + * @param int $pending_join_request_count + */ + public function setPendingJoinRequestCount($pending_join_request_count) + { + $this->pending_join_request_count = $pending_join_request_count; + } + + /** + * Optional. Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 + * + * @var integer + */ + protected $member_limit; + + /** + * Optional. Number of pending join requests created using this link + * + * @var integer + */ + protected $pending_join_request_count; + +} diff --git a/src/Types/ChatJoinRequest.php b/src/Types/ChatJoinRequest.php new file mode 100644 index 00000000..e8d1fed6 --- /dev/null +++ b/src/Types/ChatJoinRequest.php @@ -0,0 +1,150 @@ + Chat::class, + 'from' => User::class, + 'date' => true, + 'bio' => true, + 'invite_link' => ChatInviteLink::class, + ]; + + /** + * Chat to which the request was sent + * + * @var Chat + */ + protected $chat; + + /** + * User that sent the join request + * + * @var User + */ + protected $from; + + /** + * Date the request was sent in Unix time + * + * @var integer + */ + protected $date; + + /** + * Optional. Bio of the user + * + * @var string + */ + protected $bio; + + /** + * Optional. Chat invite link that was used by the user to send the join request + * + * @var ChatInviteLink + */ + protected $invite_link; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return string + */ + public function getBio() + { + return $this->bio; + } + + /** + * @param string $bio + */ + public function setBio($bio) + { + $this->bio = $bio; + } + + /** + * @return ChatInviteLink + */ + public function getInviteLink() + { + return $this->invite_link; + } + + /** + * @param ChatInviteLink $invite_link + */ + public function setInviteLink($invite_link) + { + $this->invite_link = $invite_link; + } + +} diff --git a/src/Types/ChatMemberUpdated.php b/src/Types/ChatMemberUpdated.php new file mode 100644 index 00000000..c5710c0b --- /dev/null +++ b/src/Types/ChatMemberUpdated.php @@ -0,0 +1,182 @@ + Chat::class, + 'from' => User::class, + 'date' => true, + 'old_chat_member' => ChatMember::class, + 'new_chat_member' => ChatMember::class, + 'invite_link' => ChatInviteLink::class, + ]; + + /** + * Chat the user belongs to + * + * @var Chat + */ + protected $chat; + + /** + * Performer of the action, which resulted in the change + * + * @var User + */ + protected $from; + + /** + * Date the change was done in Unix time + * + * @var Integer + */ + protected $date; + + /** + * Previous information about the chat member + * + * @var ChatMember + */ + protected $old_chat_member; + + /** + * New information about the chat member + * + * @var ChatMember + */ + protected $new_chat_member; + + /** + * Optional. Chat invite link, which was used by the user to join the chat; + * for joining by invite link events only. + * + * @var ChatInviteLink + */ + protected $invite_link; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return ChatMember + */ + public function getOldChatMember() + { + return $this->old_chat_member; + } + + /** + * @param ChatMember $old_chat_member + */ + public function setOldChatMember($old_chat_member) + { + $this->old_chat_member = $old_chat_member; + } + + /** + * @return ChatMember + */ + public function getNewChatMember() + { + return $this->new_chat_member; + } + + /** + * @param ChatMember $new_chat_member + */ + public function setNewChatMember($new_chat_member) + { + $this->new_chat_member = $new_chat_member; + } + + /** + * @return ChatInviteLink + */ + public function getInviteLink() + { + return $this->invite_link; + } + + /** + * @param ChatInviteLink $invite_link + */ + public function setInviteLink($invite_link) + { + $this->invite_link = $invite_link; + } + +} diff --git a/src/Types/Update.php b/src/Types/Update.php index 031d2b56..16f2d531 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -73,6 +73,12 @@ class Update extends BaseType implements TypeInterface protected $poll; + /** + * @var ChatMemberUpdated + */ + protected $chatMemberUpdated; + + /** * Optional. New version of a message that is known to the bot and was edited * @@ -97,21 +103,21 @@ class Update extends BaseType implements TypeInterface /** * Optional. New incoming inline query * - * @var \TelegramBot\Api\Types\Inline\InlineQuery + * @var InlineQuery */ protected $inlineQuery; /** * Optional. The result of a inline query that was chosen by a user and sent to their chat partner * - * @var \TelegramBot\Api\Types\Inline\ChosenInlineResult + * @var ChosenInlineResult */ protected $chosenInlineResult; /** * Optional. New incoming callback query * - * @var \TelegramBot\Api\Types\CallbackQuery + * @var CallbackQuery */ protected $callbackQuery; @@ -129,6 +135,14 @@ class Update extends BaseType implements TypeInterface */ protected $preCheckoutQuery; + /** + * Optional. A request to join the chat has been sent. + * The bot must have the can_invite_users administrator right in the chat to receive these updates + * + * @var ChatJoinRequest + */ + protected $chatJoinRequest; + /** * @return int */ @@ -209,6 +223,22 @@ public function getPoll() return $this->poll; } + /** + * @return ChatMemberUpdated + */ + public function getChatMemberUpdated() + { + return $this->chatMemberUpdated; + } + + /** + * @return ChatJoinRequest + */ + public function getChatJoinRequest() + { + return $this->chatJoinRequest; + } + /** * @param Poll $poll */