From a2dffe83b8e82bb3ecffbf42abd4b35623939e54 Mon Sep 17 00:00:00 2001 From: Yaroslav Molchan Date: Fri, 3 Nov 2017 17:57:26 +0200 Subject: [PATCH 001/130] Add new features from Bot API 3.4 --- src/BotApi.php | 124 +++++++++++++++++++++++--- src/Types/ArrayOfChatMemberEntity.php | 16 ++++ src/Types/Chat.php | 50 ++++++++++- src/Types/Message.php | 24 +++++ 4 files changed, 199 insertions(+), 15 deletions(-) create mode 100644 src/Types/ArrayOfChatMemberEntity.php diff --git a/src/BotApi.php b/src/BotApi.php index fc8a1fe8..92a7cd95 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -468,15 +468,15 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) /** * Use this method to send point on the map. On success, the sent Message is returned. * - * @param int $chatId - * @param float $latitude - * @param float $longitude - * @param int|null $replyToMessageId + * @param int|string $chatId + * @param float $latitude + * @param float $longitude + * @param int|null $replyToMessageId * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @param bool $disableNotification + * @param bool $disableNotification * + * @param null|int $livePeriod * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\Exception */ public function sendLocation( $chatId, @@ -484,18 +484,76 @@ public function sendLocation( $longitude, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false - ) { + $disableNotification = false, + $livePeriod = null + ) + { return Message::fromResponse($this->call('sendLocation', [ - 'chat_id' => $chatId, - 'latitude' => $latitude, - 'longitude' => $longitude, - 'reply_to_message_id' => $replyToMessageId, - 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'chat_id' => $chatId, + 'latitude' => $latitude, + 'longitude' => $longitude, + 'live_period' => $livePeriod, + 'reply_to_message_id' => $replyToMessageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, ])); } + /** + * Use this method to edit live location messages sent by the bot or via the bot (for inline bots). + * + * @param int|string $chatId + * @param int $messageId + * @param string $inlineMessageId + * @param float $latitude + * @param float $longitude + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @return \TelegramBot\Api\Types\Message + */ + public function editMessageLiveLocation( + $chatId, + $messageId, + $inlineMessageId, + $latitude, + $longitude, + $replyMarkup = null + ) + { + return Message::fromResponse($this->call('sendLocation', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'inline_message_id' => $inlineMessageId, + 'latitude' => $latitude, + 'longitude' => $longitude, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ])); + } + + /** + * Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before + * live_period expires. + * + * @param int|string $chatId + * @param int $messageId + * @param string $inlineMessageId + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @return \TelegramBot\Api\Types\Message + */ + public function stopMessageLiveLocation( + $chatId, + $messageId, + $inlineMessageId, + $replyMarkup = null + ) + { + return Message::fromResponse($this->call('sendLocation', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'inline_message_id' => $inlineMessageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ])); + } + /** * Use this method to send information about a venue. On success, the sent Message is returned. * @@ -1456,4 +1514,42 @@ public function leaveChat($chatId) 'chat_id' => $chatId ]); } -} + + /** + * Use this method to get the number of members in a chat. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return int + */ + public function getChatMembersCount($chatId) + { + return $this->call( + 'getChatMembersCount', + [ + 'chat_id' => $chatId + ] + ); + } + + /** + * Use this method to get a list of administrators in a chat. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return array + */ + public function getChatAdministrators($chatId) + { + return ArrayOfChatMemberEntity::fromResponse( + $this->call( + 'getChatMembersCount', + [ + 'chat_id' => $chatId + ] + ) + ); + } +} \ No newline at end of file diff --git a/src/Types/ArrayOfChatMemberEntity.php b/src/Types/ArrayOfChatMemberEntity.php new file mode 100644 index 00000000..95333448 --- /dev/null +++ b/src/Types/ArrayOfChatMemberEntity.php @@ -0,0 +1,16 @@ + ChatPhoto::class, 'description' => true, 'invite_link' => true, - 'pinned_message' => Message::class + 'pinned_message' => Message::class, + 'sticker_set_name' => true, + 'can_set_sticker_set' => true ]; /** @@ -106,6 +108,20 @@ class Chat extends BaseType implements TypeInterface */ protected $pinnedMessage; + /** + * Optional. For supergroups, name of group sticker set. Returned only in getChat. + * + * @var string + */ + protected $stickerSetName; + + /** + * Optional. True, if the bot can change the group sticker set. Returned only in getChat. + * + * @var bool + */ + protected $canSetStickerSet; + /** * @return int|string */ @@ -287,4 +303,36 @@ public function setPinnedMessage($pinnedMessage) { $this->pinnedMessage = $pinnedMessage; } + + /** + * @return string + */ + public function getStickerSetName() + { + return $this->stickerSetName; + } + + /** + * @param string $stickerSetName + */ + public function setStickerSetName($stickerSetName) + { + $this->stickerSetName = $stickerSetName; + } + + /** + * @return bool + */ + public function isCanSetStickerSet() + { + return $this->canSetStickerSet; + } + + /** + * @param bool $canSetStickerSet + */ + public function setCanSetStickerSet($canSetStickerSet) + { + $this->canSetStickerSet = $canSetStickerSet; + } } diff --git a/src/Types/Message.php b/src/Types/Message.php index 99199740..1b724daa 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -31,6 +31,7 @@ class Message extends BaseType implements TypeInterface 'reply_to_message' => Message::class, 'text' => true, 'entities' => ArrayOfMessageEntity::class, + 'caption_entities' => ArrayOfMessageEntity::class, 'audio' => Audio::class, 'document' => Document::class, 'photo' => ArrayOfPhotoSize::class, @@ -303,6 +304,13 @@ class Message extends BaseType implements TypeInterface */ protected $authorSignature; + /** + * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption + * + * @var ArrayOfMessageEntity + */ + protected $captionEntities; + /** * @return string */ @@ -868,4 +876,20 @@ public function setAuthorSignature($authorSignature) { $this->authorSignature = $authorSignature; } + + /** + * @return ArrayOfMessageEntity + */ + public function getCaptionEntities() + { + return $this->captionEntities; + } + + /** + * @param ArrayOfMessageEntity $captionEntities + */ + public function setCaptionEntities($captionEntities) + { + $this->captionEntities = $captionEntities; + } } From 8ba284dbbf8643b68c5892b6f04d2438b79cccaa Mon Sep 17 00:00:00 2001 From: Yaroslav Molchan Date: Fri, 3 Nov 2017 18:03:45 +0200 Subject: [PATCH 002/130] Fix PSR-2 errors --- src/BotApi.php | 11 ++++------- src/Types/Message.php | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 92a7cd95..a34ffccf 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -486,8 +486,7 @@ public function sendLocation( $replyMarkup = null, $disableNotification = false, $livePeriod = null - ) - { + ) { return Message::fromResponse($this->call('sendLocation', [ 'chat_id' => $chatId, 'latitude' => $latitude, @@ -517,8 +516,7 @@ public function editMessageLiveLocation( $latitude, $longitude, $replyMarkup = null - ) - { + ) { return Message::fromResponse($this->call('sendLocation', [ 'chat_id' => $chatId, 'message_id' => $messageId, @@ -544,8 +542,7 @@ public function stopMessageLiveLocation( $messageId, $inlineMessageId, $replyMarkup = null - ) - { + ) { return Message::fromResponse($this->call('sendLocation', [ 'chat_id' => $chatId, 'message_id' => $messageId, @@ -1552,4 +1549,4 @@ public function getChatAdministrators($chatId) ) ); } -} \ No newline at end of file +} diff --git a/src/Types/Message.php b/src/Types/Message.php index 1b724daa..b496d53f 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -305,7 +305,8 @@ class Message extends BaseType implements TypeInterface protected $authorSignature; /** - * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption + * Optional. For messages with a caption, special entities like usernames, + * URLs, bot commands, etc. that appear in the caption * * @var ArrayOfMessageEntity */ From 6140a2350ca0a0be0489dcf933a903272d517f98 Mon Sep 17 00:00:00 2001 From: Yaroslav Molchan Date: Thu, 9 Nov 2017 12:11:16 +0200 Subject: [PATCH 003/130] Add getParameters method to HttpException --- src/BotApi.php | 3 ++- src/HttpException.php | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index a34ffccf..986391f2 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -262,7 +262,8 @@ public static function curlValidate($curl, $response = null) && !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE]) ) { $errorDescription = array_key_exists('description', $json) ? $json['description'] : self::$codes[$httpCode]; - throw new HttpException($errorDescription, $httpCode); + $errorParameters = array_key_exists('parameters', $json) ? $json['parameters'] : []; + throw new HttpException($errorDescription, $httpCode, null, $errorParameters); } } diff --git a/src/HttpException.php b/src/HttpException.php index 0b80890d..9eeed332 100644 --- a/src/HttpException.php +++ b/src/HttpException.php @@ -10,5 +10,31 @@ */ class HttpException extends Exception { + /** + * @var array + */ + protected $parameters = []; + /** + * HttpException constructor. + * + * @param string $message [optional] The Exception message to throw. + * @param int $code [optional] The Exception code. + * @param Exception $previous [optional] The previous throwable used for the exception chaining. + * @param array $parameters [optional] Array of parameters returned from API. + */ + public function __construct($message = '', $code = 0, Exception $previous = null, $parameters = []) + { + $this->parameters = $parameters; + + parent::__construct($message, $code, $previous); + } + + /** + * @return array + */ + public function getParameters() + { + return $this->parameters; + } } From 42cfb38a4bd9f3fd02c8e421924a85c1f26ad9b9 Mon Sep 17 00:00:00 2001 From: Amirhossein Matini Date: Thu, 28 Dec 2017 21:16:10 +0330 Subject: [PATCH 004/130] Adding deleteWebhook Method --- src/BotApi.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/BotApi.php b/src/BotApi.php index 986391f2..f7762efe 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -419,6 +419,19 @@ public function setWebhook($url = '', $certificate = null) { return $this->call('setWebhook', ['url' => $url, 'certificate' => $certificate]); } + + + /** + * Use this method to clear webhook and use getUpdates again! + * + * @return mixed + * + * @throws \TelegramBot\Api\Exception + */ + public function deleteWebhook() + { + return $this->call('deleteWebhook'); + } /** * A simple method for testing your bot's auth token.Requires no parameters. From e6ad40d41f741da5d6ee3f119537330d0be4e908 Mon Sep 17 00:00:00 2001 From: Amirhossein Matini Date: Fri, 29 Dec 2017 02:02:53 +0330 Subject: [PATCH 005/130] Create BotApiInterface --- src/BotApiInterface | 751 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 751 insertions(+) create mode 100644 src/BotApiInterface diff --git a/src/BotApiInterface b/src/BotApiInterface new file mode 100644 index 00000000..13e22036 --- /dev/null +++ b/src/BotApiInterface @@ -0,0 +1,751 @@ +/, + * where is taken from the response. + * It is guaranteed that the link will be valid for at least 1 hour. + * When the link expires, a new one can be requested by calling getFile again. + * + * @param $fileId + * + * @return \TelegramBot\Api\Types\File + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function getFile($fileId); + + /** + * Get file contents via cURL + * + * @param $fileId + * + * @return string + * + * @throws \TelegramBot\Api\HttpException + */ + public function downloadFile($fileId); + + /** + * Use this method to send answers to an inline query. On success, True is returned. + * No more than 50 results per query are allowed. + * + * @param string $inlineQueryId + * @param AbstractInlineQueryResult[] $results + * @param int $cacheTime + * @param bool $isPersonal + * @param string $nextOffset + * @param string $switchPmText + * @param string $switchPmParameter + * + * @return mixed + * @throws Exception + */ + public function answerInlineQuery($inlineQueryId, $results, $cacheTime = 300, $isPersonal = false, $nextOffset = '', $switchPmText = null, $switchPmParameter = null); + + /** + * Use this method to kick a user from a group or a supergroup. + * In the case of supergroups, the user will not be able to return to the group + * on their own using invite links, etc., unless unbanned first. + * The bot must be an administrator in the group for this to work. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target group + * or username of the target supergroup (in the format @supergroupusername) + * @param int $userId Unique identifier of the target user + * @param null|int $untilDate Date when the user will be unbanned, unix time. + * If user is banned for more than 366 days or less than 30 seconds from the current time + * they are considered to be banned forever + * + * @return bool + */ + public function kickChatMember($chatId, $userId, $untilDate = null); + + /** + * Use this method to unban a previously kicked user in a supergroup. + * The user will not return to the group automatically, but will be able to join via link, etc. + * The bot must be an administrator in the group for this to work. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target group + * or username of the target supergroup (in the format @supergroupusername) + * @param int $userId Unique identifier of the target user + * + * @return bool + */ + public function unbanChatMember($chatId, $userId); + + /** + * Use this method to send answers to callback queries sent from inline keyboards. + * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. + * + * @param $callbackQueryId + * @param null $text + * @param bool $showAlert + * + * @return bool + */ + public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false); + + /** + * Use this method to edit text messages sent by the bot or via the bot + * + * @param int|string $chatId + * @param int $messageId + * @param string $text + * @param string $inlineMessageId + * @param string|null $parseMode + * @param bool $disablePreview + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @return Message + */ + public function editMessageText($chatId, $messageId, $text, $parseMode = null, $disablePreview = false, $replyMarkup = null, $inlineMessageId = null); + + /** + * Use this method to edit text messages sent by the bot or via the bot + * + * @param int|string $chatId + * @param int $messageId + * @param string|null $caption + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param string $inlineMessageId + * + * @return \TelegramBot\Api\Types\Message + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function editMessageCaption($chatId, $messageId, $caption = null, $replyMarkup = null, $inlineMessageId = null); + + /** + * Use this method to edit only the reply markup of messages sent by the bot or via the bot + * + * @param int|string $chatId + * @param int $messageId + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param string $inlineMessageId + * + * @return Message + */ + public function editMessageReplyMarkup($chatId, $messageId, $replyMarkup = null, $inlineMessageId = null); + + /** + * Use this method to delete a message, including service messages, with the following limitations: + * - A message can only be deleted if it was sent less than 48 hours ago. + * - Bots can delete outgoing messages in groups and supergroups. + * - Bots granted can_post_messages permissions can delete outgoing messages in channels. + * - If the bot is an administrator of a group, it can delete any message there. + * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. + * + * @param int|string $chatId + * @param int $messageId + * + * @return bool + */ + public function deleteMessage($chatId, $messageId); + + /** + * @return string + */ + public function getUrl(); + + /** + * @return string + */ + public function getFileUrl(); + + /** + * @param \TelegramBot\Api\Types\Update $update + * @param string $eventName + * + * @throws \TelegramBot\Api\Exception + */ + public function trackUpdate(Update $update, $eventName = 'Message'); + + /** + * Wrapper for tracker + * + * @param \TelegramBot\Api\Types\Message $message + * @param string $eventName + * + * @throws \TelegramBot\Api\Exception + */ + public function track(Message $message, $eventName = 'Message'); + + /** + * Use this method to send invoices. On success, the sent Message is returned. + * + * @param int|string $chatId + * @param string $title + * @param string $description + * @param string $payload + * @param string $providerToken + * @param string $startParameter + * @param string $currency + * @param array $prices + * @param string|null $photoUrl + * @param int|null $photoSize + * @param int|null $photoWidth + * @param int|null $photoHeight + * @param bool $needName + * @param bool $needPhoneNumber + * @param bool $needEmail + * @param bool $needShippingAddress + * @param bool $isFlexible + * @param int|null $replyToMessageId + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param bool $disableNotification + * + * @return Message + */ + public function sendInvoice($chatId, $title, $description, $payload, $providerToken, $startParameter, $currency, $prices, $isFlexible = false, $photoUrl = null, $photoSize = null, $photoWidth = null, $photoHeight = null, $needName = false, $needPhoneNumber = false, $needEmail = false, $needShippingAddress = false, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false); + + /** + * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API + * will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. + * On success, True is returned. + * + * @param string $shippingQueryId + * @param bool $ok + * @param array $shipping_options + * @param null|string $errorMessage + * + * @return bool + * + */ + public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null); + + /** + * Use this method to respond to such pre-checkout queries. On success, True is returned. + * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. + * + * @param string $preCheckoutQueryId + * @param bool $ok + * @param null|string $errorMessage + * + * @return mixed + */ + public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null); + + /** + * Use this method to restrict a user in a supergroup. + * The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. + * Pass True for all boolean parameters to lift restrictions from a user. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup + * (in the format @supergroupusername) + * @param int $userId Unique identifier of the target user + * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time. + * If user is restricted for more than 366 days or less than 30 seconds from the current time, + * they are considered to be restricted forever + * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues + * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos, + * video notes and voice notes, implies can_send_messages + * @param bool $canSendOtherMessages Pass True, if the user can send animations, games, stickers and + * use inline bots, implies can_send_media_messages + * @param bool $canAddWebPagePreviews Pass True, if the user may add web page previews to their messages, + * implies can_send_media_messages + * + * @return bool + */ + public function restrictChatMember($chatId, $userId, $untilDate = null, $canSendMessages = false, $canSendMediaMessages = false, $canSendOtherMessages = false, $canAddWebPagePreviews = false); + + /** + * Use this method to promote or demote a user in a supergroup or a channel. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * Pass False for all boolean parameters to demote a user. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup + * (in the format @supergroupusername) + * @param int $userId Unique identifier of the target user + * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings + * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only + * @param bool $canEditMessages Pass True, if the administrator can edit messages of other users, channels only + * @param bool $canDeleteMessages Pass True, if the administrator can delete messages of other users + * @param bool $canInviteUsers Pass True, if the administrator can invite new users to the chat + * @param bool $canRestrictMembers Pass True, if the administrator can restrict, ban or unban chat members + * @param bool $canPinMessages Pass True, if the administrator can pin messages, supergroups only + * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his + * own privileges or demote administrators that he has promoted,directly or + * indirectly (promoted by administrators that were appointed by him) + * + * @return bool + */ + public function promoteChatMember($chatId, $userId, $canChangeInfo = true, $canPostMessages = true, $canEditMessages = true, $canDeleteMessages = true, $canInviteUsers = true, $canRestrictMembers = true, $canPinMessages = true, $canPromoteMembers = true); + + /** + * Use this method to export an invite link to a supergroup or a channel. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @return string + */ + public function exportChatInviteLink($chatId); + + /** + * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data + * + * @return bool + */ + public function setChatPhoto($chatId, $photo); + + /** + * Use this method to delete a chat photo. Photos can't be changed for private chats. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return bool + */ + public function deleteChatPhoto($chatId); + + /** + * Use this method to change the title of a chat. Titles can't be changed for private chats. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param string $title New chat title, 1-255 characters + * + * @return bool + */ + public function setChatTitle($chatId, $title); + + /** + * Use this method to change the description of a supergroup or a channel. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param string|null $description New chat description, 0-255 characters + * + * @return bool + */ + public function setChatDescription($chatId, $description = null); + + /** + * Use this method to pin a message in a supergroup. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param int $messageId Identifier of a message to pin + * @param bool $disableNotification + * + * @return bool + */ + public function pinChatMessage($chatId, $messageId, $disableNotification = false); + + /** + * Use this method to unpin a message in a supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return bool + */ + public function unpinChatMessage($chatId); + + /** + * Use this method to get up to date information about the chat + * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return Chat + */ + public function getChat($chatId); + + /** + * Use this method to get information about a member of a chat. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param int $userId + * + * @return ChatMember + */ + public function getChatMember($chatId, $userId); + + /** + * Use this method for your bot to leave a group, supergroup or channel. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return bool + */ + public function leaveChat($chatId); + + /** + * Use this method to get the number of members in a chat. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return int + */ + public function getChatMembersCount($chatId); + + /** + * Use this method to get a list of administrators in a chat. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return array + */ + public function getChatAdministrators($chatId); +} From caf8add680e69b87a0373f2a4b6898acb2a45c61 Mon Sep 17 00:00:00 2001 From: Amirhossein Matini Date: Fri, 29 Dec 2017 02:04:12 +0330 Subject: [PATCH 006/130] Delete BotApiInterface --- src/BotApiInterface | 751 -------------------------------------------- 1 file changed, 751 deletions(-) delete mode 100644 src/BotApiInterface diff --git a/src/BotApiInterface b/src/BotApiInterface deleted file mode 100644 index 13e22036..00000000 --- a/src/BotApiInterface +++ /dev/null @@ -1,751 +0,0 @@ -/, - * where is taken from the response. - * It is guaranteed that the link will be valid for at least 1 hour. - * When the link expires, a new one can be requested by calling getFile again. - * - * @param $fileId - * - * @return \TelegramBot\Api\Types\File - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception - */ - public function getFile($fileId); - - /** - * Get file contents via cURL - * - * @param $fileId - * - * @return string - * - * @throws \TelegramBot\Api\HttpException - */ - public function downloadFile($fileId); - - /** - * Use this method to send answers to an inline query. On success, True is returned. - * No more than 50 results per query are allowed. - * - * @param string $inlineQueryId - * @param AbstractInlineQueryResult[] $results - * @param int $cacheTime - * @param bool $isPersonal - * @param string $nextOffset - * @param string $switchPmText - * @param string $switchPmParameter - * - * @return mixed - * @throws Exception - */ - public function answerInlineQuery($inlineQueryId, $results, $cacheTime = 300, $isPersonal = false, $nextOffset = '', $switchPmText = null, $switchPmParameter = null); - - /** - * Use this method to kick a user from a group or a supergroup. - * In the case of supergroups, the user will not be able to return to the group - * on their own using invite links, etc., unless unbanned first. - * The bot must be an administrator in the group for this to work. Returns True on success. - * - * @param int|string $chatId Unique identifier for the target group - * or username of the target supergroup (in the format @supergroupusername) - * @param int $userId Unique identifier of the target user - * @param null|int $untilDate Date when the user will be unbanned, unix time. - * If user is banned for more than 366 days or less than 30 seconds from the current time - * they are considered to be banned forever - * - * @return bool - */ - public function kickChatMember($chatId, $userId, $untilDate = null); - - /** - * Use this method to unban a previously kicked user in a supergroup. - * The user will not return to the group automatically, but will be able to join via link, etc. - * The bot must be an administrator in the group for this to work. Returns True on success. - * - * @param int|string $chatId Unique identifier for the target group - * or username of the target supergroup (in the format @supergroupusername) - * @param int $userId Unique identifier of the target user - * - * @return bool - */ - public function unbanChatMember($chatId, $userId); - - /** - * Use this method to send answers to callback queries sent from inline keyboards. - * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. - * - * @param $callbackQueryId - * @param null $text - * @param bool $showAlert - * - * @return bool - */ - public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false); - - /** - * Use this method to edit text messages sent by the bot or via the bot - * - * @param int|string $chatId - * @param int $messageId - * @param string $text - * @param string $inlineMessageId - * @param string|null $parseMode - * @param bool $disablePreview - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @return Message - */ - public function editMessageText($chatId, $messageId, $text, $parseMode = null, $disablePreview = false, $replyMarkup = null, $inlineMessageId = null); - - /** - * Use this method to edit text messages sent by the bot or via the bot - * - * @param int|string $chatId - * @param int $messageId - * @param string|null $caption - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @param string $inlineMessageId - * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception - */ - public function editMessageCaption($chatId, $messageId, $caption = null, $replyMarkup = null, $inlineMessageId = null); - - /** - * Use this method to edit only the reply markup of messages sent by the bot or via the bot - * - * @param int|string $chatId - * @param int $messageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @param string $inlineMessageId - * - * @return Message - */ - public function editMessageReplyMarkup($chatId, $messageId, $replyMarkup = null, $inlineMessageId = null); - - /** - * Use this method to delete a message, including service messages, with the following limitations: - * - A message can only be deleted if it was sent less than 48 hours ago. - * - Bots can delete outgoing messages in groups and supergroups. - * - Bots granted can_post_messages permissions can delete outgoing messages in channels. - * - If the bot is an administrator of a group, it can delete any message there. - * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. - * - * @param int|string $chatId - * @param int $messageId - * - * @return bool - */ - public function deleteMessage($chatId, $messageId); - - /** - * @return string - */ - public function getUrl(); - - /** - * @return string - */ - public function getFileUrl(); - - /** - * @param \TelegramBot\Api\Types\Update $update - * @param string $eventName - * - * @throws \TelegramBot\Api\Exception - */ - public function trackUpdate(Update $update, $eventName = 'Message'); - - /** - * Wrapper for tracker - * - * @param \TelegramBot\Api\Types\Message $message - * @param string $eventName - * - * @throws \TelegramBot\Api\Exception - */ - public function track(Message $message, $eventName = 'Message'); - - /** - * Use this method to send invoices. On success, the sent Message is returned. - * - * @param int|string $chatId - * @param string $title - * @param string $description - * @param string $payload - * @param string $providerToken - * @param string $startParameter - * @param string $currency - * @param array $prices - * @param string|null $photoUrl - * @param int|null $photoSize - * @param int|null $photoWidth - * @param int|null $photoHeight - * @param bool $needName - * @param bool $needPhoneNumber - * @param bool $needEmail - * @param bool $needShippingAddress - * @param bool $isFlexible - * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @param bool $disableNotification - * - * @return Message - */ - public function sendInvoice($chatId, $title, $description, $payload, $providerToken, $startParameter, $currency, $prices, $isFlexible = false, $photoUrl = null, $photoSize = null, $photoWidth = null, $photoHeight = null, $needName = false, $needPhoneNumber = false, $needEmail = false, $needShippingAddress = false, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false); - - /** - * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API - * will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. - * On success, True is returned. - * - * @param string $shippingQueryId - * @param bool $ok - * @param array $shipping_options - * @param null|string $errorMessage - * - * @return bool - * - */ - public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null); - - /** - * Use this method to respond to such pre-checkout queries. On success, True is returned. - * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. - * - * @param string $preCheckoutQueryId - * @param bool $ok - * @param null|string $errorMessage - * - * @return mixed - */ - public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null); - - /** - * Use this method to restrict a user in a supergroup. - * The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. - * Pass True for all boolean parameters to lift restrictions from a user. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup - * (in the format @supergroupusername) - * @param int $userId Unique identifier of the target user - * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time. - * If user is restricted for more than 366 days or less than 30 seconds from the current time, - * they are considered to be restricted forever - * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues - * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos, - * video notes and voice notes, implies can_send_messages - * @param bool $canSendOtherMessages Pass True, if the user can send animations, games, stickers and - * use inline bots, implies can_send_media_messages - * @param bool $canAddWebPagePreviews Pass True, if the user may add web page previews to their messages, - * implies can_send_media_messages - * - * @return bool - */ - public function restrictChatMember($chatId, $userId, $untilDate = null, $canSendMessages = false, $canSendMediaMessages = false, $canSendOtherMessages = false, $canAddWebPagePreviews = false); - - /** - * Use this method to promote or demote a user in a supergroup or a channel. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * Pass False for all boolean parameters to demote a user. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup - * (in the format @supergroupusername) - * @param int $userId Unique identifier of the target user - * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings - * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only - * @param bool $canEditMessages Pass True, if the administrator can edit messages of other users, channels only - * @param bool $canDeleteMessages Pass True, if the administrator can delete messages of other users - * @param bool $canInviteUsers Pass True, if the administrator can invite new users to the chat - * @param bool $canRestrictMembers Pass True, if the administrator can restrict, ban or unban chat members - * @param bool $canPinMessages Pass True, if the administrator can pin messages, supergroups only - * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his - * own privileges or demote administrators that he has promoted,directly or - * indirectly (promoted by administrators that were appointed by him) - * - * @return bool - */ - public function promoteChatMember($chatId, $userId, $canChangeInfo = true, $canPostMessages = true, $canEditMessages = true, $canDeleteMessages = true, $canInviteUsers = true, $canRestrictMembers = true, $canPinMessages = true, $canPromoteMembers = true); - - /** - * Use this method to export an invite link to a supergroup or a channel. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * @return string - */ - public function exportChatInviteLink($chatId); - - /** - * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data - * - * @return bool - */ - public function setChatPhoto($chatId, $photo); - - /** - * Use this method to delete a chat photo. Photos can't be changed for private chats. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * - * @return bool - */ - public function deleteChatPhoto($chatId); - - /** - * Use this method to change the title of a chat. Titles can't be changed for private chats. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * @param string $title New chat title, 1-255 characters - * - * @return bool - */ - public function setChatTitle($chatId, $title); - - /** - * Use this method to change the description of a supergroup or a channel. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * @param string|null $description New chat description, 0-255 characters - * - * @return bool - */ - public function setChatDescription($chatId, $description = null); - - /** - * Use this method to pin a message in a supergroup. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * @param int $messageId Identifier of a message to pin - * @param bool $disableNotification - * - * @return bool - */ - public function pinChatMessage($chatId, $messageId, $disableNotification = false); - - /** - * Use this method to unpin a message in a supergroup chat. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * - * @return bool - */ - public function unpinChatMessage($chatId); - - /** - * Use this method to get up to date information about the chat - * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * - * @return Chat - */ - public function getChat($chatId); - - /** - * Use this method to get information about a member of a chat. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * @param int $userId - * - * @return ChatMember - */ - public function getChatMember($chatId, $userId); - - /** - * Use this method for your bot to leave a group, supergroup or channel. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * - * @return bool - */ - public function leaveChat($chatId); - - /** - * Use this method to get the number of members in a chat. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * - * @return int - */ - public function getChatMembersCount($chatId); - - /** - * Use this method to get a list of administrators in a chat. - * - * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) - * - * @return array - */ - public function getChatAdministrators($chatId); -} From c492d707fe080b603ad3fd8b9fd35c5e116c46bf Mon Sep 17 00:00:00 2001 From: Artyom Makarov Date: Fri, 26 Jan 2018 16:12:30 +0300 Subject: [PATCH 007/130] Add curl timeout 5 sec --- src/BotApi.php | 1 + src/Botan.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index 986391f2..7b61bb98 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -202,6 +202,7 @@ public function call($method, array $data = null) CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => null, CURLOPT_POSTFIELDS => null, + CURLOPT_TIMEOUT => 5, ]; if ($data) { diff --git a/src/Botan.php b/src/Botan.php index 1abb17fa..37d9c5f5 100644 --- a/src/Botan.php +++ b/src/Botan.php @@ -68,7 +68,8 @@ public function track(Message $message, $eventName = 'Message') CURLOPT_HTTPHEADER => [ 'Content-Type: application/json' ], - CURLOPT_POSTFIELDS => $message->toJson() + CURLOPT_POSTFIELDS => $message->toJson(), + CURLOPT_TIMEOUT => 5, ]; curl_setopt_array($this->curl, $options); From b2367e494ac84964746740ace1e96c225e9960bc Mon Sep 17 00:00:00 2001 From: kubk Date: Mon, 12 Feb 2018 23:42:48 +0300 Subject: [PATCH 008/130] Check ext-curl --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 80fb1384..086cc4e3 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ } ], "require": { - "php" : ">=5.5.0" + "php" : ">=5.5.0", + "ext-curl": "*" }, "require-dev": { "phpunit/phpunit" : "~4.0", From ff30ae124d1625debebfcaa39d0f5e883ba7f5c1 Mon Sep 17 00:00:00 2001 From: Yaroslav Molchan Date: Thu, 15 Mar 2018 20:02:54 +0200 Subject: [PATCH 009/130] Add new features from Bot API 3.5-3.6. Add some missed methods. --- src/BotApi.php | 153 ++++++++++++++++++--- src/Collection/Collection.php | 111 +++++++++++++++ src/Collection/CollectionItemInterface.php | 8 ++ src/Collection/KeyHasUseException.php | 16 +++ src/Collection/KeyInvalidException.php | 16 +++ src/Collection/ReachedMaxSizeException.php | 16 +++ src/Types/ArrayOfMessages.php | 16 +++ src/Types/InputMedia/ArrayOfInputMedia.php | 15 ++ src/Types/InputMedia/InputMedia.php | 129 +++++++++++++++++ src/Types/InputMedia/InputMediaPhoto.php | 27 ++++ src/Types/InputMedia/InputMediaVideo.php | 150 ++++++++++++++++++++ src/Types/Message.php | 26 +++- src/Types/ReplyKeyboardRemove.php | 88 ++++++++++++ tests/Collection/CollectionTest.php | 90 ++++++++++++ 14 files changed, 838 insertions(+), 23 deletions(-) create mode 100644 src/Collection/Collection.php create mode 100644 src/Collection/CollectionItemInterface.php create mode 100644 src/Collection/KeyHasUseException.php create mode 100644 src/Collection/KeyInvalidException.php create mode 100644 src/Collection/ReachedMaxSizeException.php create mode 100644 src/Types/ArrayOfMessages.php create mode 100644 src/Types/InputMedia/ArrayOfInputMedia.php create mode 100644 src/Types/InputMedia/InputMedia.php create mode 100644 src/Types/InputMedia/InputMediaPhoto.php create mode 100644 src/Types/InputMedia/InputMediaVideo.php create mode 100644 src/Types/ReplyKeyboardRemove.php create mode 100644 tests/Collection/CollectionTest.php diff --git a/src/BotApi.php b/src/BotApi.php index 986391f2..969fd60f 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -2,11 +2,13 @@ namespace TelegramBot\Api; +use TelegramBot\Api\Types\ArrayOfMessages; use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\Chat; use TelegramBot\Api\Types\ChatMember; use TelegramBot\Api\Types\File; use TelegramBot\Api\Types\Inline\QueryResult\AbstractInlineQueryResult; +use TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\User; @@ -295,7 +297,8 @@ public static function jsonValidate($jsonString, $asArray) * @param string|null $parseMode * @param bool $disablePreview * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * * @return \TelegramBot\Api\Types\Message @@ -330,7 +333,8 @@ public function sendMessage( * @param string $firstName * @param string $lastName * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * * @return \TelegramBot\Api\Types\Message @@ -473,7 +477,8 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) * @param float $latitude * @param float $longitude * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * * @param null|int $livePeriod @@ -507,7 +512,8 @@ public function sendLocation( * @param string $inlineMessageId * @param float $latitude * @param float $longitude - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @return \TelegramBot\Api\Types\Message */ public function editMessageLiveLocation( @@ -535,7 +541,8 @@ public function editMessageLiveLocation( * @param int|string $chatId * @param int $messageId * @param string $inlineMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @return \TelegramBot\Api\Types\Message */ public function stopMessageLiveLocation( @@ -562,7 +569,8 @@ public function stopMessageLiveLocation( * @param string $address * @param string|null $foursquareId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * * @return \TelegramBot\Api\Types\Message @@ -598,7 +606,8 @@ public function sendVenue( * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $sticker * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * * @return \TelegramBot\Api\Types\Message @@ -631,8 +640,11 @@ public function sendSticker( * @param int|null $duration * @param string|null $caption * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param bool $supportsStreaming Pass True, if the uploaded video is suitable for streaming + * @param string|null $parseMode * * @return \TelegramBot\Api\Types\Message * @throws \TelegramBot\Api\InvalidArgumentException @@ -645,7 +657,9 @@ public function sendVideo( $caption = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $supportsStreaming = false, + $parseMode = null ) { return Message::fromResponse($this->call('sendVideo', [ 'chat_id' => $chatId, @@ -655,6 +669,8 @@ public function sendVideo( 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, + 'supports_streaming' => (bool)$supportsStreaming, + 'parse_mode' => $parseMode ])); } @@ -670,8 +686,10 @@ public function sendVideo( * @param \CURLFile|string $voice * @param int|null $duration * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param string|null $parseMode * * @return \TelegramBot\Api\Types\Message * @throws \TelegramBot\Api\InvalidArgumentException @@ -683,7 +701,8 @@ public function sendVoice( $duration = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $parseMode = null ) { return Message::fromResponse($this->call('sendVoice', [ 'chat_id' => $chatId, @@ -692,6 +711,7 @@ public function sendVoice( 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, + 'parse_mode' => $parseMode ])); } @@ -739,8 +759,10 @@ public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotific * @param string|null $performer * @param string|null $title * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param string|null $parseMode * * @return \TelegramBot\Api\Types\Message * @throws \TelegramBot\Api\InvalidArgumentException @@ -754,7 +776,8 @@ public function sendAudio( $title = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $parseMode = null ) { return Message::fromResponse($this->call('sendAudio', [ 'chat_id' => $chatId, @@ -765,6 +788,7 @@ public function sendAudio( 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, + 'parse_mode' => $parseMode ])); } @@ -775,8 +799,10 @@ public function sendAudio( * @param \CURLFile|string $photo * @param string|null $caption * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param string|null $parseMode * * @return \TelegramBot\Api\Types\Message * @throws \TelegramBot\Api\InvalidArgumentException @@ -788,7 +814,8 @@ public function sendPhoto( $caption = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $parseMode = null ) { return Message::fromResponse($this->call('sendPhoto', [ 'chat_id' => $chatId, @@ -797,6 +824,7 @@ public function sendPhoto( 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, + 'parse_mode' => $parseMode ])); } @@ -808,8 +836,10 @@ public function sendPhoto( * @param \CURLFile|string $document * @param string|null $caption * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param string|null $parseMode * * @return \TelegramBot\Api\Types\Message * @throws \TelegramBot\Api\InvalidArgumentException @@ -821,7 +851,8 @@ public function sendDocument( $caption = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $parseMode = null ) { return Message::fromResponse($this->call('sendDocument', [ 'chat_id' => $chatId, @@ -830,6 +861,7 @@ public function sendDocument( 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, + 'parse_mode' => $parseMode ])); } @@ -987,7 +1019,8 @@ public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = * @param string $inlineMessageId * @param string|null $parseMode * @param bool $disablePreview - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @return Message */ public function editMessageText( @@ -1016,7 +1049,8 @@ public function editMessageText( * @param int|string $chatId * @param int $messageId * @param string|null $caption - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param string $inlineMessageId * * @return \TelegramBot\Api\Types\Message @@ -1044,7 +1078,8 @@ public function editMessageCaption( * * @param int|string $chatId * @param int $messageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param string $inlineMessageId * * @return Message @@ -1163,8 +1198,12 @@ public function track(Message $message, $eventName = 'Message') * @param bool $needShippingAddress * @param bool $isFlexible * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param string|null $providerData + * @param bool $sendPhoneNumberToProvider + * @param bool $sendEmailToProvider * * @return Message */ @@ -1188,7 +1227,10 @@ public function sendInvoice( $needShippingAddress = false, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $providerData = null, + $sendPhoneNumberToProvider = false, + $sendEmailToProvider = false ) { return Message::fromResponse($this->call('sendInvoice', [ 'chat_id' => $chatId, @@ -1211,6 +1253,9 @@ public function sendInvoice( 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, + 'provider_data' => $providerData, + 'send_phone_number_to_provider' => (bool)$sendPhoneNumberToProvider, + 'send_email_to_provider' => (bool)$sendEmailToProvider ])); } @@ -1550,4 +1595,68 @@ public function getChatAdministrators($chatId) ) ); } + + /** + * As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. + * Use this method to send video messages. + * On success, the sent Message is returned. + * + * @param int|string $chatId chat_id or @channel_name + * @param \CURLFile|string $videoNote + * @param int|null $duration + * @param int|null $length + * @param int|null $replyToMessageId + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup + * @param bool $disableNotification + * + * @return \TelegramBot\Api\Types\Message + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function sendVideoNote( + $chatId, + $videoNote, + $duration = null, + $length = null, + $replyToMessageId = null, + $replyMarkup = null, + $disableNotification = false + ) { + return Message::fromResponse($this->call('sendVideoNote', [ + 'chat_id' => $chatId, + 'video_note' => $videoNote, + 'duration' => $duration, + 'length' => $length, + 'reply_to_message_id' => $replyToMessageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'disable_notification' => (bool)$disableNotification + ])); + } + + /** + * Use this method to send a group of photos or videos as an album. + * On success, the sent \TelegramBot\Api\Types\Message is returned. + * + * @param int|string $chatId + * @param ArrayOfInputMedia $media + * @param int|null $replyToMessageId + * @param bool $disableNotification + * + * @return array + * @throws \TelegramBot\Api\Exception + */ + public function sendMediaGroup( + $chatId, + $media, + $disableNotification = false, + $replyToMessageId = null + ) { + return ArrayOfMessages::fromResponse($this->call('sendMediaGroup', [ + 'chat_id' => $chatId, + 'media' => $media->toJson(), + 'reply_to_message_id' => (int)$replyToMessageId, + 'disable_notification' => (bool)$disableNotification + ])); + } } diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php new file mode 100644 index 00000000..8b5b7dfe --- /dev/null +++ b/src/Collection/Collection.php @@ -0,0 +1,111 @@ +maxCount > 0 && $this->count() + 1 >= $this->maxCount) { + throw new ReachedMaxSizeException("Maximum collection items count reached. Max size: {$this->maxCount}"); + } + + if ($key == null) { + $this->items[] = $item; + } else { + if (isset($this->items[$key])) { + throw new KeyHasUseException("Key $key already in use."); + } + $this->items[$key] = $item; + } + } + + /** + * @param $key + * @throws KeyInvalidException + * @return void + */ + public function deleteItem($key) + { + $this->checkItemKey($key); + + unset($this->items[$key]); + } + + /** + * @param $key + * @return InputMedia + * @return CollectionItemInterface + * @throws KeyInvalidException + */ + public function getItem($key) + { + $this->checkItemKey($key); + + return $this->items[$key]; + } + + /** + * @return int + */ + public function count() + { + return count($this->items); + } + + /** + * @param bool $inner + * @return array|string + */ + public function toJson($inner = false) + { + $output = []; + foreach ($this->items as $item) { + $output[] = $item->toJson(true); + } + + return $inner === false ? json_encode($output) : $output; + } + + /** + * @param int $maxCount + * @return void + */ + public function setMaxCount($maxCount) + { + $this->maxCount = $maxCount; + } + + /** + * @param $key + * @throws KeyInvalidException + */ + private function checkItemKey($key) + { + if (!isset($this->items[$key])) { + throw new KeyInvalidException("Invalid key $key."); + } + } +} diff --git a/src/Collection/CollectionItemInterface.php b/src/Collection/CollectionItemInterface.php new file mode 100644 index 00000000..1bdf2dc5 --- /dev/null +++ b/src/Collection/CollectionItemInterface.php @@ -0,0 +1,8 @@ + true, + 'media' => true, + 'caption' => true, + 'parse_mode' => true, + ]; + + /** + * Type of the result. + * + * @var string + */ + protected $type; + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), + * pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" + * to upload a new one using multipart/form-data under name. + * + * @var string + */ + protected $media; + + /** + * Optional. Caption of the photo to be sent, 0-200 characters. + * + * @var string + */ + protected $caption; + + /** + * Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, + * fixed-width text or inline URLs in the media caption. + * + * @var string + */ + protected $parseMode; + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia() + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia($media) + { + $this->media = $media; + } + + /** + * @return string + */ + public function getCaption() + { + return $this->caption; + } + + /** + * @param string $caption + */ + public function setCaption($caption) + { + $this->caption = $caption; + } + + /** + * @return string + */ + public function getParseMode() + { + return $this->parseMode; + } + + /** + * @param string $parseMode + */ + public function setParseMode($parseMode) + { + $this->parseMode = $parseMode; + } +} diff --git a/src/Types/InputMedia/InputMediaPhoto.php b/src/Types/InputMedia/InputMediaPhoto.php new file mode 100644 index 00000000..98e06a22 --- /dev/null +++ b/src/Types/InputMedia/InputMediaPhoto.php @@ -0,0 +1,27 @@ +type = 'photo'; + $this->media = $media; + $this->caption = $caption; + $this->parseMode = $parseMode; + } +} diff --git a/src/Types/InputMedia/InputMediaVideo.php b/src/Types/InputMedia/InputMediaVideo.php new file mode 100644 index 00000000..6875474a --- /dev/null +++ b/src/Types/InputMedia/InputMediaVideo.php @@ -0,0 +1,150 @@ + true, + 'media' => true, + 'caption' => true, + 'parse_mode' => true, + 'width' => true, + 'height' => true, + 'duration' => true, + 'supports_streaming' => true + ]; + + /** + * Optional. Video width. + * + * @var string + */ + protected $width; + + /** + * Optional. Video height. + * + * @var string + */ + protected $height; + + /** + * Optional. Video duration. + * + * @var string + */ + protected $duration; + + /** + * Optional. Pass True, if the uploaded video is suitable for streaming. + * + * @var bool + */ + protected $supportsStreaming; + + /** + * InputMediaVideo constructor. + * + * @param string $media + * @param null $caption + * @param null $parseMode + * @param null $width + * @param null $height + * @param null $duration + * @param bool $supportsStreaming + */ + public function __construct( + $media, + $caption = null, + $parseMode = null, + $width = null, + $height = null, + $duration = null, + $supportsStreaming = false + ) { + $this->type = 'video'; + $this->media = $media; + $this->caption = $caption; + $this->parseMode = $parseMode; + $this->width = $width; + $this->height = $height; + $this->duration = $duration; + $this->supportsStreaming = $supportsStreaming; + } + + /** + * @return string + */ + public function getWidth() + { + return $this->width; + } + + /** + * @param string $width + */ + public function setWidth($width) + { + $this->width = $width; + } + + /** + * @return string + */ + public function getHeight() + { + return $this->height; + } + + /** + * @param string $height + */ + public function setHeight($height) + { + $this->height = $height; + } + + /** + * @return string + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param string $duration + */ + public function setDuration($duration) + { + $this->duration = $duration; + } + + /** + * @return bool + */ + public function getSupportsStreaming() + { + return $this->supportsStreaming; + } + + /** + * @param bool $supportsStreaming + */ + public function setSupportsStreaming($supportsStreaming) + { + $this->supportsStreaming = $supportsStreaming; + } +} diff --git a/src/Types/Message.php b/src/Types/Message.php index b496d53f..a9fe2a7a 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -56,7 +56,8 @@ class Message extends BaseType implements TypeInterface 'invoice' => Invoice::class, 'successful_payment' => SuccessfulPayment::class, 'forward_signature' => true, - 'author_signature' => true + 'author_signature' => true, + 'connected_website' => true ]; /** @@ -312,6 +313,13 @@ class Message extends BaseType implements TypeInterface */ protected $captionEntities; + /** + * Optional. The domain name of the website on which the user has logged in. + * + * @var string + */ + protected $connectedWebsite; + /** * @return string */ @@ -893,4 +901,20 @@ public function setCaptionEntities($captionEntities) { $this->captionEntities = $captionEntities; } + + /** + * @return string + */ + public function getConnectedWebsite() + { + return $this->connectedWebsite; + } + + /** + * @param string $connectedWebsite + */ + public function setConnectedWebsite($connectedWebsite) + { + $this->connectedWebsite = $connectedWebsite; + } } diff --git a/src/Types/ReplyKeyboardRemove.php b/src/Types/ReplyKeyboardRemove.php new file mode 100644 index 00000000..891ee90d --- /dev/null +++ b/src/Types/ReplyKeyboardRemove.php @@ -0,0 +1,88 @@ + true, + 'selective' => true + ]; + + /** + * Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; + * if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup) + * + * @var bool + */ + protected $remove_keyboard; + + /** + * Optional. Use this parameter if you want to remove the keyboard for specific users only. + * Targets: + * 1) users that are @mentioned in the text of the Message object; + * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + * + * @var bool + */ + protected $selective; + + public function __construct($remove_keyboard = true, $selective = false) + { + $this->remove_keyboard = $remove_keyboard; + $this->selective = $selective; + } + + /** + * @return bool + */ + public function getRemoveKeyboard() + { + return $this->remove_keyboard; + } + + /** + * @param bool $remove_keyboard + */ + public function setRemoveKeyboard($remove_keyboard) + { + $this->remove_keyboard = $remove_keyboard; + } + + /** + * @return bool + */ + public function getSelective() + { + return $this->selective; + } + + /** + * @param bool $selective + */ + public function setSelective($selective) + { + $this->selective = $selective; + } +} diff --git a/tests/Collection/CollectionTest.php b/tests/Collection/CollectionTest.php new file mode 100644 index 00000000..a63a262d --- /dev/null +++ b/tests/Collection/CollectionTest.php @@ -0,0 +1,90 @@ + 'photo', + 'media' => 'link' + ] + ]; + + /** @test */ + public function can_add_item() + { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link')); + + $this->assertSame(1, $media->count()); + } + + /** @test */ + public function can_add_item_with_key() + { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link'), 'key'); + + $this->assertSame(1, $media->count()); + } + + /** @test */ + public function can_get_item() + { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link'), 'key'); + + $this->assertInstanceOf(CollectionItemInterface::class, $media->getItem('key')); + } + + /** @test */ + public function can_delete_item() + { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link'), 'key'); + $media->deleteItem('key'); + + $this->assertSame(0, $media->count()); + } + + /** @test */ + public function check_count() { + $media = new ArrayOfInputMedia(); + for ($i = 0; $i < 5; $i++) { + $media->addItem(new InputMediaPhoto('link')); + } + $this->assertSame(5, $media->count()); + } + + /** @test */ + public function can_not_add_more_then_max_limit() { + $this->setExpectedException(ReachedMaxSizeException::class); + $media = new ArrayOfInputMedia(); + $media->setMaxCount(2); + for ($i = 1; $i < 3; $i++) { + $media->addItem(new InputMediaPhoto('link')); + } + } + + /** @test */ + public function can_output_items_as_array() { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link')); + + $this->assertSame($this->itemsOutput, $media->toJson(true)); + } + + /** @test */ + public function can_output_items_as_json() { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link')); + + $this->assertSame(json_encode($this->itemsOutput), $media->toJson()); + } +} From 7ceb6f8a23707cb5e93c5efa284c754be5aab982 Mon Sep 17 00:00:00 2001 From: Yaroslav Molchan Date: Fri, 16 Mar 2018 16:14:53 +0200 Subject: [PATCH 010/130] Update readme --- README.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a899d45b..0b7f65a1 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,14 @@ $ composer require telegram-bot/api See example [DevAnswerBot](https://github.com/TelegramBot/DevAnswerBot) (russian). -#### API Wrapper +### API Wrapper +#### Send message ``` php $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); $bot->sendMessage($chatId, $messageText); ``` - +#### Send document ```php $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); @@ -43,7 +44,7 @@ $document = new \CURLFile('document.txt'); $bot->sendDocument($chatId, $document); ``` - +#### Send message with reply keyboard ```php $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); @@ -51,7 +52,7 @@ $keyboard = new \TelegramBot\Api\Types\ReplyKeyboardMarkup(array(array("one", "t $bot->sendMessage($chatId, $messageText, null, false, null, $keyboard); ``` - +#### Send message with inline keyboard ```php $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); @@ -65,6 +66,17 @@ $keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup( $bot->sendMessage($chatId, $messageText, null, false, null, $keyboard); ``` +#### Send media group +```php +$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); + +$media = new \TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia(); +$media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaPhoto('https://avatars3.githubusercontent.com/u/9335727')); +$media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaPhoto('https://avatars3.githubusercontent.com/u/9335727')); +// Same for video +// $media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaVideo('http://clips.vorwaerts-gmbh.de/VfE_html5.mp4')); +$bot->sendMediaGroup($chatId, $media); +``` #### Client @@ -88,7 +100,7 @@ try { } ``` -### Botan SDK +### Botan SDK (not supported more) [Botan](http://botan.io) is a telegram bot analytics system based on [Yandex.Appmetrica](http://appmetrica.yandex.com/). In this document you can find how to setup Yandex.Appmetrica account, as well as examples of Botan SDK usage. From 82c4ad473b0386a015a66018313f437a1cfefaeb Mon Sep 17 00:00:00 2001 From: Alexey Lopatin Date: Fri, 13 Apr 2018 17:54:52 +0700 Subject: [PATCH 011/130] Added ability to setup proxy for requests to Telegram API --- src/BotApi.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 026d5480..53727250 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -93,6 +93,10 @@ class BotApi 511 => 'Network Authentication Required', // RFC6585 ]; + private $proxySettings = [ + CURLOPT_PROXY => '', + CURLOPT_HTTPPROXYTUNNEL => false, + ]; /** * Default http status code @@ -154,14 +158,16 @@ class BotApi */ protected $returnArray = true; - /** * Constructor * - * @param string $token Telegram Bot API token + * @param string $token Telegram Bot API token * @param string|null $trackerToken Yandex AppMetrica application api_key + * @param array $proxySettings + * + * @throws \Exception */ - public function __construct($token, $trackerToken = null) + public function __construct($token, $trackerToken = null, $proxySettings = []) { $this->curl = curl_init(); $this->token = $token; @@ -169,6 +175,12 @@ public function __construct($token, $trackerToken = null) if ($trackerToken) { $this->tracker = new Botan($trackerToken); } + + foreach ($proxySettings as $key => $value) { + if (isset($this->proxySettings[$key])) { + $this->proxySettings[$key] = $value; + } + } } /** @@ -199,13 +211,13 @@ public function setModeObject($mode = true) */ public function call($method, array $data = null) { - $options = [ + $options = array_merge([ CURLOPT_URL => $this->getUrl().'/'.$method, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => null, CURLOPT_POSTFIELDS => null, CURLOPT_TIMEOUT => 5, - ]; + ], $this->proxySettings); if ($data) { $options[CURLOPT_POST] = true; From 25b9e83cd154e175342e4de3c53d7d8a3b386244 Mon Sep 17 00:00:00 2001 From: Alexey Lopatin Date: Fri, 13 Apr 2018 18:10:55 +0700 Subject: [PATCH 012/130] Rework proxy settings --- src/BotApi.php | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 53727250..83ca0b61 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -161,13 +161,12 @@ class BotApi /** * Constructor * - * @param string $token Telegram Bot API token + * @param string $token Telegram Bot API token * @param string|null $trackerToken Yandex AppMetrica application api_key - * @param array $proxySettings * * @throws \Exception */ - public function __construct($token, $trackerToken = null, $proxySettings = []) + public function __construct($token, $trackerToken = null) { $this->curl = curl_init(); $this->token = $token; @@ -175,12 +174,6 @@ public function __construct($token, $trackerToken = null, $proxySettings = []) if ($trackerToken) { $this->tracker = new Botan($trackerToken); } - - foreach ($proxySettings as $key => $value) { - if (isset($this->proxySettings[$key])) { - $this->proxySettings[$key] = $value; - } - } } /** @@ -211,13 +204,13 @@ public function setModeObject($mode = true) */ public function call($method, array $data = null) { - $options = array_merge([ + $options = $this->proxySettings + [ CURLOPT_URL => $this->getUrl().'/'.$method, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => null, CURLOPT_POSTFIELDS => null, CURLOPT_TIMEOUT => 5, - ], $this->proxySettings); + ]; if ($data) { $options[CURLOPT_POST] = true; @@ -1672,4 +1665,25 @@ public function sendMediaGroup( 'disable_notification' => (bool)$disableNotification ])); } + + /** + * Enable proxy for curl requests. Empty string will disable proxy. + * @param string $proxyString + */ + public function setProxy($proxyString = '') + { + if (empty($proxyString)) { + $this->proxySettings = [ + CURLOPT_PROXY => '', + CURLOPT_HTTPPROXYTUNNEL => false, + ]; + return; + } + + $this->proxySettings = [ + CURLOPT_PROXY => $proxyString, + CURLOPT_HTTPPROXYTUNNEL => true, + ]; + return; + } } From 99339eec9a71829c2213eccbe860364a1a846892 Mon Sep 17 00:00:00 2001 From: Alexey Lopatin Date: Fri, 13 Apr 2018 18:16:41 +0700 Subject: [PATCH 013/130] Rework proxy settings --- src/BotApi.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 83ca0b61..e67e4323 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -93,10 +93,7 @@ class BotApi 511 => 'Network Authentication Required', // RFC6585 ]; - private $proxySettings = [ - CURLOPT_PROXY => '', - CURLOPT_HTTPPROXYTUNNEL => false, - ]; + private $proxySettings = []; /** * Default http status code @@ -1668,22 +1665,22 @@ public function sendMediaGroup( /** * Enable proxy for curl requests. Empty string will disable proxy. + * * @param string $proxyString + * + * @return BotApi */ public function setProxy($proxyString = '') { if (empty($proxyString)) { - $this->proxySettings = [ - CURLOPT_PROXY => '', - CURLOPT_HTTPPROXYTUNNEL => false, - ]; - return; + $this->proxySettings = []; + return $this; } $this->proxySettings = [ CURLOPT_PROXY => $proxyString, CURLOPT_HTTPPROXYTUNNEL => true, ]; - return; + return $this; } } From fedb2ed832f8659d863fcf3155aa74710c8306de Mon Sep 17 00:00:00 2001 From: Alexey Lopatin Date: Fri, 13 Apr 2018 18:19:15 +0700 Subject: [PATCH 014/130] Remove redundant docs --- src/BotApi.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index e67e4323..da74677a 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -160,8 +160,6 @@ class BotApi * * @param string $token Telegram Bot API token * @param string|null $trackerToken Yandex AppMetrica application api_key - * - * @throws \Exception */ public function __construct($token, $trackerToken = null) { @@ -1341,6 +1339,7 @@ public function restrictChatMember( 'can_send_messages' => $canSendMessages, 'can_send_media_messages' => $canSendMediaMessages, 'can_send_other_messages' => $canSendOtherMessages, + 'can_add_web_page_previews' => $canAddWebPagePreviews ]); } From f7cef01df680b096106378fb9d77c8ffa98508e6 Mon Sep 17 00:00:00 2001 From: Alexey Lopatin Date: Fri, 13 Apr 2018 18:25:58 +0700 Subject: [PATCH 015/130] Remove redundant empty string --- src/BotApi.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index da74677a..9ade7f56 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1339,7 +1339,6 @@ public function restrictChatMember( 'can_send_messages' => $canSendMessages, 'can_send_media_messages' => $canSendMediaMessages, 'can_send_other_messages' => $canSendOtherMessages, - 'can_add_web_page_previews' => $canAddWebPagePreviews ]); } From 5e41463af61bf657c090d207ea6468569f63f445 Mon Sep 17 00:00:00 2001 From: Dmitry Emelyanov Date: Tue, 17 Apr 2018 19:33:36 +0300 Subject: [PATCH 016/130] Add support for set custom CURL options --- src/BotApi.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/BotApi.php b/src/BotApi.php index 9ade7f56..5ea24e14 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -127,6 +127,13 @@ class BotApi */ protected $curl; + /** + * CURL custom options + * + * @var array + */ + protected $customCurlOptions = []; + /** * Bot token * @@ -212,6 +219,10 @@ public function call($method, array $data = null) $options[CURLOPT_POSTFIELDS] = $data; } + if (!empty($this->customCurlOptions) && is_array($this->customCurlOptions)) { + $options += $this->customCurlOptions; + } + $response = self::jsonValidate($this->executeCurl($options), $this->returnArray); if ($this->returnArray) { @@ -1681,4 +1692,33 @@ public function setProxy($proxyString = '') ]; return $this; } + + /** + * Set an option for a cURL transfer + * + * @param int $option The CURLOPT_XXX option to set + * @param mixed $value The value to be set on option + */ + public function setCurlOption($option, $value) + { + $this->customCurlOptions[$option] = $value; + } + + /** + * Unset an option for a cURL transfer + * + * @param int $option The CURLOPT_XXX option to unset + */ + public function unsetCurlOption($option) + { + unset($this->customCurlOptions[$option]); + } + + /** + * Clean custom options + */ + public function resetCurlOptions() + { + $this->customCurlOptions = []; + } } From 61e185420616dfd68a7b1904f91d6911cfcde444 Mon Sep 17 00:00:00 2001 From: 7eodorus <38510234+7eodorus@users.noreply.github.com> Date: Fri, 20 Apr 2018 16:16:32 +0300 Subject: [PATCH 017/130] func getChatAdministrators use wrong api method need to use method https://core.telegram.org/bots/api#getchatadministrators --- src/BotApi.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index 9ade7f56..f1677b28 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -2,6 +2,7 @@ namespace TelegramBot\Api; +use TelegramBot\Api\Types\ArrayOfChatMemberEntity; use TelegramBot\Api\Types\ArrayOfMessages; use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\Chat; @@ -1589,7 +1590,7 @@ public function getChatAdministrators($chatId) { return ArrayOfChatMemberEntity::fromResponse( $this->call( - 'getChatMembersCount', + 'getChatAdministrators', [ 'chat_id' => $chatId ] From 8d34f3ccd3230a9fd7c7fd9ba8ec0110a059f781 Mon Sep 17 00:00:00 2001 From: Yaroslav Molchan Date: Mon, 30 Apr 2018 14:46:15 +0300 Subject: [PATCH 018/130] Fix bug with ReplyKeyboardRemove. --- src/Types/ReplyKeyboardRemove.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Types/ReplyKeyboardRemove.php b/src/Types/ReplyKeyboardRemove.php index 891ee90d..bc092227 100644 --- a/src/Types/ReplyKeyboardRemove.php +++ b/src/Types/ReplyKeyboardRemove.php @@ -36,7 +36,7 @@ class ReplyKeyboardRemove extends BaseType * * @var bool */ - protected $remove_keyboard; + protected $removeKeyboard; /** * Optional. Use this parameter if you want to remove the keyboard for specific users only. @@ -50,7 +50,7 @@ class ReplyKeyboardRemove extends BaseType public function __construct($remove_keyboard = true, $selective = false) { - $this->remove_keyboard = $remove_keyboard; + $this->removeKeyboard = $remove_keyboard; $this->selective = $selective; } @@ -59,7 +59,7 @@ public function __construct($remove_keyboard = true, $selective = false) */ public function getRemoveKeyboard() { - return $this->remove_keyboard; + return $this->removeKeyboard; } /** @@ -67,7 +67,7 @@ public function getRemoveKeyboard() */ public function setRemoveKeyboard($remove_keyboard) { - $this->remove_keyboard = $remove_keyboard; + $this->removeKeyboard = $remove_keyboard; } /** From 81e4d76e9af2097d92d3ed2fc3d27c2f21caf9c1 Mon Sep 17 00:00:00 2001 From: imDev Date: Mon, 4 Mar 2019 10:52:57 +0300 Subject: [PATCH 019/130] Fix #150 --- src/BotApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index b522df9e..4a40285d 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -221,7 +221,7 @@ public function call($method, array $data = null) } if (!empty($this->customCurlOptions) && is_array($this->customCurlOptions)) { - $options += $this->customCurlOptions; + $options = $this->customCurlOptions + $options; } $response = self::jsonValidate($this->executeCurl($options), $this->returnArray); From d6512863a715182f7f24a7775677b8c3f5a70e2b Mon Sep 17 00:00:00 2001 From: Petr Flaks Date: Wed, 1 May 2019 22:55:01 +0300 Subject: [PATCH 020/130] Add parseMode parameter to editMessageCaption method --- src/BotApi.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index b522df9e..1eadc7a7 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1065,6 +1065,7 @@ public function editMessageText( * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| * Types\ReplyKeyboardRemove|null $replyMarkup * @param string $inlineMessageId + * @param string|null $parseMode * * @return \TelegramBot\Api\Types\Message * @throws \TelegramBot\Api\InvalidArgumentException @@ -1075,7 +1076,8 @@ public function editMessageCaption( $messageId, $caption = null, $replyMarkup = null, - $inlineMessageId = null + $inlineMessageId = null, + $parseMode = null ) { return Message::fromResponse($this->call('editMessageCaption', [ 'chat_id' => $chatId, @@ -1083,6 +1085,7 @@ public function editMessageCaption( 'inline_message_id' => $inlineMessageId, 'caption' => $caption, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'parse_mode' => $parseMode ])); } From 100ed9f9ee762c4d89bd96f3c06aae5100f3b065 Mon Sep 17 00:00:00 2001 From: WebPajooh Date: Wed, 3 Jul 2019 13:51:59 +0430 Subject: [PATCH 021/130] Add animation properties and methods --- src/Types/Message.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Types/Message.php b/src/Types/Message.php index a9fe2a7a..a879242d 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -37,6 +37,7 @@ class Message extends BaseType implements TypeInterface 'photo' => ArrayOfPhotoSize::class, 'sticker' => Sticker::class, 'video' => Video::class, + 'animation' => Animation::class, 'voice' => Voice::class, 'caption' => true, 'contact' => Contact::class, @@ -160,6 +161,13 @@ class Message extends BaseType implements TypeInterface * @var \TelegramBot\Api\Types\Video */ protected $video; + + /** + * Optional. Message is a animation, information about the animation + * + * @var \TelegramBot\Api\Types\Animation + */ + protected $animation; /** * Optional. Message is a voice message, information about the file @@ -721,6 +729,22 @@ public function setVideo(Video $video) { $this->video = $video; } + + /** + * @return Animation + */ + public function getAnimation() + { + return $this->animation; + } + + /** + * @param Animation $animation + */ + public function setAnimation(Animation $animation) + { + $this->animation = $animation; + } /** * @return Voice From c3c532a7bcab1e16b10b169f8c3bd077c0259d21 Mon Sep 17 00:00:00 2001 From: WebPajooh Date: Wed, 3 Jul 2019 13:53:42 +0430 Subject: [PATCH 022/130] Create Animation.php --- src/Types/Animation.php | 247 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 src/Types/Animation.php diff --git a/src/Types/Animation.php b/src/Types/Animation.php new file mode 100644 index 00000000..a1a9f3db --- /dev/null +++ b/src/Types/Animation.php @@ -0,0 +1,247 @@ + true, + 'width' => true, + 'height' => true, + 'duration' => true, + 'thumb' => PhotoSize::class, + 'file_name' => true, + 'mime_type' => true, + 'file_size' => true + ]; + + /** + * Unique file identifier + * + * @var string + */ + protected $fileId; + + /** + * Video width as defined by sender + * + * @var int + */ + protected $width; + + /** + * Video height as defined by sender + * + * @var int + */ + protected $height; + + /** + * Duration of the video in seconds as defined by sender + * + * @var int + */ + protected $duration; + + /** + * Video thumbnail + * + * @var PhotoSize + */ + protected $thumb; + + /** + * Optional. Animation thumbnail as defined by sender + * + * @var PhotoSize + */ + protected $fileName; + + /** + * Optional. Mime type of a file as defined by sender + * + * @var string + */ + protected $mimeType; + + /** + * Optional. File size + * + * @var int + */ + protected $fileSize; + + /** + * @return int + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param int $duration + * + * @throws InvalidArgumentException + */ + public function setDuration($duration) + { + if (is_integer($duration)) { + $this->duration = $duration; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return string + */ + public function getFileId() + { + return $this->fileId; + } + + /** + * @param string $fileId + */ + public function setFileId($fileId) + { + $this->fileId = $fileId; + } + + /** + * @return int + */ + public function getFileSize() + { + return $this->fileSize; + } + + /** + * @param int $fileSize + * + * @throws InvalidArgumentException + */ + public function setFileSize($fileSize) + { + if (is_integer($fileSize)) { + $this->fileSize = $fileSize; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return int + */ + public function getHeight() + { + return $this->height; + } + + /** + * @param int $height + * + * @throws InvalidArgumentException + */ + public function setHeight($height) + { + if (is_integer($height)) { + $this->height = $height; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return string + */ + public function getMimeType() + { + return $this->mimeType; + } + + /** + * @param string $mimeType + */ + public function setMimeType($mimeType) + { + $this->mimeType = $mimeType; + } + + /** + * @return PhotoSize + */ + public function getThumb() + { + return $this->thumb; + } + + /** + * @param PhotoSize $thumb + */ + public function setThumb(PhotoSize $thumb) + { + $this->thumb = $thumb; + } + + /** + * @return string $fileName + */ + public function getFileName() + { + return $this->fileName; + } + + /** + * @param string $fileName + */ + public function setFileName($fileName) + { + $this->fileName = $fileName; + } + + /** + * @return int + */ + public function getWidth() + { + return $this->width; + } + + /** + * @param int $width + * + * @throws InvalidArgumentException + */ + public function setWidth($width) + { + if (is_integer($width)) { + $this->width = $width; + } else { + throw new InvalidArgumentException(); + } + } +} From 15ceece933050f9bf61521380aebeefd33c1f679 Mon Sep 17 00:00:00 2001 From: WebPajooh Date: Wed, 3 Jul 2019 14:19:59 +0430 Subject: [PATCH 023/130] Add sendAnimation method --- src/BotApi.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/BotApi.php b/src/BotApi.php index b522df9e..f4fb17bb 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -687,6 +687,47 @@ public function sendVideo( ])); } + /** + * Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound), + * On success, the sent Message is returned. + * Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. + * + * @param int|string $chatId chat_id or @channel_name + * @param \CURLFile|string $animation + * @param int|null $duration + * @param string|null $caption + * @param int|null $replyToMessageId + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup + * @param bool $disableNotification + * @param string|null $parseMode + * + * @return \TelegramBot\Api\Types\Message + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function sendAnimation( + $chatId, + $animation, + $duration = null, + $caption = null, + $replyToMessageId = null, + $replyMarkup = null, + $disableNotification = false, + $parseMode = null + ) { + return Message::fromResponse($this->call('sendAnimation', [ + 'chat_id' => $chatId, + 'animation' => $animation, + 'duration' => $duration, + 'caption' => $caption, + 'reply_to_message_id' => $replyToMessageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'disable_notification' => (bool)$disableNotification, + 'parse_mode' => $parseMode + ])); + } + /** * Use this method to send audio files, * if you want Telegram clients to display the file as a playable voice message. From 9c63c25d858e023f04336af72939a4e74ed4efd6 Mon Sep 17 00:00:00 2001 From: romanggit <46619934+romanggit@users.noreply.github.com> Date: Tue, 8 Oct 2019 07:21:09 +0200 Subject: [PATCH 024/130] Update BotApi.php Added socks5 using if need --- src/BotApi.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index 4a40285d..d912e8ac 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1680,7 +1680,7 @@ public function sendMediaGroup( * * @return BotApi */ - public function setProxy($proxyString = '') + public function setProxy($proxyString = '', $socks5 = false) { if (empty($proxyString)) { $this->proxySettings = []; @@ -1691,6 +1691,10 @@ public function setProxy($proxyString = '') CURLOPT_PROXY => $proxyString, CURLOPT_HTTPPROXYTUNNEL => true, ]; + + if ($socks5) { + $this->proxySettings[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5; + } return $this; } From eb577cbda1468dfc6634cf79f0003ec2b161e6b7 Mon Sep 17 00:00:00 2001 From: Pasikuta Kirill Date: Thu, 24 Oct 2019 14:08:59 +0300 Subject: [PATCH 025/130] Bot API 4.2: Added support for native polls --- src/BotApi.php | 58 ++++++++++++++ src/Types/ArrayOfPollOption.php | 16 ++++ src/Types/Message.php | 24 ++++++ src/Types/Poll.php | 130 ++++++++++++++++++++++++++++++++ src/Types/PollOption.php | 81 ++++++++++++++++++++ 5 files changed, 309 insertions(+) create mode 100644 src/Types/ArrayOfPollOption.php create mode 100644 src/Types/Poll.php create mode 100644 src/Types/PollOption.php diff --git a/src/BotApi.php b/src/BotApi.php index d912e8ac..30089e2f 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -11,6 +11,7 @@ use TelegramBot\Api\Types\Inline\QueryResult\AbstractInlineQueryResult; use TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia; use TelegramBot\Api\Types\Message; +use TelegramBot\Api\Types\Poll; use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\User; use TelegramBot\Api\Types\UserProfilePhotos; @@ -1698,6 +1699,63 @@ public function setProxy($proxyString = '', $socks5 = false) return $this; } + + /** + * Use this method to send a native poll. A native poll can't be sent to a private chat. On success, the sent \TelegramBot\Api\Types\Message is returned. + * + * @param int|string $chatId + * @param string $question + * @param array $options + * @param bool $disableNotification + * @param int|null $replyToMessageId + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup + * + * @return \TelegramBot\Api\Types\Message + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function sendPoll( + $chatId, + $question, + $options, + $disableNotification = false, + $replyToMessageId = null, + $replyMarkup = null + ) { + return Message::fromResponse($this->call('sendPoll', [ + 'chat_id' => $chatId, + 'question' => $question, + 'options' => json_encode($options), + 'disable_notification' => (bool)$disableNotification, + 'reply_to_message_id' => (int)$replyToMessageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ])); + } + + /** + * Use this method to stop a poll which was sent by the bot. On success, the stopped \TelegramBot\Api\Types\Poll with the final results is returned. + * + * @param int|string $chatId + * @param int $messageId + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup + * @return Poll + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function stopPoll( + $chatId, + $messageId, + $replyMarkup = null + ) { + return Poll::fromResponse($this->call('stopPoll', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ])); + } + /** * Set an option for a cURL transfer * diff --git a/src/Types/ArrayOfPollOption.php b/src/Types/ArrayOfPollOption.php new file mode 100644 index 00000000..9bea6719 --- /dev/null +++ b/src/Types/ArrayOfPollOption.php @@ -0,0 +1,16 @@ + Contact::class, 'location' => Location::class, 'venue' => Venue::class, + 'poll' => Poll::class, 'new_chat_member' => User::class, 'left_chat_member' => User::class, 'new_chat_title' => true, @@ -189,6 +190,13 @@ class Message extends BaseType implements TypeInterface */ protected $venue; + /** + * Optional. Message is a native poll, information about the poll + * + * @var \TelegramBot\Api\Types\Poll + */ + protected $poll; + /** * Optional. A new member was added to the group, information about them (this member may be bot itself) * @@ -540,6 +548,22 @@ public function setVenue($venue) $this->venue = $venue; } + /** + * @return Poll + */ + public function getPoll() + { + return $this->poll; + } + + /** + * @param Poll $poll + */ + public function setPoll($poll) + { + $this->poll = $poll; + } + /** * @return int */ diff --git a/src/Types/Poll.php b/src/Types/Poll.php new file mode 100644 index 00000000..9da318cb --- /dev/null +++ b/src/Types/Poll.php @@ -0,0 +1,130 @@ + true, + 'question' => true, + 'options' => ArrayOfPollOption::class, + 'is_closed' => true + ]; + + /** + * Unique poll identifier + * + * @var string + */ + protected $id; + + /** + * Poll question, 1-255 characters + * + * @var string + */ + protected $question; + + /** + * List of poll options + * Array of \TelegramBot\Api\Types\PollOption + * + * @var array + */ + protected $options; + + /** + * True, if the poll is closed + * + * @var boolean + */ + protected $isClosed; + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return string + */ + public function getQuestion() + { + return $this->question; + } + + /** + * @param string $question + */ + public function setQuestion($question) + { + $this->question = $question; + } + + /** + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * @param array $options + */ + public function setOptions($options) + { + $this->options = $options; + } + + /** + * @return bool + */ + public function isClosed() + { + return $this->isClosed; + } + + /** + * @param bool $isClosed + */ + public function setIsClosed($isClosed) + { + $this->isClosed = $isClosed; + } + + +} diff --git a/src/Types/PollOption.php b/src/Types/PollOption.php new file mode 100644 index 00000000..61454d88 --- /dev/null +++ b/src/Types/PollOption.php @@ -0,0 +1,81 @@ + true, + 'voter_count' => true + ]; + + /** + * Option text, 1-100 characters + * + * @var string + */ + protected $text; + + /** + * Number of users that voted for this option + * + * @var integer + */ + protected $voterCount; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return int + */ + public function getVoterCount() + { + return $this->voterCount; + } + + /** + * @param int $voterCount + */ + public function setVoterCount($voterCount) + { + $this->voterCount = $voterCount; + } + + +} From aeefccb938e17c3278cad4ef29b8bb9762a0c199 Mon Sep 17 00:00:00 2001 From: Kirill Pasikuta Date: Thu, 24 Oct 2019 14:40:35 +0300 Subject: [PATCH 026/130] PSR fix --- src/BotApi.php | 6 ++++-- src/Types/Poll.php | 2 -- src/Types/PollOption.php | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 30089e2f..685f9c36 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1701,7 +1701,8 @@ public function setProxy($proxyString = '', $socks5 = false) /** - * Use this method to send a native poll. A native poll can't be sent to a private chat. On success, the sent \TelegramBot\Api\Types\Message is returned. + * Use this method to send a native poll. A native poll can't be sent to a private chat. + * On success, the sent \TelegramBot\Api\Types\Message is returned. * * @param int|string $chatId * @param string $question @@ -1734,7 +1735,8 @@ public function sendPoll( } /** - * Use this method to stop a poll which was sent by the bot. On success, the stopped \TelegramBot\Api\Types\Poll with the final results is returned. + * Use this method to stop a poll which was sent by the bot. + * On success, the stopped \TelegramBot\Api\Types\Poll with the final results is returned. * * @param int|string $chatId * @param int $messageId diff --git a/src/Types/Poll.php b/src/Types/Poll.php index 9da318cb..93ae2a7f 100644 --- a/src/Types/Poll.php +++ b/src/Types/Poll.php @@ -125,6 +125,4 @@ public function setIsClosed($isClosed) { $this->isClosed = $isClosed; } - - } diff --git a/src/Types/PollOption.php b/src/Types/PollOption.php index 61454d88..5f9dbc14 100644 --- a/src/Types/PollOption.php +++ b/src/Types/PollOption.php @@ -76,6 +76,4 @@ public function setVoterCount($voterCount) { $this->voterCount = $voterCount; } - - } From 2b59014cac960534fb5086b087c7d730dfa8cb13 Mon Sep 17 00:00:00 2001 From: Scarboroid Date: Sun, 27 Oct 2019 15:27:45 +0900 Subject: [PATCH 027/130] fix incorrect check answer from telegram --- src/BotApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index 4a40285d..1038fa47 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -227,7 +227,7 @@ public function call($method, array $data = null) $response = self::jsonValidate($this->executeCurl($options), $this->returnArray); if ($this->returnArray) { - if (!isset($response['ok'])) { + if (!isset($response['ok']) || !$response['ok']) { throw new Exception($response['description'], $response['error_code']); } From 7f008323b54c702b5901bf5abc58bfc8b0a98658 Mon Sep 17 00:00:00 2001 From: Vladislav Lyshenko Date: Mon, 4 Nov 2019 16:07:24 +0200 Subject: [PATCH 028/130] Added missed Message fields --- src/Types/Message.php | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/Types/Message.php b/src/Types/Message.php index a9fe2a7a..6939b2fc 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -27,6 +27,8 @@ class Message extends BaseType implements TypeInterface 'date' => true, 'chat' => Chat::class, 'forward_from' => User::class, + 'forward_from_chat' => Chat::class, + 'forward_from_message_id' => true, 'forward_date' => true, 'reply_to_message' => Message::class, 'text' => true, @@ -35,6 +37,7 @@ class Message extends BaseType implements TypeInterface 'audio' => Audio::class, 'document' => Document::class, 'photo' => ArrayOfPhotoSize::class, + 'media_group_id' => true, 'sticker' => Sticker::class, 'video' => Video::class, 'voice' => Voice::class, @@ -95,6 +98,22 @@ class Message extends BaseType implements TypeInterface */ protected $forwardFrom; + /** + * Optional. For messages forwarded from channels, information about + * the original channel + * + * @var \TelegramBot\Api\Types\Chat + */ + protected $forwardFromChat; + + /** + * Optional. For messages forwarded from channels, identifier of + * the original message in the channel + * + * @var int + */ + protected $forwardFromMessageId; + /** * Optional. For forwarded messages, date the original message was sent in Unix time * @@ -147,6 +166,14 @@ class Message extends BaseType implements TypeInterface */ protected $photo; + /** + * Optional. The unique identifier of a media message group + * this message belongs to + * + * @var int + */ + protected $mediaGroupId; + /** * Optional. Message is a sticker, information about the sticker * @@ -476,6 +503,38 @@ public function setForwardFrom(User $forwardFrom) $this->forwardFrom = $forwardFrom; } + /** + * @return Chat + */ + public function getForwardFromChat() + { + return $this->forwardFromChat; + } + + /** + * @param Chat $forwardFromChat + */ + public function setForwardFromChat(Chat $forwardFromChat) + { + $this->forwardFromChat = $forwardFromChat; + } + + /** + * @return int + */ + public function getForwardFromMessageId() + { + return $this->forwardFromMessageId; + } + + /** + * @param int $forwardFromMessageId + */ + public function setForwardFromMessageId($forwardFromMessageId) + { + $this->forwardFromMessageId = $forwardFromMessageId; + } + /** * @return boolean */ @@ -626,6 +685,22 @@ public function setPhoto(array $photo) $this->photo = $photo; } + /** + * @return int + */ + public function getMediaGroupId() + { + return $this->mediaGroupId; + } + + /** + * @param int $mediaGroupId + */ + public function setMediaGroupId($mediaGroupId) + { + $this->mediaGroupId = $mediaGroupId; + } + /** * @return Message */ From 70be6f550ed6fc66b1a6ae30bb2c28efea821176 Mon Sep 17 00:00:00 2001 From: VladimirDeryabin Date: Wed, 12 Feb 2020 19:40:52 +0300 Subject: [PATCH 029/130] Fix typo --- src/Types/MessageEntity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Types/MessageEntity.php b/src/Types/MessageEntity.php index bd8934b4..453247a7 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -14,7 +14,7 @@ class MessageEntity extends BaseType implements TypeInterface { - const TYPE_MENTION = 'mentin'; + const TYPE_MENTION = 'mention'; const TYPE_HASHTAG = 'hashtag'; const TYPE_BOT_COMMAND = 'bot_command'; const TYPE_URL = 'url'; From 3ba986f3e47b463e1b69eedcd598b82d408a6f61 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Sat, 14 Mar 2020 22:32:02 +0100 Subject: [PATCH 030/130] Add editMessageMedia method --- src/BotApi.php | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 6dddd44f..6e28f359 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -10,6 +10,7 @@ use TelegramBot\Api\Types\File; use TelegramBot\Api\Types\Inline\QueryResult\AbstractInlineQueryResult; use TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia; +use TelegramBot\Api\Types\InputMedia\InputMedia; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Poll; use TelegramBot\Api\Types\Update; @@ -437,8 +438,8 @@ public function setWebhook($url = '', $certificate = null) { return $this->call('setWebhook', ['url' => $url, 'certificate' => $certificate]); } - - + + /** * Use this method to clear webhook and use getUpdates again! * @@ -1141,6 +1142,39 @@ public function editMessageCaption( ])); } + /** + * Use this method to edit animation, audio, document, photo, or video messages. + * If a message is a part of a message album, then it can be edited only to a photo or a video. + * Otherwise, message type can be changed arbitrarily. + * When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. + * On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned + * + * @param $chatId + * @param $messageId + * @param InputMedia $media + * @param null $inlineMessageId + * @param null $replyMarkup + * @return bool|Message + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function editMessageMedia( + $chatId, + $messageId, + InputMedia $media, + $inlineMessageId = null, + $replyMarkup = null + ) { + return Message::fromResponse($this->call('editMessageMedia', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'inline_message_id' => $inlineMessageId, + 'media' => $media->toJson(), + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ])); + } + /** * Use this method to edit only the reply markup of messages sent by the bot or via the bot * @@ -1746,7 +1780,7 @@ public function setProxy($proxyString = '', $socks5 = false) CURLOPT_PROXY => $proxyString, CURLOPT_HTTPPROXYTUNNEL => true, ]; - + if ($socks5) { $this->proxySettings[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5; } From 4431eca20347ff2773ab0b86c85ca00c98720a24 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Wed, 22 Apr 2020 12:41:59 +0200 Subject: [PATCH 031/130] Update Message type --- src/Types/ArrayOfUser.php | 16 + src/Types/Message.php | 681 +++++++++++++++++++++----------------- 2 files changed, 397 insertions(+), 300 deletions(-) create mode 100644 src/Types/ArrayOfUser.php diff --git a/src/Types/ArrayOfUser.php b/src/Types/ArrayOfUser.php new file mode 100644 index 00000000..cba90e73 --- /dev/null +++ b/src/Types/ArrayOfUser.php @@ -0,0 +1,16 @@ + Chat::class, 'forward_from_message_id' => true, 'forward_date' => true, + 'forward_signature' => true, + 'forward_sender_name' => true, 'reply_to_message' => Message::class, + 'edit_date' => true, + 'media_group_id' => true, + 'author_signature' => true, 'text' => true, 'entities' => ArrayOfMessageEntity::class, 'caption_entities' => ArrayOfMessageEntity::class, 'audio' => Audio::class, 'document' => Document::class, + 'animation' => Animation::class, 'photo' => ArrayOfPhotoSize::class, - 'media_group_id' => true, 'sticker' => Sticker::class, 'video' => Video::class, - 'animation' => Animation::class, 'voice' => Voice::class, 'caption' => true, 'contact' => Contact::class, 'location' => Location::class, 'venue' => Venue::class, 'poll' => Poll::class, - 'new_chat_member' => User::class, + 'new_chat_members' => ArrayOfUser::class, 'left_chat_member' => User::class, 'new_chat_title' => true, 'new_chat_photo' => ArrayOfPhotoSize::class, @@ -60,9 +65,8 @@ class Message extends BaseType implements TypeInterface 'pinned_message' => Message::class, 'invoice' => Invoice::class, 'successful_payment' => SuccessfulPayment::class, - 'forward_signature' => true, - 'author_signature' => true, - 'connected_website' => true + 'connected_website' => true, + 'reply_markup' => InlineKeyboardMarkup::class, ]; /** @@ -116,6 +120,21 @@ class Message extends BaseType implements TypeInterface */ protected $forwardFromMessageId; + /** + * Optional. For messages forwarded from channels, signature of the post author if present + * + * @var string + */ + protected $forwardSignature; + + /** + * Optional. Sender's name for messages forwarded from users who disallow adding a link to their account + * in forwarded messages + * + * @var string + */ + protected $forwardSenderName; + /** * Optional. For forwarded messages, date the original message was sent in Unix time * @@ -131,6 +150,28 @@ class Message extends BaseType implements TypeInterface */ protected $replyToMessage; + /** + * Optional. Date the message was last edited in Unix time + * + * @var int + */ + protected $editDate; + + /** + * Optional. The unique identifier of a media message group + * this message belongs to + * + * @var int + */ + protected $mediaGroupId; + + /** + * Optional. Signature of the post author for messages in channels + * + * @var string + */ + protected $authorSignature; + /** * Optional. For text messages, the actual UTF-8 text of the message * @@ -146,6 +187,14 @@ class Message extends BaseType implements TypeInterface */ protected $entities; + /** + * Optional. For messages with a caption, special entities like usernames, + * URLs, bot commands, etc. that appear in the caption + * + * @var ArrayOfMessageEntity + */ + protected $captionEntities; + /** * Optional. Message is an audio file, information about the file * @@ -161,20 +210,19 @@ class Message extends BaseType implements TypeInterface protected $document; /** - * Optional. Message is a photo, available sizes of the photo - * array of \TelegramBot\Api\Types\Photo + * Optional. Message is a animation, information about the animation * - * @var array + * @var \TelegramBot\Api\Types\Animation */ - protected $photo; + protected $animation; /** - * Optional. The unique identifier of a media message group - * this message belongs to + * Optional. Message is a photo, available sizes of the photo + * array of \TelegramBot\Api\Types\Photo * - * @var int + * @var array */ - protected $mediaGroupId; + protected $photo; /** * Optional. Message is a sticker, information about the sticker @@ -189,13 +237,6 @@ class Message extends BaseType implements TypeInterface * @var \TelegramBot\Api\Types\Video */ protected $video; - - /** - * Optional. Message is a animation, information about the animation - * - * @var \TelegramBot\Api\Types\Animation - */ - protected $animation; /** * Optional. Message is a voice message, information about the file @@ -204,6 +245,13 @@ class Message extends BaseType implements TypeInterface */ protected $voice; + /** + * Optional. Text description of the video (usually empty) + * + * @var string + */ + protected $caption; + /** * Optional. Message is a shared contact, information about the contact * @@ -233,11 +281,13 @@ class Message extends BaseType implements TypeInterface protected $poll; /** - * Optional. A new member was added to the group, information about them (this member may be bot itself) + * Optional. New members that were added to the group or supergroup and information about them + * (the bot itself may be one of these members) + * array of \TelegramBot\Api\Types\User * - * @var \TelegramBot\Api\Types\User + * @var array */ - protected $newChatMember; + protected $newChatMembers; /** * Optional. A member was removed from the group, information about them (this member may be bot itself) @@ -274,14 +324,6 @@ class Message extends BaseType implements TypeInterface */ protected $groupChatCreated; - /** - * Optional. Text description of the video (usually empty) - * - * @var string - */ - protected $caption; - - /** * Optional. Service message: the supergroup has been created * @@ -335,64 +377,55 @@ class Message extends BaseType implements TypeInterface protected $successfulPayment; /** - * Optional. For messages forwarded from channels, signature of the post author if present - * - * @var string - */ - protected $forwardSignature; - - /** - * Optional. Signature of the post author for messages in channels + * Optional. The domain name of the website on which the user has logged in. * * @var string */ - protected $authorSignature; - - /** - * Optional. For messages with a caption, special entities like usernames, - * URLs, bot commands, etc. that appear in the caption - * - * @var ArrayOfMessageEntity - */ - protected $captionEntities; + protected $connectedWebsite; /** - * Optional. The domain name of the website on which the user has logged in. + * Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. * - * @var string + * @var InlineKeyboardMarkup */ - protected $connectedWebsite; + protected $replyMarkup; /** - * @return string + * @return int */ - public function getCaption() + public function getMessageId() { - return $this->caption; + return $this->messageId; } /** - * @param string $caption + * @param int $messageId + * + * @throws InvalidArgumentException */ - public function setCaption($caption) + public function setMessageId($messageId) { - $this->caption = $caption; + if (is_integer($messageId) || is_float($messageId)) { + $this->messageId = $messageId; + } else { + throw new InvalidArgumentException(); + } } /** - * @return Audio + * @return User */ - public function getAudio() + public function getFrom() { - return $this->audio; + return $this->from; } /** - * @param Audio $audio + * @param User $from */ - public function setAudio(Audio $audio) + public function setFrom(User $from) { - $this->audio = $audio; + $this->from = $from; } /** @@ -411,22 +444,6 @@ public function setChat(Chat $chat) $this->chat = $chat; } - /** - * @return Contact - */ - public function getContact() - { - return $this->contact; - } - - /** - * @param Contact $contact - */ - public function setContact(Contact $contact) - { - $this->contact = $contact; - } - /** * @return int */ @@ -442,67 +459,13 @@ public function getDate() */ public function setDate($date) { - if (is_integer($date)) { + if (is_int($date)) { $this->date = $date; } else { throw new InvalidArgumentException(); } } - /** - * @return boolean - */ - public function isDeleteChatPhoto() - { - return $this->deleteChatPhoto; - } - - /** - * @param boolean $deleteChatPhoto - */ - public function setDeleteChatPhoto($deleteChatPhoto) - { - $this->deleteChatPhoto = (bool)$deleteChatPhoto; - } - - /** - * @return Document - */ - public function getDocument() - { - return $this->document; - } - - /** - * @param Document $document - */ - public function setDocument($document) - { - $this->document = $document; - } - - /** - * @return int - */ - public function getForwardDate() - { - return $this->forwardDate; - } - - /** - * @param int $forwardDate - * - * @throws InvalidArgumentException - */ - public function setForwardDate($forwardDate) - { - if (is_integer($forwardDate)) { - $this->forwardDate = $forwardDate; - } else { - throw new InvalidArgumentException(); - } - } - /** * @return User */ @@ -552,201 +515,239 @@ public function setForwardFromMessageId($forwardFromMessageId) } /** - * @return boolean + * @return string */ - public function isGroupChatCreated() + public function getForwardSignature() { - return $this->groupChatCreated; + return $this->forwardSignature; } /** - * @param boolean $groupChatCreated + * @param string $forwardSignature */ - public function setGroupChatCreated($groupChatCreated) + public function setForwardSignature($forwardSignature) { - $this->groupChatCreated = (bool)$groupChatCreated; + $this->forwardSignature = $forwardSignature; } /** - * @return User + * @return string */ - public function getLeftChatMember() + public function getForwardSenderName() { - return $this->leftChatMember; + return $this->forwardSenderName; } /** - * @param User $leftChatMember + * @param string $forwardSenderName */ - public function setLeftChatMember($leftChatMember) + public function setForwardSenderName($forwardSenderName) { - $this->leftChatMember = $leftChatMember; + $this->forwardSenderName = $forwardSenderName; } /** - * @return Location + * @return int */ - public function getLocation() + public function getForwardDate() { - return $this->location; + return $this->forwardDate; } /** - * @param Location $location + * @param int $forwardDate + * + * @throws InvalidArgumentException */ - public function setLocation(Location $location) + public function setForwardDate($forwardDate) { - $this->location = $location; + if (is_int($forwardDate)) { + $this->forwardDate = $forwardDate; + } else { + throw new InvalidArgumentException(); + } } /** - * @return Venue + * @return Message */ - public function getVenue() + public function getReplyToMessage() { - return $this->venue; + return $this->replyToMessage; } /** - * @param Venue $venue + * @param Message $replyToMessage */ - public function setVenue($venue) + public function setReplyToMessage(Message $replyToMessage) { - $this->venue = $venue; + $this->replyToMessage = $replyToMessage; } /** - * @return Poll + * @return int */ - public function getPoll() + public function getEditDate() { - return $this->poll; + return $this->editDate; } /** - * @param Poll $poll + * @param int $editDate + * + * @throws InvalidArgumentException */ - public function setPoll($poll) + public function setEditDate($editDate) { - $this->poll = $poll; + if (is_int($editDate)) { + $this->editDate = $editDate; + } else { + throw new InvalidArgumentException(); + } } /** * @return int */ - public function getMessageId() + public function getMediaGroupId() { - return $this->messageId; + return $this->mediaGroupId; } /** - * @param int $messageId - * - * @throws InvalidArgumentException + * @param int $mediaGroupId */ - public function setMessageId($messageId) + public function setMediaGroupId($mediaGroupId) { - if (is_integer($messageId) || is_float($messageId)) { - $this->messageId = $messageId; - } else { - throw new InvalidArgumentException(); - } + $this->mediaGroupId = $mediaGroupId; } /** - * @return User + * @return string */ - public function getNewChatMember() + public function getAuthorSignature() { - return $this->newChatMember; + return $this->authorSignature; } /** - * @param User $newChatMember + * @param string $authorSignature */ - public function setNewChatMember($newChatMember) + public function setAuthorSignature($authorSignature) { - $this->newChatMember = $newChatMember; + $this->authorSignature = $authorSignature; + } + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + */ + public function setText($text) + { + $this->text = $text; } /** * @return array */ - public function getNewChatPhoto() + public function getEntities() { - return $this->newChatPhoto; + return $this->entities; } /** - * @param array $newChatPhoto + * @param array $entities */ - public function setNewChatPhoto($newChatPhoto) + public function setEntities($entities) { - $this->newChatPhoto = $newChatPhoto; + $this->entities = $entities; } /** - * @return string + * @return ArrayOfMessageEntity */ - public function getNewChatTitle() + public function getCaptionEntities() { - return $this->newChatTitle; + return $this->captionEntities; } /** - * @param string $newChatTitle + * @param ArrayOfMessageEntity $captionEntities */ - public function setNewChatTitle($newChatTitle) + public function setCaptionEntities($captionEntities) { - $this->newChatTitle = $newChatTitle; + $this->captionEntities = $captionEntities; } /** - * @return array + * @return Audio */ - public function getPhoto() + public function getAudio() { - return $this->photo; + return $this->audio; } /** - * @param array $photo + * @param Audio $audio */ - public function setPhoto(array $photo) + public function setAudio(Audio $audio) { - $this->photo = $photo; + $this->audio = $audio; } /** - * @return int + * @return Document */ - public function getMediaGroupId() + public function getDocument() { - return $this->mediaGroupId; + return $this->document; } /** - * @param int $mediaGroupId + * @param Document $document */ - public function setMediaGroupId($mediaGroupId) + public function setDocument($document) { - $this->mediaGroupId = $mediaGroupId; + $this->document = $document; } /** - * @return Message + * @return Animation */ - public function getReplyToMessage() + public function getAnimation() { - return $this->replyToMessage; + return $this->animation; } /** - * @param Message $replyToMessage + * @param Animation $animation */ - public function setReplyToMessage(Message $replyToMessage) + public function setAnimation(Animation $animation) { - $this->replyToMessage = $replyToMessage; + $this->animation = $animation; + } + + /** + * @return array + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param array $photo + */ + public function setPhoto(array $photo) + { + $this->photo = $photo; } /** @@ -765,108 +766,212 @@ public function setSticker(Sticker $sticker) $this->sticker = $sticker; } + /** + * @return Video + */ + public function getVideo() + { + return $this->video; + } + + /** + * @param Video $video + */ + public function setVideo(Video $video) + { + $this->video = $video; + } + + /** + * @return Voice + */ + public function getVoice() + { + return $this->voice; + } + + /** + * @param Voice $voice + */ + public function setVoice($voice) + { + $this->voice = $voice; + } + /** * @return string */ - public function getText() + public function getCaption() { - return $this->text; + return $this->caption; } /** - * @param string $text + * @param string $caption */ - public function setText($text) + public function setCaption($caption) { - $this->text = $text; + $this->caption = $caption; + } + + /** + * @return Contact + */ + public function getContact() + { + return $this->contact; + } + + /** + * @param Contact $contact + */ + public function setContact(Contact $contact) + { + $this->contact = $contact; + } + + /** + * @return Location + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param Location $location + */ + public function setLocation(Location $location) + { + $this->location = $location; + } + + /** + * @return Venue + */ + public function getVenue() + { + return $this->venue; + } + + /** + * @param Venue $venue + */ + public function setVenue($venue) + { + $this->venue = $venue; + } + + /** + * @return Poll + */ + public function getPoll() + { + return $this->poll; + } + + /** + * @param Poll $poll + */ + public function setPoll($poll) + { + $this->poll = $poll; } /** * @return array */ - public function getEntities() + public function getNewChatMembers() { - return $this->entities; + return $this->newChatMembers; } /** - * @param array $entities + * @param array $newChatMembers */ - public function setEntities($entities) + public function setNewChatMembers($newChatMembers) { - $this->entities = $entities; + $this->newChatMembers = $newChatMembers; } /** * @return User */ - public function getFrom() + public function getLeftChatMember() { - return $this->from; + return $this->leftChatMember; } /** - * @param User $from + * @param User $leftChatMember */ - public function setFrom(User $from) + public function setLeftChatMember($leftChatMember) { - $this->from = $from; + $this->leftChatMember = $leftChatMember; } /** - * @return Video + * @return string */ - public function getVideo() + public function getNewChatTitle() { - return $this->video; + return $this->newChatTitle; } /** - * @param Video $video + * @param string $newChatTitle */ - public function setVideo(Video $video) + public function setNewChatTitle($newChatTitle) { - $this->video = $video; + $this->newChatTitle = $newChatTitle; } - + /** - * @return Animation + * @return array */ - public function getAnimation() + public function getNewChatPhoto() { - return $this->animation; + return $this->newChatPhoto; } /** - * @param Animation $animation + * @param array $newChatPhoto */ - public function setAnimation(Animation $animation) + public function setNewChatPhoto($newChatPhoto) { - $this->animation = $animation; + $this->newChatPhoto = $newChatPhoto; } /** - * @return Voice + * @return boolean */ - public function getVoice() + public function isDeleteChatPhoto() { - return $this->voice; + return $this->deleteChatPhoto; } /** - * @param Voice $voice + * @param boolean $deleteChatPhoto */ - public function setVoice($voice) + public function setDeleteChatPhoto($deleteChatPhoto) { - $this->voice = $voice; + $this->deleteChatPhoto = (bool)$deleteChatPhoto; } /** - * @param boolean $supergroupChatCreated + * @return boolean */ - public function setSupergroupChatCreated($supergroupChatCreated) + public function isGroupChatCreated() { - $this->supergroupChatCreated = $supergroupChatCreated; + return $this->groupChatCreated; + } + + /** + * @param boolean $groupChatCreated + */ + public function setGroupChatCreated($groupChatCreated) + { + $this->groupChatCreated = (bool)$groupChatCreated; } /** @@ -878,11 +983,11 @@ public function isSupergroupChatCreated() } /** - * @param boolean $channelChatCreated + * @param boolean $supergroupChatCreated */ - public function setChannelChatCreated($channelChatCreated) + public function setSupergroupChatCreated($supergroupChatCreated) { - $this->channelChatCreated = $channelChatCreated; + $this->supergroupChatCreated = $supergroupChatCreated; } /** @@ -894,11 +999,11 @@ public function isChannelChatCreated() } /** - * @param int $migrateToChatId + * @param boolean $channelChatCreated */ - public function setMigrateToChatId($migrateToChatId) + public function setChannelChatCreated($channelChatCreated) { - $this->migrateToChatId = $migrateToChatId; + $this->channelChatCreated = $channelChatCreated; } /** @@ -910,11 +1015,11 @@ public function getMigrateToChatId() } /** - * @param int $migrateFromChatId + * @param int $migrateToChatId */ - public function setMigrateFromChatId($migrateFromChatId) + public function setMigrateToChatId($migrateToChatId) { - $this->migrateFromChatId = $migrateFromChatId; + $this->migrateToChatId = $migrateToChatId; } /** @@ -925,6 +1030,14 @@ public function getMigrateFromChatId() return $this->migrateFromChatId; } + /** + * @param int $migrateFromChatId + */ + public function setMigrateFromChatId($migrateFromChatId) + { + $this->migrateFromChatId = $migrateFromChatId; + } + /** * @return Message */ @@ -980,64 +1093,32 @@ public function setSuccessfulPayment($successfulPayment) /** * @return string */ - public function getForwardSignature() - { - return $this->forwardSignature; - } - - /** - * @param string $forwardSignature - */ - public function setForwardSignature($forwardSignature) - { - $this->forwardSignature = $forwardSignature; - } - - /** - * @return string - */ - public function getAuthorSignature() - { - return $this->authorSignature; - } - - /** - * @param string $authorSignature - */ - public function setAuthorSignature($authorSignature) - { - $this->authorSignature = $authorSignature; - } - - /** - * @return ArrayOfMessageEntity - */ - public function getCaptionEntities() + public function getConnectedWebsite() { - return $this->captionEntities; + return $this->connectedWebsite; } /** - * @param ArrayOfMessageEntity $captionEntities + * @param string $connectedWebsite */ - public function setCaptionEntities($captionEntities) + public function setConnectedWebsite($connectedWebsite) { - $this->captionEntities = $captionEntities; + $this->connectedWebsite = $connectedWebsite; } /** - * @return string + * @return InlineKeyboardMarkup */ - public function getConnectedWebsite() + public function getReplyMarkup() { - return $this->connectedWebsite; + return $this->replyMarkup; } /** - * @param string $connectedWebsite + * @param InlineKeyboardMarkup $replyMarkup */ - public function setConnectedWebsite($connectedWebsite) + public function setReplyMarkup($replyMarkup) { - $this->connectedWebsite = $connectedWebsite; + $this->replyMarkup = $replyMarkup; } } From 55a14dee582dd4a636a3789d5420e5beb5908a16 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Wed, 22 Apr 2020 12:57:43 +0200 Subject: [PATCH 032/130] Added Dice type --- src/Types/Dice.php | 53 +++++++++++++++++++++++++++++++++++++++++++ src/Types/Message.php | 24 ++++++++++++++++++++ tests/MessageTest.php | 10 ++++---- 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 src/Types/Dice.php diff --git a/src/Types/Dice.php b/src/Types/Dice.php new file mode 100644 index 00000000..47c66f9b --- /dev/null +++ b/src/Types/Dice.php @@ -0,0 +1,53 @@ + true + ]; + + /** + * Value of the dice, 1-6 + * + * @var int + */ + protected $value; + + /** + * @return int + */ + public function getValue() + { + return $this->value; + } + + /** + * @param int $value + */ + public function setValue($value) + { + $this->value = $value; + } +} \ No newline at end of file diff --git a/src/Types/Message.php b/src/Types/Message.php index 3f2727a4..5c9875c4 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -52,6 +52,7 @@ class Message extends BaseType implements TypeInterface 'location' => Location::class, 'venue' => Venue::class, 'poll' => Poll::class, + 'dice' => Dice::class, 'new_chat_members' => ArrayOfUser::class, 'left_chat_member' => User::class, 'new_chat_title' => true, @@ -280,6 +281,13 @@ class Message extends BaseType implements TypeInterface */ protected $poll; + /** + * Optional. Message is a dice with random value from 1 to 6 + * + * @var \TelegramBot\Api\Types\Dice + */ + protected $dice; + /** * Optional. New members that were added to the group or supergroup and information about them * (the bot itself may be one of these members) @@ -878,6 +886,22 @@ public function setPoll($poll) $this->poll = $poll; } + /** + * @return Dice + */ + public function getDice() + { + return $this->dice; + } + + /** + * @param Dice $dice + */ + public function setDice(Dice $dice) + { + $this->dice = $dice; + } + /** * @return array */ diff --git a/tests/MessageTest.php b/tests/MessageTest.php index a148f85b..49904fbb 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -479,10 +479,10 @@ public function testSetNewChatParticipant() 'last_name' => 'Gusev', 'username' => 'iGusev' )); - $item->setNewChatMember($user); + $item->setNewChatMembers([$user]); - $this->assertAttributeEquals($user, 'newChatMember', $item); + $this->assertAttributeEquals([$user], 'newChatMembers', $item); } public function testGetNewChatParticipant() @@ -494,10 +494,10 @@ public function testGetNewChatParticipant() 'last_name' => 'Gusev', 'username' => 'iGusev' )); - $item->setNewChatMember($user); + $item->setNewChatMembers([$user]); - $this->assertEquals($user, $item->getNewChatMember()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getNewChatMember()); + $this->assertEquals([$user], $item->getNewChatMembers()); + $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getNewChatMembers()[0]); } public function testSetNewChatTitle() From 64dee7f2372c0c2dee1c0e9309edaba530ecf550 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Wed, 22 Apr 2020 21:51:41 +0200 Subject: [PATCH 033/130] Update the Poll type --- src/Types/Poll.php | 137 +++++++++++++++++++++++++++++++++++- tests/PollTest.php | 171 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 305 insertions(+), 3 deletions(-) create mode 100644 tests/PollTest.php diff --git a/src/Types/Poll.php b/src/Types/Poll.php index 93ae2a7f..6433915f 100644 --- a/src/Types/Poll.php +++ b/src/Types/Poll.php @@ -19,18 +19,32 @@ class Poll extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['id', 'question', 'options', 'is_closed']; + protected static $requiredParams = [ + 'id', + 'question', + 'options', + 'total_voter_count', + 'is_closed', + 'is_anonymous', + 'type', + 'allows_multiple_answers', + ]; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'question' => true, 'options' => ArrayOfPollOption::class, - 'is_closed' => true + 'total_voter_count' => true, + 'is_closed' => true, + 'is_anonymous' => true, + 'type' => true, + 'allows_multiple_answers' => true, + 'correct_option_id' => true, ]; /** @@ -55,6 +69,13 @@ class Poll extends BaseType implements TypeInterface */ protected $options; + /** + * Total number of users that voted in the poll + * + * @var int + */ + protected $totalVoterCount; + /** * True, if the poll is closed * @@ -62,6 +83,36 @@ class Poll extends BaseType implements TypeInterface */ protected $isClosed; + /** + * True, if the poll is anonymous + * + * @var bool + */ + protected $isAnonymous; + + /** + * Poll type, currently can be “regular” or “quiz” + * + * @var string + */ + protected $type; + + /** + * True, if the poll allows multiple answers + * + * @var bool + */ + protected $allowsMultipleAnswers; + + /** + * Optional. 0-based identifier of the correct answer option. + * Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) + * by the bot or to the private chat with the bot. + * + * @var int + */ + protected $correctOptionId; + /** * @return string */ @@ -110,6 +161,22 @@ public function setOptions($options) $this->options = $options; } + /** + * @return int + */ + public function getTotalVoterCount() + { + return $this->totalVoterCount; + } + + /** + * @param int $totalVoterCount + */ + public function setTotalVoterCount($totalVoterCount) + { + $this->totalVoterCount = $totalVoterCount; + } + /** * @return bool */ @@ -125,4 +192,68 @@ public function setIsClosed($isClosed) { $this->isClosed = $isClosed; } + + /** + * @return bool + */ + public function isAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return bool + */ + public function isAllowsMultipleAnswers() + { + return $this->allowsMultipleAnswers; + } + + /** + * @param bool $allowsMultipleAnswers + */ + public function setAllowsMultipleAnswers($allowsMultipleAnswers) + { + $this->allowsMultipleAnswers = $allowsMultipleAnswers; + } + + /** + * @return int + */ + public function getCorrectOptionId() + { + return $this->correctOptionId; + } + + /** + * @param int $correctOptionId + */ + public function setCorrectOptionId($correctOptionId) + { + $this->correctOptionId = $correctOptionId; + } } diff --git a/tests/PollTest.php b/tests/PollTest.php new file mode 100644 index 00000000..3e767511 --- /dev/null +++ b/tests/PollTest.php @@ -0,0 +1,171 @@ +setId(123456789); + + $this->assertEquals(123456789, $item->getId()); + } + + public function testSetId() + { + $item = new Poll(); + $item->setId(123456789); + + $this->assertAttributeEquals(123456789, 'id', $item); + } + + public function testGetQuestion() + { + $item = new Poll(); + $item->setQuestion('What is the name of Heisenberg from "Breaking bad"?'); + + $this->assertEquals('What is the name of Heisenberg from "Breaking bad"?', $item->getQuestion()); + } + + public function testSetQuestion() + { + $item = new Poll(); + $item->setQuestion('What is the name of Heisenberg from "Breaking bad"?'); + + $this->assertAttributeEquals('What is the name of Heisenberg from "Breaking bad"?', 'question', $item); + } + + public function testGetOptions() + { + $item = new Poll(); + $options = [ + PollOption::fromResponse([ + 'text' => 'Walter White', + 'voter_count' => 100 + ]), + ]; + + $item->setOptions($options); + + $this->assertEquals($options, $item->getOptions()); + + foreach ($item->getOptions() as $option) { + $this->assertInstanceOf(PollOption::class, $option); + } + } + + public function testSetOptions() + { + $item = new Poll(); + $options = [ + PollOption::fromResponse([ + 'text' => 'Walter White', + 'voter_count' => 100 + ]), + ]; + + $item->setOptions($options); + + $this->assertAttributeEquals($options, 'options', $item); + } + + public function testGetTotalVoterCount() + { + $item = new Poll(); + $item->setTotalVoterCount(17); + + $this->assertEquals(17, $item->getTotalVoterCount()); + } + + public function testSetTotalVoterCount() + { + $item = new Poll(); + $item->setTotalVoterCount(17); + + $this->assertAttributeEquals(17, 'totalVoterCount', $item); + } + + public function testIsClosed() + { + $item = new Poll(); + $item->setIsClosed(true); + + $this->assertTrue($item->isClosed()); + } + + public function testSetIsClosed() + { + $item = new Poll(); + $item->setIsClosed(true); + + $this->assertAttributeEquals(true, 'isClosed', $item); + } + + public function testIsAnonymous() + { + $item = new Poll(); + $item->setIsAnonymous(false); + + $this->assertFalse($item->isAnonymous()); + } + + public function testSetIsAnonymous() + { + $item = new Poll(); + $item->setIsAnonymous(false); + + $this->assertAttributeEquals(false, 'isAnonymous', $item); + } + + public function testGetType() + { + $item = new Poll(); + $item->setType('regular'); + + $this->assertEquals('regular', $item->getType()); + } + + public function testSetType() + { + $item = new Poll(); + $item->setType('regular'); + + $this->assertAttributeEquals('regular', 'type', $item); + } + + public function testAllowsMultipleAnswers() + { + $item = new Poll(); + $item->setAllowsMultipleAnswers(true); + + $this->assertTrue($item->isAllowsMultipleAnswers()); + } + + public function testSetAllowsMultipleAnswers() + { + $item = new Poll(); + $item->setAllowsMultipleAnswers(true); + + $this->assertAttributeEquals(true, 'allowsMultipleAnswers', $item); + } + + public function testGetCorrectOptionId() + { + $item = new Poll(); + $item->setCorrectOptionId(2); + + $this->assertEquals(2, $item->getCorrectOptionId()); + } + + public function testSetCorrectOptionId() + { + $item = new Poll(); + $item->setCorrectOptionId(2); + + $this->assertAttributeEquals(2, 'correctOptionId', $item); + } +} \ No newline at end of file From dedf1d35dd97993a8e3b43739e0e190b4a35fc4c Mon Sep 17 00:00:00 2001 From: eldarQa Date: Wed, 22 Apr 2020 22:13:18 +0200 Subject: [PATCH 034/130] Ignore: fixed the small things for PSR-2 --- src/BotApi.php | 3 ++- src/Types/Dice.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 6e28f359..ba040f43 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1146,7 +1146,8 @@ public function editMessageCaption( * Use this method to edit animation, audio, document, photo, or video messages. * If a message is a part of a message album, then it can be edited only to a photo or a video. * Otherwise, message type can be changed arbitrarily. - * When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. + * When inline message is edited, new file can't be uploaded. + * Use previously uploaded file via its file_id or specify a URL. * On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned * * @param $chatId diff --git a/src/Types/Dice.php b/src/Types/Dice.php index 47c66f9b..5a715027 100644 --- a/src/Types/Dice.php +++ b/src/Types/Dice.php @@ -50,4 +50,4 @@ public function setValue($value) { $this->value = $value; } -} \ No newline at end of file +} From c18695580788b14a68de09c68bd3c945dbf086b4 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Thu, 23 Apr 2020 14:07:28 +0200 Subject: [PATCH 035/130] Added method sendDice and updated method sendPoll --- .travis.yml | 2 +- src/BotApi.php | 75 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 18950229..19ced7b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ matrix: before_script: - travis_retry composer self-update - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source + - COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source script: - php vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 src/ diff --git a/src/BotApi.php b/src/BotApi.php index ba040f43..9ba50db0 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1793,22 +1793,35 @@ public function setProxy($proxyString = '', $socks5 = false) * Use this method to send a native poll. A native poll can't be sent to a private chat. * On success, the sent \TelegramBot\Api\Types\Message is returned. * - * @param int|string $chatId - * @param string $question - * @param array $options - * @param bool $disableNotification - * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup - * + * @param $chatId string|int Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param string $question Poll question, 1-255 characters + * @param array $options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each + * @param bool $isAnonymous True, if the poll needs to be anonymous, defaults to True + * @param null $type Poll type, “quiz” or “regular”, defaults to “regular” + * @param bool $allowsMultipleAnswers True, if the poll allows multiple answers, + * ignored for polls in quiz mode, defaults to False + * @param null $correctOptionId 0-based identifier of the correct answer option, required for polls in quiz mode + * @param bool $isClosed Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. + * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param int|null $replyToMessageId If the message is a reply, ID of the original message + * @param null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, + * custom reply keyboard, instructions to remove reply + * keyboard or to force a reply from the user. * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException */ public function sendPoll( $chatId, $question, $options, + $isAnonymous = false, + $type = null, + $allowsMultipleAnswers = false, + $correctOptionId = null, + $isClosed = false, $disableNotification = false, $replyToMessageId = null, $replyMarkup = null @@ -1817,9 +1830,45 @@ public function sendPoll( 'chat_id' => $chatId, 'question' => $question, 'options' => json_encode($options), - 'disable_notification' => (bool)$disableNotification, - 'reply_to_message_id' => (int)$replyToMessageId, - 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'is_anonymous' => (bool) $isAnonymous, + 'type' => (string) $type, + 'allows_multiple_answers' => (bool) $allowsMultipleAnswers, + 'correct_option_id' => (int) $correctOptionId, + 'is_closed' => (bool) $isClosed, + 'disable_notification' => (bool) $disableNotification, + 'reply_to_message_id' => (int) $replyToMessageId, + 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), + ])); + } + + /** + * Use this method to send a dice, which will have a random value from 1 to 6. + * On success, the sent Message is returned. (Yes, we're aware of the “proper” singular of die. + * But it's awkward, and we decided to help it change. One dice at a time!) + * + * @param $chatId string|int Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param null $replyToMessageId If the message is a reply, ID of the original message + * @param null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, + * custom reply keyboard, instructions to remove reply + * keyboard or to force a reply from the user. + * @return bool|Message + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function sendDice( + $chatId, + $disableNotification = false, + $replyToMessageId = null, + $replyMarkup = null + ) { + return Message::fromResponse($this->call('sendDice', [ + 'chat_id' => $chatId, + 'disable_notification' => (bool) $disableNotification, + 'reply_to_message_id' => (int) $replyToMessageId, + 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), ])); } From 4b448ace6fd3d05429eee7a480f027a9189db987 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 10 Jun 2020 19:50:48 +0300 Subject: [PATCH 036/130] getWebhookInfo method --- src/BotApi.php | 15 +++ src/Types/WebhookInfo.php | 203 ++++++++++++++++++++++++++++++++++++++ tests/WebhookInfoTest.php | 34 +++++++ 3 files changed, 252 insertions(+) create mode 100644 src/Types/WebhookInfo.php create mode 100644 tests/WebhookInfoTest.php diff --git a/src/BotApi.php b/src/BotApi.php index 9ba50db0..a47557e3 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -16,6 +16,7 @@ use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\User; use TelegramBot\Api\Types\UserProfilePhotos; +use TelegramBot\Api\Types\WebhookInfo; /** * Class BotApi @@ -452,6 +453,20 @@ public function deleteWebhook() return $this->call('deleteWebhook'); } + /** + * Use this method to get current webhook status. Requires no parameters. + * On success, returns a WebhookInfo object. If the bot is using getUpdates, + * will return an object with the url field empty. + * + * @return \TelegramBot\Api\Types\WebhookInfo + * @throws \TelegramBot\Api\Exception + * @throws \TelegramBot\Api\InvalidArgumentException + */ + public function getWebhookInfo() + { + return WebhookInfo::fromResponse($this->call('getWebhookInfo')); + } + /** * A simple method for testing your bot's auth token.Requires no parameters. * Returns basic information about the bot in form of a User object. diff --git a/src/Types/WebhookInfo.php b/src/Types/WebhookInfo.php new file mode 100644 index 00000000..0354a193 --- /dev/null +++ b/src/Types/WebhookInfo.php @@ -0,0 +1,203 @@ + true, + 'has_custom_certificate' => true, + 'pending_update_count' => true, + 'last_error_date' => true, + 'last_error_message' => true, + 'max_connections' => true, + 'allowed_updates' => true + ]; + + /** + * Webhook URL, may be empty if webhook is not set up + * + * @var string + */ + protected $url; + + /** + * True, if a custom certificate was provided for webhook certificate checks + * + * @var bool + */ + protected $hasCustomCertificate; + + /** + * Number of updates awaiting delivery + * + * @var int + */ + protected $pendingUpdateCount; + + /** + * Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook + * + * @var int + */ + protected $lastErrorDate; + + /** + * Optional. Error message in human-readable format for the most recent error that happened when trying to deliver + * an update via webhook + * + * @var string + */ + protected $lastErrorMessage; + + /** + * Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery + * + * @var int + */ + protected $maxConnections; + + /** + * Optional. A list of update types the bot is subscribed to. Defaults to all update types + * + * @var array + */ + protected $allowedUpdates; + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * @return bool + */ + public function hasCustomCertificate() + { + return $this->hasCustomCertificate; + } + + /** + * @param bool $hasCustomCertificate + */ + public function setHasCustomCertificate($hasCustomCertificate) + { + $this->hasCustomCertificate = $hasCustomCertificate; + } + + /** + * @return int + */ + public function getPendingUpdateCount() + { + return $this->pendingUpdateCount; + } + + /** + * @param int $pendingUpdateCount + */ + public function setPendingUpdateCount($pendingUpdateCount) + { + $this->pendingUpdateCount = $pendingUpdateCount; + } + + /** + * @return int + */ + public function getLastErrorDate() + { + return $this->lastErrorDate; + } + + /** + * @param int $lastErrorDate + */ + public function setLastErrorDate($lastErrorDate) + { + $this->lastErrorDate = $lastErrorDate; + } + + /** + * @return string + */ + public function getLastErrorMessage() + { + return $this->lastErrorMessage; + } + + /** + * @param string $lastErrorMessage + */ + public function setLastErrorMessage($lastErrorMessage) + { + $this->lastErrorMessage = $lastErrorMessage; + } + + /** + * @return int + */ + public function getMaxConnections() + { + return $this->maxConnections; + } + + /** + * @param int $maxConnections + */ + public function setMaxConnections($maxConnections) + { + $this->maxConnections = $maxConnections; + } + + /** + * @return array + */ + public function getAllowedUpdates() + { + return $this->allowedUpdates; + } + + /** + * @param array $allowedUpdates + */ + public function setAllowedUpdates($allowedUpdates) + { + $this->allowedUpdates = $allowedUpdates; + } +} diff --git a/tests/WebhookInfoTest.php b/tests/WebhookInfoTest.php new file mode 100644 index 00000000..06aa277f --- /dev/null +++ b/tests/WebhookInfoTest.php @@ -0,0 +1,34 @@ + '', + 'has_custom_certificate' => false, + 'pending_update_count' => 0, + 'last_error_date' => null, + 'last_error_message' => null, + 'max_connections' => 40, + 'allowed_updates' => null + )); + $this->assertInstanceOf('\TelegramBot\Api\Types\WebhookInfo', $webhookInfo); + $this->assertEquals('', $webhookInfo->getUrl()); + $this->assertEquals(false, $webhookInfo->hasCustomCertificate()); + $this->assertEquals(0, $webhookInfo->getPendingUpdateCount()); + $this->assertEquals(null, $webhookInfo->getLastErrorDate()); + $this->assertEquals(null, $webhookInfo->getLastErrorMessage()); + $this->assertEquals(40, $webhookInfo->getMaxConnections()); + $this->assertEquals(null, $webhookInfo->getAllowedUpdates()); + } +} From 6a3452fa9968a155e3ff778f1d6c44fdfe7c431c Mon Sep 17 00:00:00 2001 From: BoShurik Date: Mon, 15 Jun 2020 19:27:13 +0300 Subject: [PATCH 037/130] Fix Message type --- src/Types/Message.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Types/Message.php b/src/Types/Message.php index 5c9875c4..fd8e4c94 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -67,7 +67,6 @@ class Message extends BaseType implements TypeInterface 'invoice' => Invoice::class, 'successful_payment' => SuccessfulPayment::class, 'connected_website' => true, - 'reply_markup' => InlineKeyboardMarkup::class, ]; /** From 198ed52ce70b128b09bcee2265d97f87327da827 Mon Sep 17 00:00:00 2001 From: Nikita Zarubin Date: Thu, 3 Sep 2020 17:58:34 +0300 Subject: [PATCH 038/130] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 086cc4e3..72f90a6d 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "telegram-bot/api", - "description": "PHP Wrapper for Telegram Bot API", + "name": "nikserg/telegram-bot-api", + "description": "PHP Wrapper for Telegram Bot API. poll_answer support added", "keywords": [ "php", "telegram", From 85dc4352b52bef9780fa7c38d26d84b94c5dc6ba Mon Sep 17 00:00:00 2001 From: Nikita Zarubin Date: Thu, 3 Sep 2020 18:02:36 +0300 Subject: [PATCH 039/130] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0b7f65a1..4f268e1d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ An extended native php wrapper for [Telegram Bot API](https://core.telegram.org/bots/api) without requirements. Supports all methods and types of responses. +## Fork notes + +Original package does not support `poll_answer` messages. Added this support. + ## Bots: An introduction for developers >Bots are special Telegram accounts designed to handle messages automatically. Users can interact with bots by sending them command messages in private or group chats. From c4b63f8ed7197b1f33dfdb7f1c18a9a3d67bdd70 Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 09:28:51 +0300 Subject: [PATCH 040/130] poll_answer --- src/Types/PollAnswerQuery.php | 122 ++++++++++++++++++++++++++++++++++ src/Types/Update.php | 23 +++++++ 2 files changed, 145 insertions(+) create mode 100644 src/Types/PollAnswerQuery.php diff --git a/src/Types/PollAnswerQuery.php b/src/Types/PollAnswerQuery.php new file mode 100644 index 00000000..9910ebc5 --- /dev/null +++ b/src/Types/PollAnswerQuery.php @@ -0,0 +1,122 @@ + true, + 'user' => User::class, + 'poll_id' => true, + ]; + + + + /** + * Sender + * + * @var \TelegramBot\Api\Types\User + */ + protected $user; + + /** + * + * @var int + */ + protected $poll_id; + + /** + * @var int[] + */ + protected $option_ids; + + + /** + * @return string + */ + public function getPollId() + { + return $this->poll_id; + } + + /** + * @param string $id + */ + public function setPollId($id) + { + $this->poll_id = $id; + } + + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $from + */ + public function setUser(User $from) + { + $this->user = $from; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->getUser(); + } + + /** + * @param User $from + */ + public function setFrom(User $from) + { + return $this->setUser($from); + } + + /** + * @return int[] + */ + public function getOptionIds() + { + return $this->option_ids; + } + + /** + * @param int[] $optionIds + */ + public function setOptionIds( $optionIds) + { + $this->option_ids = $optionIds; + } + + +} diff --git a/src/Types/Update.php b/src/Types/Update.php index 118a908b..9bc858a6 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -41,6 +41,7 @@ class Update extends BaseType implements TypeInterface 'callback_query' => CallbackQuery::class, 'shipping_query' => ShippingQuery::class, 'pre_checkout_query' => PreCheckoutQuery::class, + 'poll_answer' => PollAnswerQuery::class, ]; /** @@ -60,6 +61,12 @@ class Update extends BaseType implements TypeInterface */ protected $message; + /** + * @var PollAnswerQuery + */ + protected $poll_answer; + + /** * Optional. New version of a message that is known to the bot and was edited * @@ -180,6 +187,22 @@ public function setChannelPost($channelPost) $this->channelPost = $channelPost; } + /** + * @return Message + */ + public function getPollAnswer() + { + return $this->poll_answer; + } + + /** + * @param PollAnswerQuery $pollAnswer + */ + public function setPollAnswer($pollAnswer) + { + $this->poll_answer = $pollAnswer; + } + /** * @return Message */ From e55c1c5bb538d835ff51655902593c47b28dfa8c Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 10:46:31 +0300 Subject: [PATCH 041/130] poll --- src/Types/Update.php | 50 +++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/Types/Update.php b/src/Types/Update.php index 9bc858a6..5207e6c7 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -31,17 +31,18 @@ class Update extends BaseType implements TypeInterface * @var array */ static protected $map = [ - 'update_id' => true, - 'message' => Message::class, - 'edited_message' => Message::class, - 'channel_post' => Message::class, - 'edited_channel_post' => Message::class, - 'inline_query' => InlineQuery::class, + 'update_id' => true, + 'message' => Message::class, + 'edited_message' => Message::class, + 'channel_post' => Message::class, + 'edited_channel_post' => Message::class, + 'inline_query' => InlineQuery::class, 'chosen_inline_result' => ChosenInlineResult::class, - 'callback_query' => CallbackQuery::class, - 'shipping_query' => ShippingQuery::class, - 'pre_checkout_query' => PreCheckoutQuery::class, - 'poll_answer' => PollAnswerQuery::class, + 'callback_query' => CallbackQuery::class, + 'shipping_query' => ShippingQuery::class, + 'pre_checkout_query' => PreCheckoutQuery::class, + 'poll_answer' => PollAnswerQuery::class, + 'poll' => Poll::class, ]; /** @@ -64,7 +65,12 @@ class Update extends BaseType implements TypeInterface /** * @var PollAnswerQuery */ - protected $poll_answer; + protected $pollAnswer; + + /** + * @var Poll + */ + protected $poll; /** @@ -188,11 +194,27 @@ public function setChannelPost($channelPost) } /** - * @return Message + * @return PollAnswerQuery */ public function getPollAnswer() { - return $this->poll_answer; + return $this->pollAnswer; + } + + /** + * @return Poll + */ + public function getPoll() + { + return $this->poll; + } + + /** + * @param Poll $poll + */ + public function setPoll($poll) + { + $this->poll = $poll; } /** @@ -200,7 +222,7 @@ public function getPollAnswer() */ public function setPollAnswer($pollAnswer) { - $this->poll_answer = $pollAnswer; + $this->pollAnswer = $pollAnswer; } /** From 2578bd255f589c6306f7bf417f7a97ed334aa226 Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 11:30:54 +0300 Subject: [PATCH 042/130] Added support of `poll_answer` and `poll` attributes in Update class --- README.md | 4 --- composer.json | 4 +-- .../{PollAnswerQuery.php => PollAnswer.php} | 16 +++++------ src/Types/Update.php | 28 +++++++++---------- 4 files changed, 24 insertions(+), 28 deletions(-) rename src/Types/{PollAnswerQuery.php => PollAnswer.php} (85%) diff --git a/README.md b/README.md index 4f268e1d..0b7f65a1 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,6 @@ An extended native php wrapper for [Telegram Bot API](https://core.telegram.org/bots/api) without requirements. Supports all methods and types of responses. -## Fork notes - -Original package does not support `poll_answer` messages. Added this support. - ## Bots: An introduction for developers >Bots are special Telegram accounts designed to handle messages automatically. Users can interact with bots by sending them command messages in private or group chats. diff --git a/composer.json b/composer.json index 72f90a6d..086cc4e3 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "nikserg/telegram-bot-api", - "description": "PHP Wrapper for Telegram Bot API. poll_answer support added", + "name": "telegram-bot/api", + "description": "PHP Wrapper for Telegram Bot API", "keywords": [ "php", "telegram", diff --git a/src/Types/PollAnswerQuery.php b/src/Types/PollAnswer.php similarity index 85% rename from src/Types/PollAnswerQuery.php rename to src/Types/PollAnswer.php index 9910ebc5..6b4d5d2e 100644 --- a/src/Types/PollAnswerQuery.php +++ b/src/Types/PollAnswer.php @@ -12,7 +12,7 @@ * * @package TelegramBot\Api\Types */ -class PollAnswerQuery extends BaseType +class PollAnswer extends BaseType { /** * {@inheritdoc} @@ -29,7 +29,7 @@ class PollAnswerQuery extends BaseType static protected $map = [ 'option_ids' => true, 'user' => User::class, - 'poll_id' => true, + 'pollId' => true, ]; @@ -45,12 +45,12 @@ class PollAnswerQuery extends BaseType * * @var int */ - protected $poll_id; + protected $pollId; /** * @var int[] */ - protected $option_ids; + protected $optionIds; /** @@ -58,7 +58,7 @@ class PollAnswerQuery extends BaseType */ public function getPollId() { - return $this->poll_id; + return $this->pollId; } /** @@ -66,7 +66,7 @@ public function getPollId() */ public function setPollId($id) { - $this->poll_id = $id; + $this->pollId = $id; } @@ -107,7 +107,7 @@ public function setFrom(User $from) */ public function getOptionIds() { - return $this->option_ids; + return $this->optionIds; } /** @@ -115,7 +115,7 @@ public function getOptionIds() */ public function setOptionIds( $optionIds) { - $this->option_ids = $optionIds; + $this->optionIds = $optionIds; } diff --git a/src/Types/Update.php b/src/Types/Update.php index 5207e6c7..031d2b56 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -31,18 +31,18 @@ class Update extends BaseType implements TypeInterface * @var array */ static protected $map = [ - 'update_id' => true, - 'message' => Message::class, - 'edited_message' => Message::class, - 'channel_post' => Message::class, - 'edited_channel_post' => Message::class, - 'inline_query' => InlineQuery::class, + 'update_id' => true, + 'message' => Message::class, + 'edited_message' => Message::class, + 'channel_post' => Message::class, + 'edited_channel_post' => Message::class, + 'inline_query' => InlineQuery::class, 'chosen_inline_result' => ChosenInlineResult::class, - 'callback_query' => CallbackQuery::class, - 'shipping_query' => ShippingQuery::class, - 'pre_checkout_query' => PreCheckoutQuery::class, - 'poll_answer' => PollAnswerQuery::class, - 'poll' => Poll::class, + 'callback_query' => CallbackQuery::class, + 'shipping_query' => ShippingQuery::class, + 'pre_checkout_query' => PreCheckoutQuery::class, + 'poll_answer' => PollAnswer::class, + 'poll' => Poll::class, ]; /** @@ -63,7 +63,7 @@ class Update extends BaseType implements TypeInterface protected $message; /** - * @var PollAnswerQuery + * @var PollAnswer */ protected $pollAnswer; @@ -194,7 +194,7 @@ public function setChannelPost($channelPost) } /** - * @return PollAnswerQuery + * @return PollAnswer */ public function getPollAnswer() { @@ -218,7 +218,7 @@ public function setPoll($poll) } /** - * @param PollAnswerQuery $pollAnswer + * @param PollAnswer $pollAnswer */ public function setPollAnswer($pollAnswer) { From 2ef95f24feaab019779ca71df6409b83fe88f97c Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 11:39:38 +0300 Subject: [PATCH 043/130] Added support of `poll_answer` and `poll` attributes in Update class --- src/Types/PollAnswer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index 6b4d5d2e..a23f9e77 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -29,7 +29,7 @@ class PollAnswer extends BaseType static protected $map = [ 'option_ids' => true, 'user' => User::class, - 'pollId' => true, + 'poll_id' => true, ]; From c288c29fb0c6edabb56fa0b8dbef4c7f728866bc Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 11:43:11 +0300 Subject: [PATCH 044/130] Added support of `poll_answer` and `poll` attributes in Update class --- src/Types/PollAnswer.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index a23f9e77..241ba25b 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -4,12 +4,14 @@ use TelegramBot\Api\BaseType; - /** - * Class PollAnswerQuery + * Class PollAnswer + * + * @see https://core.telegram.org/bots/api#pollanswer * * Poll answer from user * + * * @package TelegramBot\Api\Types */ class PollAnswer extends BaseType From 0891fb0d1a5f6dece13bb22a67c069ca573f8cda Mon Sep 17 00:00:00 2001 From: eldarQa Date: Fri, 4 Sep 2020 11:18:50 +0200 Subject: [PATCH 045/130] Add LoginUrl type --- src/Types/LoginUrl.php | 122 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/Types/LoginUrl.php diff --git a/src/Types/LoginUrl.php b/src/Types/LoginUrl.php new file mode 100644 index 00000000..9dd372f7 --- /dev/null +++ b/src/Types/LoginUrl.php @@ -0,0 +1,122 @@ + true, + 'forward_text' => true, + 'bot_username' => true, + 'request_write_access' => true + ]; + + /** + * An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. + * + * @var string + */ + protected $url; + + /** + * Optional. New text of the button in forwarded messages. + * + * @var string + */ + protected $forwardText; + + /** + * Optional. Username of a bot, which will be used for user authorization + * + * @var string + */ + protected $botUsername; + + /** + * Optional. Pass True to request the permission for your bot to send messages to the user. + * + * @var bool + */ + protected $requestWriteAccess; + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * @return string + */ + public function getForwardText() + { + return $this->forwardText; + } + + /** + * @param string $forwardText + */ + public function setForwardText($forwardText) + { + $this->forwardText = $forwardText; + } + + /** + * @return string + */ + public function getBotUsername() + { + return $this->botUsername; + } + + /** + * @param string $botUsername + */ + public function setBotUsername($botUsername) + { + $this->botUsername = $botUsername; + } + + /** + * @return bool + */ + public function isRequestWriteAccess() + { + return $this->requestWriteAccess; + } + + /** + * @param bool $requestWriteAccess + */ + public function setRequestWriteAccess($requestWriteAccess) + { + $this->requestWriteAccess = $requestWriteAccess; + } +} From c9f8690f0a0f3c41b67865fb6e8dad2965b530a0 Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 12:28:02 +0300 Subject: [PATCH 046/130] Added support of `poll_answer` and `poll` attributes in Update class - formatting issues --- src/Types/PollAnswer.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index 241ba25b..7132d4f7 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -9,7 +9,7 @@ * * @see https://core.telegram.org/bots/api#pollanswer * - * Poll answer from user + * This object represents an answer of a user in a non-anonymous poll. * * * @package TelegramBot\Api\Types @@ -34,17 +34,12 @@ class PollAnswer extends BaseType 'poll_id' => true, ]; - - /** - * Sender - * * @var \TelegramBot\Api\Types\User */ protected $user; /** - * * @var int */ protected $pollId; @@ -54,7 +49,6 @@ class PollAnswer extends BaseType */ protected $optionIds; - /** * @return string */ @@ -71,7 +65,6 @@ public function setPollId($id) $this->pollId = $id; } - /** * @return User */ @@ -119,6 +112,4 @@ public function setOptionIds( $optionIds) { $this->optionIds = $optionIds; } - - } From 2bec77bdd688ee3a6a94d300283aa8bc82a39c41 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Fri, 4 Sep 2020 11:37:00 +0200 Subject: [PATCH 047/130] Add tests --- tests/LoginUrlTest.php | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/LoginUrlTest.php diff --git a/tests/LoginUrlTest.php b/tests/LoginUrlTest.php new file mode 100644 index 00000000..301a783d --- /dev/null +++ b/tests/LoginUrlTest.php @@ -0,0 +1,56 @@ +setUrl('https://telegram.org'); + + $this->assertAttributeEquals('https://telegram.org', 'url', $loginUrl); + } + + public function testGetForwardText() + { + $loginUrl = new LoginUrl(); + $loginUrl->setForwardText('Log in!'); + + $this->assertAttributeEquals('Log in!', 'forwardText', $loginUrl); + } + + public function testGetBotUsername() + { + $loginUrl = new LoginUrl(); + $loginUrl->setBotUsername('TestBot'); + + $this->assertAttributeEquals('TestBot', 'botUsername', $loginUrl); + } + + public function testGetRequestWriteAccess() + { + $loginUrl = new LoginUrl(); + $loginUrl->setRequestWriteAccess(true); + + $this->assertEquals(true, $loginUrl->isRequestWriteAccess()); + } + + public function testFromResponse() + { + $loginUrl = LoginUrl::fromResponse([ + 'url' => 'https://telegram.org', + 'forward_text' => 'Log in!', + 'bot_username' => 'TestBot', + 'request_write_access' => true + ]); + + $this->assertInstanceOf('\TelegramBot\Api\Types\LoginUrl', $loginUrl); + $this->assertEquals('https://telegram.org', $loginUrl->getUrl()); + $this->assertEquals('Log in!', $loginUrl->getForwardText()); + $this->assertEquals('TestBot', $loginUrl->getBotUsername()); + $this->assertEquals(true, $loginUrl->isRequestWriteAccess()); + } +} \ No newline at end of file From bc7ddbc75986b6c2633c977240e2cb19c4452033 Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 15:15:56 +0300 Subject: [PATCH 048/130] Added support of `poll_answer` and `poll` attributes in Update class - code styling --- src/Types/PollAnswer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index 7132d4f7..d840b123 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -108,7 +108,7 @@ public function getOptionIds() /** * @param int[] $optionIds */ - public function setOptionIds( $optionIds) + public function setOptionIds($optionIds) { $this->optionIds = $optionIds; } From d14db0ee18199794b9595465aff7fecc8bb4973f Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 15:20:28 +0300 Subject: [PATCH 049/130] Added support of `poll_answer` and `poll` attributes in Update class - code styling --- src/Types/PollAnswer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index d840b123..278f3317 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -40,7 +40,7 @@ class PollAnswer extends BaseType protected $user; /** - * @var int + * @var string */ protected $pollId; From acad100504377e3560e497239d3493d5c1a0d992 Mon Sep 17 00:00:00 2001 From: "n.zarubin" Date: Fri, 4 Sep 2020 15:29:04 +0300 Subject: [PATCH 050/130] Added support of `poll_answer` and `poll` attributes in Update class - testing --- tests/PollAnswerTest.php | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/PollAnswerTest.php diff --git a/tests/PollAnswerTest.php b/tests/PollAnswerTest.php new file mode 100644 index 00000000..754ceb10 --- /dev/null +++ b/tests/PollAnswerTest.php @@ -0,0 +1,45 @@ +setPollId(123456789); + + $this->assertEquals(123456789, $item->getPollId()); + } + + public function testGetUser() + { + $item = new PollAnswer(); + $user = new User(); + $user->setId(123456); + $item->setUser($user); + + $this->assertEquals(123456, $item->getUser()->getId()); + } + public function testGetFrom() + { + $item = new PollAnswer(); + $user = new User(); + $user->setId(123456); + $item->setFrom($user); + + $this->assertEquals(123456, $item->getFrom()->getId()); + } + public function testGetOptionIds() + { + $item = new PollAnswer(); + $item->setOptionIds([1,2,3,4,5,6]); + + $this->assertArraySubset([1,2,3,4,5,6], $item->getOptionIds()); + } + + +} From 337ca0ec66722180a3f1e99252f3d8dc4318beb5 Mon Sep 17 00:00:00 2001 From: Aj-github-cmd <55585727+Aj-github-cmd@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:54:26 +0530 Subject: [PATCH 051/130] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b7f65a1..3f0e5bf2 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ An extended native php wrapper for [Telegram Bot API](https://core.telegram.org/ >The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult [Introduction to Bots](https://core.telegram.org/bots) and [Bot FAQ](https://core.telegram.org/bots/faq). -## Install +## Installation Via Composer @@ -130,7 +130,7 @@ $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API $bot->track($message, $eventName); ``` -_You can use method `getUpdates()` and all incoming messages will be automatically tracked as `Message`-event_ + You can use method 'getUpdates()'and all incoming messages will be automatically tracked as `Message`-event. #### Client ```php From c8391064fe0349c5a9ee69e93066bf1709a2edb4 Mon Sep 17 00:00:00 2001 From: Alexey Buldyk Date: Mon, 5 Oct 2020 21:03:22 +0300 Subject: [PATCH 052/130] update MessageEntity.php --- src/Types/MessageEntity.php | 59 +++++++++++++++++++++++++++++-- tests/Types/MessageEntityTest.php | 58 ++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 tests/Types/MessageEntityTest.php diff --git a/src/Types/MessageEntity.php b/src/Types/MessageEntity.php index 453247a7..33bf0ea0 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -16,14 +16,19 @@ class MessageEntity extends BaseType implements TypeInterface const TYPE_MENTION = 'mention'; const TYPE_HASHTAG = 'hashtag'; + const TYPE_CASHTAG = 'cashtag'; const TYPE_BOT_COMMAND = 'bot_command'; const TYPE_URL = 'url'; const TYPE_EMAIL = 'email'; + const TYPE_PHONE_NUMBER = 'phone_number'; const TYPE_BOLD = 'bold'; const TYPE_ITALIC = 'italic'; + const TYPE_UNDERLINE = 'underline'; + const TYPE_STRIKETHROUGH = 'strikethrough'; const TYPE_CODE = 'code'; const TYPE_PRE = 'pre'; const TYPE_TEXT_LINK = 'text_link'; + const TYPE_TEXT_MENTION = 'text_mention'; /** * {@inheritdoc} @@ -42,12 +47,16 @@ class MessageEntity extends BaseType implements TypeInterface 'offset' => true, 'length' => true, 'url' => true, + 'user' => User::class, + 'language' => true, ]; /** * Type of the entity. - * One of mention (@username), hashtag, bot_command, url, email, bold (bold text), - * italic (italic text), code (monowidth string),pre (monowidth block), text_link (for clickable text URLs) + * One of mention (@username), hashtag (#hashtag), cashtag ($USD), bot_command, url, email, phone_number, + * bold (bold text), italic (italic text), underline (underlined text), strikethrough (strikethrough text), + * code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), + * text_mention (for users without usernames) * * @var string */ @@ -74,6 +83,20 @@ class MessageEntity extends BaseType implements TypeInterface */ protected $url; + /** + * Optional. For “text_mention” only, the mentioned user + * + * @var User + */ + protected $user; + + /** + * Optional. For “pre” only, the programming language of the entity text + * + * @var string + */ + protected $language; + /** * @return string */ @@ -137,4 +160,36 @@ public function setUrl($url) { $this->url = $url; } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $user + */ + public function setUser($user) + { + $this->user = $user; + } + + /** + * @return string + */ + public function getLanguage() + { + return $this->language; + } + + /** + * @param string $language + */ + public function setLanguage($language) + { + $this->language = $language; + } } diff --git a/tests/Types/MessageEntityTest.php b/tests/Types/MessageEntityTest.php new file mode 100644 index 00000000..2c7db907 --- /dev/null +++ b/tests/Types/MessageEntityTest.php @@ -0,0 +1,58 @@ + 'text_mention', + 'offset' => 108, + 'length' => 10, + 'user' => [ + 'id' => 4815162342, + 'is_bot' => false, + 'first_name' => 'John', + 'last_name' => 'Locke', + 'username' => 'hunter', + 'language_code' => 'en', + ], + ]); + + $this->assertInstanceOf(MessageEntity::class, $messageEntity); + $this->assertEquals(MessageEntity::TYPE_TEXT_MENTION, $messageEntity->getType()); + $this->assertEquals(108, $messageEntity->getOffset()); + $this->assertEquals(10, $messageEntity->getLength()); + $this->assertNull($messageEntity->getUrl()); + $this->assertInstanceOf(User::class, $messageEntity->getUser()); + $this->assertEquals(4815162342, $messageEntity->getUser()->getId()); + $this->assertFalse($messageEntity->getUser()->isBot()); + $this->assertEquals('John', $messageEntity->getUser()->getFirstName()); + $this->assertEquals('Locke', $messageEntity->getUser()->getLastName()); + $this->assertEquals('hunter', $messageEntity->getUser()->getUsername()); + $this->assertEquals('en', $messageEntity->getUser()->getLanguageCode()); + $this->assertNull($messageEntity->getLanguage()); + } + + public function testPreFromResponse() + { + $messageEntity = MessageEntity::fromResponse([ + 'type' => 'pre', + 'offset' => 16, + 'length' => 128, + 'language' => 'php', + ]); + + $this->assertInstanceOf(MessageEntity::class, $messageEntity); + $this->assertEquals(MessageEntity::TYPE_PRE, $messageEntity->getType()); + $this->assertEquals(16, $messageEntity->getOffset()); + $this->assertEquals(128, $messageEntity->getLength()); + $this->assertNull($messageEntity->getUrl()); + $this->assertNull($messageEntity->getUser()); + $this->assertEquals('php', $messageEntity->getLanguage()); + } +} From 57572a305acd6e0f47bfd6e2ca1aa5e6833f6dd2 Mon Sep 17 00:00:00 2001 From: Liza Date: Mon, 12 Oct 2020 14:52:57 +0300 Subject: [PATCH 053/130] Update README.md: add example of text messages handling --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 3f0e5bf2..acc49e29 100644 --- a/README.md +++ b/README.md @@ -89,10 +89,20 @@ try { // $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY'); + //Handle /ping command $bot->command('ping', function ($message) use ($bot) { $bot->sendMessage($message->getChat()->getId(), 'pong!'); }); + //Handle text messages + $bot->on(function (\TelegramBot\Api\Types\Update $ update) use ($bot) { + $message = $update->getMessage(); + $id = $message->getChat()->getId(); + $bot->sendMessage($id, 'Your message: ' . $message->getText()); + }, function () { + return true; + }); + $bot->run(); } catch (\TelegramBot\Api\Exception $e) { From f20c08642cd682cbb3f05ffa389a33320201ff45 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 30 Oct 2020 20:03:49 +0800 Subject: [PATCH 054/130] Update README.md Removed the extra space character in the message processing command. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index acc49e29..dba2979c 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ try { }); //Handle text messages - $bot->on(function (\TelegramBot\Api\Types\Update $ update) use ($bot) { + $bot->on(function (\TelegramBot\Api\Types\Update $update) use ($bot) { $message = $update->getMessage(); $id = $message->getChat()->getId(); $bot->sendMessage($id, 'Your message: ' . $message->getText()); From ee0ce704100bd2f267a2c25545b046392ed1947c Mon Sep 17 00:00:00 2001 From: eldarQa Date: Tue, 12 Jan 2021 17:23:59 +0100 Subject: [PATCH 055/130] Update types --- src/Types/Chat.php | 137 ++++++++++++++++++--- src/Types/ChatLocation.php | 72 +++++++++++ src/Types/ChatPermissions.php | 220 ++++++++++++++++++++++++++++++++++ src/Types/Contact.php | 28 ++++- src/Types/Dice.php | 31 ++++- src/Types/Location.php | 106 +++++++++++++++- tests/ChatLocationTest.php | 45 +++++++ tests/ChatTest.php | 29 ++--- tests/ContactTest.php | 14 +++ tests/LocationTest.php | 81 ++++++++++++- 10 files changed, 725 insertions(+), 38 deletions(-) create mode 100644 src/Types/ChatLocation.php create mode 100644 src/Types/ChatPermissions.php create mode 100644 tests/ChatLocationTest.php diff --git a/src/Types/Chat.php b/src/Types/Chat.php index f4db50cf..3e6ce001 100644 --- a/src/Types/Chat.php +++ b/src/Types/Chat.php @@ -27,13 +27,17 @@ class Chat extends BaseType implements TypeInterface 'username' => true, 'first_name' => true, 'last_name' => true, - 'all_members_are_administrators' => true, 'photo' => ChatPhoto::class, + 'bio' => true, 'description' => true, 'invite_link' => true, 'pinned_message' => Message::class, + 'permissions' => ChatPermissions::class, + 'slow_mode_delay' => true, 'sticker_set_name' => true, - 'can_set_sticker_set' => true + 'can_set_sticker_set' => true, + 'linked_chat_id' => true, + 'location' => ChatLocation::class ]; /** @@ -78,8 +82,6 @@ class Chat extends BaseType implements TypeInterface */ protected $lastName; - protected $allMembersAreAdministrators; - /** * Optional. Chat photo. Returned only in getChat. * @@ -87,6 +89,13 @@ class Chat extends BaseType implements TypeInterface */ protected $photo; + /** + * Optional. Bio of the other party in a private chat. Returned only in getChat + * + * @var string + */ + protected $bio; + /** * Optional. Description, for supergroups and channel chats. Returned only in getChat. * @@ -108,6 +117,21 @@ class Chat extends BaseType implements TypeInterface */ protected $pinnedMessage; + /** + * Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. + * + * @var ChatPermissions + */ + protected $permissions; + + /** + * Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged + * user. Returned only in getChat. + * + * @var int + */ + protected $slowModeDelay; + /** * Optional. For supergroups, name of group sticker set. Returned only in getChat. * @@ -122,6 +146,23 @@ class Chat extends BaseType implements TypeInterface */ protected $canSetStickerSet; + /** + * Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice + * versa; for supergroups and channel chats. This identifier may be greater than 32 bits and some programming + * languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 + * bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat. + * + * @var int + */ + protected $linkedChatId; + + /** + * Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. + * + * @var ChatLocation + */ + protected $location; + /** * @return int|string */ @@ -225,35 +266,35 @@ public function setLastName($lastName) } /** - * @return mixed + * @return ChatPhoto */ - public function getAllMembersAreAdministrators() + public function getPhoto() { - return $this->allMembersAreAdministrators; + return $this->photo; } /** - * @param mixed $allMembersAreAdministrators + * @param ChatPhoto $photo */ - public function setAllMembersAreAdministrators($allMembersAreAdministrators) + public function setPhoto($photo) { - $this->allMembersAreAdministrators = $allMembersAreAdministrators; + $this->photo = $photo; } /** - * @return ChatPhoto + * @return string */ - public function getPhoto() + public function getBio() { - return $this->photo; + return $this->bio; } /** - * @param ChatPhoto $photo + * @param string $bio */ - public function setPhoto($photo) + public function setBio($bio) { - $this->photo = $photo; + $this->bio = $bio; } /** @@ -304,6 +345,38 @@ public function setPinnedMessage($pinnedMessage) $this->pinnedMessage = $pinnedMessage; } + /** + * @return ChatPermissions + */ + public function getPermissions() + { + return $this->permissions; + } + + /** + * @param ChatPermissions $permissions + */ + public function setPermissions($permissions) + { + $this->permissions = $permissions; + } + + /** + * @return int + */ + public function getSlowModeDelay() + { + return $this->slowModeDelay; + } + + /** + * @param int $slowModeDelay + */ + public function setSlowModeDelay($slowModeDelay) + { + $this->slowModeDelay = $slowModeDelay; + } + /** * @return string */ @@ -335,4 +408,36 @@ public function setCanSetStickerSet($canSetStickerSet) { $this->canSetStickerSet = $canSetStickerSet; } + + /** + * @return int + */ + public function getLinkedChatId() + { + return $this->linkedChatId; + } + + /** + * @param int $linkedChatId + */ + public function setLinkedChatId($linkedChatId) + { + $this->linkedChatId = $linkedChatId; + } + + /** + * @return ChatLocation + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param ChatLocation $location + */ + public function setLocation($location) + { + $this->location = $location; + } } diff --git a/src/Types/ChatLocation.php b/src/Types/ChatLocation.php new file mode 100644 index 00000000..2330b982 --- /dev/null +++ b/src/Types/ChatLocation.php @@ -0,0 +1,72 @@ + Location::class, + 'address' => true, + ]; + + /** + * The location to which the supergroup is connected. Can't be a live location. + * + * @var Location + */ + protected $location; + + /** + * Location address; 1-64 characters, as defined by the chat owner + * + * @var string + */ + protected $address; + + /** + * @return Location + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param Location $location + */ + public function setLocation($location) + { + $this->location = $location; + } + + /** + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * @param string $address + */ + public function setAddress($address) + { + $this->address = $address; + } +} diff --git a/src/Types/ChatPermissions.php b/src/Types/ChatPermissions.php new file mode 100644 index 00000000..99bb6787 --- /dev/null +++ b/src/Types/ChatPermissions.php @@ -0,0 +1,220 @@ + true, + 'can_send_media_messages' => true, + 'can_send_polls' => true, + 'can_send_other_messages' => true, + 'can_add_web_page_previews' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_pin_messages' => true, + ]; + + /** + * Optional. True, if the user is allowed to send text messages, contacts, locations and venues + * + * @var bool + */ + protected $canSendMessages; + + /** + * Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, + * implies can_send_messages + * + * @var bool + */ + protected $canSendMediaMessages; + + /** + * Optional. True, if the user is allowed to send polls, implies can_send_messages + * + * @var bool + */ + protected $canSendPolls; + + /** + * Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, implies + * can_send_media_messages + * + * @var bool + */ + protected $canSendOtherMessages; + + /** + * Optional. True, if the user is allowed to add web page previews to their messages, implies + * can_send_media_messages + * + * @var bool + */ + protected $canAddWebPagePreviews; + + /** + * Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public + * supergroups + * + * @var bool + */ + protected $canChangeInfo; + + /** + * Optional. True, if the user is allowed to invite new users to the chat + * + * @var bool + */ + protected $canInviteUsers; + + /** + * Optional. True, if the user is allowed to pin messages. Ignored in public supergroups + * + * @var bool + */ + protected $canPinMessages; + + /** + * @return bool + */ + public function isCanSendMessages() + { + return $this->canSendMessages; + } + + /** + * @param bool $canSendMessages + */ + public function setCanSendMessages($canSendMessages) + { + $this->canSendMessages = $canSendMessages; + } + + /** + * @return bool + */ + public function isCanSendMediaMessages() + { + return $this->canSendMediaMessages; + } + + /** + * @param bool $canSendMediaMessages + */ + public function setCanSendMediaMessages($canSendMediaMessages) + { + $this->canSendMediaMessages = $canSendMediaMessages; + } + + /** + * @return bool + */ + public function isCanSendPolls() + { + return $this->canSendPolls; + } + + /** + * @param bool $canSendPolls + */ + public function setCanSendPolls($canSendPolls) + { + $this->canSendPolls = $canSendPolls; + } + + /** + * @return bool + */ + public function isCanSendOtherMessages() + { + return $this->canSendOtherMessages; + } + + /** + * @param bool $canSendOtherMessages + */ + public function setCanSendOtherMessages($canSendOtherMessages) + { + $this->canSendOtherMessages = $canSendOtherMessages; + } + + /** + * @return bool + */ + public function isCanAddWebPagePreviews() + { + return $this->canAddWebPagePreviews; + } + + /** + * @param bool $canAddWebPagePreviews + */ + public function setCanAddWebPagePreviews($canAddWebPagePreviews) + { + $this->canAddWebPagePreviews = $canAddWebPagePreviews; + } + + /** + * @return bool + */ + public function isCanChangeInfo() + { + return $this->canChangeInfo; + } + + /** + * @param bool $canChangeInfo + */ + public function setCanChangeInfo($canChangeInfo) + { + $this->canChangeInfo = $canChangeInfo; + } + + /** + * @return bool + */ + public function isCanInviteUsers() + { + return $this->canInviteUsers; + } + + /** + * @param bool $canInviteUsers + */ + public function setCanInviteUsers($canInviteUsers) + { + $this->canInviteUsers = $canInviteUsers; + } + + /** + * @return bool + */ + public function isCanPinMessages() + { + return $this->canPinMessages; + } + + /** + * @param bool $canPinMessages + */ + public function setCanPinMessages($canPinMessages) + { + $this->canPinMessages = $canPinMessages; + } +} diff --git a/src/Types/Contact.php b/src/Types/Contact.php index e9c5564a..884a255d 100644 --- a/src/Types/Contact.php +++ b/src/Types/Contact.php @@ -7,7 +7,7 @@ /** * Class Contact - * This object represents a sticker. + * This object represents a phone contact. * * @package TelegramBot\Api\Types */ @@ -29,7 +29,8 @@ class Contact extends BaseType implements TypeInterface 'phone_number' => true, 'first_name' => true, 'last_name' => true, - 'user_id' => true + 'user_id' => true, + 'vcard' => true, ]; /** @@ -60,6 +61,13 @@ class Contact extends BaseType implements TypeInterface */ protected $userId; + /** + * Optional. Additional data about the contact in the form of a vCard + * + * @var string + */ + protected $vCard; + /** * @return string */ @@ -123,4 +131,20 @@ public function setUserId($userId) { $this->userId = $userId; } + + /** + * @return string + */ + public function getVCard() + { + return $this->vCard; + } + + /** + * @param string $vCard + */ + public function setVCard($vCard) + { + $this->vCard = $vCard; + } } diff --git a/src/Types/Dice.php b/src/Types/Dice.php index 5a715027..ee2e089c 100644 --- a/src/Types/Dice.php +++ b/src/Types/Dice.php @@ -7,8 +7,7 @@ /** * Class Dice - * This object represents a dice with random value from 1 to 6. (Yes, we're aware of the “proper” singular of die. - * But it's awkward, and we decided to help it change. One dice at a time!) + * This object represents an animated emoji that displays a random value. */ class Dice extends BaseType implements TypeInterface { @@ -17,7 +16,7 @@ class Dice extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['value']; + static protected $requiredParams = ['emoji', 'value']; /** * {@inheritdoc} @@ -25,16 +24,40 @@ class Dice extends BaseType implements TypeInterface * @var array */ static protected $map = [ + 'emoji' => true, 'value' => true ]; /** - * Value of the dice, 1-6 + * Emoji on which the dice throw animation is based + * + * @var string + */ + protected $emoji; + + /** + * Value of the dice, 1-6 for “🎲” and “🎯” base emoji, 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji * * @var int */ protected $value; + /** + * @return string + */ + public function getEmoji() + { + return $this->emoji; + } + + /** + * @param string $emoji + */ + public function setEmoji($emoji) + { + $this->emoji = $emoji; + } + /** * @return int */ diff --git a/src/Types/Location.php b/src/Types/Location.php index 5c449c96..917009bc 100644 --- a/src/Types/Location.php +++ b/src/Types/Location.php @@ -28,7 +28,11 @@ class Location extends BaseType implements TypeInterface */ static protected $map = [ 'latitude' => true, - 'longitude' => true + 'longitude' => true, + 'horizontal_accuracy' => true, + 'live_period' => true, + 'heading' => true, + 'proximity_alert_radius' => true, ]; /** @@ -45,6 +49,36 @@ class Location extends BaseType implements TypeInterface */ protected $latitude; + /** + * Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + * + * @var float + */ + protected $horizontalAccuracy; + + /** + * Optional. Time relative to the message sending date, during which the location can be updated, in seconds. For + * active live locations only. + * + * @var int + */ + protected $livePeriod; + + /** + * Optional. The direction in which user is moving, in degrees; 1-360. For active live locations only. + * + * @var int + */ + protected $heading; + + /** + * Optional. Maximum distance for proximity alerts about approaching another chat member, in meters. For sent live + * locations only. + * + * @var int + */ + protected $proximityAlertRadius; + /** * @return float */ @@ -88,4 +122,74 @@ public function setLongitude($longitude) throw new InvalidArgumentException(); } } + + /** + * @return float + */ + public function getHorizontalAccuracy() + { + return $this->horizontalAccuracy; + } + + /** + * @param float $horizontalAccuracy + * + * @throws InvalidArgumentException + */ + public function setHorizontalAccuracy($horizontalAccuracy) + { + if (is_float($horizontalAccuracy)) { + $this->horizontalAccuracy = $horizontalAccuracy; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return int + */ + public function getLivePeriod() + { + return $this->livePeriod; + } + + /** + * @param int $livePeriod + */ + public function setLivePeriod($livePeriod) + { + $this->livePeriod = $livePeriod; + } + + /** + * @return int + */ + public function getHeading() + { + return $this->heading; + } + + /** + * @param int $heading + */ + public function setHeading($heading) + { + $this->heading = $heading; + } + + /** + * @return int + */ + public function getProximityAlertRadius() + { + return $this->proximityAlertRadius; + } + + /** + * @param int $proximityAlertRadius + */ + public function setProximityAlertRadius($proximityAlertRadius) + { + $this->proximityAlertRadius = $proximityAlertRadius; + } } diff --git a/tests/ChatLocationTest.php b/tests/ChatLocationTest.php new file mode 100644 index 00000000..bdef1251 --- /dev/null +++ b/tests/ChatLocationTest.php @@ -0,0 +1,45 @@ +setLatitude(55.585827); + $location->setLongitude(37.675309); + + $chatLocation->setLocation($location); + + $this->assertEquals($location, $chatLocation->getLocation()); + } + + public function testGetPollId() + { + $chatLocation = new ChatLocation(); + $chatLocation->setAddress('Wall St. 123'); + + $this->assertEquals('Wall St. 123', $chatLocation->getAddress()); + } + + public function testFromResponse() + { + $chatLocation = ChatLocation::fromResponse( + [ + 'location' => [ + 'latitdude' => 55.585827, + 'longtitude' => 37.675309, + ], + 'address' => 'Wall St. 123' + ] + ); + $this->assertInstanceOf('\TelegramBot\Api\Types\ChatLocation', $chatLocation); + $this->assertAttributeEquals('Wall St. 123', 'address', $chatLocation); + } +} diff --git a/tests/ChatTest.php b/tests/ChatTest.php index 0dd1ae90..d274ef12 100644 --- a/tests/ChatTest.php +++ b/tests/ChatTest.php @@ -112,20 +112,6 @@ public function testGetLastName() $this->assertEquals('Gusev', $chat->getLastName()); } - public function testSetAllMembersAreAdministrators() - { - $chat = new Chat(); - $chat->setAllMembersAreAdministrators(true); - $this->assertAttributeEquals(true, 'allMembersAreAdministrators', $chat); - } - - public function testGetAllMembersAreAdministrators() - { - $chat = new Chat(); - $chat->setAllMembersAreAdministrators(true); - $this->assertEquals(true, $chat->getAllMembersAreAdministrators()); - } - public function testSetPhoto() { $chat = new Chat(); @@ -148,6 +134,20 @@ public function testGetPhoto() $this->assertEquals($photo, $chat->getPhoto()); } + public function testSetBio() + { + $chat = new Chat(); + $chat->setBio('PHP Telegram Bot API'); + $this->assertAttributeEquals('PHP Telegram Bot API', 'bio', $chat); + } + + public function testGetBio() + { + $chat = new Chat(); + $chat->setBio('PHP Telegram Bot API'); + $this->assertEquals('PHP Telegram Bot API', $chat); + } + public function testSetDescriptions() { $chat = new Chat(); @@ -176,6 +176,7 @@ public function testFromResponseUser() $this->assertEquals('Ilya', $item->getFirstName()); $this->assertEquals('Gusev', $item->getLastName()); $this->assertEquals('iGusev', $item->getUsername()); + $this->assertEquals('PHP Telegram Bot API', $item->getBio()); } /** diff --git a/tests/ContactTest.php b/tests/ContactTest.php index 7aea3aec..4a1211f3 100644 --- a/tests/ContactTest.php +++ b/tests/ContactTest.php @@ -62,6 +62,20 @@ public function testGetUserId() $this->assertEquals('iGusev', $contact->getUserId()); } + public function testSetVCard() + { + $contact = new Contact(); + $contact->setVCard('testVCard'); + $this->assertAttributeEquals('testVCard', 'vCard', $contact); + } + + public function testGetVCard() + { + $contact = new Contact(); + $contact->setVCard('testVCard'); + $this->assertEquals('testVCard', $contact->getVCard()); + } + public function testFromResponse() { $contact = Contact::fromResponse(array( diff --git a/tests/LocationTest.php b/tests/LocationTest.php index 136e40e4..758d9f30 100644 --- a/tests/LocationTest.php +++ b/tests/LocationTest.php @@ -35,12 +35,90 @@ public function testGetLongtitude() $this->assertEquals(37.675309, $location->getLongitude()); } + public function testSetHorizontalAccuracy() + { + $location = new Location(); + $location->setHorizontalAccuracy(20.5); + $this->assertAttributeEquals(20.5, 'horizontal_accuracy', $location); + } + + public function testGetHorizontalAccuracy() + { + $location = new Location(); + $location->setHorizontalAccuracy(20.5); + $this->assertEquals(20.5, $location->getHorizontalAccuracy()); + } + + public function testSetLivePeriod() + { + $location = new Location(); + $location->setLivePeriod(300); + $this->assertAttributeEquals(300, 'live_period', $location); + } + + public function testGetLivePeriod() + { + $location = new Location(); + $location->setLivePeriod(300); + $this->assertEquals(300, $location->getLivePeriod()); + } + + public function testSetHeading() + { + $location = new Location(); + $location->setHeading(100); + $this->assertAttributeEquals(100, 'heading', $location); + } + + public function testGetHeading() + { + $location = new Location(); + $location->setHeading(100); + $this->assertEquals(100, $location->getHeading()); + } + + public function testSetProximityAlertRadius() + { + $location = new Location(); + $location->setProximityAlertRadius(15); + $this->assertAttributeEquals(15, 'proximity_alert_radius', $location); + } + + public function testGetProximityAlertRadius() + { + $location = new Location(); + $location->setProximityAlertRadius(100); + $this->assertEquals(15, $location->getProximityAlertRadius()); + } + public function testFromResponse() { - $location = Location::fromResponse(array("latitude" => 55.585827, 'longitude' => 37.675309)); + $location = Location::fromResponse( + array( + "latitude" => 55.585827, + 'longitude' => 37.675309, + 'horizontal_accuracy' => 20.5, + 'live_period' => 300, + 'heading' => 100, + 'proximity_alert_radius' => 15 + ) + ); $this->assertInstanceOf('\TelegramBot\Api\Types\Location', $location); $this->assertAttributeEquals(55.585827, 'latitude', $location); $this->assertAttributeEquals(37.675309, 'longitude', $location); + $this->assertAttributeEquals(20.5, 'horizontal_accuracy', $location); + $this->assertAttributeEquals(300, 'live_period', $location); + $this->assertAttributeEquals(100, 'heading', $location); + $this->assertAttributeEquals(15, 'proximity_alert_radius', $location); + } + + /** + * @expectedException \TelegramBot\Api\InvalidArgumentException + */ + public function testSetHorizontalAccuracyException() + { + $item = new Location(); + $item->setHorizontalAccuracy('s'); } /** @@ -51,6 +129,7 @@ public function testSetLatitudeException() $item = new Location(); $item->setLatitude('s'); } + /** * @expectedException \TelegramBot\Api\InvalidArgumentException */ From fbcf948f8c53f140876232e713d996b52f709dc2 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Tue, 12 Jan 2021 18:00:20 +0100 Subject: [PATCH 056/130] fix tests --- tests/ChatLocationTest.php | 6 +++--- tests/ChatTest.php | 6 ++++-- tests/LocationTest.php | 15 +++++++-------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/ChatLocationTest.php b/tests/ChatLocationTest.php index bdef1251..a9693311 100644 --- a/tests/ChatLocationTest.php +++ b/tests/ChatLocationTest.php @@ -20,7 +20,7 @@ public function testGetLocation() $this->assertEquals($location, $chatLocation->getLocation()); } - public function testGetPollId() + public function testGetAddress() { $chatLocation = new ChatLocation(); $chatLocation->setAddress('Wall St. 123'); @@ -33,8 +33,8 @@ public function testFromResponse() $chatLocation = ChatLocation::fromResponse( [ 'location' => [ - 'latitdude' => 55.585827, - 'longtitude' => 37.675309, + 'latitude' => 55.585827, + 'longitude' => 37.675309, ], 'address' => 'Wall St. 123' ] diff --git a/tests/ChatTest.php b/tests/ChatTest.php index d274ef12..b0b463ea 100644 --- a/tests/ChatTest.php +++ b/tests/ChatTest.php @@ -145,7 +145,7 @@ public function testGetBio() { $chat = new Chat(); $chat->setBio('PHP Telegram Bot API'); - $this->assertEquals('PHP Telegram Bot API', $chat); + $this->assertEquals('PHP Telegram Bot API', $chat->getBio()); } public function testSetDescriptions() @@ -169,8 +169,10 @@ public function testFromResponseUser() 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev', - 'type' => 'private' + 'type' => 'private', + 'bio' => 'PHP Telegram Bot API' )); + $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item); $this->assertEquals(123456, $item->getId()); $this->assertEquals('Ilya', $item->getFirstName()); diff --git a/tests/LocationTest.php b/tests/LocationTest.php index 758d9f30..322c5639 100644 --- a/tests/LocationTest.php +++ b/tests/LocationTest.php @@ -2,7 +2,6 @@ namespace TelegramBot\Api\Test; - use TelegramBot\Api\Types\Location; class LocationTest extends \PHPUnit_Framework_TestCase @@ -39,7 +38,7 @@ public function testSetHorizontalAccuracy() { $location = new Location(); $location->setHorizontalAccuracy(20.5); - $this->assertAttributeEquals(20.5, 'horizontal_accuracy', $location); + $this->assertAttributeEquals(20.5, 'horizontalAccuracy', $location); } public function testGetHorizontalAccuracy() @@ -53,7 +52,7 @@ public function testSetLivePeriod() { $location = new Location(); $location->setLivePeriod(300); - $this->assertAttributeEquals(300, 'live_period', $location); + $this->assertAttributeEquals(300, 'livePeriod', $location); } public function testGetLivePeriod() @@ -81,14 +80,14 @@ public function testSetProximityAlertRadius() { $location = new Location(); $location->setProximityAlertRadius(15); - $this->assertAttributeEquals(15, 'proximity_alert_radius', $location); + $this->assertAttributeEquals(15, 'proximityAlertRadius', $location); } public function testGetProximityAlertRadius() { $location = new Location(); $location->setProximityAlertRadius(100); - $this->assertEquals(15, $location->getProximityAlertRadius()); + $this->assertEquals(100, $location->getProximityAlertRadius()); } public function testFromResponse() @@ -106,10 +105,10 @@ public function testFromResponse() $this->assertInstanceOf('\TelegramBot\Api\Types\Location', $location); $this->assertAttributeEquals(55.585827, 'latitude', $location); $this->assertAttributeEquals(37.675309, 'longitude', $location); - $this->assertAttributeEquals(20.5, 'horizontal_accuracy', $location); - $this->assertAttributeEquals(300, 'live_period', $location); + $this->assertAttributeEquals(20.5, 'horizontalAccuracy', $location); + $this->assertAttributeEquals(300, 'livePeriod', $location); $this->assertAttributeEquals(100, 'heading', $location); - $this->assertAttributeEquals(15, 'proximity_alert_radius', $location); + $this->assertAttributeEquals(15, 'proximityAlertRadius', $location); } /** From 4718e8a8e042ab8319f025324a644bf6475e02c9 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Wed, 13 Jan 2021 14:03:23 +0100 Subject: [PATCH 057/130] Add copyMessage method --- src/BotApi.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/BotApi.php b/src/BotApi.php index 53fb398e..e7d51756 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -3,6 +3,7 @@ namespace TelegramBot\Api; use TelegramBot\Api\Types\ArrayOfChatMemberEntity; +use TelegramBot\Api\Types\ArrayOfMessageEntity; use TelegramBot\Api\Types\ArrayOfMessages; use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\Chat; @@ -341,6 +342,50 @@ public function sendMessage( ])); } + /** + * @param int|string $chatId + * @param int|string $fromChatId + * @param int $messageId + * @param string|null $caption + * @param string|null $parseMode + * @param ArrayOfMessageEntity|null $captionEntities + * @param bool $disableNotification + * @param int|null $replyToMessageId + * @param bool $allowSendingWithoutReply + * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| + * Types\ReplyKeyboardRemove|null $replyMarkup + * + * @return Message + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function copyMessage( + $chatId, + $fromChatId, + $messageId, + $caption = null, + $parseMode = null, + $captionEntities = null, + $disableNotification = false, + $replyToMessageId = null, + $allowSendingWithoutReply = false, + $replyMarkup = null + ) { + return Message::fromResponse($this->call('sendMessage', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_id' => (int)$messageId, + 'caption' => $caption, + 'parse_mode' => $parseMode, + 'caption_entities' => $captionEntities, + 'disable_notification' => (bool)$disableNotification, + 'reply_to_message_id' => (int)$replyToMessageId, + 'allow_sending_without_reply' => (bool)$allowSendingWithoutReply, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ])); + } + /** * Use this method to send phone contacts * From d8df84944284c1a125e535ad5fed5041390a7b0d Mon Sep 17 00:00:00 2001 From: eldarQa Date: Wed, 13 Jan 2021 15:09:26 +0100 Subject: [PATCH 058/130] Patch: fix copyMessage method --- src/BotApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index e7d51756..c79f0eb7 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -372,7 +372,7 @@ public function copyMessage( $allowSendingWithoutReply = false, $replyMarkup = null ) { - return Message::fromResponse($this->call('sendMessage', [ + return Message::fromResponse($this->call('copyMessage', [ 'chat_id' => $chatId, 'from_chat_id' => $fromChatId, 'message_id' => (int)$messageId, From ae0c41b1ee2bf376dee93f3228ef494349568c81 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Sat, 23 Jan 2021 14:45:12 +0100 Subject: [PATCH 059/130] Add BotCommand type, setMyCommands and getMyCommands methods --- src/BotApi.php | 34 ++++++++++++++++ src/Types/ArrayOfBotCommand.php | 16 ++++++++ src/Types/BotCommand.php | 72 +++++++++++++++++++++++++++++++++ tests/BotCommandTest.php | 50 +++++++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 src/Types/ArrayOfBotCommand.php create mode 100644 src/Types/BotCommand.php create mode 100644 tests/BotCommandTest.php diff --git a/src/BotApi.php b/src/BotApi.php index c79f0eb7..2f2e82eb 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -2,6 +2,7 @@ namespace TelegramBot\Api; +use TelegramBot\Api\Types\ArrayOfBotCommand; use TelegramBot\Api\Types\ArrayOfChatMemberEntity; use TelegramBot\Api\Types\ArrayOfMessageEntity; use TelegramBot\Api\Types\ArrayOfMessages; @@ -1138,6 +1139,39 @@ public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = ]); } + /** + * Use this method to change the list of the bot's commands. Returns True on success. + * + * @param $commands + * + * @return mixed + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function setMyCommands($commands) + { + return $this->call( + 'setMyCommands', + [ + 'commands' => json_encode($commands) + ] + ); + } + + /** + * Use this method to get the current list of the bot's commands. Requires no parameters. + * Returns Array of BotCommand on success. + * + * @return mixed + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function getMyCommands() + { + return ArrayOfBotCommand::fromResponse($this->call('getMyCommands')); + } /** * Use this method to edit text messages sent by the bot or via the bot diff --git a/src/Types/ArrayOfBotCommand.php b/src/Types/ArrayOfBotCommand.php new file mode 100644 index 00000000..42923a7f --- /dev/null +++ b/src/Types/ArrayOfBotCommand.php @@ -0,0 +1,16 @@ + true, + 'description' => true, + ]; + + /** + * Text of the command, 1-32 characters. Can contain only lowercase English letters, digits and underscores. + * + * @var string + */ + protected $command; + + /** + * Description of the command, 3-256 characters. + * + * @var string + */ + protected $description; + + /** + * @return string + */ + public function getCommand() + { + return $this->command; + } + + /** + * @param string $command + */ + public function setCommand($command) + { + $this->command = $command; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + */ + public function setDescription($description) + { + $this->description = $description; + } +} diff --git a/tests/BotCommandTest.php b/tests/BotCommandTest.php new file mode 100644 index 00000000..d8d98502 --- /dev/null +++ b/tests/BotCommandTest.php @@ -0,0 +1,50 @@ +setCommand('start'); + $this->assertAttributeEquals('start', 'command', $item); + } + + public function testGetCommand() + { + $item = new BotCommand(); + $item->setCommand('start'); + $this->assertEquals('start', $item->getCommand()); + } + + public function testSetDescription() + { + $item = new BotCommand(); + $item->setDescription('This is a start command!'); + $this->assertAttributeEquals('This is a start command!', 'description', $item); + } + + public function testGetDescription() + { + $item = new BotCommand(); + $item->setDescription('This is a start command!'); + $this->assertEquals('This is a start command!', $item->getDescription()); + } + + public function testFromResponse() + { + $botCommand = BotCommand::fromResponse( + [ + 'command' => 'start', + 'description' => 'This is a start command!', + ] + ); + + $this->assertInstanceOf('\TelegramBot\Api\Types\BotCommand', $botCommand); + $this->assertEquals('start', $botCommand->getCommand()); + $this->assertEquals('This is a start command!', $botCommand->getDescription()); + } +} From bbc0f164cb41746e44b300f489d46bd42b0688e9 Mon Sep 17 00:00:00 2001 From: eldarQa Date: Tue, 9 Mar 2021 08:13:14 +0100 Subject: [PATCH 060/130] Update sendVoice & sendDice methods --- src/BotApi.php | 29 +++++++++++++++++++++++------ src/Types/Voice.php | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 2f2e82eb..abadba90 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -812,14 +812,17 @@ public function sendAnimation( * On success, the sent Message is returned. * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. * - * @param int|string $chatId chat_id or @channel_name + * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $voice - * @param int|null $duration - * @param int|null $replyToMessageId + * @param string $caption Voice message caption, 0-1024 characters after entities parsing + * @param int|null $duration + * @param int|null $replyToMessageId * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| * Types\ReplyKeyboardRemove|null $replyMarkup - * @param bool $disableNotification - * @param string|null $parseMode + * @param bool $disableNotification + * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified + * replied-to message is not found + * @param string|null $parseMode * * @return \TelegramBot\Api\Types\Message * @throws \TelegramBot\Api\InvalidArgumentException @@ -828,19 +831,23 @@ public function sendAnimation( public function sendVoice( $chatId, $voice, + $caption = null, $duration = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, + $allowSendingWithoutReply = false, $parseMode = null ) { return Message::fromResponse($this->call('sendVoice', [ 'chat_id' => $chatId, 'voice' => $voice, + 'caption' => $caption, 'duration' => $duration, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, + 'allow_sending_without_reply' => $allowSendingWithoutReply, 'parse_mode' => $parseMode ])); } @@ -1943,13 +1950,19 @@ public function sendPoll( * On success, the sent Message is returned. (Yes, we're aware of the “proper” singular of die. * But it's awkward, and we decided to help it change. One dice at a time!) * - * @param $chatId string|int Unique identifier for the target chat or username of the target channel + * @param $chatId string|int Unique identifier for the target chat or username of the target channel * (in the format @channelusername) + * @param $emoji string Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, + * “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and + * values 1-64 for “🎰”. Defaults to “🎲 * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param null $replyToMessageId If the message is a reply, ID of the original message + * @param bool $$allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to + * message is not found, * @param null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, * custom reply keyboard, instructions to remove reply * keyboard or to force a reply from the user. + * * @return bool|Message * @throws Exception * @throws HttpException @@ -1957,14 +1970,18 @@ public function sendPoll( */ public function sendDice( $chatId, + $emoji, $disableNotification = false, $replyToMessageId = null, + $allowSendingWithoutReply = false, $replyMarkup = null ) { return Message::fromResponse($this->call('sendDice', [ 'chat_id' => $chatId, + 'emoji' => $emoji, 'disable_notification' => (bool) $disableNotification, 'reply_to_message_id' => (int) $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), ])); } diff --git a/src/Types/Voice.php b/src/Types/Voice.php index f4227b2b..0b1f5e92 100644 --- a/src/Types/Voice.php +++ b/src/Types/Voice.php @@ -19,7 +19,7 @@ class Voice extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'duration']; + static protected $requiredParams = ['file_id', 'file_unique_id', 'duration']; /** * {@inheritdoc} @@ -27,19 +27,28 @@ class Voice extends BaseType implements TypeInterface * @var array */ static protected $map = [ - 'file_id' => true, - 'duration' => true, - 'mime_type' => true, - 'file_size' => true + 'file_id' => true, + 'file_unique_id' => true, + 'duration' => true, + 'mime_type' => true, + 'file_size' => true, ]; /** - * Unique identifier for this file + * Identifier for this file, which can be used to download or reuse the file * * @var string */ protected $fileId; + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be + * used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + /** * Duration of the audio in seconds as defined by sender * @@ -77,6 +86,22 @@ public function setFileId($fileId) $this->fileId = $fileId; } + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + /** * @return int */ From 804ee2a5ea69e49411998cac01bf9983c40813df Mon Sep 17 00:00:00 2001 From: eldarQa Date: Tue, 9 Mar 2021 08:23:51 +0100 Subject: [PATCH 061/130] Update tests --- tests/MessageTest.php | 26 ++++++++++++++++++++++++++ tests/VoiceTest.php | 16 ++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 49904fbb..a122e12f 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -3,6 +3,7 @@ namespace TelegramBot\Api\Test; use TelegramBot\Api\Types\Chat; +use TelegramBot\Api\Types\Dice; use TelegramBot\Api\Types\Document; use TelegramBot\Api\Types\Location; use TelegramBot\Api\Types\Audio; @@ -304,6 +305,7 @@ public function testSetVoice() $item = new Message(); $voice = Voice::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testUniqueFileId', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 @@ -317,6 +319,7 @@ public function testGetVoice() $item = new Message(); $voice = Voice::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testUniqueFileId', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 @@ -369,6 +372,29 @@ public function testGetVideo() $this->assertInstanceOf('\TelegramBot\Api\Types\Video', $item->getVideo()); } + public function testSetDice() + { + $item = new Message(); + $dice = Dice::fromResponse(array( + 'emoji' => '🎲', + 'value' => 3 + )); + $item->setDice($dice); + $this->assertAttributeEquals($dice, 'dice', $item); + } + + public function testGetDice() + { + $item = new Message(); + $dice = Dice::fromResponse(array( + 'emoji' => '🎲', + 'value' => 3 + )); + $item->setDice($dice); + $this->assertEquals($dice, $item->getDice()); + $this->assertInstanceOf('\TelegramBot\Api\Types\Dice', $item->getDice()); + } + public function testSetSticker() { $item = new Message(); diff --git a/tests/VoiceTest.php b/tests/VoiceTest.php index 35ac39f6..654227a0 100644 --- a/tests/VoiceTest.php +++ b/tests/VoiceTest.php @@ -19,6 +19,20 @@ public function testGetFileId() $this->assertEquals('testfileId', $item->getFileId()); } + public function testSetUniqueFileId() + { + $item = new Voice(); + $item->setFileUniqueId('fileUniqueId'); + $this->assertAttributeEquals('fileUniqueId', 'fileUniqueId', $item); + } + + public function testGetUniqueFileId() + { + $item = new Voice(); + $item->setFileUniqueId('fileUniqueId'); + $this->assertEquals('fileUniqueId', $item->getFileUniqueId()); + } + public function testSetDuration() { $item = new Voice(); @@ -65,12 +79,14 @@ public function testFromResponse() { $item = Voice::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 )); $this->assertInstanceOf('\TelegramBot\Api\Types\Voice', $item); $this->assertAttributeEquals('testFileId1', 'fileId', $item); + $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item); $this->assertAttributeEquals(1, 'duration', $item); $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); $this->assertAttributeEquals(3, 'fileSize', $item); From 5075a7414b07ad6517c8eea2dc9b12d383ad7256 Mon Sep 17 00:00:00 2001 From: Alexander Reznikov Date: Tue, 16 Mar 2021 14:50:03 +0300 Subject: [PATCH 062/130] Support via_bot field of Message structure --- src/Types/Message.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Types/Message.php b/src/Types/Message.php index fd8e4c94..7fb41789 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -34,6 +34,7 @@ class Message extends BaseType implements TypeInterface 'forward_signature' => true, 'forward_sender_name' => true, 'reply_to_message' => Message::class, + 'via_bot' => User::class, 'edit_date' => true, 'media_group_id' => true, 'author_signature' => true, @@ -150,6 +151,13 @@ class Message extends BaseType implements TypeInterface */ protected $replyToMessage; + /** + * Optional. Bot through which the message was sent. + * + * @var \TelegramBot\Api\Types\User + */ + protected $via_bot; + /** * Optional. Date the message was last edited in Unix time * @@ -591,6 +599,22 @@ public function setReplyToMessage(Message $replyToMessage) $this->replyToMessage = $replyToMessage; } + /** + * @return User + */ + public function getViaBot() + { + return $this->via_bot; + } + + /** + * @param User $via_bot + */ + public function setViaBot(User $via_bot) + { + $this->via_bot = $via_bot; + } + /** * @return int */ From 16704b11f7bf66cca5d77f0f25cf1bb2cfbf7263 Mon Sep 17 00:00:00 2001 From: Alexander Reznikov Date: Tue, 16 Mar 2021 23:43:03 +0300 Subject: [PATCH 063/130] Update Message.php Some cosmetic changes --- src/Types/Message.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Types/Message.php b/src/Types/Message.php index 7fb41789..876c3e8a 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -156,7 +156,7 @@ class Message extends BaseType implements TypeInterface * * @var \TelegramBot\Api\Types\User */ - protected $via_bot; + protected $viaBot; /** * Optional. Date the message was last edited in Unix time @@ -604,15 +604,15 @@ public function setReplyToMessage(Message $replyToMessage) */ public function getViaBot() { - return $this->via_bot; + return $this->viaBot; } /** - * @param User $via_bot + * @param User $viaBot */ - public function setViaBot(User $via_bot) + public function setViaBot(User $viaBot) { - $this->via_bot = $via_bot; + $this->viaBot = $viaBot; } /** From 7957db6f49777b79d1b06e01c0e9403fd6020189 Mon Sep 17 00:00:00 2001 From: Alexander Reznikov Date: Tue, 16 Mar 2021 23:43:23 +0300 Subject: [PATCH 064/130] Update MessageTest.php via_bot tests added --- tests/MessageTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/MessageTest.php b/tests/MessageTest.php index a122e12f..ec6f3d66 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -605,6 +605,35 @@ public function testGetReplyToMessage() $this->assertInstanceOf('\TelegramBot\Api\Types\Message', $item->getReplyToMessage()); } + public function testSetViaBot() + { + $item = new Message(); + $bot = User::fromResponse(array( + 'first_name' => 'Test', + 'last_name' => 'Bot', + 'username' => 'TestingBot', + 'is_bot' => 'true', + 'id' => 654321 + )); + $item->setViaBot($bot); + $this->assertAttributeEquals($bot, 'via_bot', $item); + } + + public function testGetViaBot() + { + $item = new Message(); + $bot = User::fromResponse(array( + 'first_name' => 'Test', + 'last_name' => 'Bot', + 'username' => 'TestingBot', + 'is_bot' => 'true', + 'id' => 654321 + )); + $item->setViaBot($bot); + $this->assertEquals($bot, $item->getViaBot()); + $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getViaBot()); + } + public function testSetPhoto() { $item = new Message(); From 985608a8876e58dd57ae79aa12e9b729c689b96b Mon Sep 17 00:00:00 2001 From: Alexander Reznikov Date: Tue, 16 Mar 2021 23:57:34 +0300 Subject: [PATCH 065/130] Update MessageTest.php fix type, add complete from message test --- tests/MessageTest.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/MessageTest.php b/tests/MessageTest.php index ec6f3d66..5419a907 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -616,7 +616,7 @@ public function testSetViaBot() 'id' => 654321 )); $item->setViaBot($bot); - $this->assertAttributeEquals($bot, 'via_bot', $item); + $this->assertAttributeEquals($bot, 'viaBot', $item); } public function testGetViaBot() @@ -634,6 +634,34 @@ public function testGetViaBot() $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getViaBot()); } + public function testViaBotMessage() + { + $item = new Message(); + $item = Message::fromResponse(array( + 'message_id' => 1, + 'from' => array( + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'id' => 123456, + 'username' => 'iGusev' + ), + 'date' => 2, + 'chat' => array( + 'id' => 1, + 'type' => 'group', + 'title' => 'test chat' + ), + 'via_bot' => array( + 'first_name' => 'Test', + 'last_name' => 'Bot', + 'username' => 'TestingBot', + 'is_bot' => 'true', + 'id' => 654321 + ) + )); + $this->assertEquals(654321, $item->getViaBot()->getId()); + } + public function testSetPhoto() { $item = new Message(); From 71f391c282074fbb7dfda8b294d675208304ce8f Mon Sep 17 00:00:00 2001 From: Andrey Mistulov Date: Wed, 15 Sep 2021 18:21:19 +0300 Subject: [PATCH 066/130] Fix vcard field in Contact (lowercase is correct) --- src/Types/Contact.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Types/Contact.php b/src/Types/Contact.php index 884a255d..ea195ce5 100644 --- a/src/Types/Contact.php +++ b/src/Types/Contact.php @@ -66,7 +66,7 @@ class Contact extends BaseType implements TypeInterface * * @var string */ - protected $vCard; + protected $vcard; /** * @return string @@ -137,14 +137,14 @@ public function setUserId($userId) */ public function getVCard() { - return $this->vCard; + return $this->vcard; } /** - * @param string $vCard + * @param string $vcard */ - public function setVCard($vCard) + public function setVCard($vcard) { - $this->vCard = $vCard; + $this->vcard = $vcard; } } From a7cd162090b07b2b0fd3599d607276b6ddfd282b Mon Sep 17 00:00:00 2001 From: Andrey Mistulov Date: Mon, 20 Sep 2021 21:55:54 +0300 Subject: [PATCH 067/130] Ability to set timeout with data, increased default timeout up to 10 sec --- src/BotApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index abadba90..2d6b5811 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -217,7 +217,7 @@ public function call($method, array $data = null) CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => null, CURLOPT_POSTFIELDS => null, - CURLOPT_TIMEOUT => 5, + CURLOPT_TIMEOUT => $data['timeout'] ? (int)$data['timeout'] : 10, ]; if ($data) { From be7408dec7641e4af34b15b51336b29506c825cd Mon Sep 17 00:00:00 2001 From: Andrey Mistulov Date: Tue, 21 Sep 2021 07:18:23 +0300 Subject: [PATCH 068/130] Ability to set timeout with data --- src/BotApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index 2d6b5811..f96d4286 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -217,7 +217,7 @@ public function call($method, array $data = null) CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => null, CURLOPT_POSTFIELDS => null, - CURLOPT_TIMEOUT => $data['timeout'] ? (int)$data['timeout'] : 10, + CURLOPT_TIMEOUT => isset($data['timeout']) ? (int)$data['timeout'] : 10, ]; if ($data) { From c406284b6481c716c2c2d88966e08b243b6d75b1 Mon Sep 17 00:00:00 2001 From: Andrey Mistulov Date: Sat, 9 Oct 2021 17:48:21 +0300 Subject: [PATCH 069/130] Rollback ability to set timeout from data --- src/BotApi.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index f96d4286..556a1761 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -210,14 +210,14 @@ public function setModeObject($mode = true) * @throws \TelegramBot\Api\HttpException * @throws \TelegramBot\Api\InvalidJsonException */ - public function call($method, array $data = null) + public function call($method, array $data = null, $timeout = 10) { $options = $this->proxySettings + [ CURLOPT_URL => $this->getUrl().'/'.$method, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => null, CURLOPT_POSTFIELDS => null, - CURLOPT_TIMEOUT => isset($data['timeout']) ? (int)$data['timeout'] : 10, + CURLOPT_TIMEOUT => $timeout, ]; if ($data) { From 95c80c86eb77adc5c99efc5593eda6e95fab0d5d Mon Sep 17 00:00:00 2001 From: BoShurik Date: Fri, 5 Nov 2021 13:15:07 +0300 Subject: [PATCH 070/130] Fix doc types --- src/BotApi.php | 16 ++++++++-------- src/Types/InputMedia/InputMediaPhoto.php | 4 ++-- src/Types/InputMedia/InputMediaVideo.php | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index abadba90..bfbd9860 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1132,7 +1132,7 @@ public function unbanChatMember($chatId, $userId) * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. * * @param $callbackQueryId - * @param null $text + * @param string|null $text * @param bool $showAlert * * @return bool @@ -1257,8 +1257,8 @@ public function editMessageCaption( * @param $chatId * @param $messageId * @param InputMedia $media - * @param null $inlineMessageId - * @param null $replyMarkup + * @param string|null $inlineMessageId + * @param string|null $replyMarkup * @return bool|Message * @throws Exception * @throws HttpException @@ -1902,14 +1902,14 @@ public function setProxy($proxyString = '', $socks5 = false) * @param string $question Poll question, 1-255 characters * @param array $options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each * @param bool $isAnonymous True, if the poll needs to be anonymous, defaults to True - * @param null $type Poll type, “quiz” or “regular”, defaults to “regular” + * @param string|null $type Poll type, “quiz” or “regular”, defaults to “regular” * @param bool $allowsMultipleAnswers True, if the poll allows multiple answers, * ignored for polls in quiz mode, defaults to False - * @param null $correctOptionId 0-based identifier of the correct answer option, required for polls in quiz mode + * @param string|null $correctOptionId 0-based identifier of the correct answer option, required for polls in quiz mode * @param bool $isClosed Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param int|null $replyToMessageId If the message is a reply, ID of the original message - * @param null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, + * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, * custom reply keyboard, instructions to remove reply * keyboard or to force a reply from the user. * @return \TelegramBot\Api\Types\Message @@ -1956,10 +1956,10 @@ public function sendPoll( * “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and * values 1-64 for “🎰”. Defaults to “🎲 * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. - * @param null $replyToMessageId If the message is a reply, ID of the original message + * @param string|null $replyToMessageId If the message is a reply, ID of the original message * @param bool $$allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to * message is not found, - * @param null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, + * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, * custom reply keyboard, instructions to remove reply * keyboard or to force a reply from the user. * diff --git a/src/Types/InputMedia/InputMediaPhoto.php b/src/Types/InputMedia/InputMediaPhoto.php index 98e06a22..1bf0b2b2 100644 --- a/src/Types/InputMedia/InputMediaPhoto.php +++ b/src/Types/InputMedia/InputMediaPhoto.php @@ -14,8 +14,8 @@ class InputMediaPhoto extends InputMedia * InputMediaPhoto constructor. * * @param string $media - * @param null $caption - * @param null $parseMode + * @param string|null $caption + * @param string|null $parseMode */ public function __construct($media, $caption = null, $parseMode = null) { diff --git a/src/Types/InputMedia/InputMediaVideo.php b/src/Types/InputMedia/InputMediaVideo.php index 6875474a..b1ed5552 100644 --- a/src/Types/InputMedia/InputMediaVideo.php +++ b/src/Types/InputMedia/InputMediaVideo.php @@ -58,11 +58,11 @@ class InputMediaVideo extends InputMedia * InputMediaVideo constructor. * * @param string $media - * @param null $caption - * @param null $parseMode - * @param null $width - * @param null $height - * @param null $duration + * @param string|null $caption + * @param string|null $parseMode + * @param int|null $width + * @param int|null $height + * @param int|null $duration * @param bool $supportsStreaming */ public function __construct( From 8182658d8c5a5817e23dcadfcb9b5c3d17af2d87 Mon Sep 17 00:00:00 2001 From: freeton20 Date: Mon, 29 Nov 2021 15:52:27 +0200 Subject: [PATCH 071/130] added params to answerCallbackQuery --- src/BotApi.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index bfbd9860..4543da24 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1134,15 +1134,19 @@ public function unbanChatMember($chatId, $userId) * @param $callbackQueryId * @param string|null $text * @param bool $showAlert + * @param string|null $url + * @param int $cacheTime * * @return bool */ - public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false) + public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false, $url = null, $cacheTime = 0) { return $this->call('answerCallbackQuery', [ 'callback_query_id' => $callbackQueryId, 'text' => $text, 'show_alert' => (bool)$showAlert, + 'url' => $url, + 'cache_time' => $cacheTime ]); } From 20ee384390ff03e0d3af55348d2e45e757db0042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D0=B9=20=D0=98=D0=B3?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=B2=D0=B8=D1=87=20=D0=9F=D0=B5=D1=87=D0=B5?= =?UTF-8?q?=D1=80=D1=81=D0=BA=D0=B8=D0=B9?= Date: Mon, 6 Dec 2021 15:07:48 +0300 Subject: [PATCH 072/130] Update Client.php @method Message editMessageText --- src/Client.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Client.php b/src/Client.php index 57fe0b14..fed9569a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -6,11 +6,18 @@ use ReflectionFunction; use TelegramBot\Api\Events\EventCollection; use TelegramBot\Api\Types\Update; +use TelegramBot\Api\Types\Message; +use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; +use TelegramBot\Api\Types\ReplyKeyboardRemove; +use TelegramBot\Api\Types\ForceReply; +use TelegramBot\Api\Types\ReplyKeyboardHide; +use TelegramBot\Api\Types\ReplyKeyboardMarkup; /** * Class Client * * @package TelegramBot\Api + * @method Message editMessageText(string $chatId, int $messageId, string $text, string $parseMode = null, bool $disablePreview = false, ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|InlineKeyboardMarkup|null $replyMarkup = null, string $inlineMessageId = null) */ class Client { From 0aa11c1708089a02797ef3d2ef534ef4678381aa Mon Sep 17 00:00:00 2001 From: Ilya Gusev Date: Sun, 1 May 2022 09:19:05 +0300 Subject: [PATCH 073/130] Update ContactTest.php --- tests/ContactTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ContactTest.php b/tests/ContactTest.php index 4a1211f3..d754de97 100644 --- a/tests/ContactTest.php +++ b/tests/ContactTest.php @@ -62,11 +62,11 @@ public function testGetUserId() $this->assertEquals('iGusev', $contact->getUserId()); } - public function testSetVCard() + public function testSetVcard() { $contact = new Contact(); - $contact->setVCard('testVCard'); - $this->assertAttributeEquals('testVCard', 'vCard', $contact); + $contact->setVcard('testVcard'); + $this->assertAttributeEquals('testVcard', 'vcard', $contact); } public function testGetVCard() From ca1a48bf23709f54edea50dc2d8b27db9caa63da Mon Sep 17 00:00:00 2001 From: Denis Radchenko Date: Mon, 29 Aug 2022 00:04:49 +0300 Subject: [PATCH 074/130] PHP8.1: Add CURLStringFile in PhpDoc BotApi->sendDocument() --- src/BotApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index 62070a21..4ec8f16b 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -970,7 +970,7 @@ public function sendPhoto( * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. * * @param int|string $chatId chat_id or @channel_name - * @param \CURLFile|string $document + * @param \CURLFile|\CURLStringFile|string $document * @param string|null $caption * @param int|null $replyToMessageId * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| From 99c403433b46136cd3d59f0cee652cd63204a6b0 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Sun, 18 Dec 2022 00:31:47 +0200 Subject: [PATCH 075/130] support 6.1 api update setWebhook method - Added the parameter secret_token to the method setWebhook. - As previously announced, only HTTPS links are now allowed in login_url inline keyboard buttons. --- src/BotApi.php | 43 ++++++++++++++++++++++++++++++---- src/Types/WebhookInfo.php | 49 +++++++++++++++++++++++++++++++++++++++ tests/WebhookInfoTest.php | 4 ++++ 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 62070a21..93593509 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -476,27 +476,60 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) * @param string $url HTTPS url to send updates to. Use an empty string to remove webhook integration * @param \CURLFile|string $certificate Upload your public key certificate * so that the root certificate in use can be checked + * @param string|null $ip_address The fixed IP address which will be used to send webhook requests + * instead of the IP address resolved through DNS + * @param int|null $max_connections The maximum allowed number of simultaneous HTTPS connections to the webhook + * for update delivery, 1-100. Defaults to 40. Use lower values to limit + * the load on your bot's server, and higher values to increase your bot's throughput. + * @param array|null $allowed_updates A JSON-serialized list of the update types you want your bot to receive. + * For example, specify [“message”, “edited_channel_post”, “callback_query”] + * to only receive updates of these types. See Update for a complete list of available update types. + * Specify an empty list to receive all update types except chat_member (default). + * If not specified, the previous setting will be used. + * Please note that this parameter doesn't affect updates created before the call to the setWebhook, + * so unwanted updates may be received for a short period of time. + * @param bool|null $drop_pending_updates Pass True to drop all pending updates + * @param string|null $secret_token A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, + * 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. + * The header is useful to ensure that the request comes from a webhook set by you. * * @return string * * @throws \TelegramBot\Api\Exception */ - public function setWebhook($url = '', $certificate = null) - { - return $this->call('setWebhook', ['url' => $url, 'certificate' => $certificate]); + public function setWebhook( + $url = '', + $certificate = null, + $ip_address = null, + $max_connections = 40, + $allowed_updates = null, + $drop_pending_updates = false, + $secret_token = null + ) { + return $this->call('setWebhook', [ + 'url' => $url, + 'certificate' => $certificate, + 'ip_address' => $ip_address, + 'max_connections' => $max_connections, + 'allowed_updates' => $allowed_updates, + 'drop_pending_updates' => $drop_pending_updates, + 'secret_token' => $secret_token + ]); } /** * Use this method to clear webhook and use getUpdates again! * + * @param bool $drop_pending_updates Pass True to drop all pending updates + * * @return mixed * * @throws \TelegramBot\Api\Exception */ - public function deleteWebhook() + public function deleteWebhook($drop_pending_updates = false) { - return $this->call('deleteWebhook'); + return $this->call('deleteWebhook', ['drop_pending_updates' => $drop_pending_updates]); } /** diff --git a/src/Types/WebhookInfo.php b/src/Types/WebhookInfo.php index 0354a193..33c49cb4 100644 --- a/src/Types/WebhookInfo.php +++ b/src/Types/WebhookInfo.php @@ -33,8 +33,10 @@ class WebhookInfo extends BaseType implements TypeInterface 'url' => true, 'has_custom_certificate' => true, 'pending_update_count' => true, + 'ip_address' => true, 'last_error_date' => true, 'last_error_message' => true, + 'last_synchronization_error_date' => true, 'max_connections' => true, 'allowed_updates' => true ]; @@ -60,6 +62,13 @@ class WebhookInfo extends BaseType implements TypeInterface */ protected $pendingUpdateCount; + /** + * Optional. Currently used webhook IP address + * + * @var string + */ + protected $ipAddress; + /** * Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook * @@ -75,6 +84,14 @@ class WebhookInfo extends BaseType implements TypeInterface */ protected $lastErrorMessage; + /** + * Optional. Unix time of the most recent error that happened when trying to synchronize available updates + * with Telegram datacenters + * + * @var int + */ + protected $lastSynchronizationErrorDate; + /** * Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery * @@ -121,6 +138,22 @@ public function setHasCustomCertificate($hasCustomCertificate) $this->hasCustomCertificate = $hasCustomCertificate; } + /** + * @param string $ipAddress + */ + public function setIpAddress($ipAddress) + { + $this->ipAddress = $ipAddress; + } + + /** + * @return string + */ + public function getIpAddress() + { + return $this->ipAddress; + } + /** * @return int */ @@ -169,6 +202,22 @@ public function setLastErrorMessage($lastErrorMessage) $this->lastErrorMessage = $lastErrorMessage; } + /** + * @param string $lastSynchronizationErrorDate + */ + public function setLastSynchronizationErrorDate($lastSynchronizationErrorDate) + { + $this->lastSynchronizationErrorDate = $lastSynchronizationErrorDate; + } + + /** + * @return int + */ + public function getlastSynchronizationErrorDate() + { + return $this->lastSynchronizationErrorDate; + } + /** * @return int */ diff --git a/tests/WebhookInfoTest.php b/tests/WebhookInfoTest.php index 06aa277f..ad120fae 100644 --- a/tests/WebhookInfoTest.php +++ b/tests/WebhookInfoTest.php @@ -17,8 +17,10 @@ public function testFromResponse() 'url' => '', 'has_custom_certificate' => false, 'pending_update_count' => 0, + 'ip_address' => '', 'last_error_date' => null, 'last_error_message' => null, + 'last_synchronization_error_date' => null, 'max_connections' => 40, 'allowed_updates' => null )); @@ -26,8 +28,10 @@ public function testFromResponse() $this->assertEquals('', $webhookInfo->getUrl()); $this->assertEquals(false, $webhookInfo->hasCustomCertificate()); $this->assertEquals(0, $webhookInfo->getPendingUpdateCount()); + $this->assertEquals('', $webhookInfo->getipAddress()); $this->assertEquals(null, $webhookInfo->getLastErrorDate()); $this->assertEquals(null, $webhookInfo->getLastErrorMessage()); + $this->assertEquals(null, $webhookInfo->getLastSynchronizationErrorDate()); $this->assertEquals(40, $webhookInfo->getMaxConnections()); $this->assertEquals(null, $webhookInfo->getAllowedUpdates()); } From eda0e92c375654cea1b8cf925265e52d62a21772 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Sun, 18 Dec 2022 00:47:00 +0200 Subject: [PATCH 076/130] support 6.1 api attachment menu integration - Added the field added_to_attachment_menu to the class User. - Bots integrated in the attachment menu can now be used in groups, supergroups and channels. - Added support for t.me links that can be used to select the chat in which the attachment menu with the bot will be opened. --- src/Types/User.php | 124 +++++++++++++++++++++++++++++++++++++++++++++ tests/UserTest.php | 14 ++++- 2 files changed, 137 insertions(+), 1 deletion(-) diff --git a/src/Types/User.php b/src/Types/User.php index aa84bb34..c6caa117 100644 --- a/src/Types/User.php +++ b/src/Types/User.php @@ -32,6 +32,11 @@ class User extends BaseType implements TypeInterface 'last_name' => true, 'username' => true, 'language_code' => true, + 'is_premium' => true, + 'added_to_attachment_menu' => true, + 'can_join_groups' => true, + 'can_read_all_group_messages' => true, + 'supports_inline_queries' => true, 'is_bot' => true ]; @@ -77,6 +82,41 @@ class User extends BaseType implements TypeInterface */ protected $isBot; + /** + * Optional. True, if this user is a Telegram Premium user + * + * @var bool + */ + private $isPremium; + + /** + * Optional. True, if this user added the bot to the attachment menu + * + * @var bool + */ + private $addedToAttachmentMenu; + + /** + * Optional. True, if the bot can be invited to groups. Returned only in getMe. + * + * @var bool + */ + private $canJoinGroups; + + /** + * Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. + * + * @var bool + */ + private $canReadAllGroupMessages; + + /** + * Optional. True, if the bot supports inline queries. Returned only in getMe. + * + * @var bool + */ + private $supportsInlineQueries; + /** * @return string */ @@ -178,4 +218,88 @@ public function setIsBot($isBot) { $this->isBot = $isBot; } + + +//'can_read_all_group_messages' => true, +//'supports_inline_queries' => true, + + /** + * @param bool $isPremium + */ + public function setIsPremium($isPremium) + { + $this->isPremium = $isPremium; + } + + /** + * @return bool + */ + public function getIsPremium() + { + return $this->isPremium; + } + + /** + * @param bool $addedToAttachmentMenu + */ + public function setAddedToAttachmentMenu($addedToAttachmentMenu) + { + $this->addedToAttachmentMenu = $addedToAttachmentMenu; + } + + /** + * @return bool + */ + public function getAddedToAttachmentMenu() + { + return $this->addedToAttachmentMenu; + } + + /** + * @param bool $canJoinGroups + */ + public function setCanJoinGroups($canJoinGroups) + { + $this->canJoinGroups = $canJoinGroups; + } + + /** + * @return bool + */ + public function getCanJoinGroups() + { + return $this->canJoinGroups; + } + + /** + * @param bool $canReadAllGroupMessages + */ + public function setCanReadAllGroupMessages($canReadAllGroupMessages) + { + $this->canReadAllGroupMessages = $canReadAllGroupMessages; + } + + /** + * @return bool + */ + public function getCanReadAllGroupMessages() + { + return $this->canReadAllGroupMessages; + } + + /** + * @param bool $supportsInlineQueries + */ + public function setSupportsInlineQueries($supportsInlineQueries) + { + $this->supportsInlineQueries = $supportsInlineQueries; + } + + /** + * @return bool + */ + public function getSupportsInlineQueries() + { + return $this->supportsInlineQueries; + } } diff --git a/tests/UserTest.php b/tests/UserTest.php index 1c9c115d..f7ec177f 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -84,13 +84,25 @@ public function testFromResponse() 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, - 'username' => 'iGusev' + 'username' => 'iGusev', + 'language_code' => 'en', + 'is_premium' => false, + 'added_to_attachment_menu' => false, + 'can_join_groups' => true, + 'can_read_all_group_messages' => true, + 'supports_inline_queries' => false, )); $this->assertInstanceOf('\TelegramBot\Api\Types\User', $user); $this->assertEquals(123456, $user->getId()); $this->assertEquals('Ilya', $user->getFirstName()); $this->assertEquals('Gusev', $user->getLastName()); $this->assertEquals('iGusev', $user->getUsername()); + $this->assertEquals('en', $user->getLanguageCode()); + $this->assertEquals(false, $user->getIsPremium()); + $this->assertEquals(false, $user->getAddedToAttachmentMenu()); + $this->assertEquals(true, $user->getCanJoinGroups()); + $this->assertEquals(true, $user->getCanReadAllGroupMessages()); + $this->assertEquals(false, $user->getSupportsInlineQueries()); } /** From 8b9e7f41e0a9d849a84b95124e19b8f6acce5901 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Sun, 18 Dec 2022 03:52:59 +0200 Subject: [PATCH 077/130] support 6.1 api update stickers and premium stickers The maximum value of the field file_size in the classes Animation, Audio, Document, Video, Voice, and File can no longer be stored in a signed 32-bit integer type. This change is necessary to support 4GB files uploaded by premium accounts. Added the field is_premium to the class User. Added the field premium_animation to the class Sticker. --- src/BotApi.php | 186 +++++++++++++++++++++++++++- src/Types/ArrayOfSticker.php | 16 +++ src/Types/MaskPosition.php | 16 +++ src/Types/Sticker.php | 231 ++++++++++++++++++++++++++++++++++- src/Types/StickerSet.php | 198 ++++++++++++++++++++++++++++++ 5 files changed, 643 insertions(+), 4 deletions(-) create mode 100644 src/Types/ArrayOfSticker.php create mode 100644 src/Types/MaskPosition.php create mode 100644 src/Types/StickerSet.php diff --git a/src/BotApi.php b/src/BotApi.php index 93593509..5a911e03 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -15,6 +15,7 @@ use TelegramBot\Api\Types\InputMedia\InputMedia; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Poll; +use TelegramBot\Api\Types\StickerSet; use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\User; use TelegramBot\Api\Types\UserProfilePhotos; @@ -730,7 +731,9 @@ public function sendVenue( * @param int|null $replyToMessageId * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| * Types\ReplyKeyboardRemove|null $replyMarkup - * @param bool $disableNotification + * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param bool $protectContent Protects the contents of the sent message from forwarding and saving + * @param bool $allowSendingWithoutReply Pass True if the message should be sent even if the specified replied-to message is not found * * @return \TelegramBot\Api\Types\Message * @throws \TelegramBot\Api\InvalidArgumentException @@ -741,7 +744,9 @@ public function sendSticker( $sticker, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $protectContent = false, + $allowSendingWithoutReply = false ) { return Message::fromResponse($this->call('sendSticker', [ 'chat_id' => $chatId, @@ -749,9 +754,186 @@ public function sendSticker( 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, + 'protect_content' => (bool)$protectContent, + 'allow_sending_without_reply' => (bool)$allowSendingWithoutReply, + ])); + } + + /** + * @param string $name Name of the sticker set + * + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function getStickerSet($name) + { + return StickerSet::fromResponse($this->call('getStickerSet', [ + 'name' => $name, ])); } + /** + * @param array[] $customEmojiIds List of custom emoji identifiers. + * At most 200 custom emoji identifiers can be specified. + * + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function getCustomEmojiStickers($customEmojiIds = []) + { + return StickerSet::fromResponse($this->call('getCustomEmojiStickers', [ + 'custom_emoji_ids' => $customEmojiIds, + ])); + } + + /** + * Use this method to create a new sticker set owned by a user. + * The bot will be able to edit the sticker set thus created. + * You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. + * Returns True on success. + * + * @param int $userId User identifier of created sticker set owner + * @param string $pngSticker PNG image with the sticker, must be up to 512 kilobytes in size, + * dimensions must not exceed 512px, and either width or height must be exactly 512px. + * + * @return File + * + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function uploadStickerFile($userId, $pngSticker) + { + return File::fromResponse($this->call('uploadStickerFile', [ + 'user_id' => $userId, + 'png_sticker' => $pngSticker, + ])); + } + + /** + * Use this method to create a new sticker set owned by a user. + * The bot will be able to edit the sticker set thus created. + * You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. Returns True on success. + * + * @param int $userId User identifier of created sticker set owner + * @param string $name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). + * Can contain only english letters, digits and underscores. Must begin with a letter, + * can't contain consecutive underscores and must end in “_by_”. + * is case insensitive. 1-64 characters. + * @param string $title Sticker set title, 1-64 characters + * @param string $pngSticker PNG image with the sticker, must be up to 512 kilobytes in size, + * dimensions must not exceed 512px, and either width or height must be exactly 512px. + * Pass a file_id as a String to send a file that already exists on the Telegram servers, + * pass an HTTP URL as a String for Telegram to get a file from the Internet, + * or upload a new one using multipart/form-data. + * @param string $tgsSticker TGS animation with the sticker, uploaded using multipart/form-data. + * See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements + * @param string $webmSticker WebP animation with the sticker, uploaded using multipart/form-data. + * See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements + * @param string $stickerType Sticker type, one of “png”, “tgs”, or “webp” + * @param string $emojis One or more emoji corresponding to the sticker + * @param \TelegramBot\Api\Types\MaskPosition|null $maskPosition A JSON-serialized object for position where the mask should be placed on faces + * + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function createNewStickerSet( + $userId, + $name, + $title, + $emojis, + $pngSticker, + $tgsSticker = null, + $webmSticker = null, + $stickerType = null, + $maskPosition = null + ) { + return $this->call('createNewStickerSet', [ + 'user_id' => $userId, + 'name' => $name, + 'title' => $title, + 'png_sticker' => $pngSticker, + 'tgs_sticker' => $tgsSticker, + 'webm_sticker' => $webmSticker, + 'sticker_type' => $stickerType, + 'emojis' => $emojis, + 'mask_position' => is_null($maskPosition) ? $maskPosition : $maskPosition->toJson(), + ]); + } + + /** + * Use this method to add a new sticker to a set created by the bot. + * You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. + * Animated stickers can be added to animated sticker sets and only to them. + * Animated sticker sets can have up to 50 stickers. + * Static sticker sets can have up to 120 stickers. Returns True on success. + * + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function addStickerToSet( + $userId, + $name, + $emojis, + $pngSticker, + $tgsSticker = null, + $webmSticker = null, + $maskPosition = null + ) { + return $this->call('addStickerToSet', [ + 'user_id' => $userId, + 'name' => $name, + 'png_sticker' => $pngSticker, + 'tgs_sticker' => $tgsSticker, + 'webm_sticker' => $webmSticker, + 'emojis' => $emojis, + 'mask_position' => is_null($maskPosition) ? $maskPosition : $maskPosition->toJson(), + ]); + } + + /** + * Use this method to move a sticker in a set created by the bot to a specific position. + * Returns True on success. + * + * @param string $sticker File identifier of the sticker + * @param int $position New sticker position in the set, zero-based + * + * @return bool + * + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function setStickerPositionInSet($sticker, $position) + { + return $this->call('setStickerPositionInSet', [ + 'sticker' => $sticker, + 'position' => $position, + ]); + } + + /** + * Use this method to delete a sticker from a set created by the bot. + * Returns True on success. + * + * @param string $name Sticker set name + * @param string $userId User identifier of sticker set owner + * @param File|null $thumb A PNG image with the thumbnail, + * must be up to 128 kilobytes in size and have width and height exactly 100px, + * or a TGS animation with the thumbnail up to 32 kilobytes in size + * + * @return bool + * + * @throws \TelegramBot\Api\InvalidArgumentException + * @throws \TelegramBot\Api\Exception + */ + public function setStickerSetThumb($name, $userId, $thumb = null) + { + return $this->call('setStickerSetThumb', [ + 'name' => $name, + 'user_id' => $userId, + 'thumb' => $thumb, + ]); + } + /** * Use this method to send video files, * Telegram clients support mp4 videos (other formats may be sent as Document). diff --git a/src/Types/ArrayOfSticker.php b/src/Types/ArrayOfSticker.php new file mode 100644 index 00000000..d0e4400b --- /dev/null +++ b/src/Types/ArrayOfSticker.php @@ -0,0 +1,16 @@ + true, 'thumb' => PhotoSize::class, 'file_size' => true, + 'type' => true, + 'file_unique_id' => true, + 'premium_animation' => true, + 'is_animated' => true, + 'is_video' => true, + 'emoji' => true, + 'set_name' => true, + 'mask_position' => MaskPosition::class, + 'custom_emoji_id' => true, ]; /** @@ -56,7 +73,7 @@ class Sticker extends BaseType implements TypeInterface protected $height; /** - * Document thumbnail as defined by sender + * Optional. Sticker thumbnail in the .WEBP or .JPG format * * @var PhotoSize */ @@ -69,6 +86,72 @@ class Sticker extends BaseType implements TypeInterface */ protected $fileSize; + /** + * Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”. + * The type of the sticker is independent from its format, + * which is determined by the fields is_animated and is_video. + * + * @var string + */ + protected $type; + + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. + * Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + + /** + * Optional. For premium regular stickers, premium animation for the sticker + * + * @var File + */ + protected $premiumAnimation; + + /** + * True, if the sticker is animated + * + * @var bool + */ + protected $isAnimated; + + /** + * True, if the sticker is a video sticker + * + * @var bool + */ + protected $isVideo; + + /** + * Optional. Emoji associated with the sticker + * + * @var string + */ + protected $emoji; + + /** + * Optional. Name of the sticker set to which the sticker belongs + * + * @var string + */ + protected $setName; + + /** + * Optional. For mask stickers, the position where the mask should be placed + * + * @var MaskPosition + */ + protected $maskPosition; + + /** + * Optional. For custom emoji stickers, unique identifier of the custom emoji + * + * @var string + */ + protected $customEmojiId; + /** * @return string */ @@ -166,4 +249,148 @@ public function setWidth($width) throw new InvalidArgumentException(); } } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + + /** + * @return File + */ + public function getPremiumAnimation() + { + return $this->premiumAnimation; + } + + /** + * @param File $premiumAnimation + */ + public function setPremiumAnimation(File $premiumAnimation) + { + $this->premiumAnimation = $premiumAnimation; + } + + /** + * @return bool + */ + public function getIsAnimated() + { + return $this->isAnimated; + } + + /** + * @param bool $isAnimated + */ + public function setIsAnimated($isAnimated) + { + $this->isAnimated = $isAnimated; + } + + /** + * @return bool + */ + public function getIsVideo() + { + return $this->isVideo; + } + + /** + * @param bool $isVideo + */ + public function setIsVideo($isVideo) + { + $this->isVideo = $isVideo; + } + + /** + * @return string + */ + public function getEmoji() + { + return $this->emoji; + } + + /** + * @param string $emoji + */ + public function setEmoji($emoji) + { + $this->emoji = $emoji; + } + + /** + * @return string + */ + public function getSetName() + { + return $this->setName; + } + + /** + * @param string $setName + */ + public function setSetName($setName) + { + $this->setName = $setName; + } + + /** + * @return MaskPosition + */ + public function getMaskPosition() + { + return $this->maskPosition; + } + + /** + * @param MaskPosition $maskPosition + */ + public function setMaskPosition(MaskPosition $maskPosition) + { + $this->maskPosition = $maskPosition; + } + + /** + * @return string + */ + public function getCustomEmojiId() + { + return $this->customEmojiId; + } + + /** + * @param string $customEmojiId + */ + public function setCustomEmojiId($customEmojiId) + { + $this->customEmojiId = $customEmojiId; + } } diff --git a/src/Types/StickerSet.php b/src/Types/StickerSet.php new file mode 100644 index 00000000..afc46c96 --- /dev/null +++ b/src/Types/StickerSet.php @@ -0,0 +1,198 @@ + true, + 'title' => true, + 'sticker_type' => true, + 'is_animated' => true, + 'is_video' => true, + 'stickers' => true, + 'thumb' => true, + ]; + + /** + * Sticker set name + * + * @var string + */ + protected $name; + + /** + * Sticker set title + * + * @var string + */ + protected $title; + + /** + * Type of stickers in the set, currently one of “regular”, “mask”, “custom_emoji” + * + * @var string + */ + protected $stickerType; + + /** + * True, if the sticker set contains animated stickers + * + * @var bool + */ + protected $isAnimated; + + /** + * True, if the sticker set contains video stickers + * + * @var bool + */ + protected $isVideo; + + /** + * List of all set stickers + * + * @var ArrayOfSticker + */ + protected $stickers; + + /** + * Optional. Sticker set thumbnail in the .WEBP or .TGS format + * + * @var PhotoSize + */ + protected $thumb; + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string + */ + public function getStickerType() + { + return $this->stickerType; + } + + /** + * @param string $stickerType + */ + public function setStickerType($stickerType) + { + $this->stickerType = $stickerType; + } + + /** + * @return bool + */ + public function getIsAnimated() + { + return $this->isAnimated; + } + + /** + * @param bool $isAnimated + */ + public function setIsAnimated($isAnimated) + { + $this->isAnimated = $isAnimated; + } + + /** + * @return bool + */ + public function getIsVideo() + { + return $this->isVideo; + } + + /** + * @param bool $isVideo + */ + public function setIsVideo($isVideo) + { + $this->isVideo = $isVideo; + } + + /** + * @return ArrayOfSticker + */ + public function getStickers() + { + return $this->stickers; + } + + /** + * @param ArrayOfSticker $stickers + */ + public function setStickers($stickers) + { + $this->stickers = $stickers; + } + + /** + * @return PhotoSize + */ + public function getThumb() + { + return $this->thumb; + } + + /** + * @param PhotoSize $thumb + */ + public function setThumb($thumb) + { + $this->thumb = $thumb; + } +} From 898b34b2a091ba66da3717199c12d896224d0c1b Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Sun, 18 Dec 2022 04:58:38 +0200 Subject: [PATCH 078/130] support 6.1 api add file_unique_id --- src/Types/Animation.php | 3 +- src/Types/Audio.php | 26 ++++++- src/Types/Chat.php | 77 ++++++++++++++++++- src/Types/Document.php | 24 ++++++ src/Types/File.php | 24 ++++++ src/Types/PhotoSize.php | 26 ++++++- src/Types/Video.php | 26 ++++++- src/Types/VideoNote.php | 164 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 365 insertions(+), 5 deletions(-) create mode 100644 src/Types/VideoNote.php diff --git a/src/Types/Animation.php b/src/Types/Animation.php index a1a9f3db..2e28e5a0 100644 --- a/src/Types/Animation.php +++ b/src/Types/Animation.php @@ -19,7 +19,7 @@ class Animation extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'width', 'height', 'duration']; + static protected $requiredParams = ['file_id', 'file_unique_id', 'width', 'height', 'duration']; /** * {@inheritdoc} @@ -28,6 +28,7 @@ class Animation extends BaseType implements TypeInterface */ static protected $map = [ 'file_id' => true, + 'file_unique_id' => true, 'width' => true, 'height' => true, 'duration' => true, diff --git a/src/Types/Audio.php b/src/Types/Audio.php index ef7f7c59..6c3ed13e 100644 --- a/src/Types/Audio.php +++ b/src/Types/Audio.php @@ -19,7 +19,7 @@ class Audio extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'duration']; + static protected $requiredParams = ['file_id', 'file_unique_id', 'duration']; /** * {@inheritdoc} @@ -28,6 +28,7 @@ class Audio extends BaseType implements TypeInterface */ static protected $map = [ 'file_id' => true, + 'file_unique_id' => true, 'duration' => true, 'performer' => true, 'title' => true, @@ -77,6 +78,13 @@ class Audio extends BaseType implements TypeInterface */ protected $fileSize; + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + /** * @return int */ @@ -184,4 +192,20 @@ public function setMimeType($mimeType) { $this->mimeType = $mimeType; } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } } diff --git a/src/Types/Chat.php b/src/Types/Chat.php index 3e6ce001..ed32ae61 100644 --- a/src/Types/Chat.php +++ b/src/Types/Chat.php @@ -37,7 +37,16 @@ class Chat extends BaseType implements TypeInterface 'sticker_set_name' => true, 'can_set_sticker_set' => true, 'linked_chat_id' => true, - 'location' => ChatLocation::class + 'location' => ChatLocation::class, + 'join_to_send_messages' => true, + 'join_by_request' => true, + 'message_auto_delete_time' => true, + 'has_protected_content' => true, + 'is_forum' => true, + 'active_usernames' => true, + 'emoji_status_custom_emoji_id' => true, + 'has_private_forwards' => true, + 'has_restricted_voice_and_video_messages' => true, ]; /** @@ -163,6 +172,72 @@ class Chat extends BaseType implements TypeInterface */ protected $location; + /** + * Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. + * + * @var bool + */ + protected $joinToSendMessages; + + /** + * Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat. + * + * @var bool + */ + protected $joinByRequest; + + /** + * Optional. Time after which all messages sent to the chat will be automatically deleted; in seconds. Returned + * only in getChat. + * + * @var int + */ + protected $messageAutoDeleteTime; + + /** + * Optional. True, if the chat has a custom title. Returned only in getChat. + * + * @var bool + */ + protected $hasProtectedContent; + + /** + * Optional. True, if the chat is a forum. Returned only in getChat. + * + * @var bool + */ + protected $isForum; + + /** + * Optional. True, if the chat is a forum. Returned only in getChat. + * + * @var array[] + */ + protected $activeUsernames; + + /** + * Optional. True, if the chat is a forum. Returned only in getChat. + * + * @var bool + */ + protected $emojiStatusCustomEmojiId; + + /** + * Optional. True, if the chat is a forum. Returned only in getChat. + * + * @var bool + */ + protected $hasPrivateForwards; + + /** + * Optional. True, if the chat is a forum. Returned only in getChat. + * + * @var bool + */ + protected $hasRestrictedVoiceAndVideoMessages; + + + /** * @return int|string */ diff --git a/src/Types/Document.php b/src/Types/Document.php index d84d2c49..7a173b0f 100644 --- a/src/Types/Document.php +++ b/src/Types/Document.php @@ -22,6 +22,7 @@ class Document extends BaseType implements TypeInterface */ static protected $map = [ 'file_id' => true, + 'file_unique_id' => true, 'thumb' => PhotoSize::class, 'file_name' => true, 'mime_type' => true, @@ -70,6 +71,13 @@ class Document extends BaseType implements TypeInterface */ protected $fileSize; + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + /** * @return string */ @@ -155,4 +163,20 @@ public function setThumb(PhotoSize $thumb) { $this->thumb = $thumb; } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } } diff --git a/src/Types/File.php b/src/Types/File.php index c1bccfa6..06a35f55 100644 --- a/src/Types/File.php +++ b/src/Types/File.php @@ -31,6 +31,7 @@ class File extends BaseType implements TypeInterface */ static protected $map = [ 'file_id' => true, + 'file_unique_id' => true, 'file_size' => true, 'file_path' => true ]; @@ -56,6 +57,13 @@ class File extends BaseType implements TypeInterface */ protected $filePath; + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + /** * @return string */ @@ -109,4 +117,20 @@ public function setFilePath($filePath) { $this->filePath = $filePath; } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } } diff --git a/src/Types/PhotoSize.php b/src/Types/PhotoSize.php index 61a1c744..2c989c61 100644 --- a/src/Types/PhotoSize.php +++ b/src/Types/PhotoSize.php @@ -19,7 +19,7 @@ class PhotoSize extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'width', 'height']; + static protected $requiredParams = ['file_id', 'file_unique_id', 'width', 'height']; /** * {@inheritdoc} @@ -28,6 +28,7 @@ class PhotoSize extends BaseType implements TypeInterface */ static protected $map = [ 'file_id' => true, + 'file_unique_id' => true, 'width' => true, 'height' => true, 'file_size' => true, @@ -61,6 +62,13 @@ class PhotoSize extends BaseType implements TypeInterface */ protected $fileSize; + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + /** * @return string */ @@ -142,4 +150,20 @@ public function setWidth($width) throw new InvalidArgumentException(); } } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } } diff --git a/src/Types/Video.php b/src/Types/Video.php index d82d7fd0..4ae3857c 100644 --- a/src/Types/Video.php +++ b/src/Types/Video.php @@ -19,7 +19,7 @@ class Video extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'width', 'height', 'duration']; + static protected $requiredParams = ['file_id', 'file_unique_id', 'width', 'height', 'duration']; /** * {@inheritdoc} @@ -28,6 +28,7 @@ class Video extends BaseType implements TypeInterface */ static protected $map = [ 'file_id' => true, + 'file_unique_id' => true, 'width' => true, 'height' => true, 'duration' => true, @@ -86,6 +87,13 @@ class Video extends BaseType implements TypeInterface */ protected $fileSize; + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + /** * @return int */ @@ -221,4 +229,20 @@ public function setWidth($width) throw new InvalidArgumentException(); } } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } } diff --git a/src/Types/VideoNote.php b/src/Types/VideoNote.php new file mode 100644 index 00000000..c4e40303 --- /dev/null +++ b/src/Types/VideoNote.php @@ -0,0 +1,164 @@ + true, + 'file_unique_id' => true, + 'length' => true, + 'duration' => true, + 'thumb' => PhotoSize::class, + 'file_size' => true, + ]; + + /** + * Unique identifier for this file + * + * @var string + */ + protected $fileId; + + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + + /** + * Video width and height (diameter of the video message) as defined by sender + * + * @var int + */ + protected $length; + + /** + * Duration of the video in seconds as defined by sender + * + * @var int + */ + protected $duration; + + /** + * Optional. Video thumbnail + * + * @var PhotoSize + */ + protected $thumb; + + /** + * Optional. File size in bytes + * + * @var int + */ + protected $fileSize; + + /** + * @return string + */ + public function getFileId() + { + return $this->fileId; + } + + /** + * @param string $fileId + */ + public function setFileId($fileId) + { + $this->fileId = $fileId; + } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + + /** + * @return int + */ + public function getLength() + { + return $this->length; + } + + /** + * @param int $length + */ + public function setLength($length) + { + $this->length = $length; + } + + /** + * @return int + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param int $duration + */ + public function setDuration($duration) + { + $this->duration = $duration; + } + + /** + * @return PhotoSize + */ + public function getThumb() + { + return $this->thumb; + } + + /** + * @param PhotoSize $thumb + */ + public function setThumb($thumb) + { + $this->thumb = $thumb; + } + + /** + * @return int + */ + public function getFileSize() + { + return $this->fileSize; + } + + /** + * @param int $fileSize + */ + public function setFileSize($fileSize) + { + $this->fileSize = $fileSize; + } +} From 1f621c1b1ee9a56d6d10d1ad839c44939b9432cb Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Mon, 19 Dec 2022 00:13:26 +0200 Subject: [PATCH 079/130] support 6.3 api sending messages to forum topics Added the parameter message_thread_id to the methods sendMessage, sendPhoto, sendVideo, sendAnimation, sendAudio, sendDocument, sendSticker, sendVideoNote, sendVoice, sendLocation, sendVenue, sendContact, sendPoll, sendDice, sendInvoice, sendGame, sendMediaGroup, copyMessage, forwardMessage to support sending of messages to a forum topic. --- src/BotApi.php | 397 ++++++++++++++++++------------ src/Types/MessageEntity.php | 31 +++ tests/Types/MessageEntityTest.php | 2 + 3 files changed, 272 insertions(+), 158 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 5a911e03..85db2791 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -7,14 +7,20 @@ use TelegramBot\Api\Types\ArrayOfMessageEntity; use TelegramBot\Api\Types\ArrayOfMessages; use TelegramBot\Api\Types\ArrayOfUpdates; +use TelegramBot\Api\Types\BotCommand; use TelegramBot\Api\Types\Chat; use TelegramBot\Api\Types\ChatMember; use TelegramBot\Api\Types\File; +use TelegramBot\Api\Types\ForceReply; use TelegramBot\Api\Types\Inline\QueryResult\AbstractInlineQueryResult; use TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia; use TelegramBot\Api\Types\InputMedia\InputMedia; +use TelegramBot\Api\Types\MaskPosition; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Poll; +use TelegramBot\Api\Types\ReplyKeyboardHide; +use TelegramBot\Api\Types\ReplyKeyboardMarkup; +use TelegramBot\Api\Types\ReplyKeyboardRemove; use TelegramBot\Api\Types\StickerSet; use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\User; @@ -151,7 +157,7 @@ class BotApi /** * Botan tracker * - * @var \TelegramBot\Api\Botan + * @var Botan */ protected $tracker; @@ -174,6 +180,7 @@ class BotApi * * @param string $token Telegram Bot API token * @param string|null $trackerToken Yandex AppMetrica application api_key + * @throws \Exception */ public function __construct($token, $trackerToken = null) { @@ -207,9 +214,9 @@ public function setModeObject($mode = true) * @param array|null $data * * @return mixed - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\HttpException - * @throws \TelegramBot\Api\InvalidJsonException + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException */ public function call($method, array $data = null, $timeout = 10) { @@ -254,7 +261,7 @@ public function call($method, array $data = null, $timeout = 10) * * @return string * - * @throws \TelegramBot\Api\HttpException + * @throws HttpException */ protected function executeCurl(array $options) { @@ -295,7 +302,7 @@ public static function curlValidate($curl, $response = null) * @param boolean $asArray * * @return object|array - * @throws \TelegramBot\Api\InvalidJsonException + * @throws InvalidJsonException */ public static function jsonValidate($jsonString, $asArray) { @@ -315,20 +322,21 @@ public static function jsonValidate($jsonString, $asArray) * @param string $text * @param string|null $parseMode * @param bool $disablePreview + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendMessage( $chatId, $text, $parseMode = null, $disablePreview = false, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false @@ -336,6 +344,7 @@ public function sendMessage( return Message::fromResponse($this->call('sendMessage', [ 'chat_id' => $chatId, 'text' => $text, + 'message_thread_id' => $messageThreadId, 'parse_mode' => $parseMode, 'disable_web_page_preview' => $disablePreview, 'reply_to_message_id' => (int)$replyToMessageId, @@ -352,10 +361,10 @@ public function sendMessage( * @param string|null $parseMode * @param ArrayOfMessageEntity|null $captionEntities * @param bool $disableNotification + * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param bool $allowSendingWithoutReply - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * * @return Message * @throws Exception @@ -370,6 +379,7 @@ public function copyMessage( $parseMode = null, $captionEntities = null, $disableNotification = false, + $messageThreadId = null, $replyToMessageId = null, $allowSendingWithoutReply = false, $replyMarkup = null @@ -382,6 +392,7 @@ public function copyMessage( 'parse_mode' => $parseMode, 'caption_entities' => $captionEntities, 'disable_notification' => (bool)$disableNotification, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => (int)$replyToMessageId, 'allow_sending_without_reply' => (bool)$allowSendingWithoutReply, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), @@ -395,19 +406,20 @@ public function copyMessage( * @param string $phoneNumber * @param string $firstName * @param string $lastName + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws Exception */ public function sendContact( $chatId, $phoneNumber, $firstName, $lastName = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false @@ -417,6 +429,7 @@ public function sendContact( 'phone_number' => $phoneNumber, 'first_name' => $firstName, 'last_name' => $lastName, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -439,7 +452,7 @@ public function sendContact( * @param string $action * * @return bool - * @throws \TelegramBot\Api\Exception + * @throws Exception */ public function sendChatAction($chatId, $action) { @@ -456,8 +469,8 @@ public function sendChatAction($chatId, $action) * @param int $offset * @param int $limit * - * @return \TelegramBot\Api\Types\UserProfilePhotos - * @throws \TelegramBot\Api\Exception + * @return UserProfilePhotos + * @throws Exception */ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) { @@ -496,7 +509,7 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) * * @return string * - * @throws \TelegramBot\Api\Exception + * @throws Exception */ public function setWebhook( $url = '', @@ -526,7 +539,7 @@ public function setWebhook( * * @return mixed * - * @throws \TelegramBot\Api\Exception + * @throws Exception */ public function deleteWebhook($drop_pending_updates = false) { @@ -538,9 +551,9 @@ public function deleteWebhook($drop_pending_updates = false) * On success, returns a WebhookInfo object. If the bot is using getUpdates, * will return an object with the url field empty. * - * @return \TelegramBot\Api\Types\WebhookInfo - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\InvalidArgumentException + * @return WebhookInfo + * @throws Exception + * @throws InvalidArgumentException */ public function getWebhookInfo() { @@ -551,9 +564,9 @@ public function getWebhookInfo() * A simple method for testing your bot's auth token.Requires no parameters. * Returns basic information about the bot in form of a User object. * - * @return \TelegramBot\Api\Types\User - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\InvalidArgumentException + * @return User + * @throws Exception + * @throws InvalidArgumentException */ public function getMe() { @@ -573,8 +586,8 @@ public function getMe() * @param int $timeout * * @return Update[] - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\InvalidArgumentException + * @throws Exception + * @throws InvalidArgumentException */ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) { @@ -596,21 +609,25 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) /** * Use this method to send point on the map. On success, the sent Message is returned. * - * @param int|string $chatId - * @param float $latitude - * @param float $longitude - * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup - * @param bool $disableNotification + * @param int|string $chatId + * @param float $latitude + * @param float $longitude + * @param int|null $messageThreadId + * @param int|null $replyToMessageId + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param bool $disableNotification * - * @param null|int $livePeriod - * @return \TelegramBot\Api\Types\Message + * @param null|int $livePeriod + * + * @return Message + * + * @throws Exception */ public function sendLocation( $chatId, $latitude, $longitude, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -621,6 +638,7 @@ public function sendLocation( 'latitude' => $latitude, 'longitude' => $longitude, 'live_period' => $livePeriod, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -635,9 +653,11 @@ public function sendLocation( * @param string $inlineMessageId * @param float $latitude * @param float $longitude - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup - * @return \TelegramBot\Api\Types\Message + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * + * @return Message + * + * @throws Exception */ public function editMessageLiveLocation( $chatId, @@ -664,9 +684,11 @@ public function editMessageLiveLocation( * @param int|string $chatId * @param int $messageId * @param string $inlineMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup - * @return \TelegramBot\Api\Types\Message + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * + * @return Message + * + * @throws Exception */ public function stopMessageLiveLocation( $chatId, @@ -691,13 +713,13 @@ public function stopMessageLiveLocation( * @param string $title * @param string $address * @param string|null $foursquareId + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws Exception */ public function sendVenue( $chatId, @@ -706,6 +728,7 @@ public function sendVenue( $title, $address, $foursquareId = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false @@ -717,6 +740,7 @@ public function sendVenue( 'title' => $title, 'address' => $address, 'foursquare_id' => $foursquareId, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -729,19 +753,19 @@ public function sendVenue( * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $sticker * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param null $replyMarkup * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param bool $protectContent Protects the contents of the sent message from forwarding and saving * @param bool $allowSendingWithoutReply Pass True if the message should be sent even if the specified replied-to message is not found * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendSticker( $chatId, $sticker, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -751,6 +775,7 @@ public function sendSticker( return Message::fromResponse($this->call('sendSticker', [ 'chat_id' => $chatId, 'sticker' => $sticker, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -762,8 +787,8 @@ public function sendSticker( /** * @param string $name Name of the sticker set * - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ public function getStickerSet($name) { @@ -776,8 +801,8 @@ public function getStickerSet($name) * @param array[] $customEmojiIds List of custom emoji identifiers. * At most 200 custom emoji identifiers can be specified. * - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ public function getCustomEmojiStickers($customEmojiIds = []) { @@ -798,8 +823,8 @@ public function getCustomEmojiStickers($customEmojiIds = []) * * @return File * - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ public function uploadStickerFile($userId, $pngSticker) { @@ -831,10 +856,10 @@ public function uploadStickerFile($userId, $pngSticker) * See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements * @param string $stickerType Sticker type, one of “png”, “tgs”, or “webp” * @param string $emojis One or more emoji corresponding to the sticker - * @param \TelegramBot\Api\Types\MaskPosition|null $maskPosition A JSON-serialized object for position where the mask should be placed on faces + * @param MaskPosition|null $maskPosition A JSON-serialized object for position where the mask should be placed on faces * - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ public function createNewStickerSet( $userId, @@ -867,8 +892,8 @@ public function createNewStickerSet( * Animated sticker sets can have up to 50 stickers. * Static sticker sets can have up to 120 stickers. Returns True on success. * - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ public function addStickerToSet( $userId, @@ -899,8 +924,8 @@ public function addStickerToSet( * * @return bool * - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ public function setStickerPositionInSet($sticker, $position) { @@ -922,8 +947,8 @@ public function setStickerPositionInSet($sticker, $position) * * @return bool * - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ public function setStickerSetThumb($name, $userId, $thumb = null) { @@ -943,22 +968,23 @@ public function setStickerSetThumb($name, $userId, $thumb = null) * @param \CURLFile|string $video * @param int|null $duration * @param string|null $caption + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param bool $supportsStreaming Pass True, if the uploaded video is suitable for streaming * @param string|null $parseMode * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendVideo( $chatId, $video, $duration = null, $caption = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -970,6 +996,7 @@ public function sendVideo( 'video' => $video, 'duration' => $duration, 'caption' => $caption, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -987,21 +1014,22 @@ public function sendVideo( * @param \CURLFile|string $animation * @param int|null $duration * @param string|null $caption + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendAnimation( $chatId, $animation, $duration = null, $caption = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -1012,6 +1040,7 @@ public function sendAnimation( 'animation' => $animation, 'duration' => $duration, 'caption' => $caption, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -1027,27 +1056,28 @@ public function sendAnimation( * On success, the sent Message is returned. * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. * - * @param int|string $chatId chat_id or @channel_name + * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $voice - * @param string $caption Voice message caption, 0-1024 characters after entities parsing - * @param int|null $duration - * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup - * @param bool $disableNotification - * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified + * @param string $caption Voice message caption, 0-1024 characters after entities parsing + * @param int|null $duration + * @param int|null $messageThreadId + * @param int|null $replyToMessageId + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param bool $disableNotification + * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified * replied-to message is not found - * @param string|null $parseMode + * @param string|null $parseMode * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendVoice( $chatId, $voice, $caption = null, $duration = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -1059,6 +1089,7 @@ public function sendVoice( 'voice' => $voice, 'caption' => $caption, 'duration' => $duration, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -1068,23 +1099,35 @@ public function sendVoice( } /** - * Use this method to forward messages of any kind. On success, the sent Message is returned. + * Use this method to forward messages of any kind. Service messages can't be forwarded. + * On success, the sent Message is returned. * - * @param int|string $chatId chat_id or @channel_name - * @param int $fromChatId - * @param int $messageId - * @param bool $disableNotification + * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) + * @param $messageId Message identifier in the chat specified in from_chat_id + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool $protectContent Protects the contents of the forwarded message from forwarding and saving + * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException */ - public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotification = false) - { + public function forwardMessage( + $chatId, + $fromChatId, + $messageId, + $messageThreadId = null, + $protectContent = false, + $disableNotification = false + ) { return Message::fromResponse($this->call('forwardMessage', [ 'chat_id' => $chatId, 'from_chat_id' => $fromChatId, - 'message_id' => (int)$messageId, + 'message_id' => $messageId, + 'message_thread_id' => $messageThreadId, + 'protect_content' => $protectContent, 'disable_notification' => (bool)$disableNotification, ])); } @@ -1101,24 +1144,23 @@ public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotific * For this to work, the audio must be in an .ogg file encoded with OPUS. * This behavior will be phased out in the future. For sending voice messages, use the sendVoice method instead. * - * @deprecated since 20th February. Removed backward compatibility from the method sendAudio. - * Voice messages now must be sent using the method sendVoice. - * There is no more need to specify a non-empty title or performer while sending the audio by file_id. - * * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $audio * @param int|null $duration * @param string|null $performer * @param string|null $title * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception + * @deprecated since 20th February. Removed backward compatibility from the method sendAudio. + * Voice messages now must be sent using the method sendVoice. + * There is no more need to specify a non-empty title or performer while sending the audio by file_id. + * */ public function sendAudio( $chatId, @@ -1150,20 +1192,21 @@ public function sendAudio( * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $photo * @param string|null $caption + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendPhoto( $chatId, $photo, $caption = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -1173,6 +1216,7 @@ public function sendPhoto( 'chat_id' => $chatId, 'photo' => $photo, 'caption' => $caption, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -1187,20 +1231,21 @@ public function sendPhoto( * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $document * @param string|null $caption + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendDocument( $chatId, $document, $caption = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -1210,6 +1255,7 @@ public function sendDocument( 'chat_id' => $chatId, 'document' => $document, 'caption' => $caption, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -1228,9 +1274,9 @@ public function sendDocument( * * @param $fileId * - * @return \TelegramBot\Api\Types\File - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return File + * @throws InvalidArgumentException + * @throws Exception */ public function getFile($fileId) { @@ -1244,7 +1290,8 @@ public function getFile($fileId) * * @return string * - * @throws \TelegramBot\Api\HttpException + * @throws HttpException + * @throws Exception */ public function downloadFile($fileId) { @@ -1313,6 +1360,7 @@ public function answerInlineQuery( * they are considered to be banned forever * * @return bool + * @throws Exception */ public function kickChatMember($chatId, $userId, $untilDate = null) { @@ -1333,6 +1381,7 @@ public function kickChatMember($chatId, $userId, $untilDate = null) * @param int $userId Unique identifier of the target user * * @return bool + * @throws Exception */ public function unbanChatMember($chatId, $userId) { @@ -1353,6 +1402,7 @@ public function unbanChatMember($chatId, $userId) * @param int $cacheTime * * @return bool + * @throws Exception */ public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false, $url = null, $cacheTime = 0) { @@ -1389,7 +1439,8 @@ public function setMyCommands($commands) * Use this method to get the current list of the bot's commands. Requires no parameters. * Returns Array of BotCommand on success. * - * @return mixed + * @return BotCommand[] + * * @throws Exception * @throws HttpException * @throws InvalidJsonException @@ -1408,9 +1459,10 @@ public function getMyCommands() * @param string $inlineMessageId * @param string|null $parseMode * @param bool $disablePreview - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * * @return Message + * @throws Exception */ public function editMessageText( $chatId, @@ -1438,14 +1490,13 @@ public function editMessageText( * @param int|string $chatId * @param int $messageId * @param string|null $caption - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param string $inlineMessageId * @param string|null $parseMode * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function editMessageCaption( $chatId, @@ -1479,6 +1530,7 @@ public function editMessageCaption( * @param string|null $inlineMessageId * @param string|null $replyMarkup * @return bool|Message + * * @throws Exception * @throws HttpException * @throws InvalidJsonException @@ -1504,11 +1556,11 @@ public function editMessageMedia( * * @param int|string $chatId * @param int $messageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param string $inlineMessageId * * @return Message + * @throws Exception */ public function editMessageReplyMarkup( $chatId, @@ -1536,6 +1588,7 @@ public function editMessageReplyMarkup( * @param int $messageId * * @return bool + * @throws Exception */ public function deleteMessage($chatId, $messageId) { @@ -1570,10 +1623,10 @@ public function getFileUrl() } /** - * @param \TelegramBot\Api\Types\Update $update + * @param Update $update * @param string $eventName * - * @throws \TelegramBot\Api\Exception + * @throws Exception */ public function trackUpdate(Update $update, $eventName = 'Message') { @@ -1591,10 +1644,10 @@ public function trackUpdate(Update $update, $eventName = 'Message') /** * Wrapper for tracker * - * @param \TelegramBot\Api\Types\Message $message + * @param Message $message * @param string $eventName * - * @throws \TelegramBot\Api\Exception + * @throws Exception */ public function track(Message $message, $eventName = 'Message') { @@ -1614,6 +1667,7 @@ public function track(Message $message, $eventName = 'Message') * @param string $startParameter * @param string $currency * @param array $prices + * @param bool $isFlexible * @param string|null $photoUrl * @param int|null $photoSize * @param int|null $photoWidth @@ -1622,16 +1676,16 @@ public function track(Message $message, $eventName = 'Message') * @param bool $needPhoneNumber * @param bool $needEmail * @param bool $needShippingAddress - * @param bool $isFlexible + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $providerData * @param bool $sendPhoneNumberToProvider * @param bool $sendEmailToProvider * * @return Message + * @throws Exception */ public function sendInvoice( $chatId, @@ -1651,6 +1705,7 @@ public function sendInvoice( $needPhoneNumber = false, $needEmail = false, $needShippingAddress = false, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -1696,7 +1751,7 @@ public function sendInvoice( * @param null|string $errorMessage * * @return bool - * + * @throws Exception */ public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null) { @@ -1717,6 +1772,7 @@ public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_opti * @param null|string $errorMessage * * @return mixed + * @throws Exception */ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null) { @@ -1747,6 +1803,7 @@ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMe * implies can_send_media_messages * * @return bool + * @throws Exception */ public function restrictChatMember( $chatId, @@ -1788,6 +1845,7 @@ public function restrictChatMember( * indirectly (promoted by administrators that were appointed by him) * * @return bool + * @throws Exception */ public function promoteChatMember( $chatId, @@ -1822,6 +1880,7 @@ public function promoteChatMember( * @param string|int $chatId Unique identifier for the target chat or username of the target channel * (in the format @channelusername) * @return string + * @throws Exception */ public function exportChatInviteLink($chatId) { @@ -1839,6 +1898,7 @@ public function exportChatInviteLink($chatId) * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data * * @return bool + * @throws Exception */ public function setChatPhoto($chatId, $photo) { @@ -1856,6 +1916,7 @@ public function setChatPhoto($chatId, $photo) * (in the format @channelusername) * * @return bool + * @throws Exception */ public function deleteChatPhoto($chatId) { @@ -1873,6 +1934,7 @@ public function deleteChatPhoto($chatId) * @param string $title New chat title, 1-255 characters * * @return bool + * @throws Exception */ public function setChatTitle($chatId, $title) { @@ -1891,6 +1953,7 @@ public function setChatTitle($chatId, $title) * @param string|null $description New chat description, 0-255 characters * * @return bool + * @throws Exception */ public function setChatDescription($chatId, $description = null) { @@ -1910,6 +1973,7 @@ public function setChatDescription($chatId, $description = null) * @param bool $disableNotification * * @return bool + * @throws Exception */ public function pinChatMessage($chatId, $messageId, $disableNotification = false) { @@ -1928,6 +1992,7 @@ public function pinChatMessage($chatId, $messageId, $disableNotification = false * (in the format @channelusername) * * @return bool + * @throws Exception */ public function unpinChatMessage($chatId) { @@ -1944,6 +2009,7 @@ public function unpinChatMessage($chatId) * (in the format @channelusername) * * @return Chat + * @throws Exception */ public function getChat($chatId) { @@ -1960,6 +2026,7 @@ public function getChat($chatId) * @param int $userId * * @return ChatMember + * @throws Exception */ public function getChatMember($chatId, $userId) { @@ -1976,6 +2043,7 @@ public function getChatMember($chatId, $userId) * (in the format @channelusername) * * @return bool + * @throws Exception */ public function leaveChat($chatId) { @@ -1991,6 +2059,7 @@ public function leaveChat($chatId) * (in the format @channelusername) * * @return int + * @throws Exception */ public function getChatMembersCount($chatId) { @@ -2008,7 +2077,9 @@ public function getChatMembersCount($chatId) * @param string|int $chatId Unique identifier for the target chat or username of the target channel * (in the format @channelusername) * - * @return array + * @return ChatMember[] + * @throws InvalidArgumentException + * @throws Exception */ public function getChatAdministrators($chatId) { @@ -2031,20 +2102,21 @@ public function getChatAdministrators($chatId) * @param \CURLFile|string $videoNote * @param int|null $duration * @param int|null $length + * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendVideoNote( $chatId, $videoNote, $duration = null, $length = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false @@ -2054,6 +2126,7 @@ public function sendVideoNote( 'video_note' => $videoNote, 'duration' => $duration, 'length' => $length, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification @@ -2066,21 +2139,24 @@ public function sendVideoNote( * * @param int|string $chatId * @param ArrayOfInputMedia $media - * @param int|null $replyToMessageId * @param bool $disableNotification + * @param int|null $messageThreadId + * @param int|null $replyToMessageId * - * @return array - * @throws \TelegramBot\Api\Exception + * @return Message[] + * @throws Exception */ public function sendMediaGroup( $chatId, $media, $disableNotification = false, + $messageThreadId = null, $replyToMessageId = null ) { return ArrayOfMessages::fromResponse($this->call('sendMediaGroup', [ 'chat_id' => $chatId, 'media' => $media->toJson(), + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => (int)$replyToMessageId, 'disable_notification' => (bool)$disableNotification ])); @@ -2126,12 +2202,13 @@ public function setProxy($proxyString = '', $socks5 = false) * ignored for polls in quiz mode, defaults to False * @param string|null $correctOptionId 0-based identifier of the correct answer option, required for polls in quiz mode * @param bool $isClosed Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param int|null $replyToMessageId If the message is a reply, ID of the original message * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, * custom reply keyboard, instructions to remove reply * keyboard or to force a reply from the user. - * @return \TelegramBot\Api\Types\Message + * @return Message * @throws Exception * @throws HttpException * @throws InvalidJsonException @@ -2145,6 +2222,7 @@ public function sendPoll( $allowsMultipleAnswers = false, $correctOptionId = null, $isClosed = false, + $messageThreadId = null, $disableNotification = false, $replyToMessageId = null, $replyMarkup = null @@ -2159,6 +2237,7 @@ public function sendPoll( 'correct_option_id' => (int) $correctOptionId, 'is_closed' => (bool) $isClosed, 'disable_notification' => (bool) $disableNotification, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => (int) $replyToMessageId, 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), ])); @@ -2175,8 +2254,9 @@ public function sendPoll( * “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and * values 1-64 for “🎰”. Defaults to “🎲 * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param int|null $messageThreadId * @param string|null $replyToMessageId If the message is a reply, ID of the original message - * @param bool $$allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to + * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to * message is not found, * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, * custom reply keyboard, instructions to remove reply @@ -2191,6 +2271,7 @@ public function sendDice( $chatId, $emoji, $disableNotification = false, + $messageThreadId = null, $replyToMessageId = null, $allowSendingWithoutReply = false, $replyMarkup = null @@ -2199,6 +2280,7 @@ public function sendDice( 'chat_id' => $chatId, 'emoji' => $emoji, 'disable_notification' => (bool) $disableNotification, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => (int) $replyToMessageId, 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), @@ -2211,11 +2293,10 @@ public function sendDice( * * @param int|string $chatId * @param int $messageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| - * Types\ReplyKeyboardRemove|null $replyMarkup + * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @return Poll - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ public function stopPoll( $chatId, diff --git a/src/Types/MessageEntity.php b/src/Types/MessageEntity.php index 33bf0ea0..9c71d5dc 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -11,6 +11,11 @@ use TelegramBot\Api\BaseType; use TelegramBot\Api\TypeInterface; +/** + * class MessageEntity. + * + * @author bernard-ng + */ class MessageEntity extends BaseType implements TypeInterface { @@ -29,6 +34,7 @@ class MessageEntity extends BaseType implements TypeInterface const TYPE_PRE = 'pre'; const TYPE_TEXT_LINK = 'text_link'; const TYPE_TEXT_MENTION = 'text_mention'; + const TYPE_CUSTOM_EMOJI = 'custom_emoji'; /** * {@inheritdoc} @@ -49,6 +55,7 @@ class MessageEntity extends BaseType implements TypeInterface 'url' => true, 'user' => User::class, 'language' => true, + 'custom_emoji_id' => true, ]; /** @@ -97,6 +104,14 @@ class MessageEntity extends BaseType implements TypeInterface */ protected $language; + /** + * Optional. For “custom_emoji” only, unique identifier of the custom emoji. + * Use getCustomEmojiStickers to get full information about the sticker + * + * @var string + */ + protected $custom_emoji_id; + /** * @return string */ @@ -192,4 +207,20 @@ public function setLanguage($language) { $this->language = $language; } + + /** + * @return string + */ + public function getCustomEmojiId() + { + return $this->custom_emoji_id; + } + + /** + * @param string $custom_emoji_id + */ + public function setCustomEmojiId($custom_emoji_id) + { + $this->custom_emoji_id = $custom_emoji_id; + } } diff --git a/tests/Types/MessageEntityTest.php b/tests/Types/MessageEntityTest.php index 2c7db907..acfd462e 100644 --- a/tests/Types/MessageEntityTest.php +++ b/tests/Types/MessageEntityTest.php @@ -21,6 +21,7 @@ public function testTextMentionFromResponse() 'username' => 'hunter', 'language_code' => 'en', ], + 'custom_emoji_id' => 1, ]); $this->assertInstanceOf(MessageEntity::class, $messageEntity); @@ -36,6 +37,7 @@ public function testTextMentionFromResponse() $this->assertEquals('hunter', $messageEntity->getUser()->getUsername()); $this->assertEquals('en', $messageEntity->getUser()->getLanguageCode()); $this->assertNull($messageEntity->getLanguage()); + $this->assertEquals(1, $messageEntity->getCustomEmojiId()); } public function testPreFromResponse() From 98c9a4320725e321279c6db4c8abecf576381840 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Mon, 19 Dec 2022 02:10:49 +0200 Subject: [PATCH 080/130] support 6.3 api forum topic and missing types Added support for Topics in Groups. Added the field is_forum to the class Chat. Added the fields is_topic_message and message_thread_id to the class Message to allow detection of messages belonging to a forum topic and their message thread identifier. Added the classes ForumTopicCreated, ForumTopicClosed, and ForumTopicReopened and the fields forum_topic_created, forum_topic_closed, and forum_topic_reopened to the class Message. Note that service messages about forum topic creation can't be deleted with the deleteMessage method. Added the field can_manage_topics to the classes ChatAdministratorRights, ChatPermissions, ChatMemberAdministrator, and ChatMemberRestricted. Added the parameter can_manage_topics to the method promoteChatMember. Added the methods createForumTopic, editForumTopic, closeForumTopic, reopenForumTopic, deleteForumTopic, unpinAllForumTopicMessages, and getForumTopicIconStickers for forum topic management. Added the parameter message_thread_id to the methods sendMessage, sendPhoto, sendVideo, sendAnimation, sendAudio, sendDocument, sendSticker, sendVideoNote, sendVoice, sendLocation, sendVenue, sendContact, sendPoll, sendDice, sendInvoice, sendGame, sendMediaGroup, copyMessage, forwardMessage to support sending of messages to a forum topic. Added support for Multiple Usernames via the field active_usernames in the class Chat. Added the field emoji_status_custom_emoji_id to the class Chat. --- src/BotApi.php | 185 ++++++++++++++++++++++++++++++- src/Types/Chat.php | 166 +++++++++++++++++++++++++-- src/Types/ChatMember.php | 126 ++++++++++++++++++++- src/Types/ForumTopic.php | 127 +++++++++++++++++++++ src/Types/ForumTopicClosed.php | 17 +++ src/Types/ForumTopicCreated.php | 103 +++++++++++++++++ src/Types/ForumTopicReopened.php | 17 +++ src/Types/MaskPosition.php | 103 +++++++++++++++++ src/Types/Message.php | 121 ++++++++++++++++++++ src/Types/StickerSet.php | 1 + 10 files changed, 951 insertions(+), 15 deletions(-) create mode 100644 src/Types/ForumTopic.php create mode 100644 src/Types/ForumTopicClosed.php create mode 100644 src/Types/ForumTopicCreated.php create mode 100644 src/Types/ForumTopicReopened.php diff --git a/src/BotApi.php b/src/BotApi.php index 85db2791..7b65fdb5 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -6,12 +6,14 @@ use TelegramBot\Api\Types\ArrayOfChatMemberEntity; use TelegramBot\Api\Types\ArrayOfMessageEntity; use TelegramBot\Api\Types\ArrayOfMessages; +use TelegramBot\Api\Types\ArrayOfSticker; use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\BotCommand; use TelegramBot\Api\Types\Chat; use TelegramBot\Api\Types\ChatMember; use TelegramBot\Api\Types\File; use TelegramBot\Api\Types\ForceReply; +use TelegramBot\Api\Types\ForumTopic; use TelegramBot\Api\Types\Inline\QueryResult\AbstractInlineQueryResult; use TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia; use TelegramBot\Api\Types\InputMedia\InputMedia; @@ -21,6 +23,7 @@ use TelegramBot\Api\Types\ReplyKeyboardHide; use TelegramBot\Api\Types\ReplyKeyboardMarkup; use TelegramBot\Api\Types\ReplyKeyboardRemove; +use TelegramBot\Api\Types\Sticker; use TelegramBot\Api\Types\StickerSet; use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\User; @@ -803,6 +806,8 @@ public function getStickerSet($name) * * @throws InvalidArgumentException * @throws Exception + * + * @author bernard-ng */ public function getCustomEmojiStickers($customEmojiIds = []) { @@ -860,6 +865,8 @@ public function uploadStickerFile($userId, $pngSticker) * * @throws InvalidArgumentException * @throws Exception + * + * @author bernard-ng */ public function createNewStickerSet( $userId, @@ -1843,9 +1850,13 @@ public function restrictChatMember( * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his * own privileges or demote administrators that he has promoted,directly or * indirectly (promoted by administrators that were appointed by him) - * + * @param bool $canManageTopics Pass True if the user is allowed to create, rename, close, and reopen forum topics, supergroups only + * @param bool $isAnonymous Pass True if the administrator's presence in the chat is hidden * @return bool + * * @throws Exception + * @throws HttpException + * @throws InvalidJsonException */ public function promoteChatMember( $chatId, @@ -1857,11 +1868,14 @@ public function promoteChatMember( $canInviteUsers = true, $canRestrictMembers = true, $canPinMessages = true, - $canPromoteMembers = true + $canPromoteMembers = true, + $canManageTopics = true, + $isAnonymous = false ) { return $this->call('promoteChatMember', [ 'chat_id' => $chatId, 'user_id' => $userId, + 'is_anonymous' => $isAnonymous, 'can_change_info' => $canChangeInfo, 'can_post_messages' => $canPostMessages, 'can_edit_messages' => $canEditMessages, @@ -1869,7 +1883,8 @@ public function promoteChatMember( 'can_invite_users' => $canInviteUsers, 'can_restrict_members' => $canRestrictMembers, 'can_pin_messages' => $canPinMessages, - 'can_promote_members' => $canPromoteMembers + 'can_promote_members' => $canPromoteMembers, + 'can_manage_topics' => $canManageTopics ]); } @@ -2310,6 +2325,170 @@ public function stopPoll( ])); } + /** + * Use this method to create a topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work + * and must have the can_manage_topics administrator rights. + * Returns information about the created topic as a ForumTopic object. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param string $name Topic name, 1-128 characters + * @param int $iconColor Color of the topic icon in RGB format. + * Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), + * 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F) + * @param int|null $iconCustomEmojiId Unique identifier of the custom emoji shown as the topic icon. + * Use getForumTopicIconStickers to get all allowed custom emoji identifiers. + * + * @return ForumTopic + * + * @throws Exception + * + * @author bernard-ng + */ + public function createForumTopic( + $chatId, + $name, + $iconColor, + $iconCustomEmojiId = null + ) + { + return ForumTopic::fromResponse($this->call('createForumTopic', [ + 'chat_id' => $chatId, + 'name' => $name, + 'icon_color' => $iconColor, + 'icon_custom_emoji_id' => $iconCustomEmojiId, + ])); + } + + /** + * Use this method to edit name and icon of a topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, + * unless it is the creator of the topic. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * @param string $name Topic name, 1-128 characters + * @param int|null $iconCustomEmojiId Unique identifier of the custom emoji shown as the topic icon. + * Use getForumTopicIconStickers to get all allowed custom emoji identifiers. + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function editForumTopic( + $chatId, + $messageThreadId, + $name, + $iconCustomEmojiId = null + ) + { + return $this->call('editForumTopic', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + 'name' => $name, + 'icon_custom_emoji_id' => $iconCustomEmojiId, + ]); + } + + /** + * Use this method to delete a topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, + * unless it is the creator of the topic. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function closeForumTopic($chatId, $messageThreadId) + { + return $this->call('closeForumTopic', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + ]); + } + + /** + * Use this method to reopen a closed topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, + * unless it is the creator of the topic. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function reopenForumTopic($chatId, $messageThreadId) + { + return $this->call('reopenForumTopic', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + ]); + } + + /** + * Use this method to delete a forum topic along with all its messages in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. + * Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function deleteForumTopic($chatId, $messageThreadId) + { + return $this->call('deleteForumTopic', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + ]); + } + + /** + * Use this method to clear the list of pinned messages in a forum topic. + * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. + * Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function unpinAllForumTopicMessages($chatId, $messageThreadId) + { + return $this->call('unpinAllForumTopicMessages', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + ]); + } + + /** + * Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. + * Requires no parameters. Returns an Array of Sticker objects. + * + * @return Sticker[] + * @throws Exception + * + * @author bernard-ng + */ + public function getForumTopicIconStickers() + { + return ArrayOfSticker::fromResponse($this->call('getForumTopicIconStickers')); + } + /** * Set an option for a cURL transfer * diff --git a/src/Types/Chat.php b/src/Types/Chat.php index ed32ae61..26497d4d 100644 --- a/src/Types/Chat.php +++ b/src/Types/Chat.php @@ -195,49 +195,51 @@ class Chat extends BaseType implements TypeInterface protected $messageAutoDeleteTime; /** - * Optional. True, if the chat has a custom title. Returned only in getChat. + * Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. * * @var bool */ protected $hasProtectedContent; /** - * Optional. True, if the chat is a forum. Returned only in getChat. + * Optional. True, if the supergroup chat is a forum (has topics enabled) * * @var bool */ protected $isForum; /** - * Optional. True, if the chat is a forum. Returned only in getChat. + * Optional. If non-empty, the list of all active chat usernames; + * for private chats, supergroups and channels. Returned only in getChat. * * @var array[] */ protected $activeUsernames; /** - * Optional. True, if the chat is a forum. Returned only in getChat. + * Optional. Custom emoji identifier of emoji status of the other party in a private chat. Returned only in getChat. * - * @var bool + * @var string */ protected $emojiStatusCustomEmojiId; /** - * Optional. True, if the chat is a forum. Returned only in getChat. + * Optional. True, if privacy settings of the other party in the private chat allows + * to use tg://user?id= links only in chats with the user. + * Returned only in getChat. * * @var bool */ protected $hasPrivateForwards; /** - * Optional. True, if the chat is a forum. Returned only in getChat. + * Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. + * Returned only in getChat. * * @var bool */ protected $hasRestrictedVoiceAndVideoMessages; - - /** * @return int|string */ @@ -471,7 +473,7 @@ public function setStickerSetName($stickerSetName) /** * @return bool */ - public function isCanSetStickerSet() + public function getCanSetStickerSet() { return $this->canSetStickerSet; } @@ -515,4 +517,148 @@ public function setLocation($location) { $this->location = $location; } + + /** + * @return bool + */ + public function getJoinToSendMessages() + { + return $this->joinToSendMessages; + } + + /** + * @param bool $joinToSendMessages + */ + public function setJoinToSendMessages($joinToSendMessages) + { + $this->joinToSendMessages = $joinToSendMessages; + } + + /** + * @return bool + */ + public function getJoinByRequest() + { + return $this->joinByRequest; + } + + /** + * @param bool $joinByRequest + */ + public function setJoinByRequest($joinByRequest) + { + $this->joinByRequest = $joinByRequest; + } + + /** + * @return int + */ + public function getMessageAutoDeleteTime() + { + return $this->messageAutoDeleteTime; + } + + /** + * @param int $messageAutoDeleteTime + */ + public function setMessageAutoDeleteTime($messageAutoDeleteTime) + { + $this->messageAutoDeleteTime = $messageAutoDeleteTime; + } + + /** + * @return bool + */ + public function getHasProtectedContent() + { + return $this->hasProtectedContent; + } + + /** + * @param bool $hasProtectedContent + */ + public function setHasProtectedContent($hasProtectedContent) + { + $this->hasProtectedContent = $hasProtectedContent; + } + + /** + * @return bool + */ + public function getIsForum() + { + return $this->isForum; + } + + /** + * @param bool $isForum + */ + public function setIsForum($isForum) + { + $this->isForum = $isForum; + } + + /** + * @return array + */ + public function getActiveUsernames() + { + return $this->activeUsernames; + } + + /** + * @param array $activeUsernames + */ + public function setActiveUsernames($activeUsernames) + { + $this->activeUsernames = $activeUsernames; + } + + /** + * @return bool + */ + public function getEmojiStatusCustomEmojiId() + { + return $this->emojiStatusCustomEmojiId; + } + + /** + * @param bool $emojiStatusCustomEmojiId + */ + public function setEmojiStatusCustomEmojiId($emojiStatusCustomEmojiId) + { + $this->emojiStatusCustomEmojiId = $emojiStatusCustomEmojiId; + } + + /** + * @return bool + */ + public function getHasPrivateForwards() + { + return $this->hasPrivateForwards; + } + + /** + * @param bool $hasPrivateForwards + */ + public function setHasPrivateForwards($hasPrivateForwards) + { + $this->hasPrivateForwards = $hasPrivateForwards; + } + + /** + * @return bool + */ + public function getHasRestrictedVoiceAndVideoMessages() + { + return $this->hasRestrictedVoiceAndVideoMessages; + } + + /** + * @param bool $hasRestrictedVoiceAndVideoMessages + */ + public function setHasRestrictedVoiceAndVideoMessages($hasRestrictedVoiceAndVideoMessages) + { + $this->hasRestrictedVoiceAndVideoMessages = $hasRestrictedVoiceAndVideoMessages; + } } diff --git a/src/Types/ChatMember.php b/src/Types/ChatMember.php index c107eea5..a3ba60d8 100644 --- a/src/Types/ChatMember.php +++ b/src/Types/ChatMember.php @@ -34,7 +34,12 @@ class ChatMember extends BaseType 'can_send_messages' => true, 'can_send_media_messages' => true, 'can_send_other_messages' => true, - 'can_add_web_page_previews' => true + 'can_add_web_page_previews' => true, + 'can_manage_topics' => true, + 'is_anonymous' => true, + 'custom_title' => true, + 'can_manage_chat' => true, + 'can_send_polls' => true, ]; /** @@ -52,7 +57,7 @@ class ChatMember extends BaseType protected $status; /** - * Optional. Restictred and kicked only. Date when restrictions will be lifted for this user, unix time + * Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time * * @var integer */ @@ -154,6 +159,43 @@ class ChatMember extends BaseType */ protected $canAddWebPagePreviews; + /** + * Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only + * + * @var bool + */ + protected $canManageTopics; + + /** + * True, if the user's presence in the chat is hidden + * + * @var bool + */ + protected $isAnonymous; + + /** + * Optional. Custom title for this user + * + * @var string + */ + protected $customTitle; + + /** + * True, if the administrator can access the chat event log, chat statistics, message statistics in channels, + * see channel members, see anonymous administrators in supergroups and ignore slow mode. + * Implied by any other administrator privilege + * + * @var bool + */ + protected $canManageChat; + + /** + * True, if the user is allowed to send polls + * + * @var bool + */ + protected $canSendPolls; + /** * @return User */ @@ -409,4 +451,84 @@ public function setCanAddWebPagePreviews($canAddWebPagePreviews) { $this->canAddWebPagePreviews = $canAddWebPagePreviews; } + + /** + * @return bool + */ + public function getCanManageChat() + { + return $this->canManageChat; + } + + /** + * @param bool $canManageChat + */ + public function setCanManageChat($canManageChat) + { + $this->canManageChat = $canManageChat; + } + + /** + * @return bool + */ + public function getIsAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return bool + */ + public function getCanSendPolls() + { + return $this->canSendPolls; + } + + /** + * @param bool $canSendPolls + */ + public function setCanSendPolls($canSendPolls) + { + $this->canSendPolls = $canSendPolls; + } + + /** + * @return bool + */ + public function getCanManageTopics() + { + return $this->canManageTopics; + } + + /** + * @param bool $canManageTopics + */ + public function setCanManageTopics($canManageTopics) + { + $this->canManageTopics = $canManageTopics; + } + + /** + * @return string + */ + public function getCustomTitle() + { + return $this->customTitle; + } + + /** + * @param string $customTitle + */ + public function setCustomTitle($customTitle) + { + $this->customTitle = $customTitle; + } } diff --git a/src/Types/ForumTopic.php b/src/Types/ForumTopic.php new file mode 100644 index 00000000..0d7bd058 --- /dev/null +++ b/src/Types/ForumTopic.php @@ -0,0 +1,127 @@ + + */ +class ForumTopic extends BaseType implements TypeInterface +{ + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['message_thread_id', 'name', 'icon_color']; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'message_thread_id' => true, + 'name' => true, + 'icon_color' => true, + 'icon_custom_emoji_id' => true, + ]; + + /** + * Unique identifier of the forum topic + * + * @var int + */ + protected $messageThreadId; + + /** + * Name of the topic + * + * @var string + */ + protected $name; + + /** + * Color of the topic icon in RGB format + * + * @var int + */ + protected $iconColor; + + /** + * Optional. Unique identifier of the custom emoji shown as the topic icon + * + * @var string + */ + protected $iconCustomEmojiId; + + /** + * @return int + */ + public function getMessageThreadId() + { + return $this->messageThreadId; + } + + /** + * @param int $messageThreadId + */ + public function setMessageThreadId($messageThreadId) + { + $this->messageThreadId = $messageThreadId; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int + */ + public function getIconColor() + { + return $this->iconColor; + } + + /** + * @param int $iconColor + */ + public function setIconColor($iconColor) + { + $this->iconColor = $iconColor; + } + + /** + * @return string + */ + public function getIconCustomEmojiId() + { + return $this->iconCustomEmojiId; + } + + /** + * @param string $iconCustomEmojiId + */ + public function setIconCustomEmojiId($iconCustomEmojiId) + { + $this->iconCustomEmojiId = $iconCustomEmojiId; + } +} diff --git a/src/Types/ForumTopicClosed.php b/src/Types/ForumTopicClosed.php new file mode 100644 index 00000000..6dfcc1d5 --- /dev/null +++ b/src/Types/ForumTopicClosed.php @@ -0,0 +1,17 @@ + + */ +class ForumTopicClosed extends BaseType implements TypeInterface +{ +} diff --git a/src/Types/ForumTopicCreated.php b/src/Types/ForumTopicCreated.php new file mode 100644 index 00000000..0549c9ae --- /dev/null +++ b/src/Types/ForumTopicCreated.php @@ -0,0 +1,103 @@ + + */ +class ForumTopicCreated extends BaseType implements TypeInterface +{ + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['name', 'icon_color']; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'name' => true, + 'icon_color' => true, + 'icon_custom_emoji_id' => true, + ]; + + /** + * Name of the forum topic + * + * @var string + */ + protected $name; + + /** + * Color of the forum topic + * + * @var string + */ + protected $iconColor; + + /** + * Custom emoji of the forum topic + * + * @var string + */ + protected $iconCustomEmojiId; + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return string + */ + public function getIconColor() + { + return $this->iconColor; + } + + /** + * @param string $iconColor + */ + public function setIconColor($iconColor) + { + $this->iconColor = $iconColor; + } + + /** + * @return string + */ + public function getIconCustomEmojiId() + { + return $this->iconCustomEmojiId; + } + + /** + * @param string $iconCustomEmojiId + */ + public function setIconCustomEmojiId($iconCustomEmojiId) + { + $this->iconCustomEmojiId = $iconCustomEmojiId; + } +} diff --git a/src/Types/ForumTopicReopened.php b/src/Types/ForumTopicReopened.php new file mode 100644 index 00000000..2db4c65d --- /dev/null +++ b/src/Types/ForumTopicReopened.php @@ -0,0 +1,17 @@ + + */ +class ForumTopicReopened extends BaseType implements TypeInterface +{ +} diff --git a/src/Types/MaskPosition.php b/src/Types/MaskPosition.php index ff6fbfdd..c895cae8 100644 --- a/src/Types/MaskPosition.php +++ b/src/Types/MaskPosition.php @@ -10,7 +10,110 @@ * This object describes the position on faces where a mask should be placed by default. * * @package TelegramBot\Api\Types + * @author bernard-ng */ class MaskPosition extends BaseType implements TypeInterface { + protected static $requiredParams = ['point', 'x_shift', 'y_shift', 'scale']; + + protected static $map = [ + 'point' => true, + 'x_shift' => true, + 'y_shift' => true, + 'scale' => true, + ]; + + /** + * The part of the face relative to which the mask should be placed. One of “forehead”, “eyes”, “mouth”, or “chin”. + * + * @var string + */ + protected $point; + + /** + * Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. + * For example, choosing -1.0 will place mask just to the left of the default mask position. + * + * @var float + */ + protected $xShift; + + /** + * Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. + * For example, 1.0 will place the mask just below the default mask position. + * + * @var float + */ + protected $yShift; + + /** + * Mask scaling coefficient. For example, 2.0 means double size. + * + * @var float + */ + protected $scale; + + /** + * @return string + */ + public function getPoint() + { + return $this->point; + } + + /** + * @param string $point + */ + public function setPoint($point) + { + $this->point = $point; + } + + /** + * @return float + */ + public function getXShift() + { + return $this->xShift; + } + + /** + * @param float $xShift + */ + public function setXShift($xShift) + { + $this->xShift = $xShift; + } + + /** + * @return float + */ + public function getYShift() + { + return $this->yShift; + } + + /** + * @param float $yShift + */ + public function setYShift($yShift) + { + $this->yShift = $yShift; + } + + /** + * @return float + */ + public function getScale() + { + return $this->scale; + } + + /** + * @param float $scale + */ + public function setScale($scale) + { + $this->scale = $scale; + } } diff --git a/src/Types/Message.php b/src/Types/Message.php index 876c3e8a..41e1fd86 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -68,6 +68,11 @@ class Message extends BaseType implements TypeInterface 'invoice' => Invoice::class, 'successful_payment' => SuccessfulPayment::class, 'connected_website' => true, + 'forum_topic_created' => ForumTopicCreated::class, + 'forum_topic_closed' => ForumTopicClosed::class, + 'forum_topic_reopened' => ForumTopicReopened::class, + 'is_topic_message' => true, + 'message_thread_id' => true, ]; /** @@ -405,6 +410,42 @@ class Message extends BaseType implements TypeInterface */ protected $replyMarkup; + /** + * Optional. Service message: forum topic created + * + * @var ForumTopicCreated + */ + protected $forumTopicCreated; + + /** + * Optional. Service message: forum topic closed + * + * @var ForumTopicReopened + */ + protected $forumTopicReopened; + + /** + * Optional. Service message: forum topic reopened + * + * @var ForumTopicClosed + */ + protected $forumTopicClosed; + + /** + * Optional. True, if the message is sent to a forum topic + * + * @var bool + */ + protected $isTopicMessage; + + /** + * Optional. Unique identifier of a message thread to which the message belongs; for supergroups only + * + * @var int + */ + protected $messageThreadId; + + /** * @return int */ @@ -1168,4 +1209,84 @@ public function setReplyMarkup($replyMarkup) { $this->replyMarkup = $replyMarkup; } + + /** + * @return ForumTopicCreated + */ + public function getForumTopicCreated() + { + return $this->forumTopicCreated; + } + + /** + * @param ForumTopicCreated $forumTopicCreated + */ + public function setForumTopicCreated($forumTopicCreated) + { + $this->forumTopicCreated = $forumTopicCreated; + } + + /** + * @return ForumTopicClosed + */ + public function getForumTopicClosed() + { + return $this->forumTopicClosed; + } + + /** + * @param ForumTopicClosed $forumTopicClosed + */ + public function setForumTopicClosed($forumTopicClosed) + { + $this->forumTopicClosed = $forumTopicClosed; + } + + /** + * @return ForumTopicReopened + */ + public function getForumTopicReopened() + { + return $this->forumTopicReopened; + } + + /** + * @param ForumTopicReopened $forumTopicReopened + */ + public function setForumTopicReopened($forumTopicReopened) + { + $this->forumTopicReopened = $forumTopicReopened; + } + + /** + * @return bool + */ + public function getIsTopicMessage() + { + return $this->isTopicMessage; + } + + /** + * @param bool $isTopicMessage + */ + public function setIsTopicMessage($isTopicMessage) + { + $this->isTopicMessage = $isTopicMessage; + } + + /** + * @return int|null + */ + public function getMessageThreadId() + { + return $this->messageThreadId; + } + + /** + * @param int|null $messageThreadId + */ + public function setMessageThreadId($messageThreadId) + { + $this->messageThreadId = $messageThreadId; + } } diff --git a/src/Types/StickerSet.php b/src/Types/StickerSet.php index afc46c96..10487c8d 100644 --- a/src/Types/StickerSet.php +++ b/src/Types/StickerSet.php @@ -10,6 +10,7 @@ * This object represents a sticker set. * * @package TelegramBot\Api\Types + * @author bernard-ng */ class StickerSet extends BaseType implements TypeInterface { From 9f69bc4f83d649dbcd1ebb055665cf9a21bd4a01 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Mon, 19 Dec 2022 02:28:32 +0200 Subject: [PATCH 081/130] fix #379 add reply_markup to Message map --- src/Types/Message.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Types/Message.php b/src/Types/Message.php index 41e1fd86..37c53058 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -73,6 +73,7 @@ class Message extends BaseType implements TypeInterface 'forum_topic_reopened' => ForumTopicReopened::class, 'is_topic_message' => true, 'message_thread_id' => true, + 'reply_markup' => true ]; /** From e81475f21c29cc201180721268667782356f822c Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Mon, 19 Dec 2022 02:45:27 +0200 Subject: [PATCH 082/130] fix reply_markup type --- src/Types/Message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Types/Message.php b/src/Types/Message.php index 37c53058..69dedf21 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -73,7 +73,7 @@ class Message extends BaseType implements TypeInterface 'forum_topic_reopened' => ForumTopicReopened::class, 'is_topic_message' => true, 'message_thread_id' => true, - 'reply_markup' => true + 'reply_markup' => InlineKeyboardMarkup::class ]; /** From bcdcb7c49e333196b8aa713d52b682cc2d9986b3 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Mon, 19 Dec 2022 02:50:02 +0200 Subject: [PATCH 083/130] fix User type change properties visibility --- src/Types/User.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Types/User.php b/src/Types/User.php index c6caa117..ac8709b9 100644 --- a/src/Types/User.php +++ b/src/Types/User.php @@ -87,35 +87,35 @@ class User extends BaseType implements TypeInterface * * @var bool */ - private $isPremium; + protected $isPremium; /** * Optional. True, if this user added the bot to the attachment menu * * @var bool */ - private $addedToAttachmentMenu; + protected $addedToAttachmentMenu; /** * Optional. True, if the bot can be invited to groups. Returned only in getMe. * * @var bool */ - private $canJoinGroups; + protected $canJoinGroups; /** * Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. * * @var bool */ - private $canReadAllGroupMessages; + protected $canReadAllGroupMessages; /** * Optional. True, if the bot supports inline queries. Returned only in getMe. * * @var bool */ - private $supportsInlineQueries; + protected $supportsInlineQueries; /** * @return string @@ -219,10 +219,6 @@ public function setIsBot($isBot) $this->isBot = $isBot; } - -//'can_read_all_group_messages' => true, -//'supports_inline_queries' => true, - /** * @param bool $isPremium */ @@ -302,4 +298,6 @@ public function getSupportsInlineQueries() { return $this->supportsInlineQueries; } + + } From 2fa179f06f7cc4ac166f4ed2039248745a97c953 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Mon, 19 Dec 2022 03:19:12 +0200 Subject: [PATCH 084/130] test add file_unique_id cases --- src/Types/Document.php | 2 +- src/Types/MessageEntity.php | 13 ++++++----- tests/ArrayOfPhotoSizeTest.php | 2 ++ tests/AudioTest.php | 21 +++++++++++++++++ tests/DocumentTest.php | 8 +++++++ tests/MessageTest.php | 24 ++++++++++++++++++++ tests/PhotoSizeTest.php | 2 ++ tests/StickerTest.php | 9 ++++++++ tests/UserProfilePhotosTest.php | 4 ++++ tests/VideoTest.php | 40 +++++++++++++++++++++++++++++++++ 10 files changed, 118 insertions(+), 7 deletions(-) diff --git a/src/Types/Document.php b/src/Types/Document.php index 7a173b0f..afba5ad6 100644 --- a/src/Types/Document.php +++ b/src/Types/Document.php @@ -34,7 +34,7 @@ class Document extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id']; + static protected $requiredParams = ['file_id', 'file_unique_id']; /** * Unique identifier for this file diff --git a/src/Types/MessageEntity.php b/src/Types/MessageEntity.php index 9c71d5dc..16e9d025 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -13,8 +13,9 @@ /** * class MessageEntity. + * This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. * - * @author bernard-ng + * @package TelegramBot\Api\Types */ class MessageEntity extends BaseType implements TypeInterface { @@ -110,7 +111,7 @@ class MessageEntity extends BaseType implements TypeInterface * * @var string */ - protected $custom_emoji_id; + protected $customEmojiId; /** * @return string @@ -213,14 +214,14 @@ public function setLanguage($language) */ public function getCustomEmojiId() { - return $this->custom_emoji_id; + return $this->customEmojiId; } /** - * @param string $custom_emoji_id + * @param string $customEmojiId */ - public function setCustomEmojiId($custom_emoji_id) + public function setCustomEmojiId($customEmojiId) { - $this->custom_emoji_id = $custom_emoji_id; + $this->customEmojiId = $customEmojiId; } } diff --git a/tests/ArrayOfPhotoSizeTest.php b/tests/ArrayOfPhotoSizeTest.php index 816f124d..8f51e1b6 100644 --- a/tests/ArrayOfPhotoSizeTest.php +++ b/tests/ArrayOfPhotoSizeTest.php @@ -15,6 +15,7 @@ public function testFromResponse() array( array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -25,6 +26,7 @@ public function testFromResponse() $expected = array( PhotoSize::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 diff --git a/tests/AudioTest.php b/tests/AudioTest.php index b03bb3f1..022e1edf 100644 --- a/tests/AudioTest.php +++ b/tests/AudioTest.php @@ -94,6 +94,7 @@ public function testFromResponse() { $item = Audio::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'performer' => 'testperformer', 'title' => 'testtitle', @@ -102,6 +103,7 @@ public function testFromResponse() )); $this->assertInstanceOf('\TelegramBot\Api\Types\Audio', $item); $this->assertAttributeEquals('testFileId1', 'fileId', $item); + $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item); $this->assertAttributeEquals(1, 'duration', $item); $this->assertAttributeEquals('testperformer', 'performer', $item); $this->assertAttributeEquals('testtitle', 'title', $item); @@ -110,23 +112,42 @@ public function testFromResponse() } /** + * file_id is missing * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException() { $item = Audio::fromResponse(array( + 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 )); } + /** + * duration is missing * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException2() { $item = Audio::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + )); + } + + /** + * file_unique_id is missing + * @expectedException \TelegramBot\Api\InvalidArgumentException + */ + public function testFromResponseException3() + { + $item = Audio::fromResponse(array( + 'file_id' => 'testFileId1', + 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 )); diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php index 9aee4cd4..c1cce2b3 100644 --- a/tests/DocumentTest.php +++ b/tests/DocumentTest.php @@ -27,6 +27,7 @@ public function testSetThumb() $item = new Document(); $thumb = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -40,6 +41,7 @@ public function testGetThumb() $item = new Document(); $thumb = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -104,11 +106,13 @@ public function testFromResponse() { $item = Document::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', 'file_size' => 3, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -116,12 +120,14 @@ public function testFromResponse() )); $thumb = PhotoSize::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 )); $this->assertInstanceOf('\TelegramBot\Api\Types\Document', $item); $this->assertAttributeEquals('testFileId1', 'fileId', $item); + $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item); $this->assertAttributeEquals('testFileName', 'fileName', $item); $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); $this->assertAttributeEquals(3, 'fileSize', $item); @@ -130,6 +136,7 @@ public function testFromResponse() } /** + * file_id and file_unique_id are required * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException1() @@ -140,6 +147,7 @@ public function testFromResponseException1() 'file_size' => 3, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 5419a907..8456350c 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -222,11 +222,13 @@ public function testSetDocument() $item = new Message(); $document = Document::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', 'file_size' => 3, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -241,11 +243,13 @@ public function testGetDocument() $item = new Message(); $document = Document::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', 'file_size' => 3, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -278,6 +282,7 @@ public function testSetAudio() $item = new Message(); $audio = Audio::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 @@ -291,6 +296,7 @@ public function testGetAudio() $item = new Message(); $audio = Audio::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 @@ -334,6 +340,7 @@ public function testSetVideo() $item = new Message(); $video = Video::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testUniqueFileId', 'width' => 1, 'height' => 2, 'duration' => 3, @@ -341,6 +348,7 @@ public function testSetVideo() 'file_size' => 4, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -355,6 +363,7 @@ public function testGetVideo() $item = new Message(); $video = Video::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testUniqueFileId', 'width' => 1, 'height' => 2, 'duration' => 3, @@ -362,6 +371,7 @@ public function testGetVideo() 'file_size' => 4, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -400,11 +410,16 @@ public function testSetSticker() $item = new Message(); $sticker = Sticker::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testUniqueFileId', 'width' => 1, 'height' => 2, 'file_size' => 3, + 'is_animated' => false, + 'is_video' => false, + 'type' => 'regular', 'thumb' => array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testUniqueFileId', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -419,11 +434,16 @@ public function testGetSticker() $item = new Message(); $sticker = Sticker::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testUniqueFileId', 'width' => 1, 'height' => 2, 'file_size' => 3, + 'is_animated' => false, + 'is_video' => false, + 'type' => 'regular', 'thumb' => array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testUniqueFileId', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -668,6 +688,7 @@ public function testSetPhoto() $photo = array( PhotoSize::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -685,6 +706,7 @@ public function testGetPhoto() $photo = array( PhotoSize::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -706,6 +728,7 @@ public function testGetNewChatPhoto() $photo = array( PhotoSize::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -722,6 +745,7 @@ public function testSetNewChatPhoto() $photo = array( PhotoSize::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 diff --git a/tests/PhotoSizeTest.php b/tests/PhotoSizeTest.php index 215df137..946a0e7b 100644 --- a/tests/PhotoSizeTest.php +++ b/tests/PhotoSizeTest.php @@ -66,12 +66,14 @@ public function testFromResponse() { $photoSize = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 )); $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photoSize); $this->assertAttributeEquals('testFileId1', 'fileId', $photoSize); + $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $photoSize); $this->assertAttributeEquals(1, 'width', $photoSize); $this->assertAttributeEquals(2, 'height', $photoSize); $this->assertAttributeEquals(3, 'fileSize', $photoSize); diff --git a/tests/StickerTest.php b/tests/StickerTest.php index 3d37f849..95c35b5f 100644 --- a/tests/StickerTest.php +++ b/tests/StickerTest.php @@ -67,6 +67,7 @@ public function testSetThumb() $sticker = new Sticker(); $thumb = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -80,6 +81,7 @@ public function testGetThumb() $sticker = new Sticker(); $thumb = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -93,11 +95,16 @@ public function testFromResponse() { $sticker = Sticker::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3, + 'is_animated' => false, + 'is_video' => false, + 'type' => 'regular', 'thumb' => array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -105,12 +112,14 @@ public function testFromResponse() )); $thumb = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 )); $this->assertInstanceOf('\TelegramBot\Api\Types\Sticker', $sticker); $this->assertAttributeEquals('testFileId1', 'fileId', $sticker); + $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $sticker); $this->assertAttributeEquals(1, 'width', $sticker); $this->assertAttributeEquals(2, 'height', $sticker); $this->assertAttributeEquals(3, 'fileSize', $sticker); diff --git a/tests/UserProfilePhotosTest.php b/tests/UserProfilePhotosTest.php index 2a489119..cb9d889e 100644 --- a/tests/UserProfilePhotosTest.php +++ b/tests/UserProfilePhotosTest.php @@ -30,6 +30,7 @@ public function testSetPhotos() $photos[] = array( PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => $i, 'height' => $i * 2, 'file_size' => $i * 3 @@ -48,6 +49,7 @@ public function testGetPhotos() for ($i = 0; $i < 10; $i++) { $photos[] = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => $i, 'height' => $i * 2, 'file_size' => $i * 3 @@ -66,6 +68,7 @@ public function testFromResponse() array( array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -77,6 +80,7 @@ public function testFromResponse() array( PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 diff --git a/tests/VideoTest.php b/tests/VideoTest.php index 4cea8536..a9ee1a0b 100644 --- a/tests/VideoTest.php +++ b/tests/VideoTest.php @@ -68,6 +68,7 @@ public function testSetThumb() $item = new Video(); $thumb = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -81,6 +82,7 @@ public function testGetThumb() $item = new Video(); $thumb = PhotoSize::fromResponse(array( "file_id" => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 @@ -122,6 +124,7 @@ public function testFromResponse() { $item = Video::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'duration' => 3, @@ -129,6 +132,7 @@ public function testFromResponse() 'file_size' => 4, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -136,12 +140,14 @@ public function testFromResponse() )); $thumb = PhotoSize::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 )); $this->assertInstanceOf('\TelegramBot\Api\Types\Video', $item); $this->assertAttributeEquals('testFileId1', 'fileId', $item); + $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item); $this->assertAttributeEquals(1, 'width', $item); $this->assertAttributeEquals(2, 'height', $item); $this->assertAttributeEquals(3, 'duration', $item); @@ -187,11 +193,13 @@ public function testSetFileSizeException() } /** + * file_id is required * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException1() { $item = Video::fromResponse(array( + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'duration' => 3, @@ -206,18 +214,21 @@ public function testFromResponseException1() )); } /** + * width is required * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException2() { $item = Video::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'height' => 2, 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -226,18 +237,21 @@ public function testFromResponseException2() } /** + * height is required * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException3() { $item = Video::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 @@ -246,18 +260,44 @@ public function testFromResponseException3() } /** + * duration is required * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException4() { $item = Video::fromResponse(array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'mime_type' => 'video/mp4', 'file_size' => 4, 'thumb' => array( 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 5, + 'height' => 6, + 'file_size' => 7 + ) + )); + } + + /** + * file_unique_id is required + * @expectedException \TelegramBot\Api\InvalidArgumentException + */ + public function testFromResponseException5() + { + $item = Video::fromResponse(array( + 'file_id' => 'testFileId1', + 'width' => 1, + 'height' => 2, + 'duration' => 1, + 'mime_type' => 'video/mp4', + 'file_size' => 4, + 'thumb' => array( + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 From b6bd05164aa775bca3bebb56fe14bfdd78be7cdd Mon Sep 17 00:00:00 2001 From: Pavel Novikov Date: Thu, 9 Mar 2023 09:47:48 +0400 Subject: [PATCH 085/130] Default value for $inlineKeyboard Default value for $inlineKeyboard to allow the constructor to be called with no arguments. --- src/Types/Inline/InlineKeyboardMarkup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Types/Inline/InlineKeyboardMarkup.php b/src/Types/Inline/InlineKeyboardMarkup.php index 92a5b270..170bd357 100644 --- a/src/Types/Inline/InlineKeyboardMarkup.php +++ b/src/Types/Inline/InlineKeyboardMarkup.php @@ -39,7 +39,7 @@ class InlineKeyboardMarkup extends BaseType /** * @param array $inlineKeyboard */ - public function __construct($inlineKeyboard) + public function __construct($inlineKeyboard = []) { $this->inlineKeyboard = $inlineKeyboard; } From 8964e050cc972772a6edbc9a3618d2ea4ccea75e Mon Sep 17 00:00:00 2001 From: Dmitriy Mamontov Date: Sat, 1 Apr 2023 09:29:55 +0300 Subject: [PATCH 086/130] fix Animation type add file_unique_id field --- src/Types/Animation.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Types/Animation.php b/src/Types/Animation.php index 2e28e5a0..ad50e9d9 100644 --- a/src/Types/Animation.php +++ b/src/Types/Animation.php @@ -45,6 +45,13 @@ class Animation extends BaseType implements TypeInterface */ protected $fileId; + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + /** * Video width as defined by sender * @@ -132,6 +139,22 @@ public function setFileId($fileId) $this->fileId = $fileId; } + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + /** * @return int */ From 441e7f5c87abe85b67a75d662ddae0571df87175 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Sat, 22 Apr 2023 12:04:43 +0200 Subject: [PATCH 087/130] fix #406 api method class for message location --- src/BotApi.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 59ca02e9..6ae0f306 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -670,7 +670,7 @@ public function editMessageLiveLocation( $longitude, $replyMarkup = null ) { - return Message::fromResponse($this->call('sendLocation', [ + return Message::fromResponse($this->call('editMessageLiveLocation', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, @@ -699,7 +699,7 @@ public function stopMessageLiveLocation( $inlineMessageId, $replyMarkup = null ) { - return Message::fromResponse($this->call('sendLocation', [ + return Message::fromResponse($this->call('stopMessageLiveLocation', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, From 88ae0c150a51f3fde199ba63e45b50df7b7dab88 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Fri, 21 Apr 2023 23:57:45 +0300 Subject: [PATCH 088/130] Use symfony/phpunit-bridge --- .github/workflows/tests.yaml | 60 +++ .gitignore | 4 +- .scrutinizer.yml | 26 -- .travis.yml | 21 - README.md | 3 - composer.json | 11 +- phpunit.xml.dist | 11 - tests/ArrayOfPhotoSizeTest.php | 3 +- tests/AudioTest.php | 82 +--- tests/BaseTypeTest.php | 29 +- tests/BotApiTest.php | 8 +- tests/BotCommandTest.php | 17 +- tests/ChatLocationTest.php | 7 +- tests/ChatTest.php | 95 +---- tests/ClientTest.php | 23 +- tests/Collection/CollectionTest.php | 7 +- tests/ContactTest.php | 38 +- tests/DocumentTest.php | 70 +--- tests/FileTest.php | 43 +- tests/ForceReplyTest.php | 37 +- tests/LocationTest.php | 75 +--- tests/LoginUrlTest.php | 11 +- tests/MessageTest.php | 375 +----------------- tests/PhotoSizeTest.php | 59 +-- tests/PollAnswerTest.php | 5 +- tests/PollTest.php | 102 +---- tests/ReplyKeyboardHideTest.php | 37 +- tests/ReplyKeyboardMarkupTest.php | 67 +--- tests/StickerTest.php | 78 +--- tests/Types/ArrayOfUpdatesTest.php | 5 +- tests/Types/CallbackQueryTest.php | 73 +--- tests/Types/Events/EventCollectionTest.php | 23 +- tests/Types/Events/EventTest.php | 9 +- tests/Types/Inline/ChosenInlineResultTest.php | 54 +-- .../Types/Inline/InlineKeyboardMarkupTest.php | 13 +- tests/Types/Inline/InlineQueryTest.php | 71 ++-- tests/Types/MessageEntityTest.php | 3 +- tests/UserProfilePhotosTest.php | 45 +-- tests/UserTest.php | 52 +-- tests/VideoTest.php | 118 ++---- tests/VoiceTest.php | 75 +--- tests/WebhookInfoTest.php | 3 +- tests/_fixtures/TestBaseType.php | 9 - 43 files changed, 445 insertions(+), 1512 deletions(-) create mode 100644 .github/workflows/tests.yaml delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml delete mode 100644 tests/_fixtures/TestBaseType.php diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..c1839438 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,60 @@ +on: + - pull_request + - push + +name: Tests + +jobs: + tests: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + php: + - "5.5" + - "5.6" + - "7.0" + - "7.1" + - "7.2" + - "7.3" + - "7.4" + - "8.0" + - "8.1" + - "8.2" + steps: + - + name: Checkout + uses: actions/checkout@v2 + + - + name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + + - + name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - + name: Cache dependencies installed with composer + uses: actions/cache@v2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer-{{ matrix.deps }}- + - + name: Update composer + run: composer self-update + + - + name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - + name: Run tests with phpunit + run: vendor/bin/simple-phpunit --colors=always diff --git a/.gitignore b/.gitignore index 34de0587..2487936e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ composer.lock docs vendor +.phpunit.result.cache + ### JetBrains template # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm @@ -55,4 +57,4 @@ crashlytics-build.properties # Composer vendor/ -/*.php \ No newline at end of file +/*.php diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 0fbe2943..00000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,26 +0,0 @@ -filter: - excluded_paths: [tests/*] - -checks: - php: - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true -build: - tests: - override: - - - command: 'phpunit --coverage-text --coverage-clover=coverage.clover' - coverage: - file: 'coverage.clover' - format: 'php-clover' \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 19ced7b7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: php -dist: trusty - -php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - hhvm - -matrix: - allow_failures: - - php: hhvm - -before_script: - - travis_retry composer self-update - - COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source - -script: - - php vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 src/ - - phpunit --coverage-text --coverage-clover=coverage.clover \ No newline at end of file diff --git a/README.md b/README.md index dba2979c..7524749e 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,6 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/telegram-bot/api.svg?style=flat-square)](https://packagist.org/packages/telegram-bot/api) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) -[![Build Status](https://img.shields.io/travis/TelegramBot/Api/master.svg?style=flat-square)](https://travis-ci.org/TelegramBot/Api) -[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/telegrambot/api.svg?style=flat-square)](https://scrutinizer-ci.com/g/telegrambot/api/code-structure) -[![Quality Score](https://img.shields.io/scrutinizer/g/telegrambot/api.svg?style=flat-square)](https://scrutinizer-ci.com/g/telegrambot/api) [![Total Downloads](https://img.shields.io/packagist/dt/telegram-bot/api.svg?style=flat-square)](https://packagist.org/packages/telegram-bot/api) An extended native php wrapper for [Telegram Bot API](https://core.telegram.org/bots/api) without requirements. Supports all methods and types of responses. diff --git a/composer.json b/composer.json index 086cc4e3..56a69646 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,11 @@ ], "require": { "php" : ">=5.5.0", - "ext-curl": "*" + "ext-curl": "*", + "ext-json": "*" }, "require-dev": { - "phpunit/phpunit" : "~4.0", - "squizlabs/php_codesniffer": "2.*", - "codeception/codeception": "*" + "symfony/phpunit-bridge" : "*" }, "autoload": { "psr-4": { @@ -37,11 +36,11 @@ } }, "scripts": { - "test": "phpunit" + "test": "vendor/bin/simple-phpunit" }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.3-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4abf248a..f2eebe03 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,16 +18,5 @@ src/ - - tests/ - vendor/ - - - - - - - - diff --git a/tests/ArrayOfPhotoSizeTest.php b/tests/ArrayOfPhotoSizeTest.php index 8f51e1b6..1a75816f 100644 --- a/tests/ArrayOfPhotoSizeTest.php +++ b/tests/ArrayOfPhotoSizeTest.php @@ -3,10 +3,11 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\PhotoSize; use TelegramBot\Api\Types\ArrayOfPhotoSize; -class ArrayOfPhotoSizeTest extends \PHPUnit_Framework_TestCase +class ArrayOfPhotoSizeTest extends TestCase { public function testFromResponse() diff --git a/tests/AudioTest.php b/tests/AudioTest.php index 022e1edf..11497d7d 100644 --- a/tests/AudioTest.php +++ b/tests/AudioTest.php @@ -2,18 +2,13 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\Audio; -class AudioTest extends \PHPUnit_Framework_TestCase +class AudioTest extends TestCase { public function testSetFileId() - { - $item = new Audio(); - $item->setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() { $item = new Audio(); $item->setFileId('testfileId'); @@ -21,13 +16,6 @@ public function testGetFileId() } public function testSetDuration() - { - $item = new Audio(); - $item->setDuration(1); - $this->assertAttributeEquals(1, 'duration', $item); - } - - public function testGetDuration() { $item = new Audio(); $item->setDuration(1); @@ -35,13 +23,6 @@ public function testGetDuration() } public function testSetPerformer() - { - $item = new Audio(); - $item->setPerformer('test'); - $this->assertAttributeEquals('test', 'performer', $item); - } - - public function testGetPerformer() { $item = new Audio(); $item->setPerformer('test'); @@ -49,13 +30,6 @@ public function testGetPerformer() } public function testSetTitle() - { - $item = new Audio(); - $item->setTitle('test'); - $this->assertAttributeEquals('test', 'title', $item); - } - - public function testGetTitle() { $item = new Audio(); $item->setTitle('test'); @@ -63,13 +37,6 @@ public function testGetTitle() } public function testSetFileSize() - { - $item = new Audio(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() { $item = new Audio(); $item->setFileSize(6); @@ -77,13 +44,6 @@ public function testGetFileSize() } public function testSetMimeType() - { - $item = new Audio(); - $item->setMimeType('audio/mp3'); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - } - - public function testGetMimeType() { $item = new Audio(); $item->setMimeType('audio/mp3'); @@ -101,22 +61,23 @@ public function testFromResponse() 'mime_type' => 'audio/mp3', 'file_size' => 3 )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Audio', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item); - $this->assertAttributeEquals(1, 'duration', $item); - $this->assertAttributeEquals('testperformer', 'performer', $item); - $this->assertAttributeEquals('testtitle', 'title', $item); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - $this->assertAttributeEquals(3, 'fileSize', $item); + $this->assertInstanceOf(Audio::class, $item); + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getDuration()); + $this->assertEquals('testperformer', $item->getPerformer()); + $this->assertEquals('testtitle', $item->getTitle()); + $this->assertEquals('audio/mp3', $item->getMimeType()); + $this->assertEquals(3, $item->getFileSize()); } /** * file_id is missing - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException() { + $this->expectException(InvalidArgumentException::class); + $item = Audio::fromResponse(array( 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, @@ -127,10 +88,11 @@ public function testFromResponseException() /** * duration is missing - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException2() { + $this->expectException(InvalidArgumentException::class); + $item = Audio::fromResponse(array( 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', @@ -141,10 +103,11 @@ public function testFromResponseException2() /** * file_unique_id is missing - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException3() { + $this->expectException(InvalidArgumentException::class); + $item = Audio::fromResponse(array( 'file_id' => 'testFileId1', 'duration' => 1, @@ -153,19 +116,18 @@ public function testFromResponseException3() )); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetDurationException() { + $this->expectException(InvalidArgumentException::class); + $item = new Audio(); $item->setDuration('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ + public function testSetFileSizeException() { + $this->expectException(InvalidArgumentException::class); + $item = new Audio(); $item->setFileSize('s'); } diff --git a/tests/BaseTypeTest.php b/tests/BaseTypeTest.php index 4b3ec98e..269973d9 100644 --- a/tests/BaseTypeTest.php +++ b/tests/BaseTypeTest.php @@ -2,29 +2,26 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\BaseType; +use TelegramBot\Api\InvalidArgumentException; -class BaseTypeTest extends \PHPUnit_Framework_TestCase +class BaseTypeTest extends TestCase { - public function setUp() + public function testValidate() { - include_once('tests/_fixtures/TestBaseType.php'); + $this->assertTrue(TestBaseType::validate(array('test1' => 1, 'test2' => 2, 'test3' => 3))); } - public function testRequiredParams() + public function testValidateFail() { - $testItem = new \TestBaseType(); + $this->expectException(InvalidArgumentException::class); - $this->assertAttributeEquals(array('test1', 'test2'), 'requiredParams', $testItem); - } - - public function testValidate() { - $this->assertTrue(\TestBaseType::validate(array('test1' => 1, 'test2' => 2, 'test3' => 3))); + $this->assertTrue(TestBaseType::validate(array('test1' => 1))); } +} - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testValidateFail() { - $this->assertTrue(\TestBaseType::validate(array('test1' => 1))); - } +class TestBaseType extends BaseType +{ + protected static $requiredParams = array('test1', 'test2'); } diff --git a/tests/BotApiTest.php b/tests/BotApiTest.php index 341bab3b..ce376d6c 100644 --- a/tests/BotApiTest.php +++ b/tests/BotApiTest.php @@ -2,11 +2,12 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\BotApi; use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\Update; -class BotApiTest extends \PHPUnit_Framework_TestCase +class BotApiTest extends TestCase { public function data() { @@ -107,7 +108,7 @@ public function data() */ public function testGetUpdates($updates) { - $mock = $this->getMockBuilder('\TelegramBot\Api\BotApi') + $mock = $this->getMockBuilder(BotApi::class) ->setMethods(['call']) ->enableOriginalConstructor() ->setConstructorArgs(['testToken']) @@ -119,11 +120,10 @@ public function testGetUpdates($updates) $expectedResult = ArrayOfUpdates::fromResponse($updates); $result = $mock->getUpdates(); - $this->assertInternalType('array', $result); $this->assertEquals($expectedResult, $result); foreach($result as $key => $item) { - $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $item); + $this->assertInstanceOf(Update::class, $item); $this->assertEquals($expectedResult[$key], $item); } } diff --git a/tests/BotCommandTest.php b/tests/BotCommandTest.php index d8d98502..900a2039 100644 --- a/tests/BotCommandTest.php +++ b/tests/BotCommandTest.php @@ -2,18 +2,12 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\BotCommand; -class BotCommandTest extends \PHPUnit_Framework_TestCase +class BotCommandTest extends TestCase { public function testSetCommand() - { - $item = new BotCommand(); - $item->setCommand('start'); - $this->assertAttributeEquals('start', 'command', $item); - } - - public function testGetCommand() { $item = new BotCommand(); $item->setCommand('start'); @@ -21,13 +15,6 @@ public function testGetCommand() } public function testSetDescription() - { - $item = new BotCommand(); - $item->setDescription('This is a start command!'); - $this->assertAttributeEquals('This is a start command!', 'description', $item); - } - - public function testGetDescription() { $item = new BotCommand(); $item->setDescription('This is a start command!'); diff --git a/tests/ChatLocationTest.php b/tests/ChatLocationTest.php index a9693311..47b1e1a2 100644 --- a/tests/ChatLocationTest.php +++ b/tests/ChatLocationTest.php @@ -2,10 +2,11 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\ChatLocation; use TelegramBot\Api\Types\Location; -class ChatLocationTest extends \PHPUnit_Framework_TestCase +class ChatLocationTest extends TestCase { public function testGetLocation() { @@ -39,7 +40,7 @@ public function testFromResponse() 'address' => 'Wall St. 123' ] ); - $this->assertInstanceOf('\TelegramBot\Api\Types\ChatLocation', $chatLocation); - $this->assertAttributeEquals('Wall St. 123', 'address', $chatLocation); + $this->assertInstanceOf(ChatLocation::class, $chatLocation); + $this->assertEquals('Wall St. 123', $chatLocation->getAddress()); } } diff --git a/tests/ChatTest.php b/tests/ChatTest.php index b0b463ea..1f9ce5ae 100644 --- a/tests/ChatTest.php +++ b/tests/ChatTest.php @@ -2,10 +2,12 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\Chat; use TelegramBot\Api\Types\ChatPhoto; -class ChatTest extends \PHPUnit_Framework_TestCase +class ChatTest extends TestCase { public function testFromResponseGroupChat() { @@ -25,31 +27,17 @@ public function testSetId() { $chat = new Chat(); $chat->setId(1); - $this->assertAttributeEquals(1, 'id', $chat); + $this->assertEquals(1, $chat->getId()); } public function testSet64bitId() { $chat = new Chat(); $chat->setId(2147483648); - $this->assertAttributeEquals(2147483648, 'id', $chat); - } - - public function testGetId() - { - $chat = new Chat(); - $chat->setId(1); - $this->assertEquals(1, $chat->getId()); + $this->assertEquals(2147483648, $chat->getId()); } public function testSetType() - { - $chat = new Chat(); - $chat->setType('private'); - $this->assertAttributeEquals('private', 'type', $chat); - } - - public function testGetType() { $chat = new Chat(); $chat->setType('private'); @@ -57,13 +45,6 @@ public function testGetType() } public function testSetTitle() - { - $chat = new Chat(); - $chat->setTitle('test chat'); - $this->assertAttributeEquals('test chat', 'title', $chat); - } - - public function testGetTitle() { $chat = new Chat(); $chat->setTitle('test chat'); @@ -71,13 +52,6 @@ public function testGetTitle() } public function testSetUsername() - { - $chat = new Chat(); - $chat->setUsername('iGusev'); - $this->assertAttributeEquals('iGusev', 'username', $chat); - } - - public function testGetUsername() { $chat = new Chat(); $chat->setUsername('iGusev'); @@ -85,13 +59,6 @@ public function testGetUsername() } public function testSetFirstName() - { - $chat = new Chat(); - $chat->setFirstName('Ilya'); - $this->assertAttributeEquals('Ilya', 'firstName', $chat); - } - - public function testGetFirstName() { $chat = new Chat(); $chat->setFirstName('Ilya'); @@ -99,13 +66,6 @@ public function testGetFirstName() } public function testSetLastName() - { - $chat = new Chat(); - $chat->setLastName('Gusev'); - $this->assertAttributeEquals('Gusev', 'lastName', $chat); - } - - public function testGetLastName() { $chat = new Chat(); $chat->setLastName('Gusev'); @@ -113,17 +73,6 @@ public function testGetLastName() } public function testSetPhoto() - { - $chat = new Chat(); - $photo = ChatPhoto::fromResponse([ - 'small_file_id' => 'small_file_id', - 'big_file_id' => 'big_file_id' - ]); - $chat->setPhoto($photo); - $this->assertAttributeEquals($photo, 'photo', $chat); - } - - public function testGetPhoto() { $chat = new Chat(); $photo = ChatPhoto::fromResponse([ @@ -135,13 +84,6 @@ public function testGetPhoto() } public function testSetBio() - { - $chat = new Chat(); - $chat->setBio('PHP Telegram Bot API'); - $this->assertAttributeEquals('PHP Telegram Bot API', 'bio', $chat); - } - - public function testGetBio() { $chat = new Chat(); $chat->setBio('PHP Telegram Bot API'); @@ -149,13 +91,6 @@ public function testGetBio() } public function testSetDescriptions() - { - $chat = new Chat(); - $chat->setDescription('description'); - $this->assertAttributeEquals('description', 'description', $chat); - } - - public function testGetDescription() { $chat = new Chat(); $chat->setDescription('description'); @@ -181,39 +116,35 @@ public function testFromResponseUser() $this->assertEquals('PHP Telegram Bot API', $item->getBio()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetIdException1() { + $this->expectException(InvalidArgumentException::class); + $chat = new Chat(); $chat->setId([]); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetIdException2() { + $this->expectException(InvalidArgumentException::class); + $chat = new Chat(); $chat->setId(null); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testFromResponseException2() { + $this->expectException(InvalidArgumentException::class); + $chat = Chat::fromResponse(array( 'id' => 1 )); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testFromResponseException3() { + $this->expectException(InvalidArgumentException::class); + $chat = Chat::fromResponse(array( 'type' => 'private' )); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index d5f82d8b..db170d25 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -3,14 +3,17 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use Symfony\Component\Yaml\Inline; +use TelegramBot\Api\BadMethodCallException; use TelegramBot\Api\BotApi; use TelegramBot\Api\Client; +use TelegramBot\Api\Events\EventCollection; use TelegramBot\Api\Types\Inline\InlineQuery; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Update; -class ClientTest extends \PHPUnit_Framework_TestCase +class ClientTest extends TestCase { public function data() { @@ -133,24 +136,14 @@ public function testGetInlineQueryChecker($update) $this->assertEquals(!is_null($update->getInlineQuery()), call_user_func($result, $update)); } - /** - * @expectedException \TelegramBot\Api\BadMethodCallException - * @expectedExceptionMessage Method testMethod not exists - */ public function testBadMethodCallException() { - $item = new Client('testToken'); - - $item->testMethod(); - } + $this->expectException(BadMethodCallException::class); + $this->expectErrorMessage('Method testMethod not exists'); - public function testConstructor() - { $item = new Client('testToken'); - $this->assertInstanceOf('\TelegramBot\Api\Client', $item); - $this->assertAttributeInstanceOf('\TelegramBot\Api\BotApi', 'api', $item); - $this->assertAttributeInstanceOf('\TelegramBot\Api\Events\EventCollection', 'events', $item); + $item->testMethod(); } public function testOn() @@ -303,4 +296,4 @@ public function testGetInlineQueryEvent($update) $this->assertEquals(1, $test); } } -} \ No newline at end of file +} diff --git a/tests/Collection/CollectionTest.php b/tests/Collection/CollectionTest.php index a63a262d..2a56970f 100644 --- a/tests/Collection/CollectionTest.php +++ b/tests/Collection/CollectionTest.php @@ -1,13 +1,14 @@ setExpectedException(ReachedMaxSizeException::class); + $this->expectException(ReachedMaxSizeException::class); $media = new ArrayOfInputMedia(); $media->setMaxCount(2); for ($i = 1; $i < 3; $i++) { diff --git a/tests/ContactTest.php b/tests/ContactTest.php index d754de97..34e8eb39 100644 --- a/tests/ContactTest.php +++ b/tests/ContactTest.php @@ -2,18 +2,12 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\Contact; -class ContactTest extends \PHPUnit_Framework_TestCase +class ContactTest extends TestCase { public function testSetPhoneNumber() - { - $contact = new Contact(); - $contact->setPhoneNumber('123456'); - $this->assertAttributeEquals('123456', 'phoneNumber', $contact); - } - - public function testGetPhoneNumber() { $contact = new Contact(); $contact->setPhoneNumber('123456'); @@ -21,13 +15,6 @@ public function testGetPhoneNumber() } public function testSetFirstName() - { - $contact = new Contact(); - $contact->setFirstName('Ilya'); - $this->assertAttributeEquals('Ilya', 'firstName', $contact); - } - - public function testGetFirstName() { $contact = new Contact(); $contact->setFirstName('Ilya'); @@ -35,13 +22,6 @@ public function testGetFirstName() } public function testSetLastName() - { - $contact = new Contact(); - $contact->setLastName('Gusev'); - $this->assertAttributeEquals('Gusev', 'lastName', $contact); - } - - public function testGetLastName() { $contact = new Contact(); $contact->setLastName('Gusev'); @@ -49,13 +29,6 @@ public function testGetLastName() } public function testSetUserId() - { - $contact = new Contact(); - $contact->setUserId('iGusev'); - $this->assertAttributeEquals('iGusev', 'userId', $contact); - } - - public function testGetUserId() { $contact = new Contact(); $contact->setUserId('iGusev'); @@ -63,13 +36,6 @@ public function testGetUserId() } public function testSetVcard() - { - $contact = new Contact(); - $contact->setVcard('testVcard'); - $this->assertAttributeEquals('testVcard', 'vcard', $contact); - } - - public function testGetVCard() { $contact = new Contact(); $contact->setVCard('testVCard'); diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php index c1cce2b3..8b2eb0a2 100644 --- a/tests/DocumentTest.php +++ b/tests/DocumentTest.php @@ -3,19 +3,14 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\Document; use TelegramBot\Api\Types\PhotoSize; -class DocumentTest extends \PHPUnit_Framework_TestCase +class DocumentTest extends TestCase { public function testSetFileId() - { - $item = new Document(); - $item->setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() { $item = new Document(); $item->setFileId('testfileId'); @@ -23,20 +18,6 @@ public function testGetFileId() } public function testSetThumb() - { - $item = new Document(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $item->setThumb($thumb); - $this->assertAttributeEquals($thumb, 'thumb', $item); - } - - public function testGetThumb() { $item = new Document(); $thumb = PhotoSize::fromResponse(array( @@ -52,13 +33,6 @@ public function testGetThumb() } public function testSetFileName() - { - $item = new Document(); - $item->setFileName('testfileName'); - $this->assertAttributeEquals('testfileName', 'fileName', $item); - } - - public function testGetFileName() { $item = new Document(); $item->setFileName('testfileName'); @@ -66,13 +40,6 @@ public function testGetFileName() } public function testSetFileSize() - { - $item = new Document(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() { $item = new Document(); $item->setFileSize(6); @@ -80,24 +47,16 @@ public function testGetFileSize() } public function testSetMimeType() - { - $item = new Document(); - $item->setMimeType('audio/mp3'); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - } - - public function testGetMimeType() { $item = new Document(); $item->setMimeType('audio/mp3'); $this->assertEquals('audio/mp3', $item->getMimeType()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetFileSizeException() { + $this->expectException(InvalidArgumentException::class); + $item = new Document(); $item->setFileSize('s'); } @@ -125,22 +84,23 @@ public function testFromResponse() 'height' => 6, 'file_size' => 7 )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Document', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item); - $this->assertAttributeEquals('testFileName', 'fileName', $item); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - $this->assertAttributeEquals(3, 'fileSize', $item); - $this->assertAttributeEquals($thumb, 'thumb', $item); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); + $this->assertInstanceOf(Document::class, $item); + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals('testFileName', $item->getFileName()); + $this->assertEquals('audio/mp3', $item->getMimeType()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals($thumb, $item->getThumb()); + $this->assertInstanceOf(PhotoSize::class, $item->getThumb()); } /** * file_id and file_unique_id are required - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException1() { + $this->expectException(InvalidArgumentException::class); + $item = Document::fromResponse(array( 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', diff --git a/tests/FileTest.php b/tests/FileTest.php index 459874d9..1c9cb281 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -1,18 +1,13 @@ setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() { $item = new File(); $item->setFileId('testfileId'); @@ -20,13 +15,6 @@ public function testGetFileId() } public function testSetFileSize() - { - $item = new File(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() { $item = new File(); $item->setFileSize(6); @@ -34,13 +22,6 @@ public function testGetFileSize() } public function testSetFilePath() - { - $item = new File(); - $item->setFilePath('testfilepath'); - $this->assertAttributeEquals('testfilepath', 'filePath', $item); - } - - public function testGetFilePath() { $item = new File(); $item->setFilePath('testfilepath'); @@ -54,28 +35,26 @@ public function testFromResponse() 'file_size' => 3, 'file_path' => 'testfilepath' )); - $this->assertInstanceOf('\TelegramBot\Api\Types\File', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals(3, 'fileSize', $item); - $this->assertAttributeEquals('testfilepath', 'filePath', $item); + $this->assertInstanceOf(File::class, $item); + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals('testfilepath', $item->getFilePath()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testFromResponseException() { + $this->expectException(InvalidArgumentException::class); + $item = File::fromResponse(array( 'file_size' => 3, 'file_path' => 'testfilepath' )); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetFileSizeException() { + $this->expectException(InvalidArgumentException::class); + $item = new File(); $item->setFileSize('s'); } diff --git a/tests/ForceReplyTest.php b/tests/ForceReplyTest.php index 56f916a1..a3f8db67 100644 --- a/tests/ForceReplyTest.php +++ b/tests/ForceReplyTest.php @@ -3,40 +3,41 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\ForceReply; -class ForceReplyTest extends \PHPUnit_Framework_TestCase +class ForceReplyTest extends TestCase { public function testConstructor() { $item = new ForceReply(); - $this->assertAttributeEquals(true, 'forceReply', $item); - $this->assertAttributeEquals(null, 'selective', $item); + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(null, $item->isSelective()); } public function testConstructor2() { $item = new ForceReply(true, true); - $this->assertAttributeEquals(true, 'forceReply', $item); - $this->assertAttributeEquals(true, 'selective', $item); + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(true, $item->isSelective()); } public function testConstructor3() { $item = new ForceReply(false, true); - $this->assertAttributeEquals(false, 'forceReply', $item); - $this->assertAttributeEquals(true, 'selective', $item); + $this->assertEquals(false, $item->isForceReply()); + $this->assertEquals(true, $item->isSelective()); } public function testConstructor4() { $item = new ForceReply(true); - $this->assertAttributeEquals(true, 'forceReply', $item); - $this->assertAttributeEquals(null, 'selective', $item); + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(null, $item->isSelective()); } public function testSetforceReply() @@ -45,15 +46,6 @@ public function testSetforceReply() $item->setforceReply(false); - $this->assertAttributeEquals(false, 'forceReply', $item); - } - - public function testIsforceReply() - { - $item = new ForceReply(true); - - $item->setforceReply(false); - $this->assertEquals(false, $item->isforceReply()); } @@ -63,15 +55,6 @@ public function testSetSelective() $item->setSelective(true); - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testIsSelective() - { - $item = new ForceReply(); - - $item->setSelective(true); - $this->assertEquals(true, $item->isSelective()); } diff --git a/tests/LocationTest.php b/tests/LocationTest.php index 322c5639..3bcdadf1 100644 --- a/tests/LocationTest.php +++ b/tests/LocationTest.php @@ -2,18 +2,13 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\Location; -class LocationTest extends \PHPUnit_Framework_TestCase +class LocationTest extends TestCase { public function testSetLatitude() - { - $location = new Location(); - $location->setLatitude(55.585827); - $this->assertAttributeEquals(55.585827, 'latitude', $location); - } - - public function testGetLatitude() { $location = new Location(); $location->setLatitude(55.585827); @@ -21,13 +16,6 @@ public function testGetLatitude() } public function testSetLongtitude() - { - $location = new Location(); - $location->setLongitude(37.675309); - $this->assertAttributeEquals(37.675309, 'longitude', $location); - } - - public function testGetLongtitude() { $location = new Location(); $location->setLongitude(37.675309); @@ -35,13 +23,6 @@ public function testGetLongtitude() } public function testSetHorizontalAccuracy() - { - $location = new Location(); - $location->setHorizontalAccuracy(20.5); - $this->assertAttributeEquals(20.5, 'horizontalAccuracy', $location); - } - - public function testGetHorizontalAccuracy() { $location = new Location(); $location->setHorizontalAccuracy(20.5); @@ -49,13 +30,6 @@ public function testGetHorizontalAccuracy() } public function testSetLivePeriod() - { - $location = new Location(); - $location->setLivePeriod(300); - $this->assertAttributeEquals(300, 'livePeriod', $location); - } - - public function testGetLivePeriod() { $location = new Location(); $location->setLivePeriod(300); @@ -63,13 +37,6 @@ public function testGetLivePeriod() } public function testSetHeading() - { - $location = new Location(); - $location->setHeading(100); - $this->assertAttributeEquals(100, 'heading', $location); - } - - public function testGetHeading() { $location = new Location(); $location->setHeading(100); @@ -77,13 +44,6 @@ public function testGetHeading() } public function testSetProximityAlertRadius() - { - $location = new Location(); - $location->setProximityAlertRadius(15); - $this->assertAttributeEquals(15, 'proximityAlertRadius', $location); - } - - public function testGetProximityAlertRadius() { $location = new Location(); $location->setProximityAlertRadius(100); @@ -102,38 +62,35 @@ public function testFromResponse() 'proximity_alert_radius' => 15 ) ); - $this->assertInstanceOf('\TelegramBot\Api\Types\Location', $location); - $this->assertAttributeEquals(55.585827, 'latitude', $location); - $this->assertAttributeEquals(37.675309, 'longitude', $location); - $this->assertAttributeEquals(20.5, 'horizontalAccuracy', $location); - $this->assertAttributeEquals(300, 'livePeriod', $location); - $this->assertAttributeEquals(100, 'heading', $location); - $this->assertAttributeEquals(15, 'proximityAlertRadius', $location); + $this->assertInstanceOf(Location::class, $location); + $this->assertEquals(55.585827, $location->getLatitude()); + $this->assertEquals(37.675309, $location->getLongitude()); + $this->assertEquals(20.5, $location->getHorizontalAccuracy()); + $this->assertEquals(300, $location->getLivePeriod()); + $this->assertEquals(100, $location->getHeading()); + $this->assertEquals(15, $location->getProximityAlertRadius()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetHorizontalAccuracyException() { + $this->expectException(InvalidArgumentException::class); + $item = new Location(); $item->setHorizontalAccuracy('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetLatitudeException() { + $this->expectException(InvalidArgumentException::class); + $item = new Location(); $item->setLatitude('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetLongitudeException() { + $this->expectException(InvalidArgumentException::class); + $item = new Location(); $item->setLongitude('s'); } diff --git a/tests/LoginUrlTest.php b/tests/LoginUrlTest.php index 301a783d..c73c75c2 100644 --- a/tests/LoginUrlTest.php +++ b/tests/LoginUrlTest.php @@ -2,16 +2,17 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\LoginUrl; -class LoginUrlTest extends \PHPUnit_Framework_TestCase +class LoginUrlTest extends TestCase { public function testGetUrl() { $loginUrl = new LoginUrl(); $loginUrl->setUrl('https://telegram.org'); - $this->assertAttributeEquals('https://telegram.org', 'url', $loginUrl); + $this->assertEquals('https://telegram.org', $loginUrl->getUrl()); } public function testGetForwardText() @@ -19,7 +20,7 @@ public function testGetForwardText() $loginUrl = new LoginUrl(); $loginUrl->setForwardText('Log in!'); - $this->assertAttributeEquals('Log in!', 'forwardText', $loginUrl); + $this->assertEquals('Log in!', $loginUrl->getForwardText()); } public function testGetBotUsername() @@ -27,7 +28,7 @@ public function testGetBotUsername() $loginUrl = new LoginUrl(); $loginUrl->setBotUsername('TestBot'); - $this->assertAttributeEquals('TestBot', 'botUsername', $loginUrl); + $this->assertEquals('TestBot', $loginUrl->getBotUsername()); } public function testGetRequestWriteAccess() @@ -53,4 +54,4 @@ public function testFromResponse() $this->assertEquals('TestBot', $loginUrl->getBotUsername()); $this->assertEquals(true, $loginUrl->isRequestWriteAccess()); } -} \ No newline at end of file +} diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 8456350c..d2a4d28f 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -2,6 +2,8 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\Chat; use TelegramBot\Api\Types\Dice; use TelegramBot\Api\Types\Document; @@ -16,38 +18,23 @@ use TelegramBot\Api\Types\Video; use TelegramBot\Api\Types\Voice; -class MessageTest extends \PHPUnit_Framework_TestCase +class MessageTest extends TestCase { - public function testSetMessageId() { $item = new Message(); $item->setMessageId(1); - $this->assertAttributeEquals(1, 'messageId', $item); + $this->assertEquals(1, $item->getMessageId()); } public function testSet64bitMessageId() { $item = new Message(); $item->setMessageId(2147483648); - $this->assertAttributeEquals(2147483648, 'messageId', $item); - } - - public function testGetMessageId() - { - $item = new Message(); - $item->setMessageId(1); - $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(2147483648, $item->getMessageId()); } public function testSetCaption() - { - $item = new Message(); - $item->setCaption('test'); - $this->assertAttributeEquals('test', 'caption', $item); - } - - public function testGetCaption() { $item = new Message(); $item->setCaption('test'); @@ -55,13 +42,6 @@ public function testGetCaption() } public function testSetDate() - { - $item = new Message(); - $item->setDate(1234567); - $this->assertAttributeEquals(1234567, 'date', $item); - } - - public function testGetDate() { $item = new Message(); $item->setDate(1234567); @@ -69,13 +49,6 @@ public function testGetDate() } public function testSetForwardDate() - { - $item = new Message(); - $item->setForwardDate(1234567); - $this->assertAttributeEquals(1234567, 'forwardDate', $item); - } - - public function testGetForwardDate() { $item = new Message(); $item->setForwardDate(1234567); @@ -83,19 +56,6 @@ public function testGetForwardDate() } public function testSetFrom() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setFrom($user); - $this->assertAttributeEquals($user, 'from', $item); - } - - public function testGetFrom() { $item = new Message(); $user = User::fromResponse(array( @@ -110,19 +70,6 @@ public function testGetFrom() } public function testSetForwardFrom() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setForwardFrom($user); - $this->assertAttributeEquals($user, 'forwardFrom', $item); - } - - public function testGetForwardFrom() { $item = new Message(); $user = User::fromResponse(array( @@ -137,18 +84,6 @@ public function testGetForwardFrom() } public function testSetChatGroup() - { - $item = new Message(); - $chat = Chat::fromResponse(array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - )); - $item->setChat($chat); - $this->assertAttributeEquals($chat, 'chat', $item); - } - - public function testGetChatGroup() { $item = new Message(); $chat = Chat::fromResponse(array( @@ -162,20 +97,6 @@ public function testGetChatGroup() } public function testSetChatUser() - { - $item = new Message(); - $user = Chat::fromResponse(array( - 'id' => 1, - 'type' => 'private', - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setChat($user); - $this->assertAttributeEquals($user, 'chat', $item); - } - - public function testGetChatUser() { $item = new Message(); $user = Chat::fromResponse(array( @@ -191,19 +112,6 @@ public function testGetChatUser() } public function testSetContact() - { - $item = new Message(); - $contact = Contact::fromResponse(array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'phone_number' => '123456', - 'user_id' => 'iGusev' - )); - $item->setContact($contact); - $this->assertAttributeEquals($contact, 'contact', $item); - } - - public function testGetContact() { $item = new Message(); $contact = Contact::fromResponse(array( @@ -218,27 +126,6 @@ public function testGetContact() } public function testSetDocument() - { - $item = new Message(); - $document = Document::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'file_name' => 'testFileName', - 'mime_type' => 'audio/mp3', - 'file_size' => 3, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - $item->setDocument($document); - $this->assertAttributeEquals($document, 'document', $item); - } - - public function testGetDocument() { $item = new Message(); $document = Document::fromResponse(array( @@ -261,14 +148,6 @@ public function testGetDocument() } public function testSetLocation() - { - $item = new Message(); - $location = Location::fromResponse(array('latitude' => 55.585827, 'longitude' => 37.675309)); - $item->setLocation($location); - $this->assertAttributeEquals($location, 'location', $item); - } - - public function testGetLocation() { $item = new Message(); $location = Location::fromResponse(array('latitude' => 55.585827, 'longitude' => 37.675309)); @@ -278,20 +157,6 @@ public function testGetLocation() } public function testSetAudio() - { - $item = new Message(); - $audio = Audio::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - $item->setAudio($audio); - $this->assertAttributeEquals($audio, 'audio', $item); - } - - public function testGetAudio() { $item = new Message(); $audio = Audio::fromResponse(array( @@ -307,20 +172,6 @@ public function testGetAudio() } public function testSetVoice() - { - $item = new Message(); - $voice = Voice::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testUniqueFileId', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - $item->setVoice($voice); - $this->assertAttributeEquals($voice, 'voice', $item); - } - - public function testGetVoice() { $item = new Message(); $voice = Voice::fromResponse(array( @@ -336,29 +187,6 @@ public function testGetVoice() } public function testSetVideo() - { - $item = new Message(); - $video = Video::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testUniqueFileId', - 'width' => 1, - 'height' => 2, - 'duration' => 3, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - $item->setVideo($video); - $this->assertAttributeEquals($video, 'video', $item); - } - - public function testGetVideo() { $item = new Message(); $video = Video::fromResponse(array( @@ -383,17 +211,6 @@ public function testGetVideo() } public function testSetDice() - { - $item = new Message(); - $dice = Dice::fromResponse(array( - 'emoji' => '🎲', - 'value' => 3 - )); - $item->setDice($dice); - $this->assertAttributeEquals($dice, 'dice', $item); - } - - public function testGetDice() { $item = new Message(); $dice = Dice::fromResponse(array( @@ -406,30 +223,6 @@ public function testGetDice() } public function testSetSticker() - { - $item = new Message(); - $sticker = Sticker::fromResponse(array( - "file_id" => 'testFileId1', - 'file_unique_id' => 'testUniqueFileId', - 'width' => 1, - 'height' => 2, - 'file_size' => 3, - 'is_animated' => false, - 'is_video' => false, - 'type' => 'regular', - 'thumb' => array( - "file_id" => 'testFileId1', - 'file_unique_id' => 'testUniqueFileId', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ) - )); - $item->setSticker($sticker); - $this->assertAttributeEquals($sticker, 'sticker', $item); - } - - public function testGetSticker() { $item = new Message(); $sticker = Sticker::fromResponse(array( @@ -459,14 +252,6 @@ public function testSetGroupChatCreated() $item = new Message(); $item->setGroupChatCreated(true); - $this->assertAttributeEquals(true, 'groupChatCreated', $item); - } - - public function testIsGroupChatCreated() - { - $item = new Message(); - $item->setGroupChatCreated(true); - $this->assertTrue($item->isGroupChatCreated()); } @@ -475,14 +260,6 @@ public function testSetDeleteChatPhoto() $item = new Message(); $item->setDeleteChatPhoto(true); - $this->assertAttributeEquals(true, 'deleteChatPhoto', $item); - } - - public function testIsDeleteChatPhoto() - { - $item = new Message(); - $item->setDeleteChatPhoto(true); - $this->assertTrue($item->isDeleteChatPhoto()); } @@ -497,21 +274,6 @@ public function testSetLeftChatParticipant() )); $item->setLeftChatMember($user); - - $this->assertAttributeEquals($user, 'leftChatMember', $item); - } - - public function testGetLeftChatParticipant() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setLeftChatMember($user); - $this->assertEquals($user, $item->getLeftChatMember()); $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getLeftChatMember()); } @@ -527,21 +289,6 @@ public function testSetNewChatParticipant() )); $item->setNewChatMembers([$user]); - - $this->assertAttributeEquals([$user], 'newChatMembers', $item); - } - - public function testGetNewChatParticipant() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setNewChatMembers([$user]); - $this->assertEquals([$user], $item->getNewChatMembers()); $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getNewChatMembers()[0]); } @@ -551,14 +298,6 @@ public function testSetNewChatTitle() $item = new Message(); $item->setNewChatTitle('testtitle'); - $this->assertAttributeEquals('testtitle', 'newChatTitle', $item); - } - - public function testGetNewChatTitle() - { - $item = new Message(); - $item->setNewChatTitle('testtitle'); - $this->assertEquals('testtitle', $item->getNewChatTitle()); } @@ -567,14 +306,6 @@ public function testSetText() $item = new Message(); $item->setText('testtitle'); - $this->assertAttributeEquals('testtitle', 'text', $item); - } - - public function testGetText() - { - $item = new Message(); - $item->setText('testtitle'); - $this->assertEquals('testtitle', $item->getText()); } @@ -598,48 +329,11 @@ public function testSetReplyToMessage() )); $item->setReplyToMessage($replyMessage); - $this->assertAttributeEquals($replyMessage, 'replyToMessage', $item); - } - - public function testGetReplyToMessage() - { - $item = new Message(); - $replyMessage = Message::fromResponse(array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ) - )); - $item->setReplyToMessage($replyMessage); - $this->assertEquals($replyMessage, $item->getReplyToMessage()); $this->assertInstanceOf('\TelegramBot\Api\Types\Message', $item->getReplyToMessage()); } public function testSetViaBot() - { - $item = new Message(); - $bot = User::fromResponse(array( - 'first_name' => 'Test', - 'last_name' => 'Bot', - 'username' => 'TestingBot', - 'is_bot' => 'true', - 'id' => 654321 - )); - $item->setViaBot($bot); - $this->assertAttributeEquals($bot, 'viaBot', $item); - } - - public function testGetViaBot() { $item = new Message(); $bot = User::fromResponse(array( @@ -656,7 +350,6 @@ public function testGetViaBot() public function testViaBotMessage() { - $item = new Message(); $item = Message::fromResponse(array( 'message_id' => 1, 'from' => array( @@ -697,24 +390,6 @@ public function testSetPhoto() $item->setPhoto($photo); - $this->assertAttributeEquals($photo, 'photo', $item); - } - - public function testGetPhoto() - { - $item = new Message(); - $photo = array( - PhotoSize::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - )) - ); - - $item->setPhoto($photo); - $this->assertEquals($photo, $item->getPhoto()); foreach ($item->getPhoto() as $photoItem) { @@ -735,23 +410,6 @@ public function testGetNewChatPhoto() )) ); - $item->setNewChatPhoto($photo); - $this->assertAttributeEquals($photo, 'newChatPhoto', $item); - } - - public function testSetNewChatPhoto() - { - $item = new Message(); - $photo = array( - PhotoSize::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - )) - ); - $item->setNewChatPhoto($photo); $this->assertEquals($photo, $item->getNewChatPhoto()); @@ -760,29 +418,26 @@ public function testSetNewChatPhoto() } } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetMessageIdException() { + $this->expectException(InvalidArgumentException::class); + $item = new Message(); $item->setMessageId('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetDateException() { + $this->expectException(InvalidArgumentException::class); + $item = new Message(); $item->setDate('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetForwardDateException() { + $this->expectException(InvalidArgumentException::class); + $item = new Message(); $item->setForwardDate('s'); } @@ -792,7 +447,7 @@ public function testSetSupergroupChatCreated() $item = new Message(); $item->setSupergroupChatCreated(true); - $this->assertAttributeEquals(true, 'supergroupChatCreated', $item); + $this->assertTrue($item->isSupergroupChatCreated()); } public function testIsSupergroupChatCreated() @@ -822,7 +477,7 @@ public function testSetChannelChatCreated() $item = new Message(); $item->setChannelChatCreated(true); - $this->assertAttributeEquals(true, 'channelChatCreated', $item); + $this->assertTrue($item->isChannelChatCreated()); } public function testIsChannelChatCreated() @@ -851,7 +506,7 @@ public function testSetMigrateToChatId() { $item = new Message(); $item->setMigrateToChatId(2); - $this->assertAttributeEquals(2, 'migrateToChatId', $item); + $this->assertEquals(2, $item->getMigrateToChatId()); } public function testGetMigrateToChatId() @@ -880,7 +535,7 @@ public function testSetMigrateFromChatId() { $item = new Message(); $item->setMigrateFromChatId(2); - $this->assertAttributeEquals(2, 'migrateFromChatId', $item); + $this->assertEquals(2, $item->getMigrateFromChatId()); } public function testGetMigrateFromChatId() diff --git a/tests/PhotoSizeTest.php b/tests/PhotoSizeTest.php index 946a0e7b..dcc62bcd 100644 --- a/tests/PhotoSizeTest.php +++ b/tests/PhotoSizeTest.php @@ -2,18 +2,13 @@ namespace TelegramBot\Api\Test; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\PhotoSize; +use PHPUnit\Framework\TestCase; -class PhotoSizeTest extends \PHPUnit_Framework_TestCase +class PhotoSizeTest extends TestCase { public function testSetFileId() - { - $photoSize = new PhotoSize(); - $photoSize->setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $photoSize); - } - - public function testGetFileId() { $photoSize = new PhotoSize(); $photoSize->setFileId('testfileId'); @@ -21,13 +16,6 @@ public function testGetFileId() } public function testSetWidth() - { - $photoSize = new PhotoSize(); - $photoSize->setWidth(1); - $this->assertAttributeEquals(1, 'width', $photoSize); - } - - public function testGetWidth() { $photoSize = new PhotoSize(); $photoSize->setWidth(2); @@ -35,13 +23,6 @@ public function testGetWidth() } public function testSetHeight() - { - $photoSize = new PhotoSize(); - $photoSize->setHeight(3); - $this->assertAttributeEquals(3, 'height', $photoSize); - } - - public function testGetHeight() { $photoSize = new PhotoSize(); $photoSize->setHeight(4); @@ -49,13 +30,6 @@ public function testGetHeight() } public function testSetFileSize() - { - $photoSize = new PhotoSize(); - $photoSize->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $photoSize); - } - - public function testGetFileSize() { $photoSize = new PhotoSize(); $photoSize->setFileSize(6); @@ -71,37 +45,34 @@ public function testFromResponse() 'height' => 2, 'file_size' => 3 )); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photoSize); - $this->assertAttributeEquals('testFileId1', 'fileId', $photoSize); - $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $photoSize); - $this->assertAttributeEquals(1, 'width', $photoSize); - $this->assertAttributeEquals(2, 'height', $photoSize); - $this->assertAttributeEquals(3, 'fileSize', $photoSize); + $this->assertInstanceOf(PhotoSize::class, $photoSize); + $this->assertEquals('testFileId1', $photoSize->getFileId()); + $this->assertEquals('testFileUniqueId1', $photoSize->getFileUniqueId()); + $this->assertEquals(1, $photoSize->getWidth()); + $this->assertEquals(2, $photoSize->getHeight()); + $this->assertEquals(3, $photoSize->getFileSize()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetFileSizeException() { + $this->expectException(InvalidArgumentException::class); + $item = new PhotoSize(); $item->setFileSize('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetHeightException() { + $this->expectException(InvalidArgumentException::class); + $item = new PhotoSize(); $item->setHeight('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetWidthException() { + $this->expectException(InvalidArgumentException::class); + $item = new PhotoSize(); $item->setWidth('s'); } diff --git a/tests/PollAnswerTest.php b/tests/PollAnswerTest.php index 754ceb10..601aabc7 100644 --- a/tests/PollAnswerTest.php +++ b/tests/PollAnswerTest.php @@ -4,8 +4,9 @@ use TelegramBot\Api\Types\PollAnswer; use TelegramBot\Api\Types\User; +use PHPUnit\Framework\TestCase; -class PollAnswerAnswerTest extends \PHPUnit_Framework_TestCase +class PollAnswerTest extends TestCase { public function testGetPollId() { @@ -38,7 +39,7 @@ public function testGetOptionIds() $item = new PollAnswer(); $item->setOptionIds([1,2,3,4,5,6]); - $this->assertArraySubset([1,2,3,4,5,6], $item->getOptionIds()); + $this->assertEquals([1,2,3,4,5,6], $item->getOptionIds()); } diff --git a/tests/PollTest.php b/tests/PollTest.php index 3e767511..b8804de3 100644 --- a/tests/PollTest.php +++ b/tests/PollTest.php @@ -4,31 +4,16 @@ use TelegramBot\Api\Types\Poll; use TelegramBot\Api\Types\PollOption; +use PHPUnit\Framework\TestCase; -class PollTest extends \PHPUnit_Framework_TestCase +class PollTest extends TestCase { - public function testGetId() - { - $item = new Poll(); - $item->setId(123456789); - - $this->assertEquals(123456789, $item->getId()); - } - public function testSetId() { $item = new Poll(); $item->setId(123456789); - $this->assertAttributeEquals(123456789, 'id', $item); - } - - public function testGetQuestion() - { - $item = new Poll(); - $item->setQuestion('What is the name of Heisenberg from "Breaking bad"?'); - - $this->assertEquals('What is the name of Heisenberg from "Breaking bad"?', $item->getQuestion()); + $this->assertEquals(123456789, $item->getId()); } public function testSetQuestion() @@ -36,10 +21,10 @@ public function testSetQuestion() $item = new Poll(); $item->setQuestion('What is the name of Heisenberg from "Breaking bad"?'); - $this->assertAttributeEquals('What is the name of Heisenberg from "Breaking bad"?', 'question', $item); + $this->assertEquals('What is the name of Heisenberg from "Breaking bad"?', $item->getQuestion()); } - public function testGetOptions() + public function testSetOptions() { $item = new Poll(); $options = [ @@ -58,43 +43,12 @@ public function testGetOptions() } } - public function testSetOptions() - { - $item = new Poll(); - $options = [ - PollOption::fromResponse([ - 'text' => 'Walter White', - 'voter_count' => 100 - ]), - ]; - - $item->setOptions($options); - - $this->assertAttributeEquals($options, 'options', $item); - } - - public function testGetTotalVoterCount() - { - $item = new Poll(); - $item->setTotalVoterCount(17); - - $this->assertEquals(17, $item->getTotalVoterCount()); - } - public function testSetTotalVoterCount() { $item = new Poll(); $item->setTotalVoterCount(17); - $this->assertAttributeEquals(17, 'totalVoterCount', $item); - } - - public function testIsClosed() - { - $item = new Poll(); - $item->setIsClosed(true); - - $this->assertTrue($item->isClosed()); + $this->assertEquals(17, $item->getTotalVoterCount()); } public function testSetIsClosed() @@ -102,15 +56,7 @@ public function testSetIsClosed() $item = new Poll(); $item->setIsClosed(true); - $this->assertAttributeEquals(true, 'isClosed', $item); - } - - public function testIsAnonymous() - { - $item = new Poll(); - $item->setIsAnonymous(false); - - $this->assertFalse($item->isAnonymous()); + $this->assertTrue($item->isClosed()); } public function testSetIsAnonymous() @@ -118,15 +64,7 @@ public function testSetIsAnonymous() $item = new Poll(); $item->setIsAnonymous(false); - $this->assertAttributeEquals(false, 'isAnonymous', $item); - } - - public function testGetType() - { - $item = new Poll(); - $item->setType('regular'); - - $this->assertEquals('regular', $item->getType()); + $this->assertFalse($item->isAnonymous()); } public function testSetType() @@ -134,15 +72,7 @@ public function testSetType() $item = new Poll(); $item->setType('regular'); - $this->assertAttributeEquals('regular', 'type', $item); - } - - public function testAllowsMultipleAnswers() - { - $item = new Poll(); - $item->setAllowsMultipleAnswers(true); - - $this->assertTrue($item->isAllowsMultipleAnswers()); + $this->assertEquals('regular', $item->getType()); } public function testSetAllowsMultipleAnswers() @@ -150,15 +80,7 @@ public function testSetAllowsMultipleAnswers() $item = new Poll(); $item->setAllowsMultipleAnswers(true); - $this->assertAttributeEquals(true, 'allowsMultipleAnswers', $item); - } - - public function testGetCorrectOptionId() - { - $item = new Poll(); - $item->setCorrectOptionId(2); - - $this->assertEquals(2, $item->getCorrectOptionId()); + $this->assertTrue($item->isAllowsMultipleAnswers()); } public function testSetCorrectOptionId() @@ -166,6 +88,6 @@ public function testSetCorrectOptionId() $item = new Poll(); $item->setCorrectOptionId(2); - $this->assertAttributeEquals(2, 'correctOptionId', $item); + $this->assertEquals(2, $item->getCorrectOptionId()); } -} \ No newline at end of file +} diff --git a/tests/ReplyKeyboardHideTest.php b/tests/ReplyKeyboardHideTest.php index 17bbdfa4..af9b6155 100644 --- a/tests/ReplyKeyboardHideTest.php +++ b/tests/ReplyKeyboardHideTest.php @@ -3,39 +3,40 @@ namespace TelegramBot\Api\Test; use TelegramBot\Api\Types\ReplyKeyboardHide; +use PHPUnit\Framework\TestCase; -class ReplyKeyboardHideTest extends \PHPUnit_Framework_TestCase +class ReplyKeyboardHideTest extends TestCase { public function testConstructor() { $item = new ReplyKeyboardHide(); - $this->assertAttributeEquals(true, 'hideKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(null, $item->isSelective()); } public function testConstructor2() { $item = new ReplyKeyboardHide(true, true); - $this->assertAttributeEquals(true, 'hideKeyboard', $item); - $this->assertAttributeEquals(true, 'selective', $item); + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(true, $item->isSelective()); } public function testConstructor3() { $item = new ReplyKeyboardHide(false, true); - $this->assertAttributeEquals(false, 'hideKeyboard', $item); - $this->assertAttributeEquals(true, 'selective', $item); + $this->assertEquals(false, $item->isHideKeyboard()); + $this->assertEquals(true, $item->isSelective()); } public function testConstructor4() { $item = new ReplyKeyboardHide(true); - $this->assertAttributeEquals(true, 'hideKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(null, $item->isSelective()); } public function testSetHideKeyboard() @@ -44,15 +45,6 @@ public function testSetHideKeyboard() $item->setHideKeyboard(false); - $this->assertAttributeEquals(false, 'hideKeyboard', $item); - } - - public function testIsHideKeyboard() - { - $item = new ReplyKeyboardHide(true); - - $item->setHideKeyboard(false); - $this->assertEquals(false, $item->isHideKeyboard()); } @@ -62,15 +54,6 @@ public function testSetSelective() $item->setSelective(true); - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testIsSelective() - { - $item = new ReplyKeyboardHide(); - - $item->setSelective(true); - $this->assertEquals(true, $item->isSelective()); } diff --git a/tests/ReplyKeyboardMarkupTest.php b/tests/ReplyKeyboardMarkupTest.php index e4361d6d..d0dd1d7a 100644 --- a/tests/ReplyKeyboardMarkupTest.php +++ b/tests/ReplyKeyboardMarkupTest.php @@ -3,47 +3,48 @@ namespace TelegramBot\Api\Test; use TelegramBot\Api\Types\ReplyKeyboardMarkup; +use PHPUnit\Framework\TestCase; -class ReplyKeyboardMarkupTest extends \PHPUnit_Framework_TestCase +class ReplyKeyboardMarkupTest extends TestCase { public function testConstructor() { $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $this->assertAttributeEquals(array(array('one', 'two')), 'keyboard', $item); - $this->assertAttributeEquals(null, 'oneTimeKeyboard', $item); - $this->assertAttributeEquals(null, 'resizeKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); + $this->assertEquals(array(array('one', 'two')), $item->getKeyboard()); + $this->assertEquals(null, $item->isOneTimeKeyboard()); + $this->assertEquals(null, $item->isResizeKeyboard()); + $this->assertEquals(null, $item->isSelective()); } public function testConstructor2() { $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true); - $this->assertAttributeEquals(array(array('one', 'two')), 'keyboard', $item); - $this->assertAttributeEquals(true, 'oneTimeKeyboard', $item); - $this->assertAttributeEquals(null, 'resizeKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); + $this->assertEquals(array(array('one', 'two')), $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(null, $item->isResizeKeyboard()); + $this->assertEquals(null, $item->isSelective()); } public function testConstructor3() { $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true); - $this->assertAttributeEquals(array(array('one', 'two')), 'keyboard', $item); - $this->assertAttributeEquals(true, 'oneTimeKeyboard', $item); - $this->assertAttributeEquals(true, 'resizeKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); + $this->assertEquals(array(array('one', 'two')), $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(null, $item->isSelective()); } public function testConstructor4() { $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true, true); - $this->assertAttributeEquals(array(array('one', 'two')), 'keyboard', $item); - $this->assertAttributeEquals(true, 'oneTimeKeyboard', $item); - $this->assertAttributeEquals(true, 'resizeKeyboard', $item); - $this->assertAttributeEquals(true, 'selective', $item); + $this->assertEquals(array(array('one', 'two')), $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(true, $item->isSelective()); } public function testSetKeyboard() @@ -51,14 +52,6 @@ public function testSetKeyboard() $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); $item->setKeyboard(array(array('one', 'two', 'three'))); - $this->assertAttributeEquals(array(array('one', 'two', 'three')), 'keyboard', $item); - } - - public function testGetKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setKeyboard(array(array('one', 'two', 'three'))); - $this->assertEquals(array(array('one', 'two', 'three')), $item->getKeyboard()); } @@ -67,14 +60,6 @@ public function testSetSelective() $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); $item->setSelective(true); - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testIsSelective() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setSelective(true); - $this->assertEquals(true, $item->isSelective()); } @@ -83,14 +68,6 @@ public function testSetOneTimeKeyboard() $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); $item->setOneTimeKeyboard(false); - $this->assertAttributeEquals(false, 'oneTimeKeyboard', $item); - } - - public function testIsOneTimeKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setOneTimeKeyboard(false); - $this->assertEquals(false, $item->isOneTimeKeyboard()); } @@ -99,14 +76,6 @@ public function testSetResizeKeyboard() $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); $item->setResizeKeyboard(true); - $this->assertAttributeEquals(true, 'resizeKeyboard', $item); - } - - public function testIsResizeKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setResizeKeyboard(true); - $this->assertEquals(true, $item->isResizeKeyboard()); } diff --git a/tests/StickerTest.php b/tests/StickerTest.php index 95c35b5f..961af1ab 100644 --- a/tests/StickerTest.php +++ b/tests/StickerTest.php @@ -2,18 +2,14 @@ namespace TelegramBot\Api\Test; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\PhotoSize; use TelegramBot\Api\Types\Sticker; +use PHPUnit\Framework\TestCase; -class StickerTest extends \PHPUnit_Framework_TestCase { +class StickerTest extends TestCase +{ public function testSetFileId() - { - $sticker = new Sticker(); - $sticker->setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $sticker); - } - - public function testGetFileId() { $sticker = new Sticker(); $sticker->setFileId('testfileId'); @@ -21,13 +17,6 @@ public function testGetFileId() } public function testSetWidth() - { - $sticker = new Sticker(); - $sticker->setWidth(1); - $this->assertAttributeEquals(1, 'width', $sticker); - } - - public function testGetWidth() { $sticker = new Sticker(); $sticker->setWidth(2); @@ -35,13 +24,6 @@ public function testGetWidth() } public function testSetHeight() - { - $sticker = new Sticker(); - $sticker->setHeight(3); - $this->assertAttributeEquals(3, 'height', $sticker); - } - - public function testGetHeight() { $sticker = new Sticker(); $sticker->setHeight(4); @@ -49,13 +31,6 @@ public function testGetHeight() } public function testSetFileSize() - { - $sticker = new Sticker(); - $sticker->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $sticker); - } - - public function testGetFileSize() { $sticker = new Sticker(); $sticker->setFileSize(6); @@ -63,20 +38,6 @@ public function testGetFileSize() } public function testSetThumb() - { - $sticker = new Sticker(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $sticker->setThumb($thumb); - $this->assertAttributeEquals($thumb, 'thumb', $sticker); - } - - public function testGetThumb() { $sticker = new Sticker(); $thumb = PhotoSize::fromResponse(array( @@ -88,7 +49,7 @@ public function testGetThumb() )); $sticker->setThumb($thumb); $this->assertEquals($thumb, $sticker->getThumb()); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $sticker->getThumb()); + $this->assertInstanceOf(PhotoSize::class, $sticker->getThumb()); } public function testFromResponse() @@ -117,38 +78,35 @@ public function testFromResponse() 'height' => 2, 'file_size' => 3 )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Sticker', $sticker); - $this->assertAttributeEquals('testFileId1', 'fileId', $sticker); - $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $sticker); - $this->assertAttributeEquals(1, 'width', $sticker); - $this->assertAttributeEquals(2, 'height', $sticker); - $this->assertAttributeEquals(3, 'fileSize', $sticker); - $this->assertAttributeEquals($thumb, 'thumb', $sticker); + $this->assertInstanceOf(Sticker::class, $sticker); + $this->assertEquals('testFileId1', $sticker->getFileId()); + $this->assertEquals('testFileUniqueId1', $sticker->getFileUniqueId()); + $this->assertEquals(1, $sticker->getWidth()); + $this->assertEquals(2, $sticker->getHeight()); + $this->assertEquals(3, $sticker->getFileSize()); + $this->assertEquals($thumb, $sticker->getThumb()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetFileSizeException() { + $this->expectException(InvalidArgumentException::class); + $item = new Sticker(); $item->setFileSize('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetHeightException() { + $this->expectException(InvalidArgumentException::class); + $item = new Sticker(); $item->setHeight('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetWidthException() { + $this->expectException(InvalidArgumentException::class); + $item = new Sticker(); $item->setWidth('s'); } diff --git a/tests/Types/ArrayOfUpdatesTest.php b/tests/Types/ArrayOfUpdatesTest.php index 1f3d1485..3ae5aeed 100644 --- a/tests/Types/ArrayOfUpdatesTest.php +++ b/tests/Types/ArrayOfUpdatesTest.php @@ -2,9 +2,10 @@ namespace TelegramBot\Api\Test\Types; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\ArrayOfUpdates; -class ArrayOfUpdatesTest extends \PHPUnit_Framework_TestCase +class ArrayOfUpdatesTest extends TestCase { public function data() @@ -47,7 +48,7 @@ public function testFromResponse($data) { $items = ArrayOfUpdates::fromResponse($data); - $this->assertInternalType('array', $items); + $this->assertIsArray($items); foreach($items as $item) { $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $item); diff --git a/tests/Types/CallbackQueryTest.php b/tests/Types/CallbackQueryTest.php index 2e82b5b2..5403fa57 100644 --- a/tests/Types/CallbackQueryTest.php +++ b/tests/Types/CallbackQueryTest.php @@ -2,11 +2,13 @@ namespace TelegramBot\Api\Test\Types; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\CallbackQuery; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\User; -class CallbackQueryTest extends \PHPUnit_Framework_TestCase +class CallbackQueryTest extends TestCase { protected $callbackQueryFixture = [ 'id' => 1, @@ -37,98 +39,55 @@ public function testFromResponse() $this->assertEquals($this->callbackQueryFixture['game_short_name'], $item->getGameShortName()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseExceptionEmptyId() { + public function testFromResponseExceptionEmptyId() + { + $this->expectException(InvalidArgumentException::class); + unset($this->callbackQueryFixture['id']); CallbackQuery::fromResponse($this->callbackQueryFixture); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseExceptionEmptyFrom() { + public function testFromResponseExceptionEmptyFrom() + { + $this->expectException(InvalidArgumentException::class); + unset($this->callbackQueryFixture['from']); CallbackQuery::fromResponse($this->callbackQueryFixture); } public function testSetId() - { - $item = new CallbackQuery(); - $item->setId($this->callbackQueryFixture['id']); - $this->assertAttributeEquals($this->callbackQueryFixture['id'], 'id', $item); - } - - public function testGetId() { $item = new CallbackQuery(); $item->setId($this->callbackQueryFixture['id']); $this->assertEquals($this->callbackQueryFixture['id'], $item->getId()); } - public function testSetFrom() - { - $item = new CallbackQuery(); - $user = User::fromResponse($this->callbackQueryFixture['from']); - $item->setFrom($user); - $this->assertAttributeEquals($user, 'from', $item); - } - - public function testGetFrom() { + public function testSetFrom() { $item = new CallbackQuery(); $user = User::fromResponse($this->callbackQueryFixture['from']); $item->setFrom($user); $this->assertEquals($user, $item->getFrom()); } - public function testSetInlineMessageId() - { - $item = new CallbackQuery(); - $item->setInlineMessageId($this->callbackQueryFixture['inline_message_id']); - $this->assertAttributeEquals($this->callbackQueryFixture['inline_message_id'], 'inlineMessageId', $item); - } - - public function testGetInlineMessageId() { + public function testSetInlineMessageId() { $item = new CallbackQuery(); $item->setInlineMessageId('testInlineMessageId'); $this->assertEquals('testInlineMessageId', $item->getInlineMessageId()); } - public function testSetChatInstance() - { - $item = new CallbackQuery(); - $item->setChatInstance($this->callbackQueryFixture['chat_instance']); - $this->assertAttributeEquals($this->callbackQueryFixture['chat_instance'], 'chatInstance', $item); - } - - public function testGetChatInstance() { + public function testSetChatInstance() { $item = new CallbackQuery(); $item->setChatInstance('testChatInstance'); $this->assertEquals('testChatInstance', $item->getChatInstance()); } - public function testSetData() - { - $item = new CallbackQuery(); - $item->setData($this->callbackQueryFixture['data']); - $this->assertAttributeEquals($this->callbackQueryFixture['data'], 'data', $item); - } - - public function testGetData() { + public function testSetData() { $item = new CallbackQuery(); $item->setData('testData'); $this->assertEquals('testData', $item->getData()); } - public function testSetGameShortName() - { - $item = new CallbackQuery(); - $item->setGameShortName($this->callbackQueryFixture['game_short_name']); - $this->assertAttributeEquals($this->callbackQueryFixture['game_short_name'], 'gameShortName', $item); - } - - public function testGetGameShortName() { + public function testSetGameShortName() { $item = new CallbackQuery(); $item->setGameShortName('testGameShortName'); $this->assertEquals('testGameShortName', $item->getGameShortName()); diff --git a/tests/Types/Events/EventCollectionTest.php b/tests/Types/Events/EventCollectionTest.php index 0c8640be..f7475999 100644 --- a/tests/Types/Events/EventCollectionTest.php +++ b/tests/Types/Events/EventCollectionTest.php @@ -2,11 +2,12 @@ namespace TelegramBot\Api\Test\Types\Events; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Client; use TelegramBot\Api\Events\EventCollection; use TelegramBot\Api\Types\Update; -class EventCollectionTest extends \PHPUnit_Framework_TestCase +class EventCollectionTest extends TestCase { public function data() { @@ -43,22 +44,6 @@ function ($update) { ]; } - public function testConstructor1() - { - $item = new EventCollection(); - - $this->assertAttributeEmpty('tracker', $item); - $this->assertAttributeEmpty('events', $item); - } - - public function testConstructor2() - { - $item = new EventCollection('testToken'); - - $this->assertAttributeInstanceOf('\TelegramBot\Api\Botan', 'tracker', $item); - $this->assertAttributeEmpty('events', $item); - } - /** * @param \Closure $action * @param \Closure $checker @@ -76,7 +61,7 @@ public function testAdd1($action, $checker) $innerItem = $reflectionProperty->getValue($item); $reflectionProperty->setAccessible(false); - $this->assertAttributeInternalType('array', 'events', $item); + $this->assertIsArray($innerItem); /* @var \TelegramBot\Api\Events\Event $event */ foreach($innerItem as $event) { $this->assertInstanceOf('\TelegramBot\Api\Events\Event', $event); @@ -99,7 +84,7 @@ public function testAdd2($action) $innerItem = $reflectionProperty->getValue($item); $reflectionProperty->setAccessible(false); - $this->assertAttributeInternalType('array', 'events', $item); + $this->assertIsArray($innerItem); /* @var \TelegramBot\Api\Events\Event $event */ foreach($innerItem as $event) { $this->assertInstanceOf('\TelegramBot\Api\Events\Event', $event); diff --git a/tests/Types/Events/EventTest.php b/tests/Types/Events/EventTest.php index eb45ed40..66d431e4 100644 --- a/tests/Types/Events/EventTest.php +++ b/tests/Types/Events/EventTest.php @@ -2,10 +2,11 @@ namespace TelegramBot\Api\Test\Types\Events; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Events\Event; use TelegramBot\Api\Types\Update; -class EventTest extends \PHPUnit_Framework_TestCase +class EventTest extends TestCase { public function data() { @@ -67,7 +68,6 @@ public function testGetAction($action, $checker, $update) { $item = new Event($action, $checker); - $this->assertAttributeInstanceOf('\Closure', 'action', $item); $this->assertEquals($action, $item->getAction()); } @@ -82,7 +82,6 @@ public function testGetChecker($action, $checker, $update) { $item = new Event($action, $checker); - $this->assertAttributeInstanceOf('\Closure', 'checker', $item); $this->assertEquals($checker, $item->getChecker()); } @@ -99,7 +98,7 @@ public function testExecuteAction($action, $checker, $update) $result = $item->executeAction($update); - $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $result); + $this->assertInstanceOf(Update::class, $result); $this->assertEquals($update, $result); } @@ -135,7 +134,7 @@ public function testExecuteCheker($action, $checker, $update) $result = $item->executeChecker($update); - $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $result); + $this->assertInstanceOf(Update::class, $result); $this->assertEquals($update, $result); } diff --git a/tests/Types/Inline/ChosenInlineResultTest.php b/tests/Types/Inline/ChosenInlineResultTest.php index 180e71cb..21381b47 100644 --- a/tests/Types/Inline/ChosenInlineResultTest.php +++ b/tests/Types/Inline/ChosenInlineResultTest.php @@ -2,10 +2,12 @@ namespace TelegramBot\Api\Test\Types\Inline; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\Inline\ChosenInlineResult; use TelegramBot\Api\Types\User; -class ChosenInlineResultTest extends \PHPUnit_Framework_TestCase +class ChosenInlineResultTest extends TestCase { protected $chosenInlineResultFixture = [ 'result_id' => 1, @@ -30,65 +32,47 @@ public function testFromResponse() $this->assertEquals($this->chosenInlineResultFixture['query'], $item->getQuery()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException1() { + public function testFromResponseException1() + { + $this->expectException(InvalidArgumentException::class); + unset($this->chosenInlineResultFixture['result_id']); ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() { + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + unset($this->chosenInlineResultFixture['from']); ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException3() { + public function testFromResponseException3() + { + $this->expectException(InvalidArgumentException::class); + unset($this->chosenInlineResultFixture['query']); ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); } public function testSetResultId() - { - $item = new ChosenInlineResult(); - $item->setResultId($this->chosenInlineResultFixture['result_id']); - $this->assertAttributeEquals($this->chosenInlineResultFixture['result_id'], 'resultId', $item); - } - - public function testGetResultId() { $item = new ChosenInlineResult(); $item->setResultId($this->chosenInlineResultFixture['result_id']); $this->assertEquals($this->chosenInlineResultFixture['result_id'], $item->getResultId()); } - public function testSetFrom() { - $item = new ChosenInlineResult(); - $user = User::fromResponse($this->chosenInlineResultFixture['from']); - $item->setFrom($user); - $this->assertAttributeEquals($user, 'from', $item); - } - - public function testGetFrom() { + public function testSetFrom() + { $item = new ChosenInlineResult(); $user = User::fromResponse($this->chosenInlineResultFixture['from']); $item->setFrom($user); $this->assertEquals($user, $item->getFrom()); } - public function testSetQuery() { - $item = new ChosenInlineResult(); - $item->setQuery('testQuery'); - $this->assertAttributeEquals('testQuery', 'query', $item); - } - - public function testGetQuery() { + public function testSetQuery() + { $item = new ChosenInlineResult(); $item->setQuery('testQuery'); $this->assertEquals('testQuery', $item->getQuery()); diff --git a/tests/Types/Inline/InlineKeyboardMarkupTest.php b/tests/Types/Inline/InlineKeyboardMarkupTest.php index 0eb05a09..4e10af3c 100644 --- a/tests/Types/Inline/InlineKeyboardMarkupTest.php +++ b/tests/Types/Inline/InlineKeyboardMarkupTest.php @@ -2,16 +2,17 @@ namespace TelegramBot\Api\Test\Types\Inline; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; -class InlineKeyboardMarkupTest extends \PHPUnit_Framework_TestCase +class InlineKeyboardMarkupTest extends TestCase { public function testConstructor() { $item = new InlineKeyboardMarkup([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]]); - $this->assertAttributeEquals([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]], 'inlineKeyboard', $item); + $this->assertEquals([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]], $item->getInlineKeyboard()); } public function testSetInlineKeyboard() @@ -19,14 +20,6 @@ public function testSetInlineKeyboard() $item = new InlineKeyboardMarkup([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]]); $item->setInlineKeyboard([[['url' => 'http://test.com', 'text' => 'Link']]]); - $this->assertAttributeEquals([[['url' => 'http://test.com', 'text' => 'Link']]], 'inlineKeyboard', $item); - } - - public function testGetInlineKeyboard() - { - $item = new InlineKeyboardMarkup([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]]); - $item->setInlineKeyboard([[['url' => 'http://test.com', 'text' => 'Link']]]); - $this->assertEquals([[['url' => 'http://test.com', 'text' => 'Link']]], $item->getInlineKeyboard()); } } diff --git a/tests/Types/Inline/InlineQueryTest.php b/tests/Types/Inline/InlineQueryTest.php index fa1d5f7e..ecef4ac1 100644 --- a/tests/Types/Inline/InlineQueryTest.php +++ b/tests/Types/Inline/InlineQueryTest.php @@ -2,10 +2,12 @@ namespace TelegramBot\Api\Test\Types\Inline; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\Inline\InlineQuery; use TelegramBot\Api\Types\User; -class InlineQueryTest extends \PHPUnit_Framework_TestCase +class InlineQueryTest extends TestCase { protected $inlineQueryFixture = [ 'id' => 1, @@ -44,85 +46,62 @@ public function testFromResponse2() { $this->assertEquals('', $item->getOffset()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException1() { + public function testFromResponseException1() + { + $this->expectException(InvalidArgumentException::class); + unset($this->inlineQueryFixture['id']); InlineQuery::fromResponse($this->inlineQueryFixture); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() { + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + unset($this->inlineQueryFixture['from']); InlineQuery::fromResponse($this->inlineQueryFixture); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException3() { + public function testFromResponseException3() + { + $this->expectException(InvalidArgumentException::class); + unset($this->inlineQueryFixture['query']); InlineQuery::fromResponse($this->inlineQueryFixture); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException4() { + public function testFromResponseException4() + { + $this->expectException(InvalidArgumentException::class); + unset($this->inlineQueryFixture['offset']); InlineQuery::fromResponse($this->inlineQueryFixture); } public function testSetId() - { - $item = new InlineQuery(); - $item->setId('testId'); - $this->assertAttributeEquals('testId', 'id', $item); - } - - public function testGetId() { $item = new InlineQuery(); $item->setId('testId'); $this->assertEquals('testId', $item->getId()); } - public function testSetFrom() { - $item = new InlineQuery(); - $user = User::fromResponse($this->inlineQueryFixture['from']); - $item->setFrom($user); - $this->assertAttributeEquals($user, 'from', $item); - } - - public function testGetFrom() { + public function testSetFrom() + { $item = new InlineQuery(); $user = User::fromResponse($this->inlineQueryFixture['from']); $item->setFrom($user); $this->assertEquals($user, $item->getFrom()); } - public function testSetQuery() { - $item = new InlineQuery(); - $item->setQuery('testQuery'); - $this->assertAttributeEquals('testQuery', 'query', $item); - } - - public function testGetQuery() { + public function testSetQuery() + { $item = new InlineQuery(); $item->setQuery('testQuery'); $this->assertEquals('testQuery', $item->getQuery()); } - public function testSetOffset() { - $item = new InlineQuery(); - $item->setOffset('20'); - $this->assertAttributeEquals('20', 'offset', $item); - } - - public function testGetOffset() { + public function testSetOffset() + { $item = new InlineQuery(); $item->setOffset('20'); $this->assertEquals('20', $item->getOffset()); diff --git a/tests/Types/MessageEntityTest.php b/tests/Types/MessageEntityTest.php index acfd462e..2a7f6470 100644 --- a/tests/Types/MessageEntityTest.php +++ b/tests/Types/MessageEntityTest.php @@ -2,10 +2,11 @@ namespace TelegramBot\Api\Test\Types; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\MessageEntity; use TelegramBot\Api\Types\User; -class MessageEntityTest extends \PHPUnit_Framework_TestCase +class MessageEntityTest extends TestCase { public function testTextMentionFromResponse() { diff --git a/tests/UserProfilePhotosTest.php b/tests/UserProfilePhotosTest.php index cb9d889e..af657919 100644 --- a/tests/UserProfilePhotosTest.php +++ b/tests/UserProfilePhotosTest.php @@ -3,19 +3,14 @@ namespace TelegramBot\Api\Test; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\PhotoSize; use TelegramBot\Api\Types\UserProfilePhotos; +use PHPUnit\Framework\TestCase; -class UserProfilePhotosTest extends \PHPUnit_Framework_TestCase +class UserProfilePhotosTest extends TestCase { public function testSetTotalCount() - { - $userProfilePhotos = new UserProfilePhotos(); - $userProfilePhotos->setTotalCount(1); - $this->assertAttributeEquals(1, 'totalCount', $userProfilePhotos); - } - - public function testGetTotalCount() { $userProfilePhotos = new UserProfilePhotos(); $userProfilePhotos->setTotalCount(1); @@ -23,26 +18,6 @@ public function testGetTotalCount() } public function testSetPhotos() - { - $userProfilePhotos = new UserProfilePhotos(); - $photos = array(); - for ($i = 0; $i < 10; $i++) { - $photos[] = array( - PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => $i, - 'height' => $i * 2, - 'file_size' => $i * 3 - )) - ); - } - - $userProfilePhotos->setPhotos($photos); - $this->assertAttributeEquals($photos, 'photos', $userProfilePhotos); - } - - public function testGetPhotos() { $userProfilePhotos = new UserProfilePhotos(); $photos = array(); @@ -87,21 +62,21 @@ public function testFromResponse() )) ) ); - $this->assertInstanceOf('\TelegramBot\Api\Types\UserProfilePhotos', $userProfilePhotos); - $this->assertAttributeEquals(1, 'totalCount', $userProfilePhotos); - $this->assertAttributeEquals($photos, 'photos', $userProfilePhotos); + $this->assertInstanceOf(UserProfilePhotos::class, $userProfilePhotos); + $this->assertEquals(1, $userProfilePhotos->getTotalCount()); + $this->assertEquals($photos, $userProfilePhotos->getPhotos()); + foreach ($userProfilePhotos->getPhotos() as $photoArray) { foreach($photoArray as $photo) { - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photo); + $this->assertInstanceOf(PhotoSize::class, $photo); } } } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetTotalCountException() { + $this->expectException(InvalidArgumentException::class); + $item = new UserProfilePhotos(); $item->setTotalCount('s'); } diff --git a/tests/UserTest.php b/tests/UserTest.php index f7ec177f..e9f2a77c 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -2,39 +2,27 @@ namespace TelegramBot\Api\Test; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\User; +use PHPUnit\Framework\TestCase; -class UserTest extends \PHPUnit_Framework_TestCase +class UserTest extends TestCase { public function testSetDuration() { $item = new User(); $item->setId(1); - $this->assertAttributeEquals(1, 'id', $item); + $this->assertEquals(1, $item->getId()); } public function testSet64bitId() { $item = new User(); $item->setId(2147483648); - $this->assertAttributeEquals(2147483648, 'id', $item); - } - - public function testGetDuration() - { - $item = new User(); - $item->setId(1); - $this->assertEquals(1, $item->getId()); + $this->assertEquals(2147483648, $item->getId()); } public function testSetFirstName() - { - $item = new User(); - $item->setFirstName('Ilya'); - $this->assertAttributeEquals('Ilya', 'firstName', $item); - } - - public function testGetFirstName() { $item = new User(); $item->setFirstName('Ilya'); @@ -42,13 +30,6 @@ public function testGetFirstName() } public function testSetLastName() - { - $item = new User(); - $item->setLastName('Gusev'); - $this->assertAttributeEquals('Gusev', 'lastName', $item); - } - - public function testGetLastName() { $item = new User(); $item->setLastName('Gusev'); @@ -56,24 +37,16 @@ public function testGetLastName() } public function testSetUsername() - { - $item = new User(); - $item->setUsername('iGusev'); - $this->assertAttributeEquals('iGusev', 'username', $item); - } - - public function testGetUsername() { $item = new User(); $item->setUsername('iGusev'); $this->assertEquals('iGusev', $item->getUsername()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetIdException() { + $this->expectException(InvalidArgumentException::class); + $item = new User(); $item->setId('s'); } @@ -105,22 +78,21 @@ public function testFromResponse() $this->assertEquals(false, $user->getSupportsInlineQueries()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testFromResponseException1() { + $this->expectException(InvalidArgumentException::class); + $user = User::fromResponse(array( 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' )); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ + public function testFromResponseException2() { + $this->expectException(InvalidArgumentException::class); + $user = User::fromResponse(array( 'first_name' => 'Ilya', 'last_name' => 'Gusev', diff --git a/tests/VideoTest.php b/tests/VideoTest.php index a9ee1a0b..acbc2852 100644 --- a/tests/VideoTest.php +++ b/tests/VideoTest.php @@ -2,19 +2,14 @@ namespace TelegramBot\Api\Test; +use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\PhotoSize; use TelegramBot\Api\Types\Video; +use PHPUnit\Framework\TestCase; -class VideoTest extends \PHPUnit_Framework_TestCase +class VideoTest extends TestCase { public function testSetFileId() - { - $item = new Video(); - $item->setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() { $item = new Video(); $item->setFileId('testfileId'); @@ -22,13 +17,6 @@ public function testGetFileId() } public function testSetDuration() - { - $item = new Video(); - $item->setDuration(1); - $this->assertAttributeEquals(1, 'duration', $item); - } - - public function testGetDuration() { $item = new Video(); $item->setDuration(1); @@ -36,13 +24,6 @@ public function testGetDuration() } public function testSetFileSize() - { - $item = new Video(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() { $item = new Video(); $item->setFileSize(6); @@ -50,13 +31,6 @@ public function testGetFileSize() } public function testSetMimeType() - { - $item = new Video(); - $item->setMimeType('video/mp4'); - $this->assertAttributeEquals('video/mp4', 'mimeType', $item); - } - - public function testGetMimeType() { $item = new Video(); $item->setMimeType('video/mp4'); @@ -64,20 +38,6 @@ public function testGetMimeType() } public function testSetThumb() - { - $item = new Video(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $item->setThumb($thumb); - $this->assertAttributeEquals($thumb, 'thumb', $item); - } - - public function testGetThumb() { $item = new Video(); $thumb = PhotoSize::fromResponse(array( @@ -89,17 +49,10 @@ public function testGetThumb() )); $item->setThumb($thumb); $this->assertEquals($thumb, $item->getThumb()); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); + $this->assertInstanceOf(PhotoSize::class, $item->getThumb()); } public function testSetWidth() - { - $item = new Video(); - $item->setWidth(1); - $this->assertAttributeEquals(1, 'width', $item); - } - - public function testGetWidth() { $item = new Video(); $item->setWidth(2); @@ -107,13 +60,6 @@ public function testGetWidth() } public function testSetHeight() - { - $item = new Video(); - $item->setHeight(3); - $this->assertAttributeEquals(3, 'height', $item); - } - - public function testGetHeight() { $item = new Video(); $item->setHeight(4); @@ -145,59 +91,57 @@ public function testFromResponse() 'height' => 6, 'file_size' => 7 )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Video', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item); - $this->assertAttributeEquals(1, 'width', $item); - $this->assertAttributeEquals(2, 'height', $item); - $this->assertAttributeEquals(3, 'duration', $item); - $this->assertAttributeEquals('video/mp4', 'mimeType', $item); - $this->assertAttributeEquals(4, 'fileSize', $item); - $this->assertAttributeEquals($thumb, 'thumb', $item); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); + $this->assertInstanceOf(Video::class, $item); + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(3, $item->getDuration()); + $this->assertEquals('video/mp4', $item->getMimeType()); + $this->assertEquals(4, $item->getFileSize()); + $this->assertEquals($thumb, $item->getThumb()); + $this->assertInstanceOf(PhotoSize::class, $item->getThumb()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetHeightException() { + $this->expectException(InvalidArgumentException::class); + $item = new Video(); $item->setHeight('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetWidthException() { + $this->expectException(InvalidArgumentException::class); + $item = new Video(); $item->setWidth('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ public function testSetDurationException() { + $this->expectException(InvalidArgumentException::class); + $item = new Video(); $item->setDuration('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ + public function testSetFileSizeException() { + $this->expectException(InvalidArgumentException::class); + $item = new Video(); $item->setFileSize('s'); } /** * file_id is required - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException1() { + $this->expectException(InvalidArgumentException::class); + $item = Video::fromResponse(array( 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, @@ -215,10 +159,11 @@ public function testFromResponseException1() } /** * width is required - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException2() { + $this->expectException(InvalidArgumentException::class); + $item = Video::fromResponse(array( 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', @@ -238,10 +183,11 @@ public function testFromResponseException2() /** * height is required - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException3() { + $this->expectException(InvalidArgumentException::class); + $item = Video::fromResponse(array( 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', @@ -261,10 +207,11 @@ public function testFromResponseException3() /** * duration is required - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException4() { + $this->expectException(InvalidArgumentException::class); + $item = Video::fromResponse(array( 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', @@ -284,10 +231,11 @@ public function testFromResponseException4() /** * file_unique_id is required - * @expectedException \TelegramBot\Api\InvalidArgumentException */ public function testFromResponseException5() { + $this->expectException(InvalidArgumentException::class); + $item = Video::fromResponse(array( 'file_id' => 'testFileId1', 'width' => 1, diff --git a/tests/VoiceTest.php b/tests/VoiceTest.php index 654227a0..ba8e8ea9 100644 --- a/tests/VoiceTest.php +++ b/tests/VoiceTest.php @@ -1,18 +1,13 @@ setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() { $item = new Voice(); $item->setFileId('testfileId'); @@ -20,13 +15,6 @@ public function testGetFileId() } public function testSetUniqueFileId() - { - $item = new Voice(); - $item->setFileUniqueId('fileUniqueId'); - $this->assertAttributeEquals('fileUniqueId', 'fileUniqueId', $item); - } - - public function testGetUniqueFileId() { $item = new Voice(); $item->setFileUniqueId('fileUniqueId'); @@ -34,13 +22,6 @@ public function testGetUniqueFileId() } public function testSetDuration() - { - $item = new Voice(); - $item->setDuration(1); - $this->assertAttributeEquals(1, 'duration', $item); - } - - public function testGetDuration() { $item = new Voice(); $item->setDuration(1); @@ -48,13 +29,6 @@ public function testGetDuration() } public function testSetFileSize() - { - $item = new Voice(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() { $item = new Voice(); $item->setFileSize(6); @@ -62,13 +36,6 @@ public function testGetFileSize() } public function testSetMimeType() - { - $item = new Voice(); - $item->setMimeType('audio/mp3'); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - } - - public function testGetMimeType() { $item = new Voice(); $item->setMimeType('audio/mp3'); @@ -84,30 +51,30 @@ public function testFromResponse() 'mime_type' => 'audio/mp3', 'file_size' => 3 )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Voice', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item); - $this->assertAttributeEquals(1, 'duration', $item); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - $this->assertAttributeEquals(3, 'fileSize', $item); + $this->assertInstanceOf(Voice::class, $item); + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getDuration()); + $this->assertEquals('audio/mp3', $item->getMimeType()); + $this->assertEquals(3, $item->getFileSize()); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ + public function testFromResponseException() { + $this->expectException(InvalidArgumentException::class); + $item = Voice::fromResponse(array( 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 )); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ + public function testFromResponseException2() { + $this->expectException(InvalidArgumentException::class); + $item = Voice::fromResponse(array( 'file_id' => 'testFileId1', 'mime_type' => 'audio/mp3', @@ -115,19 +82,19 @@ public function testFromResponseException2() )); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ + public function testSetDurationException() { + $this->expectException(InvalidArgumentException::class); + $item = new Voice(); $item->setDuration('s'); } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ + public function testSetFileSizeException() { + $this->expectException(InvalidArgumentException::class); + $item = new Voice(); $item->setFileSize('s'); } diff --git a/tests/WebhookInfoTest.php b/tests/WebhookInfoTest.php index ad120fae..9eca6fd8 100644 --- a/tests/WebhookInfoTest.php +++ b/tests/WebhookInfoTest.php @@ -8,8 +8,9 @@ namespace TelegramBot\Api\Test; use TelegramBot\Api\Types\WebhookInfo; +use PHPUnit\Framework\TestCase; -class WebhookInfoTest extends \PHPUnit_Framework_TestCase +class WebhookInfoTest extends TestCase { public function testFromResponse() { diff --git a/tests/_fixtures/TestBaseType.php b/tests/_fixtures/TestBaseType.php deleted file mode 100644 index 4ad2b6af..00000000 --- a/tests/_fixtures/TestBaseType.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Sat, 22 Apr 2023 12:46:33 +0300 Subject: [PATCH 089/130] Apply PHP CS Fixer --- .gitattributes | 13 +- .github/workflows/cs.yaml | 51 +++++ .github/workflows/tests.yaml | 6 +- .gitignore | 1 + .php-cs-fixer.dist.php | 27 +++ .scrutinizer.yml | 22 ++ composer.json | 7 +- src/BadMethodCallException.php | 1 - src/BaseType.php | 4 +- src/BotApi.php | 11 +- src/Botan.php | 2 - src/Collection/KeyHasUseException.php | 1 - src/Collection/KeyInvalidException.php | 1 - src/Collection/ReachedMaxSizeException.php | 1 - src/Events/Event.php | 1 - src/Events/EventCollection.php | 1 - src/Exception.php | 1 - src/InvalidArgumentException.php | 1 - src/InvalidJsonException.php | 1 - src/Types/Animation.php | 4 +- src/Types/Audio.php | 4 +- src/Types/BotCommand.php | 4 +- src/Types/CallbackQuery.php | 5 +- src/Types/Chat.php | 4 +- src/Types/ChatLocation.php | 4 +- src/Types/ChatMember.php | 4 +- src/Types/ChatPermissions.php | 4 +- src/Types/ChatPhoto.php | 4 +- src/Types/Contact.php | 4 +- src/Types/Dice.php | 4 +- src/Types/Document.php | 4 +- src/Types/File.php | 4 +- src/Types/ForceReply.php | 4 +- src/Types/Inline/ChosenInlineResult.php | 4 +- src/Types/Inline/InlineKeyboardMarkup.php | 4 +- src/Types/Inline/InlineQuery.php | 5 +- src/Types/Inline/InputMessageContent.php | 1 - .../Inline/InputMessageContent/Contact.php | 6 +- .../Inline/InputMessageContent/Location.php | 5 +- src/Types/Inline/InputMessageContent/Text.php | 5 +- .../Inline/InputMessageContent/Venue.php | 5 +- src/Types/Inline/QueryResult/Article.php | 5 +- src/Types/Inline/QueryResult/Audio.php | 4 +- src/Types/Inline/QueryResult/Contact.php | 5 +- src/Types/Inline/QueryResult/Gif.php | 4 +- src/Types/Inline/QueryResult/Location.php | 4 +- src/Types/Inline/QueryResult/Mpeg4Gif.php | 5 +- src/Types/Inline/QueryResult/Photo.php | 5 +- src/Types/Inline/QueryResult/Venue.php | 4 +- src/Types/Inline/QueryResult/Video.php | 8 +- src/Types/Inline/QueryResult/Voice.php | 5 +- src/Types/InputMedia/InputMedia.php | 4 +- src/Types/InputMedia/InputMediaVideo.php | 2 +- src/Types/Location.php | 4 +- src/Types/LoginUrl.php | 4 +- src/Types/Message.php | 6 +- src/Types/MessageEntity.php | 5 +- src/Types/Payments/Invoice.php | 4 +- src/Types/Payments/LabeledPrice.php | 4 +- src/Types/Payments/OrderInfo.php | 4 +- .../Payments/Query/AnswerPreCheckoutQuery.php | 5 +- .../Payments/Query/AnswerShippingQuery.php | 4 +- src/Types/Payments/Query/PreCheckoutQuery.php | 6 +- src/Types/Payments/Query/ShippingQuery.php | 5 +- src/Types/Payments/ShippingAddress.php | 4 +- src/Types/Payments/ShippingOption.php | 4 +- src/Types/Payments/SuccessfulPayment.php | 4 +- src/Types/PhotoSize.php | 4 +- src/Types/Poll.php | 1 - src/Types/PollAnswer.php | 4 +- src/Types/PollOption.php | 5 +- src/Types/ReplyKeyboardHide.php | 4 +- src/Types/ReplyKeyboardMarkup.php | 4 +- src/Types/ReplyKeyboardRemove.php | 4 +- src/Types/Sticker.php | 4 +- src/Types/Update.php | 5 +- src/Types/User.php | 5 +- src/Types/UserProfilePhotos.php | 4 +- src/Types/Venue.php | 4 +- src/Types/Video.php | 5 +- src/Types/Voice.php | 4 +- src/Types/WebhookInfo.php | 4 +- tests/ArrayOfPhotoSizeTest.php | 18 +- tests/AudioTest.php | 16 +- tests/BaseTypeTest.php | 6 +- tests/BotApiTest.php | 1 - tests/ChatTest.php | 16 +- tests/ClientTest.php | 4 - tests/Collection/CollectionTest.php | 12 +- tests/ContactTest.php | 4 +- tests/DocumentTest.php | 27 ++- tests/FileTest.php | 9 +- tests/ForceReplyTest.php | 9 +- tests/LocationTest.php | 6 +- tests/MessageTest.php | 205 +++++++++--------- tests/PhotoSizeTest.php | 6 +- tests/PollAnswerTest.php | 1 - tests/ReplyKeyboardHideTest.php | 8 +- tests/ReplyKeyboardMarkupTest.php | 60 ++--- tests/StickerTest.php | 24 +- tests/Types/ArrayOfUpdatesTest.php | 1 - tests/Types/CallbackQueryTest.php | 16 +- tests/Types/Events/EventCollectionTest.php | 7 +- tests/Types/Events/EventTest.php | 6 +- .../Types/Inline/InlineKeyboardMarkupTest.php | 1 - tests/Types/Inline/InlineQueryTest.php | 4 +- tests/UserProfilePhotosTest.php | 43 ++-- tests/UserTest.php | 12 +- tests/VideoTest.php | 58 ++--- tests/VoiceTest.php | 15 +- tests/WebhookInfoTest.php | 4 +- 111 files changed, 546 insertions(+), 477 deletions(-) create mode 100644 .github/workflows/cs.yaml create mode 100644 .php-cs-fixer.dist.php create mode 100644 .scrutinizer.yml diff --git a/.gitattributes b/.gitattributes index b2638710..f6d39776 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,9 +2,10 @@ # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". -/.gitattributes export-ignore -/.gitignore export-ignore -/.travis.yml export-ignore -/phpunit.xml.dist export-ignore -/.scrutinizer.yml export-ignore -/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.github export-ignore +/.scrutinizer.yml export-ignore +/phpunit.xml.dist export-ignore +/.php-cs-fixer.dist.php export-ignore +/tests export-ignore diff --git a/.github/workflows/cs.yaml b/.github/workflows/cs.yaml new file mode 100644 index 00000000..f04f2fed --- /dev/null +++ b/.github/workflows/cs.yaml @@ -0,0 +1,51 @@ +on: + - pull_request + - push + +name: CS Check + +jobs: + tests: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + php: + - "8.1" + steps: + - + name: Checkout + uses: actions/checkout@v2 + + - + name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + + - + name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - + name: Cache dependencies installed with composer + uses: actions/cache@v2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer-latest- + - + name: Update composer + run: composer self-update + + - + name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - + name: Run php-cs-fixer + run: composer cs-check diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c1839438..149d6977 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -51,10 +51,14 @@ jobs: name: Update composer run: composer self-update + - + name: Remove php-cs-fixer + run: composer remove friendsofphp/php-cs-fixer --dev --no-update + - name: Install dependencies with composer run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - name: Run tests with phpunit - run: vendor/bin/simple-phpunit --colors=always + run: composer test diff --git a/.gitignore b/.gitignore index 2487936e..0107af84 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ docs vendor .phpunit.result.cache +.php-cs-fixer.cache ### JetBrains template # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..2fd68b52 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,27 @@ +in([ + 'src', + 'tests', + ]) + ->name('*.php') +; + +return (new PhpCsFixer\Config()) + ->setFinder($finder) + ->setRules([ + '@PER' => true, + '@PER:risky' => true, + 'visibility_required' => [ + 'elements' => [ + 'property', + 'method', + // 'const', // Not supported in php < 7.1 + ], + ], + 'no_unused_imports' => true, + 'single_quote' => true, + 'no_extra_blank_lines' => true, + ]) +; diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 00000000..d0f703c8 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,22 @@ +filter: + excluded_paths: [tests/*] + +checks: + php: + remove_extra_empty_lines: true + remove_php_closing_tag: true + remove_trailing_whitespace: true + fix_use_statements: + remove_unused: true + preserve_multiple: false + preserve_blanklines: true + order_alphabetically: true + fix_php_opening_tag: true + fix_linefeed: true + fix_line_ending: true + fix_identation_4spaces: true + fix_doc_comments: true +build: + tests: + override: + - true diff --git a/composer.json b/composer.json index 56a69646..e66c8e6b 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "ext-json": "*" }, "require-dev": { - "symfony/phpunit-bridge" : "*" + "symfony/phpunit-bridge" : "*", + "friendsofphp/php-cs-fixer": "^3.16" }, "autoload": { "psr-4": { @@ -36,7 +37,9 @@ } }, "scripts": { - "test": "vendor/bin/simple-phpunit" + "test": "vendor/bin/simple-phpunit --colors=always", + "cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi", + "cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run" }, "extra": { "branch-alias": { diff --git a/src/BadMethodCallException.php b/src/BadMethodCallException.php index 210fdd8d..738087bb 100644 --- a/src/BadMethodCallException.php +++ b/src/BadMethodCallException.php @@ -10,5 +10,4 @@ */ class BadMethodCallException extends Exception { - } diff --git a/src/BaseType.php b/src/BaseType.php index 976e5d03..9f6fd297 100644 --- a/src/BaseType.php +++ b/src/BaseType.php @@ -58,7 +58,7 @@ public function map($data) protected static function toCamelCase($str) { - return str_replace(" ", "", ucwords(str_replace("_", " ", $str))); + return str_replace(' ', '', ucwords(str_replace('_', ' ', $str))); } public function toJson($inner = false) @@ -89,7 +89,7 @@ public static function fromResponse($data) if ($data === true) { return true; } - + self::validate($data); $instance = new static(); $instance->map($data); diff --git a/src/BotApi.php b/src/BotApi.php index 6ae0f306..6b618b6a 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -209,7 +209,6 @@ public function setModeObject($mode = true) return $this; } - /** * Call method * @@ -288,7 +287,7 @@ protected function executeCurl(array $options) */ public static function curlValidate($curl, $response = null) { - $json = json_decode($response, true)?: []; + $json = json_decode($response, true) ?: []; if (($httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE)) && !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE]) ) { @@ -534,7 +533,6 @@ public function setWebhook( ]); } - /** * Use this method to clear webhook and use getUpdates again! * @@ -2202,7 +2200,6 @@ public function setProxy($proxyString = '', $socks5 = false) return $this; } - /** * Use this method to send a native poll. A native poll can't be sent to a private chat. * On success, the sent \TelegramBot\Api\Types\Message is returned. @@ -2350,8 +2347,7 @@ public function createForumTopic( $name, $iconColor, $iconCustomEmojiId = null - ) - { + ) { return ForumTopic::fromResponse($this->call('createForumTopic', [ 'chat_id' => $chatId, 'name' => $name, @@ -2381,8 +2377,7 @@ public function editForumTopic( $messageThreadId, $name, $iconCustomEmojiId = null - ) - { + ) { return $this->call('editForumTopic', [ 'chat_id' => $chatId, 'message_thread_id' => $messageThreadId, diff --git a/src/Botan.php b/src/Botan.php index 37d9c5f5..9c4cd828 100644 --- a/src/Botan.php +++ b/src/Botan.php @@ -6,7 +6,6 @@ class Botan { - /** * @var string Tracker url */ @@ -19,7 +18,6 @@ class Botan */ protected $curl; - /** * Yandex AppMetrica application api_key * diff --git a/src/Collection/KeyHasUseException.php b/src/Collection/KeyHasUseException.php index 0566b140..6667e733 100644 --- a/src/Collection/KeyHasUseException.php +++ b/src/Collection/KeyHasUseException.php @@ -12,5 +12,4 @@ */ class KeyHasUseException extends Exception { - } diff --git a/src/Collection/KeyInvalidException.php b/src/Collection/KeyInvalidException.php index 993a4be3..8c87fc51 100644 --- a/src/Collection/KeyInvalidException.php +++ b/src/Collection/KeyInvalidException.php @@ -12,5 +12,4 @@ */ class KeyInvalidException extends Exception { - } diff --git a/src/Collection/ReachedMaxSizeException.php b/src/Collection/ReachedMaxSizeException.php index 360d2c96..ad31e96d 100644 --- a/src/Collection/ReachedMaxSizeException.php +++ b/src/Collection/ReachedMaxSizeException.php @@ -12,5 +12,4 @@ */ class ReachedMaxSizeException extends Exception { - } diff --git a/src/Events/Event.php b/src/Events/Event.php index 19928322..9b6b8b54 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -2,7 +2,6 @@ namespace TelegramBot\Api\Events; -use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Update; class Event diff --git a/src/Events/EventCollection.php b/src/Events/EventCollection.php index b11e40ca..c51b0ed4 100644 --- a/src/Events/EventCollection.php +++ b/src/Events/EventCollection.php @@ -35,7 +35,6 @@ public function __construct($trackerToken = null) } } - /** * Add new event to collection * diff --git a/src/Exception.php b/src/Exception.php index a47a58f6..e43cf16d 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -10,5 +10,4 @@ */ class Exception extends \Exception { - } diff --git a/src/InvalidArgumentException.php b/src/InvalidArgumentException.php index 9c650905..ae9b949e 100644 --- a/src/InvalidArgumentException.php +++ b/src/InvalidArgumentException.php @@ -10,5 +10,4 @@ */ class InvalidArgumentException extends Exception { - } diff --git a/src/InvalidJsonException.php b/src/InvalidJsonException.php index 6eea8bc5..71011e96 100644 --- a/src/InvalidJsonException.php +++ b/src/InvalidJsonException.php @@ -10,5 +10,4 @@ */ class InvalidJsonException extends Exception { - } diff --git a/src/Types/Animation.php b/src/Types/Animation.php index ad50e9d9..512224a4 100644 --- a/src/Types/Animation.php +++ b/src/Types/Animation.php @@ -19,14 +19,14 @@ class Animation extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'file_unique_id', 'width', 'height', 'duration']; + protected static $requiredParams = ['file_id', 'file_unique_id', 'width', 'height', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, 'file_unique_id' => true, 'width' => true, diff --git a/src/Types/Audio.php b/src/Types/Audio.php index 6c3ed13e..4805e143 100644 --- a/src/Types/Audio.php +++ b/src/Types/Audio.php @@ -19,14 +19,14 @@ class Audio extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'file_unique_id', 'duration']; + protected static $requiredParams = ['file_id', 'file_unique_id', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, 'file_unique_id' => true, 'duration' => true, diff --git a/src/Types/BotCommand.php b/src/Types/BotCommand.php index ae340f36..051cb246 100644 --- a/src/Types/BotCommand.php +++ b/src/Types/BotCommand.php @@ -12,14 +12,14 @@ class BotCommand extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['command', 'description']; + protected static $requiredParams = ['command', 'description']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'command' => true, 'description' => true, ]; diff --git a/src/Types/CallbackQuery.php b/src/Types/CallbackQuery.php index b82ea152..9d325040 100644 --- a/src/Types/CallbackQuery.php +++ b/src/Types/CallbackQuery.php @@ -23,14 +23,14 @@ class CallbackQuery extends BaseType * * @var array */ - static protected $requiredParams = ['id', 'from']; + protected static $requiredParams = ['id', 'from']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'from' => User::class, 'message' => Message::class, @@ -95,7 +95,6 @@ class CallbackQuery extends BaseType */ protected $gameShortName; - /** * @return string */ diff --git a/src/Types/Chat.php b/src/Types/Chat.php index 26497d4d..39377365 100644 --- a/src/Types/Chat.php +++ b/src/Types/Chat.php @@ -13,14 +13,14 @@ class Chat extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['id', 'type']; + protected static $requiredParams = ['id', 'type']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'type' => true, 'title' => true, diff --git a/src/Types/ChatLocation.php b/src/Types/ChatLocation.php index 2330b982..6b4207ce 100644 --- a/src/Types/ChatLocation.php +++ b/src/Types/ChatLocation.php @@ -12,14 +12,14 @@ class ChatLocation extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['location', 'address']; + protected static $requiredParams = ['location', 'address']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'location' => Location::class, 'address' => true, ]; diff --git a/src/Types/ChatMember.php b/src/Types/ChatMember.php index a3ba60d8..8ba126a3 100644 --- a/src/Types/ChatMember.php +++ b/src/Types/ChatMember.php @@ -11,14 +11,14 @@ class ChatMember extends BaseType * * @var array */ - static protected $requiredParams = ['user', 'status']; + protected static $requiredParams = ['user', 'status']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'user' => User::class, 'status' => true, 'until_date' => true, diff --git a/src/Types/ChatPermissions.php b/src/Types/ChatPermissions.php index 99bb6787..c7c2041f 100644 --- a/src/Types/ChatPermissions.php +++ b/src/Types/ChatPermissions.php @@ -12,14 +12,14 @@ class ChatPermissions extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = []; + protected static $requiredParams = []; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'can_send_messages' => true, 'can_send_media_messages' => true, 'can_send_polls' => true, diff --git a/src/Types/ChatPhoto.php b/src/Types/ChatPhoto.php index 29a8d8f1..3dca2895 100644 --- a/src/Types/ChatPhoto.php +++ b/src/Types/ChatPhoto.php @@ -11,14 +11,14 @@ class ChatPhoto extends BaseType * * @var array */ - static protected $requiredParams = ['small_file_id', 'big_file_id']; + protected static $requiredParams = ['small_file_id', 'big_file_id']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'small_file_id' => true, 'big_file_id' => true, ]; diff --git a/src/Types/Contact.php b/src/Types/Contact.php index ea195ce5..7069c10c 100644 --- a/src/Types/Contact.php +++ b/src/Types/Contact.php @@ -18,14 +18,14 @@ class Contact extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['phone_number', 'first_name']; + protected static $requiredParams = ['phone_number', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'phone_number' => true, 'first_name' => true, 'last_name' => true, diff --git a/src/Types/Dice.php b/src/Types/Dice.php index ee2e089c..d0bcfa21 100644 --- a/src/Types/Dice.php +++ b/src/Types/Dice.php @@ -16,14 +16,14 @@ class Dice extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['emoji', 'value']; + protected static $requiredParams = ['emoji', 'value']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'emoji' => true, 'value' => true ]; diff --git a/src/Types/Document.php b/src/Types/Document.php index afba5ad6..8c65534a 100644 --- a/src/Types/Document.php +++ b/src/Types/Document.php @@ -20,7 +20,7 @@ class Document extends BaseType implements TypeInterface * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, 'file_unique_id' => true, 'thumb' => PhotoSize::class, @@ -34,7 +34,7 @@ class Document extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'file_unique_id']; + protected static $requiredParams = ['file_id', 'file_unique_id']; /** * Unique identifier for this file diff --git a/src/Types/File.php b/src/Types/File.php index 06a35f55..2b6791fd 100644 --- a/src/Types/File.php +++ b/src/Types/File.php @@ -22,14 +22,14 @@ class File extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id']; + protected static $requiredParams = ['file_id']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, 'file_unique_id' => true, 'file_size' => true, diff --git a/src/Types/ForceReply.php b/src/Types/ForceReply.php index 6dbd2d79..ced9a30f 100644 --- a/src/Types/ForceReply.php +++ b/src/Types/ForceReply.php @@ -19,14 +19,14 @@ class ForceReply extends BaseType * * @var array */ - static protected $requiredParams = ['force_reply']; + protected static $requiredParams = ['force_reply']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'force_reply' => true, 'selective' => true ]; diff --git a/src/Types/Inline/ChosenInlineResult.php b/src/Types/Inline/ChosenInlineResult.php index ff86a004..acdb22c3 100644 --- a/src/Types/Inline/ChosenInlineResult.php +++ b/src/Types/Inline/ChosenInlineResult.php @@ -19,14 +19,14 @@ class ChosenInlineResult extends BaseType * * @var array */ - static protected $requiredParams = ['result_id', 'from', 'query']; + protected static $requiredParams = ['result_id', 'from', 'query']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'result_id' => true, 'from' => User::class, 'location' => Location::class, diff --git a/src/Types/Inline/InlineKeyboardMarkup.php b/src/Types/Inline/InlineKeyboardMarkup.php index 170bd357..b9430be7 100644 --- a/src/Types/Inline/InlineKeyboardMarkup.php +++ b/src/Types/Inline/InlineKeyboardMarkup.php @@ -17,14 +17,14 @@ class InlineKeyboardMarkup extends BaseType * * @var array */ - static protected $requiredParams = ['inline_keyboard']; + protected static $requiredParams = ['inline_keyboard']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'inline_keyboard' => true, ]; diff --git a/src/Types/Inline/InlineQuery.php b/src/Types/Inline/InlineQuery.php index b6623a89..65b56851 100644 --- a/src/Types/Inline/InlineQuery.php +++ b/src/Types/Inline/InlineQuery.php @@ -20,14 +20,14 @@ class InlineQuery extends BaseType * * @var array */ - static protected $requiredParams = ['id', 'from', 'query', 'offset']; + protected static $requiredParams = ['id', 'from', 'query', 'offset']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'from' => User::class, 'location' => Location::class, @@ -49,7 +49,6 @@ class InlineQuery extends BaseType */ protected $from; - /** * Optional. Sender location, only for bots that request user location * diff --git a/src/Types/Inline/InputMessageContent.php b/src/Types/Inline/InputMessageContent.php index ba4a314b..f3218b56 100644 --- a/src/Types/Inline/InputMessageContent.php +++ b/src/Types/Inline/InputMessageContent.php @@ -12,5 +12,4 @@ class InputMessageContent extends BaseType { - } diff --git a/src/Types/Inline/InputMessageContent/Contact.php b/src/Types/Inline/InputMessageContent/Contact.php index 508eaef2..681b9c6d 100644 --- a/src/Types/Inline/InputMessageContent/Contact.php +++ b/src/Types/Inline/InputMessageContent/Contact.php @@ -8,7 +8,6 @@ namespace TelegramBot\Api\Types\Inline\InputMessageContent; -use TelegramBot\Api\BaseType; use TelegramBot\Api\TypeInterface; use TelegramBot\Api\Types\Inline\InputMessageContent; @@ -27,14 +26,14 @@ class Contact extends InputMessageContent implements TypeInterface * * @var array */ - static protected $requiredParams = ['phone_number', 'first_name']; + protected static $requiredParams = ['phone_number', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'phone_number' => true, 'first_name' => true, 'last_name' => true, @@ -75,7 +74,6 @@ public function __construct($phoneNumber, $firstName, $lastName = null) $this->lastName = $lastName; } - /** * @return string */ diff --git a/src/Types/Inline/InputMessageContent/Location.php b/src/Types/Inline/InputMessageContent/Location.php index d20d90b7..b4a17833 100644 --- a/src/Types/Inline/InputMessageContent/Location.php +++ b/src/Types/Inline/InputMessageContent/Location.php @@ -25,14 +25,14 @@ class Location extends InputMessageContent implements TypeInterface * * @var array */ - static protected $requiredParams = ['latitude', 'longitude']; + protected static $requiredParams = ['latitude', 'longitude']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'latitude' => true, 'longitude' => true ]; @@ -62,7 +62,6 @@ public function __construct($latitude, $longitude) $this->longitude = $longitude; } - /** * @return float */ diff --git a/src/Types/Inline/InputMessageContent/Text.php b/src/Types/Inline/InputMessageContent/Text.php index fdcfce17..449ef251 100644 --- a/src/Types/Inline/InputMessageContent/Text.php +++ b/src/Types/Inline/InputMessageContent/Text.php @@ -8,7 +8,6 @@ namespace TelegramBot\Api\Types\Inline\InputMessageContent; -use TelegramBot\Api\BaseType; use TelegramBot\Api\TypeInterface; use TelegramBot\Api\Types\Inline\InputMessageContent; @@ -26,14 +25,14 @@ class Text extends InputMessageContent implements TypeInterface * * @var array */ - static protected $requiredParams = ['message_text']; + protected static $requiredParams = ['message_text']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'message_text' => true, 'parse_mode' => true, 'disable_web_page_preview' => true, diff --git a/src/Types/Inline/InputMessageContent/Venue.php b/src/Types/Inline/InputMessageContent/Venue.php index 7b57438c..2cb66628 100644 --- a/src/Types/Inline/InputMessageContent/Venue.php +++ b/src/Types/Inline/InputMessageContent/Venue.php @@ -25,14 +25,14 @@ class Venue extends InputMessageContent implements TypeInterface * * @var array */ - static protected $requiredParams = ['latitude', 'longitude', 'title', 'address']; + protected static $requiredParams = ['latitude', 'longitude', 'title', 'address']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'latitude' => true, 'longitude' => true, 'title' => true, @@ -92,7 +92,6 @@ public function __construct($latitude, $longitude, $title, $address, $foursquare $this->foursquareId = $foursquareId; } - /** * @return float */ diff --git a/src/Types/Inline/QueryResult/Article.php b/src/Types/Inline/QueryResult/Article.php index a0b12178..69bab239 100644 --- a/src/Types/Inline/QueryResult/Article.php +++ b/src/Types/Inline/QueryResult/Article.php @@ -18,14 +18,14 @@ class Article extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'title', 'input_message_content']; + protected static $requiredParams = ['type', 'id', 'title', 'input_message_content']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'title' => true, @@ -118,7 +118,6 @@ public function __construct( $this->thumbHeight = $thumbHeight; } - /** * @return string */ diff --git a/src/Types/Inline/QueryResult/Audio.php b/src/Types/Inline/QueryResult/Audio.php index d4a3e9f0..0667ac0c 100644 --- a/src/Types/Inline/QueryResult/Audio.php +++ b/src/Types/Inline/QueryResult/Audio.php @@ -29,14 +29,14 @@ class Audio extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'audio_url', 'title']; + protected static $requiredParams = ['type', 'id', 'audio_url', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'audio_url' => true, diff --git a/src/Types/Inline/QueryResult/Contact.php b/src/Types/Inline/QueryResult/Contact.php index 9fee3535..b5bfbe55 100644 --- a/src/Types/Inline/QueryResult/Contact.php +++ b/src/Types/Inline/QueryResult/Contact.php @@ -18,14 +18,14 @@ class Contact extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'phone_number', 'first_name']; + protected static $requiredParams = ['type', 'id', 'phone_number', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'phone_number' => true, @@ -121,7 +121,6 @@ public function __construct( $this->thumbHeight = $thumbHeight; } - /** * @return string */ diff --git a/src/Types/Inline/QueryResult/Gif.php b/src/Types/Inline/QueryResult/Gif.php index de3f10de..49a185be 100644 --- a/src/Types/Inline/QueryResult/Gif.php +++ b/src/Types/Inline/QueryResult/Gif.php @@ -20,14 +20,14 @@ class Gif extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'gif_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'gif_url', 'thumb_url']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'gif_url' => true, diff --git a/src/Types/Inline/QueryResult/Location.php b/src/Types/Inline/QueryResult/Location.php index 799f6be6..1c3b907f 100644 --- a/src/Types/Inline/QueryResult/Location.php +++ b/src/Types/Inline/QueryResult/Location.php @@ -29,14 +29,14 @@ class Location extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'latitude', 'longitude', 'title']; + protected static $requiredParams = ['type', 'id', 'latitude', 'longitude', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'latitude' => true, diff --git a/src/Types/Inline/QueryResult/Mpeg4Gif.php b/src/Types/Inline/QueryResult/Mpeg4Gif.php index 8578e69f..de0c7cbc 100644 --- a/src/Types/Inline/QueryResult/Mpeg4Gif.php +++ b/src/Types/Inline/QueryResult/Mpeg4Gif.php @@ -20,14 +20,14 @@ class Mpeg4Gif extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'mpeg4_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'mpeg4_url', 'thumb_url']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'mpeg4_url' => true, @@ -115,7 +115,6 @@ public function __construct( $this->caption = $caption; } - /** * @return string */ diff --git a/src/Types/Inline/QueryResult/Photo.php b/src/Types/Inline/QueryResult/Photo.php index 106ec04f..299f9a8c 100644 --- a/src/Types/Inline/QueryResult/Photo.php +++ b/src/Types/Inline/QueryResult/Photo.php @@ -19,14 +19,14 @@ class Photo extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'photo_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'photo_url', 'thumb_url']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'photo_url' => true, @@ -125,7 +125,6 @@ public function __construct( $this->caption = $caption; } - /** * @return string */ diff --git a/src/Types/Inline/QueryResult/Venue.php b/src/Types/Inline/QueryResult/Venue.php index b3c6940c..4a91a417 100644 --- a/src/Types/Inline/QueryResult/Venue.php +++ b/src/Types/Inline/QueryResult/Venue.php @@ -29,14 +29,14 @@ class Venue extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'latitude', 'longitude', 'title', 'address']; + protected static $requiredParams = ['type', 'id', 'latitude', 'longitude', 'title', 'address']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'latitude' => true, diff --git a/src/Types/Inline/QueryResult/Video.php b/src/Types/Inline/QueryResult/Video.php index 7a999cc9..961eff0d 100644 --- a/src/Types/Inline/QueryResult/Video.php +++ b/src/Types/Inline/QueryResult/Video.php @@ -18,14 +18,14 @@ class Video extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'video_url', 'mime_type', 'thumb_url', 'title']; + protected static $requiredParams = ['type', 'id', 'video_url', 'mime_type', 'thumb_url', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'video_url' => true, @@ -104,7 +104,6 @@ class Video extends AbstractInlineQueryResult */ protected $description; - /** * Video constructor * @@ -136,7 +135,7 @@ public function __construct( $inlineKeyboardMarkup = null ) { parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); - + $this->videoUrl = $videoUrl; $this->thumbUrl = $thumbUrl; $this->caption = $caption; @@ -147,7 +146,6 @@ public function __construct( $this->videoDuration = $videoDuration; } - /** * @return string */ diff --git a/src/Types/Inline/QueryResult/Voice.php b/src/Types/Inline/QueryResult/Voice.php index f86d19bb..d2445c3f 100644 --- a/src/Types/Inline/QueryResult/Voice.php +++ b/src/Types/Inline/QueryResult/Voice.php @@ -29,14 +29,14 @@ class Voice extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'voice_url', 'title']; + protected static $requiredParams = ['type', 'id', 'voice_url', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'voice_url' => true, @@ -60,7 +60,6 @@ class Voice extends AbstractInlineQueryResult */ protected $voiceUrl; - /** * Optional. Audio duration in seconds * diff --git a/src/Types/InputMedia/InputMedia.php b/src/Types/InputMedia/InputMedia.php index f6f47bb7..31915aad 100644 --- a/src/Types/InputMedia/InputMedia.php +++ b/src/Types/InputMedia/InputMedia.php @@ -18,14 +18,14 @@ class InputMedia extends BaseType implements CollectionItemInterface * * @var array */ - static protected $requiredParams = ['type', 'media']; + protected static $requiredParams = ['type', 'media']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'media' => true, 'caption' => true, diff --git a/src/Types/InputMedia/InputMediaVideo.php b/src/Types/InputMedia/InputMediaVideo.php index b1ed5552..1f684da1 100644 --- a/src/Types/InputMedia/InputMediaVideo.php +++ b/src/Types/InputMedia/InputMediaVideo.php @@ -15,7 +15,7 @@ class InputMediaVideo extends InputMedia * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'media' => true, 'caption' => true, diff --git a/src/Types/Location.php b/src/Types/Location.php index 917009bc..5514a28b 100644 --- a/src/Types/Location.php +++ b/src/Types/Location.php @@ -19,14 +19,14 @@ class Location extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['latitude', 'longitude']; + protected static $requiredParams = ['latitude', 'longitude']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'latitude' => true, 'longitude' => true, 'horizontal_accuracy' => true, diff --git a/src/Types/LoginUrl.php b/src/Types/LoginUrl.php index 9dd372f7..8249175b 100644 --- a/src/Types/LoginUrl.php +++ b/src/Types/LoginUrl.php @@ -14,14 +14,14 @@ class LoginUrl extends BaseType implements TypeInterface /** * @var array */ - static protected $requiredParams = ['url']; + protected static $requiredParams = ['url']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'url' => true, 'forward_text' => true, 'bot_username' => true, diff --git a/src/Types/Message.php b/src/Types/Message.php index 69dedf21..68cbd076 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -1,4 +1,5 @@ true, 'from' => User::class, 'date' => true, @@ -446,7 +447,6 @@ class Message extends BaseType implements TypeInterface */ protected $messageThreadId; - /** * @return int */ diff --git a/src/Types/MessageEntity.php b/src/Types/MessageEntity.php index 16e9d025..d3d2d2ea 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -19,7 +19,6 @@ */ class MessageEntity extends BaseType implements TypeInterface { - const TYPE_MENTION = 'mention'; const TYPE_HASHTAG = 'hashtag'; const TYPE_CASHTAG = 'cashtag'; @@ -42,14 +41,14 @@ class MessageEntity extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['type', 'offset', 'length']; + protected static $requiredParams = ['type', 'offset', 'length']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'offset' => true, 'length' => true, diff --git a/src/Types/Payments/Invoice.php b/src/Types/Payments/Invoice.php index 61669a8b..8f73a95b 100644 --- a/src/Types/Payments/Invoice.php +++ b/src/Types/Payments/Invoice.php @@ -15,12 +15,12 @@ class Invoice extends BaseType /** * @var array */ - static protected $requiredParams = ['title', 'description', 'start_parameter', 'currency', 'total_amount']; + protected static $requiredParams = ['title', 'description', 'start_parameter', 'currency', 'total_amount']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'title' => true, 'description' => true, 'start_parameter' => true, diff --git a/src/Types/Payments/LabeledPrice.php b/src/Types/Payments/LabeledPrice.php index c04b983b..0e2b7074 100644 --- a/src/Types/Payments/LabeledPrice.php +++ b/src/Types/Payments/LabeledPrice.php @@ -15,12 +15,12 @@ class LabeledPrice extends BaseType /** * @var array */ - static protected $requiredParams = ['label', 'amount']; + protected static $requiredParams = ['label', 'amount']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'label' => true, 'amount' => true ]; diff --git a/src/Types/Payments/OrderInfo.php b/src/Types/Payments/OrderInfo.php index 3d45d8db..6138b133 100644 --- a/src/Types/Payments/OrderInfo.php +++ b/src/Types/Payments/OrderInfo.php @@ -15,12 +15,12 @@ class OrderInfo extends BaseType /** * @var array */ - static protected $requiredParams = []; + protected static $requiredParams = []; /** * @var array */ - static protected $map = [ + protected static $map = [ 'name' => true, 'phone_number' => true, 'email' => true, diff --git a/src/Types/Payments/Query/AnswerPreCheckoutQuery.php b/src/Types/Payments/Query/AnswerPreCheckoutQuery.php index dd427d7d..a157f7de 100644 --- a/src/Types/Payments/Query/AnswerPreCheckoutQuery.php +++ b/src/Types/Payments/Query/AnswerPreCheckoutQuery.php @@ -3,7 +3,6 @@ namespace TelegramBot\Api\Types\Payments\Query; use TelegramBot\Api\BaseType; -use TelegramBot\Api\Types\Payments\ArrayOfLabeledPrice; /** * Class AnswerPreCheckoutQuery @@ -16,12 +15,12 @@ class AnswerPreCheckoutQuery extends BaseType /** * @var array */ - static protected $requiredParams = ['pre_checkout_query_id', 'ok']; + protected static $requiredParams = ['pre_checkout_query_id', 'ok']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'pre_checkout_query_id' => true, 'ok' => true, 'error_message' => true, diff --git a/src/Types/Payments/Query/AnswerShippingQuery.php b/src/Types/Payments/Query/AnswerShippingQuery.php index f7ea2871..8999ba84 100644 --- a/src/Types/Payments/Query/AnswerShippingQuery.php +++ b/src/Types/Payments/Query/AnswerShippingQuery.php @@ -17,12 +17,12 @@ class AnswerShippingQuery extends BaseType /** * @var array */ - static protected $requiredParams = ['shipping_query_id', 'ok']; + protected static $requiredParams = ['shipping_query_id', 'ok']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'shipping_query_id' => true, 'ok' => true, 'shipping_options' => ArrayOfLabeledPrice::class, diff --git a/src/Types/Payments/Query/PreCheckoutQuery.php b/src/Types/Payments/Query/PreCheckoutQuery.php index 7422f286..17c2510d 100644 --- a/src/Types/Payments/Query/PreCheckoutQuery.php +++ b/src/Types/Payments/Query/PreCheckoutQuery.php @@ -3,9 +3,7 @@ namespace TelegramBot\Api\Types\Payments\Query; use TelegramBot\Api\BaseType; -use TelegramBot\Api\Types\Payments\ArrayOfLabeledPrice; use TelegramBot\Api\Types\Payments\OrderInfo; -use TelegramBot\Api\Types\Payments\ShippingAddress; use TelegramBot\Api\Types\User; /** @@ -19,12 +17,12 @@ class PreCheckoutQuery extends BaseType /** * @var array */ - static protected $requiredParams = ['id', 'from', 'currency', 'total_amount', 'invoice_payload']; + protected static $requiredParams = ['id', 'from', 'currency', 'total_amount', 'invoice_payload']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'from' => User::class, 'currency' => true, diff --git a/src/Types/Payments/Query/ShippingQuery.php b/src/Types/Payments/Query/ShippingQuery.php index f50d1f9e..7a2c935e 100644 --- a/src/Types/Payments/Query/ShippingQuery.php +++ b/src/Types/Payments/Query/ShippingQuery.php @@ -3,7 +3,6 @@ namespace TelegramBot\Api\Types\Payments\Query; use TelegramBot\Api\BaseType; -use TelegramBot\Api\Types\Payments\ArrayOfLabeledPrice; use TelegramBot\Api\Types\Payments\ShippingAddress; use TelegramBot\Api\Types\User; @@ -18,14 +17,14 @@ class ShippingQuery extends BaseType /** * @var array */ - static protected $requiredParams = ['id', 'from', 'invoice_payload', 'shipping_address']; + protected static $requiredParams = ['id', 'from', 'invoice_payload', 'shipping_address']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'from' => User::class, 'invoice_payload' => true, diff --git a/src/Types/Payments/ShippingAddress.php b/src/Types/Payments/ShippingAddress.php index d5e34728..bc5a2403 100644 --- a/src/Types/Payments/ShippingAddress.php +++ b/src/Types/Payments/ShippingAddress.php @@ -15,12 +15,12 @@ class ShippingAddress extends BaseType /** * @var array */ - static protected $requiredParams = ['country_code', 'state', 'city', 'street_line1', 'street_line2', 'post_code']; + protected static $requiredParams = ['country_code', 'state', 'city', 'street_line1', 'street_line2', 'post_code']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'country_code' => true, 'state' => true, 'city' => true, diff --git a/src/Types/Payments/ShippingOption.php b/src/Types/Payments/ShippingOption.php index 15359592..fda483f9 100644 --- a/src/Types/Payments/ShippingOption.php +++ b/src/Types/Payments/ShippingOption.php @@ -15,12 +15,12 @@ class ShippingOption extends BaseType /** * @var array */ - static protected $requiredParams = ['id', 'title', 'prices']; + protected static $requiredParams = ['id', 'title', 'prices']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'title' => true, 'prices' => ArrayOfLabeledPrice::class diff --git a/src/Types/Payments/SuccessfulPayment.php b/src/Types/Payments/SuccessfulPayment.php index 51707930..64ce84af 100644 --- a/src/Types/Payments/SuccessfulPayment.php +++ b/src/Types/Payments/SuccessfulPayment.php @@ -15,7 +15,7 @@ class SuccessfulPayment extends BaseType /** * @var array */ - static protected $requiredParams = [ + protected static $requiredParams = [ 'currency', 'total_amount', 'invoice_payload', @@ -26,7 +26,7 @@ class SuccessfulPayment extends BaseType /** * @var array */ - static protected $map = [ + protected static $map = [ 'currency' => true, 'total_amount' => true, 'invoice_payload' => true, diff --git a/src/Types/PhotoSize.php b/src/Types/PhotoSize.php index 2c989c61..57099f0e 100644 --- a/src/Types/PhotoSize.php +++ b/src/Types/PhotoSize.php @@ -19,14 +19,14 @@ class PhotoSize extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'file_unique_id', 'width', 'height']; + protected static $requiredParams = ['file_id', 'file_unique_id', 'width', 'height']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, 'file_unique_id' => true, 'width' => true, diff --git a/src/Types/Poll.php b/src/Types/Poll.php index 6433915f..837cd298 100644 --- a/src/Types/Poll.php +++ b/src/Types/Poll.php @@ -3,7 +3,6 @@ namespace TelegramBot\Api\Types; use TelegramBot\Api\BaseType; -use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\TypeInterface; /** diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index 278f3317..c6ac7d96 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -21,14 +21,14 @@ class PollAnswer extends BaseType * * @var array */ - static protected $requiredParams = ['poll_id', 'option_ids', 'user']; + protected static $requiredParams = ['poll_id', 'option_ids', 'user']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'option_ids' => true, 'user' => User::class, 'poll_id' => true, diff --git a/src/Types/PollOption.php b/src/Types/PollOption.php index 5f9dbc14..1d22ffde 100644 --- a/src/Types/PollOption.php +++ b/src/Types/PollOption.php @@ -3,7 +3,6 @@ namespace TelegramBot\Api\Types; use TelegramBot\Api\BaseType; -use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\TypeInterface; /** @@ -19,14 +18,14 @@ class PollOption extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['text', 'voter_count']; + protected static $requiredParams = ['text', 'voter_count']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'text' => true, 'voter_count' => true ]; diff --git a/src/Types/ReplyKeyboardHide.php b/src/Types/ReplyKeyboardHide.php index d7c27e51..8dbfc8fb 100644 --- a/src/Types/ReplyKeyboardHide.php +++ b/src/Types/ReplyKeyboardHide.php @@ -20,14 +20,14 @@ class ReplyKeyboardHide extends BaseType * * @var array */ - static protected $requiredParams = ['hide_keyboard']; + protected static $requiredParams = ['hide_keyboard']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'hide_keyboard' => true, 'selective' => true ]; diff --git a/src/Types/ReplyKeyboardMarkup.php b/src/Types/ReplyKeyboardMarkup.php index 5c9cce9e..83e2192d 100644 --- a/src/Types/ReplyKeyboardMarkup.php +++ b/src/Types/ReplyKeyboardMarkup.php @@ -17,14 +17,14 @@ class ReplyKeyboardMarkup extends BaseType * * @var array */ - static protected $requiredParams = ['keyboard']; + protected static $requiredParams = ['keyboard']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'keyboard' => true, 'one_time_keyboard' => true, 'resize_keyboard' => true, diff --git a/src/Types/ReplyKeyboardRemove.php b/src/Types/ReplyKeyboardRemove.php index bc092227..519ffc5f 100644 --- a/src/Types/ReplyKeyboardRemove.php +++ b/src/Types/ReplyKeyboardRemove.php @@ -18,14 +18,14 @@ class ReplyKeyboardRemove extends BaseType * * @var array */ - static protected $requiredParams = ['remove_keyboard']; + protected static $requiredParams = ['remove_keyboard']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'remove_keyboard' => true, 'selective' => true ]; diff --git a/src/Types/Sticker.php b/src/Types/Sticker.php index 36dd136b..37590725 100644 --- a/src/Types/Sticker.php +++ b/src/Types/Sticker.php @@ -19,7 +19,7 @@ class Sticker extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = [ + protected static $requiredParams = [ 'file_id', 'file_unique_id', 'type', @@ -34,7 +34,7 @@ class Sticker extends BaseType implements TypeInterface * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, 'width' => true, 'height' => true, diff --git a/src/Types/Update.php b/src/Types/Update.php index 031d2b56..7b33fec9 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -23,14 +23,14 @@ class Update extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['update_id']; + protected static $requiredParams = ['update_id']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'update_id' => true, 'message' => Message::class, 'edited_message' => Message::class, @@ -72,7 +72,6 @@ class Update extends BaseType implements TypeInterface */ protected $poll; - /** * Optional. New version of a message that is known to the bot and was edited * diff --git a/src/Types/User.php b/src/Types/User.php index ac8709b9..b6d204fb 100644 --- a/src/Types/User.php +++ b/src/Types/User.php @@ -19,14 +19,14 @@ class User extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['id', 'first_name']; + protected static $requiredParams = ['id', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'first_name' => true, 'last_name' => true, @@ -299,5 +299,4 @@ public function getSupportsInlineQueries() return $this->supportsInlineQueries; } - } diff --git a/src/Types/UserProfilePhotos.php b/src/Types/UserProfilePhotos.php index cdfa842f..cac8f52b 100644 --- a/src/Types/UserProfilePhotos.php +++ b/src/Types/UserProfilePhotos.php @@ -19,14 +19,14 @@ class UserProfilePhotos extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['total_count', 'photos']; + protected static $requiredParams = ['total_count', 'photos']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'total_count' => true, 'photos' => ArrayOfArrayOfPhotoSize::class, ]; diff --git a/src/Types/Venue.php b/src/Types/Venue.php index 173be67c..225d15a4 100644 --- a/src/Types/Venue.php +++ b/src/Types/Venue.php @@ -24,14 +24,14 @@ class Venue extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['location', 'title', 'address']; + protected static $requiredParams = ['location', 'title', 'address']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'location' => Location::class, 'title' => true, 'address' => true, diff --git a/src/Types/Video.php b/src/Types/Video.php index 4ae3857c..f367a77e 100644 --- a/src/Types/Video.php +++ b/src/Types/Video.php @@ -19,14 +19,14 @@ class Video extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'file_unique_id', 'width', 'height', 'duration']; + protected static $requiredParams = ['file_id', 'file_unique_id', 'width', 'height', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, 'file_unique_id' => true, 'width' => true, @@ -72,7 +72,6 @@ class Video extends BaseType implements TypeInterface */ protected $thumb; - /** * Optional. Mime type of a file as defined by sender * diff --git a/src/Types/Voice.php b/src/Types/Voice.php index 0b1f5e92..e8015a96 100644 --- a/src/Types/Voice.php +++ b/src/Types/Voice.php @@ -19,14 +19,14 @@ class Voice extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'file_unique_id', 'duration']; + protected static $requiredParams = ['file_id', 'file_unique_id', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, 'file_unique_id' => true, 'duration' => true, diff --git a/src/Types/WebhookInfo.php b/src/Types/WebhookInfo.php index 33c49cb4..2b477e93 100644 --- a/src/Types/WebhookInfo.php +++ b/src/Types/WebhookInfo.php @@ -22,14 +22,14 @@ class WebhookInfo extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['url', 'has_custom_certificate', 'pending_update_count']; + protected static $requiredParams = ['url', 'has_custom_certificate', 'pending_update_count']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'url' => true, 'has_custom_certificate' => true, 'pending_update_count' => true, diff --git a/tests/ArrayOfPhotoSizeTest.php b/tests/ArrayOfPhotoSizeTest.php index 1a75816f..01aedbe8 100644 --- a/tests/ArrayOfPhotoSizeTest.php +++ b/tests/ArrayOfPhotoSizeTest.php @@ -2,37 +2,35 @@ namespace TelegramBot\Api\Test; - use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\PhotoSize; use TelegramBot\Api\Types\ArrayOfPhotoSize; class ArrayOfPhotoSizeTest extends TestCase { - public function testFromResponse() { $actual = ArrayOfPhotoSize::fromResponse( - array( - array( + [ + [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - ) + ] + ] ); - $expected = array( - PhotoSize::fromResponse(array( + $expected = [ + PhotoSize::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - )) - ); + ]) + ]; foreach($actual as $key => $item) { $this->assertEquals($expected[$key], $item); diff --git a/tests/AudioTest.php b/tests/AudioTest.php index 11497d7d..17fbb236 100644 --- a/tests/AudioTest.php +++ b/tests/AudioTest.php @@ -52,7 +52,7 @@ public function testSetMimeType() public function testFromResponse() { - $item = Audio::fromResponse(array( + $item = Audio::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, @@ -60,7 +60,7 @@ public function testFromResponse() 'title' => 'testtitle', 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); $this->assertInstanceOf(Audio::class, $item); $this->assertEquals('testFileId1', $item->getFileId()); $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); @@ -78,12 +78,12 @@ public function testFromResponseException() { $this->expectException(InvalidArgumentException::class); - $item = Audio::fromResponse(array( + $item = Audio::fromResponse([ 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); } /** @@ -93,12 +93,12 @@ public function testFromResponseException2() { $this->expectException(InvalidArgumentException::class); - $item = Audio::fromResponse(array( + $item = Audio::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); } /** @@ -108,12 +108,12 @@ public function testFromResponseException3() { $this->expectException(InvalidArgumentException::class); - $item = Audio::fromResponse(array( + $item = Audio::fromResponse([ 'file_id' => 'testFileId1', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); } public function testSetDurationException() diff --git a/tests/BaseTypeTest.php b/tests/BaseTypeTest.php index 269973d9..e0bcff77 100644 --- a/tests/BaseTypeTest.php +++ b/tests/BaseTypeTest.php @@ -10,18 +10,18 @@ class BaseTypeTest extends TestCase { public function testValidate() { - $this->assertTrue(TestBaseType::validate(array('test1' => 1, 'test2' => 2, 'test3' => 3))); + $this->assertTrue(TestBaseType::validate(['test1' => 1, 'test2' => 2, 'test3' => 3])); } public function testValidateFail() { $this->expectException(InvalidArgumentException::class); - $this->assertTrue(TestBaseType::validate(array('test1' => 1))); + $this->assertTrue(TestBaseType::validate(['test1' => 1])); } } class TestBaseType extends BaseType { - protected static $requiredParams = array('test1', 'test2'); + protected static $requiredParams = ['test1', 'test2']; } diff --git a/tests/BotApiTest.php b/tests/BotApiTest.php index ce376d6c..3d7ba9dd 100644 --- a/tests/BotApiTest.php +++ b/tests/BotApiTest.php @@ -116,7 +116,6 @@ public function testGetUpdates($updates) $mock->expects($this->once())->method('call')->willReturn($updates); - $expectedResult = ArrayOfUpdates::fromResponse($updates); $result = $mock->getUpdates(); diff --git a/tests/ChatTest.php b/tests/ChatTest.php index 1f9ce5ae..ac95f240 100644 --- a/tests/ChatTest.php +++ b/tests/ChatTest.php @@ -11,11 +11,11 @@ class ChatTest extends TestCase { public function testFromResponseGroupChat() { - $item = Chat::fromResponse(array( + $item = Chat::fromResponse([ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - )); + ]); $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item); $this->assertEquals(1, $item->getId()); @@ -99,14 +99,14 @@ public function testSetDescriptions() public function testFromResponseUser() { - $item = Chat::fromResponse(array( + $item = Chat::fromResponse([ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev', 'type' => 'private', 'bio' => 'PHP Telegram Bot API' - )); + ]); $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item); $this->assertEquals(123456, $item->getId()); @@ -136,17 +136,17 @@ public function testFromResponseException2() { $this->expectException(InvalidArgumentException::class); - $chat = Chat::fromResponse(array( + $chat = Chat::fromResponse([ 'id' => 1 - )); + ]); } public function testFromResponseException3() { $this->expectException(InvalidArgumentException::class); - $chat = Chat::fromResponse(array( + $chat = Chat::fromResponse([ 'type' => 'private' - )); + ]); } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index db170d25..18afabad 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -2,13 +2,9 @@ namespace TelegramBot\Api\Test; - use PHPUnit\Framework\TestCase; -use Symfony\Component\Yaml\Inline; use TelegramBot\Api\BadMethodCallException; -use TelegramBot\Api\BotApi; use TelegramBot\Api\Client; -use TelegramBot\Api\Events\EventCollection; use TelegramBot\Api\Types\Inline\InlineQuery; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Update; diff --git a/tests/Collection/CollectionTest.php b/tests/Collection/CollectionTest.php index 2a56970f..153e498e 100644 --- a/tests/Collection/CollectionTest.php +++ b/tests/Collection/CollectionTest.php @@ -55,7 +55,8 @@ public function can_delete_item() } /** @test */ - public function check_count() { + public function check_count() + { $media = new ArrayOfInputMedia(); for ($i = 0; $i < 5; $i++) { $media->addItem(new InputMediaPhoto('link')); @@ -64,7 +65,8 @@ public function check_count() { } /** @test */ - public function can_not_add_more_then_max_limit() { + public function can_not_add_more_then_max_limit() + { $this->expectException(ReachedMaxSizeException::class); $media = new ArrayOfInputMedia(); $media->setMaxCount(2); @@ -74,7 +76,8 @@ public function can_not_add_more_then_max_limit() { } /** @test */ - public function can_output_items_as_array() { + public function can_output_items_as_array() + { $media = new ArrayOfInputMedia(); $media->addItem(new InputMediaPhoto('link')); @@ -82,7 +85,8 @@ public function can_output_items_as_array() { } /** @test */ - public function can_output_items_as_json() { + public function can_output_items_as_json() + { $media = new ArrayOfInputMedia(); $media->addItem(new InputMediaPhoto('link')); diff --git a/tests/ContactTest.php b/tests/ContactTest.php index 34e8eb39..372032ca 100644 --- a/tests/ContactTest.php +++ b/tests/ContactTest.php @@ -44,12 +44,12 @@ public function testSetVcard() public function testFromResponse() { - $contact = Contact::fromResponse(array( + $contact = Contact::fromResponse([ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'phone_number' => '123456', 'user_id' => 'iGusev' - )); + ]); $this->assertInstanceOf('\TelegramBot\Api\Types\Contact', $contact); $this->assertEquals('123456', $contact->getPhoneNumber()); $this->assertEquals('Ilya', $contact->getFirstName()); diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php index 8b2eb0a2..c81def73 100644 --- a/tests/DocumentTest.php +++ b/tests/DocumentTest.php @@ -2,7 +2,6 @@ namespace TelegramBot\Api\Test; - use PHPUnit\Framework\TestCase; use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\Document; @@ -20,13 +19,13 @@ public function testSetFileId() public function testSetThumb() { $item = new Document(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', + $thumb = PhotoSize::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 - )); + ]); $item->setThumb($thumb); $this->assertEquals($thumb, $item->getThumb()); $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); @@ -63,27 +62,27 @@ public function testSetFileSizeException() public function testFromResponse() { - $item = Document::fromResponse(array( + $item = Document::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', 'file_size' => 3, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); - $thumb = PhotoSize::fromResponse(array( + ] + ]); + $thumb = PhotoSize::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - )); + ]); $this->assertInstanceOf(Document::class, $item); $this->assertEquals('testFileId1', $item->getFileId()); $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); @@ -101,17 +100,17 @@ public function testFromResponseException1() { $this->expectException(InvalidArgumentException::class); - $item = Document::fromResponse(array( + $item = Document::fromResponse([ 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', 'file_size' => 3, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); + ] + ]); } } diff --git a/tests/FileTest.php b/tests/FileTest.php index 1c9cb281..5a292b56 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -1,4 +1,5 @@ 'testFileId1', 'file_size' => 3, 'file_path' => 'testfilepath' - )); + ]); $this->assertInstanceOf(File::class, $item); $this->assertEquals('testFileId1', $item->getFileId()); $this->assertEquals(3, $item->getFileSize()); @@ -45,10 +46,10 @@ public function testFromResponseException() { $this->expectException(InvalidArgumentException::class); - $item = File::fromResponse(array( + $item = File::fromResponse([ 'file_size' => 3, 'file_path' => 'testfilepath' - )); + ]); } public function testSetFileSizeException() diff --git a/tests/ForceReplyTest.php b/tests/ForceReplyTest.php index a3f8db67..56944f14 100644 --- a/tests/ForceReplyTest.php +++ b/tests/ForceReplyTest.php @@ -2,7 +2,6 @@ namespace TelegramBot\Api\Test; - use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\ForceReply; @@ -62,27 +61,27 @@ public function testToJson() { $item = new ForceReply(); - $this->assertEquals(json_encode(array('force_reply' => true)), $item->toJson()); + $this->assertEquals(json_encode(['force_reply' => true]), $item->toJson()); } public function testToJson2() { $item = new ForceReply(); - $this->assertEquals(array('force_reply' => true), $item->toJson(true)); + $this->assertEquals(['force_reply' => true], $item->toJson(true)); } public function testToJson3() { $item = new ForceReply(true, true); - $this->assertEquals(json_encode(array('force_reply' => true, 'selective' => true)), $item->toJson()); + $this->assertEquals(json_encode(['force_reply' => true, 'selective' => true]), $item->toJson()); } public function testToJson4() { $item = new ForceReply(true, true); - $this->assertEquals(array('force_reply' => true, 'selective' => true), $item->toJson(true)); + $this->assertEquals(['force_reply' => true, 'selective' => true], $item->toJson(true)); } } diff --git a/tests/LocationTest.php b/tests/LocationTest.php index 3bcdadf1..4c233097 100644 --- a/tests/LocationTest.php +++ b/tests/LocationTest.php @@ -53,14 +53,14 @@ public function testSetProximityAlertRadius() public function testFromResponse() { $location = Location::fromResponse( - array( - "latitude" => 55.585827, + [ + 'latitude' => 55.585827, 'longitude' => 37.675309, 'horizontal_accuracy' => 20.5, 'live_period' => 300, 'heading' => 100, 'proximity_alert_radius' => 15 - ) + ] ); $this->assertInstanceOf(Location::class, $location); $this->assertEquals(55.585827, $location->getLatitude()); diff --git a/tests/MessageTest.php b/tests/MessageTest.php index d2a4d28f..c892b705 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -10,7 +10,6 @@ use TelegramBot\Api\Types\Location; use TelegramBot\Api\Types\Audio; use TelegramBot\Api\Types\Contact; -use TelegramBot\Api\Types\GroupChat; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\PhotoSize; use TelegramBot\Api\Types\Sticker; @@ -58,12 +57,12 @@ public function testSetForwardDate() public function testSetFrom() { $item = new Message(); - $user = User::fromResponse(array( + $user = User::fromResponse([ 'id' => 1, 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'username' => 'iGusev' - )); + ]); $item->setFrom($user); $this->assertEquals($user, $item->getFrom()); $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getFrom()); @@ -72,12 +71,12 @@ public function testSetFrom() public function testSetForwardFrom() { $item = new Message(); - $user = User::fromResponse(array( + $user = User::fromResponse([ 'id' => 1, 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'username' => 'iGusev' - )); + ]); $item->setForwardFrom($user); $this->assertEquals($user, $item->getForwardFrom()); $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getForwardFrom()); @@ -86,11 +85,11 @@ public function testSetForwardFrom() public function testSetChatGroup() { $item = new Message(); - $chat = Chat::fromResponse(array( + $chat = Chat::fromResponse([ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - )); + ]); $item->setChat($chat); $this->assertEquals($chat, $item->getChat()); $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item->getChat()); @@ -99,13 +98,13 @@ public function testSetChatGroup() public function testSetChatUser() { $item = new Message(); - $user = Chat::fromResponse(array( + $user = Chat::fromResponse([ 'id' => 1, 'type' => 'private', 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'username' => 'iGusev' - )); + ]); $item->setChat($user); $this->assertEquals($user, $item->getChat()); $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item->getChat()); @@ -114,12 +113,12 @@ public function testSetChatUser() public function testSetContact() { $item = new Message(); - $contact = Contact::fromResponse(array( + $contact = Contact::fromResponse([ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'phone_number' => '123456', 'user_id' => 'iGusev' - )); + ]); $item->setContact($contact); $this->assertEquals($contact, $item->getContact()); $this->assertInstanceOf('\TelegramBot\Api\Types\Contact', $item->getContact()); @@ -128,20 +127,20 @@ public function testSetContact() public function testSetDocument() { $item = new Message(); - $document = Document::fromResponse(array( + $document = Document::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', 'file_size' => 3, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); + ] + ]); $item->setDocument($document); $this->assertEquals($document, $item->getDocument()); $this->assertInstanceOf('\TelegramBot\Api\Types\Document', $item->getDocument()); @@ -150,7 +149,7 @@ public function testSetDocument() public function testSetLocation() { $item = new Message(); - $location = Location::fromResponse(array('latitude' => 55.585827, 'longitude' => 37.675309)); + $location = Location::fromResponse(['latitude' => 55.585827, 'longitude' => 37.675309]); $item->setLocation($location); $this->assertEquals($location, $item->getLocation()); $this->assertInstanceOf('\TelegramBot\Api\Types\Location', $item->getLocation()); @@ -159,13 +158,13 @@ public function testSetLocation() public function testSetAudio() { $item = new Message(); - $audio = Audio::fromResponse(array( + $audio = Audio::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); $item->setAudio($audio); $this->assertEquals($audio, $item->getAudio()); $this->assertInstanceOf('\TelegramBot\Api\Types\Audio', $item->getAudio()); @@ -174,13 +173,13 @@ public function testSetAudio() public function testSetVoice() { $item = new Message(); - $voice = Voice::fromResponse(array( + $voice = Voice::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testUniqueFileId', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); $item->setVoice($voice); $this->assertEquals($voice, $item->getVoice()); $this->assertInstanceOf('\TelegramBot\Api\Types\Voice', $item->getVoice()); @@ -189,7 +188,7 @@ public function testSetVoice() public function testSetVideo() { $item = new Message(); - $video = Video::fromResponse(array( + $video = Video::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testUniqueFileId', 'width' => 1, @@ -197,14 +196,14 @@ public function testSetVideo() 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); + ] + ]); $item->setVideo($video); $this->assertEquals($video, $item->getVideo()); $this->assertInstanceOf('\TelegramBot\Api\Types\Video', $item->getVideo()); @@ -213,10 +212,10 @@ public function testSetVideo() public function testSetDice() { $item = new Message(); - $dice = Dice::fromResponse(array( + $dice = Dice::fromResponse([ 'emoji' => '🎲', 'value' => 3 - )); + ]); $item->setDice($dice); $this->assertEquals($dice, $item->getDice()); $this->assertInstanceOf('\TelegramBot\Api\Types\Dice', $item->getDice()); @@ -225,8 +224,8 @@ public function testSetDice() public function testSetSticker() { $item = new Message(); - $sticker = Sticker::fromResponse(array( - "file_id" => 'testFileId1', + $sticker = Sticker::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testUniqueFileId', 'width' => 1, 'height' => 2, @@ -234,14 +233,14 @@ public function testSetSticker() 'is_animated' => false, 'is_video' => false, 'type' => 'regular', - 'thumb' => array( - "file_id" => 'testFileId1', + 'thumb' => [ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testUniqueFileId', 'width' => 1, 'height' => 2, 'file_size' => 3 - ) - )); + ] + ]); $item->setSticker($sticker); $this->assertEquals($sticker, $item->getSticker()); $this->assertInstanceOf('\TelegramBot\Api\Types\Sticker', $item->getSticker()); @@ -266,12 +265,12 @@ public function testSetDeleteChatPhoto() public function testSetLeftChatParticipant() { $item = new Message(); - $user = User::fromResponse(array( + $user = User::fromResponse([ 'id' => 1, 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'username' => 'iGusev' - )); + ]); $item->setLeftChatMember($user); $this->assertEquals($user, $item->getLeftChatMember()); @@ -281,12 +280,12 @@ public function testSetLeftChatParticipant() public function testSetNewChatParticipant() { $item = new Message(); - $user = User::fromResponse(array( + $user = User::fromResponse([ 'id' => 1, 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'username' => 'iGusev' - )); + ]); $item->setNewChatMembers([$user]); $this->assertEquals([$user], $item->getNewChatMembers()); @@ -312,21 +311,21 @@ public function testSetText() public function testSetReplyToMessage() { $item = new Message(); - $replyMessage = Message::fromResponse(array( + $replyMessage = Message::fromResponse([ 'message_id' => 1, - 'from' => array( + 'from' => [ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - ), + ], 'date' => 2, - 'chat' => array( + 'chat' => [ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - ) - )); + ] + ]); $item->setReplyToMessage($replyMessage); $this->assertEquals($replyMessage, $item->getReplyToMessage()); @@ -336,13 +335,13 @@ public function testSetReplyToMessage() public function testSetViaBot() { $item = new Message(); - $bot = User::fromResponse(array( + $bot = User::fromResponse([ 'first_name' => 'Test', 'last_name' => 'Bot', 'username' => 'TestingBot', 'is_bot' => 'true', 'id' => 654321 - )); + ]); $item->setViaBot($bot); $this->assertEquals($bot, $item->getViaBot()); $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getViaBot()); @@ -350,43 +349,43 @@ public function testSetViaBot() public function testViaBotMessage() { - $item = Message::fromResponse(array( + $item = Message::fromResponse([ 'message_id' => 1, - 'from' => array( + 'from' => [ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - ), + ], 'date' => 2, - 'chat' => array( + 'chat' => [ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - ), - 'via_bot' => array( + ], + 'via_bot' => [ 'first_name' => 'Test', 'last_name' => 'Bot', 'username' => 'TestingBot', 'is_bot' => 'true', 'id' => 654321 - ) - )); + ] + ]); $this->assertEquals(654321, $item->getViaBot()->getId()); } public function testSetPhoto() { $item = new Message(); - $photo = array( - PhotoSize::fromResponse(array( + $photo = [ + PhotoSize::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - )) - ); + ]) + ]; $item->setPhoto($photo); @@ -400,15 +399,15 @@ public function testSetPhoto() public function testGetNewChatPhoto() { $item = new Message(); - $photo = array( - PhotoSize::fromResponse(array( + $photo = [ + PhotoSize::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - )) - ); + ]) + ]; $item->setNewChatPhoto($photo); $this->assertEquals($photo, $item->getNewChatPhoto()); @@ -452,22 +451,22 @@ public function testSetSupergroupChatCreated() public function testIsSupergroupChatCreated() { - $item = Message::fromResponse(array( + $item = Message::fromResponse([ 'message_id' => 1, - 'from' => array( + 'from' => [ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - ), + ], 'date' => 2, - 'chat' => array( + 'chat' => [ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - ), + ], 'supergroup_chat_created' => true - )); + ]); $this->assertTrue($item->isSupergroupChatCreated()); } @@ -482,22 +481,22 @@ public function testSetChannelChatCreated() public function testIsChannelChatCreated() { - $item = Message::fromResponse(array( + $item = Message::fromResponse([ 'message_id' => 1, - 'from' => array( + 'from' => [ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - ), + ], 'date' => 2, - 'chat' => array( + 'chat' => [ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - ), + ], 'channel_chat_created' => true - )); + ]); $this->assertTrue($item->isChannelChatCreated()); } @@ -511,22 +510,22 @@ public function testSetMigrateToChatId() public function testGetMigrateToChatId() { - $item = Message::fromResponse(array( + $item = Message::fromResponse([ 'message_id' => 1, - 'from' => array( + 'from' => [ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - ), + ], 'date' => 2, - 'chat' => array( + 'chat' => [ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - ), + ], 'migrate_to_chat_id' => 2 - )); + ]); $this->assertEquals(2, $item->getMigrateToChatId()); } @@ -540,44 +539,44 @@ public function testSetMigrateFromChatId() public function testGetMigrateFromChatId() { - $item = Message::fromResponse(array( + $item = Message::fromResponse([ 'message_id' => 1, - 'from' => array( + 'from' => [ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - ), + ], 'date' => 2, - 'chat' => array( + 'chat' => [ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - ), + ], 'migrate_from_chat_id' => 3 - )); + ]); $this->assertEquals(3, $item->getMigrateFromChatId()); } public function testToJson1() { - $data = array( + $data = [ 'message_id' => 1, - 'from' => array( + 'from' => [ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - ), + ], 'date' => 2, - 'chat' => array( + 'chat' => [ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - ), + ], 'migrate_from_chat_id' => 3 - ); + ]; $item = Message::fromResponse($data); $this->assertJson(json_encode($data), $item->toJson()); @@ -585,29 +584,29 @@ public function testToJson1() public function testToJson2() { - $data = array( + $data = [ 'message_id' => 1, - 'from' => array( + 'from' => [ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - ), + ], 'date' => 2, - 'chat' => array( + 'chat' => [ 'id' => 1, 'type' => 'group', 'title' => 'test chat' - ), - 'entities' => array( - array( - "type" => "bot_command", - "offset" => 0, - "length" => 7, - ) - ), + ], + 'entities' => [ + [ + 'type' => 'bot_command', + 'offset' => 0, + 'length' => 7, + ] + ], 'migrate_from_chat_id' => 3 - ); + ]; $item = Message::fromResponse($data); $this->assertJson(json_encode($data), $item->toJson()); diff --git a/tests/PhotoSizeTest.php b/tests/PhotoSizeTest.php index dcc62bcd..827bc40d 100644 --- a/tests/PhotoSizeTest.php +++ b/tests/PhotoSizeTest.php @@ -38,13 +38,13 @@ public function testSetFileSize() public function testFromResponse() { - $photoSize = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', + $photoSize = PhotoSize::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 - )); + ]); $this->assertInstanceOf(PhotoSize::class, $photoSize); $this->assertEquals('testFileId1', $photoSize->getFileId()); $this->assertEquals('testFileUniqueId1', $photoSize->getFileUniqueId()); diff --git a/tests/PollAnswerTest.php b/tests/PollAnswerTest.php index 601aabc7..a03140c5 100644 --- a/tests/PollAnswerTest.php +++ b/tests/PollAnswerTest.php @@ -42,5 +42,4 @@ public function testGetOptionIds() $this->assertEquals([1,2,3,4,5,6], $item->getOptionIds()); } - } diff --git a/tests/ReplyKeyboardHideTest.php b/tests/ReplyKeyboardHideTest.php index af9b6155..89d0263e 100644 --- a/tests/ReplyKeyboardHideTest.php +++ b/tests/ReplyKeyboardHideTest.php @@ -61,27 +61,27 @@ public function testToJson() { $item = new ReplyKeyboardHide(); - $this->assertEquals(json_encode(array('hide_keyboard' => true)), $item->toJson()); + $this->assertEquals(json_encode(['hide_keyboard' => true]), $item->toJson()); } public function testToJson2() { $item = new ReplyKeyboardHide(); - $this->assertEquals(array('hide_keyboard' => true), $item->toJson(true)); + $this->assertEquals(['hide_keyboard' => true], $item->toJson(true)); } public function testToJson3() { $item = new ReplyKeyboardHide(true, true); - $this->assertEquals(json_encode(array('hide_keyboard' => true, 'selective' => true)), $item->toJson()); + $this->assertEquals(json_encode(['hide_keyboard' => true, 'selective' => true]), $item->toJson()); } public function testToJson4() { $item = new ReplyKeyboardHide(true, true); - $this->assertEquals(array('hide_keyboard' => true, 'selective' => true), $item->toJson(true)); + $this->assertEquals(['hide_keyboard' => true, 'selective' => true], $item->toJson(true)); } } diff --git a/tests/ReplyKeyboardMarkupTest.php b/tests/ReplyKeyboardMarkupTest.php index d0dd1d7a..0305895e 100644 --- a/tests/ReplyKeyboardMarkupTest.php +++ b/tests/ReplyKeyboardMarkupTest.php @@ -9,9 +9,9 @@ class ReplyKeyboardMarkupTest extends TestCase { public function testConstructor() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); + $item = new ReplyKeyboardMarkup([['one', 'two']]); - $this->assertEquals(array(array('one', 'two')), $item->getKeyboard()); + $this->assertEquals([['one', 'two']], $item->getKeyboard()); $this->assertEquals(null, $item->isOneTimeKeyboard()); $this->assertEquals(null, $item->isResizeKeyboard()); $this->assertEquals(null, $item->isSelective()); @@ -19,9 +19,9 @@ public function testConstructor() public function testConstructor2() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true); + $item = new ReplyKeyboardMarkup([['one', 'two']], true); - $this->assertEquals(array(array('one', 'two')), $item->getKeyboard()); + $this->assertEquals([['one', 'two']], $item->getKeyboard()); $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(null, $item->isResizeKeyboard()); $this->assertEquals(null, $item->isSelective()); @@ -29,9 +29,9 @@ public function testConstructor2() public function testConstructor3() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true); + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true); - $this->assertEquals(array(array('one', 'two')), $item->getKeyboard()); + $this->assertEquals([['one', 'two']], $item->getKeyboard()); $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(null, $item->isSelective()); @@ -39,9 +39,9 @@ public function testConstructor3() public function testConstructor4() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true, true); + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true); - $this->assertEquals(array(array('one', 'two')), $item->getKeyboard()); + $this->assertEquals([['one', 'two']], $item->getKeyboard()); $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(true, $item->isSelective()); @@ -49,15 +49,15 @@ public function testConstructor4() public function testSetKeyboard() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setKeyboard(array(array('one', 'two', 'three'))); + $item = new ReplyKeyboardMarkup([['one', 'two']]); + $item->setKeyboard([['one', 'two', 'three']]); - $this->assertEquals(array(array('one', 'two', 'three')), $item->getKeyboard()); + $this->assertEquals([['one', 'two', 'three']], $item->getKeyboard()); } public function testSetSelective() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); + $item = new ReplyKeyboardMarkup([['one', 'two']]); $item->setSelective(true); $this->assertEquals(true, $item->isSelective()); @@ -65,7 +65,7 @@ public function testSetSelective() public function testSetOneTimeKeyboard() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); + $item = new ReplyKeyboardMarkup([['one', 'two']]); $item->setOneTimeKeyboard(false); $this->assertEquals(false, $item->isOneTimeKeyboard()); @@ -73,7 +73,7 @@ public function testSetOneTimeKeyboard() public function testSetResizeKeyboard() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); + $item = new ReplyKeyboardMarkup([['one', 'two']]); $item->setResizeKeyboard(true); $this->assertEquals(true, $item->isResizeKeyboard()); @@ -81,42 +81,46 @@ public function testSetResizeKeyboard() public function testToJson() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); + $item = new ReplyKeyboardMarkup([['one', 'two']]); - $this->assertEquals(json_encode(array('keyboard' => array(array('one', 'two')))), $item->toJson()); + $this->assertEquals(json_encode(['keyboard' => [['one', 'two']]]), $item->toJson()); } public function testToJson2() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true, true); + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true); - $this->assertEquals(json_encode(array( - 'keyboard' => array(array('one', 'two')), + $this->assertEquals( + json_encode([ + 'keyboard' => [['one', 'two']], 'one_time_keyboard' => true, 'resize_keyboard' => true, 'selective' => true, - )), - $item->toJson()); + ]), + $item->toJson() + ); } public function testToJson3() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); + $item = new ReplyKeyboardMarkup([['one', 'two']]); - $this->assertEquals(array('keyboard' => array(array('one', 'two'))), $item->toJson(true)); + $this->assertEquals(['keyboard' => [['one', 'two']]], $item->toJson(true)); } public function testToJson4() { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true, true); + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true); - $this->assertEquals(array( - 'keyboard' => array(array('one', 'two')), + $this->assertEquals( + [ + 'keyboard' => [['one', 'two']], 'one_time_keyboard' => true, 'resize_keyboard' => true, 'selective' => true, - ), - $item->toJson(true)); + ], + $item->toJson(true) + ); } } diff --git a/tests/StickerTest.php b/tests/StickerTest.php index 961af1ab..178e7a35 100644 --- a/tests/StickerTest.php +++ b/tests/StickerTest.php @@ -40,13 +40,13 @@ public function testSetFileSize() public function testSetThumb() { $sticker = new Sticker(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', + $thumb = PhotoSize::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 - )); + ]); $sticker->setThumb($thumb); $this->assertEquals($thumb, $sticker->getThumb()); $this->assertInstanceOf(PhotoSize::class, $sticker->getThumb()); @@ -54,8 +54,8 @@ public function testSetThumb() public function testFromResponse() { - $sticker = Sticker::fromResponse(array( - "file_id" => 'testFileId1', + $sticker = Sticker::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, @@ -63,21 +63,21 @@ public function testFromResponse() 'is_animated' => false, 'is_video' => false, 'type' => 'regular', - 'thumb' => array( - "file_id" => 'testFileId1', + 'thumb' => [ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 - ) - )); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', + ] + ]); + $thumb = PhotoSize::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 - )); + ]); $this->assertInstanceOf(Sticker::class, $sticker); $this->assertEquals('testFileId1', $sticker->getFileId()); $this->assertEquals('testFileUniqueId1', $sticker->getFileUniqueId()); diff --git a/tests/Types/ArrayOfUpdatesTest.php b/tests/Types/ArrayOfUpdatesTest.php index 3ae5aeed..32b84252 100644 --- a/tests/Types/ArrayOfUpdatesTest.php +++ b/tests/Types/ArrayOfUpdatesTest.php @@ -7,7 +7,6 @@ class ArrayOfUpdatesTest extends TestCase { - public function data() { return [ diff --git a/tests/Types/CallbackQueryTest.php b/tests/Types/CallbackQueryTest.php index 5403fa57..0575237c 100644 --- a/tests/Types/CallbackQueryTest.php +++ b/tests/Types/CallbackQueryTest.php @@ -5,7 +5,6 @@ use PHPUnit\Framework\TestCase; use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\CallbackQuery; -use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\User; class CallbackQueryTest extends TestCase @@ -62,32 +61,37 @@ public function testSetId() $this->assertEquals($this->callbackQueryFixture['id'], $item->getId()); } - public function testSetFrom() { + public function testSetFrom() + { $item = new CallbackQuery(); $user = User::fromResponse($this->callbackQueryFixture['from']); $item->setFrom($user); $this->assertEquals($user, $item->getFrom()); } - public function testSetInlineMessageId() { + public function testSetInlineMessageId() + { $item = new CallbackQuery(); $item->setInlineMessageId('testInlineMessageId'); $this->assertEquals('testInlineMessageId', $item->getInlineMessageId()); } - public function testSetChatInstance() { + public function testSetChatInstance() + { $item = new CallbackQuery(); $item->setChatInstance('testChatInstance'); $this->assertEquals('testChatInstance', $item->getChatInstance()); } - public function testSetData() { + public function testSetData() + { $item = new CallbackQuery(); $item->setData('testData'); $this->assertEquals('testData', $item->getData()); } - public function testSetGameShortName() { + public function testSetGameShortName() + { $item = new CallbackQuery(); $item->setGameShortName('testGameShortName'); $this->assertEquals('testGameShortName', $item->getGameShortName()); diff --git a/tests/Types/Events/EventCollectionTest.php b/tests/Types/Events/EventCollectionTest.php index f7475999..fbdac7a9 100644 --- a/tests/Types/Events/EventCollectionTest.php +++ b/tests/Types/Events/EventCollectionTest.php @@ -3,7 +3,6 @@ namespace TelegramBot\Api\Test\Types\Events; use PHPUnit\Framework\TestCase; -use TelegramBot\Api\Client; use TelegramBot\Api\Events\EventCollection; use TelegramBot\Api\Types\Update; @@ -98,7 +97,8 @@ public function testAdd2($action) * * @dataProvider data */ - public function testHandle1($action, $checker, $update) { + public function testHandle1($action, $checker, $update) + { $item = new EventCollection('testToken'); $name = 'test'; $item->add($action, function ($update) use ($name) { @@ -129,7 +129,8 @@ public function testHandle1($action, $checker, $update) { * * @dataProvider data */ - public function testHandle2($action, $checker, $update) { + public function testHandle2($action, $checker, $update) + { $item = new EventCollection(); $name = 'test'; $item->add($action, function ($update) use ($name) { diff --git a/tests/Types/Events/EventTest.php b/tests/Types/Events/EventTest.php index 66d431e4..cf57f5cb 100644 --- a/tests/Types/Events/EventTest.php +++ b/tests/Types/Events/EventTest.php @@ -109,7 +109,8 @@ public function testExecuteAction($action, $checker, $update) * * @dataProvider data */ - public function testExecuteActionFalse($action, $checker, $update) { + public function testExecuteActionFalse($action, $checker, $update) + { $item = new Event($action, $checker); $reflection = new \ReflectionClass($item); @@ -145,7 +146,8 @@ public function testExecuteCheker($action, $checker, $update) * * @dataProvider data */ - public function testExecuteCheckerFalse($action, $checker, $update) { + public function testExecuteCheckerFalse($action, $checker, $update) + { $item = new Event($action, $checker); $reflection = new \ReflectionClass($item); diff --git a/tests/Types/Inline/InlineKeyboardMarkupTest.php b/tests/Types/Inline/InlineKeyboardMarkupTest.php index 4e10af3c..b2a1f6fe 100644 --- a/tests/Types/Inline/InlineKeyboardMarkupTest.php +++ b/tests/Types/Inline/InlineKeyboardMarkupTest.php @@ -7,7 +7,6 @@ class InlineKeyboardMarkupTest extends TestCase { - public function testConstructor() { $item = new InlineKeyboardMarkup([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]]); diff --git a/tests/Types/Inline/InlineQueryTest.php b/tests/Types/Inline/InlineQueryTest.php index ecef4ac1..dc94e7c5 100644 --- a/tests/Types/Inline/InlineQueryTest.php +++ b/tests/Types/Inline/InlineQueryTest.php @@ -33,8 +33,8 @@ public function testFromResponse1() $this->assertEquals('20', $item->getOffset()); } - - public function testFromResponse2() { + public function testFromResponse2() + { $this->inlineQueryFixture['offset'] = ''; $item = InlineQuery::fromResponse($this->inlineQueryFixture); diff --git a/tests/UserProfilePhotosTest.php b/tests/UserProfilePhotosTest.php index af657919..ccab9878 100644 --- a/tests/UserProfilePhotosTest.php +++ b/tests/UserProfilePhotosTest.php @@ -2,7 +2,6 @@ namespace TelegramBot\Api\Test; - use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\Types\PhotoSize; use TelegramBot\Api\Types\UserProfilePhotos; @@ -20,15 +19,15 @@ public function testSetTotalCount() public function testSetPhotos() { $userProfilePhotos = new UserProfilePhotos(); - $photos = array(); + $photos = []; for ($i = 0; $i < 10; $i++) { - $photos[] = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', + $photos[] = PhotoSize::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => $i, 'height' => $i * 2, 'file_size' => $i * 3 - )); + ]); } $userProfilePhotos->setPhotos($photos); @@ -37,31 +36,31 @@ public function testSetPhotos() public function testFromResponse() { - $userProfilePhotos = UserProfilePhotos::fromResponse(array( - "total_count" => 1, - 'photos' => array( - array( - array( - "file_id" => 'testFileId1', + $userProfilePhotos = UserProfilePhotos::fromResponse([ + 'total_count' => 1, + 'photos' => [ + [ + [ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 - ) - ) - ) - )); - $photos = array( - array( - PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', + ] + ] + ] + ]); + $photos = [ + [ + PhotoSize::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 - )) - ) - ); + ]) + ] + ]; $this->assertInstanceOf(UserProfilePhotos::class, $userProfilePhotos); $this->assertEquals(1, $userProfilePhotos->getTotalCount()); $this->assertEquals($photos, $userProfilePhotos->getPhotos()); diff --git a/tests/UserTest.php b/tests/UserTest.php index e9f2a77c..31239591 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -53,7 +53,7 @@ public function testSetIdException() public function testFromResponse() { - $user = User::fromResponse(array( + $user = User::fromResponse([ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'id' => 123456, @@ -64,7 +64,7 @@ public function testFromResponse() 'can_join_groups' => true, 'can_read_all_group_messages' => true, 'supports_inline_queries' => false, - )); + ]); $this->assertInstanceOf('\TelegramBot\Api\Types\User', $user); $this->assertEquals(123456, $user->getId()); $this->assertEquals('Ilya', $user->getFirstName()); @@ -82,22 +82,22 @@ public function testFromResponseException1() { $this->expectException(InvalidArgumentException::class); - $user = User::fromResponse(array( + $user = User::fromResponse([ 'last_name' => 'Gusev', 'id' => 123456, 'username' => 'iGusev' - )); + ]); } public function testFromResponseException2() { $this->expectException(InvalidArgumentException::class); - $user = User::fromResponse(array( + $user = User::fromResponse([ 'first_name' => 'Ilya', 'last_name' => 'Gusev', 'username' => 'iGusev' - )); + ]); } } diff --git a/tests/VideoTest.php b/tests/VideoTest.php index acbc2852..e118845e 100644 --- a/tests/VideoTest.php +++ b/tests/VideoTest.php @@ -40,13 +40,13 @@ public function testSetMimeType() public function testSetThumb() { $item = new Video(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', + $thumb = PhotoSize::fromResponse([ + 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'file_size' => 3 - )); + ]); $item->setThumb($thumb); $this->assertEquals($thumb, $item->getThumb()); $this->assertInstanceOf(PhotoSize::class, $item->getThumb()); @@ -68,7 +68,7 @@ public function testSetHeight() public function testFromResponse() { - $item = Video::fromResponse(array( + $item = Video::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, @@ -76,21 +76,21 @@ public function testFromResponse() 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); - $thumb = PhotoSize::fromResponse(array( + ] + ]); + $thumb = PhotoSize::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - )); + ]); $this->assertInstanceOf(Video::class, $item); $this->assertEquals('testFileId1', $item->getFileId()); $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); @@ -142,20 +142,20 @@ public function testFromResponseException1() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse(array( + $item = Video::fromResponse([ 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); + ] + ]); } /** * width is required @@ -164,21 +164,21 @@ public function testFromResponseException2() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse(array( + $item = Video::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'height' => 2, 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); + ] + ]); } /** @@ -188,21 +188,21 @@ public function testFromResponseException3() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse(array( + $item = Video::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); + ] + ]); } /** @@ -212,21 +212,21 @@ public function testFromResponseException4() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse(array( + $item = Video::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); + ] + ]); } /** @@ -236,20 +236,20 @@ public function testFromResponseException5() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse(array( + $item = Video::fromResponse([ 'file_id' => 'testFileId1', 'width' => 1, 'height' => 2, 'duration' => 1, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => array( + 'thumb' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - )); + ] + ]); } } diff --git a/tests/VoiceTest.php b/tests/VoiceTest.php index ba8e8ea9..0ce7037f 100644 --- a/tests/VoiceTest.php +++ b/tests/VoiceTest.php @@ -1,4 +1,5 @@ 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); $this->assertInstanceOf(Voice::class, $item); $this->assertEquals('testFileId1', $item->getFileId()); $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); @@ -59,30 +60,28 @@ public function testFromResponse() $this->assertEquals(3, $item->getFileSize()); } - public function testFromResponseException() { $this->expectException(InvalidArgumentException::class); - $item = Voice::fromResponse(array( + $item = Voice::fromResponse([ 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); } public function testFromResponseException2() { $this->expectException(InvalidArgumentException::class); - $item = Voice::fromResponse(array( + $item = Voice::fromResponse([ 'file_id' => 'testFileId1', 'mime_type' => 'audio/mp3', 'file_size' => 3 - )); + ]); } - public function testSetDurationException() { $this->expectException(InvalidArgumentException::class); diff --git a/tests/WebhookInfoTest.php b/tests/WebhookInfoTest.php index 9eca6fd8..e79b8188 100644 --- a/tests/WebhookInfoTest.php +++ b/tests/WebhookInfoTest.php @@ -14,7 +14,7 @@ class WebhookInfoTest extends TestCase { public function testFromResponse() { - $webhookInfo = WebhookInfo::fromResponse(array( + $webhookInfo = WebhookInfo::fromResponse([ 'url' => '', 'has_custom_certificate' => false, 'pending_update_count' => 0, @@ -24,7 +24,7 @@ public function testFromResponse() 'last_synchronization_error_date' => null, 'max_connections' => 40, 'allowed_updates' => null - )); + ]); $this->assertInstanceOf('\TelegramBot\Api\Types\WebhookInfo', $webhookInfo); $this->assertEquals('', $webhookInfo->getUrl()); $this->assertEquals(false, $webhookInfo->hasCustomCertificate()); From b5391b0ad0e3f74ed509403f63f3c456ee162246 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 25 Apr 2023 17:56:06 +0300 Subject: [PATCH 090/130] Silence scrutinizer false checks --- .scrutinizer.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d0f703c8..208e42ea 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -17,6 +17,10 @@ checks: fix_identation_4spaces: true fix_doc_comments: true build: + dependencies: + before: + - composer remove friendsofphp/php-cs-fixer --dev --no-update + tests: override: - true From 564ef23e6e4564753dfcfa9de04daf433f82119a Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 25 Apr 2023 16:22:15 +0300 Subject: [PATCH 091/130] Add tests Simplify existing one Fix found issues Add deprecations --- CHANGELOG.md | 20 +- composer.json | 1 + phpunit.xml.dist | 3 + src/BotApi.php | 1 + src/Botan.php | 3 + src/Client.php | 3 + src/Collection/Collection.php | 2 +- src/Events/EventCollection.php | 1 + src/Types/Payments/ShippingAddress.php | 12 +- src/Types/PollAnswer.php | 12 +- src/Types/ReplyKeyboardMarkup.php | 2 +- src/Types/ReplyKeyboardRemove.php | 10 +- src/Types/Sticker.php | 10 +- src/Types/StickerSet.php | 4 +- src/Types/Venue.php | 72 ++ tests/AbstractTypeTest.php | 74 +++ tests/BotCommandTest.php | 37 -- tests/ChatLocationTest.php | 46 -- tests/ChatTest.php | 152 ----- tests/ClientTest.php | 21 +- tests/Collection/CollectionTest.php | 50 +- tests/ContactTest.php | 59 -- tests/DocumentTest.php | 116 ---- .../Events/EventCollectionTest.php | 14 +- tests/{Types => }/Events/EventTest.php | 4 +- tests/FileTest.php | 63 -- tests/LocationTest.php | 98 --- tests/LoginUrlTest.php | 57 -- tests/MessageTest.php | 614 ------------------ tests/PhotoSizeTest.php | 79 --- tests/PollAnswerTest.php | 45 -- tests/PollTest.php | 93 --- tests/ReplyKeyboardHideTest.php | 87 --- tests/StickerTest.php | 113 ---- tests/Types/AnimationTest.php | 107 +++ tests/Types/ArrayOfBotCommandTest.php | 31 + tests/Types/ArrayOfChatMemberEntityTest.php | 37 ++ tests/Types/ArrayOfMessageEntityTest.php | 33 + tests/Types/ArrayOfMessagesTest.php | 39 ++ tests/{ => Types}/ArrayOfPhotoSizeTest.php | 4 +- tests/Types/ArrayOfPollOptionTest.php | 31 + tests/Types/ArrayOfStickerTest.php | 41 ++ tests/Types/ArrayOfUpdatesTest.php | 3 +- tests/Types/ArrayOfUserTest.php | 31 + tests/{ => Types}/AudioTest.php | 86 ++- tests/Types/BotCommandTest.php | 46 ++ tests/Types/CallbackQueryTest.php | 121 ++-- tests/Types/ChatLocationTest.php | 46 ++ tests/Types/ChatMemberTest.php | 105 +++ tests/Types/ChatPermissionsTest.php | 65 ++ tests/Types/ChatPhotoTest.php | 46 ++ tests/Types/ChatTest.php | 167 +++++ tests/Types/ContactTest.php | 59 ++ tests/Types/DiceTest.php | 46 ++ tests/Types/DocumentTest.php | 92 +++ tests/Types/FileTest.php | 75 +++ tests/{ => Types}/ForceReplyTest.php | 48 +- tests/Types/ForumTopicClosedTest.php | 40 ++ tests/Types/ForumTopicCreatedTest.php | 53 ++ tests/Types/ForumTopicReopenedTest.php | 40 ++ tests/Types/ForumTopicTest.php | 57 ++ tests/Types/Inline/ChosenInlineResultTest.php | 98 ++- .../Types/Inline/InlineKeyboardMarkupTest.php | 44 +- tests/Types/Inline/InlineQueryTest.php | 126 ++-- tests/Types/LocationTest.php | 88 +++ tests/Types/LoginUrlTest.php | 55 ++ tests/Types/MaskPositionTest.php | 50 ++ tests/Types/MessageEntityTest.php | 81 ++- tests/Types/MessageTest.php | 307 +++++++++ tests/Types/Payments/InvoiceTest.php | 52 ++ tests/Types/Payments/OrderInfoTest.php | 53 ++ .../Payments/Query/PreCheckoutQueryTest.php | 70 ++ .../Payments/Query/ShippingQueryTest.php | 52 ++ tests/Types/Payments/ShippingAddressTest.php | 54 ++ .../Types/Payments/SuccessfulPaymentTest.php | 68 ++ tests/Types/PhotoSizeTest.php | 86 +++ tests/Types/PollAnswerTest.php | 49 ++ tests/Types/PollOptionTest.php | 46 ++ tests/Types/PollTest.php | 81 +++ tests/Types/ReplyKeyboardHideTest.php | 81 +++ tests/{ => Types}/ReplyKeyboardMarkupTest.php | 129 ++-- tests/Types/ReplyKeyboardRemoveTest.php | 65 ++ tests/Types/StickerSetTest.php | 73 +++ tests/Types/StickerTest.php | 109 ++++ tests/Types/UpdateTest.php | 83 +++ tests/Types/UserProfilePhotosTest.php | 59 ++ tests/Types/UserTest.php | 117 ++++ tests/Types/VenueTest.php | 66 ++ tests/Types/VideoNoteTest.php | 64 ++ tests/{ => Types}/VideoTest.php | 119 ++-- tests/{ => Types}/VoiceTest.php | 73 +-- tests/Types/WebhookInfoTest.php | 63 ++ tests/UserProfilePhotosTest.php | 82 --- tests/UserTest.php | 103 --- tests/WebhookInfoTest.php | 39 -- 95 files changed, 3854 insertions(+), 2458 deletions(-) create mode 100644 tests/AbstractTypeTest.php delete mode 100644 tests/BotCommandTest.php delete mode 100644 tests/ChatLocationTest.php delete mode 100644 tests/ChatTest.php delete mode 100644 tests/ContactTest.php delete mode 100644 tests/DocumentTest.php rename tests/{Types => }/Events/EventCollectionTest.php (91%) rename tests/{Types => }/Events/EventTest.php (97%) delete mode 100644 tests/FileTest.php delete mode 100644 tests/LocationTest.php delete mode 100644 tests/LoginUrlTest.php delete mode 100644 tests/MessageTest.php delete mode 100644 tests/PhotoSizeTest.php delete mode 100644 tests/PollAnswerTest.php delete mode 100644 tests/PollTest.php delete mode 100644 tests/ReplyKeyboardHideTest.php delete mode 100644 tests/StickerTest.php create mode 100644 tests/Types/AnimationTest.php create mode 100644 tests/Types/ArrayOfBotCommandTest.php create mode 100644 tests/Types/ArrayOfChatMemberEntityTest.php create mode 100644 tests/Types/ArrayOfMessageEntityTest.php create mode 100644 tests/Types/ArrayOfMessagesTest.php rename tests/{ => Types}/ArrayOfPhotoSizeTest.php (96%) create mode 100644 tests/Types/ArrayOfPollOptionTest.php create mode 100644 tests/Types/ArrayOfStickerTest.php create mode 100644 tests/Types/ArrayOfUserTest.php rename tests/{ => Types}/AudioTest.php (64%) create mode 100644 tests/Types/BotCommandTest.php create mode 100644 tests/Types/ChatLocationTest.php create mode 100644 tests/Types/ChatMemberTest.php create mode 100644 tests/Types/ChatPermissionsTest.php create mode 100644 tests/Types/ChatPhotoTest.php create mode 100644 tests/Types/ChatTest.php create mode 100644 tests/Types/ContactTest.php create mode 100644 tests/Types/DiceTest.php create mode 100644 tests/Types/DocumentTest.php create mode 100644 tests/Types/FileTest.php rename tests/{ => Types}/ForceReplyTest.php (65%) create mode 100644 tests/Types/ForumTopicClosedTest.php create mode 100644 tests/Types/ForumTopicCreatedTest.php create mode 100644 tests/Types/ForumTopicReopenedTest.php create mode 100644 tests/Types/ForumTopicTest.php create mode 100644 tests/Types/LocationTest.php create mode 100644 tests/Types/LoginUrlTest.php create mode 100644 tests/Types/MaskPositionTest.php create mode 100644 tests/Types/MessageTest.php create mode 100644 tests/Types/Payments/InvoiceTest.php create mode 100644 tests/Types/Payments/OrderInfoTest.php create mode 100644 tests/Types/Payments/Query/PreCheckoutQueryTest.php create mode 100644 tests/Types/Payments/Query/ShippingQueryTest.php create mode 100644 tests/Types/Payments/ShippingAddressTest.php create mode 100644 tests/Types/Payments/SuccessfulPaymentTest.php create mode 100644 tests/Types/PhotoSizeTest.php create mode 100644 tests/Types/PollAnswerTest.php create mode 100644 tests/Types/PollOptionTest.php create mode 100644 tests/Types/PollTest.php create mode 100644 tests/Types/ReplyKeyboardHideTest.php rename tests/{ => Types}/ReplyKeyboardMarkupTest.php (51%) create mode 100644 tests/Types/ReplyKeyboardRemoveTest.php create mode 100644 tests/Types/StickerSetTest.php create mode 100644 tests/Types/StickerTest.php create mode 100644 tests/Types/UpdateTest.php create mode 100644 tests/Types/UserProfilePhotosTest.php create mode 100644 tests/Types/UserTest.php create mode 100644 tests/Types/VenueTest.php create mode 100644 tests/Types/VideoNoteTest.php rename tests/{ => Types}/VideoTest.php (67%) rename tests/{ => Types}/VoiceTest.php (58%) create mode 100644 tests/Types/WebhookInfoTest.php delete mode 100644 tests/UserProfilePhotosTest.php delete mode 100644 tests/UserTest.php delete mode 100644 tests/WebhookInfoTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cb17251..495cab9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,19 +2,17 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file -## NEXT - YYYY-MM-DD +## [Unreleased] - [YYYY-MM-DD] ### Added -- Nothing - -### Deprecated -- Nothing +- Add `\TelegramBot\Api\Types\Venue` mapping (`foursquare_type`, `google_place_id`, `google_place_type`) ### Fixed -- Nothing +- Fix `\TelegramBot\Api\Collection\Collection::addItem` max count constraint (#333) +- Fix `\TelegramBot\Api\Types\StickerSet` mapping -### Removed -- Nothing - -### Security -- Nothing +### Deprecated +- Deprecate `\TelegramBot\Api\Botan` class +- Deprecate `$trackerToken` parameter in `\TelegramBot\Api\BotApi::__construct` +- Deprecate `$trackerToken` parameter in `\TelegramBot\Api\Events\EventCollection::__construct` +- Deprecate `\TelegramBot\Api\Types\PollAnswer::getFrom` use `\TelegramBot\Api\Types\PollAnswer::getUser` diff --git a/composer.json b/composer.json index e66c8e6b..e64d383b 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ }, "scripts": { "test": "vendor/bin/simple-phpunit --colors=always", + "coverage": "XDEBUG_MODE=coverage vendor/bin/simple-phpunit --coverage-html build/coverage", "cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi", "cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f2eebe03..b8a9042b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,4 +19,7 @@ src/ + + + diff --git a/src/BotApi.php b/src/BotApi.php index 6b618b6a..5d176698 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -191,6 +191,7 @@ public function __construct($token, $trackerToken = null) $this->token = $token; if ($trackerToken) { + @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); $this->tracker = new Botan($trackerToken); } } diff --git a/src/Botan.php b/src/Botan.php index 9c4cd828..45ef34a1 100644 --- a/src/Botan.php +++ b/src/Botan.php @@ -4,6 +4,9 @@ use TelegramBot\Api\Types\Message; +/** + * @deprecated + */ class Botan { /** diff --git a/src/Client.php b/src/Client.php index fed9569a..d347e135 100644 --- a/src/Client.php +++ b/src/Client.php @@ -44,6 +44,9 @@ class Client */ public function __construct($token, $trackerToken = null) { + if ($trackerToken) { + @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); + } $this->api = new BotApi($token); $this->events = new EventCollection($trackerToken); } diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index 8b5b7dfe..de2ffc84 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -28,7 +28,7 @@ class Collection */ public function addItem(CollectionItemInterface $item, $key = null) { - if ($this->maxCount > 0 && $this->count() + 1 >= $this->maxCount) { + if ($this->maxCount > 0 && $this->count() + 1 > $this->maxCount) { throw new ReachedMaxSizeException("Maximum collection items count reached. Max size: {$this->maxCount}"); } diff --git a/src/Events/EventCollection.php b/src/Events/EventCollection.php index c51b0ed4..b8a4f345 100644 --- a/src/Events/EventCollection.php +++ b/src/Events/EventCollection.php @@ -31,6 +31,7 @@ class EventCollection public function __construct($trackerToken = null) { if ($trackerToken) { + @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); $this->tracker = new Botan($trackerToken); } } diff --git a/src/Types/Payments/ShippingAddress.php b/src/Types/Payments/ShippingAddress.php index bc5a2403..b871fea2 100644 --- a/src/Types/Payments/ShippingAddress.php +++ b/src/Types/Payments/ShippingAddress.php @@ -60,14 +60,14 @@ class ShippingAddress extends BaseType /** * Second line for the address * - * @var integer + * @var string */ protected $streetLine2; /** * Address post code * - * @var integer + * @var string */ protected $postCode; @@ -145,7 +145,7 @@ public function setStreetLine1($streetLine1) /** * @author MY - * @return int + * @return string */ public function getStreetLine2() { @@ -154,7 +154,7 @@ public function getStreetLine2() /** * @author MY - * @param int $streetLine2 + * @param string $streetLine2 */ public function setStreetLine2($streetLine2) { @@ -163,7 +163,7 @@ public function setStreetLine2($streetLine2) /** * @author MY - * @return int + * @return string */ public function getPostCode() { @@ -172,7 +172,7 @@ public function getPostCode() /** * @author MY - * @param int $postCode + * @param string $postCode */ public function setPostCode($postCode) { diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index c6ac7d96..5b2c6ecd 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -82,19 +82,15 @@ public function setUser(User $from) } /** + * @deprecated + * * @return User */ public function getFrom() { - return $this->getUser(); - } + @trigger_error(sprintf('Access user with %s is deprecated, use "%s::getUser" method', __METHOD__, __CLASS__), \E_USER_DEPRECATED); - /** - * @param User $from - */ - public function setFrom(User $from) - { - return $this->setUser($from); + return $this->getUser(); } /** diff --git a/src/Types/ReplyKeyboardMarkup.php b/src/Types/ReplyKeyboardMarkup.php index 83e2192d..6f20da9a 100644 --- a/src/Types/ReplyKeyboardMarkup.php +++ b/src/Types/ReplyKeyboardMarkup.php @@ -65,7 +65,7 @@ class ReplyKeyboardMarkup extends BaseType */ protected $selective; - public function __construct($keyboard, $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null) + public function __construct($keyboard = [], $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null) { $this->keyboard = $keyboard; $this->oneTimeKeyboard = $oneTimeKeyboard; diff --git a/src/Types/ReplyKeyboardRemove.php b/src/Types/ReplyKeyboardRemove.php index 519ffc5f..056b016f 100644 --- a/src/Types/ReplyKeyboardRemove.php +++ b/src/Types/ReplyKeyboardRemove.php @@ -48,9 +48,9 @@ class ReplyKeyboardRemove extends BaseType */ protected $selective; - public function __construct($remove_keyboard = true, $selective = false) + public function __construct($removeKeyboard = true, $selective = false) { - $this->removeKeyboard = $remove_keyboard; + $this->removeKeyboard = $removeKeyboard; $this->selective = $selective; } @@ -63,11 +63,11 @@ public function getRemoveKeyboard() } /** - * @param bool $remove_keyboard + * @param bool $removeKeyboard */ - public function setRemoveKeyboard($remove_keyboard) + public function setRemoveKeyboard($removeKeyboard) { - $this->removeKeyboard = $remove_keyboard; + $this->removeKeyboard = $removeKeyboard; } /** diff --git a/src/Types/Sticker.php b/src/Types/Sticker.php index 37590725..609a593d 100644 --- a/src/Types/Sticker.php +++ b/src/Types/Sticker.php @@ -36,15 +36,15 @@ class Sticker extends BaseType implements TypeInterface */ protected static $map = [ 'file_id' => true, + 'file_unique_id' => true, + 'type' => true, 'width' => true, 'height' => true, - 'thumb' => PhotoSize::class, - 'file_size' => true, - 'type' => true, - 'file_unique_id' => true, - 'premium_animation' => true, 'is_animated' => true, 'is_video' => true, + 'thumb' => PhotoSize::class, + 'file_size' => true, + 'premium_animation' => File::class, 'emoji' => true, 'set_name' => true, 'mask_position' => MaskPosition::class, diff --git a/src/Types/StickerSet.php b/src/Types/StickerSet.php index 10487c8d..2559fee8 100644 --- a/src/Types/StickerSet.php +++ b/src/Types/StickerSet.php @@ -32,8 +32,8 @@ class StickerSet extends BaseType implements TypeInterface 'sticker_type' => true, 'is_animated' => true, 'is_video' => true, - 'stickers' => true, - 'thumb' => true, + 'stickers' => ArrayOfSticker::class, + 'thumb' => PhotoSize::class, ]; /** diff --git a/src/Types/Venue.php b/src/Types/Venue.php index 225d15a4..2414a5a9 100644 --- a/src/Types/Venue.php +++ b/src/Types/Venue.php @@ -36,6 +36,9 @@ class Venue extends BaseType implements TypeInterface 'title' => true, 'address' => true, 'foursquare_id' => true, + 'foursquare_type' => true, + 'google_place_id' => true, + 'google_place_type' => true, ]; /** @@ -66,6 +69,27 @@ class Venue extends BaseType implements TypeInterface */ protected $foursquareId; + /** + * Optional. Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) + * + * @var string + */ + protected $foursquareType; + + /** + * Optional. Google Places identifier of the venue + * + * @var string + */ + protected $googlePlaceId; + + /** + * Optional. Google Places type of the venue. + * + * @var string + */ + protected $googlePlaceType; + /** * @return Location */ @@ -129,4 +153,52 @@ public function setFoursquareId($foursquareId) { $this->foursquareId = $foursquareId; } + + /** + * @return string + */ + public function getFoursquareType() + { + return $this->foursquareType; + } + + /** + * @param string $foursquareType + */ + public function setFoursquareType($foursquareType) + { + $this->foursquareType = $foursquareType; + } + + /** + * @return string + */ + public function getGooglePlaceId() + { + return $this->googlePlaceId; + } + + /** + * @param string $googlePlaceId + */ + public function setGooglePlaceId($googlePlaceId) + { + $this->googlePlaceId = $googlePlaceId; + } + + /** + * @return string + */ + public function getGooglePlaceType() + { + return $this->googlePlaceType; + } + + /** + * @param string $googlePlaceType + */ + public function setGooglePlaceType($googlePlaceType) + { + $this->googlePlaceType = $googlePlaceType; + } } diff --git a/tests/AbstractTypeTest.php b/tests/AbstractTypeTest.php new file mode 100644 index 00000000..de0a4926 --- /dev/null +++ b/tests/AbstractTypeTest.php @@ -0,0 +1,74 @@ +assertInstanceOf(static::getType(), $item); + $this->assertMinItem($item); + } + + public function testFromResponseFull() + { + $item = static::createFullInstance(); + + $this->assertInstanceOf(static::getType(), $item); + $this->assertFullItem($item); + } + + /** + * @param object $item + * @return void + */ + abstract protected function assertMinItem($item); + + /** + * @param object $item + * @return void + */ + abstract protected function assertFullItem($item); +} diff --git a/tests/BotCommandTest.php b/tests/BotCommandTest.php deleted file mode 100644 index 900a2039..00000000 --- a/tests/BotCommandTest.php +++ /dev/null @@ -1,37 +0,0 @@ -setCommand('start'); - $this->assertEquals('start', $item->getCommand()); - } - - public function testSetDescription() - { - $item = new BotCommand(); - $item->setDescription('This is a start command!'); - $this->assertEquals('This is a start command!', $item->getDescription()); - } - - public function testFromResponse() - { - $botCommand = BotCommand::fromResponse( - [ - 'command' => 'start', - 'description' => 'This is a start command!', - ] - ); - - $this->assertInstanceOf('\TelegramBot\Api\Types\BotCommand', $botCommand); - $this->assertEquals('start', $botCommand->getCommand()); - $this->assertEquals('This is a start command!', $botCommand->getDescription()); - } -} diff --git a/tests/ChatLocationTest.php b/tests/ChatLocationTest.php deleted file mode 100644 index 47b1e1a2..00000000 --- a/tests/ChatLocationTest.php +++ /dev/null @@ -1,46 +0,0 @@ -setLatitude(55.585827); - $location->setLongitude(37.675309); - - $chatLocation->setLocation($location); - - $this->assertEquals($location, $chatLocation->getLocation()); - } - - public function testGetAddress() - { - $chatLocation = new ChatLocation(); - $chatLocation->setAddress('Wall St. 123'); - - $this->assertEquals('Wall St. 123', $chatLocation->getAddress()); - } - - public function testFromResponse() - { - $chatLocation = ChatLocation::fromResponse( - [ - 'location' => [ - 'latitude' => 55.585827, - 'longitude' => 37.675309, - ], - 'address' => 'Wall St. 123' - ] - ); - $this->assertInstanceOf(ChatLocation::class, $chatLocation); - $this->assertEquals('Wall St. 123', $chatLocation->getAddress()); - } -} diff --git a/tests/ChatTest.php b/tests/ChatTest.php deleted file mode 100644 index ac95f240..00000000 --- a/tests/ChatTest.php +++ /dev/null @@ -1,152 +0,0 @@ - 1, - 'type' => 'group', - 'title' => 'test chat' - ]); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item); - $this->assertEquals(1, $item->getId()); - $this->assertEquals('test chat', $item->getTitle()); - - } - - public function testSetId() - { - $chat = new Chat(); - $chat->setId(1); - $this->assertEquals(1, $chat->getId()); - } - - public function testSet64bitId() - { - $chat = new Chat(); - $chat->setId(2147483648); - $this->assertEquals(2147483648, $chat->getId()); - } - - public function testSetType() - { - $chat = new Chat(); - $chat->setType('private'); - $this->assertEquals('private', $chat->getType()); - } - - public function testSetTitle() - { - $chat = new Chat(); - $chat->setTitle('test chat'); - $this->assertEquals('test chat', $chat->getTitle()); - } - - public function testSetUsername() - { - $chat = new Chat(); - $chat->setUsername('iGusev'); - $this->assertEquals('iGusev', $chat->getUsername()); - } - - public function testSetFirstName() - { - $chat = new Chat(); - $chat->setFirstName('Ilya'); - $this->assertEquals('Ilya', $chat->getFirstName()); - } - - public function testSetLastName() - { - $chat = new Chat(); - $chat->setLastName('Gusev'); - $this->assertEquals('Gusev', $chat->getLastName()); - } - - public function testSetPhoto() - { - $chat = new Chat(); - $photo = ChatPhoto::fromResponse([ - 'small_file_id' => 'small_file_id', - 'big_file_id' => 'big_file_id' - ]); - $chat->setPhoto($photo); - $this->assertEquals($photo, $chat->getPhoto()); - } - - public function testSetBio() - { - $chat = new Chat(); - $chat->setBio('PHP Telegram Bot API'); - $this->assertEquals('PHP Telegram Bot API', $chat->getBio()); - } - - public function testSetDescriptions() - { - $chat = new Chat(); - $chat->setDescription('description'); - $this->assertEquals('description', $chat->getDescription()); - } - - public function testFromResponseUser() - { - $item = Chat::fromResponse([ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - 'type' => 'private', - 'bio' => 'PHP Telegram Bot API' - ]); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item); - $this->assertEquals(123456, $item->getId()); - $this->assertEquals('Ilya', $item->getFirstName()); - $this->assertEquals('Gusev', $item->getLastName()); - $this->assertEquals('iGusev', $item->getUsername()); - $this->assertEquals('PHP Telegram Bot API', $item->getBio()); - } - - public function testSetIdException1() - { - $this->expectException(InvalidArgumentException::class); - - $chat = new Chat(); - $chat->setId([]); - } - - public function testSetIdException2() - { - $this->expectException(InvalidArgumentException::class); - - $chat = new Chat(); - $chat->setId(null); - } - - public function testFromResponseException2() - { - $this->expectException(InvalidArgumentException::class); - - $chat = Chat::fromResponse([ - 'id' => 1 - ]); - } - - public function testFromResponseException3() - { - $this->expectException(InvalidArgumentException::class); - - $chat = Chat::fromResponse([ - 'type' => 'private' - ]); - } -} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 18afabad..bc0737e5 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\TestCase; use TelegramBot\Api\BadMethodCallException; use TelegramBot\Api\Client; +use TelegramBot\Api\Events\EventCollection; use TelegramBot\Api\Types\Inline\InlineQuery; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Update; @@ -122,12 +123,12 @@ public function data() */ public function testGetInlineQueryChecker($update) { - $reflectionMethod = new \ReflectionMethod('TelegramBot\Api\Client', 'getInlineQueryChecker'); + $reflectionMethod = new \ReflectionMethod(Client::class, 'getInlineQueryChecker'); $reflectionMethod->setAccessible(true); $result = $reflectionMethod->invoke(null); - $this->assertInstanceOf('\Closure', $result); + $this->assertInstanceOf(\Closure::class, $result); $this->assertEquals(!is_null($update->getInlineQuery()), call_user_func($result, $update)); } @@ -146,7 +147,7 @@ public function testOn() { $item = new Client('testToken'); - $mockedEventCollection = $this->getMockBuilder('\TelegramBot\Api\Events\EventCollection') + $mockedEventCollection = $this->getMockBuilder(EventCollection::class) ->disableOriginalConstructor() ->getMock(); @@ -171,12 +172,12 @@ public function testOn() */ public function testGetChecker($update, $command) { - $reflectionMethod = new \ReflectionMethod('TelegramBot\Api\Client', 'getChecker'); + $reflectionMethod = new \ReflectionMethod(Client::class, 'getChecker'); $reflectionMethod->setAccessible(true); $result = $reflectionMethod->invoke(null, $command); - $this->assertInstanceOf('\Closure', $result); + $this->assertInstanceOf(\Closure::class, $result); preg_match(Client::REGEXP, $update->getMessage() ? $update->getMessage()->getText() : '', $matches); @@ -195,7 +196,7 @@ public function testHandle($update) { $item = new Client('testToken'); - $mockedEventCollection = $this->getMockBuilder('\TelegramBot\Api\Events\EventCollection') + $mockedEventCollection = $this->getMockBuilder(EventCollection::class) ->disableOriginalConstructor() ->getMock(); @@ -218,7 +219,7 @@ public function testHandle($update) */ public function testGetEvent($update, $command, $attr1, $attr2) { - $reflectionMethod = new \ReflectionMethod('TelegramBot\Api\Client', 'getEvent'); + $reflectionMethod = new \ReflectionMethod(Client::class, 'getEvent'); $reflectionMethod->setAccessible(true); global $test; @@ -243,7 +244,7 @@ public function testGetEvent($update, $command, $attr1, $attr2) $result = $reflectionMethod->invoke(null, $action); - $this->assertInstanceOf('\Closure', $result); + $this->assertInstanceOf(\Closure::class, $result); $mustBeCalled = !is_null($update->getMessage()); @@ -263,7 +264,7 @@ public function testGetEvent($update, $command, $attr1, $attr2) */ public function testGetInlineQueryEvent($update) { - $reflectionMethod = new \ReflectionMethod('TelegramBot\Api\Client', 'getInlineQueryEvent'); + $reflectionMethod = new \ReflectionMethod(Client::class, 'getInlineQueryEvent'); $reflectionMethod->setAccessible(true); global $test; @@ -280,7 +281,7 @@ public function testGetInlineQueryEvent($update) $result = $reflectionMethod->invoke(null, $action); - $this->assertInstanceOf('\Closure', $result); + $this->assertInstanceOf(\Closure::class, $result); $mustBeCalled = !is_null($update->getInlineQuery()); diff --git a/tests/Collection/CollectionTest.php b/tests/Collection/CollectionTest.php index 153e498e..c8aceb99 100644 --- a/tests/Collection/CollectionTest.php +++ b/tests/Collection/CollectionTest.php @@ -4,6 +4,8 @@ use PHPUnit\Framework\TestCase; use TelegramBot\Api\Collection\CollectionItemInterface; +use TelegramBot\Api\Collection\KeyHasUseException; +use TelegramBot\Api\Collection\KeyInvalidException; use TelegramBot\Api\Collection\ReachedMaxSizeException; use TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia; use TelegramBot\Api\Types\InputMedia\InputMediaPhoto; @@ -17,8 +19,7 @@ class CollectionTest extends TestCase ] ]; - /** @test */ - public function can_add_item() + public function testAddItem() { $media = new ArrayOfInputMedia(); $media->addItem(new InputMediaPhoto('link')); @@ -26,8 +27,7 @@ public function can_add_item() $this->assertSame(1, $media->count()); } - /** @test */ - public function can_add_item_with_key() + public function testAddItemWithKey() { $media = new ArrayOfInputMedia(); $media->addItem(new InputMediaPhoto('link'), 'key'); @@ -35,8 +35,16 @@ public function can_add_item_with_key() $this->assertSame(1, $media->count()); } - /** @test */ - public function can_get_item() + public function testAddItemWithDuplicateKey() + { + $this->expectException(KeyHasUseException::class); + + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link'), 'key'); + $media->addItem(new InputMediaPhoto('link'), 'key'); + } + + public function testGetItem() { $media = new ArrayOfInputMedia(); $media->addItem(new InputMediaPhoto('link'), 'key'); @@ -44,8 +52,15 @@ public function can_get_item() $this->assertInstanceOf(CollectionItemInterface::class, $media->getItem('key')); } - /** @test */ - public function can_delete_item() + public function testGetInvalidItem() + { + $this->expectException(KeyInvalidException::class); + + $media = new ArrayOfInputMedia(); + $media->getItem('key'); + } + + public function testDeleteItem() { $media = new ArrayOfInputMedia(); $media->addItem(new InputMediaPhoto('link'), 'key'); @@ -54,29 +69,27 @@ public function can_delete_item() $this->assertSame(0, $media->count()); } - /** @test */ - public function check_count() + public function testCount() { $media = new ArrayOfInputMedia(); + $media->setMaxCount(5); for ($i = 0; $i < 5; $i++) { $media->addItem(new InputMediaPhoto('link')); } $this->assertSame(5, $media->count()); } - /** @test */ - public function can_not_add_more_then_max_limit() + public function testCantAddMoreThenMaxLimit() { $this->expectException(ReachedMaxSizeException::class); $media = new ArrayOfInputMedia(); $media->setMaxCount(2); - for ($i = 1; $i < 3; $i++) { - $media->addItem(new InputMediaPhoto('link')); - } + $media->addItem(new InputMediaPhoto('link')); + $media->addItem(new InputMediaPhoto('link')); + $media->addItem(new InputMediaPhoto('link')); } - /** @test */ - public function can_output_items_as_array() + public function testCanOutputItemsAsArray() { $media = new ArrayOfInputMedia(); $media->addItem(new InputMediaPhoto('link')); @@ -84,8 +97,7 @@ public function can_output_items_as_array() $this->assertSame($this->itemsOutput, $media->toJson(true)); } - /** @test */ - public function can_output_items_as_json() + public function testCanOutputItemsAsJson() { $media = new ArrayOfInputMedia(); $media->addItem(new InputMediaPhoto('link')); diff --git a/tests/ContactTest.php b/tests/ContactTest.php deleted file mode 100644 index 372032ca..00000000 --- a/tests/ContactTest.php +++ /dev/null @@ -1,59 +0,0 @@ -setPhoneNumber('123456'); - $this->assertEquals('123456', $contact->getPhoneNumber()); - } - - public function testSetFirstName() - { - $contact = new Contact(); - $contact->setFirstName('Ilya'); - $this->assertEquals('Ilya', $contact->getFirstName()); - } - - public function testSetLastName() - { - $contact = new Contact(); - $contact->setLastName('Gusev'); - $this->assertEquals('Gusev', $contact->getLastName()); - } - - public function testSetUserId() - { - $contact = new Contact(); - $contact->setUserId('iGusev'); - $this->assertEquals('iGusev', $contact->getUserId()); - } - - public function testSetVcard() - { - $contact = new Contact(); - $contact->setVCard('testVCard'); - $this->assertEquals('testVCard', $contact->getVCard()); - } - - public function testFromResponse() - { - $contact = Contact::fromResponse([ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'phone_number' => '123456', - 'user_id' => 'iGusev' - ]); - $this->assertInstanceOf('\TelegramBot\Api\Types\Contact', $contact); - $this->assertEquals('123456', $contact->getPhoneNumber()); - $this->assertEquals('Ilya', $contact->getFirstName()); - $this->assertEquals('Gusev', $contact->getLastName()); - $this->assertEquals('iGusev', $contact->getUserId()); - } -} diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php deleted file mode 100644 index c81def73..00000000 --- a/tests/DocumentTest.php +++ /dev/null @@ -1,116 +0,0 @@ -setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetThumb() - { - $item = new Document(); - $thumb = PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ]); - $item->setThumb($thumb); - $this->assertEquals($thumb, $item->getThumb()); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); - } - - public function testSetFileName() - { - $item = new Document(); - $item->setFileName('testfileName'); - $this->assertEquals('testfileName', $item->getFileName()); - } - - public function testSetFileSize() - { - $item = new Document(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetMimeType() - { - $item = new Document(); - $item->setMimeType('audio/mp3'); - $this->assertEquals('audio/mp3', $item->getMimeType()); - } - - public function testSetFileSizeException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Document(); - $item->setFileSize('s'); - } - - public function testFromResponse() - { - $item = Document::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'file_name' => 'testFileName', - 'mime_type' => 'audio/mp3', - 'file_size' => 3, - 'thumb' => [ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ] - ]); - $thumb = PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ]); - $this->assertInstanceOf(Document::class, $item); - $this->assertEquals('testFileId1', $item->getFileId()); - $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); - $this->assertEquals('testFileName', $item->getFileName()); - $this->assertEquals('audio/mp3', $item->getMimeType()); - $this->assertEquals(3, $item->getFileSize()); - $this->assertEquals($thumb, $item->getThumb()); - $this->assertInstanceOf(PhotoSize::class, $item->getThumb()); - } - - /** - * file_id and file_unique_id are required - */ - public function testFromResponseException1() - { - $this->expectException(InvalidArgumentException::class); - - $item = Document::fromResponse([ - 'file_name' => 'testFileName', - 'mime_type' => 'audio/mp3', - 'file_size' => 3, - 'thumb' => [ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ] - ]); - } -} diff --git a/tests/Types/Events/EventCollectionTest.php b/tests/Events/EventCollectionTest.php similarity index 91% rename from tests/Types/Events/EventCollectionTest.php rename to tests/Events/EventCollectionTest.php index fbdac7a9..a66ac5d9 100644 --- a/tests/Types/Events/EventCollectionTest.php +++ b/tests/Events/EventCollectionTest.php @@ -1,8 +1,10 @@ assertIsArray($innerItem); /* @var \TelegramBot\Api\Events\Event $event */ foreach($innerItem as $event) { - $this->assertInstanceOf('\TelegramBot\Api\Events\Event', $event); + $this->assertInstanceOf(Event::class, $event); } } @@ -86,7 +88,7 @@ public function testAdd2($action) $this->assertIsArray($innerItem); /* @var \TelegramBot\Api\Events\Event $event */ foreach($innerItem as $event) { - $this->assertInstanceOf('\TelegramBot\Api\Events\Event', $event); + $this->assertInstanceOf(Event::class, $event); } } @@ -105,7 +107,7 @@ public function testHandle1($action, $checker, $update) return true; }); - $mockedTracker = $this->getMockBuilder('\TelegramBot\Api\Botan') + $mockedTracker = $this->getMockBuilder(Botan::class) ->disableOriginalConstructor() ->getMock(); @@ -137,11 +139,11 @@ public function testHandle2($action, $checker, $update) return true; }); - $mockedTracker = $this->getMockBuilder('\TelegramBot\Api\Botan') + $mockedTracker = $this->getMockBuilder(Botan::class) ->disableOriginalConstructor() ->getMock(); - $mockedEvent = $this->getMockBuilder('\TelegramBot\Api\Events\Event') + $mockedEvent = $this->getMockBuilder(Event::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Types/Events/EventTest.php b/tests/Events/EventTest.php similarity index 97% rename from tests/Types/Events/EventTest.php rename to tests/Events/EventTest.php index cf57f5cb..ce53602c 100644 --- a/tests/Types/Events/EventTest.php +++ b/tests/Events/EventTest.php @@ -1,6 +1,6 @@ assertInstanceOf('TelegramBot\Api\Events\Event', $item); + $this->assertInstanceOf(Event::class, $item); } /** diff --git a/tests/FileTest.php b/tests/FileTest.php deleted file mode 100644 index 5a292b56..00000000 --- a/tests/FileTest.php +++ /dev/null @@ -1,63 +0,0 @@ -setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetFileSize() - { - $item = new File(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetFilePath() - { - $item = new File(); - $item->setFilePath('testfilepath'); - $this->assertEquals('testfilepath', $item->getFilePath()); - } - - public function testFromResponse() - { - $item = File::fromResponse([ - 'file_id' => 'testFileId1', - 'file_size' => 3, - 'file_path' => 'testfilepath' - ]); - $this->assertInstanceOf(File::class, $item); - $this->assertEquals('testFileId1', $item->getFileId()); - $this->assertEquals(3, $item->getFileSize()); - $this->assertEquals('testfilepath', $item->getFilePath()); - } - - public function testFromResponseException() - { - $this->expectException(InvalidArgumentException::class); - - $item = File::fromResponse([ - 'file_size' => 3, - 'file_path' => 'testfilepath' - ]); - } - - public function testSetFileSizeException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new File(); - $item->setFileSize('s'); - } - -} diff --git a/tests/LocationTest.php b/tests/LocationTest.php deleted file mode 100644 index 4c233097..00000000 --- a/tests/LocationTest.php +++ /dev/null @@ -1,98 +0,0 @@ -setLatitude(55.585827); - $this->assertEquals(55.585827, $location->getLatitude()); - } - - public function testSetLongtitude() - { - $location = new Location(); - $location->setLongitude(37.675309); - $this->assertEquals(37.675309, $location->getLongitude()); - } - - public function testSetHorizontalAccuracy() - { - $location = new Location(); - $location->setHorizontalAccuracy(20.5); - $this->assertEquals(20.5, $location->getHorizontalAccuracy()); - } - - public function testSetLivePeriod() - { - $location = new Location(); - $location->setLivePeriod(300); - $this->assertEquals(300, $location->getLivePeriod()); - } - - public function testSetHeading() - { - $location = new Location(); - $location->setHeading(100); - $this->assertEquals(100, $location->getHeading()); - } - - public function testSetProximityAlertRadius() - { - $location = new Location(); - $location->setProximityAlertRadius(100); - $this->assertEquals(100, $location->getProximityAlertRadius()); - } - - public function testFromResponse() - { - $location = Location::fromResponse( - [ - 'latitude' => 55.585827, - 'longitude' => 37.675309, - 'horizontal_accuracy' => 20.5, - 'live_period' => 300, - 'heading' => 100, - 'proximity_alert_radius' => 15 - ] - ); - $this->assertInstanceOf(Location::class, $location); - $this->assertEquals(55.585827, $location->getLatitude()); - $this->assertEquals(37.675309, $location->getLongitude()); - $this->assertEquals(20.5, $location->getHorizontalAccuracy()); - $this->assertEquals(300, $location->getLivePeriod()); - $this->assertEquals(100, $location->getHeading()); - $this->assertEquals(15, $location->getProximityAlertRadius()); - } - - public function testSetHorizontalAccuracyException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Location(); - $item->setHorizontalAccuracy('s'); - } - - public function testSetLatitudeException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Location(); - $item->setLatitude('s'); - } - - public function testSetLongitudeException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Location(); - $item->setLongitude('s'); - } - -} diff --git a/tests/LoginUrlTest.php b/tests/LoginUrlTest.php deleted file mode 100644 index c73c75c2..00000000 --- a/tests/LoginUrlTest.php +++ /dev/null @@ -1,57 +0,0 @@ -setUrl('https://telegram.org'); - - $this->assertEquals('https://telegram.org', $loginUrl->getUrl()); - } - - public function testGetForwardText() - { - $loginUrl = new LoginUrl(); - $loginUrl->setForwardText('Log in!'); - - $this->assertEquals('Log in!', $loginUrl->getForwardText()); - } - - public function testGetBotUsername() - { - $loginUrl = new LoginUrl(); - $loginUrl->setBotUsername('TestBot'); - - $this->assertEquals('TestBot', $loginUrl->getBotUsername()); - } - - public function testGetRequestWriteAccess() - { - $loginUrl = new LoginUrl(); - $loginUrl->setRequestWriteAccess(true); - - $this->assertEquals(true, $loginUrl->isRequestWriteAccess()); - } - - public function testFromResponse() - { - $loginUrl = LoginUrl::fromResponse([ - 'url' => 'https://telegram.org', - 'forward_text' => 'Log in!', - 'bot_username' => 'TestBot', - 'request_write_access' => true - ]); - - $this->assertInstanceOf('\TelegramBot\Api\Types\LoginUrl', $loginUrl); - $this->assertEquals('https://telegram.org', $loginUrl->getUrl()); - $this->assertEquals('Log in!', $loginUrl->getForwardText()); - $this->assertEquals('TestBot', $loginUrl->getBotUsername()); - $this->assertEquals(true, $loginUrl->isRequestWriteAccess()); - } -} diff --git a/tests/MessageTest.php b/tests/MessageTest.php deleted file mode 100644 index c892b705..00000000 --- a/tests/MessageTest.php +++ /dev/null @@ -1,614 +0,0 @@ -setMessageId(1); - $this->assertEquals(1, $item->getMessageId()); - } - - public function testSet64bitMessageId() - { - $item = new Message(); - $item->setMessageId(2147483648); - $this->assertEquals(2147483648, $item->getMessageId()); - } - - public function testSetCaption() - { - $item = new Message(); - $item->setCaption('test'); - $this->assertEquals('test', $item->getCaption()); - } - - public function testSetDate() - { - $item = new Message(); - $item->setDate(1234567); - $this->assertEquals(1234567, $item->getDate()); - } - - public function testSetForwardDate() - { - $item = new Message(); - $item->setForwardDate(1234567); - $this->assertEquals(1234567, $item->getForwardDate()); - } - - public function testSetFrom() - { - $item = new Message(); - $user = User::fromResponse([ - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - ]); - $item->setFrom($user); - $this->assertEquals($user, $item->getFrom()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getFrom()); - } - - public function testSetForwardFrom() - { - $item = new Message(); - $user = User::fromResponse([ - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - ]); - $item->setForwardFrom($user); - $this->assertEquals($user, $item->getForwardFrom()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getForwardFrom()); - } - - public function testSetChatGroup() - { - $item = new Message(); - $chat = Chat::fromResponse([ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ]); - $item->setChat($chat); - $this->assertEquals($chat, $item->getChat()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item->getChat()); - } - - public function testSetChatUser() - { - $item = new Message(); - $user = Chat::fromResponse([ - 'id' => 1, - 'type' => 'private', - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - ]); - $item->setChat($user); - $this->assertEquals($user, $item->getChat()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item->getChat()); - } - - public function testSetContact() - { - $item = new Message(); - $contact = Contact::fromResponse([ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'phone_number' => '123456', - 'user_id' => 'iGusev' - ]); - $item->setContact($contact); - $this->assertEquals($contact, $item->getContact()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Contact', $item->getContact()); - } - - public function testSetDocument() - { - $item = new Message(); - $document = Document::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'file_name' => 'testFileName', - 'mime_type' => 'audio/mp3', - 'file_size' => 3, - 'thumb' => [ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ] - ]); - $item->setDocument($document); - $this->assertEquals($document, $item->getDocument()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Document', $item->getDocument()); - } - - public function testSetLocation() - { - $item = new Message(); - $location = Location::fromResponse(['latitude' => 55.585827, 'longitude' => 37.675309]); - $item->setLocation($location); - $this->assertEquals($location, $item->getLocation()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Location', $item->getLocation()); - } - - public function testSetAudio() - { - $item = new Message(); - $audio = Audio::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - ]); - $item->setAudio($audio); - $this->assertEquals($audio, $item->getAudio()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Audio', $item->getAudio()); - } - - public function testSetVoice() - { - $item = new Message(); - $voice = Voice::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testUniqueFileId', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - ]); - $item->setVoice($voice); - $this->assertEquals($voice, $item->getVoice()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Voice', $item->getVoice()); - } - - public function testSetVideo() - { - $item = new Message(); - $video = Video::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testUniqueFileId', - 'width' => 1, - 'height' => 2, - 'duration' => 3, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => [ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ] - ]); - $item->setVideo($video); - $this->assertEquals($video, $item->getVideo()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Video', $item->getVideo()); - } - - public function testSetDice() - { - $item = new Message(); - $dice = Dice::fromResponse([ - 'emoji' => '🎲', - 'value' => 3 - ]); - $item->setDice($dice); - $this->assertEquals($dice, $item->getDice()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Dice', $item->getDice()); - } - - public function testSetSticker() - { - $item = new Message(); - $sticker = Sticker::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testUniqueFileId', - 'width' => 1, - 'height' => 2, - 'file_size' => 3, - 'is_animated' => false, - 'is_video' => false, - 'type' => 'regular', - 'thumb' => [ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testUniqueFileId', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ] - ]); - $item->setSticker($sticker); - $this->assertEquals($sticker, $item->getSticker()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Sticker', $item->getSticker()); - } - - public function testSetGroupChatCreated() - { - $item = new Message(); - $item->setGroupChatCreated(true); - - $this->assertTrue($item->isGroupChatCreated()); - } - - public function testSetDeleteChatPhoto() - { - $item = new Message(); - $item->setDeleteChatPhoto(true); - - $this->assertTrue($item->isDeleteChatPhoto()); - } - - public function testSetLeftChatParticipant() - { - $item = new Message(); - $user = User::fromResponse([ - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - ]); - $item->setLeftChatMember($user); - - $this->assertEquals($user, $item->getLeftChatMember()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getLeftChatMember()); - } - - public function testSetNewChatParticipant() - { - $item = new Message(); - $user = User::fromResponse([ - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - ]); - $item->setNewChatMembers([$user]); - - $this->assertEquals([$user], $item->getNewChatMembers()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getNewChatMembers()[0]); - } - - public function testSetNewChatTitle() - { - $item = new Message(); - $item->setNewChatTitle('testtitle'); - - $this->assertEquals('testtitle', $item->getNewChatTitle()); - } - - public function testSetText() - { - $item = new Message(); - $item->setText('testtitle'); - - $this->assertEquals('testtitle', $item->getText()); - } - - public function testSetReplyToMessage() - { - $item = new Message(); - $replyMessage = Message::fromResponse([ - 'message_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ], - 'date' => 2, - 'chat' => [ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ] - ]); - $item->setReplyToMessage($replyMessage); - - $this->assertEquals($replyMessage, $item->getReplyToMessage()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Message', $item->getReplyToMessage()); - } - - public function testSetViaBot() - { - $item = new Message(); - $bot = User::fromResponse([ - 'first_name' => 'Test', - 'last_name' => 'Bot', - 'username' => 'TestingBot', - 'is_bot' => 'true', - 'id' => 654321 - ]); - $item->setViaBot($bot); - $this->assertEquals($bot, $item->getViaBot()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getViaBot()); - } - - public function testViaBotMessage() - { - $item = Message::fromResponse([ - 'message_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ], - 'date' => 2, - 'chat' => [ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ], - 'via_bot' => [ - 'first_name' => 'Test', - 'last_name' => 'Bot', - 'username' => 'TestingBot', - 'is_bot' => 'true', - 'id' => 654321 - ] - ]); - $this->assertEquals(654321, $item->getViaBot()->getId()); - } - - public function testSetPhoto() - { - $item = new Message(); - $photo = [ - PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ]) - ]; - - $item->setPhoto($photo); - - $this->assertEquals($photo, $item->getPhoto()); - - foreach ($item->getPhoto() as $photoItem) { - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photoItem); - } - } - - public function testGetNewChatPhoto() - { - $item = new Message(); - $photo = [ - PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ]) - ]; - - $item->setNewChatPhoto($photo); - $this->assertEquals($photo, $item->getNewChatPhoto()); - - foreach ($item->getNewChatPhoto() as $photoItem) { - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photoItem); - } - } - - public function testSetMessageIdException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Message(); - $item->setMessageId('s'); - } - - public function testSetDateException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Message(); - $item->setDate('s'); - } - - public function testSetForwardDateException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Message(); - $item->setForwardDate('s'); - } - - public function testSetSupergroupChatCreated() - { - $item = new Message(); - $item->setSupergroupChatCreated(true); - - $this->assertTrue($item->isSupergroupChatCreated()); - } - - public function testIsSupergroupChatCreated() - { - $item = Message::fromResponse([ - 'message_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ], - 'date' => 2, - 'chat' => [ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ], - 'supergroup_chat_created' => true - ]); - - $this->assertTrue($item->isSupergroupChatCreated()); - } - - public function testSetChannelChatCreated() - { - $item = new Message(); - $item->setChannelChatCreated(true); - - $this->assertTrue($item->isChannelChatCreated()); - } - - public function testIsChannelChatCreated() - { - $item = Message::fromResponse([ - 'message_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ], - 'date' => 2, - 'chat' => [ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ], - 'channel_chat_created' => true - ]); - - $this->assertTrue($item->isChannelChatCreated()); - } - - public function testSetMigrateToChatId() - { - $item = new Message(); - $item->setMigrateToChatId(2); - $this->assertEquals(2, $item->getMigrateToChatId()); - } - - public function testGetMigrateToChatId() - { - $item = Message::fromResponse([ - 'message_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ], - 'date' => 2, - 'chat' => [ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ], - 'migrate_to_chat_id' => 2 - ]); - - $this->assertEquals(2, $item->getMigrateToChatId()); - } - - public function testSetMigrateFromChatId() - { - $item = new Message(); - $item->setMigrateFromChatId(2); - $this->assertEquals(2, $item->getMigrateFromChatId()); - } - - public function testGetMigrateFromChatId() - { - $item = Message::fromResponse([ - 'message_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ], - 'date' => 2, - 'chat' => [ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ], - 'migrate_from_chat_id' => 3 - ]); - - $this->assertEquals(3, $item->getMigrateFromChatId()); - } - - public function testToJson1() - { - $data = [ - 'message_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ], - 'date' => 2, - 'chat' => [ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ], - 'migrate_from_chat_id' => 3 - ]; - - $item = Message::fromResponse($data); - $this->assertJson(json_encode($data), $item->toJson()); - } - - public function testToJson2() - { - $data = [ - 'message_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ], - 'date' => 2, - 'chat' => [ - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ], - 'entities' => [ - [ - 'type' => 'bot_command', - 'offset' => 0, - 'length' => 7, - ] - ], - 'migrate_from_chat_id' => 3 - ]; - - $item = Message::fromResponse($data); - $this->assertJson(json_encode($data), $item->toJson()); - } -} diff --git a/tests/PhotoSizeTest.php b/tests/PhotoSizeTest.php deleted file mode 100644 index 827bc40d..00000000 --- a/tests/PhotoSizeTest.php +++ /dev/null @@ -1,79 +0,0 @@ -setFileId('testfileId'); - $this->assertEquals('testfileId', $photoSize->getFileId()); - } - - public function testSetWidth() - { - $photoSize = new PhotoSize(); - $photoSize->setWidth(2); - $this->assertEquals(2, $photoSize->getWidth()); - } - - public function testSetHeight() - { - $photoSize = new PhotoSize(); - $photoSize->setHeight(4); - $this->assertEquals(4, $photoSize->getHeight()); - } - - public function testSetFileSize() - { - $photoSize = new PhotoSize(); - $photoSize->setFileSize(6); - $this->assertEquals(6, $photoSize->getFileSize()); - } - - public function testFromResponse() - { - $photoSize = PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ]); - $this->assertInstanceOf(PhotoSize::class, $photoSize); - $this->assertEquals('testFileId1', $photoSize->getFileId()); - $this->assertEquals('testFileUniqueId1', $photoSize->getFileUniqueId()); - $this->assertEquals(1, $photoSize->getWidth()); - $this->assertEquals(2, $photoSize->getHeight()); - $this->assertEquals(3, $photoSize->getFileSize()); - } - - public function testSetFileSizeException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new PhotoSize(); - $item->setFileSize('s'); - } - - public function testSetHeightException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new PhotoSize(); - $item->setHeight('s'); - } - - public function testSetWidthException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new PhotoSize(); - $item->setWidth('s'); - } -} diff --git a/tests/PollAnswerTest.php b/tests/PollAnswerTest.php deleted file mode 100644 index a03140c5..00000000 --- a/tests/PollAnswerTest.php +++ /dev/null @@ -1,45 +0,0 @@ -setPollId(123456789); - - $this->assertEquals(123456789, $item->getPollId()); - } - - public function testGetUser() - { - $item = new PollAnswer(); - $user = new User(); - $user->setId(123456); - $item->setUser($user); - - $this->assertEquals(123456, $item->getUser()->getId()); - } - public function testGetFrom() - { - $item = new PollAnswer(); - $user = new User(); - $user->setId(123456); - $item->setFrom($user); - - $this->assertEquals(123456, $item->getFrom()->getId()); - } - public function testGetOptionIds() - { - $item = new PollAnswer(); - $item->setOptionIds([1,2,3,4,5,6]); - - $this->assertEquals([1,2,3,4,5,6], $item->getOptionIds()); - } - -} diff --git a/tests/PollTest.php b/tests/PollTest.php deleted file mode 100644 index b8804de3..00000000 --- a/tests/PollTest.php +++ /dev/null @@ -1,93 +0,0 @@ -setId(123456789); - - $this->assertEquals(123456789, $item->getId()); - } - - public function testSetQuestion() - { - $item = new Poll(); - $item->setQuestion('What is the name of Heisenberg from "Breaking bad"?'); - - $this->assertEquals('What is the name of Heisenberg from "Breaking bad"?', $item->getQuestion()); - } - - public function testSetOptions() - { - $item = new Poll(); - $options = [ - PollOption::fromResponse([ - 'text' => 'Walter White', - 'voter_count' => 100 - ]), - ]; - - $item->setOptions($options); - - $this->assertEquals($options, $item->getOptions()); - - foreach ($item->getOptions() as $option) { - $this->assertInstanceOf(PollOption::class, $option); - } - } - - public function testSetTotalVoterCount() - { - $item = new Poll(); - $item->setTotalVoterCount(17); - - $this->assertEquals(17, $item->getTotalVoterCount()); - } - - public function testSetIsClosed() - { - $item = new Poll(); - $item->setIsClosed(true); - - $this->assertTrue($item->isClosed()); - } - - public function testSetIsAnonymous() - { - $item = new Poll(); - $item->setIsAnonymous(false); - - $this->assertFalse($item->isAnonymous()); - } - - public function testSetType() - { - $item = new Poll(); - $item->setType('regular'); - - $this->assertEquals('regular', $item->getType()); - } - - public function testSetAllowsMultipleAnswers() - { - $item = new Poll(); - $item->setAllowsMultipleAnswers(true); - - $this->assertTrue($item->isAllowsMultipleAnswers()); - } - - public function testSetCorrectOptionId() - { - $item = new Poll(); - $item->setCorrectOptionId(2); - - $this->assertEquals(2, $item->getCorrectOptionId()); - } -} diff --git a/tests/ReplyKeyboardHideTest.php b/tests/ReplyKeyboardHideTest.php deleted file mode 100644 index 89d0263e..00000000 --- a/tests/ReplyKeyboardHideTest.php +++ /dev/null @@ -1,87 +0,0 @@ -assertEquals(true, $item->isHideKeyboard()); - $this->assertEquals(null, $item->isSelective()); - } - - public function testConstructor2() - { - $item = new ReplyKeyboardHide(true, true); - - $this->assertEquals(true, $item->isHideKeyboard()); - $this->assertEquals(true, $item->isSelective()); - } - - public function testConstructor3() - { - $item = new ReplyKeyboardHide(false, true); - - $this->assertEquals(false, $item->isHideKeyboard()); - $this->assertEquals(true, $item->isSelective()); - } - - public function testConstructor4() - { - $item = new ReplyKeyboardHide(true); - - $this->assertEquals(true, $item->isHideKeyboard()); - $this->assertEquals(null, $item->isSelective()); - } - - public function testSetHideKeyboard() - { - $item = new ReplyKeyboardHide(true); - - $item->setHideKeyboard(false); - - $this->assertEquals(false, $item->isHideKeyboard()); - } - - public function testSetSelective() - { - $item = new ReplyKeyboardHide(); - - $item->setSelective(true); - - $this->assertEquals(true, $item->isSelective()); - } - - public function testToJson() - { - $item = new ReplyKeyboardHide(); - - $this->assertEquals(json_encode(['hide_keyboard' => true]), $item->toJson()); - } - - public function testToJson2() - { - $item = new ReplyKeyboardHide(); - - $this->assertEquals(['hide_keyboard' => true], $item->toJson(true)); - } - - public function testToJson3() - { - $item = new ReplyKeyboardHide(true, true); - - $this->assertEquals(json_encode(['hide_keyboard' => true, 'selective' => true]), $item->toJson()); - } - - public function testToJson4() - { - $item = new ReplyKeyboardHide(true, true); - - $this->assertEquals(['hide_keyboard' => true, 'selective' => true], $item->toJson(true)); - } -} diff --git a/tests/StickerTest.php b/tests/StickerTest.php deleted file mode 100644 index 178e7a35..00000000 --- a/tests/StickerTest.php +++ /dev/null @@ -1,113 +0,0 @@ -setFileId('testfileId'); - $this->assertEquals('testfileId', $sticker->getFileId()); - } - - public function testSetWidth() - { - $sticker = new Sticker(); - $sticker->setWidth(2); - $this->assertEquals(2, $sticker->getWidth()); - } - - public function testSetHeight() - { - $sticker = new Sticker(); - $sticker->setHeight(4); - $this->assertEquals(4, $sticker->getHeight()); - } - - public function testSetFileSize() - { - $sticker = new Sticker(); - $sticker->setFileSize(6); - $this->assertEquals(6, $sticker->getFileSize()); - } - - public function testSetThumb() - { - $sticker = new Sticker(); - $thumb = PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ]); - $sticker->setThumb($thumb); - $this->assertEquals($thumb, $sticker->getThumb()); - $this->assertInstanceOf(PhotoSize::class, $sticker->getThumb()); - } - - public function testFromResponse() - { - $sticker = Sticker::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3, - 'is_animated' => false, - 'is_video' => false, - 'type' => 'regular', - 'thumb' => [ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ] - ]); - $thumb = PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ]); - $this->assertInstanceOf(Sticker::class, $sticker); - $this->assertEquals('testFileId1', $sticker->getFileId()); - $this->assertEquals('testFileUniqueId1', $sticker->getFileUniqueId()); - $this->assertEquals(1, $sticker->getWidth()); - $this->assertEquals(2, $sticker->getHeight()); - $this->assertEquals(3, $sticker->getFileSize()); - $this->assertEquals($thumb, $sticker->getThumb()); - } - - public function testSetFileSizeException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Sticker(); - $item->setFileSize('s'); - } - - public function testSetHeightException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Sticker(); - $item->setHeight('s'); - } - - public function testSetWidthException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Sticker(); - $item->setWidth('s'); - } -} diff --git a/tests/Types/AnimationTest.php b/tests/Types/AnimationTest.php new file mode 100644 index 00000000..be885545 --- /dev/null +++ b/tests/Types/AnimationTest.php @@ -0,0 +1,107 @@ + 'file_id', + 'file_unique_id' => 'file_unique_id', + 'width' => 10, + 'height' => 20, + 'duration' => 30, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'file_id', + 'file_unique_id' => 'file_unique_id', + 'width' => 10, + 'height' => 20, + 'duration' => 30, + 'thumb' => PhotoSizeTest::getMinResponse(), + 'file_name' => 'file_name', + 'mime_type' => 'mime_type', + 'file_size' => 100 + ]; + } + + /** + * @param Animation $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('file_id', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(10, $item->getWidth()); + $this->assertEquals(20, $item->getHeight()); + $this->assertEquals(30, $item->getDuration()); + $this->assertNull($item->getThumb()); + $this->assertNull($item->getFileName()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + } + + /** + * @param Animation $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('file_id', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(10, $item->getWidth()); + $this->assertEquals(20, $item->getHeight()); + $this->assertEquals(30, $item->getDuration()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + $this->assertEquals('file_name', $item->getFileName()); + $this->assertEquals('mime_type', $item->getMimeType()); + $this->assertEquals(100, $item->getFileSize()); + } + + public function testSetDuration() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Animation(); + $item->setDuration('s'); + } + + public function testSetFileSize() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Animation(); + $item->setFileSize('s'); + } + + public function testSetHeight() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Animation(); + $item->setHeight('s'); + } + + public function testSetWidth() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Animation(); + $item->setWidth('s'); + } +} diff --git a/tests/Types/ArrayOfBotCommandTest.php b/tests/Types/ArrayOfBotCommandTest.php new file mode 100644 index 00000000..dddb66fd --- /dev/null +++ b/tests/Types/ArrayOfBotCommandTest.php @@ -0,0 +1,31 @@ + 'start', + 'description' => 'This is a start command!', + ], + ]); + + $expected = [ + BotCommand::fromResponse([ + 'command' => 'start', + 'description' => 'This is a start command!', + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfChatMemberEntityTest.php b/tests/Types/ArrayOfChatMemberEntityTest.php new file mode 100644 index 00000000..46ca2a93 --- /dev/null +++ b/tests/Types/ArrayOfChatMemberEntityTest.php @@ -0,0 +1,37 @@ + [ + 'id' => 1, + 'first_name' => 'first_name', + ], + 'status' => 'member', + ], + ]); + + $expected = [ + ChatMember::fromResponse([ + 'user' => [ + 'id' => 1, + 'first_name' => 'first_name', + ], + 'status' => 'member', + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfMessageEntityTest.php b/tests/Types/ArrayOfMessageEntityTest.php new file mode 100644 index 00000000..902c52a8 --- /dev/null +++ b/tests/Types/ArrayOfMessageEntityTest.php @@ -0,0 +1,33 @@ + 'mention', + 'offset' => 0, + 'length' => 10, + ], + ]); + + $expected = [ + MessageEntity::fromResponse([ + 'type' => 'mention', + 'offset' => 0, + 'length' => 10, + ]), + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfMessagesTest.php b/tests/Types/ArrayOfMessagesTest.php new file mode 100644 index 00000000..b96939af --- /dev/null +++ b/tests/Types/ArrayOfMessagesTest.php @@ -0,0 +1,39 @@ + 1, + 'date' => 1682343644, + 'chat' => [ + 'id' => 2, + 'type' => 'private', + ], + ] + ]); + + $expected = [ + Message::fromResponse([ + 'message_id' => 1, + 'date' => 1682343644, + 'chat' => [ + 'id' => 2, + 'type' => 'private', + ], + ]), + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/ArrayOfPhotoSizeTest.php b/tests/Types/ArrayOfPhotoSizeTest.php similarity index 96% rename from tests/ArrayOfPhotoSizeTest.php rename to tests/Types/ArrayOfPhotoSizeTest.php index 01aedbe8..280da570 100644 --- a/tests/ArrayOfPhotoSizeTest.php +++ b/tests/Types/ArrayOfPhotoSizeTest.php @@ -1,10 +1,10 @@ 'text', + 'voter_count' => 3 + ] + ]); + + $expected = [ + PollOption::fromResponse([ + 'text' => 'text', + 'voter_count' => 3 + ]), + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfStickerTest.php b/tests/Types/ArrayOfStickerTest.php new file mode 100644 index 00000000..3b6ea1da --- /dev/null +++ b/tests/Types/ArrayOfStickerTest.php @@ -0,0 +1,41 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'type' => 'regular', + 'width' => 1, + 'height' => 2, + 'is_animated' => false, + 'is_video' => false, + ], + ]); + + $expected = [ + Sticker::fromResponse([ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'type' => 'regular', + 'width' => 1, + 'height' => 2, + 'is_animated' => false, + 'is_video' => false, + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfUpdatesTest.php b/tests/Types/ArrayOfUpdatesTest.php index 32b84252..53ba31fc 100644 --- a/tests/Types/ArrayOfUpdatesTest.php +++ b/tests/Types/ArrayOfUpdatesTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\ArrayOfUpdates; +use TelegramBot\Api\Types\Update; class ArrayOfUpdatesTest extends TestCase { @@ -50,7 +51,7 @@ public function testFromResponse($data) $this->assertIsArray($items); foreach($items as $item) { - $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $item); + $this->assertInstanceOf(Update::class, $item); } } } diff --git a/tests/Types/ArrayOfUserTest.php b/tests/Types/ArrayOfUserTest.php new file mode 100644 index 00000000..5d99708f --- /dev/null +++ b/tests/Types/ArrayOfUserTest.php @@ -0,0 +1,31 @@ + 1, + 'first_name' => 'first_name', + ], + ]); + + $expected = [ + User::fromResponse([ + 'id' => 1, + 'first_name' => 'first_name', + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/AudioTest.php b/tests/Types/AudioTest.php similarity index 64% rename from tests/AudioTest.php rename to tests/Types/AudioTest.php index 17fbb236..b254a08c 100644 --- a/tests/AudioTest.php +++ b/tests/Types/AudioTest.php @@ -1,58 +1,30 @@ setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetDuration() - { - $item = new Audio(); - $item->setDuration(1); - $this->assertEquals(1, $item->getDuration()); - } - - public function testSetPerformer() - { - $item = new Audio(); - $item->setPerformer('test'); - $this->assertEquals('test', $item->getPerformer()); + return Audio::class; } - public function testSetTitle() + public static function getMinResponse() { - $item = new Audio(); - $item->setTitle('test'); - $this->assertEquals('test', $item->getTitle()); - } - - public function testSetFileSize() - { - $item = new Audio(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetMimeType() - { - $item = new Audio(); - $item->setMimeType('audio/mp3'); - $this->assertEquals('audio/mp3', $item->getMimeType()); + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'duration' => 1, + ]; } - public function testFromResponse() + public static function getFullResponse() { - $item = Audio::fromResponse([ + return [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, @@ -60,8 +32,30 @@ public function testFromResponse() 'title' => 'testtitle', 'mime_type' => 'audio/mp3', 'file_size' => 3 - ]); - $this->assertInstanceOf(Audio::class, $item); + ]; + } + + /** + * @param Audio $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getDuration()); + $this->assertNull($item->getPerformer()); + $this->assertNull($item->getTitle()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + } + + /** + * @param Audio $item + * @return void + */ + protected function assertFullItem($item) + { $this->assertEquals('testFileId1', $item->getFileId()); $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); $this->assertEquals(1, $item->getDuration()); @@ -78,7 +72,7 @@ public function testFromResponseException() { $this->expectException(InvalidArgumentException::class); - $item = Audio::fromResponse([ + Audio::fromResponse([ 'file_unique_id' => 'testFileUniqueId1', 'duration' => 1, 'mime_type' => 'audio/mp3', @@ -93,7 +87,7 @@ public function testFromResponseException2() { $this->expectException(InvalidArgumentException::class); - $item = Audio::fromResponse([ + Audio::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'mime_type' => 'audio/mp3', @@ -108,7 +102,7 @@ public function testFromResponseException3() { $this->expectException(InvalidArgumentException::class); - $item = Audio::fromResponse([ + Audio::fromResponse([ 'file_id' => 'testFileId1', 'duration' => 1, 'mime_type' => 'audio/mp3', diff --git a/tests/Types/BotCommandTest.php b/tests/Types/BotCommandTest.php new file mode 100644 index 00000000..c2849b06 --- /dev/null +++ b/tests/Types/BotCommandTest.php @@ -0,0 +1,46 @@ + 'start', + 'description' => 'This is a start command!', + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param BotCommand $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('start', $item->getCommand()); + $this->assertEquals('This is a start command!', $item->getDescription()); + } + + /** + * @param BotCommand $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/CallbackQueryTest.php b/tests/Types/CallbackQueryTest.php index 0575237c..250af482 100644 --- a/tests/Types/CallbackQueryTest.php +++ b/tests/Types/CallbackQueryTest.php @@ -2,99 +2,64 @@ namespace TelegramBot\Api\Test\Types; -use PHPUnit\Framework\TestCase; -use TelegramBot\Api\InvalidArgumentException; +use TelegramBot\Api\Test\AbstractTypeTest; use TelegramBot\Api\Types\CallbackQuery; -use TelegramBot\Api\Types\User; -class CallbackQueryTest extends TestCase +class CallbackQueryTest extends AbstractTypeTest { - protected $callbackQueryFixture = [ - 'id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - ], - 'inline_message_id' => 1234, - 'chat_instance' => 123, - 'data' => 'callback_data', - 'game_short_name' => 'game_name' - ]; - - public function testFromResponse() - { - $item = CallbackQuery::fromResponse($this->callbackQueryFixture); - - $user = User::fromResponse($this->callbackQueryFixture['from']); - - $this->assertInstanceOf('\TelegramBot\Api\Types\CallbackQuery', $item); - $this->assertEquals($this->callbackQueryFixture['id'], $item->getId()); - $this->assertEquals($user, $item->getFrom()); - $this->assertEquals($this->callbackQueryFixture['inline_message_id'], $item->getInlineMessageId()); - $this->assertEquals($this->callbackQueryFixture['chat_instance'], $item->getChatInstance()); - $this->assertEquals($this->callbackQueryFixture['data'], $item->getData()); - $this->assertEquals($this->callbackQueryFixture['game_short_name'], $item->getGameShortName()); - } - - public function testFromResponseExceptionEmptyId() - { - $this->expectException(InvalidArgumentException::class); - - unset($this->callbackQueryFixture['id']); - CallbackQuery::fromResponse($this->callbackQueryFixture); - } - - public function testFromResponseExceptionEmptyFrom() - { - $this->expectException(InvalidArgumentException::class); - - unset($this->callbackQueryFixture['from']); - CallbackQuery::fromResponse($this->callbackQueryFixture); - } - - public function testSetId() + protected static function getType() { - $item = new CallbackQuery(); - $item->setId($this->callbackQueryFixture['id']); - $this->assertEquals($this->callbackQueryFixture['id'], $item->getId()); + return CallbackQuery::class; } - public function testSetFrom() + public static function getMinResponse() { - $item = new CallbackQuery(); - $user = User::fromResponse($this->callbackQueryFixture['from']); - $item->setFrom($user); - $this->assertEquals($user, $item->getFrom()); + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + ]; } - public function testSetInlineMessageId() + public static function getFullResponse() { - $item = new CallbackQuery(); - $item->setInlineMessageId('testInlineMessageId'); - $this->assertEquals('testInlineMessageId', $item->getInlineMessageId()); + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + 'message' => MessageTest::getMinResponse(), + 'inline_message_id' => 'inline_message_id', + 'chat_instance' => 'chat_instance', + 'data' => 'data', + 'game_short_name' => 'game_short_name' + ]; } - public function testSetChatInstance() + /** + * @param CallbackQuery $item + * @return void + */ + protected function assertMinItem($item) { - $item = new CallbackQuery(); - $item->setChatInstance('testChatInstance'); - $this->assertEquals('testChatInstance', $item->getChatInstance()); + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertNull($item->getMessage()); + $this->assertNull($item->getInlineMessageId()); + $this->assertNull($item->getChatInstance()); + $this->assertNull($item->getData()); + $this->assertNull($item->getGameShortName()); } - public function testSetData() + /** + * @param CallbackQuery $item + * @return void + */ + protected function assertFullItem($item) { - $item = new CallbackQuery(); - $item->setData('testData'); - $this->assertEquals('testData', $item->getData()); + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getMessage()); + $this->assertEquals('inline_message_id', $item->getInlineMessageId()); + $this->assertEquals('chat_instance', $item->getChatInstance()); + $this->assertEquals('data', $item->getData()); + $this->assertEquals('game_short_name', $item->getGameShortName()); } - - public function testSetGameShortName() - { - $item = new CallbackQuery(); - $item->setGameShortName('testGameShortName'); - $this->assertEquals('testGameShortName', $item->getGameShortName()); - } - } diff --git a/tests/Types/ChatLocationTest.php b/tests/Types/ChatLocationTest.php new file mode 100644 index 00000000..e5d626a4 --- /dev/null +++ b/tests/Types/ChatLocationTest.php @@ -0,0 +1,46 @@ + LocationTest::getMinResponse(), + 'address' => 'Wall St. 123' + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ChatLocation $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertEquals('Wall St. 123', $item->getAddress()); + } + + /** + * @param ChatLocation $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/ChatMemberTest.php b/tests/Types/ChatMemberTest.php new file mode 100644 index 00000000..6fd4018d --- /dev/null +++ b/tests/Types/ChatMemberTest.php @@ -0,0 +1,105 @@ + UserTest::getMinResponse(), + 'status' => 'member', + ]; + } + + public static function getFullResponse() + { + return [ + 'user' => UserTest::getMinResponse(), + 'status' => 'member', + 'until_date' => 1682343644, + 'can_be_edited' => true, + 'can_change_info' => true, + 'can_post_messages' => true, + 'can_edit_messages' => true, + 'can_delete_messages' => true, + 'can_invite_users' => true, + 'can_restrict_members' => true, + 'can_pin_messages' => true, + 'can_promote_members' => true, + 'can_send_messages' => true, + 'can_send_media_messages' => true, + 'can_send_other_messages' => true, + 'can_add_web_page_previews' => true, + 'can_manage_topics' => true, + 'is_anonymous' => true, + 'custom_title' => 'custom_title', + 'can_manage_chat' => true, + 'can_send_polls' => true, + ]; + } + + /** + * @param ChatMember $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + $this->assertEquals('member', $item->getStatus()); + $this->assertNull($item->getUntilDate()); + $this->assertNull($item->getCanBeEdited()); + $this->assertNull($item->getCanChangeInfo()); + $this->assertNull($item->getCanPostMessages()); + $this->assertNull($item->getCanEditMessages()); + $this->assertNull($item->getCanDeleteMessages()); + $this->assertNull($item->getCanInviteUsers()); + $this->assertNull($item->getCanRestrictMembers()); + $this->assertNull($item->getCanPinMessages()); + $this->assertNull($item->getCanPromoteMembers()); + $this->assertNull($item->getCanSendMessages()); + $this->assertNull($item->getCanSendMediaMessages()); + $this->assertNull($item->getCanSendOtherMessages()); + $this->assertNull($item->getCanAddWebPagePreviews()); + $this->assertNull($item->getCanManageTopics()); + $this->assertNull($item->getIsAnonymous()); + $this->assertNull($item->getCustomTitle()); + $this->assertNull($item->getCanManageChat()); + $this->assertNull($item->getCanSendPolls()); + } + + /** + * @param ChatMember $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(1682343644, $item->getUntilDate()); + $this->assertTrue($item->getCanBeEdited()); + $this->assertTrue($item->getCanChangeInfo()); + $this->assertTrue($item->getCanPostMessages()); + $this->assertTrue($item->getCanEditMessages()); + $this->assertTrue($item->getCanDeleteMessages()); + $this->assertTrue($item->getCanInviteUsers()); + $this->assertTrue($item->getCanRestrictMembers()); + $this->assertTrue($item->getCanPinMessages()); + $this->assertTrue($item->getCanPromoteMembers()); + $this->assertTrue($item->getCanSendMessages()); + $this->assertTrue($item->getCanSendMediaMessages()); + $this->assertTrue($item->getCanSendOtherMessages()); + $this->assertTrue($item->getCanAddWebPagePreviews()); + $this->assertTrue($item->getCanManageTopics()); + $this->assertTrue($item->getIsAnonymous()); + $this->assertEquals('custom_title', $item->getCustomTitle()); + $this->assertTrue($item->getCanManageChat()); + $this->assertTrue($item->getCanSendPolls()); + } +} diff --git a/tests/Types/ChatPermissionsTest.php b/tests/Types/ChatPermissionsTest.php new file mode 100644 index 00000000..9e99ca5f --- /dev/null +++ b/tests/Types/ChatPermissionsTest.php @@ -0,0 +1,65 @@ + true, + 'can_send_media_messages' => true, + 'can_send_polls' => true, + 'can_send_other_messages' => true, + 'can_add_web_page_previews' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_pin_messages' => true, + ]; + } + + /** + * @param ChatPermissions $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertNull($item->isCanSendMessages()); + $this->assertNull($item->isCanSendMediaMessages()); + $this->assertNull($item->isCanSendPolls()); + $this->assertNull($item->isCanSendOtherMessages()); + $this->assertNull($item->isCanAddWebPagePreviews()); + $this->assertNull($item->isCanChangeInfo()); + $this->assertNull($item->isCanInviteUsers()); + $this->assertNull($item->isCanPinMessages()); + } + + /** + * @param ChatPermissions $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertTrue($item->isCanSendMessages()); + $this->assertTrue($item->isCanSendMediaMessages()); + $this->assertTrue($item->isCanSendPolls()); + $this->assertTrue($item->isCanSendOtherMessages()); + $this->assertTrue($item->isCanAddWebPagePreviews()); + $this->assertTrue($item->isCanChangeInfo()); + $this->assertTrue($item->isCanInviteUsers()); + $this->assertTrue($item->isCanPinMessages()); + } +} diff --git a/tests/Types/ChatPhotoTest.php b/tests/Types/ChatPhotoTest.php new file mode 100644 index 00000000..3557ee90 --- /dev/null +++ b/tests/Types/ChatPhotoTest.php @@ -0,0 +1,46 @@ + 'small_file_id', + 'big_file_id' => 'big_file_id', + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ChatPhoto $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('small_file_id', $item->getSmallFileId()); + $this->assertEquals('big_file_id', $item->getBigFileId()); + } + + /** + * @param ChatPhoto $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/ChatTest.php b/tests/Types/ChatTest.php new file mode 100644 index 00000000..1ea4634d --- /dev/null +++ b/tests/Types/ChatTest.php @@ -0,0 +1,167 @@ + 123456, + 'type' => 'private', + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 123456, + 'type' => 'private', + 'title' => 'title', + 'username' => 'iGusev', + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'photo' => ChatPhotoTest::getMinResponse(), + 'bio' => 'PHP Telegram Bot API', + 'description' => 'description', + 'invite_link' => 'invite_link', + 'pinned_message' => MessageTest::getMinResponse(), + 'permissions' => ChatPermissionsTest::getFullResponse(), + 'slow_mode_delay' => 10, + 'sticker_set_name' => 'sticker_set_name', + 'can_set_sticker_set' => true, + 'linked_chat_id' => 2, + 'location' => ChatLocationTest::getMinResponse(), + 'join_to_send_messages' => true, + 'join_by_request' => true, + 'message_auto_delete_time' => 10000, + 'has_protected_content' => true, + 'is_forum' => true, + 'active_usernames' => [ + 'username', + ], + 'emoji_status_custom_emoji_id' => 'emoji_status_custom_emoji_id', + 'has_private_forwards' => true, + 'has_restricted_voice_and_video_messages' => true, + ]; + } + + /** + * @param Chat $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(123456, $item->getId()); + $this->assertEquals('private', $item->getType()); + + $this->assertNull($item->getTitle()); + $this->assertNull($item->getInviteLink()); + $this->assertNull($item->getFirstName()); + $this->assertNull($item->getLastName()); + $this->assertNull($item->getUsername()); + $this->assertNull($item->getBio()); + $this->assertNull($item->getDescription()); + $this->assertNull($item->getSlowModeDelay()); + $this->assertNull($item->getStickerSetName()); + $this->assertNull($item->getCanSetStickerSet()); + $this->assertNull($item->getLinkedChatId()); + $this->assertNull($item->getJoinToSendMessages()); + $this->assertNull($item->getJoinByRequest()); + $this->assertNull($item->getMessageAutoDeleteTime()); + $this->assertNull($item->getHasProtectedContent()); + $this->assertNull($item->getIsForum()); + $this->assertNull($item->getActiveUsernames()); + $this->assertNull($item->getEmojiStatusCustomEmojiId()); + $this->assertNull($item->getHasPrivateForwards()); + $this->assertNull($item->getHasRestrictedVoiceAndVideoMessages()); + $this->assertNull($item->getPhoto()); + $this->assertNull($item->getPinnedMessage()); + $this->assertNull($item->getPermissions()); + $this->assertNull($item->getLocation()); + } + + /** + * @param Chat $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(123456, $item->getId()); + $this->assertEquals('private', $item->getType()); + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('invite_link', $item->getInviteLink()); + $this->assertEquals('Ilya', $item->getFirstName()); + $this->assertEquals('Gusev', $item->getLastName()); + $this->assertEquals('iGusev', $item->getUsername()); + $this->assertEquals('PHP Telegram Bot API', $item->getBio()); + $this->assertEquals('description', $item->getDescription()); + $this->assertEquals(10, $item->getSlowModeDelay()); + $this->assertEquals('sticker_set_name', $item->getStickerSetName()); + $this->assertEquals(true, $item->getCanSetStickerSet()); + $this->assertEquals(2, $item->getLinkedChatId()); + $this->assertEquals(true, $item->getJoinToSendMessages()); + $this->assertEquals(true, $item->getJoinByRequest()); + $this->assertEquals(10000, $item->getMessageAutoDeleteTime()); + $this->assertEquals(true, $item->getHasProtectedContent()); + $this->assertEquals(true, $item->getIsForum()); + $this->assertEquals(['username'], $item->getActiveUsernames()); + $this->assertEquals('emoji_status_custom_emoji_id', $item->getEmojiStatusCustomEmojiId()); + $this->assertEquals(true, $item->getHasPrivateForwards()); + $this->assertEquals(true, $item->getHasRestrictedVoiceAndVideoMessages()); + $this->assertEquals(ChatPhotoTest::createMinInstance(), $item->getPhoto()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getPinnedMessage()); + $this->assertEquals(ChatPermissionsTest::createFullInstance(), $item->getPermissions()); + $this->assertEquals(ChatLocationTest::createMinInstance(), $item->getLocation()); + } + + public function testSet64bitId() + { + $chat = new Chat(); + $chat->setId(2147483648); + $this->assertEquals(2147483648, $chat->getId()); + } + + public function testSetIdException1() + { + $this->expectException(InvalidArgumentException::class); + + $chat = new Chat(); + $chat->setId([]); + } + + public function testSetIdException2() + { + $this->expectException(InvalidArgumentException::class); + + $chat = new Chat(); + $chat->setId(null); + } + + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + + Chat::fromResponse([ + 'id' => 1 + ]); + } + + public function testFromResponseException3() + { + $this->expectException(InvalidArgumentException::class); + + Chat::fromResponse([ + 'type' => 'private' + ]); + } +} diff --git a/tests/Types/ContactTest.php b/tests/Types/ContactTest.php new file mode 100644 index 00000000..a8a19516 --- /dev/null +++ b/tests/Types/ContactTest.php @@ -0,0 +1,59 @@ + 'Ilya', + 'phone_number' => '123456', + ]; + } + + public static function getFullResponse() + { + return [ + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'phone_number' => '123456', + 'user_id' => 'iGusev', + 'vcard' => 'vcard', + ]; + } + + /** + * @param Contact $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('123456', $item->getPhoneNumber()); + $this->assertEquals('Ilya', $item->getFirstName()); + $this->assertNull($item->getLastName()); + $this->assertNull($item->getUserId()); + $this->assertNull($item->getVCard()); + } + + /** + * @param Contact $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('123456', $item->getPhoneNumber()); + $this->assertEquals('Ilya', $item->getFirstName()); + $this->assertEquals('Gusev', $item->getLastName()); + $this->assertEquals('iGusev', $item->getUserId()); + $this->assertEquals('vcard', $item->getVCard()); + } +} diff --git a/tests/Types/DiceTest.php b/tests/Types/DiceTest.php new file mode 100644 index 00000000..05cd250a --- /dev/null +++ b/tests/Types/DiceTest.php @@ -0,0 +1,46 @@ + '🎉', + 'value' => 5 + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param Dice $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('🎉', $item->getEmoji()); + $this->assertEquals(5, $item->getValue()); + } + + /** + * @param Dice $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/DocumentTest.php b/tests/Types/DocumentTest.php new file mode 100644 index 00000000..f482c4a9 --- /dev/null +++ b/tests/Types/DocumentTest.php @@ -0,0 +1,92 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'file_name' => 'testFileName', + 'mime_type' => 'audio/mp3', + 'file_size' => 3, + 'thumb' => PhotoSizeTest::getMinResponse(), + ]; + } + + /** + * @param Document $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertNull($item->getFileName()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + $this->assertNull($item->getThumb()); + } + + /** + * @param Document $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals('testFileName', $item->getFileName()); + $this->assertEquals('audio/mp3', $item->getMimeType()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Document(); + $item->setFileSize('s'); + } + + /** + * file_id and file_unique_id are required + */ + public function testFromResponseException1() + { + $this->expectException(InvalidArgumentException::class); + + Document::fromResponse([ + 'file_name' => 'testFileName', + 'mime_type' => 'audio/mp3', + 'file_size' => 3, + 'thumb' => [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 5, + 'height' => 6, + 'file_size' => 7 + ] + ]); + } +} diff --git a/tests/Types/FileTest.php b/tests/Types/FileTest.php new file mode 100644 index 00000000..55c4f7c6 --- /dev/null +++ b/tests/Types/FileTest.php @@ -0,0 +1,75 @@ + 'testFileId1', + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'file_unique_id', + 'file_size' => 3, + 'file_path' => 'testfilepath' + ]; + } + + /** + * @param File $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertNull($item->getFileUniqueId()); + $this->assertNull($item->getFileSize()); + $this->assertNull($item->getFilePath()); + } + + /** + * @param File $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals('testfilepath', $item->getFilePath()); + } + + public function testFromResponseException() + { + $this->expectException(InvalidArgumentException::class); + + File::fromResponse([ + 'file_size' => 3, + 'file_path' => 'testfilepath' + ]); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new File(); + $item->setFileSize('s'); + } + +} diff --git a/tests/ForceReplyTest.php b/tests/Types/ForceReplyTest.php similarity index 65% rename from tests/ForceReplyTest.php rename to tests/Types/ForceReplyTest.php index 56944f14..632025be 100644 --- a/tests/ForceReplyTest.php +++ b/tests/Types/ForceReplyTest.php @@ -1,12 +1,52 @@ true, + ]; + } + + public static function getFullResponse() + { + return [ + 'force_reply' => true, + 'selective' => true + ]; + } + + /** + * @param ForceReply $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(null, $item->isSelective()); + } + + /** + * @param ForceReply $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(true, $item->isSelective()); + } + public function testConstructor() { $item = new ForceReply(); @@ -43,7 +83,7 @@ public function testSetforceReply() { $item = new ForceReply(true); - $item->setforceReply(false); + $item->setForceReply(false); $this->assertEquals(false, $item->isforceReply()); } diff --git a/tests/Types/ForumTopicClosedTest.php b/tests/Types/ForumTopicClosedTest.php new file mode 100644 index 00000000..629e356c --- /dev/null +++ b/tests/Types/ForumTopicClosedTest.php @@ -0,0 +1,40 @@ + 'name', + 'icon_color' => 2, + ]; + } + + public static function getFullResponse() + { + return [ + 'name' => 'name', + 'icon_color' => 2, + 'icon_custom_emoji_id' => 'icon_custom_emoji_id', + ]; + } + + /** + * @param ForumTopicCreated $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals(2, $item->getIconColor()); + $this->assertNull($item->getIconCustomEmojiId()); + } + + /** + * @param ForumTopicCreated $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals(2, $item->getIconColor()); + $this->assertEquals('icon_custom_emoji_id', $item->getIconCustomEmojiId()); + } +} diff --git a/tests/Types/ForumTopicReopenedTest.php b/tests/Types/ForumTopicReopenedTest.php new file mode 100644 index 00000000..be9625cf --- /dev/null +++ b/tests/Types/ForumTopicReopenedTest.php @@ -0,0 +1,40 @@ + 1, + 'name' => 'name', + 'icon_color' => 2, + ]; + } + + public static function getFullResponse() + { + return [ + 'message_thread_id' => 1, + 'name' => 'name', + 'icon_color' => 2, + 'icon_custom_emoji_id' => 'icon_custom_emoji_id', + ]; + } + + /** + * @param ForumTopic $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getMessageThreadId()); + $this->assertEquals('name', $item->getName()); + $this->assertEquals(2, $item->getIconColor()); + $this->assertNull($item->getIconCustomEmojiId()); + } + + /** + * @param ForumTopic $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getMessageThreadId()); + $this->assertEquals('name', $item->getName()); + $this->assertEquals(2, $item->getIconColor()); + $this->assertEquals('icon_custom_emoji_id', $item->getIconCustomEmojiId()); + } +} diff --git a/tests/Types/Inline/ChosenInlineResultTest.php b/tests/Types/Inline/ChosenInlineResultTest.php index 21381b47..915e93cd 100644 --- a/tests/Types/Inline/ChosenInlineResultTest.php +++ b/tests/Types/Inline/ChosenInlineResultTest.php @@ -2,79 +2,61 @@ namespace TelegramBot\Api\Test\Types\Inline; -use PHPUnit\Framework\TestCase; -use TelegramBot\Api\InvalidArgumentException; +use TelegramBot\Api\Test\AbstractTypeTest; +use TelegramBot\Api\Test\Types\LocationTest; +use TelegramBot\Api\Test\Types\UserTest; use TelegramBot\Api\Types\Inline\ChosenInlineResult; -use TelegramBot\Api\Types\User; -class ChosenInlineResultTest extends TestCase +class ChosenInlineResultTest extends AbstractTypeTest { - protected $chosenInlineResultFixture = [ - 'result_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - ], - 'query' => 'test_query' - ]; - - public function testFromResponse() - { - $item = ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); - - $user = User::fromResponse($this->chosenInlineResultFixture['from']); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Inline\ChosenInlineResult', $item); - $this->assertEquals($this->chosenInlineResultFixture['result_id'], $item->getResultId()); - $this->assertEquals($user, $item->getFrom()); - $this->assertEquals($this->chosenInlineResultFixture['query'], $item->getQuery()); - } - - public function testFromResponseException1() + protected static function getType() { - $this->expectException(InvalidArgumentException::class); - - unset($this->chosenInlineResultFixture['result_id']); - ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); - } - - public function testFromResponseException2() - { - $this->expectException(InvalidArgumentException::class); - - unset($this->chosenInlineResultFixture['from']); - ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); + return ChosenInlineResult::class; } - public function testFromResponseException3() + public static function getMinResponse() { - $this->expectException(InvalidArgumentException::class); - - unset($this->chosenInlineResultFixture['query']); - ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); + return [ + 'result_id' => 1, + 'from' => UserTest::getMinResponse(), + 'query' => 'test_query', + ]; } - public function testSetResultId() + public static function getFullResponse() { - $item = new ChosenInlineResult(); - $item->setResultId($this->chosenInlineResultFixture['result_id']); - $this->assertEquals($this->chosenInlineResultFixture['result_id'], $item->getResultId()); + return [ + 'result_id' => 1, + 'from' => UserTest::getMinResponse(), + 'query' => 'test_query', + 'location' => LocationTest::getMinResponse(), + 'inline_message_id' => 'inline_message_id', + ]; } - public function testSetFrom() + /** + * @param ChosenInlineResult $item + * @return void + */ + protected function assertMinItem($item) { - $item = new ChosenInlineResult(); - $user = User::fromResponse($this->chosenInlineResultFixture['from']); - $item->setFrom($user); - $this->assertEquals($user, $item->getFrom()); + $this->assertEquals(1, $item->getResultId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('test_query', $item->getQuery()); + $this->assertNull($item->getLocation()); + $this->assertNull($item->getInlineMessageId()); } - public function testSetQuery() + /** + * @param ChosenInlineResult $item + * @return void + */ + protected function assertFullItem($item) { - $item = new ChosenInlineResult(); - $item->setQuery('testQuery'); - $this->assertEquals('testQuery', $item->getQuery()); + $this->assertEquals(1, $item->getResultId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('test_query', $item->getQuery()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertEquals('inline_message_id', $item->getInlineMessageId()); } } diff --git a/tests/Types/Inline/InlineKeyboardMarkupTest.php b/tests/Types/Inline/InlineKeyboardMarkupTest.php index b2a1f6fe..bfe32d1e 100644 --- a/tests/Types/Inline/InlineKeyboardMarkupTest.php +++ b/tests/Types/Inline/InlineKeyboardMarkupTest.php @@ -2,11 +2,51 @@ namespace TelegramBot\Api\Test\Types\Inline; -use PHPUnit\Framework\TestCase; +use TelegramBot\Api\Test\AbstractTypeTest; use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; -class InlineKeyboardMarkupTest extends TestCase +class InlineKeyboardMarkupTest extends AbstractTypeTest { + protected static function getType() + { + return InlineKeyboardMarkup::class; + } + + public static function getMinResponse() + { + return [ + 'inline_keyboard' => [ + [ + ['url' => 'http://test.com', 'text' => 'Link'], + ['url' => 'http://test.com', 'text' => 'Link'], + ], + ], + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param InlineKeyboardMarkup $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]], $item->getInlineKeyboard()); + } + + /** + * @param InlineKeyboardMarkup $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } + public function testConstructor() { $item = new InlineKeyboardMarkup([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]]); diff --git a/tests/Types/Inline/InlineQueryTest.php b/tests/Types/Inline/InlineQueryTest.php index dc94e7c5..4256fe8e 100644 --- a/tests/Types/Inline/InlineQueryTest.php +++ b/tests/Types/Inline/InlineQueryTest.php @@ -2,108 +2,62 @@ namespace TelegramBot\Api\Test\Types\Inline; -use PHPUnit\Framework\TestCase; -use TelegramBot\Api\InvalidArgumentException; +use TelegramBot\Api\Test\AbstractTypeTest; +use TelegramBot\Api\Test\Types\LocationTest; +use TelegramBot\Api\Test\Types\UserTest; use TelegramBot\Api\Types\Inline\InlineQuery; -use TelegramBot\Api\Types\User; -class InlineQueryTest extends TestCase +class InlineQueryTest extends AbstractTypeTest { - protected $inlineQueryFixture = [ - 'id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - ], - 'query' => 'test_query', - 'offset' => '20' - ]; - - public function testFromResponse1() - { - $item = InlineQuery::fromResponse($this->inlineQueryFixture); - - $user = User::fromResponse($this->inlineQueryFixture['from']); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Inline\InlineQuery', $item); - $this->assertEquals(1, $item->getId()); - $this->assertEquals($user, $item->getFrom()); - $this->assertEquals('20', $item->getOffset()); - } - - public function testFromResponse2() - { - $this->inlineQueryFixture['offset'] = ''; - $item = InlineQuery::fromResponse($this->inlineQueryFixture); - - $user = User::fromResponse($this->inlineQueryFixture['from']); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Inline\InlineQuery', $item); - $this->assertEquals(1, $item->getId()); - $this->assertEquals($user, $item->getFrom()); - $this->assertEquals('', $item->getOffset()); - } - - public function testFromResponseException1() - { - $this->expectException(InvalidArgumentException::class); - - unset($this->inlineQueryFixture['id']); - InlineQuery::fromResponse($this->inlineQueryFixture); - } - - public function testFromResponseException2() + protected static function getType() { - $this->expectException(InvalidArgumentException::class); - - unset($this->inlineQueryFixture['from']); - InlineQuery::fromResponse($this->inlineQueryFixture); + return InlineQuery::class; } - public function testFromResponseException3() + public static function getMinResponse() { - $this->expectException(InvalidArgumentException::class); - - unset($this->inlineQueryFixture['query']); - InlineQuery::fromResponse($this->inlineQueryFixture); + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + 'query' => 'test_query', + 'offset' => '20' + ]; } - public function testFromResponseException4() + public static function getFullResponse() { - $this->expectException(InvalidArgumentException::class); - - unset($this->inlineQueryFixture['offset']); - InlineQuery::fromResponse($this->inlineQueryFixture); + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + 'location' => LocationTest::getMinResponse(), + 'query' => 'test_query', + 'offset' => '20' + ]; } - public function testSetId() + /** + * @param InlineQuery $item + * @return void + */ + protected function assertMinItem($item) { - $item = new InlineQuery(); - $item->setId('testId'); - $this->assertEquals('testId', $item->getId()); - } - - public function testSetFrom() - { - $item = new InlineQuery(); - $user = User::fromResponse($this->inlineQueryFixture['from']); - $item->setFrom($user); - $this->assertEquals($user, $item->getFrom()); - } - - public function testSetQuery() - { - $item = new InlineQuery(); - $item->setQuery('testQuery'); - $this->assertEquals('testQuery', $item->getQuery()); + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('test_query', $item->getQuery()); + $this->assertEquals('20', $item->getOffset()); + $this->assertNull($item->getLocation()); } - public function testSetOffset() + /** + * @param InlineQuery $item + * @return void + */ + protected function assertFullItem($item) { - $item = new InlineQuery(); - $item->setOffset('20'); + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('test_query', $item->getQuery()); $this->assertEquals('20', $item->getOffset()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); } } diff --git a/tests/Types/LocationTest.php b/tests/Types/LocationTest.php new file mode 100644 index 00000000..28f6799a --- /dev/null +++ b/tests/Types/LocationTest.php @@ -0,0 +1,88 @@ + 55.585827, + 'longitude' => 37.675309, + ]; + } + + public static function getFullResponse() + { + return [ + 'latitude' => 55.585827, + 'longitude' => 37.675309, + 'horizontal_accuracy' => 20.5, + 'live_period' => 300, + 'heading' => 100, + 'proximity_alert_radius' => 15 + ]; + } + + /** + * @param Location $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(55.585827, $item->getLatitude()); + $this->assertEquals(37.675309, $item->getLongitude()); + $this->assertNull($item->getHorizontalAccuracy()); + $this->assertNull($item->getLivePeriod()); + $this->assertNull($item->getHeading()); + $this->assertNull($item->getProximityAlertRadius()); + } + + /** + * @param Location $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(55.585827, $item->getLatitude()); + $this->assertEquals(37.675309, $item->getLongitude()); + $this->assertEquals(20.5, $item->getHorizontalAccuracy()); + $this->assertEquals(300, $item->getLivePeriod()); + $this->assertEquals(100, $item->getHeading()); + $this->assertEquals(15, $item->getProximityAlertRadius()); + } + + public function testSetHorizontalAccuracyException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Location(); + $item->setHorizontalAccuracy('s'); + } + + public function testSetLatitudeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Location(); + $item->setLatitude('s'); + } + + public function testSetLongitudeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Location(); + $item->setLongitude('s'); + } + +} diff --git a/tests/Types/LoginUrlTest.php b/tests/Types/LoginUrlTest.php new file mode 100644 index 00000000..7cc00bf0 --- /dev/null +++ b/tests/Types/LoginUrlTest.php @@ -0,0 +1,55 @@ + 'https://telegram.org', + ]; + } + + public static function getFullResponse() + { + return [ + 'url' => 'https://telegram.org', + 'forward_text' => 'Log in!', + 'bot_username' => 'TestBot', + 'request_write_access' => true + ]; + } + + /** + * @param LoginUrl $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('https://telegram.org', $item->getUrl()); + $this->assertNull($item->getForwardText()); + $this->assertNull($item->getBotUsername()); + $this->assertNull($item->isRequestWriteAccess()); + } + + /** + * @param LoginUrl $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('https://telegram.org', $item->getUrl()); + $this->assertEquals('Log in!', $item->getForwardText()); + $this->assertEquals('TestBot', $item->getBotUsername()); + $this->assertEquals(true, $item->isRequestWriteAccess()); + } +} diff --git a/tests/Types/MaskPositionTest.php b/tests/Types/MaskPositionTest.php new file mode 100644 index 00000000..3641c417 --- /dev/null +++ b/tests/Types/MaskPositionTest.php @@ -0,0 +1,50 @@ + 'mouth', + 'x_shift' => 1.0, + 'y_shift' => 1.0, + 'scale' => 2.0, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param MaskPosition $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('mouth', $item->getPoint()); + $this->assertEquals('1.0', $item->getXShift()); + $this->assertEquals('1.0', $item->getYShift()); + $this->assertEquals('2.0', $item->getScale()); + } + + /** + * @param MaskPosition $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/MessageEntityTest.php b/tests/Types/MessageEntityTest.php index 2a7f6470..d3f4ed8e 100644 --- a/tests/Types/MessageEntityTest.php +++ b/tests/Types/MessageEntityTest.php @@ -2,43 +2,66 @@ namespace TelegramBot\Api\Test\Types; -use PHPUnit\Framework\TestCase; +use TelegramBot\Api\Test\AbstractTypeTest; use TelegramBot\Api\Types\MessageEntity; -use TelegramBot\Api\Types\User; -class MessageEntityTest extends TestCase +class MessageEntityTest extends AbstractTypeTest { - public function testTextMentionFromResponse() + protected static function getType() { - $messageEntity = MessageEntity::fromResponse([ + return MessageEntity::class; + } + + public static function getMinResponse() + { + return [ 'type' => 'text_mention', 'offset' => 108, 'length' => 10, - 'user' => [ - 'id' => 4815162342, - 'is_bot' => false, - 'first_name' => 'John', - 'last_name' => 'Locke', - 'username' => 'hunter', - 'language_code' => 'en', - ], - 'custom_emoji_id' => 1, - ]); + ]; + } - $this->assertInstanceOf(MessageEntity::class, $messageEntity); - $this->assertEquals(MessageEntity::TYPE_TEXT_MENTION, $messageEntity->getType()); - $this->assertEquals(108, $messageEntity->getOffset()); - $this->assertEquals(10, $messageEntity->getLength()); - $this->assertNull($messageEntity->getUrl()); - $this->assertInstanceOf(User::class, $messageEntity->getUser()); - $this->assertEquals(4815162342, $messageEntity->getUser()->getId()); - $this->assertFalse($messageEntity->getUser()->isBot()); - $this->assertEquals('John', $messageEntity->getUser()->getFirstName()); - $this->assertEquals('Locke', $messageEntity->getUser()->getLastName()); - $this->assertEquals('hunter', $messageEntity->getUser()->getUsername()); - $this->assertEquals('en', $messageEntity->getUser()->getLanguageCode()); - $this->assertNull($messageEntity->getLanguage()); - $this->assertEquals(1, $messageEntity->getCustomEmojiId()); + public static function getFullResponse() + { + return [ + 'type' => 'text_mention', + 'offset' => 108, + 'length' => 10, + 'url' => 'url', + 'user' => UserTest::getMinResponse(), + 'language' => 'language', + 'custom_emoji_id' => 'custom_emoji_id', + ]; + } + + /** + * @param MessageEntity $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(MessageEntity::TYPE_TEXT_MENTION, $item->getType()); + $this->assertEquals(108, $item->getOffset()); + $this->assertEquals(10, $item->getLength()); + $this->assertNull($item->getUrl()); + $this->assertNull($item->getUser()); + $this->assertNull($item->getLanguage()); + $this->assertNull($item->getCustomEmojiId()); + } + + /** + * @param MessageEntity $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(MessageEntity::TYPE_TEXT_MENTION, $item->getType()); + $this->assertEquals(108, $item->getOffset()); + $this->assertEquals(10, $item->getLength()); + $this->assertEquals('url', $item->getUrl()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + $this->assertEquals('language', $item->getLanguage()); + $this->assertEquals('custom_emoji_id', $item->getCustomEmojiId()); } public function testPreFromResponse() diff --git a/tests/Types/MessageTest.php b/tests/Types/MessageTest.php new file mode 100644 index 00000000..03415489 --- /dev/null +++ b/tests/Types/MessageTest.php @@ -0,0 +1,307 @@ + 1, + 'date' => 1682343644, + 'chat' => ChatTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'message_id' => 1, + 'date' => 1682343644, + 'chat' => ChatTest::getMinResponse(), + + 'from' => UserTest::getMinResponse(), + 'forward_from' => UserTest::getMinResponse(), + 'forward_from_chat' => ChatTest::getMinResponse(), + 'forward_from_message_id' => 2, + 'forward_date' => 1682343645, + 'forward_signature' => 'forward_signature', + 'forward_sender_name' => 'forward_sender_name', + 'reply_to_message' => MessageTest::getMinResponse(), + 'via_bot' => UserTest::getMinResponse(), + 'edit_date' => 1682343643, + 'media_group_id' => 3, + 'author_signature' => 'author_signature', + 'text' => 'text', + 'entities' => [ + MessageEntityTest::getMinResponse() + ], + 'caption_entities' => [ + MessageEntityTest::getMinResponse() + ], + 'audio' => AudioTest::getMinResponse(), + 'document' => DocumentTest::getMinResponse(), + 'animation' => AnimationTest::getMinResponse(), + 'photo' => [ + PhotoSizeTest::getMinResponse(), + ], + 'sticker' => StickerTest::getMinResponse(), + 'video' => VideoTest::getMinResponse(), + 'voice' => VoiceTest::getMinResponse(), + 'caption' => 'caption', + 'contact' => ContactTest::getMinResponse(), + 'location' => LocationTest::getMinResponse(), + 'venue' => VenueTest::getMinResponse(), + 'poll' => PollTest::getMinResponse(), + 'dice' => DiceTest::getMinResponse(), + 'new_chat_members' => [ + UserTest::getMinResponse(), + ], + 'left_chat_member' => UserTest::getMinResponse(), + 'new_chat_title' => 'new_chat_title', + 'new_chat_photo' => [ + PhotoSizeTest::getMinResponse(), + ], + 'delete_chat_photo' => true, + 'group_chat_created' => true, + 'supergroup_chat_created' => true, + 'channel_chat_created' => true, + 'migrate_to_chat_id' => 4, + 'migrate_from_chat_id' => 5, + 'pinned_message' => MessageTest::getMinResponse(), + 'invoice' => InvoiceTest::getMinResponse(), + 'successful_payment' => SuccessfulPaymentTest::getMinResponse(), + 'connected_website' => 'connected_website', + 'forum_topic_created' => ForumTopicCreatedTest::getMinResponse(), + 'forum_topic_closed' => ForumTopicClosedTest::getMinResponse(), + 'forum_topic_reopened' => ForumTopicReopenedTest::getMinResponse(), + 'is_topic_message' => true, + 'message_thread_id' => 6, + 'reply_markup' => InlineKeyboardMarkupTest::getMinResponse() + ]; + } + + /** + * @param Message $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + + $this->assertNull($item->getFrom()); + $this->assertNull($item->getForwardFrom()); + $this->assertNull($item->getForwardFromChat()); + $this->assertNull($item->getForwardFromMessageId()); + $this->assertNull($item->getForwardDate()); + $this->assertNull($item->getForwardSignature()); + $this->assertNull($item->getForwardSenderName()); + $this->assertNull($item->getReplyToMessage()); + $this->assertNull($item->getViaBot()); + $this->assertNull($item->getEditDate()); + $this->assertNull($item->getMediaGroupId()); + $this->assertNull($item->getAuthorSignature()); + $this->assertNull($item->getText()); + $this->assertNull($item->getEntities()); + $this->assertNull($item->getCaptionEntities()); + $this->assertNull($item->getAudio()); + $this->assertNull($item->getDocument()); + $this->assertNull($item->getAnimation()); + $this->assertNull($item->getPhoto()); + $this->assertNull($item->getSticker()); + $this->assertNull($item->getVideo()); + $this->assertNull($item->getVoice()); + $this->assertNull($item->getCaption()); + $this->assertNull($item->getContact()); + $this->assertNull($item->getLocation()); + $this->assertNull($item->getVenue()); + $this->assertNull($item->getPoll()); + $this->assertNull($item->getDice()); + $this->assertNull($item->getNewChatMembers()); + $this->assertNull($item->getLeftChatMember()); + $this->assertNull($item->getNewChatTitle()); + $this->assertNull($item->getNewChatPhoto()); + $this->assertNull($item->isDeleteChatPhoto()); + $this->assertNull($item->isGroupChatCreated()); + $this->assertNull($item->isSupergroupChatCreated()); + $this->assertNull($item->isChannelChatCreated()); + $this->assertNull($item->getMigrateToChatId()); + $this->assertNull($item->getMigrateFromChatId()); + $this->assertNull($item->getPinnedMessage()); + $this->assertNull($item->getInvoice()); + $this->assertNull($item->getSuccessfulPayment()); + $this->assertNull($item->getConnectedWebsite()); + $this->assertNull($item->getForumTopicCreated()); + $this->assertNull($item->getForumTopicClosed()); + $this->assertNull($item->getForumTopicReopened()); + $this->assertNull($item->getIsTopicMessage()); + $this->assertNull($item->getMessageThreadId()); + $this->assertNull($item->getReplyMarkup()); + } + + /** + * @param Message $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(UserTest::createMinInstance(), $item->getForwardFrom()); + $this->assertEquals(ChatTest::createMinInstance(), $item->getForwardFromChat()); + $this->assertEquals(2, $item->getForwardFromMessageId()); + $this->assertEquals(1682343645, $item->getForwardDate()); + $this->assertEquals('forward_signature', $item->getForwardSignature()); + $this->assertEquals('forward_sender_name', $item->getForwardSenderName()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getReplyToMessage()); + $this->assertEquals(UserTest::createMinInstance(), $item->getViaBot()); + $this->assertEquals(1682343643, $item->getEditDate()); + $this->assertEquals(3, $item->getMediaGroupId()); + $this->assertEquals('author_signature', $item->getAuthorSignature()); + $this->assertEquals('text', $item->getText()); + $this->assertEquals([MessageEntityTest::createMinInstance()], $item->getEntities()); + $this->assertEquals([MessageEntityTest::createMinInstance()], $item->getCaptionEntities()); + $this->assertEquals(AudioTest::createMinInstance(), $item->getAudio()); + $this->assertEquals(DocumentTest::createMinInstance(), $item->getDocument()); + $this->assertEquals(AnimationTest::createMinInstance(), $item->getAnimation()); + $this->assertEquals([PhotoSizeTest::createMinInstance()], $item->getPhoto()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(VideoTest::createMinInstance(), $item->getVideo()); + $this->assertEquals(VoiceTest::createMinInstance(), $item->getVoice()); + $this->assertEquals('caption', $item->getCaption()); + $this->assertEquals(ContactTest::createMinInstance(), $item->getContact()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertEquals(VenueTest::createMinInstance(), $item->getVenue()); + $this->assertEquals(PollTest::createMinInstance(), $item->getPoll()); + $this->assertEquals(DiceTest::createMinInstance(), $item->getDice()); + $this->assertEquals([UserTest::createMinInstance()], $item->getNewChatMembers()); + $this->assertEquals(UserTest::createMinInstance(), $item->getLeftChatMember()); + $this->assertEquals('new_chat_title', $item->getNewChatTitle()); + $this->assertEquals([PhotoSizeTest::createMinInstance()], $item->getNewChatPhoto()); + $this->assertTrue($item->isDeleteChatPhoto()); + $this->assertTrue($item->isGroupChatCreated()); + $this->assertTrue($item->isSupergroupChatCreated()); + $this->assertTrue($item->isChannelChatCreated()); + $this->assertEquals(4, $item->getMigrateToChatId()); + $this->assertEquals(5, $item->getMigrateFromChatId()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getPinnedMessage()); + $this->assertEquals(InvoiceTest::createMinInstance(), $item->getInvoice()); + $this->assertEquals(SuccessfulPaymentTest::createMinInstance(), $item->getSuccessfulPayment()); + $this->assertEquals('connected_website', $item->getConnectedWebsite()); + $this->assertEquals(ForumTopicCreatedTest::createMinInstance(), $item->getForumTopicCreated()); + // $this->assertEquals(ForumTopicClosedTest::createMinInstance(), $item->getForumTopicClosed()); + // $this->assertEquals(ForumTopicReopenedTest::createMinInstance(), $item->getForumTopicReopened()); + $this->assertTrue($item->getIsTopicMessage()); + $this->assertEquals(6, $item->getMessageThreadId()); + $this->assertEquals(InlineKeyboardMarkupTest::createMinInstance(), $item->getReplyMarkup()); + } + + public function testSet64bitMessageId() + { + $item = new Message(); + $item->setMessageId(2147483648); + $this->assertEquals(2147483648, $item->getMessageId()); + } + + public function testSetMessageIdException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Message(); + $item->setMessageId('s'); + } + + public function testSetDateException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Message(); + $item->setDate('s'); + } + + public function testSetEditDateException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Message(); + $item->setEditDate('s'); + } + + public function testSetForwardDateException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Message(); + $item->setForwardDate('s'); + } + + public function testToJson1() + { + $data = [ + 'message_id' => 1, + 'from' => [ + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'id' => 123456, + 'username' => 'iGusev' + ], + 'date' => 2, + 'chat' => [ + 'id' => 1, + 'type' => 'group', + 'title' => 'test chat' + ], + 'migrate_from_chat_id' => 3 + ]; + + $item = Message::fromResponse($data); + $this->assertJson(json_encode($data), $item->toJson()); + } + + public function testToJson2() + { + $data = [ + 'message_id' => 1, + 'from' => [ + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'id' => 123456, + 'username' => 'iGusev' + ], + 'date' => 2, + 'chat' => [ + 'id' => 1, + 'type' => 'group', + 'title' => 'test chat' + ], + 'entities' => [ + [ + 'type' => 'bot_command', + 'offset' => 0, + 'length' => 7, + ] + ], + 'migrate_from_chat_id' => 3 + ]; + + $item = Message::fromResponse($data); + $this->assertJson(json_encode($data), $item->toJson()); + } +} diff --git a/tests/Types/Payments/InvoiceTest.php b/tests/Types/Payments/InvoiceTest.php new file mode 100644 index 00000000..302aea91 --- /dev/null +++ b/tests/Types/Payments/InvoiceTest.php @@ -0,0 +1,52 @@ + 'title', + 'description' => 'description', + 'start_parameter' => 'start_parameter', + 'currency' => 'currency', + 'total_amount' => 1000, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param Invoice $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('description', $item->getDescription()); + $this->assertEquals('start_parameter', $item->getStartParameter()); + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + } + + /** + * @param Invoice $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/Payments/OrderInfoTest.php b/tests/Types/Payments/OrderInfoTest.php new file mode 100644 index 00000000..106d6f32 --- /dev/null +++ b/tests/Types/Payments/OrderInfoTest.php @@ -0,0 +1,53 @@ + 'name', + 'phone_number' => 'phone_number', + 'email' => 'email', + 'shipping_address' => ShippingAddressTest::getMinResponse() + ]; + } + + /** + * @param OrderInfo $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertNull($item->getName()); + $this->assertNull($item->getPhoneNumber()); + $this->assertNull($item->getEmail()); + $this->assertNull($item->getShippingAddress()); + } + + /** + * @param OrderInfo $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals('phone_number', $item->getPhoneNumber()); + $this->assertEquals('email', $item->getEmail()); + $this->assertEquals(ShippingAddressTest::createMinInstance(), $item->getShippingAddress()); + } +} diff --git a/tests/Types/Payments/Query/PreCheckoutQueryTest.php b/tests/Types/Payments/Query/PreCheckoutQueryTest.php new file mode 100644 index 00000000..cecf7dee --- /dev/null +++ b/tests/Types/Payments/Query/PreCheckoutQueryTest.php @@ -0,0 +1,70 @@ + 1, + 'from' => UserTest::getMinResponse(), + 'currency' => 'currency', + 'total_amount' => 1000, + 'invoice_payload' => 'invoice_payload', + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + 'currency' => 'currency', + 'total_amount' => 1000, + 'invoice_payload' => 'invoice_payload', + 'shipping_option_id' => 'shipping_option_id', + 'order_info' => OrderInfoTest::getFullResponse() + ]; + } + + /** + * @param PreCheckoutQuery $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertNull($item->getShippingOptionId()); + $this->assertNull($item->getOrderInfo()); + } + + /** + * @param PreCheckoutQuery $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertEquals('shipping_option_id', $item->getShippingOptionId()); + $this->assertEquals(OrderInfoTest::createFullInstance(), $item->getOrderInfo()); + } +} diff --git a/tests/Types/Payments/Query/ShippingQueryTest.php b/tests/Types/Payments/Query/ShippingQueryTest.php new file mode 100644 index 00000000..413544af --- /dev/null +++ b/tests/Types/Payments/Query/ShippingQueryTest.php @@ -0,0 +1,52 @@ + 1, + 'from' => UserTest::getMinResponse(), + 'invoice_payload' => 'invoice_payload', + 'shipping_address' => ShippingAddressTest::getMinResponse() + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ShippingQuery $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertEquals(ShippingAddressTest::createMinInstance(), $item->getShippingAddress()); + } + + /** + * @param ShippingQuery $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/Payments/ShippingAddressTest.php b/tests/Types/Payments/ShippingAddressTest.php new file mode 100644 index 00000000..d2016075 --- /dev/null +++ b/tests/Types/Payments/ShippingAddressTest.php @@ -0,0 +1,54 @@ + 'country_code', + 'state' => 'state', + 'city' => 'city', + 'street_line1' => 'street_line1', + 'street_line2' => 'street_line2', + 'post_code' => 'post_code', + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ShippingAddress $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('country_code', $item->getCountryCode()); + $this->assertEquals('state', $item->getState()); + $this->assertEquals('city', $item->getCity()); + $this->assertEquals('street_line1', $item->getStreetLine1()); + $this->assertEquals('street_line2', $item->getStreetLine2()); + $this->assertEquals('post_code', $item->getPostCode()); + } + + /** + * @param ShippingAddress $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/Payments/SuccessfulPaymentTest.php b/tests/Types/Payments/SuccessfulPaymentTest.php new file mode 100644 index 00000000..2c55c294 --- /dev/null +++ b/tests/Types/Payments/SuccessfulPaymentTest.php @@ -0,0 +1,68 @@ + 'currency', + 'total_amount' => 1000, + 'invoice_payload' => 'invoice_payload', + 'telegram_payment_charge_id' => 'telegram_payment_charge_id', + 'provider_payment_charge_id' => 'provider_payment_charge_id', + ]; + } + + public static function getFullResponse() + { + return [ + 'currency' => 'currency', + 'total_amount' => 1000, + 'invoice_payload' => 'invoice_payload', + 'telegram_payment_charge_id' => 'telegram_payment_charge_id', + 'provider_payment_charge_id' => 'provider_payment_charge_id', + 'shipping_option_id' => 'shipping_option_id', + 'order_info' => OrderInfoTest::getFullResponse(), + ]; + } + + /** + * @param SuccessfulPayment $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertEquals('telegram_payment_charge_id', $item->getTelegramPaymentChargeId()); + $this->assertEquals('provider_payment_charge_id', $item->getProviderPaymentChargeId()); + $this->assertNull($item->getShippingOptionId()); + $this->assertNull($item->getOrderInfo()); + } + + /** + * @param SuccessfulPayment $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertEquals('telegram_payment_charge_id', $item->getTelegramPaymentChargeId()); + $this->assertEquals('provider_payment_charge_id', $item->getProviderPaymentChargeId()); + $this->assertEquals('shipping_option_id', $item->getShippingOptionId()); + $this->assertEquals(OrderInfoTest::createFullInstance(), $item->getOrderInfo()); + } +} diff --git a/tests/Types/PhotoSizeTest.php b/tests/Types/PhotoSizeTest.php new file mode 100644 index 00000000..6b3e9dda --- /dev/null +++ b/tests/Types/PhotoSizeTest.php @@ -0,0 +1,86 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'height' => 2, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'height' => 2, + 'file_size' => 3 + ]; + } + + /** + * @param PhotoSize $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertNull($item->getFileSize()); + } + + /** + * @param PhotoSize $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(3, $item->getFileSize()); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new PhotoSize(); + $item->setFileSize('s'); + } + + public function testSetHeightException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new PhotoSize(); + $item->setHeight('s'); + } + + public function testSetWidthException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new PhotoSize(); + $item->setWidth('s'); + } +} diff --git a/tests/Types/PollAnswerTest.php b/tests/Types/PollAnswerTest.php new file mode 100644 index 00000000..4c3b0ce1 --- /dev/null +++ b/tests/Types/PollAnswerTest.php @@ -0,0 +1,49 @@ + [1,2,3,4,5,6], + 'user' => UserTest::getMinResponse(), + 'poll_id' => 123456789, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param PollAnswer $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(123456789, $item->getPollId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals([1,2,3,4,5,6], $item->getOptionIds()); + } + + /** + * @param PollAnswer $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/PollOptionTest.php b/tests/Types/PollOptionTest.php new file mode 100644 index 00000000..f1095066 --- /dev/null +++ b/tests/Types/PollOptionTest.php @@ -0,0 +1,46 @@ + 'text', + 'voter_count' => 3 + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param PollOption $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('text', $item->getText()); + $this->assertEquals(3, $item->getVoterCount()); + } + + /** + * @param PollOption $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/PollTest.php b/tests/Types/PollTest.php new file mode 100644 index 00000000..463b95ce --- /dev/null +++ b/tests/Types/PollTest.php @@ -0,0 +1,81 @@ + 123456789, + 'question' => 'What is the name of Heisenberg from "Breaking bad"?', + 'options' => [ + PollOptionTest::getMinResponse(), + ], + 'total_voter_count' => 17, + 'is_closed' => true, + 'is_anonymous' => true, + 'type' => 'regular', + 'allows_multiple_answers' => true, + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 123456789, + 'question' => 'What is the name of Heisenberg from "Breaking bad"?', + 'options' => [ + PollOptionTest::getMinResponse(), + ], + 'total_voter_count' => 17, + 'is_closed' => true, + 'is_anonymous' => true, + 'type' => 'regular', + 'allows_multiple_answers' => true, + 'correct_option_id' => 2, + ]; + } + + /** + * @param Poll $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(123456789, $item->getId()); + $this->assertEquals('What is the name of Heisenberg from "Breaking bad"?', $item->getQuestion()); + $this->assertEquals([PollOptionTest::createMinInstance()], $item->getOptions()); + $this->assertEquals(17, $item->getTotalVoterCount()); + $this->assertTrue($item->isClosed()); + $this->assertTrue($item->isAnonymous()); + $this->assertEquals('regular', $item->getType()); + $this->assertTrue($item->isAllowsMultipleAnswers()); + $this->assertNull($item->getCorrectOptionId()); + } + + /** + * @param Poll $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(123456789, $item->getId()); + $this->assertEquals('What is the name of Heisenberg from "Breaking bad"?', $item->getQuestion()); + $this->assertEquals([PollOptionTest::createMinInstance()], $item->getOptions()); + $this->assertEquals(17, $item->getTotalVoterCount()); + $this->assertTrue($item->isClosed()); + $this->assertTrue($item->isAnonymous()); + $this->assertEquals('regular', $item->getType()); + $this->assertTrue($item->isAllowsMultipleAnswers()); + $this->assertEquals(2, $item->getCorrectOptionId()); + } +} diff --git a/tests/Types/ReplyKeyboardHideTest.php b/tests/Types/ReplyKeyboardHideTest.php new file mode 100644 index 00000000..8aef3f4b --- /dev/null +++ b/tests/Types/ReplyKeyboardHideTest.php @@ -0,0 +1,81 @@ + true, + ]; + } + + public static function getFullResponse() + { + return [ + 'hide_keyboard' => true, + 'selective' => true + ]; + } + + /** + * @param ReplyKeyboardHide $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(null, $item->isSelective()); + } + + /** + * @param ReplyKeyboardHide $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(true, $item->isSelective()); + } + + public function testConstructor() + { + $item = new ReplyKeyboardHide(); + + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(null, $item->isSelective()); + } + + public function testConstructor2() + { + $item = new ReplyKeyboardHide(true, true); + + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(true, $item->isSelective()); + } + + public function testConstructor3() + { + $item = new ReplyKeyboardHide(false, true); + + $this->assertEquals(false, $item->isHideKeyboard()); + $this->assertEquals(true, $item->isSelective()); + } + + public function testConstructor4() + { + $item = new ReplyKeyboardHide(true); + + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(null, $item->isSelective()); + } +} diff --git a/tests/ReplyKeyboardMarkupTest.php b/tests/Types/ReplyKeyboardMarkupTest.php similarity index 51% rename from tests/ReplyKeyboardMarkupTest.php rename to tests/Types/ReplyKeyboardMarkupTest.php index 0305895e..14ca6c64 100644 --- a/tests/ReplyKeyboardMarkupTest.php +++ b/tests/Types/ReplyKeyboardMarkupTest.php @@ -1,12 +1,58 @@ [['one', 'two']], + ]; + } + + public static function getFullResponse() + { + return [ + 'keyboard' => [['one', 'two']], + 'one_time_keyboard' => true, + 'resize_keyboard' => true, + 'selective' => true + ]; + } + + /** + * @param ReplyKeyboardMarkup $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertNull($item->isOneTimeKeyboard()); + $this->assertNull($item->isResizeKeyboard()); + $this->assertNull($item->isSelective()); + } + + /** + * @param ReplyKeyboardMarkup $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(true, $item->isSelective()); + } + public function testConstructor() { $item = new ReplyKeyboardMarkup([['one', 'two']]); @@ -46,81 +92,4 @@ public function testConstructor4() $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(true, $item->isSelective()); } - - public function testSetKeyboard() - { - $item = new ReplyKeyboardMarkup([['one', 'two']]); - $item->setKeyboard([['one', 'two', 'three']]); - - $this->assertEquals([['one', 'two', 'three']], $item->getKeyboard()); - } - - public function testSetSelective() - { - $item = new ReplyKeyboardMarkup([['one', 'two']]); - $item->setSelective(true); - - $this->assertEquals(true, $item->isSelective()); - } - - public function testSetOneTimeKeyboard() - { - $item = new ReplyKeyboardMarkup([['one', 'two']]); - $item->setOneTimeKeyboard(false); - - $this->assertEquals(false, $item->isOneTimeKeyboard()); - } - - public function testSetResizeKeyboard() - { - $item = new ReplyKeyboardMarkup([['one', 'two']]); - $item->setResizeKeyboard(true); - - $this->assertEquals(true, $item->isResizeKeyboard()); - } - - public function testToJson() - { - $item = new ReplyKeyboardMarkup([['one', 'two']]); - - $this->assertEquals(json_encode(['keyboard' => [['one', 'two']]]), $item->toJson()); - } - - public function testToJson2() - { - $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true); - - $this->assertEquals( - json_encode([ - 'keyboard' => [['one', 'two']], - 'one_time_keyboard' => true, - 'resize_keyboard' => true, - 'selective' => true, - ]), - $item->toJson() - ); - } - - public function testToJson3() - { - $item = new ReplyKeyboardMarkup([['one', 'two']]); - - $this->assertEquals(['keyboard' => [['one', 'two']]], $item->toJson(true)); - } - - public function testToJson4() - { - $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true); - - $this->assertEquals( - [ - 'keyboard' => [['one', 'two']], - 'one_time_keyboard' => true, - 'resize_keyboard' => true, - 'selective' => true, - ], - $item->toJson(true) - ); - } - } diff --git a/tests/Types/ReplyKeyboardRemoveTest.php b/tests/Types/ReplyKeyboardRemoveTest.php new file mode 100644 index 00000000..d5fde809 --- /dev/null +++ b/tests/Types/ReplyKeyboardRemoveTest.php @@ -0,0 +1,65 @@ + true, + ]; + } + + public static function getFullResponse() + { + return [ + 'remove_keyboard' => true, + 'selective' => true + ]; + } + + /** + * @param ReplyKeyboardRemove $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(true, $item->getRemoveKeyboard()); + $this->assertEquals(false, $item->getSelective()); + } + + /** + * @param ReplyKeyboardRemove $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(true, $item->getRemoveKeyboard()); + $this->assertEquals(true, $item->getSelective()); + } + + public function testDefaultConstructor() + { + $keyboard = new ReplyKeyboardRemove(); + + $this->assertEquals(true, $keyboard->getRemoveKeyboard()); + $this->assertEquals(false, $keyboard->getSelective()); + } + + public function testConstructor() + { + $keyboard = new ReplyKeyboardRemove(false, true); + + $this->assertEquals(false, $keyboard->getRemoveKeyboard()); + $this->assertEquals(true, $keyboard->getSelective()); + } +} diff --git a/tests/Types/StickerSetTest.php b/tests/Types/StickerSetTest.php new file mode 100644 index 00000000..e5867ba8 --- /dev/null +++ b/tests/Types/StickerSetTest.php @@ -0,0 +1,73 @@ + 'name', + 'title' => 'title', + 'sticker_type' => 'regular', + 'is_animated' => true, + 'is_video' => true, + 'stickers' => [ + StickerTest::getMinResponse(), + ], + ]; + } + + public static function getFullResponse() + { + return [ + 'name' => 'name', + 'title' => 'title', + 'sticker_type' => 'regular', + 'is_animated' => true, + 'is_video' => true, + 'stickers' => [ + StickerTest::getMinResponse(), + ], + 'thumb' => PhotoSizeTest::getMinResponse(), + ]; + } + + /** + * @param StickerSet $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('regular', $item->getStickerType()); + $this->assertEquals(true, $item->getIsAnimated()); + $this->assertEquals(true, $item->getIsVideo()); + $this->assertEquals([StickerTest::createMinInstance()], $item->getStickers()); + $this->assertNull($item->getThumb()); + } + + /** + * @param StickerSet $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('regular', $item->getStickerType()); + $this->assertEquals(true, $item->getIsAnimated()); + $this->assertEquals(true, $item->getIsVideo()); + $this->assertEquals([StickerTest::createMinInstance()], $item->getStickers()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + } +} diff --git a/tests/Types/StickerTest.php b/tests/Types/StickerTest.php new file mode 100644 index 00000000..e9a614e3 --- /dev/null +++ b/tests/Types/StickerTest.php @@ -0,0 +1,109 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'type' => 'regular', + 'width' => 1, + 'height' => 2, + 'is_animated' => false, + 'is_video' => false, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'type' => 'regular', + 'width' => 1, + 'height' => 2, + 'is_animated' => false, + 'is_video' => false, + 'file_size' => 3, + 'premium_animation' => FileTest::getMinResponse(), + 'emoji' => '🎉', + 'thumb' => PhotoSizeTest::getMinResponse(), + 'set_name' => 'set', + 'custom_emoji_id' => 'custom_emoji_id', + 'mask_position' => MaskPositionTest::getMinResponse(), + ]; + } + + /** + * @param Sticker $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals('regular', $item->getType()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(false, $item->getIsAnimated()); + $this->assertEquals(false, $item->getIsVideo()); + } + + /** + * @param Sticker $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals('regular', $item->getType()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals(false, $item->getIsAnimated()); + $this->assertEquals(FileTest::createMinInstance(), $item->getPremiumAnimation()); + $this->assertEquals(false, $item->getIsVideo()); + $this->assertEquals('🎉', $item->getEmoji()); + $this->assertEquals('set', $item->getSetName()); + $this->assertEquals('custom_emoji_id', $item->getCustomEmojiId()); + $this->assertEquals(MaskPositionTest::createMinInstance(), $item->getMaskPosition()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Sticker(); + $item->setFileSize('s'); + } + + public function testSetHeightException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Sticker(); + $item->setHeight('s'); + } + + public function testSetWidthException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Sticker(); + $item->setWidth('s'); + } +} diff --git a/tests/Types/UpdateTest.php b/tests/Types/UpdateTest.php new file mode 100644 index 00000000..21a7ffbc --- /dev/null +++ b/tests/Types/UpdateTest.php @@ -0,0 +1,83 @@ + 10, + ]; + } + + public static function getFullResponse() + { + return [ + 'update_id' => 10, + 'message' => MessageTest::getMinResponse(), + 'edited_message' => MessageTest::getMinResponse(), + 'channel_post' => MessageTest::getMinResponse(), + 'edited_channel_post' => MessageTest::getMinResponse(), + 'inline_query' => InlineQueryTest::getMinResponse(), + 'chosen_inline_result' => ChosenInlineResultTest::getMinResponse(), + 'callback_query' => CallbackQueryTest::getMinResponse(), + 'shipping_query' => ShippingQueryTest::getMinResponse(), + 'pre_checkout_query' => PreCheckoutQueryTest::getMinResponse(), + 'poll_answer' => PollAnswerTest::getMinResponse(), + 'poll' => PollTest::getMinResponse(), + ]; + } + + /** + * @param $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(10, $item->getUpdateId()); + $this->assertNull($item->getMessage()); + $this->assertNull($item->getEditedMessage()); + $this->assertNull($item->getChannelPost()); + $this->assertNull($item->getEditedChannelPost()); + $this->assertNull($item->getInlineQuery()); + $this->assertNull($item->getChosenInlineResult()); + $this->assertNull($item->getCallbackQuery()); + $this->assertNull($item->getShippingQuery()); + $this->assertNull($item->getPreCheckoutQuery()); + $this->assertNull($item->getPollAnswer()); + $this->assertNull($item->getPoll()); + } + + /** + * @param $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(10, $item->getUpdateId()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getMessage()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getEditedMessage()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getChannelPost()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getEditedChannelPost()); + $this->assertEquals(InlineQueryTest::createMinInstance(), $item->getInlineQuery()); + $this->assertEquals(ChosenInlineResultTest::createMinInstance(), $item->getChosenInlineResult()); + $this->assertEquals(CallbackQueryTest::createMinInstance(), $item->getCallbackQuery()); + $this->assertEquals(ShippingQueryTest::createMinInstance(), $item->getShippingQuery()); + $this->assertEquals(PreCheckoutQueryTest::createMinInstance(), $item->getPreCheckoutQuery()); + $this->assertEquals(PollAnswerTest::createMinInstance(), $item->getPollAnswer()); + $this->assertEquals(PollTest::createMinInstance(), $item->getPoll()); + } +} diff --git a/tests/Types/UserProfilePhotosTest.php b/tests/Types/UserProfilePhotosTest.php new file mode 100644 index 00000000..a9a3f468 --- /dev/null +++ b/tests/Types/UserProfilePhotosTest.php @@ -0,0 +1,59 @@ + 1, + 'photos' => [ + [ + PhotoSizeTest::getMinResponse(), + ] + ] + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param UserProfilePhotos $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getTotalCount()); + $this->assertEquals([[PhotoSizeTest::createMinInstance()]], $item->getPhotos()); + } + + /** + * @param UserProfilePhotos $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } + + public function testSetTotalCountException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new UserProfilePhotos(); + $item->setTotalCount('s'); + } +} diff --git a/tests/Types/UserTest.php b/tests/Types/UserTest.php new file mode 100644 index 00000000..de3b485c --- /dev/null +++ b/tests/Types/UserTest.php @@ -0,0 +1,117 @@ + 123456, + 'first_name' => 'Ilya', + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 123456, + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'username' => 'iGusev', + 'language_code' => 'en', + 'is_premium' => false, + 'added_to_attachment_menu' => false, + 'can_join_groups' => true, + 'can_read_all_group_messages' => true, + 'supports_inline_queries' => false, + 'is_bot' => false, + ]; + } + + /** + * @param User $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(123456, $item->getId()); + $this->assertEquals('Ilya', $item->getFirstName()); + + $this->assertNull($item->getLastName()); + $this->assertNull($item->getUsername()); + $this->assertNull($item->getLanguageCode()); + $this->assertNull($item->getIsPremium()); + $this->assertNull($item->getAddedToAttachmentMenu()); + $this->assertNull($item->getCanJoinGroups()); + $this->assertNull($item->getCanReadAllGroupMessages()); + $this->assertNull($item->getSupportsInlineQueries()); + $this->assertNull($item->isBot()); + } + + /** + * @param User $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(123456, $item->getId()); + $this->assertEquals('Ilya', $item->getFirstName()); + $this->assertEquals('Gusev', $item->getLastName()); + $this->assertEquals('iGusev', $item->getUsername()); + $this->assertEquals('en', $item->getLanguageCode()); + $this->assertEquals(false, $item->getIsPremium()); + $this->assertEquals(false, $item->getAddedToAttachmentMenu()); + $this->assertEquals(true, $item->getCanJoinGroups()); + $this->assertEquals(true, $item->getCanReadAllGroupMessages()); + $this->assertEquals(false, $item->getSupportsInlineQueries()); + $this->assertEquals(false, $item->isBot()); + } + + public function testSet64bitId() + { + $item = new User(); + $item->setId(2147483648); + $this->assertEquals(2147483648, $item->getId()); + } + + public function testSetIdException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new User(); + $item->setId('s'); + } + + public function testFromResponseException1() + { + $this->expectException(InvalidArgumentException::class); + + User::fromResponse([ + 'last_name' => 'Gusev', + 'id' => 123456, + 'username' => 'iGusev' + ]); + } + + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + + User::fromResponse([ + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'username' => 'iGusev' + ]); + } + +} diff --git a/tests/Types/VenueTest.php b/tests/Types/VenueTest.php new file mode 100644 index 00000000..2cd40191 --- /dev/null +++ b/tests/Types/VenueTest.php @@ -0,0 +1,66 @@ + LocationTest::getMinResponse(), + 'title' => 'title', + 'address' => 'address', + ]; + } + + public static function getFullResponse() + { + return [ + 'location' => LocationTest::getMinResponse(), + 'title' => 'title', + 'address' => 'address', + 'foursquare_id' => 'foursquare_id', + 'foursquare_type' => 'foursquare_type', + 'google_place_id' => 'google_place_id', + 'google_place_type' => 'google_place_type', + ]; + } + + /** + * @param Venue $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('address', $item->getAddress()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertNull($item->getFoursquareId()); + $this->assertNull($item->getFoursquareType()); + $this->assertNull($item->getGooglePlaceId()); + $this->assertNull($item->getGooglePlaceType()); + } + + /** + * @param Venue $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('address', $item->getAddress()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertEquals('foursquare_id', $item->getFoursquareId()); + $this->assertEquals('foursquare_type', $item->getFoursquareType()); + $this->assertEquals('google_place_id', $item->getGooglePlaceId()); + $this->assertEquals('google_place_type', $item->getGooglePlaceType()); + } +} diff --git a/tests/Types/VideoNoteTest.php b/tests/Types/VideoNoteTest.php new file mode 100644 index 00000000..c4f2d471 --- /dev/null +++ b/tests/Types/VideoNoteTest.php @@ -0,0 +1,64 @@ + 'file_id', + 'file_unique_id' => 'file_unique_id', + 'length' => 1, + 'duration' => 2, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'file_id', + 'file_unique_id' => 'file_unique_id', + 'length' => 1, + 'duration' => 2, + 'thumb' => PhotoSizeTest::getMinResponse(), + 'file_size' => 3, + ]; + } + + /** + * @param VideoNote $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('file_id', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getLength()); + $this->assertEquals(2, $item->getDuration()); + $this->assertNull($item->getFileSize()); + $this->assertNull($item->getThumb()); + } + + /** + * @param VideoNote $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('file_id', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getLength()); + $this->assertEquals(2, $item->getDuration()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + } +} diff --git a/tests/VideoTest.php b/tests/Types/VideoTest.php similarity index 67% rename from tests/VideoTest.php rename to tests/Types/VideoTest.php index e118845e..a90955f3 100644 --- a/tests/VideoTest.php +++ b/tests/Types/VideoTest.php @@ -1,74 +1,32 @@ setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetDuration() - { - $item = new Video(); - $item->setDuration(1); - $this->assertEquals(1, $item->getDuration()); - } - - public function testSetFileSize() - { - $item = new Video(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetMimeType() - { - $item = new Video(); - $item->setMimeType('video/mp4'); - $this->assertEquals('video/mp4', $item->getMimeType()); + return Video::class; } - public function testSetThumb() + public static function getMinResponse() { - $item = new Video(); - $thumb = PhotoSize::fromResponse([ + return [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, - 'file_size' => 3 - ]); - $item->setThumb($thumb); - $this->assertEquals($thumb, $item->getThumb()); - $this->assertInstanceOf(PhotoSize::class, $item->getThumb()); - } - - public function testSetWidth() - { - $item = new Video(); - $item->setWidth(2); - $this->assertEquals(2, $item->getWidth()); - } - - public function testSetHeight() - { - $item = new Video(); - $item->setHeight(4); - $this->assertEquals(4, $item->getHeight()); + 'duration' => 3, + ]; } - public function testFromResponse() + public static function getFullResponse() { - $item = Video::fromResponse([ + return [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, @@ -76,22 +34,32 @@ public function testFromResponse() 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => [ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ] - ]); - $thumb = PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ]); - $this->assertInstanceOf(Video::class, $item); + 'thumb' => PhotoSizeTest::getMinResponse() + ]; + } + + /** + * @param Video $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(3, $item->getDuration()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + $this->assertNull($item->getThumb()); + } + + /** + * @param Video $item + * @return void + */ + protected function assertFullItem($item) + { $this->assertEquals('testFileId1', $item->getFileId()); $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); $this->assertEquals(1, $item->getWidth()); @@ -99,8 +67,7 @@ public function testFromResponse() $this->assertEquals(3, $item->getDuration()); $this->assertEquals('video/mp4', $item->getMimeType()); $this->assertEquals(4, $item->getFileSize()); - $this->assertEquals($thumb, $item->getThumb()); - $this->assertInstanceOf(PhotoSize::class, $item->getThumb()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); } public function testSetHeightException() @@ -142,7 +109,7 @@ public function testFromResponseException1() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse([ + Video::fromResponse([ 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, 'height' => 2, @@ -164,7 +131,7 @@ public function testFromResponseException2() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse([ + Video::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'height' => 2, @@ -188,7 +155,7 @@ public function testFromResponseException3() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse([ + Video::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, @@ -212,7 +179,7 @@ public function testFromResponseException4() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse([ + Video::fromResponse([ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 1, @@ -236,7 +203,7 @@ public function testFromResponseException5() { $this->expectException(InvalidArgumentException::class); - $item = Video::fromResponse([ + Video::fromResponse([ 'file_id' => 'testFileId1', 'width' => 1, 'height' => 2, diff --git a/tests/VoiceTest.php b/tests/Types/VoiceTest.php similarity index 58% rename from tests/VoiceTest.php rename to tests/Types/VoiceTest.php index 0ce7037f..47b3d9a7 100644 --- a/tests/VoiceTest.php +++ b/tests/Types/VoiceTest.php @@ -1,58 +1,57 @@ setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); + return Voice::class; } - public function testSetUniqueFileId() + public static function getMinResponse() { - $item = new Voice(); - $item->setFileUniqueId('fileUniqueId'); - $this->assertEquals('fileUniqueId', $item->getFileUniqueId()); - } - - public function testSetDuration() - { - $item = new Voice(); - $item->setDuration(1); - $this->assertEquals(1, $item->getDuration()); + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'duration' => 1, + ]; } - public function testSetFileSize() + public static function getFullResponse() { - $item = new Voice(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'duration' => 1, + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + ]; } - public function testSetMimeType() + /** + * @param Voice $item + * @return void + */ + protected function assertMinItem($item) { - $item = new Voice(); - $item->setMimeType('audio/mp3'); - $this->assertEquals('audio/mp3', $item->getMimeType()); + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getDuration()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); } - public function testFromResponse() + /** + * @param Voice $item + * @return void + */ + protected function assertFullItem($item) { - $item = Voice::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - ]); - $this->assertInstanceOf(Voice::class, $item); $this->assertEquals('testFileId1', $item->getFileId()); $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); $this->assertEquals(1, $item->getDuration()); @@ -64,7 +63,7 @@ public function testFromResponseException() { $this->expectException(InvalidArgumentException::class); - $item = Voice::fromResponse([ + Voice::fromResponse([ 'duration' => 1, 'mime_type' => 'audio/mp3', 'file_size' => 3 @@ -75,7 +74,7 @@ public function testFromResponseException2() { $this->expectException(InvalidArgumentException::class); - $item = Voice::fromResponse([ + Voice::fromResponse([ 'file_id' => 'testFileId1', 'mime_type' => 'audio/mp3', 'file_size' => 3 diff --git a/tests/Types/WebhookInfoTest.php b/tests/Types/WebhookInfoTest.php new file mode 100644 index 00000000..4bc8f948 --- /dev/null +++ b/tests/Types/WebhookInfoTest.php @@ -0,0 +1,63 @@ + 'https://google.com', + 'has_custom_certificate' => false, + 'pending_update_count' => 0, + ]; + } + + public static function getFullResponse() + { + return [ + 'url' => 'https://google.com', + 'has_custom_certificate' => false, + 'pending_update_count' => 0, + 'ip_address' => '127.0.0.1', + 'last_error_date' => 1682335353, + 'last_error_message' => 'Last error message', + 'last_synchronization_error_date' => 1682335353, + 'max_connections' => 40, + 'allowed_updates' => ['test'] + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('https://google.com', $item->getUrl()); + $this->assertEquals(false, $item->hasCustomCertificate()); + $this->assertEquals(0, $item->getPendingUpdateCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('https://google.com', $item->getUrl()); + $this->assertEquals(false, $item->hasCustomCertificate()); + $this->assertEquals(0, $item->getPendingUpdateCount()); + $this->assertEquals('127.0.0.1', $item->getipAddress()); + $this->assertEquals(1682335353, $item->getLastErrorDate()); + $this->assertEquals('Last error message', $item->getLastErrorMessage()); + $this->assertEquals(1682335353, $item->getLastSynchronizationErrorDate()); + $this->assertEquals(40, $item->getMaxConnections()); + $this->assertEquals(['test'], $item->getAllowedUpdates()); + } +} diff --git a/tests/UserProfilePhotosTest.php b/tests/UserProfilePhotosTest.php deleted file mode 100644 index ccab9878..00000000 --- a/tests/UserProfilePhotosTest.php +++ /dev/null @@ -1,82 +0,0 @@ -setTotalCount(1); - $this->assertEquals(1, $userProfilePhotos->getTotalCount()); - } - - public function testSetPhotos() - { - $userProfilePhotos = new UserProfilePhotos(); - $photos = []; - for ($i = 0; $i < 10; $i++) { - $photos[] = PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => $i, - 'height' => $i * 2, - 'file_size' => $i * 3 - ]); - } - - $userProfilePhotos->setPhotos($photos); - $this->assertEquals($photos, $userProfilePhotos->getPhotos()); - } - - public function testFromResponse() - { - $userProfilePhotos = UserProfilePhotos::fromResponse([ - 'total_count' => 1, - 'photos' => [ - [ - [ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ] - ] - ] - ]); - $photos = [ - [ - PhotoSize::fromResponse([ - 'file_id' => 'testFileId1', - 'file_unique_id' => 'testFileUniqueId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ]) - ] - ]; - $this->assertInstanceOf(UserProfilePhotos::class, $userProfilePhotos); - $this->assertEquals(1, $userProfilePhotos->getTotalCount()); - $this->assertEquals($photos, $userProfilePhotos->getPhotos()); - - foreach ($userProfilePhotos->getPhotos() as $photoArray) { - foreach($photoArray as $photo) { - $this->assertInstanceOf(PhotoSize::class, $photo); - } - } - } - - public function testSetTotalCountException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new UserProfilePhotos(); - $item->setTotalCount('s'); - } -} diff --git a/tests/UserTest.php b/tests/UserTest.php deleted file mode 100644 index 31239591..00000000 --- a/tests/UserTest.php +++ /dev/null @@ -1,103 +0,0 @@ -setId(1); - $this->assertEquals(1, $item->getId()); - } - - public function testSet64bitId() - { - $item = new User(); - $item->setId(2147483648); - $this->assertEquals(2147483648, $item->getId()); - } - - public function testSetFirstName() - { - $item = new User(); - $item->setFirstName('Ilya'); - $this->assertEquals('Ilya', $item->getFirstName()); - } - - public function testSetLastName() - { - $item = new User(); - $item->setLastName('Gusev'); - $this->assertEquals('Gusev', $item->getLastName()); - } - - public function testSetUsername() - { - $item = new User(); - $item->setUsername('iGusev'); - $this->assertEquals('iGusev', $item->getUsername()); - } - - public function testSetIdException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new User(); - $item->setId('s'); - } - - public function testFromResponse() - { - $user = User::fromResponse([ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - 'language_code' => 'en', - 'is_premium' => false, - 'added_to_attachment_menu' => false, - 'can_join_groups' => true, - 'can_read_all_group_messages' => true, - 'supports_inline_queries' => false, - ]); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $user); - $this->assertEquals(123456, $user->getId()); - $this->assertEquals('Ilya', $user->getFirstName()); - $this->assertEquals('Gusev', $user->getLastName()); - $this->assertEquals('iGusev', $user->getUsername()); - $this->assertEquals('en', $user->getLanguageCode()); - $this->assertEquals(false, $user->getIsPremium()); - $this->assertEquals(false, $user->getAddedToAttachmentMenu()); - $this->assertEquals(true, $user->getCanJoinGroups()); - $this->assertEquals(true, $user->getCanReadAllGroupMessages()); - $this->assertEquals(false, $user->getSupportsInlineQueries()); - } - - public function testFromResponseException1() - { - $this->expectException(InvalidArgumentException::class); - - $user = User::fromResponse([ - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ]); - } - - public function testFromResponseException2() - { - $this->expectException(InvalidArgumentException::class); - - $user = User::fromResponse([ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - ]); - } - -} diff --git a/tests/WebhookInfoTest.php b/tests/WebhookInfoTest.php deleted file mode 100644 index e79b8188..00000000 --- a/tests/WebhookInfoTest.php +++ /dev/null @@ -1,39 +0,0 @@ - '', - 'has_custom_certificate' => false, - 'pending_update_count' => 0, - 'ip_address' => '', - 'last_error_date' => null, - 'last_error_message' => null, - 'last_synchronization_error_date' => null, - 'max_connections' => 40, - 'allowed_updates' => null - ]); - $this->assertInstanceOf('\TelegramBot\Api\Types\WebhookInfo', $webhookInfo); - $this->assertEquals('', $webhookInfo->getUrl()); - $this->assertEquals(false, $webhookInfo->hasCustomCertificate()); - $this->assertEquals(0, $webhookInfo->getPendingUpdateCount()); - $this->assertEquals('', $webhookInfo->getipAddress()); - $this->assertEquals(null, $webhookInfo->getLastErrorDate()); - $this->assertEquals(null, $webhookInfo->getLastErrorMessage()); - $this->assertEquals(null, $webhookInfo->getLastSynchronizationErrorDate()); - $this->assertEquals(40, $webhookInfo->getMaxConnections()); - $this->assertEquals(null, $webhookInfo->getAllowedUpdates()); - } -} From da2ba6671ff33dfc9ed32a82a9b0735916de5fc0 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 26 Apr 2023 18:15:28 +0300 Subject: [PATCH 092/130] Fix copyMessage --- CHANGELOG.md | 1 + src/BotApi.php | 5 ++-- src/Types/MessageId.php | 52 +++++++++++++++++++++++++++++++++++ tests/Types/MessageIdTest.php | 44 +++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 src/Types/MessageId.php create mode 100644 tests/Types/MessageIdTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 495cab9f..3ca77e56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file ### Fixed - Fix `\TelegramBot\Api\Collection\Collection::addItem` max count constraint (#333) - Fix `\TelegramBot\Api\Types\StickerSet` mapping +- Fix `\TelegramBot\Api\BotApi::copyMessage` not returning `\TelegramBot\Api\Types\MessageId` ### Deprecated - Deprecate `\TelegramBot\Api\Botan` class diff --git a/src/BotApi.php b/src/BotApi.php index 5d176698..0f2960fd 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -19,6 +19,7 @@ use TelegramBot\Api\Types\InputMedia\InputMedia; use TelegramBot\Api\Types\MaskPosition; use TelegramBot\Api\Types\Message; +use TelegramBot\Api\Types\MessageId; use TelegramBot\Api\Types\Poll; use TelegramBot\Api\Types\ReplyKeyboardHide; use TelegramBot\Api\Types\ReplyKeyboardMarkup; @@ -369,7 +370,7 @@ public function sendMessage( * @param bool $allowSendingWithoutReply * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * - * @return Message + * @return MessageId * @throws Exception * @throws HttpException * @throws InvalidJsonException @@ -387,7 +388,7 @@ public function copyMessage( $allowSendingWithoutReply = false, $replyMarkup = null ) { - return Message::fromResponse($this->call('copyMessage', [ + return MessageId::fromResponse($this->call('copyMessage', [ 'chat_id' => $chatId, 'from_chat_id' => $fromChatId, 'message_id' => (int)$messageId, diff --git a/src/Types/MessageId.php b/src/Types/MessageId.php new file mode 100644 index 00000000..9d615b8e --- /dev/null +++ b/src/Types/MessageId.php @@ -0,0 +1,52 @@ + true, + ]; + + /** + * Unique message identifier + * + * @var integer + */ + protected $messageId; + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } +} diff --git a/tests/Types/MessageIdTest.php b/tests/Types/MessageIdTest.php new file mode 100644 index 00000000..65f1f590 --- /dev/null +++ b/tests/Types/MessageIdTest.php @@ -0,0 +1,44 @@ + 100, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param MessageId $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(100, $item->getMessageId()); + } + + /** + * @param MessageId $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} From af9ea44ad2a74fafd86e4baf173749d627f454da Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 26 Apr 2023 18:27:11 +0300 Subject: [PATCH 093/130] Convert variables to camelCase --- src/BotApi.php | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/BotApi.php b/src/BotApi.php index 5d176698..5a4c9db0 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -493,20 +493,20 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) * @param string $url HTTPS url to send updates to. Use an empty string to remove webhook integration * @param \CURLFile|string $certificate Upload your public key certificate * so that the root certificate in use can be checked - * @param string|null $ip_address The fixed IP address which will be used to send webhook requests + * @param string|null $ipAddress The fixed IP address which will be used to send webhook requests * instead of the IP address resolved through DNS - * @param int|null $max_connections The maximum allowed number of simultaneous HTTPS connections to the webhook + * @param int|null $maxConnections The maximum allowed number of simultaneous HTTPS connections to the webhook * for update delivery, 1-100. Defaults to 40. Use lower values to limit * the load on your bot's server, and higher values to increase your bot's throughput. - * @param array|null $allowed_updates A JSON-serialized list of the update types you want your bot to receive. + * @param array|null $allowedUpdates A JSON-serialized list of the update types you want your bot to receive. * For example, specify [“message”, “edited_channel_post”, “callback_query”] * to only receive updates of these types. See Update for a complete list of available update types. * Specify an empty list to receive all update types except chat_member (default). * If not specified, the previous setting will be used. * Please note that this parameter doesn't affect updates created before the call to the setWebhook, * so unwanted updates may be received for a short period of time. - * @param bool|null $drop_pending_updates Pass True to drop all pending updates - * @param string|null $secret_token A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, + * @param bool|null $dropPendingUpdates Pass True to drop all pending updates + * @param string|null $secretToken A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, * 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. * The header is useful to ensure that the request comes from a webhook set by you. * @@ -517,35 +517,35 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) public function setWebhook( $url = '', $certificate = null, - $ip_address = null, - $max_connections = 40, - $allowed_updates = null, - $drop_pending_updates = false, - $secret_token = null + $ipAddress = null, + $maxConnections = 40, + $allowedUpdates = null, + $dropPendingUpdates = false, + $secretToken = null ) { return $this->call('setWebhook', [ 'url' => $url, 'certificate' => $certificate, - 'ip_address' => $ip_address, - 'max_connections' => $max_connections, - 'allowed_updates' => $allowed_updates, - 'drop_pending_updates' => $drop_pending_updates, - 'secret_token' => $secret_token + 'ip_address' => $ipAddress, + 'max_connections' => $maxConnections, + 'allowed_updates' => $allowedUpdates, + 'drop_pending_updates' => $dropPendingUpdates, + 'secret_token' => $secretToken ]); } /** * Use this method to clear webhook and use getUpdates again! * - * @param bool $drop_pending_updates Pass True to drop all pending updates + * @param bool $dropPendingUpdates Pass True to drop all pending updates * * @return mixed * * @throws Exception */ - public function deleteWebhook($drop_pending_updates = false) + public function deleteWebhook($dropPendingUpdates = false) { - return $this->call('deleteWebhook', ['drop_pending_updates' => $drop_pending_updates]); + return $this->call('deleteWebhook', ['drop_pending_updates' => $dropPendingUpdates]); } /** @@ -1753,18 +1753,18 @@ public function sendInvoice( * * @param string $shippingQueryId * @param bool $ok - * @param array $shipping_options + * @param array $shippingOptions * @param null|string $errorMessage * * @return bool * @throws Exception */ - public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null) + public function answerShippingQuery($shippingQueryId, $ok = true, $shippingOptions = [], $errorMessage = null) { return $this->call('answerShippingQuery', [ 'shipping_query_id' => $shippingQueryId, 'ok' => (bool)$ok, - 'shipping_options' => json_encode($shipping_options), + 'shipping_options' => json_encode($shippingOptions), 'error_message' => $errorMessage ]); } From 74cc636c250b3d485a02aa490d2100ced96b45e8 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 26 Apr 2023 18:54:09 +0300 Subject: [PATCH 094/130] Fix serializing BotCommands inside setMyCommands. Add missing setMyCommands parameters. --- CHANGELOG.md | 8 +++++++- src/BotApi.php | 22 ++++++++++++--------- src/Collection/Collection.php | 35 ++++++++++++++------------------- src/Types/ArrayOfBotCommand.php | 9 ++++++--- src/Types/BotCommand.php | 3 ++- 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 495cab9f..cdf944f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,19 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file ### Added - Add `\TelegramBot\Api\Types\Venue` mapping (`foursquare_type`, `google_place_id`, `google_place_type`) +- Add `scope` and `languageCode` parameters to `\TelegramBot\Api\BotApi::setMyCommands` ### Fixed - Fix `\TelegramBot\Api\Collection\Collection::addItem` max count constraint (#333) - Fix `\TelegramBot\Api\Types\StickerSet` mapping +### Changed +- `\TelegramBot\Api\BotApi::getMyCommands` now returns instance `\TelegramBot\Api\Types\ArrayOfBotCommand` instead of `\TelegramBot\Api\Types\BotCommand` array +- `\TelegramBot\Api\BotApi::setMyCommands` now accepts instance of `\TelegramBot\Api\Types\ArrayOfBotCommand` instead of `\TelegramBot\Api\Types\BotCommand` array + ### Deprecated - Deprecate `\TelegramBot\Api\Botan` class - Deprecate `$trackerToken` parameter in `\TelegramBot\Api\BotApi::__construct` - Deprecate `$trackerToken` parameter in `\TelegramBot\Api\Events\EventCollection::__construct` -- Deprecate `\TelegramBot\Api\Types\PollAnswer::getFrom` use `\TelegramBot\Api\Types\PollAnswer::getUser` +- Deprecate `\TelegramBot\Api\Types\PollAnswer::getFrom` use `\TelegramBot\Api\Types\PollAnswer::getUser` instead +- Deprecate passing array of BotCommand to `\TelegramBot\Api\BotApi::setMyCommands`. Use `\TelegramBot\Api\Types\ArrayOfBotCommand` instead diff --git a/src/BotApi.php b/src/BotApi.php index 5d176698..6d325c5b 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1424,28 +1424,32 @@ public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = /** * Use this method to change the list of the bot's commands. Returns True on success. * - * @param $commands + * @param ArrayOfBotCommand $commands * * @return mixed * @throws Exception * @throws HttpException * @throws InvalidJsonException */ - public function setMyCommands($commands) + public function setMyCommands($commands, $scope = null, $languageCode = null) { - return $this->call( - 'setMyCommands', - [ - 'commands' => json_encode($commands) - ] - ); + if (!$commands instanceof ArrayOfBotCommand) { + @trigger_error(sprintf('Passing array of BotCommand to "%s::%s" is deprecated. Use %s', __CLASS__, __METHOD__, ArrayOfBotCommand::class), \E_USER_DEPRECATED); + $commands = new ArrayOfBotCommand($commands); + } + + return $this->call('setMyCommands', [ + 'commands' => $commands->toJson(), + 'scope' => $scope, + 'language_code' => $languageCode, + ]); } /** * Use this method to get the current list of the bot's commands. Requires no parameters. * Returns Array of BotCommand on success. * - * @return BotCommand[] + * @return ArrayOfBotCommand * * @throws Exception * @throws HttpException diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index de2ffc84..d71be6be 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -7,17 +7,20 @@ /** * Class Collection */ -class Collection +class Collection extends \ArrayObject { /** - * @var array + * @var int Max items count, if set 0 - unlimited */ - protected $items = []; + protected $maxCount = 0; /** - * @var int Max items count, if set 0 - unlimited + * @param CollectionItemInterface[] $items */ - protected $maxCount = 0; + public function __construct(array $items = []) + { + parent::__construct($items); + } /** * @param CollectionItemInterface $item @@ -33,12 +36,12 @@ public function addItem(CollectionItemInterface $item, $key = null) } if ($key == null) { - $this->items[] = $item; + $this->append($item); } else { - if (isset($this->items[$key])) { + if ($this->offsetExists($key)) { throw new KeyHasUseException("Key $key already in use."); } - $this->items[$key] = $item; + $this->offsetSet($key, $item); } } @@ -51,7 +54,7 @@ public function deleteItem($key) { $this->checkItemKey($key); - unset($this->items[$key]); + $this->offsetUnset($key); } /** @@ -64,15 +67,7 @@ public function getItem($key) { $this->checkItemKey($key); - return $this->items[$key]; - } - - /** - * @return int - */ - public function count() - { - return count($this->items); + return $this->offsetGet($key); } /** @@ -82,7 +77,7 @@ public function count() public function toJson($inner = false) { $output = []; - foreach ($this->items as $item) { + foreach ($this as $item) { $output[] = $item->toJson(true); } @@ -104,7 +99,7 @@ public function setMaxCount($maxCount) */ private function checkItemKey($key) { - if (!isset($this->items[$key])) { + if (!$this->offsetExists($key)) { throw new KeyInvalidException("Invalid key $key."); } } diff --git a/src/Types/ArrayOfBotCommand.php b/src/Types/ArrayOfBotCommand.php index 42923a7f..6c6d3e22 100644 --- a/src/Types/ArrayOfBotCommand.php +++ b/src/Types/ArrayOfBotCommand.php @@ -2,13 +2,16 @@ namespace TelegramBot\Api\Types; -abstract class ArrayOfBotCommand +use TelegramBot\Api\Collection\Collection; +use TelegramBot\Api\TypeInterface; + +class ArrayOfBotCommand extends Collection implements TypeInterface { public static function fromResponse($data) { - $arrayOfBotCommand = []; + $arrayOfBotCommand = new static(); foreach ($data as $botCommand) { - $arrayOfBotCommand[] = BotCommand::fromResponse($botCommand); + $arrayOfBotCommand->addItem(BotCommand::fromResponse($botCommand)); } return $arrayOfBotCommand; diff --git a/src/Types/BotCommand.php b/src/Types/BotCommand.php index 051cb246..22a0685b 100644 --- a/src/Types/BotCommand.php +++ b/src/Types/BotCommand.php @@ -3,9 +3,10 @@ namespace TelegramBot\Api\Types; use TelegramBot\Api\BaseType; +use TelegramBot\Api\Collection\CollectionItemInterface; use TelegramBot\Api\TypeInterface; -class BotCommand extends BaseType implements TypeInterface +class BotCommand extends BaseType implements TypeInterface, CollectionItemInterface { /** * {@inheritdoc} From 2682b5f3aac67a2fc345cacfaf4321fd73c922e1 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Thu, 27 Apr 2023 12:36:12 +0300 Subject: [PATCH 095/130] Psalm --- .gitattributes | 1 + .github/workflows/cs.yaml | 4 + .github/workflows/psalm.yaml | 55 ++++ .github/workflows/tests.yaml | 4 + .scrutinizer.yml | 1 + composer.json | 4 +- psalm.xml | 28 ++ src/BaseType.php | 28 +- src/BotApi.php | 186 ++++++++---- src/Botan.php | 14 +- src/Client.php | 82 +++++- src/Collection/Collection.php | 14 +- src/Collection/CollectionItemInterface.php | 4 + src/Events/Event.php | 14 +- src/Events/EventCollection.php | 11 +- src/TypeInterface.php | 4 + src/Types/Animation.php | 33 ++- src/Types/ArrayOfArrayOfPhotoSize.php | 4 + src/Types/ArrayOfBotCommand.php | 4 +- src/Types/ArrayOfChatMemberEntity.php | 4 + src/Types/ArrayOfMessageEntity.php | 4 + src/Types/ArrayOfMessages.php | 4 + src/Types/ArrayOfPhotoSize.php | 4 + src/Types/ArrayOfPollOption.php | 4 + src/Types/ArrayOfSticker.php | 4 + src/Types/ArrayOfUpdates.php | 4 + src/Types/ArrayOfUser.php | 4 + src/Types/Audio.php | 29 +- src/Types/BotCommand.php | 2 + src/Types/CallbackQuery.php | 23 +- src/Types/Chat.php | 133 +++++---- src/Types/ChatLocation.php | 2 + src/Types/ChatMember.php | 85 ++++-- src/Types/ChatPermissions.php | 40 ++- src/Types/ChatPhoto.php | 2 + src/Types/Contact.php | 17 +- src/Types/Dice.php | 2 + src/Types/Document.php | 21 +- src/Types/File.php | 15 +- src/Types/ForceReply.php | 16 +- src/Types/ForumTopic.php | 8 +- src/Types/ForumTopicCreated.php | 3 + src/Types/Inline/ChosenInlineResult.php | 18 +- src/Types/Inline/InlineKeyboardMarkup.php | 2 + src/Types/Inline/InlineQuery.php | 14 +- .../Inline/InputMessageContent/Contact.php | 12 +- .../Inline/InputMessageContent/Location.php | 4 + src/Types/Inline/InputMessageContent/Text.php | 20 +- .../Inline/InputMessageContent/Venue.php | 18 +- .../QueryResult/AbstractInlineQueryResult.php | 32 +- src/Types/Inline/QueryResult/Article.php | 48 +-- src/Types/Inline/QueryResult/Audio.php | 18 +- src/Types/Inline/QueryResult/Contact.php | 36 ++- src/Types/Inline/QueryResult/Gif.php | 28 +- src/Types/Inline/QueryResult/Location.php | 34 ++- src/Types/Inline/QueryResult/Mpeg4Gif.php | 28 +- src/Types/Inline/QueryResult/Photo.php | 42 ++- src/Types/Inline/QueryResult/Venue.php | 52 ++-- src/Types/Inline/QueryResult/Video.php | 46 ++- src/Types/Inline/QueryResult/Voice.php | 10 +- src/Types/InputMedia/InputMedia.php | 20 +- src/Types/InputMedia/InputMediaVideo.php | 32 +- src/Types/Location.php | 31 +- src/Types/LoginUrl.php | 16 +- src/Types/MaskPosition.php | 4 + src/Types/Message.php | 273 +++++++++++------- src/Types/MessageEntity.php | 23 +- src/Types/Payments/ArrayOfLabeledPrice.php | 4 + src/Types/Payments/Invoice.php | 15 + src/Types/Payments/LabeledPrice.php | 4 + src/Types/Payments/OrderInfo.php | 32 +- .../Payments/Query/AnswerPreCheckoutQuery.php | 13 +- .../Payments/Query/AnswerShippingQuery.php | 12 + src/Types/Payments/Query/PreCheckoutQuery.php | 31 +- src/Types/Payments/Query/ShippingQuery.php | 12 + src/Types/Payments/ShippingAddress.php | 18 ++ src/Types/Payments/ShippingOption.php | 9 + src/Types/Payments/SuccessfulPayment.php | 31 +- src/Types/PhotoSize.php | 18 +- src/Types/Poll.php | 15 +- src/Types/PollAnswer.php | 3 + src/Types/PollOption.php | 2 + src/Types/ReplyKeyboardHide.php | 16 +- src/Types/ReplyKeyboardMarkup.php | 28 +- src/Types/ReplyKeyboardRemove.php | 12 +- src/Types/Sticker.php | 62 ++-- src/Types/StickerSet.php | 18 +- src/Types/Update.php | 76 +++-- src/Types/User.php | 60 ++-- src/Types/UserProfilePhotos.php | 8 +- src/Types/Venue.php | 30 +- src/Types/Video.php | 32 +- src/Types/VideoNote.php | 20 +- src/Types/Voice.php | 22 +- src/Types/WebhookInfo.php | 46 ++- tests/Events/EventTest.php | 20 -- 96 files changed, 1728 insertions(+), 727 deletions(-) create mode 100644 .github/workflows/psalm.yaml create mode 100644 psalm.xml diff --git a/.gitattributes b/.gitattributes index f6d39776..aacc9b12 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,4 +8,5 @@ /.scrutinizer.yml export-ignore /phpunit.xml.dist export-ignore /.php-cs-fixer.dist.php export-ignore +/psalm.xml export-ignore /tests export-ignore diff --git a/.github/workflows/cs.yaml b/.github/workflows/cs.yaml index f04f2fed..83d50663 100644 --- a/.github/workflows/cs.yaml +++ b/.github/workflows/cs.yaml @@ -42,6 +42,10 @@ jobs: name: Update composer run: composer self-update + - + name: Remove psalm + run: composer remove vimeo/psalm --dev --no-update + - name: Install dependencies with composer run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi diff --git a/.github/workflows/psalm.yaml b/.github/workflows/psalm.yaml new file mode 100644 index 00000000..ceccd1a3 --- /dev/null +++ b/.github/workflows/psalm.yaml @@ -0,0 +1,55 @@ +on: + - pull_request + - push + +name: Psalm + +jobs: + tests: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + php: + - "8.1" + steps: + - + name: Checkout + uses: actions/checkout@v2 + + - + name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + + - + name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - + name: Cache dependencies installed with composer + uses: actions/cache@v2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer-latest- + - + name: Update composer + run: composer self-update + + - + name: Remove php-cs-fixer + run: composer remove friendsofphp/php-cs-fixer --dev --no-update + + - + name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - + name: Run Psalm + run: composer psalm diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 149d6977..0072a66d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -55,6 +55,10 @@ jobs: name: Remove php-cs-fixer run: composer remove friendsofphp/php-cs-fixer --dev --no-update + - + name: Remove psalm + run: composer remove vimeo/psalm --dev --no-update + - name: Install dependencies with composer run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 208e42ea..94b93c3d 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -20,6 +20,7 @@ build: dependencies: before: - composer remove friendsofphp/php-cs-fixer --dev --no-update + - composer remove vimeo/psalm --dev --no-update tests: override: diff --git a/composer.json b/composer.json index e64d383b..e9abe136 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ }, "require-dev": { "symfony/phpunit-bridge" : "*", - "friendsofphp/php-cs-fixer": "^3.16" + "friendsofphp/php-cs-fixer": "^3.16", + "vimeo/psalm": "^5.9" }, "autoload": { "psr-4": { @@ -39,6 +40,7 @@ "scripts": { "test": "vendor/bin/simple-phpunit --colors=always", "coverage": "XDEBUG_MODE=coverage vendor/bin/simple-phpunit --coverage-html build/coverage", + "psalm": "vendor/bin/psalm", "cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi", "cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run" }, diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..ef3650df --- /dev/null +++ b/psalm.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/BaseType.php b/src/BaseType.php index 9f6fd297..f02e0eca 100644 --- a/src/BaseType.php +++ b/src/BaseType.php @@ -42,10 +42,14 @@ public static function validate($data) throw new InvalidArgumentException(); } + /** + * @param array $data + * @return void + */ public function map($data) { foreach (static::$map as $key => $item) { - if (isset($data[$key]) && (!is_array($data[$key]) || (is_array($data[$key]) && !empty($data[$key])))) { + if (isset($data[$key]) && (!is_array($data[$key]) || !empty($data[$key]))) { $method = 'set' . self::toCamelCase($key); if ($item === true) { $this->$method($data[$key]); @@ -56,11 +60,19 @@ public function map($data) } } + /** + * @param string $str + * @return string + */ protected static function toCamelCase($str) { return str_replace(' ', '', ucwords(str_replace('_', ' ', $str))); } + /** + * @param bool $inner + * @return array|string + */ public function toJson($inner = false) { $output = []; @@ -70,6 +82,10 @@ public function toJson($inner = false) if (!is_null($this->$property)) { if (is_array($this->$property)) { $output[$key] = array_map( + /** + * @param mixed $v + * @return array|false|string + */ function ($v) { return is_object($v) ? $v->toJson(true) : $v; }, @@ -84,13 +100,15 @@ function ($v) { return $inner === false ? json_encode($output) : $output; } + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ public static function fromResponse($data) { - if ($data === true) { - return true; - } - self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ $instance = new static(); $instance->map($data); diff --git a/src/BotApi.php b/src/BotApi.php index 59cc8e50..a1af5cf4 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -14,6 +14,7 @@ use TelegramBot\Api\Types\File; use TelegramBot\Api\Types\ForceReply; use TelegramBot\Api\Types\ForumTopic; +use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; use TelegramBot\Api\Types\Inline\QueryResult\AbstractInlineQueryResult; use TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia; use TelegramBot\Api\Types\InputMedia\InputMedia; @@ -110,6 +111,9 @@ class BotApi 511 => 'Network Authentication Required', // RFC6585 ]; + /** + * @var array + */ private $proxySettings = []; /** @@ -140,7 +144,7 @@ class BotApi /** * CURL object * - * @var + * @var resource */ protected $curl; @@ -161,7 +165,7 @@ class BotApi /** * Botan tracker * - * @var Botan + * @var Botan|null */ protected $tracker; @@ -216,6 +220,7 @@ public function setModeObject($mode = true) * * @param string $method * @param array|null $data + * @param int $timeout * * @return mixed * @throws Exception @@ -237,13 +242,13 @@ public function call($method, array $data = null, $timeout = 10) $options[CURLOPT_POSTFIELDS] = $data; } - if (!empty($this->customCurlOptions) && is_array($this->customCurlOptions)) { + if (!empty($this->customCurlOptions)) { $options = $this->customCurlOptions + $options; } $response = self::jsonValidate($this->executeCurl($options), $this->returnArray); - if ($this->returnArray) { + if (\is_array($response)) { if (!isset($response['ok']) || !$response['ok']) { throw new Exception($response['description'], $response['error_code']); } @@ -271,6 +276,7 @@ protected function executeCurl(array $options) { curl_setopt_array($this->curl, $options); + /** @var string|false $result */ $result = curl_exec($this->curl); self::curlValidate($this->curl, $result); if ($result === false) { @@ -284,12 +290,19 @@ protected function executeCurl(array $options) * Response validation * * @param resource $curl - * @param string $response + * @param string|false|null $response + * * @throws HttpException + * + * @return void */ public static function curlValidate($curl, $response = null) { - $json = json_decode($response, true) ?: []; + if ($response) { + $json = json_decode($response, true) ?: []; + } else { + $json = []; + } if (($httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE)) && !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE]) ) { @@ -303,7 +316,7 @@ public static function curlValidate($curl, $response = null) * JSON validation * * @param string $jsonString - * @param boolean $asArray + * @param bool $asArray * * @return object|array * @throws InvalidJsonException @@ -328,7 +341,7 @@ public static function jsonValidate($jsonString, $asArray) * @param bool $disablePreview * @param int|null $messageThreadId * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardHide|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * * @return Message @@ -650,6 +663,7 @@ public function sendLocation( /** * Use this method to edit live location messages sent by the bot or via the bot (for inline bots). + * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param int|string $chatId * @param int $messageId @@ -658,7 +672,7 @@ public function sendLocation( * @param float $longitude * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * - * @return Message + * @return Message|true * * @throws Exception */ @@ -670,26 +684,32 @@ public function editMessageLiveLocation( $longitude, $replyMarkup = null ) { - return Message::fromResponse($this->call('editMessageLiveLocation', [ + $response = $this->call('editMessageLiveLocation', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, 'latitude' => $latitude, 'longitude' => $longitude, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ])); + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** * Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before * live_period expires. + * On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param int|string $chatId * @param int $messageId * @param string $inlineMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * - * @return Message + * @return Message|true * * @throws Exception */ @@ -699,12 +719,17 @@ public function stopMessageLiveLocation( $inlineMessageId, $replyMarkup = null ) { - return Message::fromResponse($this->call('stopMessageLiveLocation', [ + $response = $this->call('stopMessageLiveLocation', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ])); + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** @@ -755,8 +780,9 @@ public function sendVenue( * * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $sticker + * @param string|null $messageThreadId * @param int|null $replyToMessageId - * @param null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param bool $protectContent Protects the contents of the sent message from forwarding and saving * @param bool $allowSendingWithoutReply Pass True if the message should be sent even if the specified replied-to message is not found @@ -789,7 +815,7 @@ public function sendSticker( /** * @param string $name Name of the sticker set - * + * @return StickerSet * @throws InvalidArgumentException * @throws Exception */ @@ -803,7 +829,7 @@ public function getStickerSet($name) /** * @param array[] $customEmojiIds List of custom emoji identifiers. * At most 200 custom emoji identifiers can be specified. - * + * @return StickerSet * @throws InvalidArgumentException * @throws Exception * @@ -866,6 +892,8 @@ public function uploadStickerFile($userId, $pngSticker) * @throws InvalidArgumentException * @throws Exception * + * @return bool + * * @author bernard-ng */ public function createNewStickerSet( @@ -899,8 +927,17 @@ public function createNewStickerSet( * Animated sticker sets can have up to 50 stickers. * Static sticker sets can have up to 120 stickers. Returns True on success. * - * @throws InvalidArgumentException + * @param string $userId + * @param string $name + * @param string $emojis + * @param string $pngSticker + * @param string|null $tgsSticker + * @param string|null $webmSticker + * @param MaskPosition|null $maskPosition + * @return bool * @throws Exception + * @throws HttpException + * @throws InvalidJsonException */ public function addStickerToSet( $userId, @@ -1111,7 +1148,7 @@ public function sendVoice( * * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param int $fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) - * @param $messageId Message identifier in the chat specified in from_chat_id + * @param string $messageId Message identifier in the chat specified in from_chat_id * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only * @param bool $protectContent Protects the contents of the forwarded message from forwarding and saving * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. @@ -1279,7 +1316,7 @@ public function sendDocument( * It is guaranteed that the link will be valid for at least 1 hour. * When the link expires, a new one can be requested by calling getFile again. * - * @param $fileId + * @param string $fileId * * @return File * @throws InvalidArgumentException @@ -1293,7 +1330,7 @@ public function getFile($fileId) /** * Get file contents via cURL * - * @param $fileId + * @param string $fileId * * @return string * @@ -1337,10 +1374,19 @@ public function answerInlineQuery( $switchPmText = null, $switchPmParameter = null ) { - $results = array_map(function ($item) { - /* @var AbstractInlineQueryResult $item */ - return json_decode($item->toJson(), true); - }, $results); + $results = array_map( + /** + * @param AbstractInlineQueryResult $item + * @return array + */ + function ($item) { + /** @var array $array */ + $array = $item->toJson(true); + + return $array; + }, + $results + ); return $this->call('answerInlineQuery', [ 'inline_query_id' => $inlineQueryId, @@ -1402,7 +1448,7 @@ public function unbanChatMember($chatId, $userId) * Use this method to send answers to callback queries sent from inline keyboards. * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. * - * @param $callbackQueryId + * @param string $callbackQueryId * @param string|null $text * @param bool $showAlert * @param string|null $url @@ -1425,7 +1471,9 @@ public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = /** * Use this method to change the list of the bot's commands. Returns True on success. * - * @param ArrayOfBotCommand $commands + * @param ArrayOfBotCommand|BotCommand[] $commands + * @param string|null $scope + * @param string|null $languageCode * * @return mixed * @throws Exception @@ -1463,6 +1511,7 @@ public function getMyCommands() /** * Use this method to edit text messages sent by the bot or via the bot + * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param int|string $chatId * @param int $messageId @@ -1472,7 +1521,7 @@ public function getMyCommands() * @param bool $disablePreview * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * - * @return Message + * @return Message|true * @throws Exception */ public function editMessageText( @@ -1484,7 +1533,7 @@ public function editMessageText( $replyMarkup = null, $inlineMessageId = null ) { - return Message::fromResponse($this->call('editMessageText', [ + $response = $this->call('editMessageText', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'text' => $text, @@ -1492,11 +1541,17 @@ public function editMessageText( 'parse_mode' => $parseMode, 'disable_web_page_preview' => $disablePreview, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ])); + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** * Use this method to edit text messages sent by the bot or via the bot + * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param int|string $chatId * @param int $messageId @@ -1505,7 +1560,7 @@ public function editMessageText( * @param string $inlineMessageId * @param string|null $parseMode * - * @return Message + * @return Message|true * @throws InvalidArgumentException * @throws Exception */ @@ -1517,14 +1572,19 @@ public function editMessageCaption( $inlineMessageId = null, $parseMode = null ) { - return Message::fromResponse($this->call('editMessageCaption', [ + $response = $this->call('editMessageCaption', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, 'caption' => $caption, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'parse_mode' => $parseMode - ])); + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** @@ -1535,12 +1595,12 @@ public function editMessageCaption( * Use previously uploaded file via its file_id or specify a URL. * On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned * - * @param $chatId - * @param $messageId + * @param string $chatId + * @param string $messageId * @param InputMedia $media * @param string|null $inlineMessageId - * @param string|null $replyMarkup - * @return bool|Message + * @param InlineKeyboardMarkup|null $replyMarkup + * @return Message|true * * @throws Exception * @throws HttpException @@ -1553,24 +1613,30 @@ public function editMessageMedia( $inlineMessageId = null, $replyMarkup = null ) { - return Message::fromResponse($this->call('editMessageMedia', [ + $response = $this->call('editMessageMedia', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, 'media' => $media->toJson(), 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ])); + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** * Use this method to edit only the reply markup of messages sent by the bot or via the bot + * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param int|string $chatId * @param int $messageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param string $inlineMessageId * - * @return Message + * @return Message|true * @throws Exception */ public function editMessageReplyMarkup( @@ -1579,12 +1645,17 @@ public function editMessageReplyMarkup( $replyMarkup = null, $inlineMessageId = null ) { - return Message::fromResponse($this->call('editMessageReplyMarkup', [ + $response = $this->call('editMessageReplyMarkup', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ])); + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** @@ -1614,7 +1685,7 @@ public function deleteMessage($chatId, $messageId) */ public function __destruct() { - $this->curl && curl_close($this->curl); + curl_close($this->curl); } /** @@ -1638,16 +1709,22 @@ public function getFileUrl() * @param string $eventName * * @throws Exception + * + * @return void */ public function trackUpdate(Update $update, $eventName = 'Message') { if (!in_array($update->getUpdateId(), $this->trackedEvents)) { + $message = $update->getMessage(); + if (!$message) { + return; + } $this->trackedEvents[] = $update->getUpdateId(); - $this->track($update->getMessage(), $eventName); + $this->track($message, $eventName); if (count($this->trackedEvents) > self::MAX_TRACKED_EVENTS) { - $this->trackedEvents = array_slice($this->trackedEvents, round(self::MAX_TRACKED_EVENTS / 4)); + $this->trackedEvents = array_slice($this->trackedEvents, (int) round(self::MAX_TRACKED_EVENTS / 4)); } } } @@ -1659,6 +1736,8 @@ public function trackUpdate(Update $update, $eventName = 'Message') * @param string $eventName * * @throws Exception + * + * @return void */ public function track(Message $message, $eventName = 'Message') { @@ -1782,7 +1861,7 @@ public function answerShippingQuery($shippingQueryId, $ok = true, $shippingOptio * @param bool $ok * @param null|string $errorMessage * - * @return mixed + * @return bool * @throws Exception */ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null) @@ -2185,6 +2264,7 @@ public function sendMediaGroup( * Enable proxy for curl requests. Empty string will disable proxy. * * @param string $proxyString + * @param bool $socks5 * * @return BotApi */ @@ -2210,7 +2290,7 @@ public function setProxy($proxyString = '', $socks5 = false) * Use this method to send a native poll. A native poll can't be sent to a private chat. * On success, the sent \TelegramBot\Api\Types\Message is returned. * - * @param $chatId string|int Unique identifier for the target chat or username of the target channel + * @param string|int $chatId Unique identifier for the target chat or username of the target channel * (in the format @channelusername) * @param string $question Poll question, 1-255 characters * @param array $options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each @@ -2266,9 +2346,9 @@ public function sendPoll( * On success, the sent Message is returned. (Yes, we're aware of the “proper” singular of die. * But it's awkward, and we decided to help it change. One dice at a time!) * - * @param $chatId string|int Unique identifier for the target chat or username of the target channel + * @param string|int $chatId Unique identifier for the target chat or username of the target channel * (in the format @channelusername) - * @param $emoji string Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, + * @param string $emoji Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, * “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and * values 1-64 for “🎰”. Defaults to “🎲 * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. @@ -2280,7 +2360,7 @@ public function sendPoll( * custom reply keyboard, instructions to remove reply * keyboard or to force a reply from the user. * - * @return bool|Message + * @return Message * @throws Exception * @throws HttpException * @throws InvalidJsonException @@ -2495,6 +2575,8 @@ public function getForumTopicIconStickers() * * @param int $option The CURLOPT_XXX option to set * @param mixed $value The value to be set on option + * + * @return void */ public function setCurlOption($option, $value) { @@ -2505,6 +2587,8 @@ public function setCurlOption($option, $value) * Unset an option for a cURL transfer * * @param int $option The CURLOPT_XXX option to unset + * + * @return void */ public function unsetCurlOption($option) { @@ -2513,6 +2597,8 @@ public function unsetCurlOption($option) /** * Clean custom options + * + * @return void */ public function resetCurlOptions() { diff --git a/src/Botan.php b/src/Botan.php index 45ef34a1..87665207 100644 --- a/src/Botan.php +++ b/src/Botan.php @@ -6,6 +6,7 @@ /** * @deprecated + * @psalm-suppress all */ class Botan { @@ -17,7 +18,7 @@ class Botan /** * CURL object * - * @var + * @var resource */ protected $curl; @@ -41,8 +42,8 @@ public function __construct($token) throw new Exception('CURL not installed'); } - if (empty($token) || !is_string($token)) { - throw new InvalidArgumentException('Token should be a string'); + if (empty($token)) { + throw new InvalidArgumentException('Token should not be empty'); } $this->token = $token; @@ -57,6 +58,8 @@ public function __construct($token) * * @throws \TelegramBot\Api\Exception * @throws \TelegramBot\Api\HttpException + * + * @return void */ public function track(Message $message, $eventName = 'Message') { @@ -74,7 +77,10 @@ public function track(Message $message, $eventName = 'Message') ]; curl_setopt_array($this->curl, $options); - $result = BotApi::jsonValidate(curl_exec($this->curl), true); + /** @var string $response */ + $response = curl_exec($this->curl); + /** @var array $result */ + $result = BotApi::jsonValidate($response, true); BotApi::curlValidate($this->curl); diff --git a/src/Client.php b/src/Client.php index d347e135..3b08c184 100644 --- a/src/Client.php +++ b/src/Client.php @@ -64,41 +64,65 @@ public function command($name, Closure $action) return $this->on(self::getEvent($action), self::getChecker($name)); } + /** + * @return self + */ public function editedMessage(Closure $action) { return $this->on(self::getEditedMessageEvent($action), self::getEditedMessageChecker()); } + /** + * @return self + */ public function callbackQuery(Closure $action) { return $this->on(self::getCallbackQueryEvent($action), self::getCallbackQueryChecker()); } + /** + * @return self + */ public function channelPost(Closure $action) { return $this->on(self::getChannelPostEvent($action), self::getChannelPostChecker()); } + /** + * @return self + */ public function editedChannelPost(Closure $action) { return $this->on(self::getEditedChannelPostEvent($action), self::getEditedChannelPostChecker()); } + /** + * @return self + */ public function inlineQuery(Closure $action) { return $this->on(self::getInlineQueryEvent($action), self::getInlineQueryChecker()); } + /** + * @return self + */ public function chosenInlineResult(Closure $action) { return $this->on(self::getChosenInlineResultEvent($action), self::getChosenInlineResultChecker()); } + /** + * @return self + */ public function shippingQuery(Closure $action) { return $this->on(self::getShippingQueryEvent($action), self::getShippingQueryChecker()); } + /** + * @return self + */ public function preCheckoutQuery(Closure $action) { return $this->on(self::getPreCheckoutQueryEvent($action), self::getPreCheckoutQueryChecker()); @@ -124,6 +148,8 @@ public function on(Closure $event, Closure $checker = null) * Handle updates * * @param Update[] $updates + * + * @return void */ public function handle(array $updates) { @@ -136,16 +162,20 @@ public function handle(array $updates) /** * Webhook handler * - * @return array + * @return void * @throws \TelegramBot\Api\InvalidJsonException */ public function run() { - if ($data = BotApi::jsonValidate($this->getRawBody(), true)) { + if ($data = BotApi::jsonValidate((string) $this->getRawBody(), true)) { + /** @var array $data */ $this->handle([Update::fromResponse($data)]); } } + /** + * @return false|string + */ public function getRawBody() { return file_get_contents('php://input'); @@ -166,7 +196,7 @@ protected static function getEvent(Closure $action) return true; } - preg_match(self::REGEXP, $message->getText(), $matches); + preg_match(self::REGEXP, (string) $message->getText(), $matches); if (isset($matches[3]) && !empty($matches[3])) { $parameters = str_getcsv($matches[3], chr(32)); @@ -186,6 +216,9 @@ protected static function getEvent(Closure $action) }; } + /** + * @return Closure + */ protected static function getEditedMessageEvent(Closure $action) { return function (Update $update) use ($action) { @@ -199,6 +232,11 @@ protected static function getEditedMessageEvent(Closure $action) }; } + /** + * @return Closure + * + * @psalm-return Closure(Update):bool + */ protected static function getChannelPostEvent(Closure $action) { return function (Update $update) use ($action) { @@ -212,6 +250,9 @@ protected static function getChannelPostEvent(Closure $action) }; } + /** + * @return Closure + */ protected static function getCallbackQueryEvent(Closure $action) { return function (Update $update) use ($action) { @@ -225,6 +266,11 @@ protected static function getCallbackQueryEvent(Closure $action) }; } + /** + * @return Closure + * + * @psalm-return Closure(Update):bool + */ protected static function getEditedChannelPostEvent(Closure $action) { return function (Update $update) use ($action) { @@ -238,6 +284,9 @@ protected static function getEditedChannelPostEvent(Closure $action) }; } + /** + * @return Closure + */ protected static function getInlineQueryEvent(Closure $action) { return function (Update $update) use ($action) { @@ -251,6 +300,11 @@ protected static function getInlineQueryEvent(Closure $action) }; } + /** + * @return Closure + * + * @psalm-return Closure(Update):bool + */ protected static function getChosenInlineResultEvent(Closure $action) { return function (Update $update) use ($action) { @@ -264,6 +318,9 @@ protected static function getChosenInlineResultEvent(Closure $action) }; } + /** + * @return Closure + */ protected static function getShippingQueryEvent(Closure $action) { return function (Update $update) use ($action) { @@ -277,6 +334,11 @@ protected static function getShippingQueryEvent(Closure $action) }; } + /** + * @return Closure + * + * @psalm-return Closure(Update):bool + */ protected static function getPreCheckoutQueryEvent(Closure $action) { return function (Update $update) use ($action) { @@ -301,11 +363,15 @@ protected static function getChecker($name) { return function (Update $update) use ($name) { $message = $update->getMessage(); - if (is_null($message) || !strlen($message->getText())) { + if (!$message) { + return false; + } + $text = $message->getText(); + if (empty($text)) { return false; } - preg_match(self::REGEXP, $message->getText(), $matches); + preg_match(self::REGEXP, $text, $matches); return !empty($matches) && $matches[1] == $name; }; @@ -407,6 +473,12 @@ protected static function getPreCheckoutQueryChecker() }; } + /** + * @param string $name + * @param array $arguments + * @return mixed + * @throws BadMethodCallException + */ public function __call($name, array $arguments) { if (method_exists($this, $name)) { diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index d71be6be..6a1b451d 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -2,10 +2,8 @@ namespace TelegramBot\Api\Collection; -use TelegramBot\Api\Types\InputMedia\InputMedia; - /** - * Class Collection + * @extends \ArrayObject */ class Collection extends \ArrayObject { @@ -46,7 +44,7 @@ public function addItem(CollectionItemInterface $item, $key = null) } /** - * @param $key + * @param int|string $key * @throws KeyInvalidException * @return void */ @@ -58,8 +56,7 @@ public function deleteItem($key) } /** - * @param $key - * @return InputMedia + * @param int|string $key * @return CollectionItemInterface * @throws KeyInvalidException */ @@ -94,8 +91,11 @@ public function setMaxCount($maxCount) } /** - * @param $key + * @param int|string $key + * * @throws KeyInvalidException + * + * @return void */ private function checkItemKey($key) { diff --git a/src/Collection/CollectionItemInterface.php b/src/Collection/CollectionItemInterface.php index 1bdf2dc5..bdeb9f1d 100644 --- a/src/Collection/CollectionItemInterface.php +++ b/src/Collection/CollectionItemInterface.php @@ -4,5 +4,9 @@ interface CollectionItemInterface { + /** + * @param bool $inner + * @return array|string + */ public function toJson($inner = false); } diff --git a/src/Events/Event.php b/src/Events/Event.php index 9b6b8b54..fd7a45f3 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -7,7 +7,7 @@ class Event { /** - * @var \Closure + * @var \Closure|null */ protected $checker; @@ -22,7 +22,7 @@ class Event * @param \Closure $action * @param \Closure|null $checker */ - public function __construct(\Closure $action, \Closure $checker) + public function __construct(\Closure $action, \Closure $checker = null) { $this->action = $action; $this->checker = $checker; @@ -45,8 +45,6 @@ public function getChecker() } /** - * @param \TelegramBot\Api\Types\Update - * * @return mixed */ public function executeChecker(Update $message) @@ -59,16 +57,10 @@ public function executeChecker(Update $message) } /** - * @param \TelegramBot\Api\Types\Update - * * @return mixed */ public function executeAction(Update $message) { - if (is_callable($this->action)) { - return call_user_func($this->action, $message); - } - - return false; + return call_user_func($this->action, $message); } } diff --git a/src/Events/EventCollection.php b/src/Events/EventCollection.php index b8a4f345..af0481d4 100644 --- a/src/Events/EventCollection.php +++ b/src/Events/EventCollection.php @@ -19,7 +19,7 @@ class EventCollection /** * Botan tracker * - * @var \TelegramBot\Api\Botan + * @var \TelegramBot\Api\Botan|null */ protected $tracker; @@ -30,6 +30,7 @@ class EventCollection */ public function __construct($trackerToken = null) { + $this->events = []; if ($trackerToken) { @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); $this->tracker = new Botan($trackerToken); @@ -54,17 +55,17 @@ public function add(Closure $event, $checker = null) } /** - * @param \TelegramBot\Api\Types\Update + * @return void */ public function handle(Update $update) { foreach ($this->events as $event) { /* @var \TelegramBot\Api\Events\Event $event */ if ($event->executeChecker($update) === true) { - if (false === $event->executeAction($update)) { - if (!is_null($this->tracker)) { + if ($event->executeAction($update) === false) { + if ($this->tracker && ($message = $update->getMessage())) { $checker = new ReflectionFunction($event->getChecker()); - $this->tracker->track($update->getMessage(), $checker->getStaticVariables()['name']); + $this->tracker->track($message, $checker->getStaticVariables()['name']); } break; } diff --git a/src/TypeInterface.php b/src/TypeInterface.php index c3637843..7418fe9b 100644 --- a/src/TypeInterface.php +++ b/src/TypeInterface.php @@ -4,5 +4,9 @@ interface TypeInterface { + /** + * @param array $data + * @return static + */ public static function fromResponse($data); } diff --git a/src/Types/Animation.php b/src/Types/Animation.php index 512224a4..b412cc95 100644 --- a/src/Types/Animation.php +++ b/src/Types/Animation.php @@ -83,21 +83,21 @@ class Animation extends BaseType implements TypeInterface /** * Optional. Animation thumbnail as defined by sender * - * @var PhotoSize + * @var string|null */ protected $fileName; /** * Optional. Mime type of a file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; @@ -110,8 +110,8 @@ public function getDuration() } /** - * @param int $duration - * + * @param mixed $duration + * @return void * @throws InvalidArgumentException */ public function setDuration($duration) @@ -133,6 +133,7 @@ public function getFileId() /** * @param string $fileId + * @return void */ public function setFileId($fileId) { @@ -149,6 +150,7 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * @return void */ public function setFileUniqueId($fileUniqueId) { @@ -156,7 +158,7 @@ public function setFileUniqueId($fileUniqueId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -164,8 +166,8 @@ public function getFileSize() } /** - * @param int $fileSize - * + * @param mixed $fileSize + * @return void * @throws InvalidArgumentException */ public function setFileSize($fileSize) @@ -186,8 +188,8 @@ public function getHeight() } /** - * @param int $height - * + * @param mixed $height + * @return void * @throws InvalidArgumentException */ public function setHeight($height) @@ -200,7 +202,7 @@ public function setHeight($height) } /** - * @return string + * @return null|string */ public function getMimeType() { @@ -209,6 +211,7 @@ public function getMimeType() /** * @param string $mimeType + * @return void */ public function setMimeType($mimeType) { @@ -225,6 +228,7 @@ public function getThumb() /** * @param PhotoSize $thumb + * @return void */ public function setThumb(PhotoSize $thumb) { @@ -232,7 +236,7 @@ public function setThumb(PhotoSize $thumb) } /** - * @return string $fileName + * @return null|string $fileName */ public function getFileName() { @@ -241,6 +245,7 @@ public function getFileName() /** * @param string $fileName + * @return void */ public function setFileName($fileName) { @@ -256,8 +261,8 @@ public function getWidth() } /** - * @param int $width - * + * @param mixed $width + * @return void * @throws InvalidArgumentException */ public function setWidth($width) diff --git a/src/Types/ArrayOfArrayOfPhotoSize.php b/src/Types/ArrayOfArrayOfPhotoSize.php index 14491da4..3d2a1799 100644 --- a/src/Types/ArrayOfArrayOfPhotoSize.php +++ b/src/Types/ArrayOfArrayOfPhotoSize.php @@ -4,6 +4,10 @@ abstract class ArrayOfArrayOfPhotoSize { + /** + * @param array $data + * @return PhotoSize[][] + */ public static function fromResponse($data) { return array_map(function ($arrayOfPhotoSize) { diff --git a/src/Types/ArrayOfBotCommand.php b/src/Types/ArrayOfBotCommand.php index 6c6d3e22..59602c28 100644 --- a/src/Types/ArrayOfBotCommand.php +++ b/src/Types/ArrayOfBotCommand.php @@ -5,11 +5,11 @@ use TelegramBot\Api\Collection\Collection; use TelegramBot\Api\TypeInterface; -class ArrayOfBotCommand extends Collection implements TypeInterface +final class ArrayOfBotCommand extends Collection implements TypeInterface { public static function fromResponse($data) { - $arrayOfBotCommand = new static(); + $arrayOfBotCommand = new self(); foreach ($data as $botCommand) { $arrayOfBotCommand->addItem(BotCommand::fromResponse($botCommand)); } diff --git a/src/Types/ArrayOfChatMemberEntity.php b/src/Types/ArrayOfChatMemberEntity.php index 95333448..14362874 100644 --- a/src/Types/ArrayOfChatMemberEntity.php +++ b/src/Types/ArrayOfChatMemberEntity.php @@ -4,6 +4,10 @@ abstract class ArrayOfChatMemberEntity { + /** + * @param array $data + * @return ChatMember[] + */ public static function fromResponse($data) { $arrayOfChatMemberEntity = []; diff --git a/src/Types/ArrayOfMessageEntity.php b/src/Types/ArrayOfMessageEntity.php index 0b4e9945..cf05ff95 100644 --- a/src/Types/ArrayOfMessageEntity.php +++ b/src/Types/ArrayOfMessageEntity.php @@ -10,6 +10,10 @@ abstract class ArrayOfMessageEntity { + /** + * @param array $data + * @return MessageEntity[] + */ public static function fromResponse($data) { $arrayOfMessageEntity = []; diff --git a/src/Types/ArrayOfMessages.php b/src/Types/ArrayOfMessages.php index a1c316d3..f12359b2 100644 --- a/src/Types/ArrayOfMessages.php +++ b/src/Types/ArrayOfMessages.php @@ -4,6 +4,10 @@ abstract class ArrayOfMessages { + /** + * @param array $data + * @return Message[] + */ public static function fromResponse($data) { $arrayOfMessages = []; diff --git a/src/Types/ArrayOfPhotoSize.php b/src/Types/ArrayOfPhotoSize.php index e35ff840..d74b6f07 100644 --- a/src/Types/ArrayOfPhotoSize.php +++ b/src/Types/ArrayOfPhotoSize.php @@ -4,6 +4,10 @@ abstract class ArrayOfPhotoSize { + /** + * @param array $data + * @return PhotoSize[] + */ public static function fromResponse($data) { $arrayOfPhotoSize = []; diff --git a/src/Types/ArrayOfPollOption.php b/src/Types/ArrayOfPollOption.php index 9bea6719..3c589b09 100644 --- a/src/Types/ArrayOfPollOption.php +++ b/src/Types/ArrayOfPollOption.php @@ -4,6 +4,10 @@ abstract class ArrayOfPollOption { + /** + * @param array $data + * @return PollOption[] + */ public static function fromResponse($data) { $arrayOfPollOption = []; diff --git a/src/Types/ArrayOfSticker.php b/src/Types/ArrayOfSticker.php index d0e4400b..4da4a55b 100644 --- a/src/Types/ArrayOfSticker.php +++ b/src/Types/ArrayOfSticker.php @@ -4,6 +4,10 @@ abstract class ArrayOfSticker { + /** + * @param array $data + * @return Sticker[] + */ public static function fromResponse($data) { $arrayOfStickers = []; diff --git a/src/Types/ArrayOfUpdates.php b/src/Types/ArrayOfUpdates.php index 6c062b46..cacff951 100644 --- a/src/Types/ArrayOfUpdates.php +++ b/src/Types/ArrayOfUpdates.php @@ -4,6 +4,10 @@ abstract class ArrayOfUpdates { + /** + * @param array $data + * @return Update[] + */ public static function fromResponse($data) { $arrayOfUpdates = []; diff --git a/src/Types/ArrayOfUser.php b/src/Types/ArrayOfUser.php index cba90e73..cb4340ae 100644 --- a/src/Types/ArrayOfUser.php +++ b/src/Types/ArrayOfUser.php @@ -4,6 +4,10 @@ abstract class ArrayOfUser { + /** + * @param array $data + * @return User[] + */ public static function fromResponse($data) { $arrayOfUsers = []; diff --git a/src/Types/Audio.php b/src/Types/Audio.php index 4805e143..e3c8fb5c 100644 --- a/src/Types/Audio.php +++ b/src/Types/Audio.php @@ -53,28 +53,28 @@ class Audio extends BaseType implements TypeInterface /** * Optional. Performer of the audio as defined by sender or by audio tags * - * @var string + * @var string|null */ protected $performer; /** * Optional. Title of the audio as defined by sender or by audio tags * - * @var string + * @var string|null */ protected $title; /** * Optional. MIME type of the file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; @@ -94,8 +94,8 @@ public function getDuration() } /** - * @param int $duration - * + * @param mixed $duration + * @return void * @throws InvalidArgumentException */ public function setDuration($duration) @@ -108,7 +108,7 @@ public function setDuration($duration) } /** - * @return string + * @return null|string */ public function getPerformer() { @@ -117,6 +117,7 @@ public function getPerformer() /** * @param string $performer + * @return void */ public function setPerformer($performer) { @@ -124,7 +125,7 @@ public function setPerformer($performer) } /** - * @return string + * @return null|string */ public function getTitle() { @@ -133,6 +134,7 @@ public function getTitle() /** * @param string $title + * @return void */ public function setTitle($title) { @@ -149,6 +151,7 @@ public function getFileId() /** * @param string $fileId + * @return void */ public function setFileId($fileId) { @@ -156,7 +159,7 @@ public function setFileId($fileId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -164,8 +167,8 @@ public function getFileSize() } /** - * @param int $fileSize - * + * @param mixed $fileSize + * @return void * @throws InvalidArgumentException */ public function setFileSize($fileSize) @@ -178,7 +181,7 @@ public function setFileSize($fileSize) } /** - * @return string + * @return null|string */ public function getMimeType() { @@ -187,6 +190,7 @@ public function getMimeType() /** * @param string $mimeType + * @return void */ public function setMimeType($mimeType) { @@ -203,6 +207,7 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * @return void */ public function setFileUniqueId($fileUniqueId) { diff --git a/src/Types/BotCommand.php b/src/Types/BotCommand.php index 22a0685b..b1c78bd0 100644 --- a/src/Types/BotCommand.php +++ b/src/Types/BotCommand.php @@ -49,6 +49,7 @@ public function getCommand() /** * @param string $command + * @return void */ public function setCommand($command) { @@ -65,6 +66,7 @@ public function getDescription() /** * @param string $description + * @return void */ public function setDescription($description) { diff --git a/src/Types/CallbackQuery.php b/src/Types/CallbackQuery.php index 9d325040..b6b0ef95 100644 --- a/src/Types/CallbackQuery.php +++ b/src/Types/CallbackQuery.php @@ -59,7 +59,7 @@ class CallbackQuery extends BaseType * Note that message content and message date will not be available * if the message is too old * - * @var \TelegramBot\Api\Types\Message + * @var \TelegramBot\Api\Types\Message|null */ protected $message; @@ -67,7 +67,7 @@ class CallbackQuery extends BaseType * Optional. Identifier of the message sent via the bot in inline mode, * that originated the query. * - * @var string + * @var string|null */ protected $inlineMessageId; @@ -83,7 +83,7 @@ class CallbackQuery extends BaseType * Optional. Data associated with the callback button. * Be aware that a bad client can send arbitrary data in this field. * - * @var string + * @var string|null */ protected $data; @@ -91,7 +91,7 @@ class CallbackQuery extends BaseType * Optional. Short name of a Game to be returned, * serves as the unique identifier for the game * - * @var string + * @var string|null */ protected $gameShortName; @@ -105,6 +105,7 @@ public function getId() /** * @param string $id + * @return void */ public function setId($id) { @@ -121,6 +122,7 @@ public function getFrom() /** * @param User $from + * @return void */ public function setFrom(User $from) { @@ -128,7 +130,7 @@ public function setFrom(User $from) } /** - * @return Message + * @return Message|null */ public function getMessage() { @@ -137,6 +139,7 @@ public function getMessage() /** * @param Message $message + * @return void */ public function setMessage($message) { @@ -144,7 +147,7 @@ public function setMessage($message) } /** - * @return string + * @return null|string */ public function getInlineMessageId() { @@ -153,6 +156,7 @@ public function getInlineMessageId() /** * @param string $inlineMessageId + * @return void */ public function setInlineMessageId($inlineMessageId) { @@ -169,6 +173,7 @@ public function getChatInstance() /** * @param string $chatInstance + * @return void */ public function setChatInstance($chatInstance) { @@ -176,7 +181,7 @@ public function setChatInstance($chatInstance) } /** - * @return string + * @return null|string */ public function getData() { @@ -185,6 +190,7 @@ public function getData() /** * @param string $data + * @return void */ public function setData($data) { @@ -192,7 +198,7 @@ public function setData($data) } /** - * @return string + * @return null|string */ public function getGameShortName() { @@ -201,6 +207,7 @@ public function getGameShortName() /** * @param string $gameShortName + * @return void */ public function setGameShortName($gameShortName) { diff --git a/src/Types/Chat.php b/src/Types/Chat.php index 39377365..1eee67e6 100644 --- a/src/Types/Chat.php +++ b/src/Types/Chat.php @@ -52,7 +52,7 @@ class Chat extends BaseType implements TypeInterface /** * Unique identifier for this chat, not exceeding 1e13 by absolute value * - * @var int|string + * @var int|float|string */ protected $id; @@ -66,70 +66,70 @@ class Chat extends BaseType implements TypeInterface /** * Optional. Title, for channels and group chats * - * @var string + * @var string|null */ protected $title; /** * Optional. Username, for private chats and channels if available * - * @var string + * @var string|null */ protected $username; /** * Optional. First name of the other party in a private chat * - * @var string + * @var string|null */ protected $firstName; /** * Optional. Last name of the other party in a private chat * - * @var string + * @var string|null */ protected $lastName; /** * Optional. Chat photo. Returned only in getChat. * - * @var ChatPhoto + * @var ChatPhoto|null */ protected $photo; /** * Optional. Bio of the other party in a private chat. Returned only in getChat * - * @var string + * @var string|null */ protected $bio; /** * Optional. Description, for supergroups and channel chats. Returned only in getChat. * - * @var string + * @var string|null */ protected $description; /** * Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat. * - * @var string + * @var string|null */ protected $inviteLink; /** * Optional. Pinned message, for supergroups. Returned only in getChat. * - * @var Message + * @var Message|null */ protected $pinnedMessage; /** * Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. * - * @var ChatPermissions + * @var ChatPermissions|null */ protected $permissions; @@ -137,21 +137,21 @@ class Chat extends BaseType implements TypeInterface * Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged * user. Returned only in getChat. * - * @var int + * @var int|null */ protected $slowModeDelay; /** * Optional. For supergroups, name of group sticker set. Returned only in getChat. * - * @var string + * @var string|null */ protected $stickerSetName; /** * Optional. True, if the bot can change the group sticker set. Returned only in getChat. * - * @var bool + * @var bool|null */ protected $canSetStickerSet; @@ -161,28 +161,28 @@ class Chat extends BaseType implements TypeInterface * languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 * bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat. * - * @var int + * @var int|null */ protected $linkedChatId; /** * Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. * - * @var ChatLocation + * @var ChatLocation|null */ protected $location; /** * Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. * - * @var bool + * @var bool|null */ protected $joinToSendMessages; /** * Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat. * - * @var bool + * @var bool|null */ protected $joinByRequest; @@ -190,21 +190,21 @@ class Chat extends BaseType implements TypeInterface * Optional. Time after which all messages sent to the chat will be automatically deleted; in seconds. Returned * only in getChat. * - * @var int + * @var int|null */ protected $messageAutoDeleteTime; /** * Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. * - * @var bool + * @var bool|null */ protected $hasProtectedContent; /** * Optional. True, if the supergroup chat is a forum (has topics enabled) * - * @var bool + * @var bool|null */ protected $isForum; @@ -212,14 +212,14 @@ class Chat extends BaseType implements TypeInterface * Optional. If non-empty, the list of all active chat usernames; * for private chats, supergroups and channels. Returned only in getChat. * - * @var array[] + * @var array[]|null */ protected $activeUsernames; /** * Optional. Custom emoji identifier of emoji status of the other party in a private chat. Returned only in getChat. * - * @var string + * @var string|null */ protected $emojiStatusCustomEmojiId; @@ -228,7 +228,7 @@ class Chat extends BaseType implements TypeInterface * to use tg://user?id= links only in chats with the user. * Returned only in getChat. * - * @var bool + * @var bool|null */ protected $hasPrivateForwards; @@ -236,12 +236,12 @@ class Chat extends BaseType implements TypeInterface * Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. * Returned only in getChat. * - * @var bool + * @var bool|null */ protected $hasRestrictedVoiceAndVideoMessages; /** - * @return int|string + * @return int|float|string */ public function getId() { @@ -249,8 +249,8 @@ public function getId() } /** - * @param int|string $id - * + * @param mixed $id + * @return void * @throws InvalidArgumentException */ public function setId($id) @@ -272,6 +272,7 @@ public function getType() /** * @param string $type + * @return void */ public function setType($type) { @@ -279,7 +280,7 @@ public function setType($type) } /** - * @return string + * @return null|string */ public function getTitle() { @@ -288,6 +289,7 @@ public function getTitle() /** * @param string $title + * @return void */ public function setTitle($title) { @@ -295,7 +297,7 @@ public function setTitle($title) } /** - * @return string + * @return null|string */ public function getUsername() { @@ -304,6 +306,7 @@ public function getUsername() /** * @param string $username + * @return void */ public function setUsername($username) { @@ -311,7 +314,7 @@ public function setUsername($username) } /** - * @return string + * @return null|string */ public function getFirstName() { @@ -320,6 +323,7 @@ public function getFirstName() /** * @param string $firstName + * @return void */ public function setFirstName($firstName) { @@ -327,7 +331,7 @@ public function setFirstName($firstName) } /** - * @return string + * @return null|string */ public function getLastName() { @@ -336,6 +340,7 @@ public function getLastName() /** * @param string $lastName + * @return void */ public function setLastName($lastName) { @@ -343,7 +348,7 @@ public function setLastName($lastName) } /** - * @return ChatPhoto + * @return ChatPhoto|null */ public function getPhoto() { @@ -352,6 +357,7 @@ public function getPhoto() /** * @param ChatPhoto $photo + * @return void */ public function setPhoto($photo) { @@ -359,7 +365,7 @@ public function setPhoto($photo) } /** - * @return string + * @return null|string */ public function getBio() { @@ -368,6 +374,7 @@ public function getBio() /** * @param string $bio + * @return void */ public function setBio($bio) { @@ -375,7 +382,7 @@ public function setBio($bio) } /** - * @return string + * @return null|string */ public function getDescription() { @@ -384,6 +391,7 @@ public function getDescription() /** * @param string $description + * @return void */ public function setDescription($description) { @@ -391,7 +399,7 @@ public function setDescription($description) } /** - * @return string + * @return null|string */ public function getInviteLink() { @@ -400,6 +408,7 @@ public function getInviteLink() /** * @param string $inviteLink + * @return void */ public function setInviteLink($inviteLink) { @@ -407,7 +416,7 @@ public function setInviteLink($inviteLink) } /** - * @return Message + * @return Message|null */ public function getPinnedMessage() { @@ -416,6 +425,7 @@ public function getPinnedMessage() /** * @param Message $pinnedMessage + * @return void */ public function setPinnedMessage($pinnedMessage) { @@ -423,7 +433,7 @@ public function setPinnedMessage($pinnedMessage) } /** - * @return ChatPermissions + * @return ChatPermissions|null */ public function getPermissions() { @@ -432,6 +442,7 @@ public function getPermissions() /** * @param ChatPermissions $permissions + * @return void */ public function setPermissions($permissions) { @@ -439,7 +450,7 @@ public function setPermissions($permissions) } /** - * @return int + * @return int|null */ public function getSlowModeDelay() { @@ -448,6 +459,7 @@ public function getSlowModeDelay() /** * @param int $slowModeDelay + * @return void */ public function setSlowModeDelay($slowModeDelay) { @@ -455,7 +467,7 @@ public function setSlowModeDelay($slowModeDelay) } /** - * @return string + * @return null|string */ public function getStickerSetName() { @@ -464,6 +476,7 @@ public function getStickerSetName() /** * @param string $stickerSetName + * @return void */ public function setStickerSetName($stickerSetName) { @@ -471,7 +484,7 @@ public function setStickerSetName($stickerSetName) } /** - * @return bool + * @return bool|null */ public function getCanSetStickerSet() { @@ -480,6 +493,7 @@ public function getCanSetStickerSet() /** * @param bool $canSetStickerSet + * @return void */ public function setCanSetStickerSet($canSetStickerSet) { @@ -487,7 +501,7 @@ public function setCanSetStickerSet($canSetStickerSet) } /** - * @return int + * @return int|null */ public function getLinkedChatId() { @@ -496,6 +510,7 @@ public function getLinkedChatId() /** * @param int $linkedChatId + * @return void */ public function setLinkedChatId($linkedChatId) { @@ -503,7 +518,7 @@ public function setLinkedChatId($linkedChatId) } /** - * @return ChatLocation + * @return ChatLocation|null */ public function getLocation() { @@ -512,6 +527,7 @@ public function getLocation() /** * @param ChatLocation $location + * @return void */ public function setLocation($location) { @@ -519,7 +535,7 @@ public function setLocation($location) } /** - * @return bool + * @return bool|null */ public function getJoinToSendMessages() { @@ -528,6 +544,7 @@ public function getJoinToSendMessages() /** * @param bool $joinToSendMessages + * @return void */ public function setJoinToSendMessages($joinToSendMessages) { @@ -535,7 +552,7 @@ public function setJoinToSendMessages($joinToSendMessages) } /** - * @return bool + * @return bool|null */ public function getJoinByRequest() { @@ -544,6 +561,7 @@ public function getJoinByRequest() /** * @param bool $joinByRequest + * @return void */ public function setJoinByRequest($joinByRequest) { @@ -551,7 +569,7 @@ public function setJoinByRequest($joinByRequest) } /** - * @return int + * @return int|null */ public function getMessageAutoDeleteTime() { @@ -560,6 +578,7 @@ public function getMessageAutoDeleteTime() /** * @param int $messageAutoDeleteTime + * @return void */ public function setMessageAutoDeleteTime($messageAutoDeleteTime) { @@ -567,7 +586,7 @@ public function setMessageAutoDeleteTime($messageAutoDeleteTime) } /** - * @return bool + * @return bool|null */ public function getHasProtectedContent() { @@ -576,6 +595,7 @@ public function getHasProtectedContent() /** * @param bool $hasProtectedContent + * @return void */ public function setHasProtectedContent($hasProtectedContent) { @@ -583,7 +603,7 @@ public function setHasProtectedContent($hasProtectedContent) } /** - * @return bool + * @return bool|null */ public function getIsForum() { @@ -592,6 +612,7 @@ public function getIsForum() /** * @param bool $isForum + * @return void */ public function setIsForum($isForum) { @@ -599,7 +620,9 @@ public function setIsForum($isForum) } /** - * @return array + * @return array[]|null + * + * @psalm-return array|null */ public function getActiveUsernames() { @@ -608,6 +631,7 @@ public function getActiveUsernames() /** * @param array $activeUsernames + * @return void */ public function setActiveUsernames($activeUsernames) { @@ -615,7 +639,7 @@ public function setActiveUsernames($activeUsernames) } /** - * @return bool + * @return null|string */ public function getEmojiStatusCustomEmojiId() { @@ -623,7 +647,8 @@ public function getEmojiStatusCustomEmojiId() } /** - * @param bool $emojiStatusCustomEmojiId + * @param string $emojiStatusCustomEmojiId + * @return void */ public function setEmojiStatusCustomEmojiId($emojiStatusCustomEmojiId) { @@ -631,7 +656,7 @@ public function setEmojiStatusCustomEmojiId($emojiStatusCustomEmojiId) } /** - * @return bool + * @return bool|null */ public function getHasPrivateForwards() { @@ -640,6 +665,7 @@ public function getHasPrivateForwards() /** * @param bool $hasPrivateForwards + * @return void */ public function setHasPrivateForwards($hasPrivateForwards) { @@ -647,7 +673,7 @@ public function setHasPrivateForwards($hasPrivateForwards) } /** - * @return bool + * @return bool|null */ public function getHasRestrictedVoiceAndVideoMessages() { @@ -656,6 +682,7 @@ public function getHasRestrictedVoiceAndVideoMessages() /** * @param bool $hasRestrictedVoiceAndVideoMessages + * @return void */ public function setHasRestrictedVoiceAndVideoMessages($hasRestrictedVoiceAndVideoMessages) { diff --git a/src/Types/ChatLocation.php b/src/Types/ChatLocation.php index 6b4207ce..492b35be 100644 --- a/src/Types/ChatLocation.php +++ b/src/Types/ChatLocation.php @@ -48,6 +48,7 @@ public function getLocation() /** * @param Location $location + * @return void */ public function setLocation($location) { @@ -64,6 +65,7 @@ public function getAddress() /** * @param string $address + * @return void */ public function setAddress($address) { diff --git a/src/Types/ChatMember.php b/src/Types/ChatMember.php index 8ba126a3..808597e0 100644 --- a/src/Types/ChatMember.php +++ b/src/Types/ChatMember.php @@ -59,63 +59,63 @@ class ChatMember extends BaseType /** * Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time * - * @var integer + * @var integer|null */ protected $untilDate; /** * Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user * - * @var bool + * @var bool|null */ protected $canBeEdited; /** * Optional. Administrators only. True, if the administrator can change the chat title, photo and other settings * - * @var bool + * @var bool|null */ protected $canChangeInfo; /** * Optional. Administrators only. True, if the administrator can post in the channel, channels only * - * @var bool + * @var bool|null */ protected $canPostMessages; /** * Optional. Administrators only. True, if the administrator can edit messages of other users, channels only * - * @var bool + * @var bool|null */ protected $canEditMessages; /** * Optional. Administrators only. True, if the administrator can delete messages of other users * - * @var bool + * @var bool|null */ protected $canDeleteMessages; /** * Optional. Administrators only. True, if the administrator can invite new users to the chat * - * @var bool + * @var bool|null */ protected $canInviteUsers; /** * Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members * - * @var bool + * @var bool|null */ protected $canRestrictMembers; /** * Optional. Administrators only. True, if the administrator can pin messages, supergroups only * - * @var bool + * @var bool|null */ protected $canPinMessages; @@ -124,14 +124,14 @@ class ChatMember extends BaseType * privileges or demote administrators that he has promoted, directly or indirectly * (promoted by administrators that were appointed by the user) * - * @var bool + * @var bool|null */ protected $canPromoteMembers; /** * Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues * - * @var bool + * @var bool|null */ protected $canSendMessages; @@ -139,7 +139,7 @@ class ChatMember extends BaseType * Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes * and voice notes, implies can_send_messages * - * @var bool + * @var bool|null */ protected $canSendMediaMessages; @@ -147,7 +147,7 @@ class ChatMember extends BaseType * Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, * implies can_send_media_messages * - * @var bool + * @var bool|null */ protected $canSendOtherMessages; @@ -155,14 +155,14 @@ class ChatMember extends BaseType * Optional. Restricted only. True, if user may add web page previews to his messages, * implies can_send_media_messages * - * @var bool + * @var bool|null */ protected $canAddWebPagePreviews; /** * Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only * - * @var bool + * @var bool|null */ protected $canManageTopics; @@ -176,7 +176,7 @@ class ChatMember extends BaseType /** * Optional. Custom title for this user * - * @var string + * @var string|null */ protected $customTitle; @@ -206,6 +206,7 @@ public function getUser() /** * @param User $user + * @return void */ public function setUser($user) { @@ -222,6 +223,7 @@ public function getStatus() /** * @param string $status + * @return void */ public function setStatus($status) { @@ -229,7 +231,7 @@ public function setStatus($status) } /** - * @return int + * @return int|null */ public function getUntilDate() { @@ -238,6 +240,7 @@ public function getUntilDate() /** * @param int $untilDate + * @return void */ public function setUntilDate($untilDate) { @@ -245,7 +248,7 @@ public function setUntilDate($untilDate) } /** - * @return bool + * @return bool|null */ public function getCanBeEdited() { @@ -254,6 +257,7 @@ public function getCanBeEdited() /** * @param bool $canBeEdited + * @return void */ public function setCanBeEdited($canBeEdited) { @@ -261,7 +265,7 @@ public function setCanBeEdited($canBeEdited) } /** - * @return bool + * @return bool|null */ public function getCanChangeInfo() { @@ -270,6 +274,7 @@ public function getCanChangeInfo() /** * @param bool $canChangeInfo + * @return void */ public function setCanChangeInfo($canChangeInfo) { @@ -277,7 +282,7 @@ public function setCanChangeInfo($canChangeInfo) } /** - * @return bool + * @return bool|null */ public function getCanPostMessages() { @@ -286,6 +291,7 @@ public function getCanPostMessages() /** * @param bool $canPostMessages + * @return void */ public function setCanPostMessages($canPostMessages) { @@ -293,7 +299,7 @@ public function setCanPostMessages($canPostMessages) } /** - * @return bool + * @return bool|null */ public function getCanEditMessages() { @@ -302,6 +308,7 @@ public function getCanEditMessages() /** * @param bool $canEditMessages + * @return void */ public function setCanEditMessages($canEditMessages) { @@ -309,7 +316,7 @@ public function setCanEditMessages($canEditMessages) } /** - * @return bool + * @return bool|null */ public function getCanDeleteMessages() { @@ -318,6 +325,7 @@ public function getCanDeleteMessages() /** * @param bool $canDeleteMessages + * @return void */ public function setCanDeleteMessages($canDeleteMessages) { @@ -325,7 +333,7 @@ public function setCanDeleteMessages($canDeleteMessages) } /** - * @return bool + * @return bool|null */ public function getCanInviteUsers() { @@ -334,6 +342,7 @@ public function getCanInviteUsers() /** * @param bool $canInviteUsers + * @return void */ public function setCanInviteUsers($canInviteUsers) { @@ -341,7 +350,7 @@ public function setCanInviteUsers($canInviteUsers) } /** - * @return bool + * @return bool|null */ public function getCanRestrictMembers() { @@ -350,6 +359,7 @@ public function getCanRestrictMembers() /** * @param bool $canRestrictMembers + * @return void */ public function setCanRestrictMembers($canRestrictMembers) { @@ -357,7 +367,7 @@ public function setCanRestrictMembers($canRestrictMembers) } /** - * @return bool + * @return bool|null */ public function getCanPinMessages() { @@ -366,6 +376,7 @@ public function getCanPinMessages() /** * @param bool $canPinMessages + * @return void */ public function setCanPinMessages($canPinMessages) { @@ -373,7 +384,7 @@ public function setCanPinMessages($canPinMessages) } /** - * @return bool + * @return bool|null */ public function getCanPromoteMembers() { @@ -382,6 +393,7 @@ public function getCanPromoteMembers() /** * @param bool $canPromoteMembers + * @return void */ public function setCanPromoteMembers($canPromoteMembers) { @@ -389,7 +401,7 @@ public function setCanPromoteMembers($canPromoteMembers) } /** - * @return bool + * @return bool|null */ public function getCanSendMessages() { @@ -398,6 +410,7 @@ public function getCanSendMessages() /** * @param bool $canSendMessages + * @return void */ public function setCanSendMessages($canSendMessages) { @@ -405,7 +418,7 @@ public function setCanSendMessages($canSendMessages) } /** - * @return bool + * @return bool|null */ public function getCanSendMediaMessages() { @@ -414,6 +427,7 @@ public function getCanSendMediaMessages() /** * @param bool $canSendMediaMessages + * @return void */ public function setCanSendMediaMessages($canSendMediaMessages) { @@ -421,7 +435,7 @@ public function setCanSendMediaMessages($canSendMediaMessages) } /** - * @return bool + * @return bool|null */ public function getCanSendOtherMessages() { @@ -430,6 +444,7 @@ public function getCanSendOtherMessages() /** * @param bool $canSendOtherMessages + * @return void */ public function setCanSendOtherMessages($canSendOtherMessages) { @@ -437,7 +452,7 @@ public function setCanSendOtherMessages($canSendOtherMessages) } /** - * @return bool + * @return bool|null */ public function getCanAddWebPagePreviews() { @@ -446,6 +461,7 @@ public function getCanAddWebPagePreviews() /** * @param bool $canAddWebPagePreviews + * @return void */ public function setCanAddWebPagePreviews($canAddWebPagePreviews) { @@ -462,6 +478,7 @@ public function getCanManageChat() /** * @param bool $canManageChat + * @return void */ public function setCanManageChat($canManageChat) { @@ -478,6 +495,7 @@ public function getIsAnonymous() /** * @param bool $isAnonymous + * @return void */ public function setIsAnonymous($isAnonymous) { @@ -494,6 +512,7 @@ public function getCanSendPolls() /** * @param bool $canSendPolls + * @return void */ public function setCanSendPolls($canSendPolls) { @@ -501,7 +520,7 @@ public function setCanSendPolls($canSendPolls) } /** - * @return bool + * @return bool|null */ public function getCanManageTopics() { @@ -510,6 +529,7 @@ public function getCanManageTopics() /** * @param bool $canManageTopics + * @return void */ public function setCanManageTopics($canManageTopics) { @@ -517,7 +537,7 @@ public function setCanManageTopics($canManageTopics) } /** - * @return string + * @return null|string */ public function getCustomTitle() { @@ -526,6 +546,7 @@ public function getCustomTitle() /** * @param string $customTitle + * @return void */ public function setCustomTitle($customTitle) { diff --git a/src/Types/ChatPermissions.php b/src/Types/ChatPermissions.php index c7c2041f..3e93d3d7 100644 --- a/src/Types/ChatPermissions.php +++ b/src/Types/ChatPermissions.php @@ -33,7 +33,7 @@ class ChatPermissions extends BaseType implements TypeInterface /** * Optional. True, if the user is allowed to send text messages, contacts, locations and venues * - * @var bool + * @var bool|null */ protected $canSendMessages; @@ -41,14 +41,14 @@ class ChatPermissions extends BaseType implements TypeInterface * Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, * implies can_send_messages * - * @var bool + * @var bool|null */ protected $canSendMediaMessages; /** * Optional. True, if the user is allowed to send polls, implies can_send_messages * - * @var bool + * @var bool|null */ protected $canSendPolls; @@ -56,7 +56,7 @@ class ChatPermissions extends BaseType implements TypeInterface * Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, implies * can_send_media_messages * - * @var bool + * @var bool|null */ protected $canSendOtherMessages; @@ -64,7 +64,7 @@ class ChatPermissions extends BaseType implements TypeInterface * Optional. True, if the user is allowed to add web page previews to their messages, implies * can_send_media_messages * - * @var bool + * @var bool|null */ protected $canAddWebPagePreviews; @@ -72,26 +72,26 @@ class ChatPermissions extends BaseType implements TypeInterface * Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public * supergroups * - * @var bool + * @var bool|null */ protected $canChangeInfo; /** * Optional. True, if the user is allowed to invite new users to the chat * - * @var bool + * @var bool|null */ protected $canInviteUsers; /** * Optional. True, if the user is allowed to pin messages. Ignored in public supergroups * - * @var bool + * @var bool|null */ protected $canPinMessages; /** - * @return bool + * @return bool|null */ public function isCanSendMessages() { @@ -100,6 +100,7 @@ public function isCanSendMessages() /** * @param bool $canSendMessages + * @return void */ public function setCanSendMessages($canSendMessages) { @@ -107,7 +108,7 @@ public function setCanSendMessages($canSendMessages) } /** - * @return bool + * @return bool|null */ public function isCanSendMediaMessages() { @@ -116,6 +117,7 @@ public function isCanSendMediaMessages() /** * @param bool $canSendMediaMessages + * @return void */ public function setCanSendMediaMessages($canSendMediaMessages) { @@ -123,7 +125,7 @@ public function setCanSendMediaMessages($canSendMediaMessages) } /** - * @return bool + * @return bool|null */ public function isCanSendPolls() { @@ -132,6 +134,7 @@ public function isCanSendPolls() /** * @param bool $canSendPolls + * @return void */ public function setCanSendPolls($canSendPolls) { @@ -139,7 +142,7 @@ public function setCanSendPolls($canSendPolls) } /** - * @return bool + * @return bool|null */ public function isCanSendOtherMessages() { @@ -148,6 +151,7 @@ public function isCanSendOtherMessages() /** * @param bool $canSendOtherMessages + * @return void */ public function setCanSendOtherMessages($canSendOtherMessages) { @@ -155,7 +159,7 @@ public function setCanSendOtherMessages($canSendOtherMessages) } /** - * @return bool + * @return bool|null */ public function isCanAddWebPagePreviews() { @@ -164,6 +168,7 @@ public function isCanAddWebPagePreviews() /** * @param bool $canAddWebPagePreviews + * @return void */ public function setCanAddWebPagePreviews($canAddWebPagePreviews) { @@ -171,7 +176,7 @@ public function setCanAddWebPagePreviews($canAddWebPagePreviews) } /** - * @return bool + * @return bool|null */ public function isCanChangeInfo() { @@ -180,6 +185,7 @@ public function isCanChangeInfo() /** * @param bool $canChangeInfo + * @return void */ public function setCanChangeInfo($canChangeInfo) { @@ -187,7 +193,7 @@ public function setCanChangeInfo($canChangeInfo) } /** - * @return bool + * @return bool|null */ public function isCanInviteUsers() { @@ -196,6 +202,7 @@ public function isCanInviteUsers() /** * @param bool $canInviteUsers + * @return void */ public function setCanInviteUsers($canInviteUsers) { @@ -203,7 +210,7 @@ public function setCanInviteUsers($canInviteUsers) } /** - * @return bool + * @return bool|null */ public function isCanPinMessages() { @@ -212,6 +219,7 @@ public function isCanPinMessages() /** * @param bool $canPinMessages + * @return void */ public function setCanPinMessages($canPinMessages) { diff --git a/src/Types/ChatPhoto.php b/src/Types/ChatPhoto.php index 3dca2895..acce238d 100644 --- a/src/Types/ChatPhoto.php +++ b/src/Types/ChatPhoto.php @@ -47,6 +47,7 @@ public function getSmallFileId() /** * @param string $smallFileId + * @return void */ public function setSmallFileId($smallFileId) { @@ -63,6 +64,7 @@ public function getBigFileId() /** * @param string $bigFileId + * @return void */ public function setBigFileId($bigFileId) { diff --git a/src/Types/Contact.php b/src/Types/Contact.php index 7069c10c..eb4d671f 100644 --- a/src/Types/Contact.php +++ b/src/Types/Contact.php @@ -50,21 +50,21 @@ class Contact extends BaseType implements TypeInterface /** * Optional. Contact's last name * - * @var string + * @var string|null */ protected $lastName; /** * Optional. Contact's user identifier in Telegram * - * @var int + * @var int|null */ protected $userId; /** * Optional. Additional data about the contact in the form of a vCard * - * @var string + * @var string|null */ protected $vcard; @@ -78,6 +78,7 @@ public function getFirstName() /** * @param string $firstName + * @return void */ public function setFirstName($firstName) { @@ -85,7 +86,7 @@ public function setFirstName($firstName) } /** - * @return string + * @return null|string */ public function getLastName() { @@ -94,6 +95,7 @@ public function getLastName() /** * @param string $lastName + * @return void */ public function setLastName($lastName) { @@ -110,6 +112,7 @@ public function getPhoneNumber() /** * @param string $phoneNumber + * @return void */ public function setPhoneNumber($phoneNumber) { @@ -117,7 +120,7 @@ public function setPhoneNumber($phoneNumber) } /** - * @return int + * @return int|null */ public function getUserId() { @@ -126,6 +129,7 @@ public function getUserId() /** * @param int $userId + * @return void */ public function setUserId($userId) { @@ -133,7 +137,7 @@ public function setUserId($userId) } /** - * @return string + * @return null|string */ public function getVCard() { @@ -142,6 +146,7 @@ public function getVCard() /** * @param string $vcard + * @return void */ public function setVCard($vcard) { diff --git a/src/Types/Dice.php b/src/Types/Dice.php index d0bcfa21..b2077418 100644 --- a/src/Types/Dice.php +++ b/src/Types/Dice.php @@ -52,6 +52,7 @@ public function getEmoji() /** * @param string $emoji + * @return void */ public function setEmoji($emoji) { @@ -68,6 +69,7 @@ public function getValue() /** * @param int $value + * @return void */ public function setValue($value) { diff --git a/src/Types/Document.php b/src/Types/Document.php index 8c65534a..a60f6f5b 100644 --- a/src/Types/Document.php +++ b/src/Types/Document.php @@ -53,21 +53,21 @@ class Document extends BaseType implements TypeInterface /** * Optional. Original filename as defined by sender * - * @var string + * @var string|null */ protected $fileName; /** * Optional. MIME type of the file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; @@ -88,6 +88,7 @@ public function getFileId() /** * @param string $fileId + * @return void */ public function setFileId($fileId) { @@ -95,7 +96,7 @@ public function setFileId($fileId) } /** - * @return string + * @return null|string */ public function getFileName() { @@ -104,6 +105,7 @@ public function getFileName() /** * @param string $fileName + * @return void */ public function setFileName($fileName) { @@ -111,7 +113,7 @@ public function setFileName($fileName) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -119,8 +121,8 @@ public function getFileSize() } /** - * @param int $fileSize - * + * @param mixed $fileSize + * @return void * @throws InvalidArgumentException */ public function setFileSize($fileSize) @@ -133,7 +135,7 @@ public function setFileSize($fileSize) } /** - * @return string + * @return null|string */ public function getMimeType() { @@ -142,6 +144,7 @@ public function getMimeType() /** * @param string $mimeType + * @return void */ public function setMimeType($mimeType) { @@ -158,6 +161,7 @@ public function getThumb() /** * @param PhotoSize $thumb + * @return void */ public function setThumb(PhotoSize $thumb) { @@ -174,6 +178,7 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * @return void */ public function setFileUniqueId($fileUniqueId) { diff --git a/src/Types/File.php b/src/Types/File.php index 2b6791fd..eb2c5232 100644 --- a/src/Types/File.php +++ b/src/Types/File.php @@ -46,14 +46,14 @@ class File extends BaseType implements TypeInterface /** * Optional. File size, if known * - * @var int + * @var int|null */ protected $fileSize; /** * Optional. File path. Use https://api.telegram.org/file/bot/ to get the file. * - * @var string + * @var string|null */ protected $filePath; @@ -74,6 +74,7 @@ public function getFileId() /** * @param string $fileId + * @return void */ public function setFileId($fileId) { @@ -81,7 +82,7 @@ public function setFileId($fileId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -89,8 +90,8 @@ public function getFileSize() } /** - * @param int $fileSize - * + * @param mixed $fileSize + * @return void * @throws InvalidArgumentException */ public function setFileSize($fileSize) @@ -103,7 +104,7 @@ public function setFileSize($fileSize) } /** - * @return string + * @return null|string */ public function getFilePath() { @@ -112,6 +113,7 @@ public function getFilePath() /** * @param string $filePath + * @return void */ public function setFilePath($filePath) { @@ -128,6 +130,7 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * @return void */ public function setFileUniqueId($fileUniqueId) { diff --git a/src/Types/ForceReply.php b/src/Types/ForceReply.php index ced9a30f..50f11f54 100644 --- a/src/Types/ForceReply.php +++ b/src/Types/ForceReply.php @@ -44,10 +44,14 @@ class ForceReply extends BaseType * 1) users that are @mentioned in the text of the Message object; * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. * - * @var bool + * @var bool|null */ protected $selective; + /** + * @param bool $forceReply + * @param bool|null $selective + */ public function __construct($forceReply = true, $selective = null) { $this->forceReply = $forceReply; @@ -55,7 +59,7 @@ public function __construct($forceReply = true, $selective = null) } /** - * @return boolean + * @return bool */ public function isForceReply() { @@ -63,7 +67,8 @@ public function isForceReply() } /** - * @param boolean $forceReply + * @param bool $forceReply + * @return void */ public function setForceReply($forceReply) { @@ -71,7 +76,7 @@ public function setForceReply($forceReply) } /** - * @return boolean + * @return bool|null */ public function isSelective() { @@ -79,7 +84,8 @@ public function isSelective() } /** - * @param boolean $selective + * @param bool|null $selective + * @return void */ public function setSelective($selective) { diff --git a/src/Types/ForumTopic.php b/src/Types/ForumTopic.php index 0d7bd058..320e1aff 100644 --- a/src/Types/ForumTopic.php +++ b/src/Types/ForumTopic.php @@ -57,7 +57,7 @@ class ForumTopic extends BaseType implements TypeInterface /** * Optional. Unique identifier of the custom emoji shown as the topic icon * - * @var string + * @var string|null */ protected $iconCustomEmojiId; @@ -71,6 +71,7 @@ public function getMessageThreadId() /** * @param int $messageThreadId + * @return void */ public function setMessageThreadId($messageThreadId) { @@ -87,6 +88,7 @@ public function getName() /** * @param string $name + * @return void */ public function setName($name) { @@ -103,6 +105,7 @@ public function getIconColor() /** * @param int $iconColor + * @return void */ public function setIconColor($iconColor) { @@ -110,7 +113,7 @@ public function setIconColor($iconColor) } /** - * @return string + * @return null|string */ public function getIconCustomEmojiId() { @@ -119,6 +122,7 @@ public function getIconCustomEmojiId() /** * @param string $iconCustomEmojiId + * @return void */ public function setIconCustomEmojiId($iconCustomEmojiId) { diff --git a/src/Types/ForumTopicCreated.php b/src/Types/ForumTopicCreated.php index 0549c9ae..30cc78fc 100644 --- a/src/Types/ForumTopicCreated.php +++ b/src/Types/ForumTopicCreated.php @@ -63,6 +63,7 @@ public function getName() /** * @param string $name + * @return void */ public function setName($name) { @@ -79,6 +80,7 @@ public function getIconColor() /** * @param string $iconColor + * @return void */ public function setIconColor($iconColor) { @@ -95,6 +97,7 @@ public function getIconCustomEmojiId() /** * @param string $iconCustomEmojiId + * @return void */ public function setIconCustomEmojiId($iconCustomEmojiId) { diff --git a/src/Types/Inline/ChosenInlineResult.php b/src/Types/Inline/ChosenInlineResult.php index acdb22c3..7255a72b 100644 --- a/src/Types/Inline/ChosenInlineResult.php +++ b/src/Types/Inline/ChosenInlineResult.php @@ -51,7 +51,7 @@ class ChosenInlineResult extends BaseType /** * Optional. Sender location, only for bots that require user location * - * @var Location + * @var Location|null */ protected $location; @@ -60,7 +60,7 @@ class ChosenInlineResult extends BaseType * Available only if there is an inline keyboard attached to the message. * Will be also received in callback queries and can be used to edit the message. * - * @var string + * @var string|null */ protected $inlineMessageId; @@ -81,6 +81,8 @@ public function getResultId() /** * @param string $resultId + * + * @return void */ public function setResultId($resultId) { @@ -97,6 +99,8 @@ public function getFrom() /** * @param User $from + * + * @return void */ public function setFrom(User $from) { @@ -104,7 +108,7 @@ public function setFrom(User $from) } /** - * @return Location + * @return Location|null */ public function getLocation() { @@ -113,6 +117,8 @@ public function getLocation() /** * @param Location $location + * + * @return void */ public function setLocation($location) { @@ -120,7 +126,7 @@ public function setLocation($location) } /** - * @return string + * @return null|string */ public function getInlineMessageId() { @@ -129,6 +135,8 @@ public function getInlineMessageId() /** * @param string $inlineMessageId + * + * @return void */ public function setInlineMessageId($inlineMessageId) { @@ -145,6 +153,8 @@ public function getQuery() /** * @param string $query + * + * @return void */ public function setQuery($query) { diff --git a/src/Types/Inline/InlineKeyboardMarkup.php b/src/Types/Inline/InlineKeyboardMarkup.php index b9430be7..08e1f647 100644 --- a/src/Types/Inline/InlineKeyboardMarkup.php +++ b/src/Types/Inline/InlineKeyboardMarkup.php @@ -54,6 +54,8 @@ public function getInlineKeyboard() /** * @param array $inlineKeyboard + * + * @return void */ public function setInlineKeyboard($inlineKeyboard) { diff --git a/src/Types/Inline/InlineQuery.php b/src/Types/Inline/InlineQuery.php index 65b56851..dc0b9806 100644 --- a/src/Types/Inline/InlineQuery.php +++ b/src/Types/Inline/InlineQuery.php @@ -52,7 +52,7 @@ class InlineQuery extends BaseType /** * Optional. Sender location, only for bots that request user location * - * @var Location + * @var Location|null */ protected $location; @@ -80,6 +80,8 @@ public function getId() /** * @param string $id + * + * @return void */ public function setId($id) { @@ -96,6 +98,8 @@ public function getFrom() /** * @param User $from + * + * @return void */ public function setFrom(User $from) { @@ -103,7 +107,7 @@ public function setFrom(User $from) } /** - * @return Location + * @return Location|null */ public function getLocation() { @@ -112,6 +116,8 @@ public function getLocation() /** * @param Location $location + * + * @return void */ public function setLocation($location) { @@ -128,6 +134,8 @@ public function getQuery() /** * @param string $query + * + * @return void */ public function setQuery($query) { @@ -144,6 +152,8 @@ public function getOffset() /** * @param string $offset + * + * @return void */ public function setOffset($offset) { diff --git a/src/Types/Inline/InputMessageContent/Contact.php b/src/Types/Inline/InputMessageContent/Contact.php index 681b9c6d..ae92a82d 100644 --- a/src/Types/Inline/InputMessageContent/Contact.php +++ b/src/Types/Inline/InputMessageContent/Contact.php @@ -56,7 +56,7 @@ class Contact extends InputMessageContent implements TypeInterface /** * Optional. Contact's last name * - * @var string + * @var string|null */ protected $lastName; @@ -84,6 +84,8 @@ public function getPhoneNumber() /** * @param string $phoneNumber + * + * @return void */ public function setPhoneNumber($phoneNumber) { @@ -100,6 +102,8 @@ public function getFirstName() /** * @param mixed $firstName + * + * @return void */ public function setFirstName($firstName) { @@ -107,7 +111,7 @@ public function setFirstName($firstName) } /** - * @return string + * @return string|null */ public function getLastName() { @@ -115,7 +119,9 @@ public function getLastName() } /** - * @param string $lastName + * @param string|null $lastName + * + * @return void */ public function setLastName($lastName) { diff --git a/src/Types/Inline/InputMessageContent/Location.php b/src/Types/Inline/InputMessageContent/Location.php index b4a17833..e605b867 100644 --- a/src/Types/Inline/InputMessageContent/Location.php +++ b/src/Types/Inline/InputMessageContent/Location.php @@ -72,6 +72,8 @@ public function getLatitude() /** * @param float $latitude + * + * @return void */ public function setLatitude($latitude) { @@ -88,6 +90,8 @@ public function getLongitude() /** * @param float $longitude + * + * @return void */ public function setLongitude($longitude) { diff --git a/src/Types/Inline/InputMessageContent/Text.php b/src/Types/Inline/InputMessageContent/Text.php index 449ef251..bc725828 100644 --- a/src/Types/Inline/InputMessageContent/Text.php +++ b/src/Types/Inline/InputMessageContent/Text.php @@ -49,21 +49,21 @@ class Text extends InputMessageContent implements TypeInterface * Optional. Send Markdown or HTML, * if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. * - * @var string + * @var string|null */ protected $parseMode; /** * Optional. Disables link previews for links in the sent message * - * @var bool + * @var bool|null */ protected $disableWebPagePreview; /** * Text constructor. * @param string $messageText - * @param string $parseMode + * @param string|null $parseMode * @param bool $disableWebPagePreview */ public function __construct($messageText, $parseMode = null, $disableWebPagePreview = false) @@ -83,6 +83,8 @@ public function getMessageText() /** * @param string $messageText + * + * @return void */ public function setMessageText($messageText) { @@ -90,7 +92,7 @@ public function setMessageText($messageText) } /** - * @return string + * @return string|null */ public function getParseMode() { @@ -98,7 +100,9 @@ public function getParseMode() } /** - * @param string $parseMode + * @param string|null $parseMode + * + * @return void */ public function setParseMode($parseMode) { @@ -106,7 +110,7 @@ public function setParseMode($parseMode) } /** - * @return boolean + * @return bool|null */ public function isDisableWebPagePreview() { @@ -114,7 +118,9 @@ public function isDisableWebPagePreview() } /** - * @param boolean $disableWebPagePreview + * @param bool|null $disableWebPagePreview + * + * @return void */ public function setDisableWebPagePreview($disableWebPagePreview) { diff --git a/src/Types/Inline/InputMessageContent/Venue.php b/src/Types/Inline/InputMessageContent/Venue.php index 2cb66628..a6b46b80 100644 --- a/src/Types/Inline/InputMessageContent/Venue.php +++ b/src/Types/Inline/InputMessageContent/Venue.php @@ -71,7 +71,7 @@ class Venue extends InputMessageContent implements TypeInterface /** * Optional. Foursquare identifier of the venue, if known * - * @var string + * @var string|null */ protected $foursquareId; @@ -81,7 +81,7 @@ class Venue extends InputMessageContent implements TypeInterface * @param float $longitude * @param string $title * @param string $address - * @param string $foursquareId + * @param string|null $foursquareId */ public function __construct($latitude, $longitude, $title, $address, $foursquareId = null) { @@ -102,6 +102,8 @@ public function getLatitude() /** * @param float $latitude + * + * @return void */ public function setLatitude($latitude) { @@ -118,6 +120,8 @@ public function getLongitude() /** * @param float $longitude + * + * @return void */ public function setLongitude($longitude) { @@ -134,6 +138,8 @@ public function getTitle() /** * @param string $title + * + * @return void */ public function setTitle($title) { @@ -150,6 +156,8 @@ public function getAddress() /** * @param string $address + * + * @return void */ public function setAddress($address) { @@ -157,7 +165,7 @@ public function setAddress($address) } /** - * @return string + * @return string|null */ public function getFoursquareId() { @@ -165,7 +173,9 @@ public function getFoursquareId() } /** - * @param string $foursquareId + * @param string|null $foursquareId + * + * @return void */ public function setFoursquareId($foursquareId) { diff --git a/src/Types/Inline/QueryResult/AbstractInlineQueryResult.php b/src/Types/Inline/QueryResult/AbstractInlineQueryResult.php index 6d50c1f1..30c41f8e 100644 --- a/src/Types/Inline/QueryResult/AbstractInlineQueryResult.php +++ b/src/Types/Inline/QueryResult/AbstractInlineQueryResult.php @@ -31,21 +31,21 @@ class AbstractInlineQueryResult extends BaseType /** * Title for the result * - * @var string + * @var string|null */ protected $title; /** * Content of the message to be sent instead of the file * - * @var InputMessageContent + * @var InputMessageContent|null */ protected $inputMessageContent; /** * Optional. Inline keyboard attached to the message * - * @var InlineKeyboardMarkup + * @var InlineKeyboardMarkup|null */ protected $replyMarkup; @@ -53,11 +53,11 @@ class AbstractInlineQueryResult extends BaseType * AbstractInlineQueryResult constructor. * * @param string $id - * @param string $title + * @param string|null $title * @param InputMessageContent|null $inputMessageContent * @param InlineKeyboardMarkup|null $replyMarkup */ - public function __construct($id, $title, $inputMessageContent = null, $replyMarkup = null) + public function __construct($id, $title = null, $inputMessageContent = null, $replyMarkup = null) { $this->id = $id; $this->title = $title; @@ -75,6 +75,8 @@ public function getType() /** * @param string $type + * + * @return void */ public function setType($type) { @@ -91,6 +93,8 @@ public function getId() /** * @param string $id + * + * @return void */ public function setId($id) { @@ -98,7 +102,7 @@ public function setId($id) } /** - * @return string + * @return string|null */ public function getTitle() { @@ -106,7 +110,9 @@ public function getTitle() } /** - * @param string $title + * @param string|null $title + * + * @return void */ public function setTitle($title) { @@ -114,7 +120,7 @@ public function setTitle($title) } /** - * @return InputMessageContent + * @return InputMessageContent|null */ public function getInputMessageContent() { @@ -122,7 +128,9 @@ public function getInputMessageContent() } /** - * @param InputMessageContent $inputMessageContent + * @param InputMessageContent|null $inputMessageContent + * + * @return void */ public function setInputMessageContent($inputMessageContent) { @@ -130,7 +138,7 @@ public function setInputMessageContent($inputMessageContent) } /** - * @return InlineKeyboardMarkup + * @return InlineKeyboardMarkup|null */ public function getReplyMarkup() { @@ -138,7 +146,9 @@ public function getReplyMarkup() } /** - * @param InlineKeyboardMarkup $replyMarkup + * @param InlineKeyboardMarkup|null $replyMarkup + * + * @return void */ public function setReplyMarkup($replyMarkup) { diff --git a/src/Types/Inline/QueryResult/Article.php b/src/Types/Inline/QueryResult/Article.php index 69bab239..411829da 100644 --- a/src/Types/Inline/QueryResult/Article.php +++ b/src/Types/Inline/QueryResult/Article.php @@ -49,42 +49,42 @@ class Article extends AbstractInlineQueryResult /** * Optional. URL of the result * - * @var string + * @var string|null */ protected $url; /** * Optional. Pass True, if you don't want the URL to be shown in the message * - * @var bool + * @var bool|null */ protected $hideUrl; /** * Optional. Short description of the result * - * @var string + * @var string|null */ protected $description; /** * Optional. Url of the thumbnail for the result * - * @var string + * @var string|null */ protected $thumbUrl; /** * Optional. Thumbnail width * - * @var int + * @var int|null */ protected $thumbWidth; /** * Optional. Thumbnail height * - * @var int + * @var int|null */ protected $thumbHeight; @@ -119,7 +119,7 @@ public function __construct( } /** - * @return string + * @return string|null */ public function getUrl() { @@ -127,7 +127,9 @@ public function getUrl() } /** - * @param string $url + * @param string|null $url + * + * @return void */ public function setUrl($url) { @@ -135,7 +137,7 @@ public function setUrl($url) } /** - * @return boolean + * @return bool|null */ public function isHideUrl() { @@ -143,7 +145,9 @@ public function isHideUrl() } /** - * @param boolean $hideUrl + * @param bool|null $hideUrl + * + * @return void */ public function setHideUrl($hideUrl) { @@ -151,7 +155,7 @@ public function setHideUrl($hideUrl) } /** - * @return string + * @return string|null */ public function getDescription() { @@ -159,7 +163,9 @@ public function getDescription() } /** - * @param string $description + * @param string|null $description + * + * @return void */ public function setDescription($description) { @@ -167,7 +173,7 @@ public function setDescription($description) } /** - * @return string + * @return string|null */ public function getThumbUrl() { @@ -175,7 +181,9 @@ public function getThumbUrl() } /** - * @param string $thumbUrl + * @param string|null $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { @@ -183,7 +191,7 @@ public function setThumbUrl($thumbUrl) } /** - * @return int + * @return int|null */ public function getThumbWidth() { @@ -191,7 +199,9 @@ public function getThumbWidth() } /** - * @param int $thumbWidth + * @param int|null $thumbWidth + * + * @return void */ public function setThumbWidth($thumbWidth) { @@ -199,7 +209,7 @@ public function setThumbWidth($thumbWidth) } /** - * @return int + * @return int|null */ public function getThumbHeight() { @@ -207,7 +217,9 @@ public function getThumbHeight() } /** - * @param int $thumbHeight + * @param int|null $thumbHeight + * + * @return void */ public function setThumbHeight($thumbHeight) { diff --git a/src/Types/Inline/QueryResult/Audio.php b/src/Types/Inline/QueryResult/Audio.php index 0667ac0c..d4c1f2e1 100644 --- a/src/Types/Inline/QueryResult/Audio.php +++ b/src/Types/Inline/QueryResult/Audio.php @@ -64,14 +64,14 @@ class Audio extends AbstractInlineQueryResult /** * Optional. Performer * - * @var string + * @var string|null */ protected $performer; /** * Optional. Audio duration in seconds * - * @var int + * @var int|null */ protected $audioDuration; @@ -112,6 +112,8 @@ public function getAudioUrl() /** * @param string $audioUrl + * + * @return void */ public function setAudioUrl($audioUrl) { @@ -119,7 +121,7 @@ public function setAudioUrl($audioUrl) } /** - * @return string + * @return string|null */ public function getPerformer() { @@ -127,7 +129,9 @@ public function getPerformer() } /** - * @param string $performer + * @param string|null $performer + * + * @return void */ public function setPerformer($performer) { @@ -135,7 +139,7 @@ public function setPerformer($performer) } /** - * @return int + * @return int|null */ public function getAudioDuration() { @@ -143,7 +147,9 @@ public function getAudioDuration() } /** - * @param int $audioDuration + * @param int|null $audioDuration + * + * @return void */ public function setAudioDuration($audioDuration) { diff --git a/src/Types/Inline/QueryResult/Contact.php b/src/Types/Inline/QueryResult/Contact.php index b5bfbe55..f27de9c0 100644 --- a/src/Types/Inline/QueryResult/Contact.php +++ b/src/Types/Inline/QueryResult/Contact.php @@ -62,28 +62,28 @@ class Contact extends AbstractInlineQueryResult /** * Optional. Contact's last name * - * @var string + * @var string|null */ protected $lastName; /** * Optional. Url of the thumbnail for the result * - * @var string + * @var string|null */ protected $thumbUrl; /** * Optional. Thumbnail width * - * @var int + * @var int|null */ protected $thumbWidth; /** * Optional. Thumbnail height * - * @var int + * @var int|null */ protected $thumbHeight; @@ -131,6 +131,8 @@ public function getPhoneNumber() /** * @param string $phoneNumber + * + * @return void */ public function setPhoneNumber($phoneNumber) { @@ -147,6 +149,8 @@ public function getFirstName() /** * @param string $firstName + * + * @return void */ public function setFirstName($firstName) { @@ -154,7 +158,7 @@ public function setFirstName($firstName) } /** - * @return string + * @return string|null */ public function getLastName() { @@ -162,7 +166,9 @@ public function getLastName() } /** - * @param string $lastName + * @param string|null $lastName + * + * @return void */ public function setLastName($lastName) { @@ -170,7 +176,7 @@ public function setLastName($lastName) } /** - * @return string + * @return string|null */ public function getThumbUrl() { @@ -178,7 +184,9 @@ public function getThumbUrl() } /** - * @param string $thumbUrl + * @param string|null $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { @@ -186,7 +194,7 @@ public function setThumbUrl($thumbUrl) } /** - * @return int + * @return int|null */ public function getThumbWidth() { @@ -194,7 +202,9 @@ public function getThumbWidth() } /** - * @param int $thumbWidth + * @param int|null $thumbWidth + * + * @return void */ public function setThumbWidth($thumbWidth) { @@ -202,7 +212,7 @@ public function setThumbWidth($thumbWidth) } /** - * @return int + * @return int|null */ public function getThumbHeight() { @@ -210,7 +220,9 @@ public function getThumbHeight() } /** - * @param int $thumbHeight + * @param int|null $thumbHeight + * + * @return void */ public function setThumbHeight($thumbHeight) { diff --git a/src/Types/Inline/QueryResult/Gif.php b/src/Types/Inline/QueryResult/Gif.php index 49a185be..f23f51cc 100644 --- a/src/Types/Inline/QueryResult/Gif.php +++ b/src/Types/Inline/QueryResult/Gif.php @@ -57,14 +57,14 @@ class Gif extends AbstractInlineQueryResult /** * Optional. Width of the GIF * - * @var int + * @var int|null */ protected $gifWidth; /** * Optional. Height of the GIF * - * @var int + * @var int|null */ protected $gifHeight; @@ -78,7 +78,7 @@ class Gif extends AbstractInlineQueryResult /** * Optional. Caption of the GIF file to be sent, 0-200 characters * - * @var string + * @var string|null */ protected $caption; @@ -125,6 +125,8 @@ public function getGifUrl() /** * @param string $gifUrl + * + * @return void */ public function setGifUrl($gifUrl) { @@ -132,7 +134,7 @@ public function setGifUrl($gifUrl) } /** - * @return int + * @return int|null */ public function getGifWidth() { @@ -140,7 +142,9 @@ public function getGifWidth() } /** - * @param int $gifWidth + * @param int|null $gifWidth + * + * @return void */ public function setGifWidth($gifWidth) { @@ -148,7 +152,7 @@ public function setGifWidth($gifWidth) } /** - * @return int + * @return int|null */ public function getGifHeight() { @@ -156,7 +160,9 @@ public function getGifHeight() } /** - * @param int $gifHeight + * @param int|null $gifHeight + * + * @return void */ public function setGifHeight($gifHeight) { @@ -173,6 +179,8 @@ public function getThumbUrl() /** * @param string $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { @@ -180,7 +188,7 @@ public function setThumbUrl($thumbUrl) } /** - * @return string + * @return string|null */ public function getCaption() { @@ -188,7 +196,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { diff --git a/src/Types/Inline/QueryResult/Location.php b/src/Types/Inline/QueryResult/Location.php index 1c3b907f..a9ddf98b 100644 --- a/src/Types/Inline/QueryResult/Location.php +++ b/src/Types/Inline/QueryResult/Location.php @@ -73,21 +73,21 @@ class Location extends AbstractInlineQueryResult /** * Optional. Url of the thumbnail for the result * - * @var string + * @var string|null */ protected $thumbUrl; /** * Optional. Thumbnail width * - * @var int + * @var int|null */ protected $thumbWidth; /** * Optional. Thumbnail height * - * @var int + * @var int|null */ protected $thumbHeight; @@ -98,9 +98,9 @@ class Location extends AbstractInlineQueryResult * @param float $latitude * @param float $longitude * @param string $title - * @param string $thumbUrl - * @param int $thumbWidth - * @param int $thumbHeight + * @param string|null $thumbUrl + * @param int|null $thumbWidth + * @param int|null $thumbHeight * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup * @param InputMessageContent|null $inputMessageContent */ @@ -134,6 +134,8 @@ public function getLatitude() /** * @param float $latitude + * + * @return void */ public function setLatitude($latitude) { @@ -150,6 +152,8 @@ public function getLongitude() /** * @param float $longitude + * + * @return void */ public function setLongitude($longitude) { @@ -157,7 +161,7 @@ public function setLongitude($longitude) } /** - * @return string + * @return string|null */ public function getThumbUrl() { @@ -165,7 +169,9 @@ public function getThumbUrl() } /** - * @param string $thumbUrl + * @param string|null $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { @@ -173,7 +179,7 @@ public function setThumbUrl($thumbUrl) } /** - * @return int + * @return int|null */ public function getThumbWidth() { @@ -181,7 +187,9 @@ public function getThumbWidth() } /** - * @param int $thumbWidth + * @param int|null $thumbWidth + * + * @return void */ public function setThumbWidth($thumbWidth) { @@ -189,7 +197,7 @@ public function setThumbWidth($thumbWidth) } /** - * @return int + * @return int|null */ public function getThumbHeight() { @@ -197,7 +205,9 @@ public function getThumbHeight() } /** - * @param int $thumbHeight + * @param int|null $thumbHeight + * + * @return void */ public function setThumbHeight($thumbHeight) { diff --git a/src/Types/Inline/QueryResult/Mpeg4Gif.php b/src/Types/Inline/QueryResult/Mpeg4Gif.php index de0c7cbc..59d7b39f 100644 --- a/src/Types/Inline/QueryResult/Mpeg4Gif.php +++ b/src/Types/Inline/QueryResult/Mpeg4Gif.php @@ -57,14 +57,14 @@ class Mpeg4Gif extends AbstractInlineQueryResult /** * Optional. Video width * - * @var int + * @var int|null */ protected $mpeg4Width; /** * Optional. Video height * - * @var int + * @var int|null */ protected $mpeg4Height; @@ -78,7 +78,7 @@ class Mpeg4Gif extends AbstractInlineQueryResult /** * Optional. Caption of the MPEG-4 file to be sent, 0-200 characters * - * @var string + * @var string|null */ protected $caption; @@ -125,6 +125,8 @@ public function getMpeg4Url() /** * @param string $mpeg4Url + * + * @return void */ public function setMpeg4Url($mpeg4Url) { @@ -132,7 +134,7 @@ public function setMpeg4Url($mpeg4Url) } /** - * @return int + * @return int|null */ public function getMpeg4Width() { @@ -140,7 +142,9 @@ public function getMpeg4Width() } /** - * @param int $mpeg4Width + * @param int|null $mpeg4Width + * + * @return void */ public function setMpeg4Width($mpeg4Width) { @@ -148,7 +152,7 @@ public function setMpeg4Width($mpeg4Width) } /** - * @return int + * @return int|null */ public function getMpeg4Height() { @@ -156,7 +160,9 @@ public function getMpeg4Height() } /** - * @param int $mpeg4Height + * @param int|null $mpeg4Height + * + * @return void */ public function setMpeg4Height($mpeg4Height) { @@ -173,6 +179,8 @@ public function getThumbUrl() /** * @param string $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { @@ -180,7 +188,7 @@ public function setThumbUrl($thumbUrl) } /** - * @return string + * @return string|null */ public function getCaption() { @@ -188,7 +196,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { diff --git a/src/Types/Inline/QueryResult/Photo.php b/src/Types/Inline/QueryResult/Photo.php index 299f9a8c..97249054 100644 --- a/src/Types/Inline/QueryResult/Photo.php +++ b/src/Types/Inline/QueryResult/Photo.php @@ -57,35 +57,35 @@ class Photo extends AbstractInlineQueryResult /** * Optional. Width of the photo * - * @var int + * @var int|null */ protected $photoWidth; /** * Optional. Height of the photo * - * @var int + * @var int|null */ protected $photoHeight; /** * URL of the thumbnail for the photo * - * @var + * @var string */ protected $thumbUrl; /** * Optional. Short description of the result * - * @var string + * @var string|null */ protected $description; /** * Optional. Caption of the photo to be sent, 0-200 characters * - * @var string + * @var string|null */ protected $caption; @@ -135,6 +135,8 @@ public function getPhotoUrl() /** * @param string $photoUrl + * + * @return void */ public function setPhotoUrl($photoUrl) { @@ -142,7 +144,7 @@ public function setPhotoUrl($photoUrl) } /** - * @return int + * @return int|null */ public function getPhotoWidth() { @@ -150,7 +152,9 @@ public function getPhotoWidth() } /** - * @param int $photoWidth + * @param int|null $photoWidth + * + * @return void */ public function setPhotoWidth($photoWidth) { @@ -158,7 +162,7 @@ public function setPhotoWidth($photoWidth) } /** - * @return int + * @return int|null */ public function getPhotoHeight() { @@ -166,7 +170,9 @@ public function getPhotoHeight() } /** - * @param int $photoHeight + * @param int|null $photoHeight + * + * @return void */ public function setPhotoHeight($photoHeight) { @@ -174,7 +180,7 @@ public function setPhotoHeight($photoHeight) } /** - * @return mixed + * @return string */ public function getThumbUrl() { @@ -182,7 +188,9 @@ public function getThumbUrl() } /** - * @param mixed $thumbUrl + * @param string $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { @@ -190,7 +198,7 @@ public function setThumbUrl($thumbUrl) } /** - * @return string + * @return string|null */ public function getDescription() { @@ -198,7 +206,9 @@ public function getDescription() } /** - * @param string $description + * @param string|null $description + * + * @return void */ public function setDescription($description) { @@ -206,7 +216,7 @@ public function setDescription($description) } /** - * @return string + * @return string|null */ public function getCaption() { @@ -214,7 +224,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { diff --git a/src/Types/Inline/QueryResult/Venue.php b/src/Types/Inline/QueryResult/Venue.php index 4a91a417..48e4e011 100644 --- a/src/Types/Inline/QueryResult/Venue.php +++ b/src/Types/Inline/QueryResult/Venue.php @@ -75,35 +75,35 @@ class Venue extends AbstractInlineQueryResult /** * Optional. Thumbnail width * - * @var string + * @var string|null */ protected $address; /** * Optional. Url of the thumbnail for the result * - * @var string + * @var string|null */ protected $thumbUrl; /** * Optional. Thumbnail width * - * @var int + * @var int|null */ protected $thumbWidth; /** * Optional. Thumbnail height * - * @var int + * @var int|null */ protected $thumbHeight; /** * Optional. Foursquare identifier of the venue if known * - * @var int + * @var string|null */ protected $foursquareId; @@ -115,10 +115,10 @@ class Venue extends AbstractInlineQueryResult * @param float $longitude * @param string $title * @param string $address - * @param string $thumbUrl - * @param int $thumbWidth - * @param int $thumbHeight - * @param string $foursquareId + * @param string|null $thumbUrl + * @param int|null $thumbWidth + * @param int|null $thumbHeight + * @param string|null $foursquareId * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup * @param InputMessageContent|null $inputMessageContent */ @@ -156,6 +156,8 @@ public function getLatitude() /** * @param float $latitude + * + * @return void */ public function setLatitude($latitude) { @@ -172,6 +174,8 @@ public function getLongitude() /** * @param float $longitude + * + * @return void */ public function setLongitude($longitude) { @@ -179,7 +183,7 @@ public function setLongitude($longitude) } /** - * @return string + * @return string|null */ public function getAddress() { @@ -187,7 +191,9 @@ public function getAddress() } /** - * @param string $address + * @param string|null $address + * + * @return void */ public function setAddress($address) { @@ -195,7 +201,7 @@ public function setAddress($address) } /** - * @return int + * @return string|null */ public function getFoursquareId() { @@ -203,7 +209,9 @@ public function getFoursquareId() } /** - * @param int $foursquareId + * @param string|null $foursquareId + * + * @return void */ public function setFoursquareId($foursquareId) { @@ -211,7 +219,7 @@ public function setFoursquareId($foursquareId) } /** - * @return string + * @return string|null */ public function getThumbUrl() { @@ -219,7 +227,9 @@ public function getThumbUrl() } /** - * @param string $thumbUrl + * @param string|null $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { @@ -227,7 +237,7 @@ public function setThumbUrl($thumbUrl) } /** - * @return int + * @return int|null */ public function getThumbWidth() { @@ -235,7 +245,9 @@ public function getThumbWidth() } /** - * @param int $thumbWidth + * @param int|null $thumbWidth + * + * @return void */ public function setThumbWidth($thumbWidth) { @@ -243,7 +255,7 @@ public function setThumbWidth($thumbWidth) } /** - * @return int + * @return int|null */ public function getThumbHeight() { @@ -251,7 +263,9 @@ public function getThumbHeight() } /** - * @param int $thumbHeight + * @param int|null $thumbHeight + * + * @return void */ public function setThumbHeight($thumbHeight) { diff --git a/src/Types/Inline/QueryResult/Video.php b/src/Types/Inline/QueryResult/Video.php index 961eff0d..48cbc8e5 100644 --- a/src/Types/Inline/QueryResult/Video.php +++ b/src/Types/Inline/QueryResult/Video.php @@ -65,21 +65,21 @@ class Video extends AbstractInlineQueryResult /** * Optional. Video width * - * @var int + * @var int|null */ protected $videoWidth; /** * Optional. Video height * - * @var int + * @var int|null */ protected $videoHeight; /** * Optional. Video duration in seconds * - * @var int + * @var int|null */ protected $videoDuration; @@ -93,14 +93,14 @@ class Video extends AbstractInlineQueryResult /** * Optional. Short description of the result * - * @var string + * @var string|null */ protected $caption; /** * Optional. Short description of the result * - * @var string + * @var string|null */ protected $description; @@ -156,6 +156,8 @@ public function getVideoUrl() /** * @param string $videoUrl + * + * @return void */ public function setVideoUrl($videoUrl) { @@ -172,6 +174,8 @@ public function getMimeType() /** * @param string $mimeType + * + * @return void */ public function setMimeType($mimeType) { @@ -179,7 +183,7 @@ public function setMimeType($mimeType) } /** - * @return int + * @return int|null */ public function getVideoWidth() { @@ -187,7 +191,9 @@ public function getVideoWidth() } /** - * @param int $videoWidth + * @param int|null $videoWidth + * + * @return void */ public function setVideoWidth($videoWidth) { @@ -195,7 +201,7 @@ public function setVideoWidth($videoWidth) } /** - * @return int + * @return int|null */ public function getVideoHeight() { @@ -203,7 +209,9 @@ public function getVideoHeight() } /** - * @param int $videoHeight + * @param int|null $videoHeight + * + * @return void */ public function setVideoHeight($videoHeight) { @@ -211,7 +219,7 @@ public function setVideoHeight($videoHeight) } /** - * @return int + * @return int|null */ public function getVideoDuration() { @@ -219,7 +227,9 @@ public function getVideoDuration() } /** - * @param int $videoDuration + * @param int|null $videoDuration + * + * @return void */ public function setVideoDuration($videoDuration) { @@ -236,6 +246,8 @@ public function getThumbUrl() /** * @param mixed $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { @@ -243,7 +255,7 @@ public function setThumbUrl($thumbUrl) } /** - * @return string + * @return string|null */ public function getCaption() { @@ -251,7 +263,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { @@ -259,7 +273,7 @@ public function setCaption($caption) } /** - * @return string + * @return string|null */ public function getDescription() { @@ -267,7 +281,9 @@ public function getDescription() } /** - * @param string $description + * @param string|null $description + * + * @return void */ public function setDescription($description) { diff --git a/src/Types/Inline/QueryResult/Voice.php b/src/Types/Inline/QueryResult/Voice.php index d2445c3f..e8158827 100644 --- a/src/Types/Inline/QueryResult/Voice.php +++ b/src/Types/Inline/QueryResult/Voice.php @@ -63,7 +63,7 @@ class Voice extends AbstractInlineQueryResult /** * Optional. Audio duration in seconds * - * @var int + * @var int|null */ protected $voiceDuration; @@ -103,6 +103,8 @@ public function getVoiceUrl() /** * @param string $voiceUrl + * + * @return void */ public function setVoiceUrl($voiceUrl) { @@ -110,7 +112,7 @@ public function setVoiceUrl($voiceUrl) } /** - * @return int + * @return int|null */ public function getVoiceDuration() { @@ -118,7 +120,9 @@ public function getVoiceDuration() } /** - * @param int $voiceDuration + * @param int|null $voiceDuration + * + * @return void */ public function setVoiceDuration($voiceDuration) { diff --git a/src/Types/InputMedia/InputMedia.php b/src/Types/InputMedia/InputMedia.php index 31915aad..97b520ae 100644 --- a/src/Types/InputMedia/InputMedia.php +++ b/src/Types/InputMedia/InputMedia.php @@ -51,7 +51,7 @@ class InputMedia extends BaseType implements CollectionItemInterface /** * Optional. Caption of the photo to be sent, 0-200 characters. * - * @var string + * @var string|null */ protected $caption; @@ -59,7 +59,7 @@ class InputMedia extends BaseType implements CollectionItemInterface * Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, * fixed-width text or inline URLs in the media caption. * - * @var string + * @var string|null */ protected $parseMode; @@ -73,6 +73,8 @@ public function getType() /** * @param string $type + * + * @return void */ public function setType($type) { @@ -89,6 +91,8 @@ public function getMedia() /** * @param string $media + * + * @return void */ public function setMedia($media) { @@ -96,7 +100,7 @@ public function setMedia($media) } /** - * @return string + * @return string|null */ public function getCaption() { @@ -104,7 +108,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { @@ -112,7 +118,7 @@ public function setCaption($caption) } /** - * @return string + * @return string|null */ public function getParseMode() { @@ -120,7 +126,9 @@ public function getParseMode() } /** - * @param string $parseMode + * @param string|null $parseMode + * + * @return void */ public function setParseMode($parseMode) { diff --git a/src/Types/InputMedia/InputMediaVideo.php b/src/Types/InputMedia/InputMediaVideo.php index 1f684da1..f6836a44 100644 --- a/src/Types/InputMedia/InputMediaVideo.php +++ b/src/Types/InputMedia/InputMediaVideo.php @@ -29,28 +29,28 @@ class InputMediaVideo extends InputMedia /** * Optional. Video width. * - * @var string + * @var int|null */ protected $width; /** * Optional. Video height. * - * @var string + * @var int|null */ protected $height; /** * Optional. Video duration. * - * @var string + * @var int|null */ protected $duration; /** * Optional. Pass True, if the uploaded video is suitable for streaming. * - * @var bool + * @var bool|null */ protected $supportsStreaming; @@ -85,7 +85,7 @@ public function __construct( } /** - * @return string + * @return int|null */ public function getWidth() { @@ -93,7 +93,9 @@ public function getWidth() } /** - * @param string $width + * @param int|null $width + * + * @return void */ public function setWidth($width) { @@ -101,7 +103,7 @@ public function setWidth($width) } /** - * @return string + * @return int|null */ public function getHeight() { @@ -109,7 +111,9 @@ public function getHeight() } /** - * @param string $height + * @param int|null $height + * + * @return void */ public function setHeight($height) { @@ -117,7 +121,7 @@ public function setHeight($height) } /** - * @return string + * @return int|null */ public function getDuration() { @@ -125,7 +129,9 @@ public function getDuration() } /** - * @param string $duration + * @param int|null $duration + * + * @return void */ public function setDuration($duration) { @@ -133,7 +139,7 @@ public function setDuration($duration) } /** - * @return bool + * @return bool|null */ public function getSupportsStreaming() { @@ -141,7 +147,9 @@ public function getSupportsStreaming() } /** - * @param bool $supportsStreaming + * @param bool|null $supportsStreaming + * + * @return void */ public function setSupportsStreaming($supportsStreaming) { diff --git a/src/Types/Location.php b/src/Types/Location.php index 5514a28b..19a17f8f 100644 --- a/src/Types/Location.php +++ b/src/Types/Location.php @@ -52,7 +52,7 @@ class Location extends BaseType implements TypeInterface /** * Optional. The radius of uncertainty for the location, measured in meters; 0-1500 * - * @var float + * @var float|null */ protected $horizontalAccuracy; @@ -60,14 +60,14 @@ class Location extends BaseType implements TypeInterface * Optional. Time relative to the message sending date, during which the location can be updated, in seconds. For * active live locations only. * - * @var int + * @var int|null */ protected $livePeriod; /** * Optional. The direction in which user is moving, in degrees; 1-360. For active live locations only. * - * @var int + * @var int|null */ protected $heading; @@ -75,7 +75,7 @@ class Location extends BaseType implements TypeInterface * Optional. Maximum distance for proximity alerts about approaching another chat member, in meters. For sent live * locations only. * - * @var int + * @var int|null */ protected $proximityAlertRadius; @@ -88,8 +88,8 @@ public function getLatitude() } /** - * @param float $latitude - * + * @param mixed $latitude + * @return void * @throws InvalidArgumentException */ public function setLatitude($latitude) @@ -110,8 +110,8 @@ public function getLongitude() } /** - * @param float $longitude - * + * @param mixed $longitude + * @return void * @throws InvalidArgumentException */ public function setLongitude($longitude) @@ -124,7 +124,7 @@ public function setLongitude($longitude) } /** - * @return float + * @return float|null */ public function getHorizontalAccuracy() { @@ -132,8 +132,8 @@ public function getHorizontalAccuracy() } /** - * @param float $horizontalAccuracy - * + * @param mixed $horizontalAccuracy + * @return void * @throws InvalidArgumentException */ public function setHorizontalAccuracy($horizontalAccuracy) @@ -146,7 +146,7 @@ public function setHorizontalAccuracy($horizontalAccuracy) } /** - * @return int + * @return int|null */ public function getLivePeriod() { @@ -155,6 +155,7 @@ public function getLivePeriod() /** * @param int $livePeriod + * @return void */ public function setLivePeriod($livePeriod) { @@ -162,7 +163,7 @@ public function setLivePeriod($livePeriod) } /** - * @return int + * @return int|null */ public function getHeading() { @@ -171,6 +172,7 @@ public function getHeading() /** * @param int $heading + * @return void */ public function setHeading($heading) { @@ -178,7 +180,7 @@ public function setHeading($heading) } /** - * @return int + * @return int|null */ public function getProximityAlertRadius() { @@ -187,6 +189,7 @@ public function getProximityAlertRadius() /** * @param int $proximityAlertRadius + * @return void */ public function setProximityAlertRadius($proximityAlertRadius) { diff --git a/src/Types/LoginUrl.php b/src/Types/LoginUrl.php index 8249175b..c441f4e2 100644 --- a/src/Types/LoginUrl.php +++ b/src/Types/LoginUrl.php @@ -38,21 +38,21 @@ class LoginUrl extends BaseType implements TypeInterface /** * Optional. New text of the button in forwarded messages. * - * @var string + * @var string|null */ protected $forwardText; /** * Optional. Username of a bot, which will be used for user authorization * - * @var string + * @var string|null */ protected $botUsername; /** * Optional. Pass True to request the permission for your bot to send messages to the user. * - * @var bool + * @var bool|null */ protected $requestWriteAccess; @@ -66,6 +66,7 @@ public function getUrl() /** * @param string $url + * @return void */ public function setUrl($url) { @@ -73,7 +74,7 @@ public function setUrl($url) } /** - * @return string + * @return null|string */ public function getForwardText() { @@ -82,6 +83,7 @@ public function getForwardText() /** * @param string $forwardText + * @return void */ public function setForwardText($forwardText) { @@ -89,7 +91,7 @@ public function setForwardText($forwardText) } /** - * @return string + * @return null|string */ public function getBotUsername() { @@ -98,6 +100,7 @@ public function getBotUsername() /** * @param string $botUsername + * @return void */ public function setBotUsername($botUsername) { @@ -105,7 +108,7 @@ public function setBotUsername($botUsername) } /** - * @return bool + * @return bool|null */ public function isRequestWriteAccess() { @@ -114,6 +117,7 @@ public function isRequestWriteAccess() /** * @param bool $requestWriteAccess + * @return void */ public function setRequestWriteAccess($requestWriteAccess) { diff --git a/src/Types/MaskPosition.php b/src/Types/MaskPosition.php index c895cae8..466ec5e6 100644 --- a/src/Types/MaskPosition.php +++ b/src/Types/MaskPosition.php @@ -63,6 +63,7 @@ public function getPoint() /** * @param string $point + * @return void */ public function setPoint($point) { @@ -79,6 +80,7 @@ public function getXShift() /** * @param float $xShift + * @return void */ public function setXShift($xShift) { @@ -95,6 +97,7 @@ public function getYShift() /** * @param float $yShift + * @return void */ public function setYShift($yShift) { @@ -111,6 +114,7 @@ public function getScale() /** * @param float $scale + * @return void */ public function setScale($scale) { diff --git a/src/Types/Message.php b/src/Types/Message.php index 68cbd076..609308f5 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -80,14 +80,14 @@ class Message extends BaseType implements TypeInterface /** * Unique message identifier * - * @var int + * @var int|float */ protected $messageId; /** * Optional. Sender name. Can be empty for messages sent to channels * - * @var \TelegramBot\Api\Types\User + * @var \TelegramBot\Api\Types\User|null */ protected $from; @@ -108,7 +108,7 @@ class Message extends BaseType implements TypeInterface /** * Optional. For forwarded messages, sender of the original message * - * @var \TelegramBot\Api\Types\User + * @var \TelegramBot\Api\Types\User|null */ protected $forwardFrom; @@ -116,7 +116,7 @@ class Message extends BaseType implements TypeInterface * Optional. For messages forwarded from channels, information about * the original channel * - * @var \TelegramBot\Api\Types\Chat + * @var \TelegramBot\Api\Types\Chat|null */ protected $forwardFromChat; @@ -124,14 +124,14 @@ class Message extends BaseType implements TypeInterface * Optional. For messages forwarded from channels, identifier of * the original message in the channel * - * @var int + * @var int|null */ protected $forwardFromMessageId; /** * Optional. For messages forwarded from channels, signature of the post author if present * - * @var string + * @var string|null */ protected $forwardSignature; @@ -139,14 +139,14 @@ class Message extends BaseType implements TypeInterface * Optional. Sender's name for messages forwarded from users who disallow adding a link to their account * in forwarded messages * - * @var string + * @var string|null */ protected $forwardSenderName; /** * Optional. For forwarded messages, date the original message was sent in Unix time * - * @var int + * @var int|null */ protected $forwardDate; @@ -154,21 +154,21 @@ class Message extends BaseType implements TypeInterface * Optional. For replies, the original message. Note that the Message object in this field will not contain further * reply_to_message fields even if it itself is a reply. * - * @var \TelegramBot\Api\Types\Message + * @var \TelegramBot\Api\Types\Message|null */ protected $replyToMessage; /** * Optional. Bot through which the message was sent. * - * @var \TelegramBot\Api\Types\User + * @var \TelegramBot\Api\Types\User|null */ protected $viaBot; /** * Optional. Date the message was last edited in Unix time * - * @var int + * @var int|null */ protected $editDate; @@ -176,21 +176,21 @@ class Message extends BaseType implements TypeInterface * Optional. The unique identifier of a media message group * this message belongs to * - * @var int + * @var int|null */ protected $mediaGroupId; /** * Optional. Signature of the post author for messages in channels * - * @var string + * @var string|null */ protected $authorSignature; /** * Optional. For text messages, the actual UTF-8 text of the message * - * @var string + * @var string|null */ protected $text; @@ -198,7 +198,7 @@ class Message extends BaseType implements TypeInterface * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. * array of \TelegramBot\Api\Types\MessageEntity * - * @var array + * @var array|null */ protected $entities; @@ -206,28 +206,28 @@ class Message extends BaseType implements TypeInterface * Optional. For messages with a caption, special entities like usernames, * URLs, bot commands, etc. that appear in the caption * - * @var ArrayOfMessageEntity + * @var ArrayOfMessageEntity|null */ protected $captionEntities; /** * Optional. Message is an audio file, information about the file * - * @var \TelegramBot\Api\Types\Audio + * @var \TelegramBot\Api\Types\Audio|null */ protected $audio; /** * Optional. Message is a general file, information about the file * - * @var \TelegramBot\Api\Types\Document + * @var \TelegramBot\Api\Types\Document|null */ protected $document; /** * Optional. Message is a animation, information about the animation * - * @var \TelegramBot\Api\Types\Animation + * @var \TelegramBot\Api\Types\Animation|null */ protected $animation; @@ -235,70 +235,70 @@ class Message extends BaseType implements TypeInterface * Optional. Message is a photo, available sizes of the photo * array of \TelegramBot\Api\Types\Photo * - * @var array + * @var array|null */ protected $photo; /** * Optional. Message is a sticker, information about the sticker * - * @var \TelegramBot\Api\Types\Sticker + * @var \TelegramBot\Api\Types\Sticker|null */ protected $sticker; /** * Optional. Message is a video, information about the video * - * @var \TelegramBot\Api\Types\Video + * @var \TelegramBot\Api\Types\Video|null */ protected $video; /** * Optional. Message is a voice message, information about the file * - * @var \TelegramBot\Api\Types\Voice + * @var \TelegramBot\Api\Types\Voice|null */ protected $voice; /** * Optional. Text description of the video (usually empty) * - * @var string + * @var string|null */ protected $caption; /** * Optional. Message is a shared contact, information about the contact * - * @var \TelegramBot\Api\Types\Contact + * @var \TelegramBot\Api\Types\Contact|null */ protected $contact; /** * Optional. Message is a shared location, information about the location * - * @var \TelegramBot\Api\Types\Location + * @var \TelegramBot\Api\Types\Location|null */ protected $location; /** * Optional. Message is a venue, information about the venue * - * @var \TelegramBot\Api\Types\Venue + * @var \TelegramBot\Api\Types\Venue|null */ protected $venue; /** * Optional. Message is a native poll, information about the poll * - * @var \TelegramBot\Api\Types\Poll + * @var \TelegramBot\Api\Types\Poll|null */ protected $poll; /** * Optional. Message is a dice with random value from 1 to 6 * - * @var \TelegramBot\Api\Types\Dice + * @var \TelegramBot\Api\Types\Dice|null */ protected $dice; @@ -307,56 +307,56 @@ class Message extends BaseType implements TypeInterface * (the bot itself may be one of these members) * array of \TelegramBot\Api\Types\User * - * @var array + * @var array|null */ protected $newChatMembers; /** * Optional. A member was removed from the group, information about them (this member may be bot itself) * - * @var \TelegramBot\Api\Types\User + * @var \TelegramBot\Api\Types\User|null */ protected $leftChatMember; /** * Optional. A group title was changed to this value * - * @var string + * @var string|null */ protected $newChatTitle; /** * Optional. A group photo was change to this value * - * @var mixed + * @var PhotoSize[]|null */ protected $newChatPhoto; /** * Optional. Informs that the group photo was deleted * - * @var bool + * @var bool|null */ protected $deleteChatPhoto; /** * Optional. Informs that the group has been created * - * @var bool + * @var bool|null */ protected $groupChatCreated; /** * Optional. Service message: the supergroup has been created * - * @var bool + * @var bool|null */ protected $supergroupChatCreated; /** * Optional. Service message: the channel has been created * - * @var bool + * @var bool|null */ protected $channelChatCreated; @@ -364,7 +364,7 @@ class Message extends BaseType implements TypeInterface * Optional. The group has been migrated to a supergroup with the specified identifier, * not exceeding 1e13 by absolute value * - * @var int + * @var int|null */ protected $migrateToChatId; @@ -372,7 +372,7 @@ class Message extends BaseType implements TypeInterface * Optional. The supergroup has been migrated from a group with the specified identifier, * not exceeding 1e13 by absolute value * - * @var int + * @var int|null */ protected $migrateFromChatId; @@ -380,75 +380,75 @@ class Message extends BaseType implements TypeInterface * Optional. Specified message was pinned.Note that the Message object in this field * will not contain further reply_to_message fields even if it is itself a reply. * - * @var Message + * @var Message|null */ protected $pinnedMessage; /** * Optional. Message is an invoice for a payment, information about the invoice. * - * @var Invoice + * @var Invoice|null */ protected $invoice; /** * Optional. Message is a service message about a successful payment, information about the payment. * - * @var SuccessfulPayment + * @var SuccessfulPayment|null */ protected $successfulPayment; /** * Optional. The domain name of the website on which the user has logged in. * - * @var string + * @var string|null */ protected $connectedWebsite; /** * Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. * - * @var InlineKeyboardMarkup + * @var InlineKeyboardMarkup|null */ protected $replyMarkup; /** * Optional. Service message: forum topic created * - * @var ForumTopicCreated + * @var ForumTopicCreated|null */ protected $forumTopicCreated; /** * Optional. Service message: forum topic closed * - * @var ForumTopicReopened + * @var ForumTopicReopened|null */ protected $forumTopicReopened; /** * Optional. Service message: forum topic reopened * - * @var ForumTopicClosed + * @var ForumTopicClosed|null */ protected $forumTopicClosed; /** * Optional. True, if the message is sent to a forum topic * - * @var bool + * @var bool|null */ protected $isTopicMessage; /** * Optional. Unique identifier of a message thread to which the message belongs; for supergroups only * - * @var int + * @var int|null */ protected $messageThreadId; /** - * @return int + * @return int|float */ public function getMessageId() { @@ -456,8 +456,8 @@ public function getMessageId() } /** - * @param int $messageId - * + * @param mixed $messageId + * @return void * @throws InvalidArgumentException */ public function setMessageId($messageId) @@ -470,7 +470,7 @@ public function setMessageId($messageId) } /** - * @return User + * @return User|null */ public function getFrom() { @@ -479,6 +479,7 @@ public function getFrom() /** * @param User $from + * @return void */ public function setFrom(User $from) { @@ -495,6 +496,7 @@ public function getChat() /** * @param Chat $chat + * @return void */ public function setChat(Chat $chat) { @@ -510,8 +512,8 @@ public function getDate() } /** - * @param int $date - * + * @param mixed $date + * @return void * @throws InvalidArgumentException */ public function setDate($date) @@ -524,7 +526,7 @@ public function setDate($date) } /** - * @return User + * @return User|null */ public function getForwardFrom() { @@ -533,6 +535,7 @@ public function getForwardFrom() /** * @param User $forwardFrom + * @return void */ public function setForwardFrom(User $forwardFrom) { @@ -540,7 +543,7 @@ public function setForwardFrom(User $forwardFrom) } /** - * @return Chat + * @return Chat|null */ public function getForwardFromChat() { @@ -549,6 +552,7 @@ public function getForwardFromChat() /** * @param Chat $forwardFromChat + * @return void */ public function setForwardFromChat(Chat $forwardFromChat) { @@ -556,7 +560,7 @@ public function setForwardFromChat(Chat $forwardFromChat) } /** - * @return int + * @return int|null */ public function getForwardFromMessageId() { @@ -565,6 +569,7 @@ public function getForwardFromMessageId() /** * @param int $forwardFromMessageId + * @return void */ public function setForwardFromMessageId($forwardFromMessageId) { @@ -572,7 +577,7 @@ public function setForwardFromMessageId($forwardFromMessageId) } /** - * @return string + * @return null|string */ public function getForwardSignature() { @@ -581,6 +586,7 @@ public function getForwardSignature() /** * @param string $forwardSignature + * @return void */ public function setForwardSignature($forwardSignature) { @@ -588,7 +594,7 @@ public function setForwardSignature($forwardSignature) } /** - * @return string + * @return null|string */ public function getForwardSenderName() { @@ -597,6 +603,7 @@ public function getForwardSenderName() /** * @param string $forwardSenderName + * @return void */ public function setForwardSenderName($forwardSenderName) { @@ -604,7 +611,7 @@ public function setForwardSenderName($forwardSenderName) } /** - * @return int + * @return int|null */ public function getForwardDate() { @@ -612,8 +619,8 @@ public function getForwardDate() } /** - * @param int $forwardDate - * + * @param mixed $forwardDate + * @return void * @throws InvalidArgumentException */ public function setForwardDate($forwardDate) @@ -626,7 +633,7 @@ public function setForwardDate($forwardDate) } /** - * @return Message + * @return null|self */ public function getReplyToMessage() { @@ -635,6 +642,7 @@ public function getReplyToMessage() /** * @param Message $replyToMessage + * @return void */ public function setReplyToMessage(Message $replyToMessage) { @@ -642,7 +650,7 @@ public function setReplyToMessage(Message $replyToMessage) } /** - * @return User + * @return User|null */ public function getViaBot() { @@ -651,6 +659,7 @@ public function getViaBot() /** * @param User $viaBot + * @return void */ public function setViaBot(User $viaBot) { @@ -658,7 +667,7 @@ public function setViaBot(User $viaBot) } /** - * @return int + * @return int|null */ public function getEditDate() { @@ -666,8 +675,8 @@ public function getEditDate() } /** - * @param int $editDate - * + * @param mixed $editDate + * @return void * @throws InvalidArgumentException */ public function setEditDate($editDate) @@ -680,7 +689,7 @@ public function setEditDate($editDate) } /** - * @return int + * @return int|null */ public function getMediaGroupId() { @@ -689,6 +698,7 @@ public function getMediaGroupId() /** * @param int $mediaGroupId + * @return void */ public function setMediaGroupId($mediaGroupId) { @@ -696,7 +706,7 @@ public function setMediaGroupId($mediaGroupId) } /** - * @return string + * @return null|string */ public function getAuthorSignature() { @@ -705,6 +715,7 @@ public function getAuthorSignature() /** * @param string $authorSignature + * @return void */ public function setAuthorSignature($authorSignature) { @@ -712,7 +723,7 @@ public function setAuthorSignature($authorSignature) } /** - * @return string + * @return null|string */ public function getText() { @@ -721,6 +732,7 @@ public function getText() /** * @param string $text + * @return void */ public function setText($text) { @@ -728,7 +740,7 @@ public function setText($text) } /** - * @return array + * @return array|null */ public function getEntities() { @@ -737,6 +749,7 @@ public function getEntities() /** * @param array $entities + * @return void */ public function setEntities($entities) { @@ -744,7 +757,7 @@ public function setEntities($entities) } /** - * @return ArrayOfMessageEntity + * @return ArrayOfMessageEntity|null */ public function getCaptionEntities() { @@ -753,6 +766,7 @@ public function getCaptionEntities() /** * @param ArrayOfMessageEntity $captionEntities + * @return void */ public function setCaptionEntities($captionEntities) { @@ -760,7 +774,7 @@ public function setCaptionEntities($captionEntities) } /** - * @return Audio + * @return Audio|null */ public function getAudio() { @@ -769,6 +783,7 @@ public function getAudio() /** * @param Audio $audio + * @return void */ public function setAudio(Audio $audio) { @@ -776,7 +791,7 @@ public function setAudio(Audio $audio) } /** - * @return Document + * @return Document|null */ public function getDocument() { @@ -785,6 +800,7 @@ public function getDocument() /** * @param Document $document + * @return void */ public function setDocument($document) { @@ -792,7 +808,7 @@ public function setDocument($document) } /** - * @return Animation + * @return Animation|null */ public function getAnimation() { @@ -801,6 +817,7 @@ public function getAnimation() /** * @param Animation $animation + * @return void */ public function setAnimation(Animation $animation) { @@ -808,7 +825,7 @@ public function setAnimation(Animation $animation) } /** - * @return array + * @return array|null */ public function getPhoto() { @@ -817,6 +834,7 @@ public function getPhoto() /** * @param array $photo + * @return void */ public function setPhoto(array $photo) { @@ -824,7 +842,7 @@ public function setPhoto(array $photo) } /** - * @return Sticker + * @return Sticker|null */ public function getSticker() { @@ -833,6 +851,7 @@ public function getSticker() /** * @param Sticker $sticker + * @return void */ public function setSticker(Sticker $sticker) { @@ -840,7 +859,7 @@ public function setSticker(Sticker $sticker) } /** - * @return Video + * @return Video|null */ public function getVideo() { @@ -849,6 +868,7 @@ public function getVideo() /** * @param Video $video + * @return void */ public function setVideo(Video $video) { @@ -856,7 +876,7 @@ public function setVideo(Video $video) } /** - * @return Voice + * @return Voice|null */ public function getVoice() { @@ -865,6 +885,7 @@ public function getVoice() /** * @param Voice $voice + * @return void */ public function setVoice($voice) { @@ -872,7 +893,7 @@ public function setVoice($voice) } /** - * @return string + * @return null|string */ public function getCaption() { @@ -881,6 +902,7 @@ public function getCaption() /** * @param string $caption + * @return void */ public function setCaption($caption) { @@ -888,7 +910,7 @@ public function setCaption($caption) } /** - * @return Contact + * @return Contact|null */ public function getContact() { @@ -897,6 +919,7 @@ public function getContact() /** * @param Contact $contact + * @return void */ public function setContact(Contact $contact) { @@ -904,7 +927,7 @@ public function setContact(Contact $contact) } /** - * @return Location + * @return Location|null */ public function getLocation() { @@ -913,6 +936,7 @@ public function getLocation() /** * @param Location $location + * @return void */ public function setLocation(Location $location) { @@ -920,7 +944,7 @@ public function setLocation(Location $location) } /** - * @return Venue + * @return Venue|null */ public function getVenue() { @@ -929,6 +953,7 @@ public function getVenue() /** * @param Venue $venue + * @return void */ public function setVenue($venue) { @@ -936,7 +961,7 @@ public function setVenue($venue) } /** - * @return Poll + * @return Poll|null */ public function getPoll() { @@ -945,6 +970,7 @@ public function getPoll() /** * @param Poll $poll + * @return void */ public function setPoll($poll) { @@ -952,7 +978,7 @@ public function setPoll($poll) } /** - * @return Dice + * @return Dice|null */ public function getDice() { @@ -961,6 +987,7 @@ public function getDice() /** * @param Dice $dice + * @return void */ public function setDice(Dice $dice) { @@ -968,7 +995,7 @@ public function setDice(Dice $dice) } /** - * @return array + * @return array|null */ public function getNewChatMembers() { @@ -977,6 +1004,7 @@ public function getNewChatMembers() /** * @param array $newChatMembers + * @return void */ public function setNewChatMembers($newChatMembers) { @@ -984,7 +1012,7 @@ public function setNewChatMembers($newChatMembers) } /** - * @return User + * @return User|null */ public function getLeftChatMember() { @@ -993,6 +1021,7 @@ public function getLeftChatMember() /** * @param User $leftChatMember + * @return void */ public function setLeftChatMember($leftChatMember) { @@ -1000,7 +1029,7 @@ public function setLeftChatMember($leftChatMember) } /** - * @return string + * @return null|string */ public function getNewChatTitle() { @@ -1009,6 +1038,7 @@ public function getNewChatTitle() /** * @param string $newChatTitle + * @return void */ public function setNewChatTitle($newChatTitle) { @@ -1016,7 +1046,7 @@ public function setNewChatTitle($newChatTitle) } /** - * @return array + * @return PhotoSize[]|null */ public function getNewChatPhoto() { @@ -1024,7 +1054,8 @@ public function getNewChatPhoto() } /** - * @param array $newChatPhoto + * @param PhotoSize[]|null $newChatPhoto + * @return void */ public function setNewChatPhoto($newChatPhoto) { @@ -1032,7 +1063,7 @@ public function setNewChatPhoto($newChatPhoto) } /** - * @return boolean + * @return bool|null */ public function isDeleteChatPhoto() { @@ -1040,15 +1071,16 @@ public function isDeleteChatPhoto() } /** - * @param boolean $deleteChatPhoto + * @param mixed $deleteChatPhoto + * @return void */ public function setDeleteChatPhoto($deleteChatPhoto) { - $this->deleteChatPhoto = (bool)$deleteChatPhoto; + $this->deleteChatPhoto = (bool) $deleteChatPhoto; } /** - * @return boolean + * @return bool|null */ public function isGroupChatCreated() { @@ -1056,15 +1088,16 @@ public function isGroupChatCreated() } /** - * @param boolean $groupChatCreated + * @param mixed $groupChatCreated + * @return void */ public function setGroupChatCreated($groupChatCreated) { - $this->groupChatCreated = (bool)$groupChatCreated; + $this->groupChatCreated = (bool) $groupChatCreated; } /** - * @return boolean + * @return bool|null */ public function isSupergroupChatCreated() { @@ -1072,7 +1105,8 @@ public function isSupergroupChatCreated() } /** - * @param boolean $supergroupChatCreated + * @param bool $supergroupChatCreated + * @return void */ public function setSupergroupChatCreated($supergroupChatCreated) { @@ -1080,7 +1114,7 @@ public function setSupergroupChatCreated($supergroupChatCreated) } /** - * @return boolean + * @return bool|null */ public function isChannelChatCreated() { @@ -1088,7 +1122,8 @@ public function isChannelChatCreated() } /** - * @param boolean $channelChatCreated + * @param bool $channelChatCreated + * @return void */ public function setChannelChatCreated($channelChatCreated) { @@ -1096,7 +1131,7 @@ public function setChannelChatCreated($channelChatCreated) } /** - * @return int + * @return int|null */ public function getMigrateToChatId() { @@ -1105,6 +1140,7 @@ public function getMigrateToChatId() /** * @param int $migrateToChatId + * @return void */ public function setMigrateToChatId($migrateToChatId) { @@ -1112,7 +1148,7 @@ public function setMigrateToChatId($migrateToChatId) } /** - * @return int + * @return int|null */ public function getMigrateFromChatId() { @@ -1121,6 +1157,7 @@ public function getMigrateFromChatId() /** * @param int $migrateFromChatId + * @return void */ public function setMigrateFromChatId($migrateFromChatId) { @@ -1128,7 +1165,7 @@ public function setMigrateFromChatId($migrateFromChatId) } /** - * @return Message + * @return null|self */ public function getPinnedMessage() { @@ -1137,6 +1174,7 @@ public function getPinnedMessage() /** * @param Message $pinnedMessage + * @return void */ public function setPinnedMessage($pinnedMessage) { @@ -1145,7 +1183,8 @@ public function setPinnedMessage($pinnedMessage) /** * @author MY - * @return Invoice + * + * @return Invoice|null */ public function getInvoice() { @@ -1155,6 +1194,7 @@ public function getInvoice() /** * @author MY * @param Invoice $invoice + * @return void */ public function setInvoice($invoice) { @@ -1163,7 +1203,8 @@ public function setInvoice($invoice) /** * @author MY - * @return SuccessfulPayment + * + * @return SuccessfulPayment|null */ public function getSuccessfulPayment() { @@ -1173,6 +1214,7 @@ public function getSuccessfulPayment() /** * @author MY * @param SuccessfulPayment $successfulPayment + * @return void */ public function setSuccessfulPayment($successfulPayment) { @@ -1180,7 +1222,7 @@ public function setSuccessfulPayment($successfulPayment) } /** - * @return string + * @return null|string */ public function getConnectedWebsite() { @@ -1189,6 +1231,7 @@ public function getConnectedWebsite() /** * @param string $connectedWebsite + * @return void */ public function setConnectedWebsite($connectedWebsite) { @@ -1196,7 +1239,7 @@ public function setConnectedWebsite($connectedWebsite) } /** - * @return InlineKeyboardMarkup + * @return InlineKeyboardMarkup|null */ public function getReplyMarkup() { @@ -1205,6 +1248,7 @@ public function getReplyMarkup() /** * @param InlineKeyboardMarkup $replyMarkup + * @return void */ public function setReplyMarkup($replyMarkup) { @@ -1212,7 +1256,7 @@ public function setReplyMarkup($replyMarkup) } /** - * @return ForumTopicCreated + * @return ForumTopicCreated|null */ public function getForumTopicCreated() { @@ -1221,6 +1265,7 @@ public function getForumTopicCreated() /** * @param ForumTopicCreated $forumTopicCreated + * @return void */ public function setForumTopicCreated($forumTopicCreated) { @@ -1228,7 +1273,7 @@ public function setForumTopicCreated($forumTopicCreated) } /** - * @return ForumTopicClosed + * @return ForumTopicClosed|null */ public function getForumTopicClosed() { @@ -1237,6 +1282,7 @@ public function getForumTopicClosed() /** * @param ForumTopicClosed $forumTopicClosed + * @return void */ public function setForumTopicClosed($forumTopicClosed) { @@ -1244,7 +1290,7 @@ public function setForumTopicClosed($forumTopicClosed) } /** - * @return ForumTopicReopened + * @return ForumTopicReopened|null */ public function getForumTopicReopened() { @@ -1253,6 +1299,7 @@ public function getForumTopicReopened() /** * @param ForumTopicReopened $forumTopicReopened + * @return void */ public function setForumTopicReopened($forumTopicReopened) { @@ -1260,7 +1307,7 @@ public function setForumTopicReopened($forumTopicReopened) } /** - * @return bool + * @return bool|null */ public function getIsTopicMessage() { @@ -1269,6 +1316,7 @@ public function getIsTopicMessage() /** * @param bool $isTopicMessage + * @return void */ public function setIsTopicMessage($isTopicMessage) { @@ -1285,6 +1333,7 @@ public function getMessageThreadId() /** * @param int|null $messageThreadId + * @return void */ public function setMessageThreadId($messageThreadId) { diff --git a/src/Types/MessageEntity.php b/src/Types/MessageEntity.php index d3d2d2ea..54eb90db 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -86,21 +86,21 @@ class MessageEntity extends BaseType implements TypeInterface /** * Optional. For “text_link” only, url that will be opened after user taps on the text * - * @var string + * @var string|null */ protected $url; /** * Optional. For “text_mention” only, the mentioned user * - * @var User + * @var User|null */ protected $user; /** * Optional. For “pre” only, the programming language of the entity text * - * @var string + * @var string|null */ protected $language; @@ -108,7 +108,7 @@ class MessageEntity extends BaseType implements TypeInterface * Optional. For “custom_emoji” only, unique identifier of the custom emoji. * Use getCustomEmojiStickers to get full information about the sticker * - * @var string + * @var string|null */ protected $customEmojiId; @@ -122,6 +122,7 @@ public function getType() /** * @param string $type + * @return void */ public function setType($type) { @@ -138,6 +139,7 @@ public function getOffset() /** * @param int $offset + * @return void */ public function setOffset($offset) { @@ -154,6 +156,7 @@ public function getLength() /** * @param int $length + * @return void */ public function setLength($length) { @@ -161,7 +164,7 @@ public function setLength($length) } /** - * @return string + * @return null|string */ public function getUrl() { @@ -170,6 +173,7 @@ public function getUrl() /** * @param string $url + * @return void */ public function setUrl($url) { @@ -177,7 +181,7 @@ public function setUrl($url) } /** - * @return User + * @return User|null */ public function getUser() { @@ -186,6 +190,7 @@ public function getUser() /** * @param User $user + * @return void */ public function setUser($user) { @@ -193,7 +198,7 @@ public function setUser($user) } /** - * @return string + * @return null|string */ public function getLanguage() { @@ -202,6 +207,7 @@ public function getLanguage() /** * @param string $language + * @return void */ public function setLanguage($language) { @@ -209,7 +215,7 @@ public function setLanguage($language) } /** - * @return string + * @return null|string */ public function getCustomEmojiId() { @@ -218,6 +224,7 @@ public function getCustomEmojiId() /** * @param string $customEmojiId + * @return void */ public function setCustomEmojiId($customEmojiId) { diff --git a/src/Types/Payments/ArrayOfLabeledPrice.php b/src/Types/Payments/ArrayOfLabeledPrice.php index 85c60974..ab2f111c 100644 --- a/src/Types/Payments/ArrayOfLabeledPrice.php +++ b/src/Types/Payments/ArrayOfLabeledPrice.php @@ -4,6 +4,10 @@ abstract class ArrayOfLabeledPrice { + /** + * @param array $data + * @return LabeledPrice[] + */ public static function fromResponse($data) { $arrayOfLabeledPrice = []; diff --git a/src/Types/Payments/Invoice.php b/src/Types/Payments/Invoice.php index 8f73a95b..9df2c29b 100644 --- a/src/Types/Payments/Invoice.php +++ b/src/Types/Payments/Invoice.php @@ -74,7 +74,10 @@ public function getTitle() /** * @author MY + * * @param string $title + * + * @return void */ public function setTitle($title) { @@ -92,7 +95,10 @@ public function getDescription() /** * @author MY + * * @param string $description + * + * @return void */ public function setDescription($description) { @@ -110,7 +116,10 @@ public function getStartParameter() /** * @author MY + * * @param string $startParameter + * + * @return void */ public function setStartParameter($startParameter) { @@ -128,7 +137,10 @@ public function getCurrency() /** * @author MY + * * @param string $currency + * + * @return void */ public function setCurrency($currency) { @@ -146,7 +158,10 @@ public function getTotalAmount() /** * @author MY + * * @param int $totalAmount + * + * @return void */ public function setTotalAmount($totalAmount) { diff --git a/src/Types/Payments/LabeledPrice.php b/src/Types/Payments/LabeledPrice.php index 0e2b7074..be6c7a53 100644 --- a/src/Types/Payments/LabeledPrice.php +++ b/src/Types/Payments/LabeledPrice.php @@ -49,6 +49,8 @@ public function getLabel() /** * @param string $label + * + * @return void */ public function setLabel($label) { @@ -65,6 +67,8 @@ public function getAmount() /** * @param int $amount + * + * @return void */ public function setAmount($amount) { diff --git a/src/Types/Payments/OrderInfo.php b/src/Types/Payments/OrderInfo.php index 6138b133..d730595c 100644 --- a/src/Types/Payments/OrderInfo.php +++ b/src/Types/Payments/OrderInfo.php @@ -30,34 +30,35 @@ class OrderInfo extends BaseType /** * Optional. User name * - * @var string + * @var string|null */ protected $name; /** * Optional. User's phone number * - * @var string + * @var string|null */ protected $phoneNumber; /** * Optional. User email * - * @var string + * @var string|null */ protected $email; /** * Optional. User shipping address * - * @var ShippingAddress + * @var ShippingAddress|null */ protected $shippingAddress; /** * @author MY - * @return string + * + * @return null|string */ public function getName() { @@ -66,7 +67,10 @@ public function getName() /** * @author MY + * * @param string $name + * + * @return void */ public function setName($name) { @@ -75,7 +79,8 @@ public function setName($name) /** * @author MY - * @return string + * + * @return null|string */ public function getPhoneNumber() { @@ -84,7 +89,10 @@ public function getPhoneNumber() /** * @author MY + * * @param string $phoneNumber + * + * @return void */ public function setPhoneNumber($phoneNumber) { @@ -93,7 +101,8 @@ public function setPhoneNumber($phoneNumber) /** * @author MY - * @return string + * + * @return null|string */ public function getEmail() { @@ -102,7 +111,10 @@ public function getEmail() /** * @author MY + * * @param string $email + * + * @return void */ public function setEmail($email) { @@ -111,7 +123,8 @@ public function setEmail($email) /** * @author MY - * @return ShippingAddress + * + * @return ShippingAddress|null */ public function getShippingAddress() { @@ -120,7 +133,10 @@ public function getShippingAddress() /** * @author MY + * * @param ShippingAddress $shippingAddress + * + * @return void */ public function setShippingAddress($shippingAddress) { diff --git a/src/Types/Payments/Query/AnswerPreCheckoutQuery.php b/src/Types/Payments/Query/AnswerPreCheckoutQuery.php index a157f7de..f28741b7 100644 --- a/src/Types/Payments/Query/AnswerPreCheckoutQuery.php +++ b/src/Types/Payments/Query/AnswerPreCheckoutQuery.php @@ -49,7 +49,7 @@ class AnswerPreCheckoutQuery extends BaseType /** * @author MY - * @return true + * @return bool */ public function getOk() { @@ -58,7 +58,10 @@ public function getOk() /** * @author MY - * @param true $ok + * + * @param bool $ok + * + * @return void */ public function setOk($ok) { @@ -76,7 +79,10 @@ public function getErrorMessage() /** * @author MY + * * @param string $errorMessage + * + * @return void */ public function setErrorMessage($errorMessage) { @@ -94,7 +100,10 @@ public function getPreCheckoutQueryId() /** * @author MY + * * @param string $preCheckoutQueryId + * + * @return void */ public function setPreCheckoutQueryId($preCheckoutQueryId) { diff --git a/src/Types/Payments/Query/AnswerShippingQuery.php b/src/Types/Payments/Query/AnswerShippingQuery.php index 8999ba84..c663e72e 100644 --- a/src/Types/Payments/Query/AnswerShippingQuery.php +++ b/src/Types/Payments/Query/AnswerShippingQuery.php @@ -69,7 +69,10 @@ public function getShippingQueryId() /** * @author MY + * * @param string $shippingQueryId + * + * @return void */ public function setShippingQueryId($shippingQueryId) { @@ -87,7 +90,10 @@ public function getOk() /** * @author MY + * * @param true $ok + * + * @return void */ public function setOk($ok) { @@ -105,7 +111,10 @@ public function getShippingOptions() /** * @author MY + * * @param array $shippingOptions + * + * @return void */ public function setShippingOptions($shippingOptions) { @@ -123,7 +132,10 @@ public function getErrorMessage() /** * @author MY + * * @param string $errorMessage + * + * @return void */ public function setErrorMessage($errorMessage) { diff --git a/src/Types/Payments/Query/PreCheckoutQuery.php b/src/Types/Payments/Query/PreCheckoutQuery.php index 17c2510d..51b2e49a 100644 --- a/src/Types/Payments/Query/PreCheckoutQuery.php +++ b/src/Types/Payments/Query/PreCheckoutQuery.php @@ -70,14 +70,14 @@ class PreCheckoutQuery extends BaseType /** * Optional. Identifier of the shipping option chosen by the user * - * @var string + * @var string|null */ protected $shippingOptionId; /** * Optional. Order info provided by the user * - * @var OrderInfo + * @var OrderInfo|null */ protected $orderInfo; @@ -92,7 +92,10 @@ public function getId() /** * @author MY + * * @param string $id + * + * @return void */ public function setId($id) { @@ -110,7 +113,10 @@ public function getFrom() /** * @author MY + * * @param User $from + * + * @return void */ public function setFrom($from) { @@ -128,7 +134,10 @@ public function getCurrency() /** * @author MY + * * @param string $currency + * + * @return void */ public function setCurrency($currency) { @@ -146,7 +155,10 @@ public function getTotalAmount() /** * @author MY + * * @param int $totalAmount + * + * @return void */ public function setTotalAmount($totalAmount) { @@ -164,7 +176,10 @@ public function getInvoicePayload() /** * @author MY + * * @param mixed $invoicePayload + * + * @return void */ public function setInvoicePayload($invoicePayload) { @@ -173,7 +188,8 @@ public function setInvoicePayload($invoicePayload) /** * @author MY - * @return string + * + * @return null|string */ public function getShippingOptionId() { @@ -182,7 +198,10 @@ public function getShippingOptionId() /** * @author MY + * * @param string $shippingOptionId + * + * @return void */ public function setShippingOptionId($shippingOptionId) { @@ -191,7 +210,8 @@ public function setShippingOptionId($shippingOptionId) /** * @author MY - * @return OrderInfo + * + * @return OrderInfo|null */ public function getOrderInfo() { @@ -200,7 +220,10 @@ public function getOrderInfo() /** * @author MY + * * @param OrderInfo $orderInfo + * + * @return void */ public function setOrderInfo($orderInfo) { diff --git a/src/Types/Payments/Query/ShippingQuery.php b/src/Types/Payments/Query/ShippingQuery.php index 7a2c935e..df4c54bf 100644 --- a/src/Types/Payments/Query/ShippingQuery.php +++ b/src/Types/Payments/Query/ShippingQuery.php @@ -70,7 +70,10 @@ public function getId() /** * @author MY + * * @param string $id + * + * @return void */ public function setId($id) { @@ -88,7 +91,10 @@ public function getFrom() /** * @author MY + * * @param User $from + * + * @return void */ public function setFrom($from) { @@ -106,7 +112,10 @@ public function getInvoicePayload() /** * @author MY + * * @param string $invoicePayload + * + * @return void */ public function setInvoicePayload($invoicePayload) { @@ -124,7 +133,10 @@ public function getShippingAddress() /** * @author MY + * * @param ShippingAddress $shippingAddress + * + * @return void */ public function setShippingAddress($shippingAddress) { diff --git a/src/Types/Payments/ShippingAddress.php b/src/Types/Payments/ShippingAddress.php index b871fea2..3f1f626e 100644 --- a/src/Types/Payments/ShippingAddress.php +++ b/src/Types/Payments/ShippingAddress.php @@ -82,7 +82,10 @@ public function getCountryCode() /** * @author MY + * * @param string $countryCode + * + * @return void */ public function setCountryCode($countryCode) { @@ -100,7 +103,10 @@ public function getState() /** * @author MY + * * @param string $state + * + * @return void */ public function setState($state) { @@ -118,7 +124,10 @@ public function getCity() /** * @author MY + * * @param string $city + * + * @return void */ public function setCity($city) { @@ -136,7 +145,10 @@ public function getStreetLine1() /** * @author MY + * * @param string $streetLine1 + * + * @return void */ public function setStreetLine1($streetLine1) { @@ -154,7 +166,10 @@ public function getStreetLine2() /** * @author MY + * * @param string $streetLine2 + * + * @return void */ public function setStreetLine2($streetLine2) { @@ -172,7 +187,10 @@ public function getPostCode() /** * @author MY + * * @param string $postCode + * + * @return void */ public function setPostCode($postCode) { diff --git a/src/Types/Payments/ShippingOption.php b/src/Types/Payments/ShippingOption.php index fda483f9..34bf3447 100644 --- a/src/Types/Payments/ShippingOption.php +++ b/src/Types/Payments/ShippingOption.php @@ -58,7 +58,10 @@ public function getId() /** * @author MY + * * @param string $id + * + * @return void */ public function setId($id) { @@ -76,7 +79,10 @@ public function getTitle() /** * @author MY + * * @param string $title + * + * @return void */ public function setTitle($title) { @@ -94,7 +100,10 @@ public function getPrices() /** * @author MY + * * @param array $prices + * + * @return void */ public function setPrices($prices) { diff --git a/src/Types/Payments/SuccessfulPayment.php b/src/Types/Payments/SuccessfulPayment.php index 64ce84af..b9186e0d 100644 --- a/src/Types/Payments/SuccessfulPayment.php +++ b/src/Types/Payments/SuccessfulPayment.php @@ -60,14 +60,14 @@ class SuccessfulPayment extends BaseType /** * Optional. Identifier of the shipping option chosen by the user * - * @var string + * @var string|null */ protected $shippingOptionId; /** * Optional. Order info provided by the user * - * @var OrderInfo + * @var OrderInfo|null */ protected $orderInfo; @@ -96,7 +96,10 @@ public function getCurrency() /** * @author MY + * * @param string $currency + * + * @return void */ public function setCurrency($currency) { @@ -114,7 +117,10 @@ public function getTotalAmount() /** * @author MY + * * @param int $totalAmount + * + * @return void */ public function setTotalAmount($totalAmount) { @@ -132,7 +138,10 @@ public function getInvoicePayload() /** * @author MY + * * @param array $invoicePayload + * + * @return void */ public function setInvoicePayload($invoicePayload) { @@ -141,7 +150,8 @@ public function setInvoicePayload($invoicePayload) /** * @author MY - * @return string + * + * @return null|string */ public function getShippingOptionId() { @@ -150,7 +160,10 @@ public function getShippingOptionId() /** * @author MY + * * @param string $shippingOptionId + * + * @return void */ public function setShippingOptionId($shippingOptionId) { @@ -168,7 +181,10 @@ public function getTelegramPaymentChargeId() /** * @author MY + * * @param string $telegramPaymentChargeId + * + * @return void */ public function setTelegramPaymentChargeId($telegramPaymentChargeId) { @@ -186,7 +202,10 @@ public function getProviderPaymentChargeId() /** * @author MY + * * @param mixed $providerPaymentChargeId + * + * @return void */ public function setProviderPaymentChargeId($providerPaymentChargeId) { @@ -195,7 +214,8 @@ public function setProviderPaymentChargeId($providerPaymentChargeId) /** * @author MY - * @return OrderInfo + * + * @return OrderInfo|null */ public function getOrderInfo() { @@ -204,7 +224,10 @@ public function getOrderInfo() /** * @author MY + * * @param OrderInfo $orderInfo + * + * @return void */ public function setOrderInfo($orderInfo) { diff --git a/src/Types/PhotoSize.php b/src/Types/PhotoSize.php index 57099f0e..50c69063 100644 --- a/src/Types/PhotoSize.php +++ b/src/Types/PhotoSize.php @@ -58,7 +58,7 @@ class PhotoSize extends BaseType implements TypeInterface /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; @@ -79,6 +79,7 @@ public function getFileId() /** * @param string $fileId + * @return void */ public function setFileId($fileId) { @@ -86,7 +87,7 @@ public function setFileId($fileId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -94,8 +95,8 @@ public function getFileSize() } /** - * @param int $fileSize - * + * @param mixed $fileSize + * @return void * @throws InvalidArgumentException */ public function setFileSize($fileSize) @@ -116,8 +117,8 @@ public function getHeight() } /** - * @param int $height - * + * @param mixed $height + * @return void * @throws InvalidArgumentException */ public function setHeight($height) @@ -138,8 +139,8 @@ public function getWidth() } /** - * @param int $width - * + * @param mixed $width + * @return void * @throws InvalidArgumentException */ public function setWidth($width) @@ -161,6 +162,7 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * @return void */ public function setFileUniqueId($fileUniqueId) { diff --git a/src/Types/Poll.php b/src/Types/Poll.php index 837cd298..2f59f611 100644 --- a/src/Types/Poll.php +++ b/src/Types/Poll.php @@ -78,7 +78,7 @@ class Poll extends BaseType implements TypeInterface /** * True, if the poll is closed * - * @var boolean + * @var bool */ protected $isClosed; @@ -108,7 +108,7 @@ class Poll extends BaseType implements TypeInterface * Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) * by the bot or to the private chat with the bot. * - * @var int + * @var int|null */ protected $correctOptionId; @@ -122,6 +122,7 @@ public function getId() /** * @param string $id + * @return void */ public function setId($id) { @@ -138,6 +139,7 @@ public function getQuestion() /** * @param string $question + * @return void */ public function setQuestion($question) { @@ -154,6 +156,7 @@ public function getOptions() /** * @param array $options + * @return void */ public function setOptions($options) { @@ -170,6 +173,7 @@ public function getTotalVoterCount() /** * @param int $totalVoterCount + * @return void */ public function setTotalVoterCount($totalVoterCount) { @@ -186,6 +190,7 @@ public function isClosed() /** * @param bool $isClosed + * @return void */ public function setIsClosed($isClosed) { @@ -202,6 +207,7 @@ public function isAnonymous() /** * @param bool $isAnonymous + * @return void */ public function setIsAnonymous($isAnonymous) { @@ -218,6 +224,7 @@ public function getType() /** * @param string $type + * @return void */ public function setType($type) { @@ -234,6 +241,7 @@ public function isAllowsMultipleAnswers() /** * @param bool $allowsMultipleAnswers + * @return void */ public function setAllowsMultipleAnswers($allowsMultipleAnswers) { @@ -241,7 +249,7 @@ public function setAllowsMultipleAnswers($allowsMultipleAnswers) } /** - * @return int + * @return int|null */ public function getCorrectOptionId() { @@ -250,6 +258,7 @@ public function getCorrectOptionId() /** * @param int $correctOptionId + * @return void */ public function setCorrectOptionId($correctOptionId) { diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index 5b2c6ecd..5ae68123 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -59,6 +59,7 @@ public function getPollId() /** * @param string $id + * @return void */ public function setPollId($id) { @@ -75,6 +76,7 @@ public function getUser() /** * @param User $from + * @return void */ public function setUser(User $from) { @@ -103,6 +105,7 @@ public function getOptionIds() /** * @param int[] $optionIds + * @return void */ public function setOptionIds($optionIds) { diff --git a/src/Types/PollOption.php b/src/Types/PollOption.php index 1d22ffde..45beabb6 100644 --- a/src/Types/PollOption.php +++ b/src/Types/PollOption.php @@ -54,6 +54,7 @@ public function getText() /** * @param string $text + * @return void */ public function setText($text) { @@ -70,6 +71,7 @@ public function getVoterCount() /** * @param int $voterCount + * @return void */ public function setVoterCount($voterCount) { diff --git a/src/Types/ReplyKeyboardHide.php b/src/Types/ReplyKeyboardHide.php index 8dbfc8fb..7952605f 100644 --- a/src/Types/ReplyKeyboardHide.php +++ b/src/Types/ReplyKeyboardHide.php @@ -45,10 +45,14 @@ class ReplyKeyboardHide extends BaseType * 1) users that are @mentioned in the text of the Message object; * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. * - * @var bool + * @var bool|null */ protected $selective; + /** + * @param bool $hideKeyboard + * @param bool|null $selective + */ public function __construct($hideKeyboard = true, $selective = null) { $this->hideKeyboard = $hideKeyboard; @@ -56,7 +60,7 @@ public function __construct($hideKeyboard = true, $selective = null) } /** - * @return boolean + * @return bool */ public function isHideKeyboard() { @@ -64,7 +68,8 @@ public function isHideKeyboard() } /** - * @param boolean $hideKeyboard + * @param bool $hideKeyboard + * @return void */ public function setHideKeyboard($hideKeyboard) { @@ -72,7 +77,7 @@ public function setHideKeyboard($hideKeyboard) } /** - * @return boolean + * @return bool|null */ public function isSelective() { @@ -80,7 +85,8 @@ public function isSelective() } /** - * @param boolean $selective + * @param bool $selective + * @return void */ public function setSelective($selective) { diff --git a/src/Types/ReplyKeyboardMarkup.php b/src/Types/ReplyKeyboardMarkup.php index 6f20da9a..20fdfb0a 100644 --- a/src/Types/ReplyKeyboardMarkup.php +++ b/src/Types/ReplyKeyboardMarkup.php @@ -44,14 +44,14 @@ class ReplyKeyboardMarkup extends BaseType * (e.g., make the keyboard smaller if there are just two rows of buttons). * Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. * - * @var bool + * @var bool|null */ protected $resizeKeyboard; /** * Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. * - * @var bool + * @var bool|null */ protected $oneTimeKeyboard; @@ -61,10 +61,16 @@ class ReplyKeyboardMarkup extends BaseType * 1) users that are @mentioned in the text of the Message object; * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. * - * @var bool + * @var bool|null */ protected $selective; + /** + * @param array $keyboard + * @param bool|null $oneTimeKeyboard + * @param bool|null $resizeKeyboard + * @param bool|null $selective + */ public function __construct($keyboard = [], $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null) { $this->keyboard = $keyboard; @@ -83,6 +89,7 @@ public function getKeyboard() /** * @param array $keyboard + * @return void */ public function setKeyboard($keyboard) { @@ -90,7 +97,7 @@ public function setKeyboard($keyboard) } /** - * @return boolean + * @return bool|null */ public function isOneTimeKeyboard() { @@ -98,7 +105,8 @@ public function isOneTimeKeyboard() } /** - * @param boolean $oneTimeKeyboard + * @param bool $oneTimeKeyboard + * @return void */ public function setOneTimeKeyboard($oneTimeKeyboard) { @@ -106,7 +114,7 @@ public function setOneTimeKeyboard($oneTimeKeyboard) } /** - * @return boolean + * @return bool|null */ public function isResizeKeyboard() { @@ -114,7 +122,8 @@ public function isResizeKeyboard() } /** - * @param boolean $resizeKeyboard + * @param bool $resizeKeyboard + * @return void */ public function setResizeKeyboard($resizeKeyboard) { @@ -122,7 +131,7 @@ public function setResizeKeyboard($resizeKeyboard) } /** - * @return boolean + * @return bool|null */ public function isSelective() { @@ -130,7 +139,8 @@ public function isSelective() } /** - * @param boolean $selective + * @param bool $selective + * @return void */ public function setSelective($selective) { diff --git a/src/Types/ReplyKeyboardRemove.php b/src/Types/ReplyKeyboardRemove.php index 056b016f..7f55a036 100644 --- a/src/Types/ReplyKeyboardRemove.php +++ b/src/Types/ReplyKeyboardRemove.php @@ -44,10 +44,14 @@ class ReplyKeyboardRemove extends BaseType * 1) users that are @mentioned in the text of the Message object; * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. * - * @var bool + * @var bool|null */ protected $selective; + /** + * @param bool $removeKeyboard + * @param bool $selective + */ public function __construct($removeKeyboard = true, $selective = false) { $this->removeKeyboard = $removeKeyboard; @@ -64,6 +68,7 @@ public function getRemoveKeyboard() /** * @param bool $removeKeyboard + * @return void */ public function setRemoveKeyboard($removeKeyboard) { @@ -71,7 +76,7 @@ public function setRemoveKeyboard($removeKeyboard) } /** - * @return bool + * @return bool|null */ public function getSelective() { @@ -79,7 +84,8 @@ public function getSelective() } /** - * @param bool $selective + * @param bool|null $selective + * @return void */ public function setSelective($selective) { diff --git a/src/Types/Sticker.php b/src/Types/Sticker.php index 609a593d..8f2c91ef 100644 --- a/src/Types/Sticker.php +++ b/src/Types/Sticker.php @@ -75,14 +75,14 @@ class Sticker extends BaseType implements TypeInterface /** * Optional. Sticker thumbnail in the .WEBP or .JPG format * - * @var PhotoSize + * @var PhotoSize|null */ protected $thumb; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; @@ -106,7 +106,7 @@ class Sticker extends BaseType implements TypeInterface /** * Optional. For premium regular stickers, premium animation for the sticker * - * @var File + * @var File|null */ protected $premiumAnimation; @@ -127,28 +127,28 @@ class Sticker extends BaseType implements TypeInterface /** * Optional. Emoji associated with the sticker * - * @var string + * @var string|null */ protected $emoji; /** * Optional. Name of the sticker set to which the sticker belongs * - * @var string + * @var string|null */ protected $setName; /** * Optional. For mask stickers, the position where the mask should be placed * - * @var MaskPosition + * @var MaskPosition|null */ protected $maskPosition; /** * Optional. For custom emoji stickers, unique identifier of the custom emoji * - * @var string + * @var string|null */ protected $customEmojiId; @@ -162,6 +162,8 @@ public function getFileId() /** * @param string $fileId + * + * @return void */ public function setFileId($fileId) { @@ -169,7 +171,7 @@ public function setFileId($fileId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -177,9 +179,11 @@ public function getFileSize() } /** - * @param int $fileSize + * @param mixed $fileSize * * @throws InvalidArgumentException + * + * @return void */ public function setFileSize($fileSize) { @@ -199,9 +203,11 @@ public function getHeight() } /** - * @param int $height + * @param mixed $height * * @throws InvalidArgumentException + * + * @return void */ public function setHeight($height) { @@ -213,7 +219,7 @@ public function setHeight($height) } /** - * @return PhotoSize + * @return PhotoSize|null */ public function getThumb() { @@ -222,6 +228,8 @@ public function getThumb() /** * @param PhotoSize $thumb + * + * @return void */ public function setThumb(PhotoSize $thumb) { @@ -237,9 +245,11 @@ public function getWidth() } /** - * @param int $width + * @param mixed $width * * @throws InvalidArgumentException + * + * @return void */ public function setWidth($width) { @@ -260,6 +270,8 @@ public function getType() /** * @param string $type + * + * @return void */ public function setType($type) { @@ -276,6 +288,8 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * + * @return void */ public function setFileUniqueId($fileUniqueId) { @@ -283,7 +297,7 @@ public function setFileUniqueId($fileUniqueId) } /** - * @return File + * @return File|null */ public function getPremiumAnimation() { @@ -292,6 +306,8 @@ public function getPremiumAnimation() /** * @param File $premiumAnimation + * + * @return void */ public function setPremiumAnimation(File $premiumAnimation) { @@ -308,6 +324,8 @@ public function getIsAnimated() /** * @param bool $isAnimated + * + * @return void */ public function setIsAnimated($isAnimated) { @@ -324,6 +342,8 @@ public function getIsVideo() /** * @param bool $isVideo + * + * @return void */ public function setIsVideo($isVideo) { @@ -331,7 +351,7 @@ public function setIsVideo($isVideo) } /** - * @return string + * @return null|string */ public function getEmoji() { @@ -340,6 +360,8 @@ public function getEmoji() /** * @param string $emoji + * + * @return void */ public function setEmoji($emoji) { @@ -347,7 +369,7 @@ public function setEmoji($emoji) } /** - * @return string + * @return null|string */ public function getSetName() { @@ -356,6 +378,8 @@ public function getSetName() /** * @param string $setName + * + * @return void */ public function setSetName($setName) { @@ -363,7 +387,7 @@ public function setSetName($setName) } /** - * @return MaskPosition + * @return MaskPosition|null */ public function getMaskPosition() { @@ -372,6 +396,8 @@ public function getMaskPosition() /** * @param MaskPosition $maskPosition + * + * @return void */ public function setMaskPosition(MaskPosition $maskPosition) { @@ -379,7 +405,7 @@ public function setMaskPosition(MaskPosition $maskPosition) } /** - * @return string + * @return null|string */ public function getCustomEmojiId() { @@ -388,6 +414,8 @@ public function getCustomEmojiId() /** * @param string $customEmojiId + * + * @return void */ public function setCustomEmojiId($customEmojiId) { diff --git a/src/Types/StickerSet.php b/src/Types/StickerSet.php index 2559fee8..5127238f 100644 --- a/src/Types/StickerSet.php +++ b/src/Types/StickerSet.php @@ -81,7 +81,7 @@ class StickerSet extends BaseType implements TypeInterface /** * Optional. Sticker set thumbnail in the .WEBP or .TGS format * - * @var PhotoSize + * @var PhotoSize|null */ protected $thumb; @@ -95,6 +95,8 @@ public function getName() /** * @param string $name + * + * @return void */ public function setName($name) { @@ -111,6 +113,8 @@ public function getTitle() /** * @param string $title + * + * @return void */ public function setTitle($title) { @@ -127,6 +131,8 @@ public function getStickerType() /** * @param string $stickerType + * + * @return void */ public function setStickerType($stickerType) { @@ -143,6 +149,8 @@ public function getIsAnimated() /** * @param bool $isAnimated + * + * @return void */ public function setIsAnimated($isAnimated) { @@ -159,6 +167,8 @@ public function getIsVideo() /** * @param bool $isVideo + * + * @return void */ public function setIsVideo($isVideo) { @@ -175,6 +185,8 @@ public function getStickers() /** * @param ArrayOfSticker $stickers + * + * @return void */ public function setStickers($stickers) { @@ -182,7 +194,7 @@ public function setStickers($stickers) } /** - * @return PhotoSize + * @return PhotoSize|null */ public function getThumb() { @@ -191,6 +203,8 @@ public function getThumb() /** * @param PhotoSize $thumb + * + * @return void */ public function setThumb($thumb) { diff --git a/src/Types/Update.php b/src/Types/Update.php index 7b33fec9..3d324d90 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -58,73 +58,77 @@ class Update extends BaseType implements TypeInterface /** * Optional. New incoming message of any kind — text, photo, sticker, etc. * - * @var Message + * @var Message|null */ protected $message; /** - * @var PollAnswer + * Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself. + * + * @var PollAnswer|null */ protected $pollAnswer; /** - * @var Poll + * Optional. New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot + * + * @var Poll|null */ protected $poll; /** * Optional. New version of a message that is known to the bot and was edited * - * @var Message + * @var Message|null */ protected $editedMessage; /** * Optional. New incoming channel post of any kind — text, photo, sticker, etc. * - * @var Message + * @var Message|null */ protected $channelPost; /** * Optional. New version of a channel post that is known to the bot and was edited * - * @var Message + * @var Message|null */ protected $editedChannelPost; /** * Optional. New incoming inline query * - * @var \TelegramBot\Api\Types\Inline\InlineQuery + * @var \TelegramBot\Api\Types\Inline\InlineQuery|null */ 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 \TelegramBot\Api\Types\Inline\ChosenInlineResult|null */ protected $chosenInlineResult; /** * Optional. New incoming callback query * - * @var \TelegramBot\Api\Types\CallbackQuery + * @var \TelegramBot\Api\Types\CallbackQuery|null */ protected $callbackQuery; /** * Optional. New incoming shipping query. Only for invoices with flexible price * - * @var ShippingQuery + * @var ShippingQuery|null */ protected $shippingQuery; /** * Optional. New incoming pre-checkout query. Contains full information about checkout * - * @var PreCheckoutQuery + * @var PreCheckoutQuery|null */ protected $preCheckoutQuery; @@ -138,6 +142,8 @@ public function getUpdateId() /** * @param int $updateId + * + * @return void */ public function setUpdateId($updateId) { @@ -145,7 +151,7 @@ public function setUpdateId($updateId) } /** - * @return Message + * @return Message|null */ public function getMessage() { @@ -154,6 +160,8 @@ public function getMessage() /** * @param Message $message + * + * @return void */ public function setMessage(Message $message) { @@ -161,7 +169,7 @@ public function setMessage(Message $message) } /** - * @return Message + * @return Message|null */ public function getEditedMessage() { @@ -170,6 +178,8 @@ public function getEditedMessage() /** * @param Message $editedMessage + * + * @return void */ public function setEditedMessage($editedMessage) { @@ -177,7 +187,7 @@ public function setEditedMessage($editedMessage) } /** - * @return Message + * @return Message|null */ public function getChannelPost() { @@ -186,6 +196,8 @@ public function getChannelPost() /** * @param Message $channelPost + * + * @return void */ public function setChannelPost($channelPost) { @@ -193,7 +205,7 @@ public function setChannelPost($channelPost) } /** - * @return PollAnswer + * @return PollAnswer|null */ public function getPollAnswer() { @@ -201,7 +213,7 @@ public function getPollAnswer() } /** - * @return Poll + * @return Poll|null */ public function getPoll() { @@ -210,6 +222,8 @@ public function getPoll() /** * @param Poll $poll + * + * @return void */ public function setPoll($poll) { @@ -218,6 +232,8 @@ public function setPoll($poll) /** * @param PollAnswer $pollAnswer + * + * @return void */ public function setPollAnswer($pollAnswer) { @@ -225,7 +241,7 @@ public function setPollAnswer($pollAnswer) } /** - * @return Message + * @return Message|null */ public function getEditedChannelPost() { @@ -234,6 +250,8 @@ public function getEditedChannelPost() /** * @param Message $editedChannelPost + * + * @return void */ public function setEditedChannelPost($editedChannelPost) { @@ -241,7 +259,7 @@ public function setEditedChannelPost($editedChannelPost) } /** - * @return InlineQuery + * @return InlineQuery|null */ public function getInlineQuery() { @@ -250,6 +268,8 @@ public function getInlineQuery() /** * @param InlineQuery $inlineQuery + * + * @return void */ public function setInlineQuery($inlineQuery) { @@ -257,7 +277,7 @@ public function setInlineQuery($inlineQuery) } /** - * @return ChosenInlineResult + * @return ChosenInlineResult|null */ public function getChosenInlineResult() { @@ -266,6 +286,8 @@ public function getChosenInlineResult() /** * @param ChosenInlineResult $chosenInlineResult + * + * @return void */ public function setChosenInlineResult($chosenInlineResult) { @@ -273,7 +295,7 @@ public function setChosenInlineResult($chosenInlineResult) } /** - * @return CallbackQuery + * @return CallbackQuery|null */ public function getCallbackQuery() { @@ -282,6 +304,8 @@ public function getCallbackQuery() /** * @param CallbackQuery $callbackQuery + * + * @return void */ public function setCallbackQuery($callbackQuery) { @@ -290,7 +314,8 @@ public function setCallbackQuery($callbackQuery) /** * @author MY - * @return ShippingQuery + * + * @return ShippingQuery|null */ public function getShippingQuery() { @@ -299,7 +324,10 @@ public function getShippingQuery() /** * @author MY + * * @param ShippingQuery $shippingQuery + * + * @return void */ public function setShippingQuery($shippingQuery) { @@ -308,7 +336,8 @@ public function setShippingQuery($shippingQuery) /** * @author MY - * @return PreCheckoutQuery + * + * @return PreCheckoutQuery|null */ public function getPreCheckoutQuery() { @@ -317,7 +346,10 @@ public function getPreCheckoutQuery() /** * @author MY + * * @param PreCheckoutQuery $preCheckoutQuery + * + * @return void */ public function setPreCheckoutQuery($preCheckoutQuery) { diff --git a/src/Types/User.php b/src/Types/User.php index b6d204fb..34a8be78 100644 --- a/src/Types/User.php +++ b/src/Types/User.php @@ -43,7 +43,7 @@ class User extends BaseType implements TypeInterface /** * Unique identifier for this user or bot * - * @var int + * @var int|float */ protected $id; @@ -57,21 +57,21 @@ class User extends BaseType implements TypeInterface /** * Optional. User‘s or bot’s last name * - * @var string + * @var string|null */ protected $lastName; /** * Optional. User‘s or bot’s username * - * @var string + * @var string|null */ protected $username; /** * Optional. IETF language tag of the user's language * - * @var string + * @var string|null */ protected $languageCode; @@ -85,35 +85,35 @@ class User extends BaseType implements TypeInterface /** * Optional. True, if this user is a Telegram Premium user * - * @var bool + * @var bool|null */ protected $isPremium; /** * Optional. True, if this user added the bot to the attachment menu * - * @var bool + * @var bool|null */ protected $addedToAttachmentMenu; /** * Optional. True, if the bot can be invited to groups. Returned only in getMe. * - * @var bool + * @var bool|null */ protected $canJoinGroups; /** * Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. * - * @var bool + * @var bool|null */ protected $canReadAllGroupMessages; /** * Optional. True, if the bot supports inline queries. Returned only in getMe. * - * @var bool + * @var bool|null */ protected $supportsInlineQueries; @@ -127,6 +127,8 @@ public function getFirstName() /** * @param string $firstName + * + * @return void */ public function setFirstName($firstName) { @@ -134,7 +136,7 @@ public function setFirstName($firstName) } /** - * @return int + * @return int|float */ public function getId() { @@ -142,9 +144,11 @@ public function getId() } /** - * @param int $id + * @param mixed $id * * @throws InvalidArgumentException + * + * @return void */ public function setId($id) { @@ -156,7 +160,7 @@ public function setId($id) } /** - * @return string + * @return null|string */ public function getLastName() { @@ -165,6 +169,8 @@ public function getLastName() /** * @param string $lastName + * + * @return void */ public function setLastName($lastName) { @@ -172,7 +178,7 @@ public function setLastName($lastName) } /** - * @return string + * @return null|string */ public function getUsername() { @@ -181,6 +187,8 @@ public function getUsername() /** * @param string $username + * + * @return void */ public function setUsername($username) { @@ -188,7 +196,7 @@ public function setUsername($username) } /** - * @return string + * @return null|string */ public function getLanguageCode() { @@ -197,6 +205,8 @@ public function getLanguageCode() /** * @param string $languageCode + * + * @return void */ public function setLanguageCode($languageCode) { @@ -213,6 +223,8 @@ public function isBot() /** * @param bool $isBot + * + * @return void */ public function setIsBot($isBot) { @@ -221,6 +233,8 @@ public function setIsBot($isBot) /** * @param bool $isPremium + * + * @return void */ public function setIsPremium($isPremium) { @@ -228,7 +242,7 @@ public function setIsPremium($isPremium) } /** - * @return bool + * @return bool|null */ public function getIsPremium() { @@ -237,6 +251,8 @@ public function getIsPremium() /** * @param bool $addedToAttachmentMenu + * + * @return void */ public function setAddedToAttachmentMenu($addedToAttachmentMenu) { @@ -244,7 +260,7 @@ public function setAddedToAttachmentMenu($addedToAttachmentMenu) } /** - * @return bool + * @return bool|null */ public function getAddedToAttachmentMenu() { @@ -253,6 +269,8 @@ public function getAddedToAttachmentMenu() /** * @param bool $canJoinGroups + * + * @return void */ public function setCanJoinGroups($canJoinGroups) { @@ -260,7 +278,7 @@ public function setCanJoinGroups($canJoinGroups) } /** - * @return bool + * @return bool|null */ public function getCanJoinGroups() { @@ -269,6 +287,8 @@ public function getCanJoinGroups() /** * @param bool $canReadAllGroupMessages + * + * @return void */ public function setCanReadAllGroupMessages($canReadAllGroupMessages) { @@ -276,7 +296,7 @@ public function setCanReadAllGroupMessages($canReadAllGroupMessages) } /** - * @return bool + * @return bool|null */ public function getCanReadAllGroupMessages() { @@ -285,6 +305,8 @@ public function getCanReadAllGroupMessages() /** * @param bool $supportsInlineQueries + * + * @return void */ public function setSupportsInlineQueries($supportsInlineQueries) { @@ -292,7 +314,7 @@ public function setSupportsInlineQueries($supportsInlineQueries) } /** - * @return bool + * @return bool|null */ public function getSupportsInlineQueries() { diff --git a/src/Types/UserProfilePhotos.php b/src/Types/UserProfilePhotos.php index cac8f52b..5c22c33d 100644 --- a/src/Types/UserProfilePhotos.php +++ b/src/Types/UserProfilePhotos.php @@ -34,7 +34,7 @@ class UserProfilePhotos extends BaseType implements TypeInterface /** * Total number of profile pictures the target user has * - * @var Integer + * @var int */ protected $totalCount; @@ -56,6 +56,8 @@ public function getPhotos() /** * @param array $photos + * + * @return void */ public function setPhotos($photos) { @@ -71,9 +73,11 @@ public function getTotalCount() } /** - * @param int $totalCount + * @param mixed $totalCount * * @throws InvalidArgumentException + * + * @return void */ public function setTotalCount($totalCount) { diff --git a/src/Types/Venue.php b/src/Types/Venue.php index 2414a5a9..38718f64 100644 --- a/src/Types/Venue.php +++ b/src/Types/Venue.php @@ -65,28 +65,28 @@ class Venue extends BaseType implements TypeInterface /** * Optional. Foursquare identifier of the venue * - * @var string + * @var string|null */ protected $foursquareId; /** * Optional. Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) * - * @var string + * @var string|null */ protected $foursquareType; /** * Optional. Google Places identifier of the venue * - * @var string + * @var string|null */ protected $googlePlaceId; /** * Optional. Google Places type of the venue. * - * @var string + * @var string|null */ protected $googlePlaceType; @@ -100,6 +100,8 @@ public function getLocation() /** * @param Location $location + * + * @return void */ public function setLocation($location) { @@ -116,6 +118,8 @@ public function getTitle() /** * @param string $title + * + * @return void */ public function setTitle($title) { @@ -132,6 +136,8 @@ public function getAddress() /** * @param string $address + * + * @return void */ public function setAddress($address) { @@ -139,7 +145,7 @@ public function setAddress($address) } /** - * @return string + * @return null|string */ public function getFoursquareId() { @@ -148,6 +154,8 @@ public function getFoursquareId() /** * @param string $foursquareId + * + * @return void */ public function setFoursquareId($foursquareId) { @@ -155,7 +163,7 @@ public function setFoursquareId($foursquareId) } /** - * @return string + * @return null|string */ public function getFoursquareType() { @@ -164,6 +172,8 @@ public function getFoursquareType() /** * @param string $foursquareType + * + * @return void */ public function setFoursquareType($foursquareType) { @@ -171,7 +181,7 @@ public function setFoursquareType($foursquareType) } /** - * @return string + * @return null|string */ public function getGooglePlaceId() { @@ -180,6 +190,8 @@ public function getGooglePlaceId() /** * @param string $googlePlaceId + * + * @return void */ public function setGooglePlaceId($googlePlaceId) { @@ -187,7 +199,7 @@ public function setGooglePlaceId($googlePlaceId) } /** - * @return string + * @return null|string */ public function getGooglePlaceType() { @@ -196,6 +208,8 @@ public function getGooglePlaceType() /** * @param string $googlePlaceType + * + * @return void */ public function setGooglePlaceType($googlePlaceType) { diff --git a/src/Types/Video.php b/src/Types/Video.php index f367a77e..b0ef4a75 100644 --- a/src/Types/Video.php +++ b/src/Types/Video.php @@ -75,14 +75,14 @@ class Video extends BaseType implements TypeInterface /** * Optional. Mime type of a file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; @@ -102,9 +102,11 @@ public function getDuration() } /** - * @param int $duration + * @param mixed $duration * * @throws InvalidArgumentException + * + * @return void */ public function setDuration($duration) { @@ -125,6 +127,8 @@ public function getFileId() /** * @param string $fileId + * + * @return void */ public function setFileId($fileId) { @@ -132,7 +136,7 @@ public function setFileId($fileId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -140,9 +144,11 @@ public function getFileSize() } /** - * @param int $fileSize + * @param mixed $fileSize * * @throws InvalidArgumentException + * + * @return void */ public function setFileSize($fileSize) { @@ -162,9 +168,11 @@ public function getHeight() } /** - * @param int $height + * @param mixed $height * * @throws InvalidArgumentException + * + * @return void */ public function setHeight($height) { @@ -176,7 +184,7 @@ public function setHeight($height) } /** - * @return string + * @return null|string */ public function getMimeType() { @@ -185,6 +193,8 @@ public function getMimeType() /** * @param string $mimeType + * + * @return void */ public function setMimeType($mimeType) { @@ -201,6 +211,8 @@ public function getThumb() /** * @param PhotoSize $thumb + * + * @return void */ public function setThumb(PhotoSize $thumb) { @@ -216,9 +228,11 @@ public function getWidth() } /** - * @param int $width + * @param mixed $width * * @throws InvalidArgumentException + * + * @return void */ public function setWidth($width) { @@ -239,6 +253,8 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * + * @return void */ public function setFileUniqueId($fileUniqueId) { diff --git a/src/Types/VideoNote.php b/src/Types/VideoNote.php index c4e40303..a10325a3 100644 --- a/src/Types/VideoNote.php +++ b/src/Types/VideoNote.php @@ -55,14 +55,14 @@ class VideoNote extends BaseType implements TypeInterface /** * Optional. Video thumbnail * - * @var PhotoSize + * @var PhotoSize|null */ protected $thumb; /** * Optional. File size in bytes * - * @var int + * @var int|null */ protected $fileSize; @@ -76,6 +76,8 @@ public function getFileId() /** * @param string $fileId + * + * @return void */ public function setFileId($fileId) { @@ -92,6 +94,8 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * + * @return void */ public function setFileUniqueId($fileUniqueId) { @@ -108,6 +112,8 @@ public function getLength() /** * @param int $length + * + * @return void */ public function setLength($length) { @@ -124,6 +130,8 @@ public function getDuration() /** * @param int $duration + * + * @return void */ public function setDuration($duration) { @@ -131,7 +139,7 @@ public function setDuration($duration) } /** - * @return PhotoSize + * @return PhotoSize|null */ public function getThumb() { @@ -140,6 +148,8 @@ public function getThumb() /** * @param PhotoSize $thumb + * + * @return void */ public function setThumb($thumb) { @@ -147,7 +157,7 @@ public function setThumb($thumb) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -156,6 +166,8 @@ public function getFileSize() /** * @param int $fileSize + * + * @return void */ public function setFileSize($fileSize) { diff --git a/src/Types/Voice.php b/src/Types/Voice.php index e8015a96..005303c6 100644 --- a/src/Types/Voice.php +++ b/src/Types/Voice.php @@ -59,14 +59,14 @@ class Voice extends BaseType implements TypeInterface /** * Optional. MIME type of the file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; @@ -80,6 +80,8 @@ public function getFileId() /** * @param string $fileId + * + * @return void */ public function setFileId($fileId) { @@ -96,6 +98,8 @@ public function getFileUniqueId() /** * @param string $fileUniqueId + * + * @return void */ public function setFileUniqueId($fileUniqueId) { @@ -111,9 +115,11 @@ public function getDuration() } /** - * @param int $duration + * @param mixed $duration * * @throws InvalidArgumentException + * + * @return void */ public function setDuration($duration) { @@ -125,7 +131,7 @@ public function setDuration($duration) } /** - * @return string + * @return null|string */ public function getMimeType() { @@ -134,6 +140,8 @@ public function getMimeType() /** * @param string $mimeType + * + * @return void */ public function setMimeType($mimeType) { @@ -141,7 +149,7 @@ public function setMimeType($mimeType) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -149,9 +157,11 @@ public function getFileSize() } /** - * @param int $fileSize + * @param mixed $fileSize * * @throws InvalidArgumentException + * + * @return void */ public function setFileSize($fileSize) { diff --git a/src/Types/WebhookInfo.php b/src/Types/WebhookInfo.php index 2b477e93..68a64327 100644 --- a/src/Types/WebhookInfo.php +++ b/src/Types/WebhookInfo.php @@ -65,14 +65,14 @@ class WebhookInfo extends BaseType implements TypeInterface /** * Optional. Currently used webhook IP address * - * @var string + * @var string|null */ protected $ipAddress; /** * Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook * - * @var int + * @var int|null */ protected $lastErrorDate; @@ -80,7 +80,7 @@ class WebhookInfo extends BaseType implements TypeInterface * Optional. Error message in human-readable format for the most recent error that happened when trying to deliver * an update via webhook * - * @var string + * @var string|null */ protected $lastErrorMessage; @@ -88,21 +88,21 @@ class WebhookInfo extends BaseType implements TypeInterface * Optional. Unix time of the most recent error that happened when trying to synchronize available updates * with Telegram datacenters * - * @var int + * @var int|null */ protected $lastSynchronizationErrorDate; /** * Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery * - * @var int + * @var int|null */ protected $maxConnections; /** * Optional. A list of update types the bot is subscribed to. Defaults to all update types * - * @var array + * @var array|null */ protected $allowedUpdates; @@ -116,6 +116,8 @@ public function getUrl() /** * @param string $url + * + * @return void */ public function setUrl($url) { @@ -132,6 +134,8 @@ public function hasCustomCertificate() /** * @param bool $hasCustomCertificate + * + * @return void */ public function setHasCustomCertificate($hasCustomCertificate) { @@ -140,6 +144,8 @@ public function setHasCustomCertificate($hasCustomCertificate) /** * @param string $ipAddress + * + * @return void */ public function setIpAddress($ipAddress) { @@ -147,7 +153,7 @@ public function setIpAddress($ipAddress) } /** - * @return string + * @return null|string */ public function getIpAddress() { @@ -164,6 +170,8 @@ public function getPendingUpdateCount() /** * @param int $pendingUpdateCount + * + * @return void */ public function setPendingUpdateCount($pendingUpdateCount) { @@ -171,7 +179,7 @@ public function setPendingUpdateCount($pendingUpdateCount) } /** - * @return int + * @return int|null */ public function getLastErrorDate() { @@ -180,6 +188,8 @@ public function getLastErrorDate() /** * @param int $lastErrorDate + * + * @return void */ public function setLastErrorDate($lastErrorDate) { @@ -187,7 +197,7 @@ public function setLastErrorDate($lastErrorDate) } /** - * @return string + * @return null|string */ public function getLastErrorMessage() { @@ -196,6 +206,8 @@ public function getLastErrorMessage() /** * @param string $lastErrorMessage + * + * @return void */ public function setLastErrorMessage($lastErrorMessage) { @@ -203,7 +215,9 @@ public function setLastErrorMessage($lastErrorMessage) } /** - * @param string $lastSynchronizationErrorDate + * @param int $lastSynchronizationErrorDate + * + * @return void */ public function setLastSynchronizationErrorDate($lastSynchronizationErrorDate) { @@ -211,15 +225,15 @@ public function setLastSynchronizationErrorDate($lastSynchronizationErrorDate) } /** - * @return int + * @return int|null */ - public function getlastSynchronizationErrorDate() + public function getLastSynchronizationErrorDate() { return $this->lastSynchronizationErrorDate; } /** - * @return int + * @return int|null */ public function getMaxConnections() { @@ -228,6 +242,8 @@ public function getMaxConnections() /** * @param int $maxConnections + * + * @return void */ public function setMaxConnections($maxConnections) { @@ -235,7 +251,7 @@ public function setMaxConnections($maxConnections) } /** - * @return array + * @return array|null */ public function getAllowedUpdates() { @@ -244,6 +260,8 @@ public function getAllowedUpdates() /** * @param array $allowedUpdates + * + * @return void */ public function setAllowedUpdates($allowedUpdates) { diff --git a/tests/Events/EventTest.php b/tests/Events/EventTest.php index ce53602c..3247a4e5 100644 --- a/tests/Events/EventTest.php +++ b/tests/Events/EventTest.php @@ -102,26 +102,6 @@ public function testExecuteAction($action, $checker, $update) $this->assertEquals($update, $result); } - /** - * @param \Closure $action - * @param \Closure $checker - * @param Update $update - * - * @dataProvider data - */ - public function testExecuteActionFalse($action, $checker, $update) - { - $item = new Event($action, $checker); - - $reflection = new \ReflectionClass($item); - $reflectionProperty = $reflection->getProperty('action'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($item, 1); - $reflectionProperty->setAccessible(false); - - $this->assertFalse($item->executeAction($update)); - } - /** * @param \Closure $action * @param \Closure $checker From e843079f77097e0611cdc75299c405b24593af8a Mon Sep 17 00:00:00 2001 From: eerzho Date: Mon, 1 May 2023 23:20:29 +0200 Subject: [PATCH 096/130] added is_persistent parameter in ReplyKeyboardMarkup --- src/Types/ReplyKeyboardMarkup.php | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Types/ReplyKeyboardMarkup.php b/src/Types/ReplyKeyboardMarkup.php index 20fdfb0a..2c247b37 100644 --- a/src/Types/ReplyKeyboardMarkup.php +++ b/src/Types/ReplyKeyboardMarkup.php @@ -28,7 +28,8 @@ class ReplyKeyboardMarkup extends BaseType 'keyboard' => true, 'one_time_keyboard' => true, 'resize_keyboard' => true, - 'selective' => true + 'selective' => true, + 'is_persistent' => true ]; /** @@ -65,18 +66,28 @@ class ReplyKeyboardMarkup extends BaseType */ protected $selective; + /** + * Optional. Requests clients to always show the keyboard when the regular keyboard is hidden. + * Defaults to false, in which case the custom keyboard can be hidden and opened with a keyboard icon. + * + * @var bool|null + */ + protected $isPersistent; + /** * @param array $keyboard * @param bool|null $oneTimeKeyboard * @param bool|null $resizeKeyboard * @param bool|null $selective + * @param bool|null $isPersistent */ - public function __construct($keyboard = [], $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null) + public function __construct($keyboard = [], $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null, $isPersistent = null) { $this->keyboard = $keyboard; $this->oneTimeKeyboard = $oneTimeKeyboard; $this->resizeKeyboard = $resizeKeyboard; $this->selective = $selective; + $this->isPersistent = $isPersistent; } /** @@ -146,4 +157,21 @@ public function setSelective($selective) { $this->selective = $selective; } + + /** + * @return bool|null + */ + public function getIsPersistent() + { + return $this->isPersistent; + } + + /** + * @param bool $isPersistent + * @return void + */ + public function setIsPersistent($isPersistent) + { + $this->isPersistent = $isPersistent; + } } From f18e74043819279fe86b87d278c345682f7670e9 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 2 May 2023 11:10:33 +0300 Subject: [PATCH 097/130] WebApp Support --- src/BotApi.php | 20 +++++++- src/Types/Message.php | 27 +++++++++- src/Types/SentWebAppMessage.php | 49 ++++++++++++++++++ src/Types/WebAppData.php | 74 +++++++++++++++++++++++++++ tests/Types/MessageTest.php | 3 ++ tests/Types/SentWebAppMessageTest.php | 44 ++++++++++++++++ tests/Types/WebAppDataTest.php | 46 +++++++++++++++++ 7 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 src/Types/SentWebAppMessage.php create mode 100644 src/Types/WebAppData.php create mode 100644 tests/Types/SentWebAppMessageTest.php create mode 100644 tests/Types/WebAppDataTest.php diff --git a/src/BotApi.php b/src/BotApi.php index a1af5cf4..8612988b 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -25,6 +25,7 @@ use TelegramBot\Api\Types\ReplyKeyboardHide; use TelegramBot\Api\Types\ReplyKeyboardMarkup; use TelegramBot\Api\Types\ReplyKeyboardRemove; +use TelegramBot\Api\Types\SentWebAppMessage; use TelegramBot\Api\Types\Sticker; use TelegramBot\Api\Types\StickerSet; use TelegramBot\Api\Types\Update; @@ -335,7 +336,7 @@ public static function jsonValidate($jsonString, $asArray) /** * Use this method to send text messages. On success, the sent \TelegramBot\Api\Types\Message is returned. * - * @param int|string $chatId + * @param int|float|string $chatId * @param string $text * @param string|null $parseMode * @param bool $disablePreview @@ -2570,6 +2571,23 @@ public function getForumTopicIconStickers() return ArrayOfSticker::fromResponse($this->call('getForumTopicIconStickers')); } + /** + * @param string $webAppQueryId + * @param AbstractInlineQueryResult $result + * @return SentWebAppMessage + * @throws Exception + * @throws HttpException + * @throws InvalidArgumentException + * @throws InvalidJsonException + */ + public function answerWebAppQuery($webAppQueryId, $result) + { + return SentWebAppMessage::fromResponse($this->call('answerWebAppQuery', [ + 'web_app_query_id' => $webAppQueryId, + 'result' => $result->toJson(), + ])); + } + /** * Set an option for a cURL transfer * diff --git a/src/Types/Message.php b/src/Types/Message.php index 609308f5..abd6adad 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -74,7 +74,8 @@ class Message extends BaseType implements TypeInterface 'forum_topic_reopened' => ForumTopicReopened::class, 'is_topic_message' => true, 'message_thread_id' => true, - 'reply_markup' => InlineKeyboardMarkup::class + 'web_app_data' => WebAppData::class, + 'reply_markup' => InlineKeyboardMarkup::class, ]; /** @@ -405,6 +406,13 @@ class Message extends BaseType implements TypeInterface */ protected $connectedWebsite; + /** + * Optional. Service message: data sent by a Web App + * + * @var WebAppData|null + */ + protected $webAppData; + /** * Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. * @@ -1238,6 +1246,23 @@ public function setConnectedWebsite($connectedWebsite) $this->connectedWebsite = $connectedWebsite; } + /** + * @return WebAppData|null + */ + public function getWebAppData() + { + return $this->webAppData; + } + + /** + * @param WebAppData|null $webAppData + * @return void + */ + public function setWebAppData($webAppData) + { + $this->webAppData = $webAppData; + } + /** * @return InlineKeyboardMarkup|null */ diff --git a/src/Types/SentWebAppMessage.php b/src/Types/SentWebAppMessage.php new file mode 100644 index 00000000..27e32e25 --- /dev/null +++ b/src/Types/SentWebAppMessage.php @@ -0,0 +1,49 @@ + true, + ]; + + /** + * Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. + * + * @var string|null + */ + protected $inlineMessageId; + + /** + * @return string|null + */ + public function getInlineMessageId() + { + return $this->inlineMessageId; + } + + /** + * @param string|null $inlineMessageId + * @return void + */ + public function setInlineMessageId($inlineMessageId) + { + $this->inlineMessageId = $inlineMessageId; + } +} diff --git a/src/Types/WebAppData.php b/src/Types/WebAppData.php new file mode 100644 index 00000000..ee88dbc0 --- /dev/null +++ b/src/Types/WebAppData.php @@ -0,0 +1,74 @@ + true, + 'button_text' => true, + ]; + + /** + * The data. Be aware that a bad client can send arbitrary data in this field. + * + * @var string + */ + protected $data; + + /** + * Text of the web_app keyboard button from which the Web App was opened. Be aware that a bad client can send arbitrary data in this field. + * + * @var string + */ + protected $buttonText; + + /** + * @return string + */ + public function getData() + { + return $this->data; + } + + /** + * @param string $data + * @return void + */ + public function setData($data) + { + $this->data = $data; + } + + /** + * @return string + */ + public function getButtonText() + { + return $this->buttonText; + } + + /** + * @param string $buttonText + * @return void + */ + public function setButtonText($buttonText) + { + $this->buttonText = $buttonText; + } +} diff --git a/tests/Types/MessageTest.php b/tests/Types/MessageTest.php index 03415489..9fa8f958 100644 --- a/tests/Types/MessageTest.php +++ b/tests/Types/MessageTest.php @@ -89,6 +89,7 @@ public static function getFullResponse() 'forum_topic_reopened' => ForumTopicReopenedTest::getMinResponse(), 'is_topic_message' => true, 'message_thread_id' => 6, + 'web_app_data' => WebAppDataTest::getMinResponse(), 'reply_markup' => InlineKeyboardMarkupTest::getMinResponse() ]; } @@ -150,6 +151,7 @@ protected function assertMinItem($item) $this->assertNull($item->getForumTopicReopened()); $this->assertNull($item->getIsTopicMessage()); $this->assertNull($item->getMessageThreadId()); + $this->assertNull($item->getWebAppData()); $this->assertNull($item->getReplyMarkup()); } @@ -210,6 +212,7 @@ protected function assertFullItem($item) // $this->assertEquals(ForumTopicReopenedTest::createMinInstance(), $item->getForumTopicReopened()); $this->assertTrue($item->getIsTopicMessage()); $this->assertEquals(6, $item->getMessageThreadId()); + $this->assertEquals(WebAppDataTest::createMinInstance(), $item->getWebAppData()); $this->assertEquals(InlineKeyboardMarkupTest::createMinInstance(), $item->getReplyMarkup()); } diff --git a/tests/Types/SentWebAppMessageTest.php b/tests/Types/SentWebAppMessageTest.php new file mode 100644 index 00000000..37820df2 --- /dev/null +++ b/tests/Types/SentWebAppMessageTest.php @@ -0,0 +1,44 @@ + 'inline_message_id', + ]; + } + + /** + * @param SentWebAppMessage $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertNull($item->getInlineMessageId()); + } + + /** + * @param SentWebAppMessage $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('inline_message_id', $item->getInlineMessageId()); + } +} diff --git a/tests/Types/WebAppDataTest.php b/tests/Types/WebAppDataTest.php new file mode 100644 index 00000000..a5879146 --- /dev/null +++ b/tests/Types/WebAppDataTest.php @@ -0,0 +1,46 @@ + 'data', + 'button_text' => 'button_text', + ]; + } + + public static function getFullResponse() + { + return self::getMinResponse(); + } + + /** + * @param WebAppData $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('data', $item->getData()); + $this->assertEquals('button_text', $item->getButtonText()); + } + + /** + * @param WebAppData $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} From e07ac2b411ee5567cdaa927b4343ae6425cafb84 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 2 May 2023 18:39:42 +0300 Subject: [PATCH 098/130] Add ReplyKeyboardMarkup::$isPersistent tests --- tests/Types/ReplyKeyboardMarkupTest.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/Types/ReplyKeyboardMarkupTest.php b/tests/Types/ReplyKeyboardMarkupTest.php index 14ca6c64..960ec6c7 100644 --- a/tests/Types/ReplyKeyboardMarkupTest.php +++ b/tests/Types/ReplyKeyboardMarkupTest.php @@ -25,7 +25,8 @@ public static function getFullResponse() 'keyboard' => [['one', 'two']], 'one_time_keyboard' => true, 'resize_keyboard' => true, - 'selective' => true + 'selective' => true, + 'is_persistent' => true, ]; } @@ -39,6 +40,7 @@ protected function assertMinItem($item) $this->assertNull($item->isOneTimeKeyboard()); $this->assertNull($item->isResizeKeyboard()); $this->assertNull($item->isSelective()); + $this->assertNull($item->getIsPersistent()); } /** @@ -51,6 +53,7 @@ protected function assertFullItem($item) $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(true, $item->getIsPersistent()); } public function testConstructor() @@ -61,6 +64,7 @@ public function testConstructor() $this->assertEquals(null, $item->isOneTimeKeyboard()); $this->assertEquals(null, $item->isResizeKeyboard()); $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getIsPersistent()); } public function testConstructor2() @@ -71,6 +75,7 @@ public function testConstructor2() $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(null, $item->isResizeKeyboard()); $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getIsPersistent()); } public function testConstructor3() @@ -81,6 +86,7 @@ public function testConstructor3() $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getIsPersistent()); } public function testConstructor4() @@ -91,5 +97,17 @@ public function testConstructor4() $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(null, $item->getIsPersistent()); + } + + public function testConstructor5() + { + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true, true); + + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(true, $item->getIsPersistent()); } } From f688ef1c8c178feb843444799f23f405321e07ab Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 2 May 2023 18:46:55 +0300 Subject: [PATCH 099/130] CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f03b175..7bcbfe0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file ### Added - Add `\TelegramBot\Api\Types\Venue` mapping (`foursquare_type`, `google_place_id`, `google_place_type`) - Add `scope` and `languageCode` parameters to `\TelegramBot\Api\BotApi::setMyCommands` +- Add WebApp support: `\TelegramBot\Api\BotApi::answerWebAppQuery` method and `\TelegramBot\Api\Types\Message::$webAppData` property +- Add `\TelegramBot\Api\Types\ReplyKeyboardMarkup::$isPersistent` property ### Fixed - Fix `\TelegramBot\Api\Collection\Collection::addItem` max count constraint (#333) From 5f7ab4c40267612c10ee4f9a328e1e19fa77edb5 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 2 May 2023 18:55:58 +0300 Subject: [PATCH 100/130] ReplyKeyboardMarkup::$inputFieldPlaceholder --- CHANGELOG.md | 1 + src/Types/ReplyKeyboardMarkup.php | 31 +++++++++++++++++-- tests/Types/ReplyKeyboardMarkupTest.php | 40 ++++++++++++++++++------- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bcbfe0e..77ff2ab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Add `scope` and `languageCode` parameters to `\TelegramBot\Api\BotApi::setMyCommands` - Add WebApp support: `\TelegramBot\Api\BotApi::answerWebAppQuery` method and `\TelegramBot\Api\Types\Message::$webAppData` property - Add `\TelegramBot\Api\Types\ReplyKeyboardMarkup::$isPersistent` property +- Add `\TelegramBot\Api\Types\ReplyKeyboardMarkup::$inputFieldPlaceholder` property ### Fixed - Fix `\TelegramBot\Api\Collection\Collection::addItem` max count constraint (#333) diff --git a/src/Types/ReplyKeyboardMarkup.php b/src/Types/ReplyKeyboardMarkup.php index 2c247b37..f490ec4f 100644 --- a/src/Types/ReplyKeyboardMarkup.php +++ b/src/Types/ReplyKeyboardMarkup.php @@ -29,7 +29,8 @@ class ReplyKeyboardMarkup extends BaseType 'one_time_keyboard' => true, 'resize_keyboard' => true, 'selective' => true, - 'is_persistent' => true + 'is_persistent' => true, + 'input_field_placeholder' => true, ]; /** @@ -74,20 +75,29 @@ class ReplyKeyboardMarkup extends BaseType */ protected $isPersistent; + /** + * Optional. The placeholder to be shown in the input field when the keyboard is active; 1-64 characters + * + * @var string|null + */ + protected $inputFieldPlaceholder; + /** * @param array $keyboard * @param bool|null $oneTimeKeyboard * @param bool|null $resizeKeyboard * @param bool|null $selective * @param bool|null $isPersistent + * @param string|null $inputFieldPlaceholder */ - public function __construct($keyboard = [], $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null, $isPersistent = null) + public function __construct($keyboard = [], $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null, $isPersistent = null, $inputFieldPlaceholder = null) { $this->keyboard = $keyboard; $this->oneTimeKeyboard = $oneTimeKeyboard; $this->resizeKeyboard = $resizeKeyboard; $this->selective = $selective; $this->isPersistent = $isPersistent; + $this->inputFieldPlaceholder = $inputFieldPlaceholder; } /** @@ -174,4 +184,21 @@ public function setIsPersistent($isPersistent) { $this->isPersistent = $isPersistent; } + + /** + * @return string|null + */ + public function getInputFieldPlaceholder() + { + return $this->inputFieldPlaceholder; + } + + /** + * @param string|null $inputFieldPlaceholder + * @return void + */ + public function setInputFieldPlaceholder($inputFieldPlaceholder) + { + $this->inputFieldPlaceholder = $inputFieldPlaceholder; + } } diff --git a/tests/Types/ReplyKeyboardMarkupTest.php b/tests/Types/ReplyKeyboardMarkupTest.php index 960ec6c7..f3154e13 100644 --- a/tests/Types/ReplyKeyboardMarkupTest.php +++ b/tests/Types/ReplyKeyboardMarkupTest.php @@ -27,6 +27,7 @@ public static function getFullResponse() 'resize_keyboard' => true, 'selective' => true, 'is_persistent' => true, + 'input_field_placeholder' => 'input_field_placeholder', ]; } @@ -41,6 +42,7 @@ protected function assertMinItem($item) $this->assertNull($item->isResizeKeyboard()); $this->assertNull($item->isSelective()); $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); } /** @@ -54,6 +56,7 @@ protected function assertFullItem($item) $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(true, $item->isSelective()); $this->assertEquals(true, $item->getIsPersistent()); + $this->assertEquals('input_field_placeholder', $item->getInputFieldPlaceholder()); } public function testConstructor() @@ -61,10 +64,11 @@ public function testConstructor() $item = new ReplyKeyboardMarkup([['one', 'two']]); $this->assertEquals([['one', 'two']], $item->getKeyboard()); - $this->assertEquals(null, $item->isOneTimeKeyboard()); - $this->assertEquals(null, $item->isResizeKeyboard()); - $this->assertEquals(null, $item->isSelective()); - $this->assertEquals(null, $item->getIsPersistent()); + $this->assertNull($item->isOneTimeKeyboard()); + $this->assertNull($item->isResizeKeyboard()); + $this->assertNull($item->isSelective()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); } public function testConstructor2() @@ -73,9 +77,10 @@ public function testConstructor2() $this->assertEquals([['one', 'two']], $item->getKeyboard()); $this->assertEquals(true, $item->isOneTimeKeyboard()); - $this->assertEquals(null, $item->isResizeKeyboard()); - $this->assertEquals(null, $item->isSelective()); - $this->assertEquals(null, $item->getIsPersistent()); + $this->assertNull($item->isResizeKeyboard()); + $this->assertNull($item->isSelective()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); } public function testConstructor3() @@ -85,8 +90,9 @@ public function testConstructor3() $this->assertEquals([['one', 'two']], $item->getKeyboard()); $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(true, $item->isResizeKeyboard()); - $this->assertEquals(null, $item->isSelective()); - $this->assertEquals(null, $item->getIsPersistent()); + $this->assertNull($item->isSelective()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); } public function testConstructor4() @@ -97,7 +103,8 @@ public function testConstructor4() $this->assertEquals(true, $item->isOneTimeKeyboard()); $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(true, $item->isSelective()); - $this->assertEquals(null, $item->getIsPersistent()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); } public function testConstructor5() @@ -109,5 +116,18 @@ public function testConstructor5() $this->assertEquals(true, $item->isResizeKeyboard()); $this->assertEquals(true, $item->isSelective()); $this->assertEquals(true, $item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); + } + + public function testConstructor6() + { + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true, true, 'input_field_placeholder'); + + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(true, $item->getIsPersistent()); + $this->assertEquals('input_field_placeholder', $item->getInputFieldPlaceholder()); } } From fa8e7676570aa78e3a4f0d9cd077401e300958f3 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Thu, 11 May 2023 18:06:27 +0300 Subject: [PATCH 101/130] Fix $messageThreadId parameter BC brake --- CHANGELOG.md | 1 + src/BotApi.php | 106 ++++++++++++++++++++++++------------------------- 2 files changed, 54 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77ff2ab9..2b490b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Fix `\TelegramBot\Api\Collection\Collection::addItem` max count constraint (#333) - Fix `\TelegramBot\Api\Types\StickerSet` mapping - Fix `\TelegramBot\Api\BotApi::copyMessage` not returning `\TelegramBot\Api\Types\MessageId` +- Fix new `$messageThreadId` parameter in `\TelegramBot\Api\BotApi` methods placed not in the end of the list of parameters ### Changed - `\TelegramBot\Api\BotApi::getMyCommands` now returns instance `\TelegramBot\Api\Types\ArrayOfBotCommand` instead of `\TelegramBot\Api\Types\BotCommand` array diff --git a/src/BotApi.php b/src/BotApi.php index 8612988b..f4da380a 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -340,10 +340,10 @@ public static function jsonValidate($jsonString, $asArray) * @param string $text * @param string|null $parseMode * @param bool $disablePreview - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardHide|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param int|null $messageThreadId * * @return Message * @throws InvalidArgumentException @@ -354,10 +354,10 @@ public function sendMessage( $text, $parseMode = null, $disablePreview = false, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendMessage', [ 'chat_id' => $chatId, @@ -379,10 +379,10 @@ public function sendMessage( * @param string|null $parseMode * @param ArrayOfMessageEntity|null $captionEntities * @param bool $disableNotification - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param bool $allowSendingWithoutReply * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param int|null $messageThreadId * * @return MessageId * @throws Exception @@ -397,10 +397,10 @@ public function copyMessage( $parseMode = null, $captionEntities = null, $disableNotification = false, - $messageThreadId = null, $replyToMessageId = null, $allowSendingWithoutReply = false, - $replyMarkup = null + $replyMarkup = null, + $messageThreadId = null ) { return MessageId::fromResponse($this->call('copyMessage', [ 'chat_id' => $chatId, @@ -424,10 +424,10 @@ public function copyMessage( * @param string $phoneNumber * @param string $firstName * @param string $lastName - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param int|null $messageThreadId * * @return Message * @throws Exception @@ -437,10 +437,10 @@ public function sendContact( $phoneNumber, $firstName, $lastName = null, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendContact', [ 'chat_id' => $chatId, @@ -629,12 +629,11 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) * @param int|string $chatId * @param float $latitude * @param float $longitude - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification - * * @param null|int $livePeriod + * @param int|null $messageThreadId * * @return Message * @@ -644,11 +643,11 @@ public function sendLocation( $chatId, $latitude, $longitude, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $livePeriod = null + $livePeriod = null, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendLocation', [ 'chat_id' => $chatId, @@ -742,10 +741,10 @@ public function stopMessageLiveLocation( * @param string $title * @param string $address * @param string|null $foursquareId - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param int|null $messageThreadId * * @return Message * @throws Exception @@ -757,10 +756,10 @@ public function sendVenue( $title, $address, $foursquareId = null, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendVenue', [ 'chat_id' => $chatId, @@ -781,12 +780,12 @@ public function sendVenue( * * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $sticker - * @param string|null $messageThreadId * @param int|null $replyToMessageId * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param bool $protectContent Protects the contents of the sent message from forwarding and saving * @param bool $allowSendingWithoutReply Pass True if the message should be sent even if the specified replied-to message is not found + * @param string|null $messageThreadId * * @return Message * @throws InvalidArgumentException @@ -795,12 +794,12 @@ public function sendVenue( public function sendSticker( $chatId, $sticker, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, $protectContent = false, - $allowSendingWithoutReply = false + $allowSendingWithoutReply = false, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendSticker', [ 'chat_id' => $chatId, @@ -1013,12 +1012,12 @@ public function setStickerSetThumb($name, $userId, $thumb = null) * @param \CURLFile|string $video * @param int|null $duration * @param string|null $caption - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param bool $supportsStreaming Pass True, if the uploaded video is suitable for streaming * @param string|null $parseMode + * @param int|null $messageThreadId * * @return Message * @throws InvalidArgumentException @@ -1029,12 +1028,12 @@ public function sendVideo( $video, $duration = null, $caption = null, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, $supportsStreaming = false, - $parseMode = null + $parseMode = null, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendVideo', [ 'chat_id' => $chatId, @@ -1059,11 +1058,11 @@ public function sendVideo( * @param \CURLFile|string $animation * @param int|null $duration * @param string|null $caption - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification - * @param string|null $parseMode + * @param string|null $parseMode, + * @param int|null $messageThreadId * * @return Message * @throws InvalidArgumentException @@ -1074,11 +1073,11 @@ public function sendAnimation( $animation, $duration = null, $caption = null, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $parseMode = null + $parseMode = null, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendAnimation', [ 'chat_id' => $chatId, @@ -1105,13 +1104,13 @@ public function sendAnimation( * @param \CURLFile|string $voice * @param string $caption Voice message caption, 0-1024 characters after entities parsing * @param int|null $duration - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified * replied-to message is not found * @param string|null $parseMode + * @param int|null $messageThreadId * * @return Message * @throws InvalidArgumentException @@ -1122,12 +1121,12 @@ public function sendVoice( $voice, $caption = null, $duration = null, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, $allowSendingWithoutReply = false, - $parseMode = null + $parseMode = null, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendVoice', [ 'chat_id' => $chatId, @@ -1150,9 +1149,9 @@ public function sendVoice( * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param int $fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) * @param string $messageId Message identifier in the chat specified in from_chat_id - * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only * @param bool $protectContent Protects the contents of the forwarded message from forwarding and saving * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only * * @return Message * @throws Exception @@ -1163,9 +1162,9 @@ public function forwardMessage( $chatId, $fromChatId, $messageId, - $messageThreadId = null, $protectContent = false, - $disableNotification = false + $disableNotification = false, + $messageThreadId = null ) { return Message::fromResponse($this->call('forwardMessage', [ 'chat_id' => $chatId, @@ -1237,11 +1236,11 @@ public function sendAudio( * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $photo * @param string|null $caption - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode + * @param int|null $messageThreadId * * @return Message * @throws InvalidArgumentException @@ -1251,11 +1250,11 @@ public function sendPhoto( $chatId, $photo, $caption = null, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $parseMode = null + $parseMode = null, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendPhoto', [ 'chat_id' => $chatId, @@ -1276,11 +1275,11 @@ public function sendPhoto( * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|\CURLStringFile|string $document * @param string|null $caption - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode + * @param int|null $messageThreadId * * @return Message * @throws InvalidArgumentException @@ -1290,11 +1289,11 @@ public function sendDocument( $chatId, $document, $caption = null, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $parseMode = null + $parseMode = null, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendDocument', [ 'chat_id' => $chatId, @@ -1767,13 +1766,13 @@ public function track(Message $message, $eventName = 'Message') * @param bool $needPhoneNumber * @param bool $needEmail * @param bool $needShippingAddress - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $providerData * @param bool $sendPhoneNumberToProvider * @param bool $sendEmailToProvider + * @param int|null $messageThreadId * * @return Message * @throws Exception @@ -1796,13 +1795,13 @@ public function sendInvoice( $needPhoneNumber = false, $needEmail = false, $needShippingAddress = false, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, $providerData = null, $sendPhoneNumberToProvider = false, - $sendEmailToProvider = false + $sendEmailToProvider = false, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendInvoice', [ 'chat_id' => $chatId, @@ -1822,6 +1821,7 @@ public function sendInvoice( 'need_phone_number' => $needPhoneNumber, 'need_email' => $needEmail, 'need_shipping_address' => $needShippingAddress, + 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool)$disableNotification, @@ -2201,10 +2201,10 @@ public function getChatAdministrators($chatId) * @param \CURLFile|string $videoNote * @param int|null $duration * @param int|null $length - * @param int|null $messageThreadId * @param int|null $replyToMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification + * @param int|null $messageThreadId * * @return Message * @throws InvalidArgumentException @@ -2215,10 +2215,10 @@ public function sendVideoNote( $videoNote, $duration = null, $length = null, - $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendVideoNote', [ 'chat_id' => $chatId, @@ -2239,8 +2239,8 @@ public function sendVideoNote( * @param int|string $chatId * @param ArrayOfInputMedia $media * @param bool $disableNotification - * @param int|null $messageThreadId * @param int|null $replyToMessageId + * @param int|null $messageThreadId * * @return Message[] * @throws Exception @@ -2249,8 +2249,8 @@ public function sendMediaGroup( $chatId, $media, $disableNotification = false, - $messageThreadId = null, - $replyToMessageId = null + $replyToMessageId = null, + $messageThreadId = null ) { return ArrayOfMessages::fromResponse($this->call('sendMediaGroup', [ 'chat_id' => $chatId, @@ -2301,12 +2301,12 @@ public function setProxy($proxyString = '', $socks5 = false) * ignored for polls in quiz mode, defaults to False * @param string|null $correctOptionId 0-based identifier of the correct answer option, required for polls in quiz mode * @param bool $isClosed Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. - * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param int|null $replyToMessageId If the message is a reply, ID of the original message * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, * custom reply keyboard, instructions to remove reply * keyboard or to force a reply from the user. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only * @return Message * @throws Exception * @throws HttpException @@ -2321,10 +2321,10 @@ public function sendPoll( $allowsMultipleAnswers = false, $correctOptionId = null, $isClosed = false, - $messageThreadId = null, $disableNotification = false, $replyToMessageId = null, - $replyMarkup = null + $replyMarkup = null, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendPoll', [ 'chat_id' => $chatId, @@ -2353,13 +2353,13 @@ public function sendPoll( * “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and * values 1-64 for “🎰”. Defaults to “🎲 * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. - * @param int|null $messageThreadId * @param string|null $replyToMessageId If the message is a reply, ID of the original message * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to * message is not found, * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, * custom reply keyboard, instructions to remove reply * keyboard or to force a reply from the user. + * @param int|null $messageThreadId * * @return Message * @throws Exception @@ -2370,10 +2370,10 @@ public function sendDice( $chatId, $emoji, $disableNotification = false, - $messageThreadId = null, $replyToMessageId = null, $allowSendingWithoutReply = false, - $replyMarkup = null + $replyMarkup = null, + $messageThreadId = null ) { return Message::fromResponse($this->call('sendDice', [ 'chat_id' => $chatId, From 78eaab45844020f3ec850c925855dd135391a537 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Thu, 11 May 2023 18:18:16 +0300 Subject: [PATCH 102/130] Prepare release --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b490b2a..862e55b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file -## [Unreleased] - [YYYY-MM-DD] +## 2.4.0 - 2023-05-11 ### Added - Add `\TelegramBot\Api\Types\Venue` mapping (`foursquare_type`, `google_place_id`, `google_place_type`) diff --git a/composer.json b/composer.json index e9abe136..eb8c286b 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev" + "dev-master": "2.4-dev" } } } From 71357a0410bb12654a1136b7b8a55da9bf1fa819 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 23 May 2023 19:02:24 +0300 Subject: [PATCH 103/130] Add missing protect_content and allow_sending_without_reply parameters --- .php-cs-fixer.dist.php | 5 + .scrutinizer.yml | 36 +++-- CHANGELOG.md | 5 + src/BotApi.php | 306 ++++++++++++++++++++++++++--------------- src/HttpException.php | 6 +- src/Types/Voice.php | 8 +- 6 files changed, 231 insertions(+), 135 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2fd68b52..84419a13 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -23,5 +23,10 @@ 'no_unused_imports' => true, 'single_quote' => true, 'no_extra_blank_lines' => true, + 'cast_spaces' => true, + 'phpdoc_align' => [ + 'align' => 'left', + ], + 'binary_operator_spaces' => true, ]) ; diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 94b93c3d..2bf3b16c 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,27 +1,25 @@ filter: excluded_paths: [tests/*] -checks: - php: - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true +#checks: +# php: +# remove_extra_empty_lines: true +# remove_php_closing_tag: true +# remove_trailing_whitespace: true +# fix_use_statements: +# remove_unused: true +# preserve_multiple: false +# preserve_blanklines: true +# order_alphabetically: true +# fix_php_opening_tag: true +# fix_linefeed: true +# fix_line_ending: true +# fix_identation_4spaces: true +# fix_doc_comments: true build: dependencies: - before: - - composer remove friendsofphp/php-cs-fixer --dev --no-update - - composer remove vimeo/psalm --dev --no-update - + override: + - true tests: override: - true diff --git a/CHANGELOG.md b/CHANGELOG.md index 862e55b1..19acb159 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file +## 2.5.0 - YYYY-MM-DD + +### Added +- Add missing `protect_content` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods + ## 2.4.0 - 2023-05-11 ### Added diff --git a/src/BotApi.php b/src/BotApi.php index f4da380a..86324889 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -344,6 +344,8 @@ public static function jsonValidate($jsonString, $asArray) * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardHide|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws InvalidArgumentException @@ -357,7 +359,9 @@ public function sendMessage( $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendMessage', [ 'chat_id' => $chatId, @@ -365,9 +369,11 @@ public function sendMessage( 'message_thread_id' => $messageThreadId, 'parse_mode' => $parseMode, 'disable_web_page_preview' => $disablePreview, - 'reply_to_message_id' => (int)$replyToMessageId, + 'reply_to_message_id' => (int) $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -383,6 +389,7 @@ public function sendMessage( * @param bool $allowSendingWithoutReply * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param int|null $messageThreadId + * @param bool|null $protectContent * * @return MessageId * @throws Exception @@ -400,20 +407,22 @@ public function copyMessage( $replyToMessageId = null, $allowSendingWithoutReply = false, $replyMarkup = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null ) { return MessageId::fromResponse($this->call('copyMessage', [ 'chat_id' => $chatId, 'from_chat_id' => $fromChatId, - 'message_id' => (int)$messageId, + 'message_id' => (int) $messageId, 'caption' => $caption, 'parse_mode' => $parseMode, 'caption_entities' => $captionEntities, - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => (int)$replyToMessageId, - 'allow_sending_without_reply' => (bool)$allowSendingWithoutReply, + 'reply_to_message_id' => (int) $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'protect_content' => (bool) $protectContent, ])); } @@ -428,6 +437,8 @@ public function copyMessage( * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws Exception @@ -440,7 +451,9 @@ public function sendContact( $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendContact', [ 'chat_id' => $chatId, @@ -450,7 +463,9 @@ public function sendContact( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -493,9 +508,9 @@ public function sendChatAction($chatId, $action) public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) { return UserProfilePhotos::fromResponse($this->call('getUserProfilePhotos', [ - 'user_id' => (int)$userId, - 'offset' => (int)$offset, - 'limit' => (int)$limit, + 'user_id' => (int) $userId, + 'offset' => (int) $offset, + 'limit' => (int) $limit, ])); } @@ -509,12 +524,12 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) * @param \CURLFile|string $certificate Upload your public key certificate * so that the root certificate in use can be checked * @param string|null $ipAddress The fixed IP address which will be used to send webhook requests - * instead of the IP address resolved through DNS + * instead of the IP address resolved through DNS * @param int|null $maxConnections The maximum allowed number of simultaneous HTTPS connections to the webhook - * for update delivery, 1-100. Defaults to 40. Use lower values to limit - * the load on your bot's server, and higher values to increase your bot's throughput. + * for update delivery, 1-100. Defaults to 40. Use lower values to limit + * the load on your bot's server, and higher values to increase your bot's throughput. * @param array|null $allowedUpdates A JSON-serialized list of the update types you want your bot to receive. - * For example, specify [“message”, “edited_channel_post”, “callback_query”] + * For example, specify [“message”, “edited_channel_post”, “callback_query”] * to only receive updates of these types. See Update for a complete list of available update types. * Specify an empty list to receive all update types except chat_member (default). * If not specified, the previous setting will be used. @@ -522,8 +537,8 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) * so unwanted updates may be received for a short period of time. * @param bool|null $dropPendingUpdates Pass True to drop all pending updates * @param string|null $secretToken A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, - * 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. - * The header is useful to ensure that the request comes from a webhook set by you. + * 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. + * The header is useful to ensure that the request comes from a webhook set by you. * * @return string * @@ -634,6 +649,8 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) * @param bool $disableNotification * @param null|int $livePeriod * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @@ -647,17 +664,21 @@ public function sendLocation( $replyMarkup = null, $disableNotification = false, $livePeriod = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendLocation', [ - 'chat_id' => $chatId, - 'latitude' => $latitude, - 'longitude' => $longitude, - 'live_period' => $livePeriod, - 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, - 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'chat_id' => $chatId, + 'latitude' => $latitude, + 'longitude' => $longitude, + 'live_period' => $livePeriod, + 'message_thread_id' => $messageThreadId, + 'reply_to_message_id' => $replyToMessageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -665,11 +686,11 @@ public function sendLocation( * Use this method to edit live location messages sent by the bot or via the bot (for inline bots). * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * - * @param int|string $chatId - * @param int $messageId - * @param string $inlineMessageId - * @param float $latitude - * @param float $longitude + * @param int|string $chatId + * @param int $messageId + * @param string $inlineMessageId + * @param float $latitude + * @param float $longitude * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * * @return Message|true @@ -685,12 +706,12 @@ public function editMessageLiveLocation( $replyMarkup = null ) { $response = $this->call('editMessageLiveLocation', [ - 'chat_id' => $chatId, - 'message_id' => $messageId, + 'chat_id' => $chatId, + 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, - 'latitude' => $latitude, - 'longitude' => $longitude, - 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'latitude' => $latitude, + 'longitude' => $longitude, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), ]); if ($response === true) { return true; @@ -704,9 +725,9 @@ public function editMessageLiveLocation( * live_period expires. * On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned. * - * @param int|string $chatId - * @param int $messageId - * @param string $inlineMessageId + * @param int|string $chatId + * @param int $messageId + * @param string $inlineMessageId * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * * @return Message|true @@ -720,10 +741,10 @@ public function stopMessageLiveLocation( $replyMarkup = null ) { $response = $this->call('stopMessageLiveLocation', [ - 'chat_id' => $chatId, - 'message_id' => $messageId, + 'chat_id' => $chatId, + 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, - 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), ]); if ($response === true) { return true; @@ -745,6 +766,8 @@ public function stopMessageLiveLocation( * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws Exception @@ -759,7 +782,9 @@ public function sendVenue( $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendVenue', [ 'chat_id' => $chatId, @@ -771,7 +796,9 @@ public function sendVenue( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -807,9 +834,9 @@ public function sendSticker( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, - 'protect_content' => (bool)$protectContent, - 'allow_sending_without_reply' => (bool)$allowSendingWithoutReply, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -828,7 +855,7 @@ public function getStickerSet($name) /** * @param array[] $customEmojiIds List of custom emoji identifiers. - * At most 200 custom emoji identifiers can be specified. + * At most 200 custom emoji identifiers can be specified. * @return StickerSet * @throws InvalidArgumentException * @throws Exception @@ -1018,6 +1045,8 @@ public function setStickerSetThumb($name, $userId, $thumb = null) * @param bool $supportsStreaming Pass True, if the uploaded video is suitable for streaming * @param string|null $parseMode * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws InvalidArgumentException @@ -1033,7 +1062,9 @@ public function sendVideo( $disableNotification = false, $supportsStreaming = false, $parseMode = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendVideo', [ 'chat_id' => $chatId, @@ -1043,9 +1074,11 @@ public function sendVideo( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, - 'supports_streaming' => (bool)$supportsStreaming, - 'parse_mode' => $parseMode + 'disable_notification' => (bool) $disableNotification, + 'supports_streaming' => (bool) $supportsStreaming, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -1063,6 +1096,8 @@ public function sendVideo( * @param bool $disableNotification * @param string|null $parseMode, * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws InvalidArgumentException @@ -1077,7 +1112,9 @@ public function sendAnimation( $replyMarkup = null, $disableNotification = false, $parseMode = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendAnimation', [ 'chat_id' => $chatId, @@ -1087,8 +1124,10 @@ public function sendAnimation( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, - 'parse_mode' => $parseMode + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -1108,9 +1147,10 @@ public function sendAnimation( * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified - * replied-to message is not found + * replied-to message is not found * @param string|null $parseMode * @param int|null $messageThreadId + * @param bool|null $protectContent * * @return Message * @throws InvalidArgumentException @@ -1126,7 +1166,8 @@ public function sendVoice( $disableNotification = false, $allowSendingWithoutReply = false, $parseMode = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null ) { return Message::fromResponse($this->call('sendVoice', [ 'chat_id' => $chatId, @@ -1136,9 +1177,10 @@ public function sendVoice( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, 'allow_sending_without_reply' => $allowSendingWithoutReply, - 'parse_mode' => $parseMode + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, ])); } @@ -1172,7 +1214,7 @@ public function forwardMessage( 'message_id' => $messageId, 'message_thread_id' => $messageThreadId, 'protect_content' => $protectContent, - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, ])); } @@ -1197,6 +1239,8 @@ public function forwardMessage( * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws InvalidArgumentException @@ -1215,7 +1259,9 @@ public function sendAudio( $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $parseMode = null + $parseMode = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendAudio', [ 'chat_id' => $chatId, @@ -1225,8 +1271,10 @@ public function sendAudio( 'title' => $title, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, - 'parse_mode' => $parseMode + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -1241,6 +1289,8 @@ public function sendAudio( * @param bool $disableNotification * @param string|null $parseMode * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws InvalidArgumentException @@ -1254,7 +1304,9 @@ public function sendPhoto( $replyMarkup = null, $disableNotification = false, $parseMode = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendPhoto', [ 'chat_id' => $chatId, @@ -1263,8 +1315,10 @@ public function sendPhoto( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, - 'parse_mode' => $parseMode + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -1280,6 +1334,8 @@ public function sendPhoto( * @param bool $disableNotification * @param string|null $parseMode * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws InvalidArgumentException @@ -1293,7 +1349,9 @@ public function sendDocument( $replyMarkup = null, $disableNotification = false, $parseMode = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendDocument', [ 'chat_id' => $chatId, @@ -1302,8 +1360,10 @@ public function sendDocument( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, - 'parse_mode' => $parseMode + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -1406,7 +1466,7 @@ function ($item) { * The bot must be an administrator in the group for this to work. Returns True on success. * * @param int|string $chatId Unique identifier for the target group - * or username of the target supergroup (in the format @supergroupusername) + * or username of the target supergroup (in the format @supergroupusername) * @param int $userId Unique identifier of the target user * @param null|int $untilDate Date when the user will be unbanned, unix time. * If user is banned for more than 366 days or less than 30 seconds from the current time @@ -1430,7 +1490,7 @@ public function kickChatMember($chatId, $userId, $untilDate = null) * The bot must be an administrator in the group for this to work. Returns True on success. * * @param int|string $chatId Unique identifier for the target group - * or username of the target supergroup (in the format @supergroupusername) + * or username of the target supergroup (in the format @supergroupusername) * @param int $userId Unique identifier of the target user * * @return bool @@ -1462,7 +1522,7 @@ public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = return $this->call('answerCallbackQuery', [ 'callback_query_id' => $callbackQueryId, 'text' => $text, - 'show_alert' => (bool)$showAlert, + 'show_alert' => (bool) $showAlert, 'url' => $url, 'cache_time' => $cacheTime ]); @@ -1773,6 +1833,8 @@ public function track(Message $message, $eventName = 'Message') * @param bool $sendPhoneNumberToProvider * @param bool $sendEmailToProvider * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws Exception @@ -1801,7 +1863,9 @@ public function sendInvoice( $providerData = null, $sendPhoneNumberToProvider = false, $sendEmailToProvider = false, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendInvoice', [ 'chat_id' => $chatId, @@ -1824,10 +1888,12 @@ public function sendInvoice( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, 'provider_data' => $providerData, - 'send_phone_number_to_provider' => (bool)$sendPhoneNumberToProvider, - 'send_email_to_provider' => (bool)$sendEmailToProvider + 'send_phone_number_to_provider' => (bool) $sendPhoneNumberToProvider, + 'send_email_to_provider' => (bool) $sendEmailToProvider, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -1848,7 +1914,7 @@ public function answerShippingQuery($shippingQueryId, $ok = true, $shippingOptio { return $this->call('answerShippingQuery', [ 'shipping_query_id' => $shippingQueryId, - 'ok' => (bool)$ok, + 'ok' => (bool) $ok, 'shipping_options' => json_encode($shippingOptions), 'error_message' => $errorMessage ]); @@ -1869,7 +1935,7 @@ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMe { return $this->call('answerPreCheckoutQuery', [ 'pre_checkout_query_id' => $preCheckoutQueryId, - 'ok' => (bool)$ok, + 'ok' => (bool) $ok, 'error_message' => $errorMessage ]); } @@ -1880,11 +1946,11 @@ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMe * Pass True for all boolean parameters to lift restrictions from a user. * * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup - * (in the format @supergroupusername) + * (in the format @supergroupusername) * @param int $userId Unique identifier of the target user * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time. - * If user is restricted for more than 366 days or less than 30 seconds from the current time, - * they are considered to be restricted forever + * If user is restricted for more than 366 days or less than 30 seconds from the current time, + * they are considered to be restricted forever * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos, * video notes and voice notes, implies can_send_messages @@ -1922,7 +1988,7 @@ public function restrictChatMember( * Pass False for all boolean parameters to demote a user. * * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup - * (in the format @supergroupusername) + * (in the format @supergroupusername) * @param int $userId Unique identifier of the target user * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only @@ -2048,7 +2114,7 @@ public function setChatTitle($chatId, $title) * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * @param string|null $description New chat description, 0-255 characters * * @return bool @@ -2067,7 +2133,7 @@ public function setChatDescription($chatId, $description = null) * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * @param int $messageId Identifier of a message to pin * @param bool $disableNotification * @@ -2088,7 +2154,7 @@ public function pinChatMessage($chatId, $messageId, $disableNotification = false * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * * @return bool * @throws Exception @@ -2105,7 +2171,7 @@ public function unpinChatMessage($chatId) * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * * @return Chat * @throws Exception @@ -2121,7 +2187,7 @@ public function getChat($chatId) * Use this method to get information about a member of a chat. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * @param int $userId * * @return ChatMember @@ -2139,7 +2205,7 @@ public function getChatMember($chatId, $userId) * Use this method for your bot to leave a group, supergroup or channel. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * * @return bool * @throws Exception @@ -2155,7 +2221,7 @@ public function leaveChat($chatId) * Use this method to get the number of members in a chat. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * * @return int * @throws Exception @@ -2174,7 +2240,7 @@ public function getChatMembersCount($chatId) * Use this method to get a list of administrators in a chat. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * * @return ChatMember[] * @throws InvalidArgumentException @@ -2205,6 +2271,8 @@ public function getChatAdministrators($chatId) * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup * @param bool $disableNotification * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message * @throws InvalidArgumentException @@ -2218,7 +2286,9 @@ public function sendVideoNote( $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendVideoNote', [ 'chat_id' => $chatId, @@ -2228,7 +2298,9 @@ public function sendVideoNote( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -2241,6 +2313,8 @@ public function sendVideoNote( * @param bool $disableNotification * @param int|null $replyToMessageId * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply * * @return Message[] * @throws Exception @@ -2250,14 +2324,18 @@ public function sendMediaGroup( $media, $disableNotification = false, $replyToMessageId = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return ArrayOfMessages::fromResponse($this->call('sendMediaGroup', [ 'chat_id' => $chatId, 'media' => $media->toJson(), 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => (int)$replyToMessageId, - 'disable_notification' => (bool)$disableNotification + 'reply_to_message_id' => (int) $replyToMessageId, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -2292,21 +2370,24 @@ public function setProxy($proxyString = '', $socks5 = false) * On success, the sent \TelegramBot\Api\Types\Message is returned. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * @param string $question Poll question, 1-255 characters * @param array $options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each * @param bool $isAnonymous True, if the poll needs to be anonymous, defaults to True * @param string|null $type Poll type, “quiz” or “regular”, defaults to “regular” * @param bool $allowsMultipleAnswers True, if the poll allows multiple answers, - * ignored for polls in quiz mode, defaults to False + * ignored for polls in quiz mode, defaults to False * @param string|null $correctOptionId 0-based identifier of the correct answer option, required for polls in quiz mode * @param bool $isClosed Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param int|null $replyToMessageId If the message is a reply, ID of the original message * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, - * custom reply keyboard, instructions to remove reply - * keyboard or to force a reply from the user. + * custom reply keyboard, instructions to remove reply + * keyboard or to force a reply from the user. * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * * @return Message * @throws Exception * @throws HttpException @@ -2324,7 +2405,9 @@ public function sendPoll( $disableNotification = false, $replyToMessageId = null, $replyMarkup = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null ) { return Message::fromResponse($this->call('sendPoll', [ 'chat_id' => $chatId, @@ -2339,6 +2422,8 @@ public function sendPoll( 'message_thread_id' => $messageThreadId, 'reply_to_message_id' => (int) $replyToMessageId, 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), + 'protect_content' => (bool) $protectContent, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, ])); } @@ -2348,18 +2433,19 @@ public function sendPoll( * But it's awkward, and we decided to help it change. One dice at a time!) * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * @param string $emoji Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, - * “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and - * values 1-64 for “🎰”. Defaults to “🎲 + * “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and + * values 1-64 for “🎰”. Defaults to “🎲 * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param string|null $replyToMessageId If the message is a reply, ID of the original message * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to - * message is not found, + * message is not found, * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, - * custom reply keyboard, instructions to remove reply - * keyboard or to force a reply from the user. + * custom reply keyboard, instructions to remove reply + * keyboard or to force a reply from the user. * @param int|null $messageThreadId + * @param bool|null $protectContent * * @return Message * @throws Exception @@ -2373,7 +2459,8 @@ public function sendDice( $replyToMessageId = null, $allowSendingWithoutReply = false, $replyMarkup = null, - $messageThreadId = null + $messageThreadId = null, + $protectContent = null ) { return Message::fromResponse($this->call('sendDice', [ 'chat_id' => $chatId, @@ -2383,6 +2470,7 @@ public function sendDice( 'reply_to_message_id' => (int) $replyToMessageId, 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), + 'protect_content' => (bool) $protectContent, ])); } diff --git a/src/HttpException.php b/src/HttpException.php index 9eeed332..4b826c64 100644 --- a/src/HttpException.php +++ b/src/HttpException.php @@ -18,10 +18,10 @@ class HttpException extends Exception /** * HttpException constructor. * - * @param string $message [optional] The Exception message to throw. - * @param int $code [optional] The Exception code. + * @param string $message [optional] The Exception message to throw. + * @param int $code [optional] The Exception code. * @param Exception $previous [optional] The previous throwable used for the exception chaining. - * @param array $parameters [optional] Array of parameters returned from API. + * @param array $parameters [optional] Array of parameters returned from API. */ public function __construct($message = '', $code = 0, Exception $previous = null, $parameters = []) { diff --git a/src/Types/Voice.php b/src/Types/Voice.php index 005303c6..8d4e4cba 100644 --- a/src/Types/Voice.php +++ b/src/Types/Voice.php @@ -27,11 +27,11 @@ class Voice extends BaseType implements TypeInterface * @var array */ protected static $map = [ - 'file_id' => true, + 'file_id' => true, 'file_unique_id' => true, - 'duration' => true, - 'mime_type' => true, - 'file_size' => true, + 'duration' => true, + 'mime_type' => true, + 'file_size' => true, ]; /** From 820d7330ff819a3b8673d1a318ad0fd78be98f4e Mon Sep 17 00:00:00 2001 From: BoShurik Date: Thu, 8 Jun 2023 13:02:15 +0300 Subject: [PATCH 104/130] Fix phpDoc for $replyMarkup parameters --- CHANGELOG.md | 4 +++ src/BotApi.php | 51 ++++++++++++++++----------------- src/Client.php | 3 +- src/Types/ReplyKeyboardHide.php | 2 ++ 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19acb159..b18aa77d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file ### Added - Add missing `protect_content` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods +- Add missing phpDoc for `$replyMarkup` parameters + +### Deprecated +- Deprecate `\TelegramBot\Api\Types\ReplyKeyboardHide` class ## 2.4.0 - 2023-05-11 diff --git a/src/BotApi.php b/src/BotApi.php index 86324889..53922bf6 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -22,7 +22,6 @@ use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\MessageId; use TelegramBot\Api\Types\Poll; -use TelegramBot\Api\Types\ReplyKeyboardHide; use TelegramBot\Api\Types\ReplyKeyboardMarkup; use TelegramBot\Api\Types\ReplyKeyboardRemove; use TelegramBot\Api\Types\SentWebAppMessage; @@ -341,7 +340,7 @@ public static function jsonValidate($jsonString, $asArray) * @param string|null $parseMode * @param bool $disablePreview * @param int|null $replyToMessageId - * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardHide|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param int|null $messageThreadId * @param bool|null $protectContent @@ -387,7 +386,7 @@ public function sendMessage( * @param bool $disableNotification * @param int|null $replyToMessageId * @param bool $allowSendingWithoutReply - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param int|null $messageThreadId * @param bool|null $protectContent * @@ -434,7 +433,7 @@ public function copyMessage( * @param string $firstName * @param string $lastName * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param int|null $messageThreadId * @param bool|null $protectContent @@ -645,7 +644,7 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) * @param float $latitude * @param float $longitude * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param null|int $livePeriod * @param int|null $messageThreadId @@ -691,7 +690,7 @@ public function sendLocation( * @param string $inlineMessageId * @param float $latitude * @param float $longitude - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * * @return Message|true * @@ -728,7 +727,7 @@ public function editMessageLiveLocation( * @param int|string $chatId * @param int $messageId * @param string $inlineMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * * @return Message|true * @@ -763,7 +762,7 @@ public function stopMessageLiveLocation( * @param string $address * @param string|null $foursquareId * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param int|null $messageThreadId * @param bool|null $protectContent @@ -1040,7 +1039,7 @@ public function setStickerSetThumb($name, $userId, $thumb = null) * @param int|null $duration * @param string|null $caption * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param bool $supportsStreaming Pass True, if the uploaded video is suitable for streaming * @param string|null $parseMode @@ -1092,7 +1091,7 @@ public function sendVideo( * @param int|null $duration * @param string|null $caption * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode, * @param int|null $messageThreadId @@ -1144,7 +1143,7 @@ public function sendAnimation( * @param string $caption Voice message caption, 0-1024 characters after entities parsing * @param int|null $duration * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified * replied-to message is not found @@ -1236,7 +1235,7 @@ public function forwardMessage( * @param string|null $performer * @param string|null $title * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode * @param bool|null $protectContent @@ -1285,7 +1284,7 @@ public function sendAudio( * @param \CURLFile|string $photo * @param string|null $caption * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode * @param int|null $messageThreadId @@ -1330,7 +1329,7 @@ public function sendPhoto( * @param \CURLFile|\CURLStringFile|string $document * @param string|null $caption * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param string|null $parseMode * @param int|null $messageThreadId @@ -1579,7 +1578,7 @@ public function getMyCommands() * @param string $inlineMessageId * @param string|null $parseMode * @param bool $disablePreview - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|null $replyMarkup * * @return Message|true * @throws Exception @@ -1616,7 +1615,7 @@ public function editMessageText( * @param int|string $chatId * @param int $messageId * @param string|null $caption - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|null $replyMarkup * @param string $inlineMessageId * @param string|null $parseMode * @@ -1693,7 +1692,7 @@ public function editMessageMedia( * * @param int|string $chatId * @param int $messageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|null $replyMarkup * @param string $inlineMessageId * * @return Message|true @@ -1827,7 +1826,7 @@ public function track(Message $message, $eventName = 'Message') * @param bool $needEmail * @param bool $needShippingAddress * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param string|null $providerData * @param bool $sendPhoneNumberToProvider @@ -2268,7 +2267,7 @@ public function getChatAdministrators($chatId) * @param int|null $duration * @param int|null $length * @param int|null $replyToMessageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification * @param int|null $messageThreadId * @param bool|null $protectContent @@ -2381,9 +2380,9 @@ public function setProxy($proxyString = '', $socks5 = false) * @param bool $isClosed Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. * @param int|null $replyToMessageId If the message is a reply, ID of the original message - * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, - * custom reply keyboard, instructions to remove reply - * keyboard or to force a reply from the user. + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, + * custom reply keyboard, instructions to remove reply + * keyboard or to force a reply from the user. * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply @@ -2441,9 +2440,9 @@ public function sendPoll( * @param string|null $replyToMessageId If the message is a reply, ID of the original message * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to * message is not found, - * @param object|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, - * custom reply keyboard, instructions to remove reply - * keyboard or to force a reply from the user. + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, + * custom reply keyboard, instructions to remove reply + * keyboard or to force a reply from the user. * @param int|null $messageThreadId * @param bool|null $protectContent * @@ -2480,7 +2479,7 @@ public function sendDice( * * @param int|string $chatId * @param int $messageId - * @param ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|null $replyMarkup + * @param InlineKeyboardMarkup|null $replyMarkup * @return Poll * @throws InvalidArgumentException * @throws Exception diff --git a/src/Client.php b/src/Client.php index 3b08c184..33322d86 100644 --- a/src/Client.php +++ b/src/Client.php @@ -10,14 +10,13 @@ use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; use TelegramBot\Api\Types\ReplyKeyboardRemove; use TelegramBot\Api\Types\ForceReply; -use TelegramBot\Api\Types\ReplyKeyboardHide; use TelegramBot\Api\Types\ReplyKeyboardMarkup; /** * Class Client * * @package TelegramBot\Api - * @method Message editMessageText(string $chatId, int $messageId, string $text, string $parseMode = null, bool $disablePreview = false, ReplyKeyboardMarkup|ReplyKeyboardHide|ForceReply|ReplyKeyboardRemove|InlineKeyboardMarkup|null $replyMarkup = null, string $inlineMessageId = null) + * @method Message editMessageText(string $chatId, int $messageId, string $text, string $parseMode = null, bool $disablePreview = false, ReplyKeyboardMarkup|ForceReply|ReplyKeyboardRemove|InlineKeyboardMarkup|null $replyMarkup = null, string $inlineMessageId = null) */ class Client { diff --git a/src/Types/ReplyKeyboardHide.php b/src/Types/ReplyKeyboardHide.php index 7952605f..6dad3664 100644 --- a/src/Types/ReplyKeyboardHide.php +++ b/src/Types/ReplyKeyboardHide.php @@ -5,6 +5,8 @@ use TelegramBot\Api\BaseType; /** + * @deprecated Use ReplyKeyboardRemove + * * Class ReplyKeyboardHide * Upon receiving a message with this object, Telegram clients will hide the current custom keyboard * and display the default letter-keyboard. By default, custom keyboards are displayed From e538b5537980d8a1e28c3143d4059c254ba16660 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Mon, 29 May 2023 18:34:34 +0300 Subject: [PATCH 105/130] Support `attach://` and rename `thumb` to `thumbnail` --- CHANGELOG.md | 7 +- src/BotApi.php | 83 +++++++++++++---- src/Types/Animation.php | 32 ++++++- src/Types/Document.php | 32 ++++++- src/Types/Inline/QueryResult/Article.php | 108 +++++++++++++++++----- src/Types/Inline/QueryResult/Contact.php | 108 +++++++++++++++++----- src/Types/Inline/QueryResult/Gif.php | 38 ++++++-- src/Types/Inline/QueryResult/Location.php | 108 +++++++++++++++++----- src/Types/Inline/QueryResult/Mpeg4Gif.php | 38 ++++++-- src/Types/Inline/QueryResult/Photo.php | 38 ++++++-- src/Types/Inline/QueryResult/Venue.php | 108 +++++++++++++++++----- src/Types/Inline/QueryResult/Video.php | 42 +++++++-- src/Types/Sticker.php | 32 ++++++- src/Types/StickerSet.php | 30 +++++- src/Types/Video.php | 38 ++++++-- src/Types/VideoNote.php | 30 +++++- tests/Types/AnimationTest.php | 6 +- tests/Types/DocumentTest.php | 8 +- tests/Types/StickerSetTest.php | 6 +- tests/Types/StickerTest.php | 4 +- tests/Types/VideoNoteTest.php | 6 +- tests/Types/VideoTest.php | 16 ++-- 22 files changed, 727 insertions(+), 191 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b18aa77d..cf5fb8c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,14 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file ### Added - Add missing `protect_content` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods +- Add support `attach://` in `\TelegramBot\Api\BotApi` methods `sendMediaGroup`, `createNewStickerSet`, `addStickerToSet`, `editMessageMedia` +- Rename `thumb` to `thumbnail` parameter in `Animation`, `Document`, `Sticker`, `StickerSet`, `Video`, `VideoNote` types +- Rename `thumb_*` to `thumbnail_*` parameter in `Inline/QueryResult` types - Add missing phpDoc for `$replyMarkup` parameters - +- ### Deprecated +- Deprecate using `thumb*` methods in `\TelegramBot\Api\BotApi` +- Deprecate method `\TelegramBot\Api\BotApi::setStickerSetThumb`. Use `\TelegramBot\Api\BotApi::setStickerSetThumbnail` instead - Deprecate `\TelegramBot\Api\Types\ReplyKeyboardHide` class ## 2.4.0 - 2023-05-11 diff --git a/src/BotApi.php b/src/BotApi.php index 53922bf6..c1c72676 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -914,6 +914,7 @@ public function uploadStickerFile($userId, $pngSticker) * @param string $stickerType Sticker type, one of “png”, “tgs”, or “webp” * @param string $emojis One or more emoji corresponding to the sticker * @param MaskPosition|null $maskPosition A JSON-serialized object for position where the mask should be placed on faces + * @param array $attachments Attachments to use in attach:// * * @throws InvalidArgumentException * @throws Exception @@ -931,7 +932,8 @@ public function createNewStickerSet( $tgsSticker = null, $webmSticker = null, $stickerType = null, - $maskPosition = null + $maskPosition = null, + $attachments = [] ) { return $this->call('createNewStickerSet', [ 'user_id' => $userId, @@ -943,7 +945,7 @@ public function createNewStickerSet( 'sticker_type' => $stickerType, 'emojis' => $emojis, 'mask_position' => is_null($maskPosition) ? $maskPosition : $maskPosition->toJson(), - ]); + ] + $attachments); } /** @@ -960,6 +962,8 @@ public function createNewStickerSet( * @param string|null $tgsSticker * @param string|null $webmSticker * @param MaskPosition|null $maskPosition + * @param array $attachments Attachments to use in attach:// + * * @return bool * @throws Exception * @throws HttpException @@ -972,7 +976,8 @@ public function addStickerToSet( $pngSticker, $tgsSticker = null, $webmSticker = null, - $maskPosition = null + $maskPosition = null, + $attachments = [] ) { return $this->call('addStickerToSet', [ 'user_id' => $userId, @@ -982,7 +987,7 @@ public function addStickerToSet( 'webm_sticker' => $webmSticker, 'emojis' => $emojis, 'mask_position' => is_null($maskPosition) ? $maskPosition : $maskPosition->toJson(), - ]); + ] + $attachments); } /** @@ -1011,24 +1016,46 @@ public function setStickerPositionInSet($sticker, $position) * * @param string $name Sticker set name * @param string $userId User identifier of sticker set owner - * @param File|null $thumb A PNG image with the thumbnail, - * must be up to 128 kilobytes in size and have width and height exactly 100px, - * or a TGS animation with the thumbnail up to 32 kilobytes in size + * @param File|null $thumbnail A PNG image with the thumbnail, + * must be up to 128 kilobytes in size and have width and height exactly 100px, + * or a TGS animation with the thumbnail up to 32 kilobytes in size * * @return bool * * @throws InvalidArgumentException * @throws Exception */ - public function setStickerSetThumb($name, $userId, $thumb = null) + public function setStickerSetThumbnail($name, $userId, $thumbnail = null) { return $this->call('setStickerSetThumb', [ 'name' => $name, 'user_id' => $userId, - 'thumb' => $thumb, + 'thumbnail' => $thumbnail, ]); } + /** + * @deprecated Use setStickerSetThumbnail + * + * Use this method to delete a sticker from a set created by the bot. + * Returns True on success. + * + * @param string $name Sticker set name + * @param string $userId User identifier of sticker set owner + * @param File|null $thumb A PNG image with the thumbnail, + * must be up to 128 kilobytes in size and have width and height exactly 100px, + * or a TGS animation with the thumbnail up to 32 kilobytes in size + * + * @return bool + * + * @throws InvalidArgumentException + * @throws Exception + */ + public function setStickerSetThumb($name, $userId, $thumb = null) + { + return $this->setStickerSetThumbnail($name, $userId, $thumb); + } + /** * Use this method to send video files, * Telegram clients support mp4 videos (other formats may be sent as Document). @@ -1046,6 +1073,7 @@ public function setStickerSetThumb($name, $userId, $thumb = null) * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail * * @return Message * @throws InvalidArgumentException @@ -1063,7 +1091,8 @@ public function sendVideo( $parseMode = null, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $thumbnail = null ) { return Message::fromResponse($this->call('sendVideo', [ 'chat_id' => $chatId, @@ -1078,6 +1107,7 @@ public function sendVideo( 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'thumbnail' => $thumbnail, ])); } @@ -1097,6 +1127,7 @@ public function sendVideo( * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail * * @return Message * @throws InvalidArgumentException @@ -1113,7 +1144,8 @@ public function sendAnimation( $parseMode = null, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $thumbnail = null ) { return Message::fromResponse($this->call('sendAnimation', [ 'chat_id' => $chatId, @@ -1127,6 +1159,7 @@ public function sendAnimation( 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'thumbnail' => $thumbnail, ])); } @@ -1240,6 +1273,7 @@ public function forwardMessage( * @param string|null $parseMode * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail * * @return Message * @throws InvalidArgumentException @@ -1260,7 +1294,8 @@ public function sendAudio( $disableNotification = false, $parseMode = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $thumbnail = null ) { return Message::fromResponse($this->call('sendAudio', [ 'chat_id' => $chatId, @@ -1274,6 +1309,7 @@ public function sendAudio( 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'thumbnail' => $thumbnail, ])); } @@ -1335,6 +1371,7 @@ public function sendPhoto( * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail * * @return Message * @throws InvalidArgumentException @@ -1350,7 +1387,8 @@ public function sendDocument( $parseMode = null, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $thumbnail = null ) { return Message::fromResponse($this->call('sendDocument', [ 'chat_id' => $chatId, @@ -1363,6 +1401,7 @@ public function sendDocument( 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'thumbnail' => $thumbnail, ])); } @@ -1659,6 +1698,8 @@ public function editMessageCaption( * @param InputMedia $media * @param string|null $inlineMessageId * @param InlineKeyboardMarkup|null $replyMarkup + * @param array $attachments Attachments to use in attach:// + * * @return Message|true * * @throws Exception @@ -1670,7 +1711,8 @@ public function editMessageMedia( $messageId, InputMedia $media, $inlineMessageId = null, - $replyMarkup = null + $replyMarkup = null, + $attachments = [] ) { $response = $this->call('editMessageMedia', [ 'chat_id' => $chatId, @@ -1678,7 +1720,7 @@ public function editMessageMedia( 'inline_message_id' => $inlineMessageId, 'media' => $media->toJson(), 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ]); + ] + $attachments); if ($response === true) { return true; } @@ -2272,6 +2314,7 @@ public function getChatAdministrators($chatId) * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail * * @return Message * @throws InvalidArgumentException @@ -2287,7 +2330,8 @@ public function sendVideoNote( $disableNotification = false, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $thumbnail = null ) { return Message::fromResponse($this->call('sendVideoNote', [ 'chat_id' => $chatId, @@ -2300,6 +2344,7 @@ public function sendVideoNote( 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'thumbnail' => $thumbnail, ])); } @@ -2314,6 +2359,7 @@ public function sendVideoNote( * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param array $attachments Attachments to use in attach:// * * @return Message[] * @throws Exception @@ -2325,7 +2371,8 @@ public function sendMediaGroup( $replyToMessageId = null, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $attachments = [] ) { return ArrayOfMessages::fromResponse($this->call('sendMediaGroup', [ 'chat_id' => $chatId, @@ -2335,7 +2382,7 @@ public function sendMediaGroup( 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, - ])); + ] + $attachments)); } /** diff --git a/src/Types/Animation.php b/src/Types/Animation.php index b412cc95..c33deeba 100644 --- a/src/Types/Animation.php +++ b/src/Types/Animation.php @@ -32,7 +32,7 @@ class Animation extends BaseType implements TypeInterface 'width' => true, 'height' => true, 'duration' => true, - 'thumb' => PhotoSize::class, + 'thumbnail' => PhotoSize::class, 'file_name' => true, 'mime_type' => true, 'file_size' => true @@ -78,7 +78,7 @@ class Animation extends BaseType implements TypeInterface * * @var PhotoSize */ - protected $thumb; + protected $thumbnail; /** * Optional. Animation thumbnail as defined by sender @@ -221,18 +221,40 @@ public function setMimeType($mimeType) /** * @return PhotoSize */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * @return void + */ + public function setThumbnail(PhotoSize $thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null + */ public function getThumb() { - return $this->thumb; + return $this->getThumbnail(); } /** + * @deprecated use setThumbnail method + * * @param PhotoSize $thumb + * * @return void */ - public function setThumb(PhotoSize $thumb) + public function setThumb($thumb) { - $this->thumb = $thumb; + $this->setThumbnail($thumb); } /** diff --git a/src/Types/Document.php b/src/Types/Document.php index a60f6f5b..e7b951bd 100644 --- a/src/Types/Document.php +++ b/src/Types/Document.php @@ -23,7 +23,7 @@ class Document extends BaseType implements TypeInterface protected static $map = [ 'file_id' => true, 'file_unique_id' => true, - 'thumb' => PhotoSize::class, + 'thumbnail' => PhotoSize::class, 'file_name' => true, 'mime_type' => true, 'file_size' => true @@ -48,7 +48,7 @@ class Document extends BaseType implements TypeInterface * * @var PhotoSize */ - protected $thumb; + protected $thumbnail; /** * Optional. Original filename as defined by sender @@ -154,18 +154,40 @@ public function setMimeType($mimeType) /** * @return PhotoSize */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * @return void + */ + public function setThumbnail(PhotoSize $thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null + */ public function getThumb() { - return $this->thumb; + return $this->getThumbnail(); } /** + * @deprecated use setThumbnail method + * * @param PhotoSize $thumb + * * @return void */ - public function setThumb(PhotoSize $thumb) + public function setThumb($thumb) { - $this->thumb = $thumb; + $this->setThumbnail($thumb); } /** diff --git a/src/Types/Inline/QueryResult/Article.php b/src/Types/Inline/QueryResult/Article.php index 411829da..8d48c0df 100644 --- a/src/Types/Inline/QueryResult/Article.php +++ b/src/Types/Inline/QueryResult/Article.php @@ -34,9 +34,9 @@ class Article extends AbstractInlineQueryResult 'url' => true, 'hide_url' => true, 'description' => true, - 'thumb_url' => true, - 'thumb_width' => true, - 'thumb_height' => true, + 'thumbnail_url' => true, + 'thumbnail_width' => true, + 'thumbnail_height' => true, ]; /** @@ -72,21 +72,21 @@ class Article extends AbstractInlineQueryResult * * @var string|null */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Thumbnail width * * @var int|null */ - protected $thumbWidth; + protected $thumbnailWidth; /** * Optional. Thumbnail height * * @var int|null */ - protected $thumbHeight; + protected $thumbnailHeight; /** * InlineQueryResultArticle constructor. @@ -94,9 +94,9 @@ class Article extends AbstractInlineQueryResult * @param string $id * @param string $title * @param string|null $description - * @param string|null $thumbUrl - * @param int|null $thumbWidth - * @param int|null $thumbHeight + * @param string|null $thumbnailUrl + * @param int|null $thumbnailWidth + * @param int|null $thumbnailHeight * @param InputMessageContent $inputMessageContent * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup */ @@ -104,18 +104,18 @@ public function __construct( $id, $title, $description = null, - $thumbUrl = null, - $thumbWidth = null, - $thumbHeight = null, + $thumbnailUrl = null, + $thumbnailWidth = null, + $thumbnailHeight = null, $inputMessageContent = null, $inlineKeyboardMarkup = null ) { parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->description = $description; - $this->thumbUrl = $thumbUrl; - $this->thumbWidth = $thumbWidth; - $this->thumbHeight = $thumbHeight; + $this->thumbnailUrl = $thumbnailUrl; + $this->thumbnailWidth = $thumbnailWidth; + $this->thumbnailHeight = $thumbnailHeight; } /** @@ -175,54 +175,120 @@ public function setDescription($description) /** * @return string|null */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string|null $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string|null + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string|null $thumbUrl * * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); + } + + /** + * @return int|null + */ + public function getThumbnailWidth() + { + return $this->thumbnailWidth; } /** + * @param int|null $thumbnailWidth + * + * @return void + */ + public function setThumbnailWidth($thumbnailWidth) + { + $this->thumbnailWidth = $thumbnailWidth; + } + + /** + * @deprecated Use getThumbnailWidth + * * @return int|null */ public function getThumbWidth() { - return $this->thumbWidth; + return $this->getThumbnailWidth(); } /** + * @deprecated Use setThumbnailWidth + * * @param int|null $thumbWidth * * @return void */ public function setThumbWidth($thumbWidth) { - $this->thumbWidth = $thumbWidth; + $this->setThumbnailWidth($thumbWidth); + } + + /** + * @return int|null + */ + public function getThumbnailHeight() + { + return $this->thumbnailHeight; + } + + /** + * @param int|null $thumbnailHeight + * + * @return void + */ + public function setThumbnailHeight($thumbnailHeight) + { + $this->thumbnailHeight = $thumbnailHeight; } /** + * @deprecated Use getThumbnailHeight + * * @return int|null */ public function getThumbHeight() { - return $this->thumbHeight; + return $this->getThumbnailHeight(); } /** + * @deprecated Use setThumbnailWidth + * * @param int|null $thumbHeight * * @return void */ public function setThumbHeight($thumbHeight) { - $this->thumbHeight = $thumbHeight; + $this->setThumbnailHeight($thumbHeight); } } diff --git a/src/Types/Inline/QueryResult/Contact.php b/src/Types/Inline/QueryResult/Contact.php index f27de9c0..8e0f4347 100644 --- a/src/Types/Inline/QueryResult/Contact.php +++ b/src/Types/Inline/QueryResult/Contact.php @@ -33,9 +33,9 @@ class Contact extends AbstractInlineQueryResult 'last_name' => true, 'reply_markup' => InlineKeyboardMarkup::class, 'input_message_content' => InputMessageContent::class, - 'thumb_url' => true, - 'thumb_width' => true, - 'thumb_height' => true, + 'thumbnail_url' => true, + 'thumbnail_width' => true, + 'thumbnail_height' => true, ]; /** @@ -71,21 +71,21 @@ class Contact extends AbstractInlineQueryResult * * @var string|null */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Thumbnail width * * @var int|null */ - protected $thumbWidth; + protected $thumbnailWidth; /** * Optional. Thumbnail height * * @var int|null */ - protected $thumbHeight; + protected $thumbnailHeight; /** * Contact constructor. @@ -94,9 +94,9 @@ class Contact extends AbstractInlineQueryResult * @param string $phoneNumber * @param string $firstName * @param string $lastName - * @param string $thumbUrl - * @param int $thumbWidth - * @param int $thumbHeight + * @param string $thumbnailUrl + * @param int $thumbnailWidth + * @param int $thumbnailHeight * @param InputMessageContent|null $inputMessageContent * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup */ @@ -105,9 +105,9 @@ public function __construct( $phoneNumber, $firstName, $lastName = null, - $thumbUrl = null, - $thumbWidth = null, - $thumbHeight = null, + $thumbnailUrl = null, + $thumbnailWidth = null, + $thumbnailHeight = null, $inputMessageContent = null, $inlineKeyboardMarkup = null ) { @@ -116,9 +116,9 @@ public function __construct( $this->phoneNumber = $phoneNumber; $this->firstName = $firstName; $this->lastName = $lastName; - $this->thumbUrl = $thumbUrl; - $this->thumbWidth = $thumbWidth; - $this->thumbHeight = $thumbHeight; + $this->thumbnailUrl = $thumbnailUrl; + $this->thumbnailWidth = $thumbnailWidth; + $this->thumbnailHeight = $thumbnailHeight; } /** @@ -178,54 +178,120 @@ public function setLastName($lastName) /** * @return string|null */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string|null $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string|null + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string|null $thumbUrl * * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** * @return int|null */ + public function getThumbnailWidth() + { + return $this->thumbnailWidth; + } + + /** + * @param int|null $thumbnailWidth + * + * @return void + */ + public function setThumbnailWidth($thumbnailWidth) + { + $this->thumbnailWidth = $thumbnailWidth; + } + + /** + * @deprecated Use getThumbnailWidth + * + * @return int|null + */ public function getThumbWidth() { - return $this->thumbWidth; + return $this->getThumbnailWidth(); } /** + * @deprecated Use setThumbnailWidth + * * @param int|null $thumbWidth * * @return void */ public function setThumbWidth($thumbWidth) { - $this->thumbWidth = $thumbWidth; + $this->setThumbnailWidth($thumbWidth); + } + + /** + * @return int|null + */ + public function getThumbnailHeight() + { + return $this->thumbnailHeight; } /** + * @param int|null $thumbnailHeight + * + * @return void + */ + public function setThumbnailHeight($thumbnailHeight) + { + $this->thumbnailHeight = $thumbnailHeight; + } + + /** + * @deprecated Use getThumbnailHeight + * * @return int|null */ public function getThumbHeight() { - return $this->thumbHeight; + return $this->getThumbnailHeight(); } /** + * @deprecated Use setThumbnailWidth + * * @param int|null $thumbHeight * * @return void */ public function setThumbHeight($thumbHeight) { - $this->thumbHeight = $thumbHeight; + $this->setThumbnailHeight($thumbHeight); } } diff --git a/src/Types/Inline/QueryResult/Gif.php b/src/Types/Inline/QueryResult/Gif.php index f23f51cc..1bf388ed 100644 --- a/src/Types/Inline/QueryResult/Gif.php +++ b/src/Types/Inline/QueryResult/Gif.php @@ -20,7 +20,7 @@ class Gif extends AbstractInlineQueryResult * * @var array */ - protected static $requiredParams = ['type', 'id', 'gif_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'gif_url', 'thumbnail_url']; /** * {@inheritdoc} @@ -33,7 +33,7 @@ class Gif extends AbstractInlineQueryResult 'gif_url' => true, 'gif_width' => true, 'gif_height' => true, - 'thumb_url' => true, + 'thumbnail_url' => true, 'title' => true, 'caption' => true, 'reply_markup' => InlineKeyboardMarkup::class, @@ -73,7 +73,7 @@ class Gif extends AbstractInlineQueryResult * * @var string */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Caption of the GIF file to be sent, 0-200 characters @@ -87,7 +87,7 @@ class Gif extends AbstractInlineQueryResult * * @param string $id * @param string $gifUrl - * @param string $thumbUrl + * @param string|null $thumbnailUrl * @param int|null $gifWidth * @param int|null $gifHeight * @param string|null $title @@ -98,7 +98,7 @@ class Gif extends AbstractInlineQueryResult public function __construct( $id, $gifUrl, - $thumbUrl = null, + $thumbnailUrl = null, $title = null, $caption = null, $gifWidth = null, @@ -109,7 +109,7 @@ public function __construct( parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->gifUrl = $gifUrl; - $this->thumbUrl = is_null($thumbUrl) ? $gifUrl : $thumbUrl; + $this->thumbnailUrl = is_null($thumbnailUrl) ? $gifUrl : $thumbnailUrl; $this->gifWidth = $gifWidth; $this->gifHeight = $gifHeight; $this->caption = $caption; @@ -172,19 +172,41 @@ public function setGifHeight($gifHeight) /** * @return string */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string $thumbUrl * * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** diff --git a/src/Types/Inline/QueryResult/Location.php b/src/Types/Inline/QueryResult/Location.php index a9ddf98b..9c64339e 100644 --- a/src/Types/Inline/QueryResult/Location.php +++ b/src/Types/Inline/QueryResult/Location.php @@ -42,9 +42,9 @@ class Location extends AbstractInlineQueryResult 'latitude' => true, 'longitude' => true, 'title' => true, - 'thumb_url' => true, - 'thumb_width' => true, - 'thumb_height' => true, + 'thumbnail_url' => true, + 'thumbnail_width' => true, + 'thumbnail_height' => true, 'reply_markup' => InlineKeyboardMarkup::class, 'input_message_content' => InputMessageContent::class, ]; @@ -75,21 +75,21 @@ class Location extends AbstractInlineQueryResult * * @var string|null */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Thumbnail width * * @var int|null */ - protected $thumbWidth; + protected $thumbnailWidth; /** * Optional. Thumbnail height * * @var int|null */ - protected $thumbHeight; + protected $thumbnailHeight; /** * Voice constructor @@ -98,9 +98,9 @@ class Location extends AbstractInlineQueryResult * @param float $latitude * @param float $longitude * @param string $title - * @param string|null $thumbUrl - * @param int|null $thumbWidth - * @param int|null $thumbHeight + * @param string|null $thumbnailUrl + * @param int|null $thumbnailWidth + * @param int|null $thumbnailHeight * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup * @param InputMessageContent|null $inputMessageContent */ @@ -109,9 +109,9 @@ public function __construct( $latitude, $longitude, $title, - $thumbUrl = null, - $thumbWidth = null, - $thumbHeight = null, + $thumbnailUrl = null, + $thumbnailWidth = null, + $thumbnailHeight = null, $inlineKeyboardMarkup = null, $inputMessageContent = null ) { @@ -119,9 +119,9 @@ public function __construct( $this->latitude = $latitude; $this->longitude = $longitude; - $this->thumbUrl = $thumbUrl; - $this->thumbWidth = $thumbWidth; - $this->thumbHeight = $thumbHeight; + $this->thumbnailUrl = $thumbnailUrl; + $this->thumbnailWidth = $thumbnailWidth; + $this->thumbnailHeight = $thumbnailHeight; } /** @@ -163,54 +163,120 @@ public function setLongitude($longitude) /** * @return string|null */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string|null $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string|null + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string|null $thumbUrl * * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); + } + + /** + * @return int|null + */ + public function getThumbnailWidth() + { + return $this->thumbnailWidth; } /** + * @param int|null $thumbnailWidth + * + * @return void + */ + public function setThumbnailWidth($thumbnailWidth) + { + $this->thumbnailWidth = $thumbnailWidth; + } + + /** + * @deprecated Use getThumbnailWidth + * * @return int|null */ public function getThumbWidth() { - return $this->thumbWidth; + return $this->getThumbnailWidth(); } /** + * @deprecated Use setThumbnailWidth + * * @param int|null $thumbWidth * * @return void */ public function setThumbWidth($thumbWidth) { - $this->thumbWidth = $thumbWidth; + $this->setThumbnailWidth($thumbWidth); + } + + /** + * @return int|null + */ + public function getThumbnailHeight() + { + return $this->thumbnailHeight; + } + + /** + * @param int|null $thumbnailHeight + * + * @return void + */ + public function setThumbnailHeight($thumbnailHeight) + { + $this->thumbnailHeight = $thumbnailHeight; } /** + * @deprecated Use getThumbnailHeight + * * @return int|null */ public function getThumbHeight() { - return $this->thumbHeight; + return $this->getThumbnailHeight(); } /** + * @deprecated Use setThumbnailWidth + * * @param int|null $thumbHeight * * @return void */ public function setThumbHeight($thumbHeight) { - $this->thumbHeight = $thumbHeight; + $this->setThumbnailHeight($thumbHeight); } } diff --git a/src/Types/Inline/QueryResult/Mpeg4Gif.php b/src/Types/Inline/QueryResult/Mpeg4Gif.php index 59d7b39f..f5e5cce1 100644 --- a/src/Types/Inline/QueryResult/Mpeg4Gif.php +++ b/src/Types/Inline/QueryResult/Mpeg4Gif.php @@ -20,7 +20,7 @@ class Mpeg4Gif extends AbstractInlineQueryResult * * @var array */ - protected static $requiredParams = ['type', 'id', 'mpeg4_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'mpeg4_url', 'thumbnail_url']; /** * {@inheritdoc} @@ -33,7 +33,7 @@ class Mpeg4Gif extends AbstractInlineQueryResult 'mpeg4_url' => true, 'mpeg4_width' => true, 'mpeg4_height' => true, - 'thumb_url' => true, + 'thumbnail_url' => true, 'title' => true, 'caption' => true, 'reply_markup' => InlineKeyboardMarkup::class, @@ -73,7 +73,7 @@ class Mpeg4Gif extends AbstractInlineQueryResult * * @var string */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Caption of the MPEG-4 file to be sent, 0-200 characters @@ -87,7 +87,7 @@ class Mpeg4Gif extends AbstractInlineQueryResult * * @param string $id * @param string $mpeg4Url - * @param string $thumbUrl + * @param string $thumbnailUrl * @param int|null $mpeg4Width * @param int|null $mpeg4Height * @param string|null $caption @@ -98,7 +98,7 @@ class Mpeg4Gif extends AbstractInlineQueryResult public function __construct( $id, $mpeg4Url, - $thumbUrl, + $thumbnailUrl, $title = null, $caption = null, $mpeg4Width = null, @@ -109,7 +109,7 @@ public function __construct( parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->mpeg4Url = $mpeg4Url; - $this->thumbUrl = $thumbUrl; + $this->thumbnailUrl = $thumbnailUrl; $this->mpeg4Width = $mpeg4Width; $this->mpeg4Height = $mpeg4Height; $this->caption = $caption; @@ -172,19 +172,41 @@ public function setMpeg4Height($mpeg4Height) /** * @return string */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string $thumbUrl * * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** diff --git a/src/Types/Inline/QueryResult/Photo.php b/src/Types/Inline/QueryResult/Photo.php index 97249054..e53d9408 100644 --- a/src/Types/Inline/QueryResult/Photo.php +++ b/src/Types/Inline/QueryResult/Photo.php @@ -19,7 +19,7 @@ class Photo extends AbstractInlineQueryResult * * @var array */ - protected static $requiredParams = ['type', 'id', 'photo_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'photo_url', 'thumbnail_url']; /** * {@inheritdoc} @@ -30,7 +30,7 @@ class Photo extends AbstractInlineQueryResult 'type' => true, 'id' => true, 'photo_url' => true, - 'thumb_url' => true, + 'thumbnail_url' => true, 'photo_width' => true, 'photo_height' => true, 'title' => true, @@ -73,7 +73,7 @@ class Photo extends AbstractInlineQueryResult * * @var string */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Short description of the result @@ -94,7 +94,7 @@ class Photo extends AbstractInlineQueryResult * * @param string $id * @param string $photoUrl - * @param string $thumbUrl + * @param string $thumbnailUrl * @param int|null $photoWidth * @param int|null $photoHeight * @param string|null $title @@ -106,7 +106,7 @@ class Photo extends AbstractInlineQueryResult public function __construct( $id, $photoUrl, - $thumbUrl, + $thumbnailUrl, $photoWidth = null, $photoHeight = null, $title = null, @@ -118,7 +118,7 @@ public function __construct( parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->photoUrl = $photoUrl; - $this->thumbUrl = $thumbUrl; + $this->thumbnailUrl = $thumbnailUrl; $this->photoWidth = $photoWidth; $this->photoHeight = $photoHeight; $this->description = $description; @@ -182,19 +182,41 @@ public function setPhotoHeight($photoHeight) /** * @return string */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string $thumbUrl * * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** diff --git a/src/Types/Inline/QueryResult/Venue.php b/src/Types/Inline/QueryResult/Venue.php index 48e4e011..34631044 100644 --- a/src/Types/Inline/QueryResult/Venue.php +++ b/src/Types/Inline/QueryResult/Venue.php @@ -44,9 +44,9 @@ class Venue extends AbstractInlineQueryResult 'title' => true, 'address' => true, 'foursquare_id' => true, - 'thumb_url' => true, - 'thumb_width' => true, - 'thumb_height' => true, + 'thumbnail_url' => true, + 'thumbnail_width' => true, + 'thumbnail_height' => true, 'reply_markup' => InlineKeyboardMarkup::class, 'input_message_content' => InputMessageContent::class, ]; @@ -84,21 +84,21 @@ class Venue extends AbstractInlineQueryResult * * @var string|null */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Thumbnail width * * @var int|null */ - protected $thumbWidth; + protected $thumbnailWidth; /** * Optional. Thumbnail height * * @var int|null */ - protected $thumbHeight; + protected $thumbnailHeight; /** * Optional. Foursquare identifier of the venue if known @@ -115,9 +115,9 @@ class Venue extends AbstractInlineQueryResult * @param float $longitude * @param string $title * @param string $address - * @param string|null $thumbUrl - * @param int|null $thumbWidth - * @param int|null $thumbHeight + * @param string|null $thumbnailUrl + * @param int|null $thumbnailWidth + * @param int|null $thumbnailHeight * @param string|null $foursquareId * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup * @param InputMessageContent|null $inputMessageContent @@ -128,9 +128,9 @@ public function __construct( $longitude, $title, $address, - $thumbUrl = null, - $thumbWidth = null, - $thumbHeight = null, + $thumbnailUrl = null, + $thumbnailWidth = null, + $thumbnailHeight = null, $foursquareId = null, $inputMessageContent = null, $inlineKeyboardMarkup = null @@ -140,9 +140,9 @@ public function __construct( $this->latitude = $latitude; $this->longitude = $longitude; $this->address = $address; - $this->thumbUrl = $thumbUrl; - $this->thumbWidth = $thumbWidth; - $this->thumbHeight = $thumbHeight; + $this->thumbnailUrl = $thumbnailUrl; + $this->thumbnailWidth = $thumbnailWidth; + $this->thumbnailHeight = $thumbnailHeight; $this->foursquareId = $foursquareId; } @@ -221,54 +221,120 @@ public function setFoursquareId($foursquareId) /** * @return string|null */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string|null $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string|null + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string|null $thumbUrl * * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); + } + + /** + * @return int|null + */ + public function getThumbnailWidth() + { + return $this->thumbnailWidth; } /** + * @param int|null $thumbnailWidth + * + * @return void + */ + public function setThumbnailWidth($thumbnailWidth) + { + $this->thumbnailWidth = $thumbnailWidth; + } + + /** + * @deprecated Use getThumbnailWidth + * * @return int|null */ public function getThumbWidth() { - return $this->thumbWidth; + return $this->getThumbnailWidth(); } /** + * @deprecated Use setThumbnailWidth + * * @param int|null $thumbWidth * * @return void */ public function setThumbWidth($thumbWidth) { - $this->thumbWidth = $thumbWidth; + $this->setThumbnailWidth($thumbWidth); + } + + /** + * @return int|null + */ + public function getThumbnailHeight() + { + return $this->thumbnailHeight; + } + + /** + * @param int|null $thumbnailHeight + * + * @return void + */ + public function setThumbnailHeight($thumbnailHeight) + { + $this->thumbnailHeight = $thumbnailHeight; } /** + * @deprecated Use getThumbnailHeight + * * @return int|null */ public function getThumbHeight() { - return $this->thumbHeight; + return $this->getThumbnailHeight(); } /** + * @deprecated Use setThumbnailWidth + * * @param int|null $thumbHeight * * @return void */ public function setThumbHeight($thumbHeight) { - $this->thumbHeight = $thumbHeight; + $this->setThumbnailHeight($thumbHeight); } } diff --git a/src/Types/Inline/QueryResult/Video.php b/src/Types/Inline/QueryResult/Video.php index 48cbc8e5..9eec6962 100644 --- a/src/Types/Inline/QueryResult/Video.php +++ b/src/Types/Inline/QueryResult/Video.php @@ -18,7 +18,7 @@ class Video extends AbstractInlineQueryResult * * @var array */ - protected static $requiredParams = ['type', 'id', 'video_url', 'mime_type', 'thumb_url', 'title']; + protected static $requiredParams = ['type', 'id', 'video_url', 'mime_type', 'thumbnail_url', 'title']; /** * {@inheritdoc} @@ -30,7 +30,7 @@ class Video extends AbstractInlineQueryResult 'id' => true, 'video_url' => true, 'mime_type' => true, - 'thumb_url' => true, + 'thumbnail_url' => true, 'title' => true, 'caption' => true, 'description' => true, @@ -88,7 +88,7 @@ class Video extends AbstractInlineQueryResult * * @var string */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Short description of the result @@ -109,7 +109,7 @@ class Video extends AbstractInlineQueryResult * * @param string $id * @param string $videoUrl - * @param string $thumbUrl + * @param string $thumbnailUrl * @param string $mimeType * @param string $title * @param string|null $caption @@ -123,7 +123,7 @@ class Video extends AbstractInlineQueryResult public function __construct( $id, $videoUrl, - $thumbUrl, + $thumbnailUrl, $mimeType, $title, $caption = null, @@ -137,7 +137,7 @@ public function __construct( parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->videoUrl = $videoUrl; - $this->thumbUrl = $thumbUrl; + $this->thumbnailUrl = $thumbnailUrl; $this->caption = $caption; $this->description = $description; $this->mimeType = $mimeType; @@ -237,21 +237,43 @@ public function setVideoDuration($videoDuration) } /** - * @return mixed + * @return string + */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** - * @param mixed $thumbUrl + * @deprecated Use setThumbnailUrl + * + * @param string $thumbUrl * * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** diff --git a/src/Types/Sticker.php b/src/Types/Sticker.php index 8f2c91ef..3a948caf 100644 --- a/src/Types/Sticker.php +++ b/src/Types/Sticker.php @@ -42,7 +42,7 @@ class Sticker extends BaseType implements TypeInterface 'height' => true, 'is_animated' => true, 'is_video' => true, - 'thumb' => PhotoSize::class, + 'thumbnail' => PhotoSize::class, 'file_size' => true, 'premium_animation' => File::class, 'emoji' => true, @@ -77,7 +77,7 @@ class Sticker extends BaseType implements TypeInterface * * @var PhotoSize|null */ - protected $thumb; + protected $thumbnail; /** * Optional. File size @@ -221,19 +221,41 @@ public function setHeight($height) /** * @return PhotoSize|null */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * + * @return void + */ + public function setThumbnail(PhotoSize $thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null + */ public function getThumb() { - return $this->thumb; + return $this->getThumbnail(); } /** + * @deprecated use setThumbnail method + * * @param PhotoSize $thumb * * @return void */ - public function setThumb(PhotoSize $thumb) + public function setThumb($thumb) { - $this->thumb = $thumb; + $this->setThumbnail($thumb); } /** diff --git a/src/Types/StickerSet.php b/src/Types/StickerSet.php index 5127238f..6f038bea 100644 --- a/src/Types/StickerSet.php +++ b/src/Types/StickerSet.php @@ -33,7 +33,7 @@ class StickerSet extends BaseType implements TypeInterface 'is_animated' => true, 'is_video' => true, 'stickers' => ArrayOfSticker::class, - 'thumb' => PhotoSize::class, + 'thumbnail' => PhotoSize::class, ]; /** @@ -83,7 +83,7 @@ class StickerSet extends BaseType implements TypeInterface * * @var PhotoSize|null */ - protected $thumb; + protected $thumbnail; /** * @return string @@ -196,18 +196,40 @@ public function setStickers($stickers) /** * @return PhotoSize|null */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * + * @return void + */ + public function setThumbnail($thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null + */ public function getThumb() { - return $this->thumb; + return $this->getThumbnail(); } /** + * @deprecated use setThumbnail method + * * @param PhotoSize $thumb * * @return void */ public function setThumb($thumb) { - $this->thumb = $thumb; + $this->setThumbnail($thumb); } } diff --git a/src/Types/Video.php b/src/Types/Video.php index b0ef4a75..abf79e8a 100644 --- a/src/Types/Video.php +++ b/src/Types/Video.php @@ -32,7 +32,7 @@ class Video extends BaseType implements TypeInterface 'width' => true, 'height' => true, 'duration' => true, - 'thumb' => PhotoSize::class, + 'thumbnail' => PhotoSize::class, 'mime_type' => true, 'file_size' => true ]; @@ -68,9 +68,9 @@ class Video extends BaseType implements TypeInterface /** * Video thumbnail * - * @var PhotoSize + * @var PhotoSize|null */ - protected $thumb; + protected $thumbnail; /** * Optional. Mime type of a file as defined by sender @@ -202,21 +202,43 @@ public function setMimeType($mimeType) } /** - * @return PhotoSize + * @return PhotoSize|null + */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize|null $thumbnail + * + * @return void + */ + public function setThumbnail($thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null */ public function getThumb() { - return $this->thumb; + return $this->getThumbnail(); } /** - * @param PhotoSize $thumb + * @deprecated use setThumbnail method + * + * @param PhotoSize|null $thumb * * @return void */ - public function setThumb(PhotoSize $thumb) + public function setThumb($thumb) { - $this->thumb = $thumb; + $this->setThumbnail($thumb); } /** diff --git a/src/Types/VideoNote.php b/src/Types/VideoNote.php index a10325a3..a33ae9cc 100644 --- a/src/Types/VideoNote.php +++ b/src/Types/VideoNote.php @@ -20,7 +20,7 @@ class VideoNote extends BaseType implements TypeInterface 'file_unique_id' => true, 'length' => true, 'duration' => true, - 'thumb' => PhotoSize::class, + 'thumbnail' => PhotoSize::class, 'file_size' => true, ]; @@ -57,7 +57,7 @@ class VideoNote extends BaseType implements TypeInterface * * @var PhotoSize|null */ - protected $thumb; + protected $thumbnail; /** * Optional. File size in bytes @@ -141,19 +141,41 @@ public function setDuration($duration) /** * @return PhotoSize|null */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * + * @return void + */ + public function setThumbnail($thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null + */ public function getThumb() { - return $this->thumb; + return $this->getThumbnail(); } /** + * @deprecated use setThumbnail method + * * @param PhotoSize $thumb * * @return void */ public function setThumb($thumb) { - $this->thumb = $thumb; + $this->setThumbnail($thumb); } /** diff --git a/tests/Types/AnimationTest.php b/tests/Types/AnimationTest.php index be885545..9aba5b58 100644 --- a/tests/Types/AnimationTest.php +++ b/tests/Types/AnimationTest.php @@ -32,7 +32,7 @@ public static function getFullResponse() 'width' => 10, 'height' => 20, 'duration' => 30, - 'thumb' => PhotoSizeTest::getMinResponse(), + 'thumbnail' => PhotoSizeTest::getMinResponse(), 'file_name' => 'file_name', 'mime_type' => 'mime_type', 'file_size' => 100 @@ -50,7 +50,7 @@ protected function assertMinItem($item) $this->assertEquals(10, $item->getWidth()); $this->assertEquals(20, $item->getHeight()); $this->assertEquals(30, $item->getDuration()); - $this->assertNull($item->getThumb()); + $this->assertNull($item->getThumbnail()); $this->assertNull($item->getFileName()); $this->assertNull($item->getMimeType()); $this->assertNull($item->getFileSize()); @@ -67,7 +67,7 @@ protected function assertFullItem($item) $this->assertEquals(10, $item->getWidth()); $this->assertEquals(20, $item->getHeight()); $this->assertEquals(30, $item->getDuration()); - $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); $this->assertEquals('file_name', $item->getFileName()); $this->assertEquals('mime_type', $item->getMimeType()); $this->assertEquals(100, $item->getFileSize()); diff --git a/tests/Types/DocumentTest.php b/tests/Types/DocumentTest.php index f482c4a9..a0734669 100644 --- a/tests/Types/DocumentTest.php +++ b/tests/Types/DocumentTest.php @@ -29,7 +29,7 @@ public static function getFullResponse() 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', 'file_size' => 3, - 'thumb' => PhotoSizeTest::getMinResponse(), + 'thumbnail' => PhotoSizeTest::getMinResponse(), ]; } @@ -44,7 +44,7 @@ protected function assertMinItem($item) $this->assertNull($item->getFileName()); $this->assertNull($item->getMimeType()); $this->assertNull($item->getFileSize()); - $this->assertNull($item->getThumb()); + $this->assertNull($item->getThumbnail()); } /** @@ -58,7 +58,7 @@ protected function assertFullItem($item) $this->assertEquals('testFileName', $item->getFileName()); $this->assertEquals('audio/mp3', $item->getMimeType()); $this->assertEquals(3, $item->getFileSize()); - $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); } public function testSetFileSizeException() @@ -80,7 +80,7 @@ public function testFromResponseException1() 'file_name' => 'testFileName', 'mime_type' => 'audio/mp3', 'file_size' => 3, - 'thumb' => [ + 'thumbnail' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, diff --git a/tests/Types/StickerSetTest.php b/tests/Types/StickerSetTest.php index e5867ba8..b15ab212 100644 --- a/tests/Types/StickerSetTest.php +++ b/tests/Types/StickerSetTest.php @@ -37,7 +37,7 @@ public static function getFullResponse() 'stickers' => [ StickerTest::getMinResponse(), ], - 'thumb' => PhotoSizeTest::getMinResponse(), + 'thumbnail' => PhotoSizeTest::getMinResponse(), ]; } @@ -53,7 +53,7 @@ protected function assertMinItem($item) $this->assertEquals(true, $item->getIsAnimated()); $this->assertEquals(true, $item->getIsVideo()); $this->assertEquals([StickerTest::createMinInstance()], $item->getStickers()); - $this->assertNull($item->getThumb()); + $this->assertNull($item->getThumbnail()); } /** @@ -68,6 +68,6 @@ protected function assertFullItem($item) $this->assertEquals(true, $item->getIsAnimated()); $this->assertEquals(true, $item->getIsVideo()); $this->assertEquals([StickerTest::createMinInstance()], $item->getStickers()); - $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); } } diff --git a/tests/Types/StickerTest.php b/tests/Types/StickerTest.php index e9a614e3..cd880d50 100644 --- a/tests/Types/StickerTest.php +++ b/tests/Types/StickerTest.php @@ -39,7 +39,7 @@ public static function getFullResponse() 'file_size' => 3, 'premium_animation' => FileTest::getMinResponse(), 'emoji' => '🎉', - 'thumb' => PhotoSizeTest::getMinResponse(), + 'thumbnail' => PhotoSizeTest::getMinResponse(), 'set_name' => 'set', 'custom_emoji_id' => 'custom_emoji_id', 'mask_position' => MaskPositionTest::getMinResponse(), @@ -80,7 +80,7 @@ protected function assertFullItem($item) $this->assertEquals('set', $item->getSetName()); $this->assertEquals('custom_emoji_id', $item->getCustomEmojiId()); $this->assertEquals(MaskPositionTest::createMinInstance(), $item->getMaskPosition()); - $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); } public function testSetFileSizeException() diff --git a/tests/Types/VideoNoteTest.php b/tests/Types/VideoNoteTest.php index c4f2d471..b0197075 100644 --- a/tests/Types/VideoNoteTest.php +++ b/tests/Types/VideoNoteTest.php @@ -29,7 +29,7 @@ public static function getFullResponse() 'file_unique_id' => 'file_unique_id', 'length' => 1, 'duration' => 2, - 'thumb' => PhotoSizeTest::getMinResponse(), + 'thumbnail' => PhotoSizeTest::getMinResponse(), 'file_size' => 3, ]; } @@ -45,7 +45,7 @@ protected function assertMinItem($item) $this->assertEquals(1, $item->getLength()); $this->assertEquals(2, $item->getDuration()); $this->assertNull($item->getFileSize()); - $this->assertNull($item->getThumb()); + $this->assertNull($item->getThumbnail()); } /** @@ -59,6 +59,6 @@ protected function assertFullItem($item) $this->assertEquals(1, $item->getLength()); $this->assertEquals(2, $item->getDuration()); $this->assertEquals(3, $item->getFileSize()); - $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); } } diff --git a/tests/Types/VideoTest.php b/tests/Types/VideoTest.php index a90955f3..d74a5489 100644 --- a/tests/Types/VideoTest.php +++ b/tests/Types/VideoTest.php @@ -34,7 +34,7 @@ public static function getFullResponse() 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => PhotoSizeTest::getMinResponse() + 'thumbnail' => PhotoSizeTest::getMinResponse() ]; } @@ -51,7 +51,7 @@ protected function assertMinItem($item) $this->assertEquals(3, $item->getDuration()); $this->assertNull($item->getMimeType()); $this->assertNull($item->getFileSize()); - $this->assertNull($item->getThumb()); + $this->assertNull($item->getThumbnail()); } /** @@ -67,7 +67,7 @@ protected function assertFullItem($item) $this->assertEquals(3, $item->getDuration()); $this->assertEquals('video/mp4', $item->getMimeType()); $this->assertEquals(4, $item->getFileSize()); - $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumb()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); } public function testSetHeightException() @@ -116,7 +116,7 @@ public function testFromResponseException1() 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => [ + 'thumbnail' => [ 'file_id' => 'testFileId1', 'width' => 5, 'height' => 6, @@ -138,7 +138,7 @@ public function testFromResponseException2() 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => [ + 'thumbnail' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, @@ -162,7 +162,7 @@ public function testFromResponseException3() 'duration' => 3, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => [ + 'thumbnail' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, @@ -186,7 +186,7 @@ public function testFromResponseException4() 'height' => 2, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => [ + 'thumbnail' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, @@ -210,7 +210,7 @@ public function testFromResponseException5() 'duration' => 1, 'mime_type' => 'video/mp4', 'file_size' => 4, - 'thumb' => [ + 'thumbnail' => [ 'file_id' => 'testFileId1', 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, From 100fd4e5a861c16b7276929b292eab91d04ceab2 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 27 Jun 2023 15:47:00 +0300 Subject: [PATCH 106/130] Fix phpDoc for $allowedUpdates parameters --- CHANGELOG.md | 3 ++- src/BotApi.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf5fb8c7..24acbe10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Rename `thumb` to `thumbnail` parameter in `Animation`, `Document`, `Sticker`, `StickerSet`, `Video`, `VideoNote` types - Rename `thumb_*` to `thumbnail_*` parameter in `Inline/QueryResult` types - Add missing phpDoc for `$replyMarkup` parameters -- +- Fix phpDoc for `\TelegramBot\Api\BotApi::setWebhook` `$allowedUpdates` parameter. Automatically serialize if array passed + ### Deprecated - Deprecate using `thumb*` methods in `\TelegramBot\Api\BotApi` - Deprecate method `\TelegramBot\Api\BotApi::setStickerSetThumb`. Use `\TelegramBot\Api\BotApi::setStickerSetThumbnail` instead diff --git a/src/BotApi.php b/src/BotApi.php index c1c72676..1e69767a 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -527,13 +527,13 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) * @param int|null $maxConnections The maximum allowed number of simultaneous HTTPS connections to the webhook * for update delivery, 1-100. Defaults to 40. Use lower values to limit * the load on your bot's server, and higher values to increase your bot's throughput. - * @param array|null $allowedUpdates A JSON-serialized list of the update types you want your bot to receive. - * For example, specify [“message”, “edited_channel_post”, “callback_query”] - * to only receive updates of these types. See Update for a complete list of available update types. - * Specify an empty list to receive all update types except chat_member (default). - * If not specified, the previous setting will be used. - * Please note that this parameter doesn't affect updates created before the call to the setWebhook, - * so unwanted updates may be received for a short period of time. + * @param array|string|null $allowedUpdates A JSON-serialized list of the update types you want your bot to receive. + * For example, specify [“message”, “edited_channel_post”, “callback_query”] + * to only receive updates of these types. See Update for a complete list of available update types. + * Specify an empty list to receive all update types except chat_member (default). + * If not specified, the previous setting will be used. + * Please note that this parameter doesn't affect updates created before the call to the setWebhook, + * so unwanted updates may be received for a short period of time. * @param bool|null $dropPendingUpdates Pass True to drop all pending updates * @param string|null $secretToken A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, * 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. @@ -557,7 +557,7 @@ public function setWebhook( 'certificate' => $certificate, 'ip_address' => $ipAddress, 'max_connections' => $maxConnections, - 'allowed_updates' => $allowedUpdates, + 'allowed_updates' => \is_array($allowedUpdates) ? json_encode($allowedUpdates) : $allowedUpdates, 'drop_pending_updates' => $dropPendingUpdates, 'secret_token' => $secretToken ]); From d8d0344a3442ce2b13800649dd416c0cdbf8e9b3 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 9 Aug 2023 15:43:32 +0300 Subject: [PATCH 107/130] Fix Message::newChatMembers phpDoc --- CHANGELOG.md | 1 + src/Types/Message.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24acbe10..057fa6fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Rename `thumb_*` to `thumbnail_*` parameter in `Inline/QueryResult` types - Add missing phpDoc for `$replyMarkup` parameters - Fix phpDoc for `\TelegramBot\Api\BotApi::setWebhook` `$allowedUpdates` parameter. Automatically serialize if array passed +- Fix phpDoc for `\TelegramBot\Api\Types\Message::$newChatMembers` ### Deprecated - Deprecate using `thumb*` methods in `\TelegramBot\Api\BotApi` diff --git a/src/Types/Message.php b/src/Types/Message.php index abd6adad..c344bfd5 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -308,7 +308,7 @@ class Message extends BaseType implements TypeInterface * (the bot itself may be one of these members) * array of \TelegramBot\Api\Types\User * - * @var array|null + * @var \TelegramBot\Api\Types\User[]|null */ protected $newChatMembers; @@ -1003,7 +1003,7 @@ public function setDice(Dice $dice) } /** - * @return array|null + * @return \TelegramBot\Api\Types\User[]|null */ public function getNewChatMembers() { @@ -1011,7 +1011,7 @@ public function getNewChatMembers() } /** - * @param array $newChatMembers + * @param \TelegramBot\Api\Types\User[]|null $newChatMembers * @return void */ public function setNewChatMembers($newChatMembers) From f6a61d5104c99562c212a7e69165f94d29658013 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 9 Aug 2023 16:11:09 +0300 Subject: [PATCH 108/130] Add getChatMemberCount and banChatMember --- CHANGELOG.md | 4 ++++ src/BotApi.php | 58 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 057fa6fe..c0c2770e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,11 +12,15 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Add missing phpDoc for `$replyMarkup` parameters - Fix phpDoc for `\TelegramBot\Api\BotApi::setWebhook` `$allowedUpdates` parameter. Automatically serialize if array passed - Fix phpDoc for `\TelegramBot\Api\Types\Message::$newChatMembers` +- Add `\TelegramBot\Api\BotApi::getChatMemberCount` method +- Add `\TelegramBot\Api\BotApi::banChatMember` method ### Deprecated - Deprecate using `thumb*` methods in `\TelegramBot\Api\BotApi` - Deprecate method `\TelegramBot\Api\BotApi::setStickerSetThumb`. Use `\TelegramBot\Api\BotApi::setStickerSetThumbnail` instead - Deprecate `\TelegramBot\Api\Types\ReplyKeyboardHide` class +- Deprecate `\TelegramBot\Api\BotApi::getChatMembersCount`. Use `\TelegramBot\Api\BotApi::getChatMemberCount` instead +- Deprecate `\TelegramBot\Api\BotApi::kickChatMember`. Use `\TelegramBot\Api\BotApi::banChatMember` instead ## 2.4.0 - 2023-05-11 diff --git a/src/BotApi.php b/src/BotApi.php index 1e69767a..a719004a 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -1515,6 +1515,8 @@ function ($item) { */ public function kickChatMember($chatId, $userId, $untilDate = null) { + @trigger_error(sprintf('Method "%s::%s" is deprecated. Use "banChatMember"', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + return $this->call('kickChatMember', [ 'chat_id' => $chatId, 'user_id' => $userId, @@ -1522,6 +1524,35 @@ public function kickChatMember($chatId, $userId, $untilDate = null) ]); } + /** + * Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, + * the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Returns True on success. + * + * @param int|string $chatId Unique identifier for the target group or username of the + * target supergroup or channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * @param null|int $untilDate Date when the user will be unbanned, unix time. + * If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. + * Applied for supergroups and channels only. + * @param bool|null $revokeMessages Pass True to delete all messages from the chat for the user that is being removed. + * If False, the user will be able to see messages in the group that were sent before the user was removed. + * Always True for supergroups and channels. + * + * @return bool + * @throws Exception + */ + public function banChatMember($chatId, $userId, $untilDate = null, $revokeMessages = null) + { + return $this->call('banChatMember', [ + 'chat_id' => $chatId, + 'user_id' => $userId, + 'until_date' => $untilDate, + 'revoke_messages' => $revokeMessages, + ]); + } + /** * Use this method to unban a previously kicked user in a supergroup. * The user will not return to the group automatically, but will be able to join via link, etc. @@ -2269,12 +2300,27 @@ public function leaveChat($chatId) */ public function getChatMembersCount($chatId) { - return $this->call( - 'getChatMembersCount', - [ - 'chat_id' => $chatId - ] - ); + @trigger_error(sprintf('Method "%s::%s" is deprecated. Use "getChatMemberCount"', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + return $this->call('getChatMembersCount', [ + 'chat_id' => $chatId + ]); + } + + /** + * Use this method to get the number of members in a chat. Returns Int on success. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup or channel + * (in the format @channelusername) + * + * @return int + * @throws Exception + */ + public function getChatMemberCount($chatId) + { + return $this->call('getChatMemberCount', [ + 'chat_id' => $chatId + ]); } /** From d66f4cfcf525564190d55d157290635063e2d99a Mon Sep 17 00:00:00 2001 From: fonclub Date: Fri, 14 Jul 2023 14:49:33 +0300 Subject: [PATCH 109/130] Unpin message by Id Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned. https://core.telegram.org/bots/api#unpinchatmessage --- CHANGELOG.md | 1 + src/BotApi.php | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0c2770e..a71a65d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Fix phpDoc for `\TelegramBot\Api\Types\Message::$newChatMembers` - Add `\TelegramBot\Api\BotApi::getChatMemberCount` method - Add `\TelegramBot\Api\BotApi::banChatMember` method +- Add `$messageId` to `\TelegramBot\Api\BotApi::unpinChatMessage` ### Deprecated - Deprecate using `thumb*` methods in `\TelegramBot\Api\BotApi` diff --git a/src/BotApi.php b/src/BotApi.php index a719004a..45feaa58 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -2227,14 +2227,16 @@ public function pinChatMessage($chatId, $messageId, $disableNotification = false * * @param string|int $chatId Unique identifier for the target chat or username of the target channel * (in the format @channelusername) + * @param int|null $messageId Identifier of a message to pin (optional) * * @return bool * @throws Exception */ - public function unpinChatMessage($chatId) + public function unpinChatMessage($chatId, $messageId = null) { return $this->call('unpinChatMessage', [ - 'chat_id' => $chatId + 'chat_id' => $chatId, + 'message_id' => $messageId, ]); } From 4f4784dfebb8026c6a4b365f2836369494ceb203 Mon Sep 17 00:00:00 2001 From: Numair Awan <62851858+NumairAwan@users.noreply.github.com> Date: Mon, 26 Jun 2023 00:16:22 +0500 Subject: [PATCH 110/130] Update ForceReply.php Added input_field_placeholder field to change the reply input placeholder text. --- src/Types/ForceReply.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Types/ForceReply.php b/src/Types/ForceReply.php index 50f11f54..19c186d6 100644 --- a/src/Types/ForceReply.php +++ b/src/Types/ForceReply.php @@ -28,6 +28,7 @@ class ForceReply extends BaseType */ protected static $map = [ 'force_reply' => true, + 'input_field_placeholder' => true, 'selective' => true ]; @@ -38,6 +39,13 @@ class ForceReply extends BaseType */ protected $forceReply; + /** + * The placeholder to be shown in the input field when the reply is active; 1-64 characters + * + * @var string + */ + protected $inputFieldPlaceholder; + /** * Optional. Use this parameter if you want to show the keyboard to specific users only. * Targets: @@ -52,9 +60,10 @@ class ForceReply extends BaseType * @param bool $forceReply * @param bool|null $selective */ - public function __construct($forceReply = true, $selective = null) + public function __construct($forceReply = true, $inputFieldPlaceholder = false, $selective = null) { $this->forceReply = $forceReply; + $this->inputFieldPlaceholder = $inputFieldPlaceholder; $this->selective = $selective; } @@ -66,6 +75,23 @@ public function isForceReply() return $this->forceReply; } + /** + * @param string $inputFieldPlaceholder + * @return void + */ + public function setInputFieldPlaceholder($inputFieldPlaceholder) + { + $this->inputFieldPlaceholder = $inputFieldPlaceholder; + } + + /** + * @return string|null + */ + public function getInputFieldPlaceholder() + { + return $this->inputFieldPlaceholder; + } + /** * @param bool $forceReply * @return void From 9f75b31322f05913e2b31c2670b537075d532970 Mon Sep 17 00:00:00 2001 From: Numair Awan <62851858+NumairAwan@users.noreply.github.com> Date: Mon, 26 Jun 2023 14:53:44 +0500 Subject: [PATCH 111/130] Update ForceReply.php Moved $inputFieldPlaceholder to the last position. --- src/Types/ForceReply.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Types/ForceReply.php b/src/Types/ForceReply.php index 19c186d6..44315bf6 100644 --- a/src/Types/ForceReply.php +++ b/src/Types/ForceReply.php @@ -60,7 +60,7 @@ class ForceReply extends BaseType * @param bool $forceReply * @param bool|null $selective */ - public function __construct($forceReply = true, $inputFieldPlaceholder = false, $selective = null) + public function __construct($forceReply = true, $selective = null, $inputFieldPlaceholder = false) { $this->forceReply = $forceReply; $this->inputFieldPlaceholder = $inputFieldPlaceholder; @@ -74,23 +74,6 @@ public function isForceReply() { return $this->forceReply; } - - /** - * @param string $inputFieldPlaceholder - * @return void - */ - public function setInputFieldPlaceholder($inputFieldPlaceholder) - { - $this->inputFieldPlaceholder = $inputFieldPlaceholder; - } - - /** - * @return string|null - */ - public function getInputFieldPlaceholder() - { - return $this->inputFieldPlaceholder; - } /** * @param bool $forceReply @@ -117,4 +100,21 @@ public function setSelective($selective) { $this->selective = $selective; } + + /** + * @param string $inputFieldPlaceholder + * @return void + */ + public function setInputFieldPlaceholder($inputFieldPlaceholder) + { + $this->inputFieldPlaceholder = $inputFieldPlaceholder; + } + + /** + * @return string|null + */ + public function getInputFieldPlaceholder() + { + return $this->inputFieldPlaceholder; + } } From 95dae45762a604fcca02eec1df815810b6005ee9 Mon Sep 17 00:00:00 2001 From: Numair Awan <62851858+NumairAwan@users.noreply.github.com> Date: Mon, 26 Jun 2023 15:05:17 +0500 Subject: [PATCH 112/130] Update CHANGELOG.md Added `\TelegramBot\Api\Types\ForceReply::$inputFieldPlaceholder` property --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a71a65d3..c2f448f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Add `\TelegramBot\Api\BotApi::getChatMemberCount` method - Add `\TelegramBot\Api\BotApi::banChatMember` method - Add `$messageId` to `\TelegramBot\Api\BotApi::unpinChatMessage` +- Add `\TelegramBot\Api\Types\ForceReply::$inputFieldPlaceholder` property ### Deprecated - Deprecate using `thumb*` methods in `\TelegramBot\Api\BotApi` From 5382dbd42f50cfb62c6120d0414cdf32ccab7114 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 9 Aug 2023 16:37:21 +0300 Subject: [PATCH 113/130] Fix pipeline checks --- src/Types/ForceReply.php | 15 ++++++++------- tests/Types/ForceReplyTest.php | 7 +++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Types/ForceReply.php b/src/Types/ForceReply.php index 44315bf6..1cc04256 100644 --- a/src/Types/ForceReply.php +++ b/src/Types/ForceReply.php @@ -42,10 +42,10 @@ class ForceReply extends BaseType /** * The placeholder to be shown in the input field when the reply is active; 1-64 characters * - * @var string + * @var string|null */ protected $inputFieldPlaceholder; - + /** * Optional. Use this parameter if you want to show the keyboard to specific users only. * Targets: @@ -59,12 +59,13 @@ class ForceReply extends BaseType /** * @param bool $forceReply * @param bool|null $selective + * @param string|null $inputFieldPlaceholder */ - public function __construct($forceReply = true, $selective = null, $inputFieldPlaceholder = false) + public function __construct($forceReply = true, $selective = null, $inputFieldPlaceholder = null) { $this->forceReply = $forceReply; - $this->inputFieldPlaceholder = $inputFieldPlaceholder; $this->selective = $selective; + $this->inputFieldPlaceholder = $inputFieldPlaceholder; } /** @@ -74,7 +75,7 @@ public function isForceReply() { return $this->forceReply; } - + /** * @param bool $forceReply * @return void @@ -102,14 +103,14 @@ public function setSelective($selective) } /** - * @param string $inputFieldPlaceholder + * @param string|null $inputFieldPlaceholder * @return void */ public function setInputFieldPlaceholder($inputFieldPlaceholder) { $this->inputFieldPlaceholder = $inputFieldPlaceholder; } - + /** * @return string|null */ diff --git a/tests/Types/ForceReplyTest.php b/tests/Types/ForceReplyTest.php index 632025be..0215c3d8 100644 --- a/tests/Types/ForceReplyTest.php +++ b/tests/Types/ForceReplyTest.php @@ -23,6 +23,7 @@ public static function getFullResponse() { return [ 'force_reply' => true, + 'input_field_placeholder' => 'input_field_placeholder', 'selective' => true ]; } @@ -35,6 +36,7 @@ protected function assertMinItem($item) { $this->assertEquals(true, $item->isForceReply()); $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); } /** @@ -45,6 +47,7 @@ protected function assertFullItem($item) { $this->assertEquals(true, $item->isForceReply()); $this->assertEquals(true, $item->isSelective()); + $this->assertEquals('input_field_placeholder', $item->getInputFieldPlaceholder()); } public function testConstructor() @@ -53,6 +56,7 @@ public function testConstructor() $this->assertEquals(true, $item->isForceReply()); $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); } public function testConstructor2() @@ -61,6 +65,7 @@ public function testConstructor2() $this->assertEquals(true, $item->isForceReply()); $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); } public function testConstructor3() @@ -69,6 +74,7 @@ public function testConstructor3() $this->assertEquals(false, $item->isForceReply()); $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); } public function testConstructor4() @@ -77,6 +83,7 @@ public function testConstructor4() $this->assertEquals(true, $item->isForceReply()); $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); } public function testSetforceReply() From 117b20e42e8e73ec4616afecf09a2ef27ba68e9d Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 9 Aug 2023 16:51:42 +0300 Subject: [PATCH 114/130] Prepare release --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f448f3..0f532937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file -## 2.5.0 - YYYY-MM-DD +## 2.5.0 - 2023-08-09 ### Added - Add missing `protect_content` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods diff --git a/composer.json b/composer.json index eb8c286b..252b7ea0 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "2.5-dev" } } } From e9f7838937a1edf95fbcaa620f414f43fbd81c9f Mon Sep 17 00:00:00 2001 From: BoShurik Date: Mon, 4 Sep 2023 16:31:53 +0300 Subject: [PATCH 115/130] my_chat_member, chat_member, chat_join_request updates and invite link methods --- CHANGELOG.md | 10 ++ composer.json | 9 +- src/BotApi.php | 112 ++++++++++++ src/Types/ChatInviteLink.php | 249 ++++++++++++++++++++++++++ src/Types/ChatJoinRequest.php | 174 ++++++++++++++++++ src/Types/ChatMemberUpdated.php | 199 ++++++++++++++++++++ src/Types/Update.php | 78 ++++++++ tests/Types/ChatInviteLinkTest.php | 74 ++++++++ tests/Types/ChatJoinRequestTest.php | 64 +++++++ tests/Types/ChatMemberUpdatedTest.php | 68 +++++++ tests/Types/UpdateTest.php | 13 +- 11 files changed, 1046 insertions(+), 4 deletions(-) create mode 100644 src/Types/ChatInviteLink.php create mode 100644 src/Types/ChatJoinRequest.php create mode 100644 src/Types/ChatMemberUpdated.php create mode 100644 tests/Types/ChatInviteLinkTest.php create mode 100644 tests/Types/ChatJoinRequestTest.php create mode 100644 tests/Types/ChatMemberUpdatedTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f532937..0a092388 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file +## 2.6.0 - YYYY-MM-DD +- Add `\TelegramBot\Api\Types\Update::$myChatMember` field +- Add `\TelegramBot\Api\Types\Update::$chatMember` field +- Add `\TelegramBot\Api\Types\Update::$chatJoinRequest` field +- Add `\TelegramBot\Api\BotApi::createChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::editChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::revokeChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::approveChatJoinRequest` api method +- Add `\TelegramBot\Api\BotApi::declineChatJoinRequest` api method + ## 2.5.0 - 2023-08-09 ### Added diff --git a/composer.json b/composer.json index 252b7ea0..24abe76d 100644 --- a/composer.json +++ b/composer.json @@ -42,11 +42,16 @@ "coverage": "XDEBUG_MODE=coverage vendor/bin/simple-phpunit --coverage-html build/coverage", "psalm": "vendor/bin/psalm", "cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi", - "cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run" + "cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run", + "checks": [ + "@cs-fix", + "@psalm", + "@test" + ] }, "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } } } diff --git a/src/BotApi.php b/src/BotApi.php index 45feaa58..53ef612f 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -10,6 +10,7 @@ use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\BotCommand; use TelegramBot\Api\Types\Chat; +use TelegramBot\Api\Types\ChatInviteLink; use TelegramBot\Api\Types\ChatMember; use TelegramBot\Api\Types\File; use TelegramBot\Api\Types\ForceReply; @@ -2126,6 +2127,117 @@ public function exportChatInviteLink($chatId) ]); } + /** + * Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat + * for this to work and must have the appropriate administrator rights. + * The link can be revoked using the method revokeChatInviteLink. + * Returns the new invite link as ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string|null $name Invite link name; 0-32 characters + * @param int|null $expireDate Point in time (Unix timestamp) when the link will expire + * @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously + * after joining the chat via this invite link; 1-99999 + * @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators. + * If True, member_limit can't be specified + * @return ChatInviteLink + * @throws Exception + */ + public function createChatInviteLink($chatId, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null) + { + return ChatInviteLink::fromResponse($this->call('createChatInviteLink', [ + 'chat_id' => $chatId, + 'name' => $name, + 'expire_date' => $expireDate, + 'member_limit' => $memberLimit, + 'creates_join_request' => $createsJoinRequest, + ])); + } + + /** + * Use this method to edit a non-primary invite link created by the bot. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Returns the edited invite link as a ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string $inviteLink The invite link to edit + * @param string|null $name Invite link name; 0-32 characters + * @param int|null $expireDate Point in time (Unix timestamp) when the link will expire + * @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously + * after joining the chat via this invite link; 1-99999 + * @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators. + * If True, member_limit can't be specified + * @return ChatInviteLink + * @throws Exception + */ + public function editChatInviteLink($chatId, $inviteLink, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null) + { + return ChatInviteLink::fromResponse($this->call('editChatInviteLink', [ + 'chat_id' => $chatId, + 'invite_link' => $inviteLink, + 'name' => $name, + 'expire_date' => $expireDate, + 'member_limit' => $memberLimit, + 'creates_join_request' => $createsJoinRequest, + ])); + } + + /** + * Use this method to revoke an invite link created by the bot. + * If the primary link is revoked, a new link is automatically generated. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Returns the revoked invite link as ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string $inviteLink The invite link to edit + * @return ChatInviteLink + * @throws Exception + */ + public function revokeChatInviteLink($chatId, $inviteLink) + { + return ChatInviteLink::fromResponse($this->call('revokeChatInviteLink', [ + 'chat_id' => $chatId, + 'invite_link' => $inviteLink, + ])); + } + + /** + * Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and + * must have the can_invite_users administrator right. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * @return bool + * @throws Exception + */ + public function approveChatJoinRequest($chatId, $userId) + { + return $this->call('approveChatJoinRequest', [ + 'chat_id' => $chatId, + 'user_id' => $userId, + ]); + } + + /** + * Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and + * must have the can_invite_users administrator right. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * @return bool + * @throws Exception + */ + public function declineChatJoinRequest($chatId, $userId) + { + return $this->call('declineChatJoinRequest', [ + 'chat_id' => $chatId, + 'user_id' => $userId, + ]); + } + /** * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. diff --git a/src/Types/ChatInviteLink.php b/src/Types/ChatInviteLink.php new file mode 100644 index 00000000..4cbfbbe5 --- /dev/null +++ b/src/Types/ChatInviteLink.php @@ -0,0 +1,249 @@ + 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 $inviteLink; + + /** + * 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 bool + */ + protected $createsJoinRequest; + + /** + * True, if the link is primary + * + * @var bool + */ + protected $isPrimary; + + /** + * True, if the link is revoked + * + * @var bool + */ + protected $isRevoked; + + /** + * Optional. Invite link name + * + * @var string|null + */ + protected $name; + + /** + * Optional. Point in time (Unix timestamp) when the link will expire or has been expired + * + * @var int|null + */ + protected $expireDate; + + /** + * Optional. The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 + * + * @var int|null + */ + protected $memberLimit; + + /** + * Optional. Number of pending join requests created using this link + * + * @var int|null + */ + protected $pendingJoinRequestCount; + + /** + * @return string + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param string $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } + + /** + * @return User + */ + public function getCreator() + { + return $this->creator; + } + + /** + * @param User $creator + * @return void + */ + public function setCreator($creator) + { + $this->creator = $creator; + } + + /** + * @return bool + */ + public function getCreatesJoinRequest() + { + return $this->createsJoinRequest; + } + + /** + * @param bool $createsJoinRequest + * @return void + */ + public function setCreatesJoinRequest($createsJoinRequest) + { + $this->createsJoinRequest = $createsJoinRequest; + } + + /** + * @return bool + */ + public function isPrimary() + { + return $this->isPrimary; + } + + /** + * @param bool $isPrimary + * @return void + */ + public function setIsPrimary($isPrimary) + { + $this->isPrimary = $isPrimary; + } + + /** + * @return bool + */ + public function isRevoked() + { + return $this->isRevoked; + } + + /** + * @param bool $isRevoked + * @return void + */ + public function setIsRevoked($isRevoked) + { + $this->isRevoked = $isRevoked; + } + + /** + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * @param string|null $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int|null + */ + public function getExpireDate() + { + return $this->expireDate; + } + + /** + * @param int|null $expireDate + * @return void + */ + public function setExpireDate($expireDate) + { + $this->expireDate = $expireDate; + } + + /** + * @return int|null + */ + public function getMemberLimit() + { + return $this->memberLimit; + } + + /** + * @param int|null $memberLimit + * @return void + */ + public function setMemberLimit($memberLimit) + { + $this->memberLimit = $memberLimit; + } + + /** + * @return int|null + */ + public function getPendingJoinRequestCount() + { + return $this->pendingJoinRequestCount; + } + + /** + * @param int|null $pendingJoinRequestCount + * @return void + */ + public function setPendingJoinRequestCount($pendingJoinRequestCount) + { + $this->pendingJoinRequestCount = $pendingJoinRequestCount; + } +} diff --git a/src/Types/ChatJoinRequest.php b/src/Types/ChatJoinRequest.php new file mode 100644 index 00000000..76b33718 --- /dev/null +++ b/src/Types/ChatJoinRequest.php @@ -0,0 +1,174 @@ + Chat::class, + 'from' => User::class, + 'user_chat_id' => true, + '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; + + /** + * Identifier of a private chat with the user who sent the join request. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot can use this identifier for 24 hours to send messages until the join request is processed, assuming no other administrator contacted the user. + * + * @var int + */ + protected $userChatId; + + /** + * Date the request was sent in Unix time + * + * @var int + */ + protected $date; + + /** + * Optional. Bio of the user. + * + * @var string|null + */ + protected $bio; + + /** + * Optional. Chat invite link that was used by the user to send the join request + * + * @var ChatInviteLink|null + */ + protected $inviteLink; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + * @return void + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * @return int + */ + public function getUserChatId() + { + return $this->userChatId; + } + + /** + * @param int $userChatId + * @return void + */ + public function setUserChatId($userChatId) + { + $this->userChatId = $userChatId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return string|null + */ + public function getBio() + { + return $this->bio; + } + + /** + * @param string|null $bio + * @return void + */ + public function setBio($bio) + { + $this->bio = $bio; + } + + /** + * @return ChatInviteLink|null + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param ChatInviteLink|null $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } +} diff --git a/src/Types/ChatMemberUpdated.php b/src/Types/ChatMemberUpdated.php new file mode 100644 index 00000000..2c3ffb86 --- /dev/null +++ b/src/Types/ChatMemberUpdated.php @@ -0,0 +1,199 @@ + Chat::class, + 'from' => User::class, + 'date' => true, + 'old_chat_member' => ChatMember::class, + 'new_chat_member' => ChatMember::class, + 'invite_link' => ChatInviteLink::class, + 'via_chat_folder_invite_link' => true, + ]; + + /** + * 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 int + */ + protected $date; + + /** + * Previous information about the chat member + * + * @var ChatMember + */ + protected $oldChatMember; + + /** + * New information about the chat member + * + * @var ChatMember + */ + protected $newChatMember; + + /** + * Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events only. + * + * @var ChatInviteLink|null + */ + protected $inviteLink; + + /** + * Optional. True, if the user joined the chat via a chat folder invite link + * + * @var bool|null + */ + protected $viaChatFolderInviteLink; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + * @return void + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return ChatMember + */ + public function getOldChatMember() + { + return $this->oldChatMember; + } + + /** + * @param ChatMember $oldChatMember + * @return void + */ + public function setOldChatMember($oldChatMember) + { + $this->oldChatMember = $oldChatMember; + } + + /** + * @return ChatMember + */ + public function getNewChatMember() + { + return $this->newChatMember; + } + + /** + * @param ChatMember $newChatMember + * @return void + */ + public function setNewChatMember($newChatMember) + { + $this->newChatMember = $newChatMember; + } + + /** + * @return ChatInviteLink|null + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param ChatInviteLink|null $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } + + /** + * @return bool|null + */ + public function getViaChatFolderInviteLink() + { + return $this->viaChatFolderInviteLink; + } + + /** + * @param bool|null $viaChatFolderInviteLink + * @return void + */ + public function setViaChatFolderInviteLink($viaChatFolderInviteLink) + { + $this->viaChatFolderInviteLink = $viaChatFolderInviteLink; + } +} diff --git a/src/Types/Update.php b/src/Types/Update.php index 3d324d90..4138ed07 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -43,6 +43,9 @@ class Update extends BaseType implements TypeInterface 'pre_checkout_query' => PreCheckoutQuery::class, 'poll_answer' => PollAnswer::class, 'poll' => Poll::class, + 'my_chat_member' => ChatMemberUpdated::class, + 'chat_member' => ChatMemberUpdated::class, + 'chat_join_request' => ChatJoinRequest::class, ]; /** @@ -132,6 +135,30 @@ class Update extends BaseType implements TypeInterface */ protected $preCheckoutQuery; + /** + * Optional. 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. + * + * @var ChatMemberUpdated|null + */ + protected $myChatMember; + + /** + * Optional. A chat member's status was updated in a chat. The bot must be an administrator in the chat and must + * explicitly specify “chat_member” in the list of allowed_updates to receive these updates. + * + * @var ChatMemberUpdated|null + */ + protected $chatMember; + + /** + * 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|null + */ + protected $chatJoinRequest; + /** * @return int */ @@ -355,4 +382,55 @@ public function setPreCheckoutQuery($preCheckoutQuery) { $this->preCheckoutQuery = $preCheckoutQuery; } + + /** + * @return ChatMemberUpdated|null + */ + public function getMyChatMember() + { + return $this->myChatMember; + } + + /** + * @param ChatMemberUpdated|null $myChatMember + * @return void + */ + public function setMyChatMember($myChatMember) + { + $this->myChatMember = $myChatMember; + } + + /** + * @return ChatMemberUpdated|null + */ + public function getChatMember() + { + return $this->chatMember; + } + + /** + * @param ChatMemberUpdated|null $chatMember + * @return void + */ + public function setChatMember($chatMember) + { + $this->chatMember = $chatMember; + } + + /** + * @return ChatJoinRequest|null + */ + public function getChatJoinRequest() + { + return $this->chatJoinRequest; + } + + /** + * @param ChatJoinRequest|null $chatJoinRequest + * @return void + */ + public function setChatJoinRequest($chatJoinRequest) + { + $this->chatJoinRequest = $chatJoinRequest; + } } diff --git a/tests/Types/ChatInviteLinkTest.php b/tests/Types/ChatInviteLinkTest.php new file mode 100644 index 00000000..459d62bd --- /dev/null +++ b/tests/Types/ChatInviteLinkTest.php @@ -0,0 +1,74 @@ + 'invite_link', + 'creator' => UserTest::getMinResponse(), + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + ]; + } + + public static function getFullResponse() + { + return [ + 'invite_link' => 'invite_link', + 'creator' => UserTest::getMinResponse(), + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + 'name' => 'name', + 'expire_date' => 100500, + 'member_limit' => 10, + 'pending_join_request_count' => 10, + ]; + } + + /** + * @param ChatInviteLink $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('invite_link', $item->getInviteLink()); + $this->assertEquals(UserTest::createMinInstance(), $item->getCreator()); + $this->assertTrue($item->getCreatesJoinRequest()); + $this->assertTrue($item->isPrimary()); + $this->assertTrue($item->isRevoked()); + $this->assertNull($item->getName()); + $this->assertNull($item->getExpireDate()); + $this->assertNull($item->getMemberLimit()); + $this->assertNull($item->getPendingJoinRequestCount()); + } + + /** + * @param ChatInviteLink $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('invite_link', $item->getInviteLink()); + $this->assertEquals(UserTest::createMinInstance(), $item->getCreator()); + $this->assertTrue($item->getCreatesJoinRequest()); + $this->assertTrue($item->isPrimary()); + $this->assertTrue($item->isRevoked()); + $this->assertEquals('name', $item->getName()); + $this->assertEquals(100500, $item->getExpireDate()); + $this->assertEquals(10, $item->getMemberLimit()); + $this->assertEquals(10, $item->getPendingJoinRequestCount()); + } +} diff --git a/tests/Types/ChatJoinRequestTest.php b/tests/Types/ChatJoinRequestTest.php new file mode 100644 index 00000000..faaa52fe --- /dev/null +++ b/tests/Types/ChatJoinRequestTest.php @@ -0,0 +1,64 @@ + ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'user_chat_id' => 10, + 'date' => 100500, + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'user_chat_id' => 10, + 'date' => 100500, + 'bio' => 'bio', + 'invite_link' => ChatInviteLinkTest::getMinResponse(), + ]; + } + + /** + * @param ChatJoinRequest $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(10, $item->getUserChatId()); + $this->assertEquals(100500, $item->getDate()); + $this->assertNull($item->getBio()); + $this->assertNull($item->getInviteLink()); + } + + /** + * @param ChatJoinRequest $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(10, $item->getUserChatId()); + $this->assertEquals(100500, $item->getDate()); + $this->assertEquals('bio', $item->getBio()); + $this->assertEquals(ChatInviteLinkTest::createMinInstance(), $item->getInviteLink()); + } +} diff --git a/tests/Types/ChatMemberUpdatedTest.php b/tests/Types/ChatMemberUpdatedTest.php new file mode 100644 index 00000000..8f80f995 --- /dev/null +++ b/tests/Types/ChatMemberUpdatedTest.php @@ -0,0 +1,68 @@ + ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'date' => 100500, + 'old_chat_member' => ChatMemberTest::getMinResponse(), + 'new_chat_member' => ChatMemberTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'date' => 100500, + 'old_chat_member' => ChatMemberTest::getMinResponse(), + 'new_chat_member' => ChatMemberTest::getMinResponse(), + 'invite_link' => ChatInviteLinkTest::getMinResponse(), + 'via_chat_folder_invite_link' => true, + ]; + } + + /** + * @param ChatMemberUpdated $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(100500, $item->getDate()); + $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getOldChatMember()); + $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getNewChatMember()); + $this->assertNull($item->getInviteLink()); + $this->assertNull($item->getViaChatFolderInviteLink()); + } + + /** + * @param ChatMemberUpdated $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(100500, $item->getDate()); + $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getOldChatMember()); + $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getNewChatMember()); + $this->assertEquals(ChatInviteLinkTest::createMinInstance(), $item->getInviteLink()); + $this->assertTrue($item->getViaChatFolderInviteLink()); + } +} diff --git a/tests/Types/UpdateTest.php b/tests/Types/UpdateTest.php index 21a7ffbc..73852b3d 100644 --- a/tests/Types/UpdateTest.php +++ b/tests/Types/UpdateTest.php @@ -38,11 +38,14 @@ public static function getFullResponse() 'pre_checkout_query' => PreCheckoutQueryTest::getMinResponse(), 'poll_answer' => PollAnswerTest::getMinResponse(), 'poll' => PollTest::getMinResponse(), + 'my_chat_member' => ChatMemberUpdatedTest::getMinResponse(), + 'chat_member' => ChatMemberUpdatedTest::getMinResponse(), + 'chat_join_request' => ChatJoinRequestTest::getMinResponse(), ]; } /** - * @param $item + * @param Update $item * @return void */ protected function assertMinItem($item) @@ -59,10 +62,13 @@ protected function assertMinItem($item) $this->assertNull($item->getPreCheckoutQuery()); $this->assertNull($item->getPollAnswer()); $this->assertNull($item->getPoll()); + $this->assertNull($item->getMyChatMember()); + $this->assertNull($item->getChatMember()); + $this->assertNull($item->getChatJoinRequest()); } /** - * @param $item + * @param Update $item * @return void */ protected function assertFullItem($item) @@ -79,5 +85,8 @@ protected function assertFullItem($item) $this->assertEquals(PreCheckoutQueryTest::createMinInstance(), $item->getPreCheckoutQuery()); $this->assertEquals(PollAnswerTest::createMinInstance(), $item->getPollAnswer()); $this->assertEquals(PollTest::createMinInstance(), $item->getPoll()); + $this->assertEquals(ChatMemberUpdatedTest::createMinInstance(), $item->getMyChatMember()); + $this->assertEquals(ChatMemberUpdatedTest::createMinInstance(), $item->getChatMember()); + $this->assertEquals(ChatJoinRequestTest::createMinInstance(), $item->getChatJoinRequest()); } } From eb1fb3e9aec83eb465cca6e072ecde1b955176e3 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Fri, 28 Apr 2023 18:50:27 +0300 Subject: [PATCH 116/130] Local Bot API Server support Third-party http-client support window.Telegram.WebApp.initData validation --- .github/workflows/tests.yaml | 4 + .php-cs-fixer.dist.php | 2 + CHANGELOG.md | 3 + README.md | 44 +--- composer.json | 14 +- psalm.xml | 9 +- src/BotApi.php | 282 +++++++++++------------ src/Botan.php | 6 +- src/Client.php | 7 +- src/Events/EventCollection.php | 3 +- src/Http/AbstractHttpClient.php | 37 +++ src/Http/CurlHttpClient.php | 226 ++++++++++++++++++ src/Http/HttpClientInterface.php | 31 +++ src/Http/PsrHttpClient.php | 82 +++++++ src/Http/SymfonyHttpClient.php | 54 +++++ src/HttpException.php | 4 +- tests/BotApiTest.php | 33 ++- tests/Types/ArrayOfMessageEntityTest.php | 10 +- 18 files changed, 637 insertions(+), 214 deletions(-) create mode 100644 src/Http/AbstractHttpClient.php create mode 100644 src/Http/CurlHttpClient.php create mode 100644 src/Http/HttpClientInterface.php create mode 100644 src/Http/PsrHttpClient.php create mode 100644 src/Http/SymfonyHttpClient.php diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0072a66d..8b0618cf 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -59,6 +59,10 @@ jobs: name: Remove psalm run: composer remove vimeo/psalm --dev --no-update + - + name: Remove http client dependencies + run: composer remove psr/http-client psr/http-factory symfony/http-client guzzlehttp/guzzle --dev --no-update + - name: Install dependencies with composer run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 84419a13..0413b8d7 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -23,10 +23,12 @@ 'no_unused_imports' => true, 'single_quote' => true, 'no_extra_blank_lines' => true, + 'array_indentation' => true, 'cast_spaces' => true, 'phpdoc_align' => [ 'align' => 'left', ], 'binary_operator_spaces' => true, + 'single_line_empty_body' => false, ]) ; diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a092388..cafc20d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Add `\TelegramBot\Api\BotApi::revokeChatInviteLink` api method - Add `\TelegramBot\Api\BotApi::approveChatJoinRequest` api method - Add `\TelegramBot\Api\BotApi::declineChatJoinRequest` api method +- Add support for third party http clients (`psr/http-client` and `symfony/http-client`) +- Add support for local bot API server +- Add method `\TelegramBot\Api\BotApi::validateWebAppData` to validate `window.Telegram.WebApp.initData` ## 2.5.0 - 2023-08-09 diff --git a/README.md b/README.md index 7524749e..f3b7bf04 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,6 @@ require_once "vendor/autoload.php"; try { $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN'); - // or initialize with botan.io tracker api key - // $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY'); - //Handle /ping command $bot->command('ping', function ($message) use ($bot) { @@ -107,45 +104,26 @@ try { } ``` -### Botan SDK (not supported more) - -[Botan](http://botan.io) is a telegram bot analytics system based on [Yandex.Appmetrica](http://appmetrica.yandex.com/). -In this document you can find how to setup Yandex.Appmetrica account, as well as examples of Botan SDK usage. - -### Creating an account - * Register at http://appmetrica.yandex.com/ - * After registration you will be prompted to create Application. Please use @YourBotName as a name. - * Save an API key from settings page, you will use it as a token for Botan API calls. - * Download lib for your language, and use it as described below. Don`t forget to insert your token! - -Since we are only getting started, you may discover that some existing reports in AppMetriсa aren't properly working for Telegram bots, like Geography, Gender, Age, Library, Devices, Traffic sources and Network sections. We will polish that later. - -## SDK usage - -#### Standalone +#### Local Bot API Server -```php -$tracker = new \TelegramBot\Api\Botan('YOUR_BOTAN_TRACKER_API_KEY'); - -$tracker->track($message, $eventName); -``` +For using custom [local bot API server](https://core.telegram.org/bots/api#using-a-local-bot-api-server) -#### API Wrapper ```php -$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY'); - -$bot->track($message, $eventName); +use TelegramBot\Api\Client; +$token = 'YOUR_BOT_API_TOKEN'; +$bot = new Client($token, null, null, 'http://localhost:8081'); ``` - You can use method 'getUpdates()'and all incoming messages will be automatically tracked as `Message`-event. +#### Third-party Http Client -#### Client ```php -$bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY'); +use Symfony\Component\HttpClient\HttpClient; +use TelegramBot\Api\BotApi; +use TelegramBot\Api\Http\SymfonyHttpClient; +$token = 'YOUR_BOT_API_TOKEN'; +$bot = new Client($token, null, new SymfonyHttpClient(HttpClient::create());); ``` -_All registered commands are automatically tracked as command name_ - ## Change log Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. diff --git a/composer.json b/composer.json index 24abe76d..b835131b 100644 --- a/composer.json +++ b/composer.json @@ -24,8 +24,18 @@ }, "require-dev": { "symfony/phpunit-bridge" : "*", - "friendsofphp/php-cs-fixer": "^3.16", - "vimeo/psalm": "^5.9" + "friendsofphp/php-cs-fixer": "~3.28.0", + "vimeo/psalm": "^5.9", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", + "symfony/http-client": "^4.3 | ^5.0 | ^6.0", + "guzzlehttp/guzzle": "^7.0" + }, + "suggest": { + "psr/http-client": "To use psr/http-client", + "psr/http-factory": "To use psr/http-client", + "guzzlehttp/guzzle": "To use psr/http-client", + "symfony/http-client": "To use symfony/http-client" }, "autoload": { "psr-4": { diff --git a/psalm.xml b/psalm.xml index ef3650df..d0e78e7a 100644 --- a/psalm.xml +++ b/psalm.xml @@ -19,10 +19,9 @@ - - - - - + + + + diff --git a/src/BotApi.php b/src/BotApi.php index 53ef612f..1e2c3237 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -2,6 +2,8 @@ namespace TelegramBot\Api; +use TelegramBot\Api\Http\CurlHttpClient; +use TelegramBot\Api\Http\HttpClientInterface; use TelegramBot\Api\Types\ArrayOfBotCommand; use TelegramBot\Api\Types\ArrayOfChatMemberEntity; use TelegramBot\Api\Types\ArrayOfMessageEntity; @@ -41,6 +43,8 @@ class BotApi { /** + * @deprecated + * * HTTP codes * * @var array @@ -113,57 +117,59 @@ class BotApi ]; /** - * @var array + * Url prefixes */ - private $proxySettings = []; + const URL_PREFIX = 'https://api.telegram.org/bot'; + + /** + * Url prefix for files + */ + const FILE_URL_PREFIX = 'https://api.telegram.org/file/bot'; /** + * @deprecated + * * Default http status code */ const DEFAULT_STATUS_CODE = 200; /** + * @deprecated + * * Not Modified http status code */ const NOT_MODIFIED_STATUS_CODE = 304; /** + * @deprecated + * * Limits for tracked ids */ const MAX_TRACKED_EVENTS = 200; /** - * Url prefixes + * @var HttpClientInterface */ - const URL_PREFIX = 'https://api.telegram.org/bot'; + private $httpClient; /** - * Url prefix for files + * @var string */ - const FILE_URL_PREFIX = 'https://api.telegram.org/file/bot'; + private $token; /** - * CURL object - * - * @var resource + * @var string */ - protected $curl; + private $endpoint; /** - * CURL custom options - * - * @var array + * @var string|null */ - protected $customCurlOptions = []; + private $fileEndpoint; /** - * Bot token + * @deprecated * - * @var string - */ - protected $token; - - /** * Botan tracker * * @var Botan|null @@ -171,6 +177,8 @@ class BotApi protected $tracker; /** + * @deprecated + * * list of event ids * * @var array @@ -178,23 +186,18 @@ class BotApi protected $trackedEvents = []; /** - * Check whether return associative array - * - * @var bool - */ - protected $returnArray = true; - - /** - * Constructor - * * @param string $token Telegram Bot API token * @param string|null $trackerToken Yandex AppMetrica application api_key - * @throws \Exception + * @param HttpClientInterface|null $httpClient + * @param string|null $endpoint */ - public function __construct($token, $trackerToken = null) + public function __construct($token, $trackerToken = null, HttpClientInterface $httpClient = null, $endpoint = null) { - $this->curl = curl_init(); $this->token = $token; + $this->endpoint = ($endpoint ?: self::URL_PREFIX) . $token; + $this->fileEndpoint = $endpoint ? null : (self::FILE_URL_PREFIX . $token); + + $this->httpClient = $httpClient ?: new CurlHttpClient(); if ($trackerToken) { @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); @@ -203,6 +206,36 @@ public function __construct($token, $trackerToken = null) } /** + * @param string $rawData + * @param int|null $authDateDiff + * @return bool + */ + public function validateWebAppData($rawData, $authDateDiff = null) + { + parse_str($rawData, $data); + + $sign = $data['hash']; + unset($data['hash']); + + if ($authDateDiff && (time() - $data['auth_date'] > $authDateDiff)) { + return false; + } + + ksort($data); + $checkString = ''; + foreach ($data as $k => $v) { + $checkString .= "$k=$v\n"; + } + $checkString = trim($checkString); + + $secret = hash_hmac('sha256', $this->token, 'WebAppData', true); + + return bin2hex(hash_hmac('sha256', $checkString, $secret, true)) === $sign; + } + + /** + * @deprecated + * * Set return array * * @param bool $mode @@ -211,83 +244,62 @@ public function __construct($token, $trackerToken = null) */ public function setModeObject($mode = true) { - $this->returnArray = !$mode; + @trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED); return $this; } /** + * @deprecated + * * Call method * * @param string $method * @param array|null $data - * @param int $timeout + * @param int|null $timeout * * @return mixed * @throws Exception * @throws HttpException * @throws InvalidJsonException */ - public function call($method, array $data = null, $timeout = 10) + public function call($method, array $data = null, $timeout = null) { - $options = $this->proxySettings + [ - CURLOPT_URL => $this->getUrl().'/'.$method, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_POST => null, - CURLOPT_POSTFIELDS => null, - CURLOPT_TIMEOUT => $timeout, - ]; - - if ($data) { - $options[CURLOPT_POST] = true; - $options[CURLOPT_POSTFIELDS] = $data; - } - - if (!empty($this->customCurlOptions)) { - $options = $this->customCurlOptions + $options; + if ($timeout !== null) { + @trigger_error(sprintf('Passing $timeout parameter in %s::%s is deprecated. Use http client options', __CLASS__, __METHOD__), \E_USER_DEPRECATED); } - $response = self::jsonValidate($this->executeCurl($options), $this->returnArray); - - if (\is_array($response)) { - if (!isset($response['ok']) || !$response['ok']) { - throw new Exception($response['description'], $response['error_code']); - } - - return $response['result']; - } + $endpoint = $this->endpoint . '/' . $method; - if (!$response->ok) { - throw new Exception($response->description, $response->error_code); - } - - return $response->result; + return $this->httpClient->request($endpoint, $data); } /** - * curl_exec wrapper for response validation + * Get file contents via cURL * - * @param array $options + * @param string $fileId * * @return string * * @throws HttpException + * @throws Exception */ - protected function executeCurl(array $options) + public function downloadFile($fileId) { - curl_setopt_array($this->curl, $options); - - /** @var string|false $result */ - $result = curl_exec($this->curl); - self::curlValidate($this->curl, $result); - if ($result === false) { - throw new HttpException(curl_error($this->curl), curl_errno($this->curl)); + $file = $this->getFile($fileId); + if (!$path = $file->getFilePath()) { + throw new Exception('Empty file_path property'); + } + if (!$this->fileEndpoint) { + return file_get_contents($path); } - return $result; + return $this->httpClient->download($this->fileEndpoint . '/' . $path); } /** + * @deprecated + * * Response validation * * @param resource $curl @@ -299,6 +311,8 @@ protected function executeCurl(array $options) */ public static function curlValidate($curl, $response = null) { + @trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + if ($response) { $json = json_decode($response, true) ?: []; } else { @@ -1426,29 +1440,6 @@ public function getFile($fileId) return File::fromResponse($this->call('getFile', ['file_id' => $fileId])); } - /** - * Get file contents via cURL - * - * @param string $fileId - * - * @return string - * - * @throws HttpException - * @throws Exception - */ - public function downloadFile($fileId) - { - $file = $this->getFile($fileId); - $options = [ - CURLOPT_HEADER => 0, - CURLOPT_HTTPGET => 1, - CURLOPT_RETURNTRANSFER => 1, - CURLOPT_URL => $this->getFileUrl().'/'.$file->getFilePath(), - ]; - - return $this->executeCurl($options); - } - /** * Use this method to send answers to an inline query. On success, True is returned. * No more than 50 results per query are allowed. @@ -1814,30 +1805,8 @@ public function deleteMessage($chatId, $messageId) } /** - * Close curl - */ - public function __destruct() - { - curl_close($this->curl); - } - - /** - * @return string - */ - public function getUrl() - { - return self::URL_PREFIX.$this->token; - } - - /** - * @return string - */ - public function getFileUrl() - { - return self::FILE_URL_PREFIX.$this->token; - } - - /** + * @deprecated + * * @param Update $update * @param string $eventName * @@ -1847,6 +1816,8 @@ public function getFileUrl() */ public function trackUpdate(Update $update, $eventName = 'Message') { + @trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + if (!in_array($update->getUpdateId(), $this->trackedEvents)) { $message = $update->getMessage(); if (!$message) { @@ -1863,6 +1834,8 @@ public function trackUpdate(Update $update, $eventName = 'Message') } /** + * @deprecated + * * Wrapper for tracker * * @param Message $message @@ -1874,6 +1847,8 @@ public function trackUpdate(Update $update, $eventName = 'Message') */ public function track(Message $message, $eventName = 'Message') { + @trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + if ($this->tracker instanceof Botan) { $this->tracker->track($message, $eventName); } @@ -2545,32 +2520,6 @@ public function sendMediaGroup( ] + $attachments)); } - /** - * Enable proxy for curl requests. Empty string will disable proxy. - * - * @param string $proxyString - * @param bool $socks5 - * - * @return BotApi - */ - public function setProxy($proxyString = '', $socks5 = false) - { - if (empty($proxyString)) { - $this->proxySettings = []; - return $this; - } - - $this->proxySettings = [ - CURLOPT_PROXY => $proxyString, - CURLOPT_HTTPPROXYTUNNEL => true, - ]; - - if ($socks5) { - $this->proxySettings[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5; - } - return $this; - } - /** * Use this method to send a native poll. A native poll can't be sent to a private chat. * On success, the sent \TelegramBot\Api\Types\Message is returned. @@ -2882,6 +2831,25 @@ public function answerWebAppQuery($webAppQueryId, $result) ])); } + /** + * Enable proxy for curl requests. Empty string will disable proxy. + * + * @param string $proxyString + * @param bool $socks5 + * + * @return BotApi + */ + public function setProxy($proxyString = '', $socks5 = false) + { + @trigger_error(sprintf('Method "%s:%s" is deprecated. Manage options on HttpClient instance', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if (method_exists($this->httpClient, 'setProxy')) { + $this->httpClient->setProxy($proxyString, $socks5); + } + + return $this; + } + /** * Set an option for a cURL transfer * @@ -2892,7 +2860,11 @@ public function answerWebAppQuery($webAppQueryId, $result) */ public function setCurlOption($option, $value) { - $this->customCurlOptions[$option] = $value; + @trigger_error(sprintf('Method "%s:%s" is deprecated. Manage options on http client instance', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if (method_exists($this->httpClient, 'setOption')) { + $this->httpClient->setOption($option, $value); + } } /** @@ -2904,7 +2876,11 @@ public function setCurlOption($option, $value) */ public function unsetCurlOption($option) { - unset($this->customCurlOptions[$option]); + @trigger_error(sprintf('Method "%s:%s" is deprecated. Manage options on http client instance', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if (method_exists($this->httpClient, 'unsetOption')) { + $this->httpClient->unsetOption($option); + } } /** @@ -2914,6 +2890,10 @@ public function unsetCurlOption($option) */ public function resetCurlOptions() { - $this->customCurlOptions = []; + @trigger_error(sprintf('Method "%s:%s" is deprecated. Manage options on http client instance', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if (method_exists($this->httpClient, 'resetOptions')) { + $this->httpClient->resetOptions(); + } } } diff --git a/src/Botan.php b/src/Botan.php index 87665207..efc9f67f 100644 --- a/src/Botan.php +++ b/src/Botan.php @@ -34,14 +34,10 @@ class Botan * * @param string $token * - * @throws \Exception + * @throws InvalidArgumentException */ public function __construct($token) { - if (!function_exists('curl_version')) { - throw new Exception('CURL not installed'); - } - if (empty($token)) { throw new InvalidArgumentException('Token should not be empty'); } diff --git a/src/Client.php b/src/Client.php index 33322d86..c81abd68 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,6 +5,7 @@ use Closure; use ReflectionFunction; use TelegramBot\Api\Events\EventCollection; +use TelegramBot\Api\Http\HttpClientInterface; use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; @@ -40,13 +41,15 @@ class Client * * @param string $token Telegram Bot API token * @param string|null $trackerToken Yandex AppMetrica application api_key + * @param HttpClientInterface|null $httpClient + * @param string|null $endpoint */ - public function __construct($token, $trackerToken = null) + public function __construct($token, $trackerToken = null, HttpClientInterface $httpClient = null, $endpoint = null) { if ($trackerToken) { @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); } - $this->api = new BotApi($token); + $this->api = new BotApi($token, $trackerToken, $httpClient, $endpoint); $this->events = new EventCollection($trackerToken); } diff --git a/src/Events/EventCollection.php b/src/Events/EventCollection.php index af0481d4..510854d5 100644 --- a/src/Events/EventCollection.php +++ b/src/Events/EventCollection.php @@ -48,8 +48,7 @@ public function __construct($trackerToken = null) public function add(Closure $event, $checker = null) { $this->events[] = !is_null($checker) ? new Event($event, $checker) - : new Event($event, function () { - }); + : new Event($event, function () {}); return $this; } diff --git a/src/Http/AbstractHttpClient.php b/src/Http/AbstractHttpClient.php new file mode 100644 index 00000000..6c04bcc2 --- /dev/null +++ b/src/Http/AbstractHttpClient.php @@ -0,0 +1,37 @@ +doRequest($url, $data); + + if (!isset($response['ok']) || !$response['ok']) { + throw new Exception($response['description'], $response['error_code']); + } + + return $response['result']; + } + + public function download($url) + { + return $this->doDownload($url); + } + + /** + * @param string $url + * @param array|null $data + * @return array + */ + abstract protected function doRequest($url, array $data = null); + + /** + * @param string $url + * @return string + */ + abstract protected function doDownload($url); +} diff --git a/src/Http/CurlHttpClient.php b/src/Http/CurlHttpClient.php new file mode 100644 index 00000000..910afda2 --- /dev/null +++ b/src/Http/CurlHttpClient.php @@ -0,0 +1,226 @@ + 'Continue', + 101 => 'Switching Protocols', + 102 => 'Processing', // RFC2518 + // Success 2xx + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 207 => 'Multi-Status', // RFC4918 + 208 => 'Already Reported', // RFC5842 + 226 => 'IM Used', // RFC3229 + // Redirection 3xx + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', // 1.1 + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + // 306 is deprecated but reserved + 307 => 'Temporary Redirect', + 308 => 'Permanent Redirect', // RFC7238 + // Client Error 4xx + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Payload Too Large', + 414 => 'URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Range Not Satisfiable', + 417 => 'Expectation Failed', + 422 => 'Unprocessable Entity', // RFC4918 + 423 => 'Locked', // RFC4918 + 424 => 'Failed Dependency', // RFC4918 + 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 + 426 => 'Upgrade Required', // RFC2817 + 428 => 'Precondition Required', // RFC6585 + 429 => 'Too Many Requests', // RFC6585 + 431 => 'Request Header Fields Too Large', // RFC6585 + // Server Error 5xx + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 + 507 => 'Insufficient Storage', // RFC4918 + 508 => 'Loop Detected', // RFC5842 + 510 => 'Not Extended', // RFC2774 + 511 => 'Network Authentication Required', // RFC6585 + ]; + + /** + * Default http status code + */ + const DEFAULT_STATUS_CODE = 200; + + /** + * Not Modified http status code + */ + const NOT_MODIFIED_STATUS_CODE = 304; + + /** + * CURL object + * + * @var resource + */ + private $curl; + + /** + * @var array + */ + private $options; + + public function __construct(array $options = []) + { + $this->curl = curl_init(); + $this->options = $options; + } + + /** + * @inheritDoc + */ + protected function doRequest($url, array $data = null) + { + $options = $this->options + [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + ]; + + if ($data) { + $options[CURLOPT_POST] = true; + $options[CURLOPT_POSTFIELDS] = $data; + } + + return self::jsonValidate($this->execute($options)); + } + + /** + * @inheritDoc + */ + protected function doDownload($url) + { + $options = [ + CURLOPT_HEADER => false, + CURLOPT_HTTPGET => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_URL => $url, + ]; + + return $this->execute($options); + } + + /** + * @param array $options + * @return string + * @throws HttpException + */ + private function execute(array $options) + { + curl_setopt_array($this->curl, $options); + + /** @var string|false $result */ + $result = curl_exec($this->curl); + if ($result === false) { + throw new HttpException(curl_error($this->curl), curl_errno($this->curl)); + } + + self::curlValidate($this->curl, $result); + + return $result; + } + + /** + * @param string $jsonString + * @return array + * @throws InvalidJsonException + */ + private static function jsonValidate($jsonString) + { + /** @var array $json */ + $json = json_decode($jsonString, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new InvalidJsonException(json_last_error_msg(), json_last_error()); + } + + return $json; + } + + /** + * @param resource $curl + * @param string|null $response + * @return void + * @throws HttpException + */ + private static function curlValidate($curl, $response = null) + { + $json = json_decode((string) $response, true) ?: []; + + if (($httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE)) + && !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE]) + ) { + $errorDescription = array_key_exists('description', $json) ? $json['description'] : self::$codes[$httpCode]; + $errorParameters = array_key_exists('parameters', $json) ? $json['parameters'] : []; + + throw new HttpException($errorDescription, $httpCode, null, $errorParameters); + } + } + + /** + * @param string $option + * @param string|int|bool $value + * @return void + */ + public function setOption($option, $value) + { + $this->options[$option] = $value; + } + + /** + * @param string $option + * @return void + */ + public function unsetOption($option) + { + unset($this->options[$option]); + } + + /** + * @return void + */ + public function resetOptions() + { + $this->options = []; + } +} diff --git a/src/Http/HttpClientInterface.php b/src/Http/HttpClientInterface.php new file mode 100644 index 00000000..7503c14c --- /dev/null +++ b/src/Http/HttpClientInterface.php @@ -0,0 +1,31 @@ +http = $http; + $this->requestFactory = $requestFactory; + } + + /** + * @inheritDoc + */ + protected function doRequest($url, array $data = null) + { + if ($data) { + $method = 'POST'; + } else { + $method = 'GET'; + } + + $request = $this->requestFactory->createRequest($method, $url); + try { + $response = $this->http->sendRequest($request); + } catch (ClientExceptionInterface $exception) { + throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); + } + + $content = $response->getBody()->getContents(); + + return self::jsonValidate($content); + } + + /** + * @inheritDoc + */ + protected function doDownload($url) + { + $request = $this->requestFactory->createRequest('GET', $url); + + try { + return $this->http->sendRequest($request)->getBody()->getContents(); + } catch (ClientExceptionInterface $exception) { + throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); + } + } + + /** + * @param string $jsonString + * @return array + * @throws InvalidJsonException + */ + private static function jsonValidate($jsonString) + { + /** @var array $json */ + $json = json_decode($jsonString, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new InvalidJsonException(json_last_error_msg(), json_last_error()); + } + + return $json; + } +} diff --git a/src/Http/SymfonyHttpClient.php b/src/Http/SymfonyHttpClient.php new file mode 100644 index 00000000..2b229576 --- /dev/null +++ b/src/Http/SymfonyHttpClient.php @@ -0,0 +1,54 @@ +http = $http; + } + + /** + * @inheritDoc + */ + protected function doRequest($url, array $data = null) + { + $options = []; + if ($data) { + $method = 'POST'; + $options['body'] = $data; + } else { + $method = 'GET'; + } + + $response = $this->http->request($method, $url, $options); + + try { + return $response->toArray(); + } catch (ExceptionInterface $exception) { + throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); + } + } + + /** + * @inheritDoc + */ + protected function doDownload($url) + { + try { + return $this->http->request('GET', $url)->getContent(); + } catch (ExceptionInterface $exception) { + throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); + } + } +} diff --git a/src/HttpException.php b/src/HttpException.php index 4b826c64..e6859920 100644 --- a/src/HttpException.php +++ b/src/HttpException.php @@ -20,10 +20,10 @@ class HttpException extends Exception * * @param string $message [optional] The Exception message to throw. * @param int $code [optional] The Exception code. - * @param Exception $previous [optional] The previous throwable used for the exception chaining. + * @param \Throwable|\Exception $previous [optional] The previous throwable used for the exception chaining. * @param array $parameters [optional] Array of parameters returned from API. */ - public function __construct($message = '', $code = 0, Exception $previous = null, $parameters = []) + public function __construct($message = '', $code = 0, $previous = null, $parameters = []) { $this->parameters = $parameters; diff --git a/tests/BotApiTest.php b/tests/BotApiTest.php index 3d7ba9dd..823292d3 100644 --- a/tests/BotApiTest.php +++ b/tests/BotApiTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use TelegramBot\Api\BotApi; +use TelegramBot\Api\Http\HttpClientInterface; use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\Update; @@ -108,16 +109,18 @@ public function data() */ public function testGetUpdates($updates) { - $mock = $this->getMockBuilder(BotApi::class) - ->setMethods(['call']) - ->enableOriginalConstructor() - ->setConstructorArgs(['testToken']) - ->getMock(); + $httpClient = $this->createHttpClient(); + $botApi = $this->createBotApi($httpClient); - $mock->expects($this->once())->method('call')->willReturn($updates); + $httpClient + ->expects($this->once()) + ->method('request') + ->willReturn($updates) + ; + + $result = $botApi->getUpdates(); $expectedResult = ArrayOfUpdates::fromResponse($updates); - $result = $mock->getUpdates(); $this->assertEquals($expectedResult, $result); @@ -126,4 +129,20 @@ public function testGetUpdates($updates) $this->assertEquals($expectedResult[$key], $item); } } + + /** + * @return HttpClientInterface&\PHPUnit\Framework\MockObject\MockObject + */ + private function createHttpClient() + { + /** @var HttpClientInterface $httpClient */ + $httpClient = $this->createMock(HttpClientInterface::class); + + return $httpClient; + } + + private function createBotApi(HttpClientInterface $httpClient) + { + return new BotApi('token', null, $httpClient); + } } diff --git a/tests/Types/ArrayOfMessageEntityTest.php b/tests/Types/ArrayOfMessageEntityTest.php index 902c52a8..ce6ca65d 100644 --- a/tests/Types/ArrayOfMessageEntityTest.php +++ b/tests/Types/ArrayOfMessageEntityTest.php @@ -11,11 +11,11 @@ class ArrayOfMessageEntityTest extends TestCase public function testFromResponse() { $items = ArrayOfMessageEntity::fromResponse([ - [ - 'type' => 'mention', - 'offset' => 0, - 'length' => 10, - ], + [ + 'type' => 'mention', + 'offset' => 0, + 'length' => 10, + ], ]); $expected = [ From 8265aa72743d36f95216eda45b0e1be0d924fdab Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 26 Sep 2023 15:55:46 +0600 Subject: [PATCH 117/130] setProxy method for CurlHttpClient for BC --- src/Http/CurlHttpClient.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Http/CurlHttpClient.php b/src/Http/CurlHttpClient.php index 910afda2..6a8a6e8d 100644 --- a/src/Http/CurlHttpClient.php +++ b/src/Http/CurlHttpClient.php @@ -197,6 +197,29 @@ private static function curlValidate($curl, $response = null) } } + /** + * Enable proxy for curl requests. Empty string will disable proxy. + * + * @param string $proxyString + * @param bool $socks5 + * @return void + */ + public function setProxy($proxyString = '', $socks5 = false) + { + if (empty($proxyString)) { + unset($this->options[CURLOPT_PROXY], $this->options[CURLOPT_HTTPPROXYTUNNEL], $this->options[CURLOPT_PROXYTYPE]); + + return; + } + + $this->options[CURLOPT_PROXY] = $proxyString; + $this->options[CURLOPT_HTTPPROXYTUNNEL] = true; + + if ($socks5) { + $this->options[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5; + } + } + /** * @param string $option * @param string|int|bool $value From d6bc8375952078eedc32e9c4d6b840b5a8d44327 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 26 Sep 2023 20:00:56 +0600 Subject: [PATCH 118/130] Fix sending files via third-party clients --- .github/workflows/tests.yaml | 2 +- composer.json | 7 ++++++ src/Http/PsrHttpClient.php | 43 ++++++++++++++++++++++++++++++++-- src/Http/SymfonyHttpClient.php | 6 +++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8b0618cf..b666cc08 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -61,7 +61,7 @@ jobs: - name: Remove http client dependencies - run: composer remove psr/http-client psr/http-factory symfony/http-client guzzlehttp/guzzle --dev --no-update + run: composer remove psr/http-client psr/http-factory php-http/multipart-stream-builder symfony/http-client guzzlehttp/guzzle --dev --no-update - name: Install dependencies with composer diff --git a/composer.json b/composer.json index b835131b..cdffbf2a 100644 --- a/composer.json +++ b/composer.json @@ -28,12 +28,14 @@ "vimeo/psalm": "^5.9", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", + "php-http/multipart-stream-builder": "^1.0", "symfony/http-client": "^4.3 | ^5.0 | ^6.0", "guzzlehttp/guzzle": "^7.0" }, "suggest": { "psr/http-client": "To use psr/http-client", "psr/http-factory": "To use psr/http-client", + "php-http/multipart-stream-builder": "To use psr/http-client", "guzzlehttp/guzzle": "To use psr/http-client", "symfony/http-client": "To use symfony/http-client" }, @@ -63,5 +65,10 @@ "branch-alias": { "dev-master": "2.6-dev" } + }, + "config": { + "allow-plugins": { + "php-http/discovery": false + } } } diff --git a/src/Http/PsrHttpClient.php b/src/Http/PsrHttpClient.php index df71e44e..0e886453 100644 --- a/src/Http/PsrHttpClient.php +++ b/src/Http/PsrHttpClient.php @@ -2,9 +2,11 @@ namespace TelegramBot\Api\Http; +use Http\Message\MultipartStream\MultipartStreamBuilder; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; use TelegramBot\Api\HttpException; use TelegramBot\Api\InvalidJsonException; @@ -20,10 +22,19 @@ class PsrHttpClient extends AbstractHttpClient */ private $requestFactory; - public function __construct(ClientInterface $http, RequestFactoryInterface $requestFactory) - { + /** + * @var StreamFactoryInterface + */ + private $streamFactory; + + public function __construct( + ClientInterface $http, + RequestFactoryInterface $requestFactory, + StreamFactoryInterface $streamFactory + ) { $this->http = $http; $this->requestFactory = $requestFactory; + $this->streamFactory = $streamFactory; } /** @@ -33,11 +44,39 @@ protected function doRequest($url, array $data = null) { if ($data) { $method = 'POST'; + $data = array_filter($data); } else { $method = 'GET'; } $request = $this->requestFactory->createRequest($method, $url); + if ($method === 'POST') { + $multipart = false; + + /** @var array $data */ + foreach ($data as &$value) { + if ($value instanceof \CURLFile) { + $value = fopen($value->getFilename(), 'r'); + $multipart = true; + } + } + unset($value); + + if ($multipart) { + $builder = new MultipartStreamBuilder($this->streamFactory); + foreach ($data as $name => $value) { + $builder->addResource($name, $value); + } + $stream = $builder->build(); + $request = $request->withHeader('Content-Type', "multipart/form-data; boundary={$builder->getBoundary()}"); + } else { + $stream = $this->streamFactory->createStream(http_build_query($data)); + $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded'); + } + + $request = $request->withBody($stream); + } + try { $response = $this->http->sendRequest($request); } catch (ClientExceptionInterface $exception) { diff --git a/src/Http/SymfonyHttpClient.php b/src/Http/SymfonyHttpClient.php index 2b229576..18dd2961 100644 --- a/src/Http/SymfonyHttpClient.php +++ b/src/Http/SymfonyHttpClient.php @@ -26,6 +26,12 @@ protected function doRequest($url, array $data = null) $options = []; if ($data) { $method = 'POST'; + foreach ($data as &$value) { + if ($value instanceof \CURLFile) { + $value = fopen($value->getFilename(), 'r'); + } + } + $options['body'] = $data; } else { $method = 'GET'; From ee6311e166d052236744401ec99ece20763d685c Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 27 Sep 2023 15:55:20 +0600 Subject: [PATCH 119/130] Better file upload support in symfony/http-client --- .github/workflows/tests.yaml | 2 +- composer.json | 6 ++++-- src/Http/SymfonyHttpClient.php | 12 ++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b666cc08..225a4bfb 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -61,7 +61,7 @@ jobs: - name: Remove http client dependencies - run: composer remove psr/http-client psr/http-factory php-http/multipart-stream-builder symfony/http-client guzzlehttp/guzzle --dev --no-update + run: composer remove psr/http-client psr/http-factory php-http/multipart-stream-builder symfony/http-client symfony/mime guzzlehttp/guzzle --dev --no-update - name: Install dependencies with composer diff --git a/composer.json b/composer.json index cdffbf2a..85fe2440 100644 --- a/composer.json +++ b/composer.json @@ -30,14 +30,16 @@ "psr/http-factory": "^1.0", "php-http/multipart-stream-builder": "^1.0", "symfony/http-client": "^4.3 | ^5.0 | ^6.0", + "symfony/mime": "^4.3 | ^5.0 | ^6.0", "guzzlehttp/guzzle": "^7.0" }, "suggest": { "psr/http-client": "To use psr/http-client", "psr/http-factory": "To use psr/http-client", "php-http/multipart-stream-builder": "To use psr/http-client", - "guzzlehttp/guzzle": "To use psr/http-client", - "symfony/http-client": "To use symfony/http-client" + "guzzlehttp/guzzle": "To use guzzlehttp/guzzle psr implementation", + "symfony/http-client": "To use symfony/http-client", + "symfony/mime": "To use symfony/http-client" }, "autoload": { "psr-4": { diff --git a/src/Http/SymfonyHttpClient.php b/src/Http/SymfonyHttpClient.php index 18dd2961..b24a30da 100644 --- a/src/Http/SymfonyHttpClient.php +++ b/src/Http/SymfonyHttpClient.php @@ -2,6 +2,8 @@ namespace TelegramBot\Api\Http; +use Symfony\Component\Mime\Part\DataPart; +use Symfony\Component\Mime\Part\Multipart\FormDataPart; use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface as SymfonyHttpClientInterface; use TelegramBot\Api\HttpException; @@ -26,13 +28,19 @@ protected function doRequest($url, array $data = null) $options = []; if ($data) { $method = 'POST'; + + $data = array_filter($data); foreach ($data as &$value) { if ($value instanceof \CURLFile) { - $value = fopen($value->getFilename(), 'r'); + $value = DataPart::fromPath($value->getFilename()); + } elseif (!\is_string($value) && !\is_array($value)) { + $value = (string) $value; } } + $formData = new FormDataPart($data); - $options['body'] = $data; + $options['headers'] = $formData->getPreparedHeaders()->toArray(); + $options['body'] = $formData->toIterable(); } else { $method = 'GET'; } From 939b6d764be1a2a32ef7c58a8ca38521eb7f6dd1 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Fri, 29 Sep 2023 12:37:00 +0600 Subject: [PATCH 120/130] Message Video Note --- CHANGELOG.md | 1 + src/Types/Message.php | 25 +++++++++++++++++++++++++ tests/Types/MessageTest.php | 3 +++ 3 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cafc20d4..ca400033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Add support for third party http clients (`psr/http-client` and `symfony/http-client`) - Add support for local bot API server - Add method `\TelegramBot\Api\BotApi::validateWebAppData` to validate `window.Telegram.WebApp.initData` +- Add `\TelegramBot\Api\Types\Message::$videoNote` field ## 2.5.0 - 2023-08-09 diff --git a/src/Types/Message.php b/src/Types/Message.php index c344bfd5..e95b16c9 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -48,6 +48,7 @@ class Message extends BaseType implements TypeInterface 'photo' => ArrayOfPhotoSize::class, 'sticker' => Sticker::class, 'video' => Video::class, + 'video_note' => VideoNote::class, 'voice' => Voice::class, 'caption' => true, 'contact' => Contact::class, @@ -254,6 +255,13 @@ class Message extends BaseType implements TypeInterface */ protected $video; + /** + * Optional. Message is a video note, information about the video message + * + * @var \TelegramBot\Api\Types\VideoNote|null + */ + protected $videoNote; + /** * Optional. Message is a voice message, information about the file * @@ -874,6 +882,23 @@ public function getVideo() return $this->video; } + /** + * @return VideoNote|null + */ + public function getVideoNote() + { + return $this->videoNote; + } + + /** + * @param VideoNote|null $videoNote + * @return void + */ + public function setVideoNote($videoNote) + { + $this->videoNote = $videoNote; + } + /** * @param Video $video * @return void diff --git a/tests/Types/MessageTest.php b/tests/Types/MessageTest.php index 9fa8f958..b15472d4 100644 --- a/tests/Types/MessageTest.php +++ b/tests/Types/MessageTest.php @@ -59,6 +59,7 @@ public static function getFullResponse() ], 'sticker' => StickerTest::getMinResponse(), 'video' => VideoTest::getMinResponse(), + 'video_note' => VideoNoteTest::getMinResponse(), 'voice' => VoiceTest::getMinResponse(), 'caption' => 'caption', 'contact' => ContactTest::getMinResponse(), @@ -125,6 +126,7 @@ protected function assertMinItem($item) $this->assertNull($item->getPhoto()); $this->assertNull($item->getSticker()); $this->assertNull($item->getVideo()); + $this->assertNull($item->getVideoNote()); $this->assertNull($item->getVoice()); $this->assertNull($item->getCaption()); $this->assertNull($item->getContact()); @@ -186,6 +188,7 @@ protected function assertFullItem($item) $this->assertEquals([PhotoSizeTest::createMinInstance()], $item->getPhoto()); $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); $this->assertEquals(VideoTest::createMinInstance(), $item->getVideo()); + $this->assertEquals(VideoNoteTest::createMinInstance(), $item->getVideoNote()); $this->assertEquals(VoiceTest::createMinInstance(), $item->getVoice()); $this->assertEquals('caption', $item->getCaption()); $this->assertEquals(ContactTest::createMinInstance(), $item->getContact()); From d363950ae4b67fed02d5522fc0b153b033d600a4 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Fri, 29 Sep 2023 16:01:02 +0600 Subject: [PATCH 121/130] Pass to HttpException correct description in custom http clients --- src/Http/PsrHttpClient.php | 11 ++++++++++- src/Http/SymfonyHttpClient.php | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Http/PsrHttpClient.php b/src/Http/PsrHttpClient.php index 0e886453..912d711e 100644 --- a/src/Http/PsrHttpClient.php +++ b/src/Http/PsrHttpClient.php @@ -85,7 +85,16 @@ protected function doRequest($url, array $data = null) $content = $response->getBody()->getContents(); - return self::jsonValidate($content); + $json = self::jsonValidate($content); + + if (!\in_array($response->getStatusCode(), [200, 304])) { + $errorDescription = array_key_exists('description', $json) ? $json['description'] : $response->getReasonPhrase(); + $errorParameters = array_key_exists('parameters', $json) ? $json['parameters'] : []; + + throw new HttpException($errorDescription, $response->getStatusCode(), null, $errorParameters); + } + + return $json; } /** diff --git a/src/Http/SymfonyHttpClient.php b/src/Http/SymfonyHttpClient.php index b24a30da..7dea7df1 100644 --- a/src/Http/SymfonyHttpClient.php +++ b/src/Http/SymfonyHttpClient.php @@ -5,6 +5,7 @@ use Symfony\Component\Mime\Part\DataPart; use Symfony\Component\Mime\Part\Multipart\FormDataPart; use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface as SymfonyHttpClientInterface; use TelegramBot\Api\HttpException; @@ -50,7 +51,16 @@ protected function doRequest($url, array $data = null) try { return $response->toArray(); } catch (ExceptionInterface $exception) { - throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); + if ($exception instanceof HttpExceptionInterface) { + $response = $exception->getResponse()->toArray(false); + $message = array_key_exists('description', $response) ? $response['description'] : $exception->getMessage(); + $parameters = array_key_exists('parameters', $response) ? $response['parameters'] : []; + } else { + $message = $exception->getMessage(); + $parameters = []; + } + + throw new HttpException($message, $exception->getCode(), $exception, $parameters); } } From d11cf3a7d61455d8530d8ad1ab5bd90f3caa91a1 Mon Sep 17 00:00:00 2001 From: Ilya Gusev Date: Sun, 30 Jun 2024 22:57:24 +0700 Subject: [PATCH 122/130] Actualize to 7.4 (#474) * Actualized Types: Chat User Added missed Types: ArrayOfReactionType MessageOriginChannel ReactionType ReactionTypeCustomEmoji ReactionTypeEmoji Added some tests * Actualized Types * Actualized Types * Actualized Types * Actualized Types * rm tracker * rm tracker * upd Chat classes * php cs-fixer * upd MessageOriginChannel * fix BotApiTest * added types to User --- .github/workflows/tests.yaml | 8 - composer.json | 2 +- psalm.xml | 2 +- src/BotApi.php | 82 +- src/Botan.php | 95 -- src/Client.php | 10 +- src/Events/EventCollection.php | 29 +- src/Types/Animation.php | 106 +- .../ArrayOfBusinessOpeningHoursInterval.php | 20 + src/Types/ArrayOfChat.php | 20 + src/Types/ArrayOfChatBoost.php | 23 + src/Types/ArrayOfMessageEntity.php | 3 + src/Types/ArrayOfMessages.php | 3 + src/Types/ArrayOfPhotoSize.php | 3 + src/Types/ArrayOfPollOption.php | 3 + src/Types/ArrayOfReactionType.php | 28 + src/Types/ArrayOfSharedUser.php | 23 + src/Types/Audio.php | 132 +- src/Types/BackgroundFill.php | 39 + src/Types/BackgroundFillFreeformGradient.php | 53 + src/Types/BackgroundFillGradient.php | 97 ++ src/Types/BackgroundFillSolid.php | 53 + src/Types/BackgroundType.php | 39 + src/Types/BackgroundTypeChatTheme.php | 53 + src/Types/BackgroundTypeFill.php | 78 ++ src/Types/BackgroundTypePattern.php | 153 +++ src/Types/BackgroundTypeWallpaper.php | 128 ++ src/Types/Birthdate.php | 99 ++ src/Types/BotDescription.php | 54 + src/Types/BotShortDescription.php | 54 + src/Types/BusinessConnection.php | 174 +++ src/Types/BusinessIntro.php | 92 ++ src/Types/BusinessLocation.php | 74 ++ src/Types/BusinessMessagesDeleted.php | 102 ++ src/Types/BusinessOpeningHours.php | 74 ++ src/Types/BusinessOpeningHoursInterval.php | 74 ++ src/Types/CallbackGame.php | 10 + src/Types/CallbackQuery.php | 11 +- src/Types/Chat.php | 550 +-------- src/Types/ChatAdministratorRights.php | 411 +++++++ src/Types/ChatBackground.php | 55 + src/Types/ChatBoost.php | 126 ++ src/Types/ChatBoostAdded.php | 55 + src/Types/ChatBoostRemoved.php | 126 ++ src/Types/ChatBoostSource.php | 96 ++ src/Types/ChatBoostSourceGiftCode.php | 53 + src/Types/ChatBoostSourceGiveaway.php | 103 ++ src/Types/ChatBoostSourcePremium.php | 85 ++ src/Types/ChatBoostUpdated.php | 78 ++ src/Types/ChatFullInfo.php | 1069 +++++++++++++++++ src/Types/ChatMember.php | 540 +-------- src/Types/ChatMemberAdministrator.php | 458 +++++++ src/Types/ChatMemberBanned.php | 58 + src/Types/ChatMemberLeft.php | 23 + src/Types/ChatMemberMember.php | 23 + src/Types/ChatMemberOwner.php | 83 ++ src/Types/ChatMemberRestricted.php | 433 +++++++ src/Types/ChatMemberUpdated.php | 35 + src/Types/ChatPhoto.php | 50 + src/Types/ChatShared.php | 156 +++ src/Types/Dice.php | 2 + src/Types/Document.php | 114 +- src/Types/ExternalReplyInfo.php | 646 ++++++++++ src/Types/ForumTopicCreated.php | 16 +- src/Types/ForumTopicEdited.php | 73 ++ src/Types/Game.php | 174 +++ src/Types/GeneralForumTopicHidden.php | 10 + src/Types/GeneralForumTopicUnhidden.php | 10 + src/Types/Giveaway.php | 230 ++++ src/Types/GiveawayCompleted.php | 105 ++ src/Types/GiveawayCreated.php | 10 + src/Types/GiveawayWinners.php | 311 +++++ src/Types/InaccessibleMessage.php | 131 ++ src/Types/Inline/InlineKeyboardButton.php | 283 +++++ src/Types/Inline/InlineKeyboardMarkup.php | 6 - .../Inline/SwitchInlineQueryChosenChat.php | 148 +++ src/Types/InputMedia/InputMedia.php | 151 +-- src/Types/InputMedia/InputMediaAnimation.php | 308 +++++ src/Types/InputMedia/InputMediaAudio.php | 260 ++++ src/Types/InputMedia/InputMediaDocument.php | 212 ++++ src/Types/InputMedia/InputMediaPhoto.php | 197 ++- src/Types/InputMedia/InputMediaVideo.php | 263 +++- src/Types/InputPollOption.php | 105 ++ src/Types/KeyboardButton.php | 213 ++++ src/Types/KeyboardButtonPollType.php | 50 + src/Types/KeyboardButtonRequestChat.php | 307 +++++ src/Types/KeyboardButtonRequestUsers.php | 206 ++++ src/Types/LinkPreviewOptions.php | 148 +++ src/Types/Location.php | 18 +- src/Types/MaybeInaccessibleMessage.php | 26 + src/Types/Message.php | 1022 +++++++++++----- src/Types/MessageAutoDeleteTimerChanged.php | 55 + src/Types/MessageEntity.php | 12 +- src/Types/MessageId.php | 14 +- src/Types/MessageOrigin.php | 45 + src/Types/MessageOriginChannel.php | 56 + src/Types/MessageOriginChat.php | 44 + src/Types/MessageOriginHiddenUser.php | 32 + src/Types/MessageOriginUser.php | 32 + src/Types/MessageReactionCountUpdated.php | 124 ++ src/Types/MessageReactionUpdated.php | 199 +++ src/Types/PhotoSize.php | 76 +- src/Types/Poll.php | 127 +- src/Types/PollAnswer.php | 66 +- src/Types/PollOption.php | 27 +- src/Types/ProximityAlertTriggered.php | 105 ++ src/Types/ReactionCount.php | 74 ++ src/Types/ReactionType.php | 36 + src/Types/ReactionTypeCustomEmoji.php | 56 + src/Types/ReactionTypeEmoji.php | 55 + src/Types/ReplyParameters.php | 205 ++++ src/Types/ResponseParameters.php | 78 ++ src/Types/SharedUser.php | 155 +++ src/Types/Story.php | 85 ++ src/Types/TextQuote.php | 131 ++ src/Types/User.php | 172 +-- src/Types/UserChatBoosts.php | 54 + src/Types/UsersShared.php | 81 ++ src/Types/Venue.php | 16 +- src/Types/VideoChatEnded.php | 55 + src/Types/VideoChatParticipantsInvited.php | 55 + src/Types/VideoChatScheduled.php | 55 + src/Types/VideoChatStarted.php | 10 + src/Types/VideoNote.php | 10 + src/Types/WebAppInfo.php | 55 + src/Types/WriteAccessAllowed.php | 98 ++ tests/BotApiTest.php | 2 +- tests/ClientTest.php | 3 +- tests/Collection/CollectionTest.php | 16 - tests/Events/EventCollectionTest.php | 38 - tests/Types/ChatMemberTest.php | 105 -- tests/Types/ChatMemberUpdatedTest.php | 68 -- tests/Types/ChatTest.php | 39 - tests/Types/MessageOriginChannelTest.php | 74 ++ tests/Types/MessageTest.php | 20 - tests/Types/PollAnswerTest.php | 1 - tests/Types/ReactionTypeCustomEmojiTest.php | 46 + ...geIdTest.php => ReactionTypeEmojiTest.php} | 16 +- tests/Types/UpdateTest.php | 4 - tests/Types/UserTest.php | 70 ++ 140 files changed, 13145 insertions(+), 2431 deletions(-) delete mode 100644 src/Botan.php create mode 100644 src/Types/ArrayOfBusinessOpeningHoursInterval.php create mode 100644 src/Types/ArrayOfChat.php create mode 100644 src/Types/ArrayOfChatBoost.php create mode 100644 src/Types/ArrayOfReactionType.php create mode 100644 src/Types/ArrayOfSharedUser.php create mode 100644 src/Types/BackgroundFill.php create mode 100644 src/Types/BackgroundFillFreeformGradient.php create mode 100644 src/Types/BackgroundFillGradient.php create mode 100644 src/Types/BackgroundFillSolid.php create mode 100644 src/Types/BackgroundType.php create mode 100644 src/Types/BackgroundTypeChatTheme.php create mode 100644 src/Types/BackgroundTypeFill.php create mode 100644 src/Types/BackgroundTypePattern.php create mode 100644 src/Types/BackgroundTypeWallpaper.php create mode 100644 src/Types/Birthdate.php create mode 100644 src/Types/BotDescription.php create mode 100644 src/Types/BotShortDescription.php create mode 100644 src/Types/BusinessConnection.php create mode 100644 src/Types/BusinessIntro.php create mode 100644 src/Types/BusinessLocation.php create mode 100644 src/Types/BusinessMessagesDeleted.php create mode 100644 src/Types/BusinessOpeningHours.php create mode 100644 src/Types/BusinessOpeningHoursInterval.php create mode 100644 src/Types/CallbackGame.php create mode 100644 src/Types/ChatAdministratorRights.php create mode 100644 src/Types/ChatBackground.php create mode 100644 src/Types/ChatBoost.php create mode 100644 src/Types/ChatBoostAdded.php create mode 100644 src/Types/ChatBoostRemoved.php create mode 100644 src/Types/ChatBoostSource.php create mode 100644 src/Types/ChatBoostSourceGiftCode.php create mode 100644 src/Types/ChatBoostSourceGiveaway.php create mode 100644 src/Types/ChatBoostSourcePremium.php create mode 100644 src/Types/ChatBoostUpdated.php create mode 100644 src/Types/ChatFullInfo.php create mode 100644 src/Types/ChatMemberAdministrator.php create mode 100644 src/Types/ChatMemberBanned.php create mode 100644 src/Types/ChatMemberLeft.php create mode 100644 src/Types/ChatMemberMember.php create mode 100644 src/Types/ChatMemberOwner.php create mode 100644 src/Types/ChatMemberRestricted.php create mode 100644 src/Types/ChatShared.php create mode 100644 src/Types/ExternalReplyInfo.php create mode 100644 src/Types/ForumTopicEdited.php create mode 100644 src/Types/Game.php create mode 100644 src/Types/GeneralForumTopicHidden.php create mode 100644 src/Types/GeneralForumTopicUnhidden.php create mode 100644 src/Types/Giveaway.php create mode 100644 src/Types/GiveawayCompleted.php create mode 100644 src/Types/GiveawayCreated.php create mode 100644 src/Types/GiveawayWinners.php create mode 100644 src/Types/InaccessibleMessage.php create mode 100644 src/Types/Inline/InlineKeyboardButton.php create mode 100644 src/Types/Inline/SwitchInlineQueryChosenChat.php create mode 100644 src/Types/InputMedia/InputMediaAnimation.php create mode 100644 src/Types/InputMedia/InputMediaAudio.php create mode 100644 src/Types/InputMedia/InputMediaDocument.php create mode 100644 src/Types/InputPollOption.php create mode 100644 src/Types/KeyboardButton.php create mode 100644 src/Types/KeyboardButtonPollType.php create mode 100644 src/Types/KeyboardButtonRequestChat.php create mode 100644 src/Types/KeyboardButtonRequestUsers.php create mode 100644 src/Types/LinkPreviewOptions.php create mode 100644 src/Types/MaybeInaccessibleMessage.php create mode 100644 src/Types/MessageAutoDeleteTimerChanged.php create mode 100644 src/Types/MessageOrigin.php create mode 100644 src/Types/MessageOriginChannel.php create mode 100644 src/Types/MessageOriginChat.php create mode 100644 src/Types/MessageOriginHiddenUser.php create mode 100644 src/Types/MessageOriginUser.php create mode 100644 src/Types/MessageReactionCountUpdated.php create mode 100644 src/Types/MessageReactionUpdated.php create mode 100644 src/Types/ProximityAlertTriggered.php create mode 100644 src/Types/ReactionCount.php create mode 100644 src/Types/ReactionType.php create mode 100644 src/Types/ReactionTypeCustomEmoji.php create mode 100644 src/Types/ReactionTypeEmoji.php create mode 100644 src/Types/ReplyParameters.php create mode 100644 src/Types/ResponseParameters.php create mode 100644 src/Types/SharedUser.php create mode 100644 src/Types/Story.php create mode 100644 src/Types/TextQuote.php create mode 100644 src/Types/UserChatBoosts.php create mode 100644 src/Types/UsersShared.php create mode 100644 src/Types/VideoChatEnded.php create mode 100644 src/Types/VideoChatParticipantsInvited.php create mode 100644 src/Types/VideoChatScheduled.php create mode 100644 src/Types/VideoChatStarted.php create mode 100644 src/Types/WebAppInfo.php create mode 100644 src/Types/WriteAccessAllowed.php delete mode 100644 tests/Types/ChatMemberTest.php delete mode 100644 tests/Types/ChatMemberUpdatedTest.php create mode 100644 tests/Types/MessageOriginChannelTest.php create mode 100644 tests/Types/ReactionTypeCustomEmojiTest.php rename tests/Types/{MessageIdTest.php => ReactionTypeEmojiTest.php} (58%) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 225a4bfb..76cd14fe 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,14 +13,6 @@ jobs: os: - ubuntu-latest php: - - "5.5" - - "5.6" - - "7.0" - - "7.1" - - "7.2" - - "7.3" - - "7.4" - - "8.0" - "8.1" - "8.2" steps: diff --git a/composer.json b/composer.json index 85fe2440..c41dbb68 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php" : ">=5.5.0", + "php" : ">=8.1", "ext-curl": "*", "ext-json": "*" }, diff --git a/psalm.xml b/psalm.xml index d0e78e7a..4cfcea27 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ token = $token; $this->endpoint = ($endpoint ?: self::URL_PREFIX) . $token; $this->fileEndpoint = $endpoint ? null : (self::FILE_URL_PREFIX . $token); $this->httpClient = $httpClient ?: new CurlHttpClient(); - - if ($trackerToken) { - @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); - $this->tracker = new Botan($trackerToken); - } } /** @@ -643,12 +619,6 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) 'timeout' => $timeout, ])); - if ($this->tracker instanceof Botan) { - foreach ($updates as $update) { - $this->trackUpdate($update); - } - } - return $updates; } @@ -1804,56 +1774,6 @@ public function deleteMessage($chatId, $messageId) ]); } - /** - * @deprecated - * - * @param Update $update - * @param string $eventName - * - * @throws Exception - * - * @return void - */ - public function trackUpdate(Update $update, $eventName = 'Message') - { - @trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED); - - if (!in_array($update->getUpdateId(), $this->trackedEvents)) { - $message = $update->getMessage(); - if (!$message) { - return; - } - $this->trackedEvents[] = $update->getUpdateId(); - - $this->track($message, $eventName); - - if (count($this->trackedEvents) > self::MAX_TRACKED_EVENTS) { - $this->trackedEvents = array_slice($this->trackedEvents, (int) round(self::MAX_TRACKED_EVENTS / 4)); - } - } - } - - /** - * @deprecated - * - * Wrapper for tracker - * - * @param Message $message - * @param string $eventName - * - * @throws Exception - * - * @return void - */ - public function track(Message $message, $eventName = 'Message') - { - @trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED); - - if ($this->tracker instanceof Botan) { - $this->tracker->track($message, $eventName); - } - } - /** * Use this method to send invoices. On success, the sent Message is returned. * diff --git a/src/Botan.php b/src/Botan.php deleted file mode 100644 index efc9f67f..00000000 --- a/src/Botan.php +++ /dev/null @@ -1,95 +0,0 @@ -token = $token; - $this->curl = curl_init(); - } - - /** - * Event tracking - * - * @param \TelegramBot\Api\Types\Message $message - * @param string $eventName - * - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\HttpException - * - * @return void - */ - public function track(Message $message, $eventName = 'Message') - { - $uid = $message->getFrom()->getId(); - - $options = [ - CURLOPT_URL => self::BASE_URL . "?token={$this->token}&uid={$uid}&name={$eventName}", - CURLOPT_RETURNTRANSFER => true, - CURLOPT_POST => true, - CURLOPT_HTTPHEADER => [ - 'Content-Type: application/json' - ], - CURLOPT_POSTFIELDS => $message->toJson(), - CURLOPT_TIMEOUT => 5, - ]; - - curl_setopt_array($this->curl, $options); - /** @var string $response */ - $response = curl_exec($this->curl); - /** @var array $result */ - $result = BotApi::jsonValidate($response, true); - - BotApi::curlValidate($this->curl); - - if ($result['status'] !== 'accepted') { - throw new Exception('Error Processing Request'); - } - } - - /** - * Destructor. Close curl - */ - public function __destruct() - { - $this->curl && curl_close($this->curl); - } -} diff --git a/src/Client.php b/src/Client.php index c81abd68..b9da94ba 100644 --- a/src/Client.php +++ b/src/Client.php @@ -40,17 +40,13 @@ class Client * Client constructor * * @param string $token Telegram Bot API token - * @param string|null $trackerToken Yandex AppMetrica application api_key * @param HttpClientInterface|null $httpClient * @param string|null $endpoint */ - public function __construct($token, $trackerToken = null, HttpClientInterface $httpClient = null, $endpoint = null) + public function __construct($token, HttpClientInterface $httpClient = null, $endpoint = null) { - if ($trackerToken) { - @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); - } - $this->api = new BotApi($token, $trackerToken, $httpClient, $endpoint); - $this->events = new EventCollection($trackerToken); + $this->api = new BotApi($token, $httpClient, $endpoint); + $this->events = new EventCollection(); } /** diff --git a/src/Events/EventCollection.php b/src/Events/EventCollection.php index 510854d5..84d98abd 100644 --- a/src/Events/EventCollection.php +++ b/src/Events/EventCollection.php @@ -3,8 +3,6 @@ namespace TelegramBot\Api\Events; use Closure; -use ReflectionFunction; -use TelegramBot\Api\Botan; use TelegramBot\Api\Types\Update; class EventCollection @@ -14,28 +12,7 @@ class EventCollection * * @var array */ - protected $events; - - /** - * Botan tracker - * - * @var \TelegramBot\Api\Botan|null - */ - protected $tracker; - - /** - * EventCollection constructor. - * - * @param string $trackerToken - */ - public function __construct($trackerToken = null) - { - $this->events = []; - if ($trackerToken) { - @trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED); - $this->tracker = new Botan($trackerToken); - } - } + protected $events = []; /** * Add new event to collection @@ -62,10 +39,6 @@ public function handle(Update $update) /* @var \TelegramBot\Api\Events\Event $event */ if ($event->executeChecker($update) === true) { if ($event->executeAction($update) === false) { - if ($this->tracker && ($message = $update->getMessage())) { - $checker = new ReflectionFunction($event->getChecker()); - $this->tracker->track($message, $checker->getStaticVariables()['name']); - } break; } } diff --git a/src/Types/Animation.php b/src/Types/Animation.php index c33deeba..141cc7aa 100644 --- a/src/Types/Animation.php +++ b/src/Types/Animation.php @@ -74,55 +74,33 @@ class Animation extends BaseType implements TypeInterface protected $duration; /** - * Video thumbnail + * Optional. Animation thumbnail as defined by sender * * @var PhotoSize */ protected $thumbnail; /** - * Optional. Animation thumbnail as defined by sender + * Optional. Original animation filename as defined by sender * * @var string|null */ protected $fileName; /** - * Optional. Mime type of a file as defined by sender + * Optional. MIME type of the file as defined by sender * * @var string|null */ protected $mimeType; /** - * Optional. File size + * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. * * @var int|null */ protected $fileSize; - /** - * @return int - */ - public function getDuration() - { - return $this->duration; - } - - /** - * @param mixed $duration - * @return void - * @throws InvalidArgumentException - */ - public function setDuration($duration) - { - if (is_integer($duration)) { - $this->duration = $duration; - } else { - throw new InvalidArgumentException(); - } - } - /** * @return string */ @@ -158,22 +136,22 @@ public function setFileUniqueId($fileUniqueId) } /** - * @return int|null + * @return int */ - public function getFileSize() + public function getWidth() { - return $this->fileSize; + return $this->width; } /** - * @param mixed $fileSize + * @param int $width * @return void * @throws InvalidArgumentException */ - public function setFileSize($fileSize) + public function setWidth($width) { - if (is_integer($fileSize)) { - $this->fileSize = $fileSize; + if (is_integer($width)) { + $this->width = $width; } else { throw new InvalidArgumentException(); } @@ -188,7 +166,7 @@ public function getHeight() } /** - * @param mixed $height + * @param int $height * @return void * @throws InvalidArgumentException */ @@ -202,20 +180,25 @@ public function setHeight($height) } /** - * @return null|string + * @return int */ - public function getMimeType() + public function getDuration() { - return $this->mimeType; + return $this->duration; } /** - * @param string $mimeType + * @param int $duration * @return void + * @throws InvalidArgumentException */ - public function setMimeType($mimeType) + public function setDuration($duration) { - $this->mimeType = $mimeType; + if (is_integer($duration)) { + $this->duration = $duration; + } else { + throw new InvalidArgumentException(); + } } /** @@ -236,61 +219,56 @@ public function setThumbnail(PhotoSize $thumbnail) } /** - * @deprecated use getThumbnail method - * - * @return PhotoSize|null + * @return string|null */ - public function getThumb() + public function getFileName() { - return $this->getThumbnail(); + return $this->fileName; } /** - * @deprecated use setThumbnail method - * - * @param PhotoSize $thumb - * + * @param string $fileName * @return void */ - public function setThumb($thumb) + public function setFileName($fileName) { - $this->setThumbnail($thumb); + $this->fileName = $fileName; } /** - * @return null|string $fileName + * @return string|null */ - public function getFileName() + public function getMimeType() { - return $this->fileName; + return $this->mimeType; } /** - * @param string $fileName + * @param string $mimeType * @return void */ - public function setFileName($fileName) + public function setMimeType($mimeType) { - $this->fileName = $fileName; + $this->mimeType = $mimeType; } /** - * @return int + * @return int|null */ - public function getWidth() + public function getFileSize() { - return $this->width; + return $this->fileSize; } /** - * @param mixed $width + * @param int|null $fileSize * @return void * @throws InvalidArgumentException */ - public function setWidth($width) + public function setFileSize($fileSize) { - if (is_integer($width)) { - $this->width = $width; + if (is_integer($fileSize) || is_null($fileSize)) { + $this->fileSize = $fileSize; } else { throw new InvalidArgumentException(); } diff --git a/src/Types/ArrayOfBusinessOpeningHoursInterval.php b/src/Types/ArrayOfBusinessOpeningHoursInterval.php new file mode 100644 index 00000000..d2b497d6 --- /dev/null +++ b/src/Types/ArrayOfBusinessOpeningHoursInterval.php @@ -0,0 +1,20 @@ + true, 'performer' => true, 'title' => true, + 'file_name' => true, 'mime_type' => true, - 'file_size' => true + 'file_size' => true, + 'thumbnail' => PhotoSize::class ]; /** @@ -44,7 +46,14 @@ class Audio extends BaseType implements TypeInterface protected $fileId; /** - * Photo width + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + + /** + * Duration of the audio in seconds as defined by sender * * @var int */ @@ -64,6 +73,13 @@ class Audio extends BaseType implements TypeInterface */ protected $title; + /** + * Optional. Original filename as defined by sender + * + * @var string|null + */ + protected $fileName; + /** * Optional. MIME type of the file as defined by sender * @@ -72,18 +88,52 @@ class Audio extends BaseType implements TypeInterface protected $mimeType; /** - * Optional. File size + * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. * * @var int|null */ protected $fileSize; /** - * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * Optional. Thumbnail of the album cover to which the music file belongs * - * @var string + * @var PhotoSize|null */ - protected $fileUniqueId; + protected $thumbnail; + + /** + * @return string + */ + public function getFileId() + { + return $this->fileId; + } + + /** + * @param string $fileId + * @return void + */ + public function setFileId($fileId) + { + $this->fileId = $fileId; + } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } /** * @return int @@ -94,7 +144,7 @@ public function getDuration() } /** - * @param mixed $duration + * @param int $duration * @return void * @throws InvalidArgumentException */ @@ -108,7 +158,7 @@ public function setDuration($duration) } /** - * @return null|string + * @return string|null */ public function getPerformer() { @@ -116,7 +166,7 @@ public function getPerformer() } /** - * @param string $performer + * @param string|null $performer * @return void */ public function setPerformer($performer) @@ -125,7 +175,7 @@ public function setPerformer($performer) } /** - * @return null|string + * @return string|null */ public function getTitle() { @@ -133,7 +183,7 @@ public function getTitle() } /** - * @param string $title + * @param string|null $title * @return void */ public function setTitle($title) @@ -142,75 +192,75 @@ public function setTitle($title) } /** - * @return string + * @return string|null */ - public function getFileId() + public function getFileName() { - return $this->fileId; + return $this->fileName; } /** - * @param string $fileId + * @param string|null $fileName * @return void */ - public function setFileId($fileId) + public function setFileName($fileName) { - $this->fileId = $fileId; + $this->fileName = $fileName; } /** - * @return int|null + * @return string|null */ - public function getFileSize() + public function getMimeType() { - return $this->fileSize; + return $this->mimeType; } /** - * @param mixed $fileSize + * @param string|null $mimeType * @return void - * @throws InvalidArgumentException */ - public function setFileSize($fileSize) + public function setMimeType($mimeType) { - if (is_integer($fileSize)) { - $this->fileSize = $fileSize; - } else { - throw new InvalidArgumentException(); - } + $this->mimeType = $mimeType; } /** - * @return null|string + * @return int|null */ - public function getMimeType() + public function getFileSize() { - return $this->mimeType; + return $this->fileSize; } /** - * @param string $mimeType + * @param int|null $fileSize * @return void + * @throws InvalidArgumentException */ - public function setMimeType($mimeType) + public function setFileSize($fileSize) { - $this->mimeType = $mimeType; + if (is_integer($fileSize) || is_null($fileSize)) { + $this->fileSize = $fileSize; + } else { + throw new InvalidArgumentException(); + } } /** - * @return string + * @return PhotoSize|null */ - public function getFileUniqueId() + public function getThumbnail() { - return $this->fileUniqueId; + return $this->thumbnail; } /** - * @param string $fileUniqueId + * @param PhotoSize|null $thumbnail * @return void */ - public function setFileUniqueId($fileUniqueId) + public function setThumbnail($thumbnail) { - $this->fileUniqueId = $fileUniqueId; + $this->thumbnail = $thumbnail; } } diff --git a/src/Types/BackgroundFill.php b/src/Types/BackgroundFill.php new file mode 100644 index 00000000..8da9d869 --- /dev/null +++ b/src/Types/BackgroundFill.php @@ -0,0 +1,39 @@ +type; + } + + /** + * @param string $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } +} diff --git a/src/Types/BackgroundFillFreeformGradient.php b/src/Types/BackgroundFillFreeformGradient.php new file mode 100644 index 00000000..3d028e04 --- /dev/null +++ b/src/Types/BackgroundFillFreeformGradient.php @@ -0,0 +1,53 @@ + true, + 'colors' => true, + ]; + + /** + * A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format + * + * @var array + */ + protected $colors; + + /** + * @return array + */ + public function getColors() + { + return $this->colors; + } + + /** + * @param array $colors + * @return void + */ + public function setColors($colors) + { + $this->colors = $colors; + } +} diff --git a/src/Types/BackgroundFillGradient.php b/src/Types/BackgroundFillGradient.php new file mode 100644 index 00000000..740a9249 --- /dev/null +++ b/src/Types/BackgroundFillGradient.php @@ -0,0 +1,97 @@ + true, + 'top_color' => true, + 'bottom_color' => true, + 'rotation_angle' => true, + ]; + + /** + * Top color of the gradient in the RGB24 format + * + * @var int + */ + protected $topColor; + + /** + * Bottom color of the gradient in the RGB24 format + * + * @var int + */ + protected $bottomColor; + + /** + * Clockwise rotation angle of the background fill in degrees; 0-359 + * + * @var int + */ + protected $rotationAngle; + + /** + * @return int + */ + public function getTopColor() + { + return $this->topColor; + } + + /** + * @param int $topColor + * @return void + */ + public function setTopColor($topColor) + { + $this->topColor = $topColor; + } + + /** + * @return int + */ + public function getBottomColor() + { + return $this->bottomColor; + } + + /** + * @param int $bottomColor + * @return void + */ + public function setBottomColor($bottomColor) + { + $this->bottomColor = $bottomColor; + } + + /** + * @return int + */ + public function getRotationAngle() + { + return $this->rotationAngle; + } + + /** + * @param int $rotationAngle + * @return void + */ + public function setRotationAngle($rotationAngle) + { + $this->rotationAngle = $rotationAngle; + } +} diff --git a/src/Types/BackgroundFillSolid.php b/src/Types/BackgroundFillSolid.php new file mode 100644 index 00000000..f9fe2bf8 --- /dev/null +++ b/src/Types/BackgroundFillSolid.php @@ -0,0 +1,53 @@ + true, + 'color' => true, + ]; + + /** + * The color of the background fill in the RGB24 format + * + * @var int + */ + protected $color; + + /** + * @return int + */ + public function getColor() + { + return $this->color; + } + + /** + * @param int $color + * @return void + */ + public function setColor($color) + { + $this->color = $color; + } +} diff --git a/src/Types/BackgroundType.php b/src/Types/BackgroundType.php new file mode 100644 index 00000000..dc2d8c30 --- /dev/null +++ b/src/Types/BackgroundType.php @@ -0,0 +1,39 @@ +type; + } + + /** + * @param string $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } +} diff --git a/src/Types/BackgroundTypeChatTheme.php b/src/Types/BackgroundTypeChatTheme.php new file mode 100644 index 00000000..6fb4d567 --- /dev/null +++ b/src/Types/BackgroundTypeChatTheme.php @@ -0,0 +1,53 @@ + true, + 'theme_name' => true, + ]; + + /** + * Name of the chat theme, which is usually an emoji + * + * @var string + */ + protected $themeName; + + /** + * @return string + */ + public function getThemeName() + { + return $this->themeName; + } + + /** + * @param string $themeName + * @return void + */ + public function setThemeName($themeName) + { + $this->themeName = $themeName; + } +} diff --git a/src/Types/BackgroundTypeFill.php b/src/Types/BackgroundTypeFill.php new file mode 100644 index 00000000..dab90920 --- /dev/null +++ b/src/Types/BackgroundTypeFill.php @@ -0,0 +1,78 @@ + true, + 'fill' => BackgroundFill::class, + 'dark_theme_dimming' => true, + ]; + + /** + * The background fill + * + * @var BackgroundFill + */ + protected $fill; + + /** + * Dimming of the background in dark themes, as a percentage; 0-100 + * + * @var int + */ + protected $darkThemeDimming; + + /** + * @return BackgroundFill + */ + public function getFill() + { + return $this->fill; + } + + /** + * @param BackgroundFill $fill + * @return void + */ + public function setFill(BackgroundFill $fill) + { + $this->fill = $fill; + } + + /** + * @return int + */ + public function getDarkThemeDimming() + { + return $this->darkThemeDimming; + } + + /** + * @param int $darkThemeDimming + * @return void + */ + public function setDarkThemeDimming($darkThemeDimming) + { + $this->darkThemeDimming = $darkThemeDimming; + } +} diff --git a/src/Types/BackgroundTypePattern.php b/src/Types/BackgroundTypePattern.php new file mode 100644 index 00000000..c9c37b66 --- /dev/null +++ b/src/Types/BackgroundTypePattern.php @@ -0,0 +1,153 @@ + true, + 'document' => Document::class, + 'fill' => BackgroundFill::class, + 'intensity' => true, + 'is_inverted' => true, + 'is_moving' => true, + ]; + + /** + * Document with the pattern + * + * @var Document + */ + protected $document; + + /** + * The background fill that is combined with the pattern + * + * @var BackgroundFill + */ + protected $fill; + + /** + * Intensity of the pattern when it is shown above the filled background; 0-100 + * + * @var int + */ + protected $intensity; + + /** + * Optional. True, if the background fill must be applied only to the pattern itself. All other pixels are black in this case. For dark themes only + * + * @var bool|null + */ + protected $isInverted; + + /** + * Optional. True, if the background moves slightly when the device is tilted + * + * @var bool|null + */ + protected $isMoving; + + /** + * @return Document + */ + public function getDocument() + { + return $this->document; + } + + /** + * @param Document $document + * @return void + */ + public function setDocument(Document $document) + { + $this->document = $document; + } + + /** + * @return BackgroundFill + */ + public function getFill() + { + return $this->fill; + } + + /** + * @param BackgroundFill $fill + * @return void + */ + public function setFill(BackgroundFill $fill) + { + $this->fill = $fill; + } + + /** + * @return int + */ + public function getIntensity() + { + return $this->intensity; + } + + /** + * @param int $intensity + * @return void + */ + public function setIntensity($intensity) + { + $this->intensity = $intensity; + } + + /** + * @return bool|null + */ + public function getIsInverted() + { + return $this->isInverted; + } + + /** + * @param bool $isInverted + * @return void + */ + public function setIsInverted($isInverted) + { + $this->isInverted = $isInverted; + } + + /** + * @return bool|null + */ + public function getIsMoving() + { + return $this->isMoving; + } + + /** + * @param bool $isMoving + * @return void + */ + public function setIsMoving($isMoving) + { + $this->isMoving = $isMoving; + } +} diff --git a/src/Types/BackgroundTypeWallpaper.php b/src/Types/BackgroundTypeWallpaper.php new file mode 100644 index 00000000..dba3baa7 --- /dev/null +++ b/src/Types/BackgroundTypeWallpaper.php @@ -0,0 +1,128 @@ + true, + 'document' => Document::class, + 'dark_theme_dimming' => true, + 'is_blurred' => true, + 'is_moving' => true, + ]; + + /** + * Document with the wallpaper + * + * @var Document + */ + protected $document; + + /** + * Dimming of the background in dark themes, as a percentage; 0-100 + * + * @var int + */ + protected $darkThemeDimming; + + /** + * Optional. True, if the wallpaper is downscaled to fit in a 450x450 square and then box-blurred with radius 12 + * + * @var bool|null + */ + protected $isBlurred; + + /** + * Optional. True, if the background moves slightly when the device is tilted + * + * @var bool|null + */ + protected $isMoving; + + /** + * @return Document + */ + public function getDocument() + { + return $this->document; + } + + /** + * @param Document $document + * @return void + */ + public function setDocument(Document $document) + { + $this->document = $document; + } + + /** + * @return int + */ + public function getDarkThemeDimming() + { + return $this->darkThemeDimming; + } + + /** + * @param int $darkThemeDimming + * @return void + */ + public function setDarkThemeDimming($darkThemeDimming) + { + $this->darkThemeDimming = $darkThemeDimming; + } + + /** + * @return bool|null + */ + public function getIsBlurred() + { + return $this->isBlurred; + } + + /** + * @param bool $isBlurred + * @return void + */ + public function setIsBlurred($isBlurred) + { + $this->isBlurred = $isBlurred; + } + + /** + * @return bool|null + */ + public function getIsMoving() + { + return $this->isMoving; + } + + /** + * @param bool $isMoving + * @return void + */ + public function setIsMoving($isMoving) + { + $this->isMoving = $isMoving; + } +} diff --git a/src/Types/Birthdate.php b/src/Types/Birthdate.php new file mode 100644 index 00000000..2e2d1b7e --- /dev/null +++ b/src/Types/Birthdate.php @@ -0,0 +1,99 @@ + true, + 'month' => true, + 'year' => true, + ]; + + /** + * Day of the user's birth; 1-31 + * + * @var int + */ + protected $day; + + /** + * Month of the user's birth; 1-12 + * + * @var int + */ + protected $month; + + /** + * Optional. Year of the user's birth + * + * @var int|null + */ + protected $year; + + /** + * @return int + */ + public function getDay() + { + return $this->day; + } + + /** + * @param int $day + * @return void + */ + public function setDay($day) + { + $this->day = $day; + } + + /** + * @return int + */ + public function getMonth() + { + return $this->month; + } + + /** + * @param int $month + * @return void + */ + public function setMonth($month) + { + $this->month = $month; + } + + /** + * @return int|null + */ + public function getYear() + { + return $this->year; + } + + /** + * @param int|null $year + * @return void + */ + public function setYear($year) + { + $this->year = $year; + } +} diff --git a/src/Types/BotDescription.php b/src/Types/BotDescription.php new file mode 100644 index 00000000..28188681 --- /dev/null +++ b/src/Types/BotDescription.php @@ -0,0 +1,54 @@ + true + ]; + + /** + * The bot's description + * + * @var string + */ + protected $description; + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + */ + public function setDescription($description) + { + $this->description = $description; + } +} diff --git a/src/Types/BotShortDescription.php b/src/Types/BotShortDescription.php new file mode 100644 index 00000000..29bb381d --- /dev/null +++ b/src/Types/BotShortDescription.php @@ -0,0 +1,54 @@ + true + ]; + + /** + * The bot's short description + * + * @var string + */ + protected $shortDescription; + + /** + * @return string + */ + public function getShortDescription() + { + return $this->shortDescription; + } + + /** + * @param string $shortDescription + */ + public function setShortDescription($shortDescription) + { + $this->shortDescription = $shortDescription; + } +} diff --git a/src/Types/BusinessConnection.php b/src/Types/BusinessConnection.php new file mode 100644 index 00000000..247f051f --- /dev/null +++ b/src/Types/BusinessConnection.php @@ -0,0 +1,174 @@ + true, + 'user' => User::class, + 'user_chat_id' => true, + 'date' => true, + 'can_reply' => true, + 'is_enabled' => true + ]; + + /** + * Unique identifier of the business connection + * + * @var string + */ + protected $id; + + /** + * Business account user that created the business connection + * + * @var User + */ + protected $user; + + /** + * Identifier of a private chat with the user who created the business connection + * + * @var int + */ + protected $userChatId; + + /** + * Date the connection was established in Unix time + * + * @var int + */ + protected $date; + + /** + * True, if the bot can act on behalf of the business account in chats that were active in the last 24 hours + * + * @var bool + */ + protected $canReply; + + /** + * True, if the connection is active + * + * @var bool + */ + protected $isEnabled; + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $user + */ + public function setUser($user) + { + $this->user = $user; + } + + /** + * @return int + */ + public function getUserChatId() + { + return $this->userChatId; + } + + /** + * @param int $userChatId + */ + public function setUserChatId($userChatId) + { + $this->userChatId = $userChatId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return bool + */ + public function getCanReply() + { + return $this->canReply; + } + + /** + * @param bool $canReply + */ + public function setCanReply($canReply) + { + $this->canReply = $canReply; + } + + /** + * @return bool + */ + public function getIsEnabled() + { + return $this->isEnabled; + } + + /** + * @param bool $isEnabled + */ + public function setIsEnabled($isEnabled) + { + $this->isEnabled = $isEnabled; + } +} diff --git a/src/Types/BusinessIntro.php b/src/Types/BusinessIntro.php new file mode 100644 index 00000000..7b6030df --- /dev/null +++ b/src/Types/BusinessIntro.php @@ -0,0 +1,92 @@ + true, + 'message' => true, + 'sticker' => Sticker::class, + ]; + + /** + * Optional. Title text of the business intro + * + * @var string|null + */ + protected $title; + + /** + * Optional. Message text of the business intro + * + * @var string|null + */ + protected $message; + + /** + * Optional. Sticker of the business intro + * + * @var Sticker|null + */ + protected $sticker; + + /** + * @return string|null + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string|null $title + * @return void + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string|null + */ + public function getMessage() + { + return $this->message; + } + + /** + * @param string|null $message + * @return void + */ + public function setMessage($message) + { + $this->message = $message; + } + + /** + * @return Sticker|null + */ + public function getSticker() + { + return $this->sticker; + } + + /** + * @param Sticker|null $sticker + * @return void + */ + public function setSticker($sticker) + { + $this->sticker = $sticker; + } +} diff --git a/src/Types/BusinessLocation.php b/src/Types/BusinessLocation.php new file mode 100644 index 00000000..9d8e2b0d --- /dev/null +++ b/src/Types/BusinessLocation.php @@ -0,0 +1,74 @@ + true, + 'location' => Location::class, + ]; + + /** + * Address of the business + * + * @var string + */ + protected $address; + + /** + * Optional. Location of the business + * + * @var Location|null + */ + protected $location; + + /** + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * @param string $address + * @return void + */ + public function setAddress($address) + { + $this->address = $address; + } + + /** + * @return Location|null + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param Location|null $location + * @return void + */ + public function setLocation($location) + { + $this->location = $location; + } +} diff --git a/src/Types/BusinessMessagesDeleted.php b/src/Types/BusinessMessagesDeleted.php new file mode 100644 index 00000000..68438f1b --- /dev/null +++ b/src/Types/BusinessMessagesDeleted.php @@ -0,0 +1,102 @@ + true, + 'chat' => Chat::class, + 'message_ids' => true + ]; + + /** + * Unique identifier of the business connection + * + * @var string + */ + protected $businessConnectionId; + + /** + * Information about a chat in the business account. The bot may not have access to the chat or the corresponding user. + * + * @var Chat + */ + protected $chat; + + /** + * The list of identifiers of deleted messages in the chat of the business account + * + * @var int[] + */ + protected $messageIds; + + /** + * @return string + */ + public function getBusinessConnectionId() + { + return $this->businessConnectionId; + } + + /** + * @param string $businessConnectionId + */ + public function setBusinessConnectionId($businessConnectionId) + { + $this->businessConnectionId = $businessConnectionId; + } + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int[] + */ + public function getMessageIds() + { + return $this->messageIds; + } + + /** + * @param int[] $messageIds + */ + public function setMessageIds(array $messageIds) + { + $this->messageIds = $messageIds; + } +} diff --git a/src/Types/BusinessOpeningHours.php b/src/Types/BusinessOpeningHours.php new file mode 100644 index 00000000..67ea67a3 --- /dev/null +++ b/src/Types/BusinessOpeningHours.php @@ -0,0 +1,74 @@ + true, + 'opening_hours' => ArrayOfBusinessOpeningHoursInterval::class, + ]; + + /** + * Unique name of the time zone for which the opening hours are defined + * + * @var string + */ + protected $timeZoneName; + + /** + * List of time intervals describing business opening hours + * + * @var array + */ + protected $openingHours; + + /** + * @return string + */ + public function getTimeZoneName() + { + return $this->timeZoneName; + } + + /** + * @param string $timeZoneName + * @return void + */ + public function setTimeZoneName($timeZoneName) + { + $this->timeZoneName = $timeZoneName; + } + + /** + * @return array + */ + public function getOpeningHours() + { + return $this->openingHours; + } + + /** + * @param array $openingHours + * @return void + */ + public function setOpeningHours($openingHours) + { + $this->openingHours = $openingHours; + } +} diff --git a/src/Types/BusinessOpeningHoursInterval.php b/src/Types/BusinessOpeningHoursInterval.php new file mode 100644 index 00000000..6f7b8065 --- /dev/null +++ b/src/Types/BusinessOpeningHoursInterval.php @@ -0,0 +1,74 @@ + true, + 'closing_minute' => true, + ]; + + /** + * The minute's sequence number in a week, starting on Monday, marking the start of the time interval during which the business is open; 0 - 7 * 24 * 60 + * + * @var int + */ + protected $openingMinute; + + /** + * The minute's sequence number in a week, starting on Monday, marking the end of the time interval during which the business is open; 0 - 8 * 24 * 60 + * + * @var int + */ + protected $closingMinute; + + /** + * @return int + */ + public function getOpeningMinute() + { + return $this->openingMinute; + } + + /** + * @param int $openingMinute + * @return void + */ + public function setOpeningMinute($openingMinute) + { + $this->openingMinute = $openingMinute; + } + + /** + * @return int + */ + public function getClosingMinute() + { + return $this->closingMinute; + } + + /** + * @param int $closingMinute + * @return void + */ + public function setClosingMinute($closingMinute) + { + $this->closingMinute = $closingMinute; + } +} diff --git a/src/Types/CallbackGame.php b/src/Types/CallbackGame.php new file mode 100644 index 00000000..193daad7 --- /dev/null +++ b/src/Types/CallbackGame.php @@ -0,0 +1,10 @@ + true, 'from' => User::class, - 'message' => Message::class, + 'message' => MaybeInaccessibleMessage::class, 'inline_message_id' => true, 'chat_instance' => true, 'data' => true, @@ -59,7 +58,7 @@ class CallbackQuery extends BaseType * Note that message content and message date will not be available * if the message is too old * - * @var \TelegramBot\Api\Types\Message|null + * @var \TelegramBot\Api\Types\MaybeInaccessibleMessage|null */ protected $message; @@ -130,7 +129,7 @@ public function setFrom(User $from) } /** - * @return Message|null + * @return MaybeInaccessibleMessage|null */ public function getMessage() { @@ -138,7 +137,7 @@ public function getMessage() } /** - * @param Message $message + * @param MaybeInaccessibleMessage $message * @return void */ public function setMessage($message) diff --git a/src/Types/Chat.php b/src/Types/Chat.php index 1eee67e6..9ff38e9a 100644 --- a/src/Types/Chat.php +++ b/src/Types/Chat.php @@ -6,6 +6,12 @@ use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\TypeInterface; +/** + * Class Chat + * This object represents a chat. + * + * @package TelegramBot\Api\Types + */ class Chat extends BaseType implements TypeInterface { /** @@ -27,221 +33,60 @@ class Chat extends BaseType implements TypeInterface 'username' => true, 'first_name' => true, 'last_name' => true, - 'photo' => ChatPhoto::class, - 'bio' => true, - 'description' => true, - 'invite_link' => true, - 'pinned_message' => Message::class, - 'permissions' => ChatPermissions::class, - 'slow_mode_delay' => true, - 'sticker_set_name' => true, - 'can_set_sticker_set' => true, - 'linked_chat_id' => true, - 'location' => ChatLocation::class, - 'join_to_send_messages' => true, - 'join_by_request' => true, - 'message_auto_delete_time' => true, - 'has_protected_content' => true, 'is_forum' => true, - 'active_usernames' => true, - 'emoji_status_custom_emoji_id' => true, - 'has_private_forwards' => true, - 'has_restricted_voice_and_video_messages' => true, ]; /** - * Unique identifier for this chat, not exceeding 1e13 by absolute value + * Unique identifier for this chat. * - * @var int|float|string + * @var int|float */ protected $id; /** - * Type of chat, can be either “private”, “group”, “supergroup” or “channel” + * Type of chat, can be either “private”, “group”, “supergroup” or “channel”. * * @var string */ protected $type; /** - * Optional. Title, for channels and group chats + * Optional. Title, for supergroups, channels and group chats. * * @var string|null */ protected $title; /** - * Optional. Username, for private chats and channels if available + * Optional. Username, for private chats, supergroups and channels if available. * * @var string|null */ protected $username; /** - * Optional. First name of the other party in a private chat + * Optional. First name of the other party in a private chat. * * @var string|null */ protected $firstName; /** - * Optional. Last name of the other party in a private chat + * Optional. Last name of the other party in a private chat. * * @var string|null */ protected $lastName; /** - * Optional. Chat photo. Returned only in getChat. - * - * @var ChatPhoto|null - */ - protected $photo; - - /** - * Optional. Bio of the other party in a private chat. Returned only in getChat - * - * @var string|null - */ - protected $bio; - - /** - * Optional. Description, for supergroups and channel chats. Returned only in getChat. - * - * @var string|null - */ - protected $description; - - /** - * Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat. - * - * @var string|null - */ - protected $inviteLink; - - /** - * Optional. Pinned message, for supergroups. Returned only in getChat. - * - * @var Message|null - */ - protected $pinnedMessage; - - /** - * Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. - * - * @var ChatPermissions|null - */ - protected $permissions; - - /** - * Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged - * user. Returned only in getChat. - * - * @var int|null - */ - protected $slowModeDelay; - - /** - * Optional. For supergroups, name of group sticker set. Returned only in getChat. - * - * @var string|null - */ - protected $stickerSetName; - - /** - * Optional. True, if the bot can change the group sticker set. Returned only in getChat. - * - * @var bool|null - */ - protected $canSetStickerSet; - - /** - * Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice - * versa; for supergroups and channel chats. This identifier may be greater than 32 bits and some programming - * languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 - * bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat. - * - * @var int|null - */ - protected $linkedChatId; - - /** - * Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. - * - * @var ChatLocation|null - */ - protected $location; - - /** - * Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. - * - * @var bool|null - */ - protected $joinToSendMessages; - - /** - * Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat. - * - * @var bool|null - */ - protected $joinByRequest; - - /** - * Optional. Time after which all messages sent to the chat will be automatically deleted; in seconds. Returned - * only in getChat. - * - * @var int|null - */ - protected $messageAutoDeleteTime; - - /** - * Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. - * - * @var bool|null - */ - protected $hasProtectedContent; - - /** - * Optional. True, if the supergroup chat is a forum (has topics enabled) + * Optional. True, if the supergroup chat is a forum (has topics enabled). * * @var bool|null */ protected $isForum; /** - * Optional. If non-empty, the list of all active chat usernames; - * for private chats, supergroups and channels. Returned only in getChat. - * - * @var array[]|null - */ - protected $activeUsernames; - - /** - * Optional. Custom emoji identifier of emoji status of the other party in a private chat. Returned only in getChat. - * - * @var string|null - */ - protected $emojiStatusCustomEmojiId; - - /** - * Optional. True, if privacy settings of the other party in the private chat allows - * to use tg://user?id= links only in chats with the user. - * Returned only in getChat. - * - * @var bool|null - */ - protected $hasPrivateForwards; - - /** - * Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. - * Returned only in getChat. - * - * @var bool|null - */ - protected $hasRestrictedVoiceAndVideoMessages; - - /** - * @return int|float|string + * @return int|float */ public function getId() { @@ -253,9 +98,9 @@ public function getId() * @return void * @throws InvalidArgumentException */ - public function setId($id) + public function setId($id): void { - if (is_integer($id) || is_float($id) || is_string($id)) { + if (is_integer($id) || is_float($id)) { $this->id = $id; } else { throw new InvalidArgumentException(); @@ -272,15 +117,14 @@ public function getType() /** * @param string $type - * @return void */ - public function setType($type) + public function setType($type): void { $this->type = $type; } /** - * @return null|string + * @return string|null */ public function getTitle() { @@ -288,16 +132,15 @@ public function getTitle() } /** - * @param string $title - * @return void + * @param string|null $title */ - public function setTitle($title) + public function setTitle($title): void { $this->title = $title; } /** - * @return null|string + * @return string|null */ public function getUsername() { @@ -305,16 +148,15 @@ public function getUsername() } /** - * @param string $username - * @return void + * @param string|null $username */ - public function setUsername($username) + public function setUsername($username): void { $this->username = $username; } /** - * @return null|string + * @return string|null */ public function getFirstName() { @@ -322,16 +164,15 @@ public function getFirstName() } /** - * @param string $firstName - * @return void + * @param string|null $firstName */ - public function setFirstName($firstName) + public function setFirstName($firstName): void { $this->firstName = $firstName; } /** - * @return null|string + * @return string|null */ public function getLastName() { @@ -339,269 +180,13 @@ public function getLastName() } /** - * @param string $lastName - * @return void + * @param string|null $lastName */ - public function setLastName($lastName) + public function setLastName($lastName): void { $this->lastName = $lastName; } - /** - * @return ChatPhoto|null - */ - public function getPhoto() - { - return $this->photo; - } - - /** - * @param ChatPhoto $photo - * @return void - */ - public function setPhoto($photo) - { - $this->photo = $photo; - } - - /** - * @return null|string - */ - public function getBio() - { - return $this->bio; - } - - /** - * @param string $bio - * @return void - */ - public function setBio($bio) - { - $this->bio = $bio; - } - - /** - * @return null|string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - * @return void - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * @return null|string - */ - public function getInviteLink() - { - return $this->inviteLink; - } - - /** - * @param string $inviteLink - * @return void - */ - public function setInviteLink($inviteLink) - { - $this->inviteLink = $inviteLink; - } - - /** - * @return Message|null - */ - public function getPinnedMessage() - { - return $this->pinnedMessage; - } - - /** - * @param Message $pinnedMessage - * @return void - */ - public function setPinnedMessage($pinnedMessage) - { - $this->pinnedMessage = $pinnedMessage; - } - - /** - * @return ChatPermissions|null - */ - public function getPermissions() - { - return $this->permissions; - } - - /** - * @param ChatPermissions $permissions - * @return void - */ - public function setPermissions($permissions) - { - $this->permissions = $permissions; - } - - /** - * @return int|null - */ - public function getSlowModeDelay() - { - return $this->slowModeDelay; - } - - /** - * @param int $slowModeDelay - * @return void - */ - public function setSlowModeDelay($slowModeDelay) - { - $this->slowModeDelay = $slowModeDelay; - } - - /** - * @return null|string - */ - public function getStickerSetName() - { - return $this->stickerSetName; - } - - /** - * @param string $stickerSetName - * @return void - */ - public function setStickerSetName($stickerSetName) - { - $this->stickerSetName = $stickerSetName; - } - - /** - * @return bool|null - */ - public function getCanSetStickerSet() - { - return $this->canSetStickerSet; - } - - /** - * @param bool $canSetStickerSet - * @return void - */ - public function setCanSetStickerSet($canSetStickerSet) - { - $this->canSetStickerSet = $canSetStickerSet; - } - - /** - * @return int|null - */ - public function getLinkedChatId() - { - return $this->linkedChatId; - } - - /** - * @param int $linkedChatId - * @return void - */ - public function setLinkedChatId($linkedChatId) - { - $this->linkedChatId = $linkedChatId; - } - - /** - * @return ChatLocation|null - */ - public function getLocation() - { - return $this->location; - } - - /** - * @param ChatLocation $location - * @return void - */ - public function setLocation($location) - { - $this->location = $location; - } - - /** - * @return bool|null - */ - public function getJoinToSendMessages() - { - return $this->joinToSendMessages; - } - - /** - * @param bool $joinToSendMessages - * @return void - */ - public function setJoinToSendMessages($joinToSendMessages) - { - $this->joinToSendMessages = $joinToSendMessages; - } - - /** - * @return bool|null - */ - public function getJoinByRequest() - { - return $this->joinByRequest; - } - - /** - * @param bool $joinByRequest - * @return void - */ - public function setJoinByRequest($joinByRequest) - { - $this->joinByRequest = $joinByRequest; - } - - /** - * @return int|null - */ - public function getMessageAutoDeleteTime() - { - return $this->messageAutoDeleteTime; - } - - /** - * @param int $messageAutoDeleteTime - * @return void - */ - public function setMessageAutoDeleteTime($messageAutoDeleteTime) - { - $this->messageAutoDeleteTime = $messageAutoDeleteTime; - } - - /** - * @return bool|null - */ - public function getHasProtectedContent() - { - return $this->hasProtectedContent; - } - - /** - * @param bool $hasProtectedContent - * @return void - */ - public function setHasProtectedContent($hasProtectedContent) - { - $this->hasProtectedContent = $hasProtectedContent; - } - /** * @return bool|null */ @@ -611,81 +196,10 @@ public function getIsForum() } /** - * @param bool $isForum - * @return void + * @param bool|null $isForum */ - public function setIsForum($isForum) + public function setIsForum($isForum): void { $this->isForum = $isForum; } - - /** - * @return array[]|null - * - * @psalm-return array|null - */ - public function getActiveUsernames() - { - return $this->activeUsernames; - } - - /** - * @param array $activeUsernames - * @return void - */ - public function setActiveUsernames($activeUsernames) - { - $this->activeUsernames = $activeUsernames; - } - - /** - * @return null|string - */ - public function getEmojiStatusCustomEmojiId() - { - return $this->emojiStatusCustomEmojiId; - } - - /** - * @param string $emojiStatusCustomEmojiId - * @return void - */ - public function setEmojiStatusCustomEmojiId($emojiStatusCustomEmojiId) - { - $this->emojiStatusCustomEmojiId = $emojiStatusCustomEmojiId; - } - - /** - * @return bool|null - */ - public function getHasPrivateForwards() - { - return $this->hasPrivateForwards; - } - - /** - * @param bool $hasPrivateForwards - * @return void - */ - public function setHasPrivateForwards($hasPrivateForwards) - { - $this->hasPrivateForwards = $hasPrivateForwards; - } - - /** - * @return bool|null - */ - public function getHasRestrictedVoiceAndVideoMessages() - { - return $this->hasRestrictedVoiceAndVideoMessages; - } - - /** - * @param bool $hasRestrictedVoiceAndVideoMessages - * @return void - */ - public function setHasRestrictedVoiceAndVideoMessages($hasRestrictedVoiceAndVideoMessages) - { - $this->hasRestrictedVoiceAndVideoMessages = $hasRestrictedVoiceAndVideoMessages; - } } diff --git a/src/Types/ChatAdministratorRights.php b/src/Types/ChatAdministratorRights.php new file mode 100644 index 00000000..a2b54a9c --- /dev/null +++ b/src/Types/ChatAdministratorRights.php @@ -0,0 +1,411 @@ + true, + 'can_manage_chat' => true, + 'can_delete_messages' => true, + 'can_manage_video_chats' => true, + 'can_restrict_members' => true, + 'can_promote_members' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_post_stories' => true, + 'can_edit_stories' => true, + 'can_delete_stories' => true, + 'can_post_messages' => true, + 'can_edit_messages' => true, + 'can_pin_messages' => true, + 'can_manage_topics' => true, + ]; + + /** + * True, if the user's presence in the chat is hidden + * + * @var bool + */ + protected $isAnonymous; + + /** + * True, if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode. Implied by any other administrator privilege. + * + * @var bool + */ + protected $canManageChat; + + /** + * True, if the administrator can delete messages of other users + * + * @var bool + */ + protected $canDeleteMessages; + + /** + * True, if the administrator can manage video chats + * + * @var bool + */ + protected $canManageVideoChats; + + /** + * True, if the administrator can restrict, ban or unban chat members, or access supergroup statistics + * + * @var bool + */ + protected $canRestrictMembers; + + /** + * True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user) + * + * @var bool + */ + protected $canPromoteMembers; + + /** + * True, if the user is allowed to change the chat title, photo and other settings + * + * @var bool + */ + protected $canChangeInfo; + + /** + * True, if the user is allowed to invite new users to the chat + * + * @var bool + */ + protected $canInviteUsers; + + /** + * True, if the administrator can post stories to the chat + * + * @var bool + */ + protected $canPostStories; + + /** + * True, if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat's story archive + * + * @var bool + */ + protected $canEditStories; + + /** + * True, if the administrator can delete stories posted by other users + * + * @var bool + */ + protected $canDeleteStories; + + /** + * Optional. True, if the administrator can post messages in the channel, or access channel statistics; for channels only + * + * @var bool|null + */ + protected $canPostMessages; + + /** + * Optional. True, if the administrator can edit messages of other users and can pin messages; for channels only + * + * @var bool|null + */ + protected $canEditMessages; + + /** + * Optional. True, if the user is allowed to pin messages; for groups and supergroups only + * + * @var bool|null + */ + protected $canPinMessages; + + /** + * Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only + * + * @var bool|null + */ + protected $canManageTopics; + + /** + * @return bool + */ + public function isAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + * @return void + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return bool + */ + public function canManageChat() + { + return $this->canManageChat; + } + + /** + * @param bool $canManageChat + * @return void + */ + public function setCanManageChat($canManageChat) + { + $this->canManageChat = $canManageChat; + } + + /** + * @return bool + */ + public function canDeleteMessages() + { + return $this->canDeleteMessages; + } + + /** + * @param bool $canDeleteMessages + * @return void + */ + public function setCanDeleteMessages($canDeleteMessages) + { + $this->canDeleteMessages = $canDeleteMessages; + } + + /** + * @return bool + */ + public function canManageVideoChats() + { + return $this->canManageVideoChats; + } + + /** + * @param bool $canManageVideoChats + * @return void + */ + public function setCanManageVideoChats($canManageVideoChats) + { + $this->canManageVideoChats = $canManageVideoChats; + } + + /** + * @return bool + */ + public function canRestrictMembers() + { + return $this->canRestrictMembers; + } + + /** + * @param bool $canRestrictMembers + * @return void + */ + public function setCanRestrictMembers($canRestrictMembers) + { + $this->canRestrictMembers = $canRestrictMembers; + } + + /** + * @return bool + */ + public function canPromoteMembers() + { + return $this->canPromoteMembers; + } + + /** + * @param bool $canPromoteMembers + * @return void + */ + public function setCanPromoteMembers($canPromoteMembers) + { + $this->canPromoteMembers = $canPromoteMembers; + } + + /** + * @return bool + */ + public function canChangeInfo() + { + return $this->canChangeInfo; + } + + /** + * @param bool $canChangeInfo + * @return void + */ + public function setCanChangeInfo($canChangeInfo) + { + $this->canChangeInfo = $canChangeInfo; + } + + /** + * @return bool + */ + public function canInviteUsers() + { + return $this->canInviteUsers; + } + + /** + * @param bool $canInviteUsers + * @return void + */ + public function setCanInviteUsers($canInviteUsers) + { + $this->canInviteUsers = $canInviteUsers; + } + + /** + * @return bool + */ + public function canPostStories() + { + return $this->canPostStories; + } + + /** + * @param bool $canPostStories + * @return void + */ + public function setCanPostStories($canPostStories) + { + $this->canPostStories = $canPostStories; + } + + /** + * @return bool + */ + public function canEditStories() + { + return $this->canEditStories; + } + + /** + * @param bool $canEditStories + * @return void + */ + public function setCanEditStories($canEditStories) + { + $this->canEditStories = $canEditStories; + } + + /** + * @return bool + */ + public function canDeleteStories() + { + return $this->canDeleteStories; + } + + /** + * @param bool $canDeleteStories + * @return void + */ + public function setCanDeleteStories($canDeleteStories) + { + $this->canDeleteStories = $canDeleteStories; + } + + /** + * @return bool|null + */ + public function canPostMessages() + { + return $this->canPostMessages; + } + + /** + * @param bool|null $canPostMessages + * @return void + */ + public function setCanPostMessages($canPostMessages) + { + $this->canPostMessages = $canPostMessages; + } + + /** + * @return bool|null + */ + public function canEditMessages() + { + return $this->canEditMessages; + } + + /** + * @param bool|null $canEditMessages + * @return void + */ + public function setCanEditMessages($canEditMessages) + { + $this->canEditMessages = $canEditMessages; + } + + /** + * @return bool|null + */ + public function canPinMessages() + { + return $this->canPinMessages; + } + + /** + * @param bool|null $canPinMessages + * @return void + */ + public function setCanPinMessages($canPinMessages) + { + $this->canPinMessages = $canPinMessages; + } + + /** + * @return bool|null + */ + public function canManageTopics() + { + return $this->canManageTopics; + } + + /** + * @param bool|null $canManageTopics + * @return void + */ + public function setCanManageTopics($canManageTopics) + { + $this->canManageTopics = $canManageTopics; + } +} diff --git a/src/Types/ChatBackground.php b/src/Types/ChatBackground.php new file mode 100644 index 00000000..614c9469 --- /dev/null +++ b/src/Types/ChatBackground.php @@ -0,0 +1,55 @@ + BackgroundType::class, + ]; + + /** + * Type of the background + * + * @var BackgroundType + */ + protected $type; + + /** + * @return BackgroundType + */ + public function getType() + { + return $this->type; + } + + /** + * @param BackgroundType $type + * @return void + */ + public function setType(BackgroundType $type) + { + $this->type = $type; + } +} diff --git a/src/Types/ChatBoost.php b/src/Types/ChatBoost.php new file mode 100644 index 00000000..a913c839 --- /dev/null +++ b/src/Types/ChatBoost.php @@ -0,0 +1,126 @@ + true, + 'add_date' => true, + 'expiration_date' => true, + 'source' => ChatBoostSource::class + ]; + + /** + * Unique identifier of the boost + * + * @var string + */ + protected $boostId; + + /** + * Point in time (Unix timestamp) when the chat was boosted + * + * @var int + */ + protected $addDate; + + /** + * Point in time (Unix timestamp) when the boost will automatically expire, unless the booster's Telegram Premium subscription is prolonged + * + * @var int + */ + protected $expirationDate; + + /** + * Source of the added boost + * + * @var ChatBoostSource + */ + protected $source; + + /** + * @return string + */ + public function getBoostId() + { + return $this->boostId; + } + + /** + * @param string $boostId + */ + public function setBoostId($boostId) + { + $this->boostId = $boostId; + } + + /** + * @return int + */ + public function getAddDate() + { + return $this->addDate; + } + + /** + * @param int $addDate + */ + public function setAddDate($addDate) + { + $this->addDate = $addDate; + } + + /** + * @return int + */ + public function getExpirationDate() + { + return $this->expirationDate; + } + + /** + * @param int $expirationDate + */ + public function setExpirationDate($expirationDate) + { + $this->expirationDate = $expirationDate; + } + + /** + * @return ChatBoostSource + */ + public function getSource() + { + return $this->source; + } + + /** + * @param ChatBoostSource $source + */ + public function setSource($source) + { + $this->source = $source; + } +} diff --git a/src/Types/ChatBoostAdded.php b/src/Types/ChatBoostAdded.php new file mode 100644 index 00000000..5e040e80 --- /dev/null +++ b/src/Types/ChatBoostAdded.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * Number of boosts added by the user + * + * @var int + */ + protected $boostCount; + + /** + * @return int + */ + public function getBoostCount() + { + return $this->boostCount; + } + + /** + * @param int $boostCount + * @return void + */ + public function setBoostCount($boostCount) + { + $this->boostCount = $boostCount; + } +} diff --git a/src/Types/ChatBoostRemoved.php b/src/Types/ChatBoostRemoved.php new file mode 100644 index 00000000..8ec1e8f9 --- /dev/null +++ b/src/Types/ChatBoostRemoved.php @@ -0,0 +1,126 @@ + Chat::class, + 'boost_id' => true, + 'remove_date' => true, + 'source' => ChatBoostSource::class + ]; + + /** + * Chat which was boosted + * + * @var Chat + */ + protected $chat; + + /** + * Unique identifier of the boost + * + * @var string + */ + protected $boostId; + + /** + * Point in time (Unix timestamp) when the boost was removed + * + * @var int + */ + protected $removeDate; + + /** + * Source of the removed boost + * + * @var ChatBoostSource + */ + protected $source; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return string + */ + public function getBoostId() + { + return $this->boostId; + } + + /** + * @param string $boostId + */ + public function setBoostId($boostId) + { + $this->boostId = $boostId; + } + + /** + * @return int + */ + public function getRemoveDate() + { + return $this->removeDate; + } + + /** + * @param int $removeDate + */ + public function setRemoveDate($removeDate) + { + $this->removeDate = $removeDate; + } + + /** + * @return ChatBoostSource + */ + public function getSource() + { + return $this->source; + } + + /** + * @param ChatBoostSource $source + */ + public function setSource($source) + { + $this->source = $source; + } +} diff --git a/src/Types/ChatBoostSource.php b/src/Types/ChatBoostSource.php new file mode 100644 index 00000000..bb3a0917 --- /dev/null +++ b/src/Types/ChatBoostSource.php @@ -0,0 +1,96 @@ + true, + 'user' => User::class, + ]; + + public static function fromResponse($data) + { + self::validate($data); + $source = $data['source']; + + switch ($source) { + case 'premium': + return ChatBoostSourcePremium::fromResponse($data); + case 'gift_code': + return ChatBoostSourceGiftCode::fromResponse($data); + case 'giveaway': + return ChatBoostSourceGiveaway::fromResponse($data); + default: + throw new InvalidArgumentException("Unknown chat boost source: $source"); + } + } + + /** + * Source of the boost, always “premium”, “gift_code”, or “giveaway” + * + * @var string + */ + protected $source; + + /** + * User that boosted the chat or for which the gift code was created + * + * @var User + */ + protected $user; + + /** + * @return string + */ + public function getSource() + { + return $this->source; + } + + /** + * @param string $source + */ + public function setSource($source) + { + $this->source = $source; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $user + */ + public function setUser($user) + { + $this->user = $user; + } +} diff --git a/src/Types/ChatBoostSourceGiftCode.php b/src/Types/ChatBoostSourceGiftCode.php new file mode 100644 index 00000000..f54f6cc7 --- /dev/null +++ b/src/Types/ChatBoostSourceGiftCode.php @@ -0,0 +1,53 @@ + true, + 'user' => User::class + ]; + + /** + * Source of the boost, always “gift_code” + * + * @var string + */ + protected $source = 'gift_code'; + + /** + * User for which the gift code was created + * + * @var User + */ + protected $user; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } +} diff --git a/src/Types/ChatBoostSourceGiveaway.php b/src/Types/ChatBoostSourceGiveaway.php new file mode 100644 index 00000000..941e45a8 --- /dev/null +++ b/src/Types/ChatBoostSourceGiveaway.php @@ -0,0 +1,103 @@ + true, + 'giveaway_message_id' => true, + 'user' => User::class, + 'is_unclaimed' => true + ]; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * Source of the boost, always “giveaway” + * + * @var string + */ + protected $source = 'giveaway'; + + /** + * Identifier of a message in the chat with the giveaway + * + * @var int|null + */ + protected $giveawayMessageId; + + /** + * Optional. User that won the prize in the giveaway if any + * + * @var User|null + */ + protected $user; + + /** + * Optional. True, if the giveaway was completed, but there was no user to win the prize + * + * @var bool|null + */ + protected $isUnclaimed; + + /** + * @return int|null + */ + public function getGiveawayMessageId(): ?int + { + return $this->giveawayMessageId; + } + + /** + * @param int|null $giveawayMessageId + * @return void + */ + public function setGiveawayMessageId(?int $giveawayMessageId): void + { + $this->giveawayMessageId = $giveawayMessageId; + } + + /** + * @return bool|null + */ + public function getIsUnclaimed(): ?bool + { + return $this->isUnclaimed; + } + + /** + * @param bool|null $isUnclaimed + * @return void + */ + public function setIsUnclaimed(?bool $isUnclaimed): void + { + $this->isUnclaimed = $isUnclaimed; + } +} diff --git a/src/Types/ChatBoostSourcePremium.php b/src/Types/ChatBoostSourcePremium.php new file mode 100644 index 00000000..9e05b62f --- /dev/null +++ b/src/Types/ChatBoostSourcePremium.php @@ -0,0 +1,85 @@ + true, + 'user' => User::class + ]; + + /** + * Source of the boost, always “premium” + * + * @var string + */ + protected $source = 'premium'; + + /** + * User that boosted the chat + * + * @var User + */ + protected $user; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getSource(): string + { + return $this->source; + } + + /** + * @param string $source + */ + public function setSource($source): void + { + $this->source = $source; + } + + /** + * @return User + */ + public function getUser(): User + { + return $this->user; + } + + /** + * @param User $user + */ + public function setUser($user): void + { + $this->user = $user; + } +} diff --git a/src/Types/ChatBoostUpdated.php b/src/Types/ChatBoostUpdated.php new file mode 100644 index 00000000..1298db0c --- /dev/null +++ b/src/Types/ChatBoostUpdated.php @@ -0,0 +1,78 @@ + Chat::class, + 'boost' => ChatBoost::class + ]; + + /** + * Chat which was boosted + * + * @var Chat + */ + protected $chat; + + /** + * Information about the chat boost + * + * @var ChatBoost + */ + protected $boost; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return ChatBoost + */ + public function getBoost() + { + return $this->boost; + } + + /** + * @param ChatBoost $boost + */ + public function setBoost($boost) + { + $this->boost = $boost; + } +} diff --git a/src/Types/ChatFullInfo.php b/src/Types/ChatFullInfo.php new file mode 100644 index 00000000..b3a93cfa --- /dev/null +++ b/src/Types/ChatFullInfo.php @@ -0,0 +1,1069 @@ + true, + 'type' => true, + 'title' => true, + 'username' => true, + 'first_name' => true, + 'last_name' => true, + 'is_forum' => true, + 'accent_color_id' => true, + 'max_reaction_count' => true, + 'photo' => ChatPhoto::class, + 'active_usernames' => true, + 'birthdate' => true, + 'business_intro' => true, + 'business_location' => true, + 'business_opening_hours' => true, + 'personal_chat' => Chat::class, + 'available_reactions' => ArrayOfReactionType::class, + 'background_custom_emoji_id' => true, + 'profile_accent_color_id' => true, + 'profile_background_custom_emoji_id' => true, + 'emoji_status_custom_emoji_id' => true, + 'emoji_status_expiration_date' => true, + 'bio' => true, + 'has_private_forwards' => true, + 'has_restricted_voice_and_video_messages' => true, + 'join_to_send_messages' => true, + 'join_by_request' => true, + 'description' => true, + 'invite_link' => true, + 'pinned_message' => Message::class, + 'permissions' => ChatPermissions::class, + 'slow_mode_delay' => true, + 'unrestrict_boost_count' => true, + 'message_auto_delete_time' => true, + 'has_aggressive_anti_spam_enabled' => true, + 'has_hidden_members' => true, + 'has_protected_content' => true, + 'has_visible_history' => true, + 'sticker_set_name' => true, + 'can_set_sticker_set' => true, + 'custom_emoji_sticker_set_name' => true, + 'linked_chat_id' => true, + 'location' => ChatLocation::class, + ]; + + /** + * Unique identifier for this chat. + * + * @var int|float|string + */ + protected $id; + + /** + * Type of chat, can be either “private”, “group”, “supergroup” or “channel”. + * + * @var string + */ + protected $type; + + /** + * Optional. Title, for supergroups, channels and group chats. + * + * @var string|null + */ + protected $title; + + /** + * Optional. Username, for private chats, supergroups and channels if available. + * + * @var string|null + */ + protected $username; + + /** + * Optional. First name of the other party in a private chat. + * + * @var string|null + */ + protected $firstName; + + /** + * Optional. Last name of the other party in a private chat. + * + * @var string|null + */ + protected $lastName; + + /** + * Optional. True, if the supergroup chat is a forum (has topics enabled). + * + * @var bool|null + */ + protected $isForum; + + /** + * Optional. Identifier of the accent color for the chat name and backgrounds of the chat photo, reply header, and link preview. + * + * @var int|null + */ + protected $accentColorId; + + /** + * Optional. The maximum number of reactions that can be set on a message in the chat. + * + * @var int|null + */ + protected $maxReactionCount; + + /** + * Optional. Chat photo. Returned only in getChat. + * + * @var ChatPhoto|null + */ + protected $photo; + + /** + * Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels. Returned only in getChat. + * + * @var array|null + */ + protected $activeUsernames; + + /** + * Optional. For private chats, the date of birth of the user. + * + * @var string|null + */ + protected $birthdate; + + /** + * Optional. For private chats with business accounts, the intro of the business. + * + * @var string|null + */ + protected $businessIntro; + + /** + * Optional. For private chats with business accounts, the location of the business. + * + * @var string|null + */ + protected $businessLocation; + + /** + * Optional. For private chats with business accounts, the opening hours of the business. + * + * @var string|null + */ + protected $businessOpeningHours; + + /** + * Optional. For private chats, the personal channel of the user. + * + * @var Chat|null + */ + protected $personalChat; + + /** + * Optional. List of available reactions allowed in the chat. If omitted, then all emoji reactions are allowed. Returned only in getChat. + * + * @var array|null + */ + protected $availableReactions; + + /** + * Optional. Custom emoji identifier of emoji chosen by the chat for the reply header and link preview background. + * + * @var string|null + */ + protected $backgroundCustomEmojiId; + + /** + * Optional. Identifier of the accent color for the chat's profile background. + * + * @var int|null + */ + protected $profileAccentColorId; + + /** + * Optional. Custom emoji identifier of the emoji chosen by the chat for its profile background. + * + * @var string|null + */ + protected $profileBackgroundCustomEmojiId; + + /** + * Optional. Custom emoji identifier of the emoji status of the chat or the other party in a private chat. Returned only in getChat. + * + * @var string|null + */ + protected $emojiStatusCustomEmojiId; + + /** + * Optional. Expiration date of the emoji status of the chat or the other party in a private chat, in Unix time, if any. + * + * @var int|null + */ + protected $emojiStatusExpirationDate; + + /** + * Optional. Bio of the other party in a private chat. Returned only in getChat. + * + * @var string|null + */ + protected $bio; + + /** + * Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id= links only in chats with the user. + * + * @var bool|null + */ + protected $hasPrivateForwards; + + /** + * Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. Returned only in getChat. + * + * @var bool|null + */ + protected $hasRestrictedVoiceAndVideoMessages; + + /** + * Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. + * + * @var bool|null + */ + protected $joinToSendMessages; + + /** + * Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat. + * + * @var bool|null + */ + protected $joinByRequest; + + /** + * Optional. Description, for groups, supergroups and channel chats. Returned only in getChat. + * + * @var string|null + */ + protected $description; + + /** + * Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat. + * + * @var string|null + */ + protected $inviteLink; + + /** + * Optional. The most recent pinned message (by sending date). Returned only in getChat. + * + * @var Message|null + */ + protected $pinnedMessage; + + /** + * Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. + * + * @var ChatPermissions|null + */ + protected $permissions; + + /** + * Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unprivileged user; in seconds. Returned only in getChat. + * + * @var int|null + */ + protected $slowModeDelay; + + /** + * Optional. For supergroups, the minimum number of boosts that a non-administrator user needs to add in order to ignore slow mode and chat permissions. + * + * @var int|null + */ + protected $unrestrictBoostCount; + + /** + * Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat. + * + * @var int|null + */ + protected $messageAutoDeleteTime; + + /** + * Optional. True, if aggressive anti-spam checks are enabled in the supergroup. The field is only available to chat administrators. Returned only in getChat. + * + * @var bool|null + */ + protected $hasAggressiveAntiSpamEnabled; + + /** + * Optional. True, if non-administrators can only get the list of bots and administrators in the chat. Returned only in getChat. + * + * @var bool|null + */ + protected $hasHiddenMembers; + + /** + * Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. + * + * @var bool|null + */ + protected $hasProtectedContent; + + /** + * Optional. True, if new chat members will have access to old messages; available only to chat administrators. Returned only in getChat. + * + * @var bool|null + */ + protected $hasVisibleHistory; + + /** + * Optional. For supergroups, name of the group sticker set. Returned only in getChat. + * + * @var string|null + */ + protected $stickerSetName; + + /** + * Optional. True, if the bot can change the group sticker set. Returned only in getChat. + * + * @var bool|null + */ + protected $canSetStickerSet; + + /** + * Optional. For supergroups, the name of the group's custom emoji sticker set. Custom emoji from this set can be used by all users and bots in the group. + * + * @var string|null + */ + protected $customEmojiStickerSetName; + + /** + * Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice versa; for supergroups and channel chats. This identifier may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + * + * @var int|null + */ + protected $linkedChatId; + + /** + * Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. + * + * @var ChatLocation|null + */ + protected $location; + + /** + * @return int|float|string + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $id + * @return void + * @throws InvalidArgumentException + */ + public function setId($id) + { + if (is_integer($id) || is_float($id) || is_string($id)) { + $this->id = $id; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string|null + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string|null $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string|null + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param string|null $username + */ + public function setUsername($username) + { + $this->username = $username; + } + + /** + * @return string|null + */ + public function getFirstName() + { + return $this->firstName; + } + + /** + * @param string|null $firstName + */ + public function setFirstName($firstName) + { + $this->firstName = $firstName; + } + + /** + * @return string|null + */ + public function getLastName() + { + return $this->lastName; + } + + /** + * @param string|null $lastName + */ + public function setLastName($lastName) + { + $this->lastName = $lastName; + } + + /** + * @return bool|null + */ + public function getIsForum() + { + return $this->isForum; + } + + /** + * @param bool|null $isForum + */ + public function setIsForum($isForum) + { + $this->isForum = $isForum; + } + + /** + * @return int|null + */ + public function getAccentColorId() + { + return $this->accentColorId; + } + + /** + * @param int|null $accentColorId + */ + public function setAccentColorId($accentColorId) + { + $this->accentColorId = $accentColorId; + } + + /** + * @return int|null + */ + public function getMaxReactionCount() + { + return $this->maxReactionCount; + } + + /** + * @param int|null $maxReactionCount + */ + public function setMaxReactionCount($maxReactionCount) + { + $this->maxReactionCount = $maxReactionCount; + } + + /** + * @return ChatPhoto|null + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param ChatPhoto|null $photo + */ + public function setPhoto($photo) + { + $this->photo = $photo; + } + + /** + * @return array|null + */ + public function getActiveUsernames() + { + return $this->activeUsernames; + } + + /** + * @param array|null $activeUsernames + */ + public function setActiveUsernames($activeUsernames) + { + $this->activeUsernames = $activeUsernames; + } + + /** + * @return string|null + */ + public function getBirthdate() + { + return $this->birthdate; + } + + /** + * @param string|null $birthdate + */ + public function setBirthdate($birthdate) + { + $this->birthdate = $birthdate; + } + + /** + * @return string|null + */ + public function getBusinessIntro() + { + return $this->businessIntro; + } + + /** + * @param string|null $businessIntro + */ + public function setBusinessIntro($businessIntro) + { + $this->businessIntro = $businessIntro; + } + + /** + * @return string|null + */ + public function getBusinessLocation() + { + return $this->businessLocation; + } + + /** + * @param string|null $businessLocation + */ + public function setBusinessLocation($businessLocation) + { + $this->businessLocation = $businessLocation; + } + + /** + * @return string|null + */ + public function getBusinessOpeningHours() + { + return $this->businessOpeningHours; + } + + /** + * @param string|null $businessOpeningHours + */ + public function setBusinessOpeningHours($businessOpeningHours) + { + $this->businessOpeningHours = $businessOpeningHours; + } + + /** + * @return Chat|null + */ + public function getPersonalChat() + { + return $this->personalChat; + } + + /** + * @param Chat|null $personalChat + */ + public function setPersonalChat($personalChat) + { + $this->personalChat = $personalChat; + } + + /** + * @return array|null + */ + public function getAvailableReactions() + { + return $this->availableReactions; + } + + /** + * @param array|null $availableReactions + */ + public function setAvailableReactions($availableReactions) + { + $this->availableReactions = $availableReactions; + } + + /** + * @return string|null + */ + public function getBackgroundCustomEmojiId() + { + return $this->backgroundCustomEmojiId; + } + + /** + * @param string|null $backgroundCustomEmojiId + */ + public function setBackgroundCustomEmojiId($backgroundCustomEmojiId) + { + $this->backgroundCustomEmojiId = $backgroundCustomEmojiId; + } + + /** + * @return int|null + */ + public function getProfileAccentColorId() + { + return $this->profileAccentColorId; + } + + /** + * @param int|null $profileAccentColorId + */ + public function setProfileAccentColorId($profileAccentColorId) + { + $this->profileAccentColorId = $profileAccentColorId; + } + + /** + * @return string|null + */ + public function getProfileBackgroundCustomEmojiId() + { + return $this->profileBackgroundCustomEmojiId; + } + + /** + * @param string|null $profileBackgroundCustomEmojiId + */ + public function setProfileBackgroundCustomEmojiId($profileBackgroundCustomEmojiId) + { + $this->profileBackgroundCustomEmojiId = $profileBackgroundCustomEmojiId; + } + + /** + * @return string|null + */ + public function getEmojiStatusCustomEmojiId() + { + return $this->emojiStatusCustomEmojiId; + } + + /** + * @param string|null $emojiStatusCustomEmojiId + */ + public function setEmojiStatusCustomEmojiId($emojiStatusCustomEmojiId) + { + $this->emojiStatusCustomEmojiId = $emojiStatusCustomEmojiId; + } + + /** + * @return int|null + */ + public function getEmojiStatusExpirationDate() + { + return $this->emojiStatusExpirationDate; + } + + /** + * @param int|null $emojiStatusExpirationDate + */ + public function setEmojiStatusExpirationDate($emojiStatusExpirationDate) + { + $this->emojiStatusExpirationDate = $emojiStatusExpirationDate; + } + + /** + * @return string|null + */ + public function getBio() + { + return $this->bio; + } + + /** + * @param string|null $bio + */ + public function setBio($bio) + { + $this->bio = $bio; + } + + /** + * @return bool|null + */ + public function getHasPrivateForwards() + { + return $this->hasPrivateForwards; + } + + /** + * @param bool|null $hasPrivateForwards + */ + public function setHasPrivateForwards($hasPrivateForwards) + { + $this->hasPrivateForwards = $hasPrivateForwards; + } + + /** + * @return bool|null + */ + public function getHasRestrictedVoiceAndVideoMessages() + { + return $this->hasRestrictedVoiceAndVideoMessages; + } + + /** + * @param bool|null $hasRestrictedVoiceAndVideoMessages + */ + public function setHasRestrictedVoiceAndVideoMessages($hasRestrictedVoiceAndVideoMessages) + { + $this->hasRestrictedVoiceAndVideoMessages = $hasRestrictedVoiceAndVideoMessages; + } + + /** + * @return bool|null + */ + public function getJoinToSendMessages() + { + return $this->joinToSendMessages; + } + + /** + * @param bool|null $joinToSendMessages + */ + public function setJoinToSendMessages($joinToSendMessages) + { + $this->joinToSendMessages = $joinToSendMessages; + } + + /** + * @return bool|null + */ + public function getJoinByRequest() + { + return $this->joinByRequest; + } + + /** + * @param bool|null $joinByRequest + */ + public function setJoinByRequest($joinByRequest) + { + $this->joinByRequest = $joinByRequest; + } + + /** + * @return string|null + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string|null $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * @return string|null + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param string|null $inviteLink + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } + + /** + * @return Message|null + */ + public function getPinnedMessage() + { + return $this->pinnedMessage; + } + + /** + * @param Message|null $pinnedMessage + */ + public function setPinnedMessage($pinnedMessage) + { + $this->pinnedMessage = $pinnedMessage; + } + + /** + * @return ChatPermissions|null + */ + public function getPermissions() + { + return $this->permissions; + } + + /** + * @param ChatPermissions|null $permissions + */ + public function setPermissions($permissions) + { + $this->permissions = $permissions; + } + + /** + * @return int|null + */ + public function getSlowModeDelay() + { + return $this->slowModeDelay; + } + + /** + * @param int|null $slowModeDelay + */ + public function setSlowModeDelay($slowModeDelay) + { + $this->slowModeDelay = $slowModeDelay; + } + + /** + * @return int|null + */ + public function getUnrestrictBoostCount() + { + return $this->unrestrictBoostCount; + } + + /** + * @param int|null $unrestrictBoostCount + */ + public function setUnrestrictBoostCount($unrestrictBoostCount) + { + $this->unrestrictBoostCount = $unrestrictBoostCount; + } + + /** + * @return int|null + */ + public function getMessageAutoDeleteTime() + { + return $this->messageAutoDeleteTime; + } + + /** + * @param int|null $messageAutoDeleteTime + */ + public function setMessageAutoDeleteTime($messageAutoDeleteTime) + { + $this->messageAutoDeleteTime = $messageAutoDeleteTime; + } + + /** + * @return bool|null + */ + public function getHasAggressiveAntiSpamEnabled() + { + return $this->hasAggressiveAntiSpamEnabled; + } + + /** + * @param bool|null $hasAggressiveAntiSpamEnabled + */ + public function setHasAggressiveAntiSpamEnabled($hasAggressiveAntiSpamEnabled) + { + $this->hasAggressiveAntiSpamEnabled = $hasAggressiveAntiSpamEnabled; + } + + /** + * @return bool|null + */ + public function getHasHiddenMembers() + { + return $this->hasHiddenMembers; + } + + /** + * @param bool|null $hasHiddenMembers + */ + public function setHasHiddenMembers($hasHiddenMembers) + { + $this->hasHiddenMembers = $hasHiddenMembers; + } + + /** + * @return bool|null + */ + public function getHasProtectedContent() + { + return $this->hasProtectedContent; + } + + /** + * @param bool|null $hasProtectedContent + */ + public function setHasProtectedContent($hasProtectedContent) + { + $this->hasProtectedContent = $hasProtectedContent; + } + + /** + * @return bool|null + */ + public function getHasVisibleHistory() + { + return $this->hasVisibleHistory; + } + + /** + * @param bool|null $hasVisibleHistory + */ + public function setHasVisibleHistory($hasVisibleHistory) + { + $this->hasVisibleHistory = $hasVisibleHistory; + } + + /** + * @return string|null + */ + public function getStickerSetName() + { + return $this->stickerSetName; + } + + /** + * @param string|null $stickerSetName + */ + public function setStickerSetName($stickerSetName) + { + $this->stickerSetName = $stickerSetName; + } + + /** + * @return bool|null + */ + public function getCanSetStickerSet() + { + return $this->canSetStickerSet; + } + + /** + * @param bool|null $canSetStickerSet + */ + public function setCanSetStickerSet($canSetStickerSet) + { + $this->canSetStickerSet = $canSetStickerSet; + } + + /** + * @return string|null + */ + public function getCustomEmojiStickerSetName() + { + return $this->customEmojiStickerSetName; + } + + /** + * @param string|null $customEmojiStickerSetName + */ + public function setCustomEmojiStickerSetName($customEmojiStickerSetName) + { + $this->customEmojiStickerSetName = $customEmojiStickerSetName; + } + + /** + * @return int|null + */ + public function getLinkedChatId() + { + return $this->linkedChatId; + } + + /** + * @param int|null $linkedChatId + */ + public function setLinkedChatId($linkedChatId) + { + $this->linkedChatId = $linkedChatId; + } + + /** + * @return ChatLocation|null + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param ChatLocation|null $location + */ + public function setLocation($location) + { + $this->location = $location; + } +} diff --git a/src/Types/ChatMember.php b/src/Types/ChatMember.php index 808597e0..f8df0915 100644 --- a/src/Types/ChatMember.php +++ b/src/Types/ChatMember.php @@ -3,15 +3,47 @@ namespace TelegramBot\Api\Types; use TelegramBot\Api\BaseType; +use TelegramBot\Api\InvalidArgumentException; +use TelegramBot\Api\TypeInterface; -class ChatMember extends BaseType +abstract class ChatMember extends BaseType implements TypeInterface { /** * {@inheritdoc} * * @var array */ - protected static $requiredParams = ['user', 'status']; + protected static $requiredParams = ['status', 'user']; + + /** + * Factory method to create a concrete ChatMember instance + * + * @param array $data + * @return ChatMember + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + $status = $data['status']; + + switch ($status) { + case 'creator': + return ChatMemberOwner::fromResponse($data); + case 'administrator': + return ChatMemberAdministrator::fromResponse($data); + case 'member': + return ChatMemberMember::fromResponse($data); + case 'restricted': + return ChatMemberRestricted::fromResponse($data); + case 'left': + return ChatMemberLeft::fromResponse($data); + case 'kicked': + return ChatMemberBanned::fromResponse($data); + default: + throw new InvalidArgumentException("Unknown chat member status: $status"); + } + } /** * {@inheritdoc} @@ -19,199 +51,23 @@ class ChatMember extends BaseType * @var array */ protected static $map = [ - 'user' => User::class, 'status' => true, - 'until_date' => true, - 'can_be_edited' => true, - 'can_change_info' => true, - 'can_post_messages' => true, - 'can_edit_messages' => true, - 'can_delete_messages' => true, - 'can_invite_users' => true, - 'can_restrict_members' => true, - 'can_pin_messages' => true, - 'can_promote_members' => true, - 'can_send_messages' => true, - 'can_send_media_messages' => true, - 'can_send_other_messages' => true, - 'can_add_web_page_previews' => true, - 'can_manage_topics' => true, - 'is_anonymous' => true, - 'custom_title' => true, - 'can_manage_chat' => true, - 'can_send_polls' => true, + 'user' => User::class, ]; /** - * Information about the user - * - * @var User - */ - protected $user; - - /** - * The member's status in the chat. Can be “creator”, “administrator”, “member”, “restricted”, “left” or “kicked” + * The member's status in the chat * * @var string */ protected $status; /** - * Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time - * - * @var integer|null - */ - protected $untilDate; - - /** - * Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user - * - * @var bool|null - */ - protected $canBeEdited; - - /** - * Optional. Administrators only. True, if the administrator can change the chat title, photo and other settings - * - * @var bool|null - */ - protected $canChangeInfo; - - /** - * Optional. Administrators only. True, if the administrator can post in the channel, channels only - * - * @var bool|null - */ - protected $canPostMessages; - - /** - * Optional. Administrators only. True, if the administrator can edit messages of other users, channels only - * - * @var bool|null - */ - protected $canEditMessages; - - /** - * Optional. Administrators only. True, if the administrator can delete messages of other users - * - * @var bool|null - */ - protected $canDeleteMessages; - - /** - * Optional. Administrators only. True, if the administrator can invite new users to the chat - * - * @var bool|null - */ - protected $canInviteUsers; - - /** - * Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members - * - * @var bool|null - */ - protected $canRestrictMembers; - - /** - * Optional. Administrators only. True, if the administrator can pin messages, supergroups only - * - * @var bool|null - */ - protected $canPinMessages; - - /** - * Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own - * privileges or demote administrators that he has promoted, directly or indirectly - * (promoted by administrators that were appointed by the user) - * - * @var bool|null - */ - protected $canPromoteMembers; - - /** - * Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues - * - * @var bool|null - */ - protected $canSendMessages; - - /** - * Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes - * and voice notes, implies can_send_messages - * - * @var bool|null - */ - protected $canSendMediaMessages; - - /** - * Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, - * implies can_send_media_messages - * - * @var bool|null - */ - protected $canSendOtherMessages; - - /** - * Optional. Restricted only. True, if user may add web page previews to his messages, - * implies can_send_media_messages - * - * @var bool|null - */ - protected $canAddWebPagePreviews; - - /** - * Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only - * - * @var bool|null - */ - protected $canManageTopics; - - /** - * True, if the user's presence in the chat is hidden - * - * @var bool - */ - protected $isAnonymous; - - /** - * Optional. Custom title for this user - * - * @var string|null - */ - protected $customTitle; - - /** - * True, if the administrator can access the chat event log, chat statistics, message statistics in channels, - * see channel members, see anonymous administrators in supergroups and ignore slow mode. - * Implied by any other administrator privilege - * - * @var bool - */ - protected $canManageChat; - - /** - * True, if the user is allowed to send polls + * Information about the user * - * @var bool - */ - protected $canSendPolls; - - /** - * @return User - */ - public function getUser() - { - return $this->user; - } - - /** - * @param User $user - * @return void + * @var User */ - public function setUser($user) - { - $this->user = $user; - } + protected $user; /** * @return string @@ -231,325 +87,19 @@ public function setStatus($status) } /** - * @return int|null - */ - public function getUntilDate() - { - return $this->untilDate; - } - - /** - * @param int $untilDate - * @return void - */ - public function setUntilDate($untilDate) - { - $this->untilDate = $untilDate; - } - - /** - * @return bool|null - */ - public function getCanBeEdited() - { - return $this->canBeEdited; - } - - /** - * @param bool $canBeEdited - * @return void - */ - public function setCanBeEdited($canBeEdited) - { - $this->canBeEdited = $canBeEdited; - } - - /** - * @return bool|null - */ - public function getCanChangeInfo() - { - return $this->canChangeInfo; - } - - /** - * @param bool $canChangeInfo - * @return void - */ - public function setCanChangeInfo($canChangeInfo) - { - $this->canChangeInfo = $canChangeInfo; - } - - /** - * @return bool|null - */ - public function getCanPostMessages() - { - return $this->canPostMessages; - } - - /** - * @param bool $canPostMessages - * @return void - */ - public function setCanPostMessages($canPostMessages) - { - $this->canPostMessages = $canPostMessages; - } - - /** - * @return bool|null - */ - public function getCanEditMessages() - { - return $this->canEditMessages; - } - - /** - * @param bool $canEditMessages - * @return void - */ - public function setCanEditMessages($canEditMessages) - { - $this->canEditMessages = $canEditMessages; - } - - /** - * @return bool|null - */ - public function getCanDeleteMessages() - { - return $this->canDeleteMessages; - } - - /** - * @param bool $canDeleteMessages - * @return void - */ - public function setCanDeleteMessages($canDeleteMessages) - { - $this->canDeleteMessages = $canDeleteMessages; - } - - /** - * @return bool|null - */ - public function getCanInviteUsers() - { - return $this->canInviteUsers; - } - - /** - * @param bool $canInviteUsers - * @return void - */ - public function setCanInviteUsers($canInviteUsers) - { - $this->canInviteUsers = $canInviteUsers; - } - - /** - * @return bool|null - */ - public function getCanRestrictMembers() - { - return $this->canRestrictMembers; - } - - /** - * @param bool $canRestrictMembers - * @return void - */ - public function setCanRestrictMembers($canRestrictMembers) - { - $this->canRestrictMembers = $canRestrictMembers; - } - - /** - * @return bool|null - */ - public function getCanPinMessages() - { - return $this->canPinMessages; - } - - /** - * @param bool $canPinMessages - * @return void - */ - public function setCanPinMessages($canPinMessages) - { - $this->canPinMessages = $canPinMessages; - } - - /** - * @return bool|null - */ - public function getCanPromoteMembers() - { - return $this->canPromoteMembers; - } - - /** - * @param bool $canPromoteMembers - * @return void - */ - public function setCanPromoteMembers($canPromoteMembers) - { - $this->canPromoteMembers = $canPromoteMembers; - } - - /** - * @return bool|null - */ - public function getCanSendMessages() - { - return $this->canSendMessages; - } - - /** - * @param bool $canSendMessages - * @return void - */ - public function setCanSendMessages($canSendMessages) - { - $this->canSendMessages = $canSendMessages; - } - - /** - * @return bool|null - */ - public function getCanSendMediaMessages() - { - return $this->canSendMediaMessages; - } - - /** - * @param bool $canSendMediaMessages - * @return void - */ - public function setCanSendMediaMessages($canSendMediaMessages) - { - $this->canSendMediaMessages = $canSendMediaMessages; - } - - /** - * @return bool|null - */ - public function getCanSendOtherMessages() - { - return $this->canSendOtherMessages; - } - - /** - * @param bool $canSendOtherMessages - * @return void - */ - public function setCanSendOtherMessages($canSendOtherMessages) - { - $this->canSendOtherMessages = $canSendOtherMessages; - } - - /** - * @return bool|null - */ - public function getCanAddWebPagePreviews() - { - return $this->canAddWebPagePreviews; - } - - /** - * @param bool $canAddWebPagePreviews - * @return void - */ - public function setCanAddWebPagePreviews($canAddWebPagePreviews) - { - $this->canAddWebPagePreviews = $canAddWebPagePreviews; - } - - /** - * @return bool - */ - public function getCanManageChat() - { - return $this->canManageChat; - } - - /** - * @param bool $canManageChat - * @return void - */ - public function setCanManageChat($canManageChat) - { - $this->canManageChat = $canManageChat; - } - - /** - * @return bool - */ - public function getIsAnonymous() - { - return $this->isAnonymous; - } - - /** - * @param bool $isAnonymous - * @return void - */ - public function setIsAnonymous($isAnonymous) - { - $this->isAnonymous = $isAnonymous; - } - - /** - * @return bool - */ - public function getCanSendPolls() - { - return $this->canSendPolls; - } - - /** - * @param bool $canSendPolls - * @return void - */ - public function setCanSendPolls($canSendPolls) - { - $this->canSendPolls = $canSendPolls; - } - - /** - * @return bool|null - */ - public function getCanManageTopics() - { - return $this->canManageTopics; - } - - /** - * @param bool $canManageTopics - * @return void - */ - public function setCanManageTopics($canManageTopics) - { - $this->canManageTopics = $canManageTopics; - } - - /** - * @return null|string + * @return User */ - public function getCustomTitle() + public function getUser() { - return $this->customTitle; + return $this->user; } /** - * @param string $customTitle + * @param User $user * @return void */ - public function setCustomTitle($customTitle) + public function setUser($user) { - $this->customTitle = $customTitle; + $this->user = $user; } } diff --git a/src/Types/ChatMemberAdministrator.php b/src/Types/ChatMemberAdministrator.php new file mode 100644 index 00000000..0ee56bf7 --- /dev/null +++ b/src/Types/ChatMemberAdministrator.php @@ -0,0 +1,458 @@ + true, + 'user' => User::class, + 'can_be_edited' => true, + 'is_anonymous' => true, + 'can_manage_chat' => true, + 'can_delete_messages' => true, + 'can_manage_video_chats' => true, + 'can_restrict_members' => true, + 'can_promote_members' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_post_stories' => true, + 'can_edit_stories' => true, + 'can_delete_stories' => true, + 'can_post_messages' => true, + 'can_edit_messages' => true, + 'can_pin_messages' => true, + 'can_manage_topics' => true, + 'custom_title' => true, + ]; + + /** + * True, if the bot is allowed to edit administrator privileges of that user + * + * @var bool + */ + protected $canBeEdited; + + /** + * True, if the user's presence in the chat is hidden + * + * @var bool + */ + protected $isAnonymous; + + /** + * True, if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode + * + * @var bool + */ + protected $canManageChat; + + /** + * True, if the administrator can delete messages of other users + * + * @var bool + */ + protected $canDeleteMessages; + + /** + * True, if the administrator can manage video chats + * + * @var bool + */ + protected $canManageVideoChats; + + /** + * True, if the administrator can restrict, ban or unban chat members, or access supergroup statistics + * + * @var bool + */ + protected $canRestrictMembers; + + /** + * True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly + * + * @var bool + */ + protected $canPromoteMembers; + + /** + * True, if the user is allowed to change the chat title, photo and other settings + * + * @var bool + */ + protected $canChangeInfo; + + /** + * True, if the user is allowed to invite new users to the chat + * + * @var bool + */ + protected $canInviteUsers; + + /** + * True, if the administrator can post stories to the chat + * + * @var bool|null + */ + protected $canPostStories; + + /** + * True, if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat's story archive + * + * @var bool|null + */ + protected $canEditStories; + + /** + * True, if the administrator can delete stories posted by other users + * + * @var bool|null + */ + protected $canDeleteStories; + + /** + * Optional. True, if the administrator can post messages in the channel, or access channel statistics; for channels only + * + * @var bool|null + */ + protected $canPostMessages; + + /** + * Optional. True, if the administrator can edit messages of other users and can pin messages; for channels only + * + * @var bool|null + */ + protected $canEditMessages; + + /** + * Optional. True, if the user is allowed to pin messages; for groups and supergroups only + * + * @var bool|null + */ + protected $canPinMessages; + + /** + * Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only + * + * @var bool|null + */ + protected $canManageTopics; + + /** + * Optional. Custom title for this user + * + * @var string|null + */ + protected $customTitle; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return bool + */ + public function canBeEdited() + { + return $this->canBeEdited; + } + + /** + * @param bool $canBeEdited + * @return void + */ + public function setCanBeEdited($canBeEdited) + { + $this->canBeEdited = $canBeEdited; + } + + /** + * @return bool + */ + public function isAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + * @return void + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return bool + */ + public function canManageChat() + { + return $this->canManageChat; + } + + /** + * @param bool $canManageChat + * @return void + */ + public function setCanManageChat($canManageChat) + { + $this->canManageChat = $canManageChat; + } + + /** + * @return bool + */ + public function canDeleteMessages() + { + return $this->canDeleteMessages; + } + + /** + * @param bool $canDeleteMessages + * @return void + */ + public function setCanDeleteMessages($canDeleteMessages) + { + $this->canDeleteMessages = $canDeleteMessages; + } + + /** + * @return bool + */ + public function canManageVideoChats() + { + return $this->canManageVideoChats; + } + + /** + * @param bool $canManageVideoChats + * @return void + */ + public function setCanManageVideoChats($canManageVideoChats) + { + $this->canManageVideoChats = $canManageVideoChats; + } + + /** + * @return bool + */ + public function canRestrictMembers() + { + return $this->canRestrictMembers; + } + + /** + * @param bool $canRestrictMembers + * @return void + */ + public function setCanRestrictMembers($canRestrictMembers) + { + $this->canRestrictMembers = $canRestrictMembers; + } + + /** + * @return bool + */ + public function canPromoteMembers() + { + return $this->canPromoteMembers; + } + + /** + * @param bool $canPromoteMembers + * @return void + */ + public function setCanPromoteMembers($canPromoteMembers) + { + $this->canPromoteMembers = $canPromoteMembers; + } + + /** + * @return bool + */ + public function canChangeInfo() + { + return $this->canChangeInfo; + } + + /** + * @param bool $canChangeInfo + * @return void + */ + public function setCanChangeInfo($canChangeInfo) + { + $this->canChangeInfo = $canChangeInfo; + } + + /** + * @return bool + */ + public function canInviteUsers() + { + return $this->canInviteUsers; + } + + /** + * @param bool $canInviteUsers + * @return void + */ + public function setCanInviteUsers($canInviteUsers) + { + $this->canInviteUsers = $canInviteUsers; + } + + /** + * @return bool|null + */ + public function canPostStories() + { + return $this->canPostStories; + } + + /** + * @param bool|null $canPostStories + * @return void + */ + public function setCanPostStories($canPostStories) + { + $this->canPostStories = $canPostStories; + } + + /** + * @return bool|null + */ + public function canEditStories() + { + return $this->canEditStories; + } + + /** + * @param bool|null $canEditStories + * @return void + */ + public function setCanEditStories($canEditStories) + { + $this->canEditStories = $canEditStories; + } + + /** + * @return bool|null + */ + public function canDeleteStories() + { + return $this->canDeleteStories; + } + + /** + * @param bool|null $canDeleteStories + * @return void + */ + public function setCanDeleteStories($canDeleteStories) + { + $this->canDeleteStories = $canDeleteStories; + } + + /** + * @return bool|null + */ + public function canPostMessages() + { + return $this->canPostMessages; + } + + /** + * @param bool|null $canPostMessages + * @return void + */ + public function setCanPostMessages($canPostMessages) + { + $this->canPostMessages = $canPostMessages; + } + + /** + * @return bool|null + */ + public function canEditMessages() + { + return $this->canEditMessages; + } + + /** + * @param bool|null $canEditMessages + * @return void + */ + public function setCanEditMessages($canEditMessages) + { + $this->canEditMessages = $canEditMessages; + } + + /** + * @return bool|null + */ + public function canPinMessages() + { + return $this->canPinMessages; + } + + /** + * @param bool|null $canPinMessages + * @return void + */ + public function setCanPinMessages($canPinMessages) + { + $this->canPinMessages = $canPinMessages; + } + + /** + * @return bool|null + */ + public function canManageTopics() + { + return $this->canManageTopics; + } + + /** + * @param bool|null $canManageTopics + * @return void + */ + public function setCanManageTopics($canManageTopics) + { + $this->canManageTopics = $canManageTopics; + } + + /** + * @return string|null + */ + public function getCustomTitle() + { + return $this->customTitle; + } + + /** + * @param string|null $customTitle + * @return void + */ + public function setCustomTitle($customTitle) + { + $this->customTitle = $customTitle; + } +} diff --git a/src/Types/ChatMemberBanned.php b/src/Types/ChatMemberBanned.php new file mode 100644 index 00000000..17647318 --- /dev/null +++ b/src/Types/ChatMemberBanned.php @@ -0,0 +1,58 @@ + true, + 'user' => User::class, + 'until_date' => true, + ]; + + /** + * Date when restrictions will be lifted for this user; Unix time. If 0, then the user is banned forever + * + * @var int + */ + protected $untilDate; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return int + */ + public function getUntilDate() + { + return $this->untilDate; + } + + /** + * @param int $untilDate + * @return void + */ + public function setUntilDate($untilDate) + { + $this->untilDate = $untilDate; + } +} diff --git a/src/Types/ChatMemberLeft.php b/src/Types/ChatMemberLeft.php new file mode 100644 index 00000000..85c96feb --- /dev/null +++ b/src/Types/ChatMemberLeft.php @@ -0,0 +1,23 @@ +map($data); + + return $instance; + } +} diff --git a/src/Types/ChatMemberMember.php b/src/Types/ChatMemberMember.php new file mode 100644 index 00000000..ae1a8678 --- /dev/null +++ b/src/Types/ChatMemberMember.php @@ -0,0 +1,23 @@ +map($data); + + return $instance; + } +} diff --git a/src/Types/ChatMemberOwner.php b/src/Types/ChatMemberOwner.php new file mode 100644 index 00000000..e6c6520c --- /dev/null +++ b/src/Types/ChatMemberOwner.php @@ -0,0 +1,83 @@ + true, + 'user' => User::class, + 'is_anonymous' => true, + 'custom_title' => true, + ]; + + /** + * True, if the user's presence in the chat is hidden + * + * @var bool + */ + protected $isAnonymous; + + /** + * Optional. Custom title for this user + * + * @var string|null + */ + protected $customTitle; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return bool + */ + public function isAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + * @return void + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return string|null + */ + public function getCustomTitle() + { + return $this->customTitle; + } + + /** + * @param string|null $customTitle + * @return void + */ + public function setCustomTitle($customTitle) + { + $this->customTitle = $customTitle; + } +} diff --git a/src/Types/ChatMemberRestricted.php b/src/Types/ChatMemberRestricted.php new file mode 100644 index 00000000..386305b4 --- /dev/null +++ b/src/Types/ChatMemberRestricted.php @@ -0,0 +1,433 @@ + true, + 'user' => User::class, + 'is_member' => true, + 'can_send_messages' => true, + 'can_send_audios' => true, + 'can_send_documents' => true, + 'can_send_photos' => true, + 'can_send_videos' => true, + 'can_send_video_notes' => true, + 'can_send_voice_notes' => true, + 'can_send_polls' => true, + 'can_send_other_messages' => true, + 'can_add_web_page_previews' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_pin_messages' => true, + 'can_manage_topics' => true, + 'until_date' => true, + ]; + + /** + * True, if the user is a member of the chat at the moment of the request + * + * @var bool + */ + protected $isMember; + + /** + * True, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues + * + * @var bool + */ + protected $canSendMessages; + + /** + * True, if the user is allowed to send audios + * + * @var bool + */ + protected $canSendAudios; + + /** + * True, if the user is allowed to send documents + * + * @var bool + */ + protected $canSendDocuments; + + /** + * True, if the user is allowed to send photos + * + * @var bool + */ + protected $canSendPhotos; + + /** + * True, if the user is allowed to send videos + * + * @var bool + */ + protected $canSendVideos; + + /** + * True, if the user is allowed to send video notes + * + * @var bool + */ + protected $canSendVideoNotes; + + /** + * True, if the user is allowed to send voice notes + * + * @var bool + */ + protected $canSendVoiceNotes; + + /** + * True, if the user is allowed to send polls + * + * @var bool + */ + protected $canSendPolls; + + /** + * True, if the user is allowed to send animations, games, stickers and use inline bots + * + * @var bool + */ + protected $canSendOtherMessages; + + /** + * True, if the user is allowed to add web page previews to their messages + * + * @var bool + */ + protected $canAddWebPagePreviews; + + /** + * True, if the user is allowed to change the chat title, photo and other settings + * + * @var bool + */ + protected $canChangeInfo; + + /** + * True, if the user is allowed to invite new users to the chat + * + * @var bool + */ + protected $canInviteUsers; + + /** + * True, if the user is allowed to pin messages + * + * @var bool + */ + protected $canPinMessages; + + /** + * True, if the user is allowed to create forum topics + * + * @var bool + */ + protected $canManageTopics; + + /** + * Date when restrictions will be lifted for this user; Unix time. If 0, then the user is restricted forever + * + * @var int + */ + protected $untilDate; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return bool + */ + public function isMember() + { + return $this->isMember; + } + + /** + * @param bool $isMember + * @return void + */ + public function setIsMember($isMember) + { + $this->isMember = $isMember; + } + + /** + * @return bool + */ + public function canSendMessages() + { + return $this->canSendMessages; + } + + /** + * @param bool $canSendMessages + * @return void + */ + public function setCanSendMessages($canSendMessages) + { + $this->canSendMessages = $canSendMessages; + } + + /** + * @return bool + */ + public function canSendAudios() + { + return $this->canSendAudios; + } + + /** + * @param bool $canSendAudios + * @return void + */ + public function setCanSendAudios($canSendAudios) + { + $this->canSendAudios = $canSendAudios; + } + + /** + * @return bool + */ + public function canSendDocuments() + { + return $this->canSendDocuments; + } + + /** + * @param bool $canSendDocuments + * @return void + */ + public function setCanSendDocuments($canSendDocuments) + { + $this->canSendDocuments = $canSendDocuments; + } + + /** + * @return bool + */ + public function canSendPhotos() + { + return $this->canSendPhotos; + } + + /** + * @param bool $canSendPhotos + * @return void + */ + public function setCanSendPhotos($canSendPhotos) + { + $this->canSendPhotos = $canSendPhotos; + } + + /** + * @return bool + */ + public function canSendVideos() + { + return $this->canSendVideos; + } + + /** + * @param bool $canSendVideos + * @return void + */ + public function setCanSendVideos($canSendVideos) + { + $this->canSendVideos = $canSendVideos; + } + + /** + * @return bool + */ + public function canSendVideoNotes() + { + return $this->canSendVideoNotes; + } + + /** + * @param bool $canSendVideoNotes + * @return void + */ + public function setCanSendVideoNotes($canSendVideoNotes) + { + $this->canSendVideoNotes = $canSendVideoNotes; + } + + /** + * @return bool + */ + public function canSendVoiceNotes() + { + return $this->canSendVoiceNotes; + } + + /** + * @param bool $canSendVoiceNotes + * @return void + */ + public function setCanSendVoiceNotes($canSendVoiceNotes) + { + $this->canSendVoiceNotes = $canSendVoiceNotes; + } + + /** + * @return bool + */ + public function canSendPolls() + { + return $this->canSendPolls; + } + + /** + * @param bool $canSendPolls + * @return void + */ + public function setCanSendPolls($canSendPolls) + { + $this->canSendPolls = $canSendPolls; + } + + /** + * @return bool + */ + public function canSendOtherMessages() + { + return $this->canSendOtherMessages; + } + + /** + * @param bool $canSendOtherMessages + * @return void + */ + public function setCanSendOtherMessages($canSendOtherMessages) + { + $this->canSendOtherMessages = $canSendOtherMessages; + } + + /** + * @return bool + */ + public function canAddWebPagePreviews() + { + return $this->canAddWebPagePreviews; + } + + /** + * @param bool $canAddWebPagePreviews + * @return void + */ + public function setCanAddWebPagePreviews($canAddWebPagePreviews) + { + $this->canAddWebPagePreviews = $canAddWebPagePreviews; + } + + /** + * @return bool + */ + public function canChangeInfo() + { + return $this->canChangeInfo; + } + + /** + * @param bool $canChangeInfo + * @return void + */ + public function setCanChangeInfo($canChangeInfo) + { + $this->canChangeInfo = $canChangeInfo; + } + + /** + * @return bool + */ + public function canInviteUsers() + { + return $this->canInviteUsers; + } + + /** + * @param bool $canInviteUsers + * @return void + */ + public function setCanInviteUsers($canInviteUsers) + { + $this->canInviteUsers = $canInviteUsers; + } + + /** + * @return bool + */ + public function canPinMessages() + { + return $this->canPinMessages; + } + + /** + * @param bool $canPinMessages + * @return void + */ + public function setCanPinMessages($canPinMessages) + { + $this->canPinMessages = $canPinMessages; + } + + /** + * @return bool + */ + public function canManageTopics() + { + return $this->canManageTopics; + } + + /** + * @param bool $canManageTopics + * @return void + */ + public function setCanManageTopics($canManageTopics) + { + $this->canManageTopics = $canManageTopics; + } + + /** + * @return int + */ + public function getUntilDate() + { + return $this->untilDate; + } + + /** + * @param int $untilDate + * @return void + */ + public function setUntilDate($untilDate) + { + $this->untilDate = $untilDate; + } +} diff --git a/src/Types/ChatMemberUpdated.php b/src/Types/ChatMemberUpdated.php index 2c3ffb86..298f8169 100644 --- a/src/Types/ChatMemberUpdated.php +++ b/src/Types/ChatMemberUpdated.php @@ -26,9 +26,20 @@ class ChatMemberUpdated extends BaseType implements TypeInterface 'old_chat_member' => ChatMember::class, 'new_chat_member' => ChatMember::class, 'invite_link' => ChatInviteLink::class, + 'via_join_request' => true, 'via_chat_folder_invite_link' => true, ]; + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + /** * Chat the user belongs to * @@ -78,6 +89,13 @@ class ChatMemberUpdated extends BaseType implements TypeInterface */ protected $viaChatFolderInviteLink; + /** + * Optional. True, if the user joined the chat after sending a direct join request without using an invite link and being approved by an administrator + * + * @var bool|null + */ + protected $viaJoinRequest; + /** * @return Chat */ @@ -196,4 +214,21 @@ public function setViaChatFolderInviteLink($viaChatFolderInviteLink) { $this->viaChatFolderInviteLink = $viaChatFolderInviteLink; } + + /** + * @return bool|null + */ + public function getViaJoinRequest() + { + return $this->viaJoinRequest; + } + + /** + * @param bool|null $viaJoinRequest + * @return void + */ + public function setViaJoinRequest($viaJoinRequest) + { + $this->viaJoinRequest = $viaJoinRequest; + } } diff --git a/src/Types/ChatPhoto.php b/src/Types/ChatPhoto.php index acce238d..7fbabceb 100644 --- a/src/Types/ChatPhoto.php +++ b/src/Types/ChatPhoto.php @@ -20,7 +20,9 @@ class ChatPhoto extends BaseType */ protected static $map = [ 'small_file_id' => true, + 'small_file_unique_id' => true, 'big_file_id' => true, + 'big_file_unique_id' => true, ]; /** @@ -30,6 +32,13 @@ class ChatPhoto extends BaseType */ protected $smallFileId; + /** + * Unique file identifier of small (160x160) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $smallFileUniqueId; + /** * Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download. * @@ -37,6 +46,13 @@ class ChatPhoto extends BaseType */ protected $bigFileId; + /** + * Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $bigFileUniqueId; + /** * @return string */ @@ -54,6 +70,23 @@ public function setSmallFileId($smallFileId) $this->smallFileId = $smallFileId; } + /** + * @return string + */ + public function getSmallFileUniqueId() + { + return $this->smallFileUniqueId; + } + + /** + * @param string $smallFileUniqueId + * @return void + */ + public function setSmallFileUniqueId($smallFileUniqueId) + { + $this->smallFileUniqueId = $smallFileUniqueId; + } + /** * @return string */ @@ -70,4 +103,21 @@ public function setBigFileId($bigFileId) { $this->bigFileId = $bigFileId; } + + /** + * @return string + */ + public function getBigFileUniqueId() + { + return $this->bigFileUniqueId; + } + + /** + * @param string $bigFileUniqueId + * @return void + */ + public function setBigFileUniqueId($bigFileUniqueId) + { + $this->bigFileUniqueId = $bigFileUniqueId; + } } diff --git a/src/Types/ChatShared.php b/src/Types/ChatShared.php new file mode 100644 index 00000000..fc28a422 --- /dev/null +++ b/src/Types/ChatShared.php @@ -0,0 +1,156 @@ + true, + 'chat_id' => true, + 'title' => true, + 'username' => true, + 'photo' => ArrayOfPhotoSize::class, + ]; + + /** + * Identifier of the request + * + * @var int + */ + protected $requestId; + + /** + * Identifier of the shared chat + * + * @var int + */ + protected $chatId; + + /** + * Optional. Title of the chat + * + * @var string|null + */ + protected $title; + + /** + * Optional. Username of the chat + * + * @var string|null + */ + protected $username; + + /** + * Optional. Available sizes of the chat photo + * Array of \TelegramBot\Api\Types\PhotoSize + * + * @var array|null + */ + protected $photo; + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @param int $requestId + * @return void + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + } + + /** + * @return int + */ + public function getChatId() + { + return $this->chatId; + } + + /** + * @param int $chatId + * @return void + */ + public function setChatId($chatId) + { + $this->chatId = $chatId; + } + + /** + * @return string|null + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string|null $title + * @return void + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string|null + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param string|null $username + * @return void + */ + public function setUsername($username) + { + $this->username = $username; + } + + /** + * @return array|null + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param array|null $photo + * @return void + */ + public function setPhoto($photo) + { + $this->photo = $photo; + } +} diff --git a/src/Types/Dice.php b/src/Types/Dice.php index b2077418..7ebde544 100644 --- a/src/Types/Dice.php +++ b/src/Types/Dice.php @@ -8,6 +8,8 @@ /** * Class Dice * This object represents an animated emoji that displays a random value. + * + * @package TelegramBot\Api\Types */ class Dice extends BaseType implements TypeInterface { diff --git a/src/Types/Document.php b/src/Types/Document.php index e7b951bd..8b067f68 100644 --- a/src/Types/Document.php +++ b/src/Types/Document.php @@ -8,7 +8,7 @@ /** * Class Document - * This object represents a general file (as opposed to photos and audio files). + * This object represents a general file (as opposed to photos, voice messages and audio files). * Telegram users can send files of any type of up to 1.5 GB in size. * * @package TelegramBot\Api\Types @@ -44,9 +44,16 @@ class Document extends BaseType implements TypeInterface protected $fileId; /** - * Document thumbnail as defined by sender + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + + /** + * Optional. Document thumbnail as defined by sender * - * @var PhotoSize + * @var PhotoSize|null */ protected $thumbnail; @@ -65,19 +72,12 @@ class Document extends BaseType implements TypeInterface protected $mimeType; /** - * Optional. File size + * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. * * @var int|null */ protected $fileSize; - /** - * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. - * - * @var string - */ - protected $fileUniqueId; - /** * @return string */ @@ -96,114 +96,114 @@ public function setFileId($fileId) } /** - * @return null|string + * @return string */ - public function getFileName() + public function getFileUniqueId() { - return $this->fileName; + return $this->fileUniqueId; } /** - * @param string $fileName + * @param string $fileUniqueId * @return void */ - public function setFileName($fileName) + public function setFileUniqueId($fileUniqueId) { - $this->fileName = $fileName; + $this->fileUniqueId = $fileUniqueId; } /** - * @return int|null + * @return PhotoSize|null */ - public function getFileSize() + public function getThumbnail() { - return $this->fileSize; + return $this->thumbnail; } /** - * @param mixed $fileSize + * @param PhotoSize|null $thumbnail * @return void - * @throws InvalidArgumentException */ - public function setFileSize($fileSize) + public function setThumbnail($thumbnail) { - if (is_integer($fileSize)) { - $this->fileSize = $fileSize; - } else { - throw new InvalidArgumentException(); - } + $this->thumbnail = $thumbnail; } /** - * @return null|string + * @deprecated use getThumbnail method + * + * @return PhotoSize|null */ - public function getMimeType() + public function getThumb() { - return $this->mimeType; + return $this->getThumbnail(); } /** - * @param string $mimeType + * @deprecated use setThumbnail method + * + * @param PhotoSize $thumb + * * @return void */ - public function setMimeType($mimeType) + public function setThumb($thumb) { - $this->mimeType = $mimeType; + $this->setThumbnail($thumb); } /** - * @return PhotoSize + * @return string|null */ - public function getThumbnail() + public function getFileName() { - return $this->thumbnail; + return $this->fileName; } /** - * @param PhotoSize $thumbnail + * @param string|null $fileName * @return void */ - public function setThumbnail(PhotoSize $thumbnail) + public function setFileName($fileName) { - $this->thumbnail = $thumbnail; + $this->fileName = $fileName; } /** - * @deprecated use getThumbnail method - * - * @return PhotoSize|null + * @return string|null */ - public function getThumb() + public function getMimeType() { - return $this->getThumbnail(); + return $this->mimeType; } /** - * @deprecated use setThumbnail method - * - * @param PhotoSize $thumb - * + * @param string|null $mimeType * @return void */ - public function setThumb($thumb) + public function setMimeType($mimeType) { - $this->setThumbnail($thumb); + $this->mimeType = $mimeType; } /** - * @return string + * @return int|null */ - public function getFileUniqueId() + public function getFileSize() { - return $this->fileUniqueId; + return $this->fileSize; } /** - * @param string $fileUniqueId + * @param int|null $fileSize * @return void + * @throws InvalidArgumentException */ - public function setFileUniqueId($fileUniqueId) + public function setFileSize($fileSize) { - $this->fileUniqueId = $fileUniqueId; + if (is_integer($fileSize) || is_null($fileSize)) { + $this->fileSize = $fileSize; + } else { + throw new InvalidArgumentException(); + } } } diff --git a/src/Types/ExternalReplyInfo.php b/src/Types/ExternalReplyInfo.php new file mode 100644 index 00000000..0a760c82 --- /dev/null +++ b/src/Types/ExternalReplyInfo.php @@ -0,0 +1,646 @@ + MessageOrigin::class, + 'chat' => Chat::class, + 'message_id' => true, + 'link_preview_options' => LinkPreviewOptions::class, + 'animation' => Animation::class, + 'audio' => Audio::class, + 'document' => Document::class, + 'photo' => ArrayOfPhotoSize::class, + 'sticker' => Sticker::class, + 'story' => Story::class, + 'video' => Video::class, + 'video_note' => VideoNote::class, + 'voice' => Voice::class, + 'has_media_spoiler' => true, + 'contact' => Contact::class, + 'dice' => Dice::class, + 'game' => Game::class, + 'giveaway' => Giveaway::class, + 'giveaway_winners' => GiveawayWinners::class, + 'invoice' => Invoice::class, + 'location' => Location::class, + 'poll' => Poll::class, + 'venue' => Venue::class, + ]; + + /** + * Origin of the message replied to by the given message + * + * @var MessageOrigin + */ + protected $origin; + + /** + * Optional. Chat the original message belongs to. Available only if the chat is a supergroup or a channel. + * + * @var Chat|null + */ + protected $chat; + + /** + * Optional. Unique message identifier inside the original chat. Available only if the original chat is a supergroup or a channel. + * + * @var int|null + */ + protected $messageId; + + /** + * Optional. Options used for link preview generation for the original message, if it is a text message + * + * @var LinkPreviewOptions|null + */ + protected $linkPreviewOptions; + + /** + * Optional. Message is an animation, information about the animation + * + * @var Animation|null + */ + protected $animation; + + /** + * Optional. Message is an audio file, information about the file + * + * @var Audio|null + */ + protected $audio; + + /** + * Optional. Message is a general file, information about the file + * + * @var Document|null + */ + protected $document; + + /** + * Optional. Message is a photo, available sizes of the photo + * + * @var array|null + */ + protected $photo; + + /** + * Optional. Message is a sticker, information about the sticker + * + * @var Sticker|null + */ + protected $sticker; + + /** + * Optional. Message is a forwarded story + * + * @var Story|null + */ + protected $story; + + /** + * Optional. Message is a video, information about the video + * + * @var Video|null + */ + protected $video; + + /** + * Optional. Message is a video note, information about the video message + * + * @var VideoNote|null + */ + protected $videoNote; + + /** + * Optional. Message is a voice message, information about the file + * + * @var Voice|null + */ + protected $voice; + + /** + * Optional. True, if the message media is covered by a spoiler animation + * + * @var bool|null + */ + protected $hasMediaSpoiler; + + /** + * Optional. Message is a shared contact, information about the contact + * + * @var Contact|null + */ + protected $contact; + + /** + * Optional. Message is a dice with random value + * + * @var Dice|null + */ + protected $dice; + + /** + * Optional. Message is a game, information about the game + * + * @var Game|null + */ + protected $game; + + /** + * Optional. Message is a scheduled giveaway, information about the giveaway + * + * @var Giveaway|null + */ + protected $giveaway; + + /** + * Optional. A giveaway with public winners was completed + * + * @var GiveawayWinners|null + */ + protected $giveawayWinners; + + /** + * Optional. Message is an invoice for a payment, information about the invoice + * + * @var Invoice|null + */ + protected $invoice; + + /** + * Optional. Message is a shared location, information about the location + * + * @var Location|null + */ + protected $location; + + /** + * Optional. Message is a native poll, information about the poll + * + * @var Poll|null + */ + protected $poll; + + /** + * Optional. Message is a venue, information about the venue + * + * @var Venue|null + */ + protected $venue; + + /** + * @return MessageOrigin + */ + public function getOrigin() + { + return $this->origin; + } + + /** + * @param MessageOrigin $origin + * @return void + */ + public function setOrigin(MessageOrigin $origin) + { + $this->origin = $origin; + } + + /** + * @return Chat|null + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat|null $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int|null + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int|null $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } + + /** + * @return LinkPreviewOptions|null + */ + public function getLinkPreviewOptions() + { + return $this->linkPreviewOptions; + } + + /** + * @param LinkPreviewOptions|null $linkPreviewOptions + * @return void + */ + public function setLinkPreviewOptions($linkPreviewOptions) + { + $this->linkPreviewOptions = $linkPreviewOptions; + } + + /** + * @return Animation|null + */ + public function getAnimation() + { + return $this->animation; + } + + /** + * @param Animation|null $animation + * @return void + */ + public function setAnimation($animation) + { + $this->animation = $animation; + } + + /** + * @return Audio|null + */ + public function getAudio() + { + return $this->audio; + } + + /** + * @param Audio|null $audio + * @return void + */ + public function setAudio($audio) + { + $this->audio = $audio; + } + + /** + * @return Document|null + */ + public function getDocument() + { + return $this->document; + } + + /** + * @param Document|null $document + * @return void + */ + public function setDocument($document) + { + $this->document = $document; + } + + /** + * @return array|null + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param array|null $photo + * @return void + */ + public function setPhoto($photo) + { + $this->photo = $photo; + } + + /** + * @return Sticker|null + */ + public function getSticker() + { + return $this->sticker; + } + + /** + * @param Sticker|null $sticker + * @return void + */ + public function setSticker($sticker) + { + $this->sticker = $sticker; + } + + /** + * @return Story|null + */ + public function getStory() + { + return $this->story; + } + + /** + * @param Story|null $story + * @return void + */ + public function setStory($story) + { + $this->story = $story; + } + + /** + * @return Video|null + */ + public function getVideo() + { + return $this->video; + } + + /** + * @param Video|null $video + * @return void + */ + public function setVideo($video) + { + $this->video = $video; + } + + /** + * @return VideoNote|null + */ + public function getVideoNote() + { + return $this->videoNote; + } + + /** + * @param VideoNote|null $videoNote + * @return void + */ + public function setVideoNote($videoNote) + { + $this->videoNote = $videoNote; + } + + /** + * @return Voice|null + */ + public function getVoice() + { + return $this->voice; + } + + /** + * @param Voice|null $voice + * @return void + */ + public function setVoice($voice) + { + $this->voice = $voice; + } + + /** + * @return bool|null + */ + public function getHasMediaSpoiler() + { + return $this->hasMediaSpoiler; + } + + /** + * @param bool|null $hasMediaSpoiler + * @return void + */ + public function setHasMediaSpoiler($hasMediaSpoiler) + { + $this->hasMediaSpoiler = $hasMediaSpoiler; + } + + /** + * @return Contact|null + */ + public function getContact() + { + return $this->contact; + } + + /** + * @param Contact|null $contact + * @return void + */ + public function setContact($contact) + { + $this->contact = $contact; + } + + /** + * @return Dice|null + */ + public function getDice() + { + return $this->dice; + } + + /** + * @param Dice|null $dice + * @return void + */ + public function setDice($dice) + { + $this->dice = $dice; + } + + /** + * @return Game|null + */ + public function getGame() + { + return $this->game; + } + + /** + * @param Game|null $game + * @return void + */ + public function setGame($game) + { + $this->game = $game; + } + + /** + * @return Giveaway|null + */ + public function getGiveaway() + { + return $this->giveaway; + } + + /** + * @param Giveaway|null $giveaway + * @return void + */ + public function setGiveaway($giveaway) + { + $this->giveaway = $giveaway; + } + + /** + * @return GiveawayWinners|null + */ + public function getGiveawayWinners() + { + return $this->giveawayWinners; + } + + /** + * @param GiveawayWinners|null $giveawayWinners + * @return void + */ + public function setGiveawayWinners($giveawayWinners) + { + $this->giveawayWinners = $giveawayWinners; + } + + /** + * @return Invoice|null + */ + public function getInvoice() + { + return $this->invoice; + } + + /** + * @param Invoice|null $invoice + * @return void + */ + public function setInvoice($invoice) + { + $this->invoice = $invoice; + } + + /** + * @return Location|null + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param Location|null $location + * @return void + */ + public function setLocation($location) + { + $this->location = $location; + } + + /** + * @return Poll|null + */ + public function getPoll() + { + return $this->poll; + } + + /** + * @param Poll|null $poll + * @return void + */ + public function setPoll($poll) + { + $this->poll = $poll; + } + + /** + * @return Venue|null + */ + public function getVenue() + { + return $this->venue; + } + + /** + * @param Venue|null $venue + * @return void + */ + public function setVenue($venue) + { + $this->venue = $venue; + } +} + +/** + * Class ArrayOfPhotoSize + * Represents an array of PhotoSize objects. + * + * @package TelegramBot\Api\Types + */ +class ArrayOfPhotoSize extends BaseType implements TypeInterface +{ + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'photos' => PhotoSize::class, + ]; + + /** + * @var array + */ + protected $photos; + + /** + * @return array + */ + public function getPhotos() + { + return $this->photos; + } + + /** + * @param array $photos + * @return void + */ + public function setPhotos($photos) + { + $this->photos = $photos; + } +} diff --git a/src/Types/ForumTopicCreated.php b/src/Types/ForumTopicCreated.php index 30cc78fc..f1da401c 100644 --- a/src/Types/ForumTopicCreated.php +++ b/src/Types/ForumTopicCreated.php @@ -6,7 +6,7 @@ use TelegramBot\Api\TypeInterface; /** - * class ForumTopicCreated. + * Class ForumTopicCreated * This object represents a service message about a new forum topic created in the chat. * * @package TelegramBot\Api\Types @@ -42,14 +42,14 @@ class ForumTopicCreated extends BaseType implements TypeInterface /** * Color of the forum topic * - * @var string + * @var int */ protected $iconColor; /** - * Custom emoji of the forum topic + * Optional. Unique identifier of the custom emoji shown as the topic icon * - * @var string + * @var string|null */ protected $iconCustomEmojiId; @@ -71,7 +71,7 @@ public function setName($name) } /** - * @return string + * @return int */ public function getIconColor() { @@ -79,7 +79,7 @@ public function getIconColor() } /** - * @param string $iconColor + * @param int $iconColor * @return void */ public function setIconColor($iconColor) @@ -88,7 +88,7 @@ public function setIconColor($iconColor) } /** - * @return string + * @return string|null */ public function getIconCustomEmojiId() { @@ -96,7 +96,7 @@ public function getIconCustomEmojiId() } /** - * @param string $iconCustomEmojiId + * @param string|null $iconCustomEmojiId * @return void */ public function setIconCustomEmojiId($iconCustomEmojiId) diff --git a/src/Types/ForumTopicEdited.php b/src/Types/ForumTopicEdited.php new file mode 100644 index 00000000..c51a9c25 --- /dev/null +++ b/src/Types/ForumTopicEdited.php @@ -0,0 +1,73 @@ + true, + 'icon_custom_emoji_id' => true, + ]; + + /** + * Optional. New name of the topic, if it was edited + * + * @var string|null + */ + protected $name; + + /** + * Optional. New identifier of the custom emoji shown as the topic icon, if it was edited; an empty string if the icon was removed + * + * @var string|null + */ + protected $iconCustomEmojiId; + + /** + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * @param string|null $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return string|null + */ + public function getIconCustomEmojiId() + { + return $this->iconCustomEmojiId; + } + + /** + * @param string|null $iconCustomEmojiId + * @return void + */ + public function setIconCustomEmojiId($iconCustomEmojiId) + { + $this->iconCustomEmojiId = $iconCustomEmojiId; + } +} diff --git a/src/Types/Game.php b/src/Types/Game.php new file mode 100644 index 00000000..ae5c417f --- /dev/null +++ b/src/Types/Game.php @@ -0,0 +1,174 @@ + true, + 'description' => true, + 'photo' => ArrayOfPhotoSize::class, + 'text' => true, + 'text_entities' => ArrayOfMessageEntity::class, + 'animation' => Animation::class + ]; + + /** + * Title of the game + * + * @var string + */ + protected $title; + + /** + * Description of the game + * + * @var string + */ + protected $description; + + /** + * Photo that will be displayed in the game message in chats + * + * @var PhotoSize[] + */ + protected $photo; + + /** + * Optional. Brief description of the game or high scores included in the game message + * + * @var string|null + */ + protected $text; + + /** + * Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. + * + * @var MessageEntity[]|null + */ + protected $textEntities; + + /** + * Optional. Animation that will be displayed in the game message in chats + * + * @var Animation|null + */ + protected $animation; + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * @return PhotoSize[] + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param PhotoSize[] $photo + */ + public function setPhoto(array $photo) + { + $this->photo = $photo; + } + + /** + * @return string|null + */ + public function getText() + { + return $this->text; + } + + /** + * @param string|null $text + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return MessageEntity[]|null + */ + public function getTextEntities() + { + return $this->textEntities; + } + + /** + * @param MessageEntity[]|null $textEntities + */ + public function setTextEntities($textEntities) + { + $this->textEntities = $textEntities; + } + + /** + * @return Animation|null + */ + public function getAnimation() + { + return $this->animation; + } + + /** + * @param Animation|null $animation + */ + public function setAnimation($animation) + { + $this->animation = $animation; + } +} diff --git a/src/Types/GeneralForumTopicHidden.php b/src/Types/GeneralForumTopicHidden.php new file mode 100644 index 00000000..3bbd25c2 --- /dev/null +++ b/src/Types/GeneralForumTopicHidden.php @@ -0,0 +1,10 @@ + ArrayOfChat::class, + 'winners_selection_date' => true, + 'winner_count' => true, + 'only_new_members' => true, + 'has_public_winners' => true, + 'prize_description' => true, + 'country_codes' => true, + 'premium_subscription_month_count' => true, + ]; + + /** + * The list of chats which the user must join to participate in the giveaway + * + * @var array + */ + protected $chats; + + /** + * Point in time (Unix timestamp) when winners of the giveaway will be selected + * + * @var int + */ + protected $winnersSelectionDate; + + /** + * The number of users which are supposed to be selected as winners of the giveaway + * + * @var int + */ + protected $winnerCount; + + /** + * Optional. True, if only users who join the chats after the giveaway started should be eligible to win + * + * @var bool|null + */ + protected $onlyNewMembers; + + /** + * Optional. True, if the list of giveaway winners will be visible to everyone + * + * @var bool|null + */ + protected $hasPublicWinners; + + /** + * Optional. Description of additional giveaway prize + * + * @var string|null + */ + protected $prizeDescription; + + /** + * Optional. A list of two-letter ISO 3166-1 alpha-2 country codes indicating the countries from which eligible users for the giveaway must come. If empty, then all users can participate in the giveaway. Users with a phone number that was bought on Fragment can always participate in giveaways. + * + * @var array|null + */ + protected $countryCodes; + + /** + * Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for + * + * @var int|null + */ + protected $premiumSubscriptionMonthCount; + + /** + * @return array + */ + public function getChats() + { + return $this->chats; + } + + /** + * @param array $chats + * @return void + */ + public function setChats($chats) + { + $this->chats = $chats; + } + + /** + * @return int + */ + public function getWinnersSelectionDate() + { + return $this->winnersSelectionDate; + } + + /** + * @param int $winnersSelectionDate + * @return void + */ + public function setWinnersSelectionDate($winnersSelectionDate) + { + $this->winnersSelectionDate = $winnersSelectionDate; + } + + /** + * @return int + */ + public function getWinnerCount() + { + return $this->winnerCount; + } + + /** + * @param int $winnerCount + * @return void + */ + public function setWinnerCount($winnerCount) + { + $this->winnerCount = $winnerCount; + } + + /** + * @return bool|null + */ + public function getOnlyNewMembers() + { + return $this->onlyNewMembers; + } + + /** + * @param bool|null $onlyNewMembers + * @return void + */ + public function setOnlyNewMembers($onlyNewMembers) + { + $this->onlyNewMembers = $onlyNewMembers; + } + + /** + * @return bool|null + */ + public function getHasPublicWinners() + { + return $this->hasPublicWinners; + } + + /** + * @param bool|null $hasPublicWinners + * @return void + */ + public function setHasPublicWinners($hasPublicWinners) + { + $this->hasPublicWinners = $hasPublicWinners; + } + + /** + * @return string|null + */ + public function getPrizeDescription() + { + return $this->prizeDescription; + } + + /** + * @param string|null $prizeDescription + * @return void + */ + public function setPrizeDescription($prizeDescription) + { + $this->prizeDescription = $prizeDescription; + } + + /** + * @return array|null + */ + public function getCountryCodes() + { + return $this->countryCodes; + } + + /** + * @param array|null $countryCodes + * @return void + */ + public function setCountryCodes($countryCodes) + { + $this->countryCodes = $countryCodes; + } + + /** + * @return int|null + */ + public function getPremiumSubscriptionMonthCount() + { + return $this->premiumSubscriptionMonthCount; + } + + /** + * @param int|null $premiumSubscriptionMonthCount + * @return void + */ + public function setPremiumSubscriptionMonthCount($premiumSubscriptionMonthCount) + { + $this->premiumSubscriptionMonthCount = $premiumSubscriptionMonthCount; + } +} diff --git a/src/Types/GiveawayCompleted.php b/src/Types/GiveawayCompleted.php new file mode 100644 index 00000000..28ac6b92 --- /dev/null +++ b/src/Types/GiveawayCompleted.php @@ -0,0 +1,105 @@ + true, + 'unclaimed_prize_count' => true, + 'giveaway_message' => MaybeInaccessibleMessage::class, + ]; + + /** + * Number of winners in the giveaway + * + * @var int + */ + protected $winnerCount; + + /** + * Optional. Number of undistributed prizes + * + * @var int|null + */ + protected $unclaimedPrizeCount; + + /** + * Optional. Message with the giveaway that was completed, if it wasn't deleted + * + * @var MaybeInaccessibleMessage|null + */ + protected $giveawayMessage; + + /** + * @return int + */ + public function getWinnerCount() + { + return $this->winnerCount; + } + + /** + * @param int $winnerCount + * @return void + */ + public function setWinnerCount($winnerCount) + { + $this->winnerCount = $winnerCount; + } + + /** + * @return int|null + */ + public function getUnclaimedPrizeCount() + { + return $this->unclaimedPrizeCount; + } + + /** + * @param int|null $unclaimedPrizeCount + * @return void + */ + public function setUnclaimedPrizeCount($unclaimedPrizeCount) + { + $this->unclaimedPrizeCount = $unclaimedPrizeCount; + } + + /** + * @return MaybeInaccessibleMessage|null + */ + public function getGiveawayMessage() + { + return $this->giveawayMessage; + } + + /** + * @param MaybeInaccessibleMessage|null $giveawayMessage + * @return void + */ + public function setGiveawayMessage($giveawayMessage) + { + $this->giveawayMessage = $giveawayMessage; + } +} diff --git a/src/Types/GiveawayCreated.php b/src/Types/GiveawayCreated.php new file mode 100644 index 00000000..61bb8cf8 --- /dev/null +++ b/src/Types/GiveawayCreated.php @@ -0,0 +1,10 @@ + Chat::class, + 'giveaway_message_id' => true, + 'winners_selection_date' => true, + 'winner_count' => true, + 'winners' => ArrayOfUser::class, + 'additional_chat_count' => true, + 'premium_subscription_month_count' => true, + 'unclaimed_prize_count' => true, + 'only_new_members' => true, + 'was_refunded' => true, + 'prize_description' => true, + ]; + + /** + * The chat that created the giveaway + * + * @var Chat + */ + protected $chat; + + /** + * Identifier of the message with the giveaway in the chat + * + * @var int + */ + protected $giveawayMessageId; + + /** + * Point in time (Unix timestamp) when winners of the giveaway were selected + * + * @var int + */ + protected $winnersSelectionDate; + + /** + * Total number of winners in the giveaway + * + * @var int + */ + protected $winnerCount; + + /** + * List of up to 100 winners of the giveaway + * + * @var array + */ + protected $winners; + + /** + * Optional. The number of other chats the user had to join in order to be eligible for the giveaway + * + * @var int|null + */ + protected $additionalChatCount; + + /** + * Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for + * + * @var int|null + */ + protected $premiumSubscriptionMonthCount; + + /** + * Optional. Number of undistributed prizes + * + * @var int|null + */ + protected $unclaimedPrizeCount; + + /** + * Optional. True, if only users who had joined the chats after the giveaway started were eligible to win + * + * @var bool|null + */ + protected $onlyNewMembers; + + /** + * Optional. True, if the giveaway was canceled because the payment for it was refunded + * + * @var bool|null + */ + protected $wasRefunded; + + /** + * Optional. Description of additional giveaway prize + * + * @var string|null + */ + protected $prizeDescription; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getGiveawayMessageId() + { + return $this->giveawayMessageId; + } + + /** + * @param int $giveawayMessageId + * @return void + */ + public function setGiveawayMessageId($giveawayMessageId) + { + $this->giveawayMessageId = $giveawayMessageId; + } + + /** + * @return int + */ + public function getWinnersSelectionDate() + { + return $this->winnersSelectionDate; + } + + /** + * @param int $winnersSelectionDate + * @return void + */ + public function setWinnersSelectionDate($winnersSelectionDate) + { + $this->winnersSelectionDate = $winnersSelectionDate; + } + + /** + * @return int + */ + public function getWinnerCount() + { + return $this->winnerCount; + } + + /** + * @param int $winnerCount + * @return void + */ + public function setWinnerCount($winnerCount) + { + $this->winnerCount = $winnerCount; + } + + /** + * @return array + */ + public function getWinners() + { + return $this->winners; + } + + /** + * @param array $winners + * @return void + */ + public function setWinners($winners) + { + $this->winners = $winners; + } + + /** + * @return int|null + */ + public function getAdditionalChatCount() + { + return $this->additionalChatCount; + } + + /** + * @param int|null $additionalChatCount + * @return void + */ + public function setAdditionalChatCount($additionalChatCount) + { + $this->additionalChatCount = $additionalChatCount; + } + + /** + * @return int|null + */ + public function getPremiumSubscriptionMonthCount() + { + return $this->premiumSubscriptionMonthCount; + } + + /** + * @param int|null $premiumSubscriptionMonthCount + * @return void + */ + public function setPremiumSubscriptionMonthCount($premiumSubscriptionMonthCount) + { + $this->premiumSubscriptionMonthCount = $premiumSubscriptionMonthCount; + } + + /** + * @return int|null + */ + public function getUnclaimedPrizeCount() + { + return $this->unclaimedPrizeCount; + } + + /** + * @param int|null $unclaimedPrizeCount + * @return void + */ + public function setUnclaimedPrizeCount($unclaimedPrizeCount) + { + $this->unclaimedPrizeCount = $unclaimedPrizeCount; + } + + /** + * @return bool|null + */ + public function getOnlyNewMembers() + { + return $this->onlyNewMembers; + } + + /** + * @param bool|null $onlyNewMembers + * @return void + */ + public function setOnlyNewMembers($onlyNewMembers) + { + $this->onlyNewMembers = $onlyNewMembers; + } + + /** + * @return bool|null + */ + public function getWasRefunded() + { + return $this->wasRefunded; + } + + /** + * @param bool|null $wasRefunded + * @return void + */ + public function setWasRefunded($wasRefunded) + { + $this->wasRefunded = $wasRefunded; + } + + /** + * @return string|null + */ + public function getPrizeDescription() + { + return $this->prizeDescription; + } + + /** + * @param string|null $prizeDescription + * @return void + */ + public function setPrizeDescription($prizeDescription) + { + $this->prizeDescription = $prizeDescription; + } +} diff --git a/src/Types/InaccessibleMessage.php b/src/Types/InaccessibleMessage.php new file mode 100644 index 00000000..1f41e04e --- /dev/null +++ b/src/Types/InaccessibleMessage.php @@ -0,0 +1,131 @@ + Chat::class, + 'message_id' => true, + 'date' => true, + ]; + + /** + * Chat the message belonged to + * + * @var Chat + */ + protected $chat; + + /** + * Unique message identifier inside the chat + * + * @var int + */ + protected $messageId; + + /** + * Always 0. The field can be used to differentiate regular and inaccessible messages. + * + * @var int + */ + protected $date; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat(Chat $chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + * @throws InvalidArgumentException + */ + public function setMessageId($messageId) + { + if (!is_int($messageId)) { + throw new InvalidArgumentException('MessageId must be an integer'); + } + $this->messageId = $messageId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + * @throws InvalidArgumentException + */ + public function setDate($date) + { + if (!is_int($date)) { + throw new InvalidArgumentException('Date must be an integer'); + } + $this->date = $date; + } +} diff --git a/src/Types/Inline/InlineKeyboardButton.php b/src/Types/Inline/InlineKeyboardButton.php new file mode 100644 index 00000000..afdf17ed --- /dev/null +++ b/src/Types/Inline/InlineKeyboardButton.php @@ -0,0 +1,283 @@ + true, + 'url' => true, + 'callback_data' => true, + 'web_app' => WebAppInfo::class, + 'login_url' => LoginUrl::class, + 'switch_inline_query' => true, + 'switch_inline_query_current_chat' => true, + 'switch_inline_query_chosen_chat' => SwitchInlineQueryChosenChat::class, + 'callback_game' => CallbackGame::class, + 'pay' => true, + ]; + + /** + * Label text on the button + * + * @var string + */ + protected $text; + + /** + * Optional. HTTP or tg:// URL to be opened when the button is pressed + * + * @var string|null + */ + protected $url; + + /** + * Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes + * + * @var string|null + */ + protected $callbackData; + + /** + * Optional. Description of the Web App that will be launched when the user presses the button + * + * @var WebAppInfo|null + */ + protected $webApp; + + /** + * Optional. An HTTPS URL used to automatically authorize the user + * + * @var LoginUrl|null + */ + protected $loginUrl; + + /** + * Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field + * + * @var string|null + */ + protected $switchInlineQuery; + + /** + * Optional. If set, pressing the button will insert the bot's username and the specified inline query in the current chat's input field + * + * @var string|null + */ + protected $switchInlineQueryCurrentChat; + + /** + * Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field + * + * @var SwitchInlineQueryChosenChat|null + */ + protected $switchInlineQueryChosenChat; + + /** + * Optional. Description of the game that will be launched when the user presses the button + * + * @var CallbackGame|null + */ + protected $callbackGame; + + /** + * Optional. Specify True to send a Pay button + * + * @var bool|null + */ + protected $pay; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return string|null + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string|null $url + * @return void + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * @return string|null + */ + public function getCallbackData() + { + return $this->callbackData; + } + + /** + * @param string|null $callbackData + * @return void + */ + public function setCallbackData($callbackData) + { + $this->callbackData = $callbackData; + } + + /** + * @return WebAppInfo|null + */ + public function getWebApp() + { + return $this->webApp; + } + + /** + * @param WebAppInfo|null $webApp + * @return void + */ + public function setWebApp($webApp) + { + $this->webApp = $webApp; + } + + /** + * @return LoginUrl|null + */ + public function getLoginUrl() + { + return $this->loginUrl; + } + + /** + * @param LoginUrl|null $loginUrl + * @return void + */ + public function setLoginUrl($loginUrl) + { + $this->loginUrl = $loginUrl; + } + + /** + * @return string|null + */ + public function getSwitchInlineQuery() + { + return $this->switchInlineQuery; + } + + /** + * @param string|null $switchInlineQuery + * @return void + */ + public function setSwitchInlineQuery($switchInlineQuery) + { + $this->switchInlineQuery = $switchInlineQuery; + } + + /** + * @return string|null + */ + public function getSwitchInlineQueryCurrentChat() + { + return $this->switchInlineQueryCurrentChat; + } + + /** + * @param string|null $switchInlineQueryCurrentChat + * @return void + */ + public function setSwitchInlineQueryCurrentChat($switchInlineQueryCurrentChat) + { + $this->switchInlineQueryCurrentChat = $switchInlineQueryCurrentChat; + } + + /** + * @return SwitchInlineQueryChosenChat|null + */ + public function getSwitchInlineQueryChosenChat() + { + return $this->switchInlineQueryChosenChat; + } + + /** + * @param SwitchInlineQueryChosenChat|null $switchInlineQueryChosenChat + * @return void + */ + public function setSwitchInlineQueryChosenChat($switchInlineQueryChosenChat) + { + $this->switchInlineQueryChosenChat = $switchInlineQueryChosenChat; + } + + /** + * @return CallbackGame|null + */ + public function getCallbackGame() + { + return $this->callbackGame; + } + + /** + * @param CallbackGame|null $callbackGame + * @return void + */ + public function setCallbackGame($callbackGame) + { + $this->callbackGame = $callbackGame; + } + + /** + * @return bool|null + */ + public function isPay() + { + return $this->pay; + } + + /** + * @param bool|null $pay + * @return void + */ + public function setPay($pay) + { + $this->pay = $pay; + } +} diff --git a/src/Types/Inline/InlineKeyboardMarkup.php b/src/Types/Inline/InlineKeyboardMarkup.php index 08e1f647..5868e725 100644 --- a/src/Types/Inline/InlineKeyboardMarkup.php +++ b/src/Types/Inline/InlineKeyboardMarkup.php @@ -1,10 +1,4 @@ true, + 'allow_user_chats' => true, + 'allow_bot_chats' => true, + 'allow_group_chats' => true, + 'allow_channel_chats' => true + ]; + + /** + * Optional. The default inline query to be inserted in the input field. If left empty, only the bot's username will be inserted. + * + * @var string|null + */ + protected $query; + + /** + * Optional. True, if private chats with users can be chosen. + * + * @var bool|null + */ + protected $allowUserChats; + + /** + * Optional. True, if private chats with bots can be chosen. + * + * @var bool|null + */ + protected $allowBotChats; + + /** + * Optional. True, if group and supergroup chats can be chosen. + * + * @var bool|null + */ + protected $allowGroupChats; + + /** + * Optional. True, if channel chats can be chosen. + * + * @var bool|null + */ + protected $allowChannelChats; + + /** + * @return string|null + */ + public function getQuery() + { + return $this->query; + } + + /** + * @param string|null $query + * @return void + */ + public function setQuery($query) + { + $this->query = $query; + } + + /** + * @return bool|null + */ + public function getAllowUserChats() + { + return $this->allowUserChats; + } + + /** + * @param bool|null $allowUserChats + * @return void + */ + public function setAllowUserChats($allowUserChats) + { + $this->allowUserChats = $allowUserChats; + } + + /** + * @return bool|null + */ + public function getAllowBotChats() + { + return $this->allowBotChats; + } + + /** + * @param bool|null $allowBotChats + * @return void + */ + public function setAllowBotChats($allowBotChats) + { + $this->allowBotChats = $allowBotChats; + } + + /** + * @return bool|null + */ + public function getAllowGroupChats() + { + return $this->allowGroupChats; + } + + /** + * @param bool|null $allowGroupChats + * @return void + */ + public function setAllowGroupChats($allowGroupChats) + { + $this->allowGroupChats = $allowGroupChats; + } + + /** + * @return bool|null + */ + public function getAllowChannelChats() + { + return $this->allowChannelChats; + } + + /** + * @param bool|null $allowChannelChats + * @return void + */ + public function setAllowChannelChats($allowChannelChats) + { + $this->allowChannelChats = $allowChannelChats; + } +} diff --git a/src/Types/InputMedia/InputMedia.php b/src/Types/InputMedia/InputMedia.php index 97b520ae..e3f5bb75 100644 --- a/src/Types/InputMedia/InputMedia.php +++ b/src/Types/InputMedia/InputMedia.php @@ -4,134 +4,43 @@ use TelegramBot\Api\BaseType; use TelegramBot\Api\Collection\CollectionItemInterface; +use TelegramBot\Api\TypeInterface; +use TelegramBot\Api\InvalidArgumentException; /** * Class InputMedia * This object represents the content of a media message to be sent. + * It should be one of InputMediaAnimation, InputMediaDocument, InputMediaAudio, InputMediaPhoto, InputMediaVideo. * - * @package TelegramBot\Api + * @package TelegramBot\Api\Types */ -class InputMedia extends BaseType implements CollectionItemInterface +class InputMedia extends BaseType implements TypeInterface, CollectionItemInterface { /** - * {@inheritdoc} - * - * @var array - */ - protected static $requiredParams = ['type', 'media']; - - /** - * {@inheritdoc} - * - * @var array - */ - protected static $map = [ - 'type' => true, - 'media' => true, - 'caption' => true, - 'parse_mode' => true, - ]; - - /** - * Type of the result. - * - * @var string - */ - protected $type; - - /** - * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), - * pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" - * to upload a new one using multipart/form-data under name. - * - * @var string - */ - protected $media; - - /** - * Optional. Caption of the photo to be sent, 0-200 characters. - * - * @var string|null - */ - protected $caption; - - /** - * Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, - * fixed-width text or inline URLs in the media caption. - * - * @var string|null - */ - protected $parseMode; - - /** - * @return string - */ - public function getType() - { - return $this->type; - } - - /** - * @param string $type - * - * @return void - */ - public function setType($type) - { - $this->type = $type; - } - - /** - * @return string - */ - public function getMedia() - { - return $this->media; - } - - /** - * @param string $media - * - * @return void - */ - public function setMedia($media) - { - $this->media = $media; - } - - /** - * @return string|null - */ - public function getCaption() - { - return $this->caption; - } - - /** - * @param string|null $caption - * - * @return void - */ - public function setCaption($caption) - { - $this->caption = $caption; - } - - /** - * @return string|null - */ - public function getParseMode() - { - return $this->parseMode; - } - - /** - * @param string|null $parseMode - * - * @return void - */ - public function setParseMode($parseMode) - { - $this->parseMode = $parseMode; + * Factory method to create an instance of the appropriate InputMedia subclass based on the type. + * + * @param array $data + * @return InputMediaAnimation|InputMediaDocument|InputMediaAudio|InputMediaPhoto|InputMediaVideo + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + $type = $data['type']; + + switch ($type) { + case 'animation': + return InputMediaAnimation::fromResponse($data); + case 'document': + return InputMediaDocument::fromResponse($data); + case 'audio': + return InputMediaAudio::fromResponse($data); + case 'photo': + return InputMediaPhoto::fromResponse($data); + case 'video': + return InputMediaVideo::fromResponse($data); + default: + throw new InvalidArgumentException('Unknown media type: ' . $data['type']); + } } } diff --git a/src/Types/InputMedia/InputMediaAnimation.php b/src/Types/InputMedia/InputMediaAnimation.php new file mode 100644 index 00000000..94a6bd78 --- /dev/null +++ b/src/Types/InputMedia/InputMediaAnimation.php @@ -0,0 +1,308 @@ + true, + 'media' => true, + 'thumbnail' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'show_caption_above_media' => true, + 'width' => true, + 'height' => true, + 'duration' => true, + 'has_spoiler' => true + ]; + + /** + * Type of the result, must be animation + * + * @var string + */ + protected $type = 'animation'; + + /** + * File to send + * + * @var string + */ + protected $media; + + /** + * Optional. Thumbnail of the file sent + * + * @var string|null + */ + protected $thumbnail; + + /** + * Optional. Caption of the animation to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the animation caption + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Pass True, if the caption must be shown above the message media + * + * @var bool|null + */ + protected $showCaptionAboveMedia; + + /** + * Optional. Animation width + * + * @var int|null + */ + protected $width; + + /** + * Optional. Animation height + * + * @var int|null + */ + protected $height; + + /** + * Optional. Animation duration in seconds + * + * @var int|null + */ + protected $duration; + + /** + * Optional. Pass True if the animation needs to be covered with a spoiler animation + * + * @var bool|null + */ + protected $hasSpoiler; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia(string $media): void + { + $this->media = $media; + } + + /** + * @return string|null + */ + public function getThumbnail(): ?string + { + return $this->thumbnail; + } + + /** + * @param string|null $thumbnail + */ + public function setThumbnail(?string $thumbnail): void + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption(?string $caption): void + { + $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode(?string $parseMode): void + { + $this->parseMode = $parseMode; + } + + /** + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities(?array $captionEntities): void + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getShowCaptionAboveMedia(): ?bool + { + return $this->showCaptionAboveMedia; + } + + /** + * @param bool|null $showCaptionAboveMedia + */ + public function setShowCaptionAboveMedia(?bool $showCaptionAboveMedia): void + { + $this->showCaptionAboveMedia = $showCaptionAboveMedia; + } + + /** + * @return int|null + */ + public function getWidth(): ?int + { + return $this->width; + } + + /** + * @param int|null $width + */ + public function setWidth(?int $width): void + { + $this->width = $width; + } + + /** + * @return int|null + */ + public function getHeight(): ?int + { + return $this->height; + } + + /** + * @param int|null $height + */ + public function setHeight(?int $height): void + { + $this->height = $height; + } + + /** + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * @param int|null $duration + */ + public function setDuration(?int $duration): void + { + $this->duration = $duration; + } + + /** + * @return bool|null + */ + public function getHasSpoiler(): ?bool + { + return $this->hasSpoiler; + } + + /** + * @param bool|null $hasSpoiler + */ + public function setHasSpoiler(?bool $hasSpoiler): void + { + $this->hasSpoiler = $hasSpoiler; + } +} diff --git a/src/Types/InputMedia/InputMediaAudio.php b/src/Types/InputMedia/InputMediaAudio.php new file mode 100644 index 00000000..8bd555d3 --- /dev/null +++ b/src/Types/InputMedia/InputMediaAudio.php @@ -0,0 +1,260 @@ + true, + 'media' => true, + 'thumbnail' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'duration' => true, + 'performer' => true, + 'title' => true + ]; + + /** + * Type of the result, must be audio + * + * @var string + */ + protected $type = 'audio'; + + /** + * File to send + * + * @var string + */ + protected $media; + + /** + * Optional. Thumbnail of the file sent + * + * @var string|null + */ + protected $thumbnail; + + /** + * Optional. Caption of the audio to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the audio caption + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Duration of the audio in seconds + * + * @var int|null + */ + protected $duration; + + /** + * Optional. Performer of the audio + * + * @var string|null + */ + protected $performer; + + /** + * Optional. Title of the audio + * + * @var string|null + */ + protected $title; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia(string $media): void + { + $this->media = $media; + } + + /** + * @return string|null + */ + public function getThumbnail(): ?string + { + return $this->thumbnail; + } + + /** + * @param string|null $thumbnail + */ + public function setThumbnail(?string $thumbnail): void + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption(?string $caption): void + { + $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode(?string $parseMode): void + { + $this->parseMode = $parseMode; + } + + /** + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities(?array $captionEntities): void + { + $this->captionEntities = $captionEntities; + } + + /** + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * @param int|null $duration + */ + public function setDuration(?int $duration): void + { + $this->duration = $duration; + } + + /** + * @return string|null + */ + public function getPerformer(): ?string + { + return $this->performer; + } + + /** + * @param string|null $performer + */ + public function setPerformer(?string $performer): void + { + $this->performer = $performer; + } + + /** + * @return string|null + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param string|null $title + */ + public function setTitle(?string $title): void + { + $this->title = $title; + } +} diff --git a/src/Types/InputMedia/InputMediaDocument.php b/src/Types/InputMedia/InputMediaDocument.php new file mode 100644 index 00000000..3012e232 --- /dev/null +++ b/src/Types/InputMedia/InputMediaDocument.php @@ -0,0 +1,212 @@ + true, + 'media' => true, + 'thumbnail' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'disable_content_type_detection' => true + ]; + + /** + * Type of the result, must be document + * + * @var string + */ + protected $type = 'document'; + + /** + * File to send + * + * @var string + */ + protected $media; + + /** + * Optional. Thumbnail of the file sent + * + * @var string|null + */ + protected $thumbnail; + + /** + * Optional. Caption of the document to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the document caption + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data. Always True, if the document is sent as part of an album. + * + * @var bool|null + */ + protected $disableContentTypeDetection; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia(string $media): void + { + $this->media = $media; + } + + /** + * @return string|null + */ + public function getThumbnail(): ?string + { + return $this->thumbnail; + } + + /** + * @param string|null $thumbnail + */ + public function setThumbnail(?string $thumbnail): void + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption(?string $caption): void + { + $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode(?string $parseMode): void + { + $this->parseMode = $parseMode; + } + + /** + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities(?array $captionEntities): void + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getDisableContentTypeDetection(): ?bool + { + return $this->disableContentTypeDetection; + } + + /** + * @param bool|null $disableContentTypeDetection + */ + public function setDisableContentTypeDetection(?bool $disableContentTypeDetection): void + { + $this->disableContentTypeDetection = $disableContentTypeDetection; + } +} diff --git a/src/Types/InputMedia/InputMediaPhoto.php b/src/Types/InputMedia/InputMediaPhoto.php index 1bf0b2b2..891e2327 100644 --- a/src/Types/InputMedia/InputMediaPhoto.php +++ b/src/Types/InputMedia/InputMediaPhoto.php @@ -2,26 +2,211 @@ namespace TelegramBot\Api\Types\InputMedia; +use TelegramBot\Api\InvalidArgumentException; + /** * Class InputMediaPhoto * Represents a photo to be sent. * - * @package TelegramBot\Api + * @package TelegramBot\Api\Types */ class InputMediaPhoto extends InputMedia { /** - * InputMediaPhoto constructor. + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['type', 'media']; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'type' => true, + 'media' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'show_caption_above_media' => true, + 'has_spoiler' => true + ]; + + /** + * Type of the result, must be photo + * + * @var string + */ + protected $type; + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. + * + * @var string + */ + protected $media; + + /** + * Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the photo caption. See formatting options for more details. + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Pass True, if the caption must be shown above the message media * + * @var bool|null + */ + protected $showCaptionAboveMedia; + + /** + * Optional. Pass True if the photo needs to be covered with a spoiler animation + * + * @var bool|null + */ + protected $hasSpoiler; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia() + { + return $this->media; + } + + /** * @param string $media - * @param string|null $caption - * @param string|null $parseMode */ - public function __construct($media, $caption = null, $parseMode = null) + public function setMedia($media) { - $this->type = 'photo'; $this->media = $media; + } + + /** + * @return string|null + */ + public function getCaption() + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption($caption) + { $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode() + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode($parseMode) + { $this->parseMode = $parseMode; } + + /** + * @return array|null + */ + public function getCaptionEntities() + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities($captionEntities) + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getShowCaptionAboveMedia() + { + return $this->showCaptionAboveMedia; + } + + /** + * @param bool|null $showCaptionAboveMedia + */ + public function setShowCaptionAboveMedia($showCaptionAboveMedia) + { + $this->showCaptionAboveMedia = $showCaptionAboveMedia; + } + + /** + * @return bool|null + */ + public function getHasSpoiler() + { + return $this->hasSpoiler; + } + + /** + * @param bool|null $hasSpoiler + */ + public function setHasSpoiler($hasSpoiler) + { + $this->hasSpoiler = $hasSpoiler; + } } diff --git a/src/Types/InputMedia/InputMediaVideo.php b/src/Types/InputMedia/InputMediaVideo.php index f6836a44..b51b32bb 100644 --- a/src/Types/InputMedia/InputMediaVideo.php +++ b/src/Types/InputMedia/InputMediaVideo.php @@ -2,14 +2,23 @@ namespace TelegramBot\Api\Types\InputMedia; +use TelegramBot\Api\InvalidArgumentException; + /** * Class InputMediaVideo * Represents a video to be sent. * - * @package TelegramBot\Api + * @package TelegramBot\Api\Types */ class InputMediaVideo extends InputMedia { + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['type', 'media']; + /** * {@inheritdoc} * @@ -18,86 +27,241 @@ class InputMediaVideo extends InputMedia protected static $map = [ 'type' => true, 'media' => true, + 'thumbnail' => true, 'caption' => true, 'parse_mode' => true, + 'caption_entities' => true, + 'show_caption_above_media' => true, 'width' => true, 'height' => true, 'duration' => true, - 'supports_streaming' => true + 'supports_streaming' => true, + 'has_spoiler' => true ]; /** - * Optional. Video width. + * Type of the result, must be video + * + * @var string + */ + protected $type = 'video'; + + /** + * File to send + * + * @var string + */ + protected $media; + + /** + * Optional. Thumbnail of the file sent + * + * @var string|null + */ + protected $thumbnail; + + /** + * Optional. Caption of the video to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the video caption + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Pass True, if the caption must be shown above the message media + * + * @var bool|null + */ + protected $showCaptionAboveMedia; + + /** + * Optional. Video width * * @var int|null */ protected $width; /** - * Optional. Video height. + * Optional. Video height * * @var int|null */ protected $height; /** - * Optional. Video duration. + * Optional. Video duration in seconds * * @var int|null */ protected $duration; /** - * Optional. Pass True, if the uploaded video is suitable for streaming. + * Optional. Pass True if the uploaded video is suitable for streaming * * @var bool|null */ protected $supportsStreaming; /** - * InputMediaVideo constructor. + * Optional. Pass True if the video needs to be covered with a spoiler animation * + * @var bool|null + */ + protected $hasSpoiler; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** * @param string $media - * @param string|null $caption - * @param string|null $parseMode - * @param int|null $width - * @param int|null $height - * @param int|null $duration - * @param bool $supportsStreaming - */ - public function __construct( - $media, - $caption = null, - $parseMode = null, - $width = null, - $height = null, - $duration = null, - $supportsStreaming = false - ) { - $this->type = 'video'; + */ + public function setMedia(string $media): void + { $this->media = $media; + } + + /** + * @return string|null + */ + public function getThumbnail(): ?string + { + return $this->thumbnail; + } + + /** + * @param string|null $thumbnail + */ + public function setThumbnail(?string $thumbnail): void + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption(?string $caption): void + { $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode(?string $parseMode): void + { $this->parseMode = $parseMode; - $this->width = $width; - $this->height = $height; - $this->duration = $duration; - $this->supportsStreaming = $supportsStreaming; + } + + /** + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities(?array $captionEntities): void + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getShowCaptionAboveMedia(): ?bool + { + return $this->showCaptionAboveMedia; + } + + /** + * @param bool|null $showCaptionAboveMedia + */ + public function setShowCaptionAboveMedia(?bool $showCaptionAboveMedia): void + { + $this->showCaptionAboveMedia = $showCaptionAboveMedia; } /** * @return int|null */ - public function getWidth() + public function getWidth(): ?int { return $this->width; } /** * @param int|null $width - * - * @return void */ - public function setWidth($width) + public function setWidth(?int $width): void { $this->width = $width; } @@ -105,17 +269,15 @@ public function setWidth($width) /** * @return int|null */ - public function getHeight() + public function getHeight(): ?int { return $this->height; } /** * @param int|null $height - * - * @return void */ - public function setHeight($height) + public function setHeight(?int $height): void { $this->height = $height; } @@ -123,17 +285,15 @@ public function setHeight($height) /** * @return int|null */ - public function getDuration() + public function getDuration(): ?int { return $this->duration; } /** * @param int|null $duration - * - * @return void */ - public function setDuration($duration) + public function setDuration(?int $duration): void { $this->duration = $duration; } @@ -141,18 +301,33 @@ public function setDuration($duration) /** * @return bool|null */ - public function getSupportsStreaming() + public function getSupportsStreaming(): ?bool { return $this->supportsStreaming; } /** * @param bool|null $supportsStreaming - * - * @return void */ - public function setSupportsStreaming($supportsStreaming) + public function setSupportsStreaming(?bool $supportsStreaming): void { $this->supportsStreaming = $supportsStreaming; } + + /** + * @return bool|null + */ + public function getHasSpoiler(): ?bool + { + return $this->hasSpoiler; + } + + /** + * @param bool|null $hasSpoiler + */ + public function setHasSpoiler(?bool $hasSpoiler): void + { + $this->hasSpoiler = $hasSpoiler; + } + } diff --git a/src/Types/InputPollOption.php b/src/Types/InputPollOption.php new file mode 100644 index 00000000..f6791a23 --- /dev/null +++ b/src/Types/InputPollOption.php @@ -0,0 +1,105 @@ + true, + 'text_parse_mode' => true, + 'text_entities' => ArrayOfMessageEntity::class + ]; + + /** + * Option text, 1-100 characters + * + * @var string + */ + protected $text; + + /** + * Optional. Mode for parsing entities in the text. Currently, only custom emoji entities are allowed + * + * @var string|null + */ + protected $textParseMode; + + /** + * Optional. A JSON-serialized list of special entities that appear in the poll option text + * + * @var array|null + */ + protected $textEntities; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return string|null + */ + public function getTextParseMode() + { + return $this->textParseMode; + } + + /** + * @param string|null $textParseMode + * @return void + */ + public function setTextParseMode($textParseMode) + { + $this->textParseMode = $textParseMode; + } + + /** + * @return array|null + */ + public function getTextEntities() + { + return $this->textEntities; + } + + /** + * @param array|null $textEntities + * @return void + */ + public function setTextEntities($textEntities) + { + $this->textEntities = $textEntities; + } +} diff --git a/src/Types/KeyboardButton.php b/src/Types/KeyboardButton.php new file mode 100644 index 00000000..9db786a9 --- /dev/null +++ b/src/Types/KeyboardButton.php @@ -0,0 +1,213 @@ + true, + 'request_users' => KeyboardButtonRequestUsers::class, + 'request_chat' => KeyboardButtonRequestChat::class, + 'request_contact' => true, + 'request_location' => true, + 'request_poll' => KeyboardButtonPollType::class, + 'web_app' => WebAppInfo::class, + ]; + + /** + * Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed + * + * @var string + */ + protected $text; + + /** + * Optional. If specified, pressing the button will open a list of suitable users. + * Identifiers of selected users will be sent to the bot in a “users_shared” service message. + * Available in private chats only. + * + * @var KeyboardButtonRequestUsers|null + */ + protected $requestUsers; + + /** + * Optional. If specified, pressing the button will open a list of suitable chats. + * Tapping on a chat will send its identifier to the bot in a “chat_shared” service message. + * Available in private chats only. + * + * @var KeyboardButtonRequestChat|null + */ + protected $requestChat; + + /** + * Optional. If True, the user's phone number will be sent as a contact when the button is pressed. + * Available in private chats only. + * + * @var bool|null + */ + protected $requestContact; + + /** + * Optional. If True, the user's current location will be sent when the button is pressed. + * Available in private chats only. + * + * @var bool|null + */ + protected $requestLocation; + + /** + * Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. + * Available in private chats only. + * + * @var KeyboardButtonPollType|null + */ + protected $requestPoll; + + /** + * Optional. If specified, the described Web App will be launched when the button is pressed. + * The Web App will be able to send a “web_app_data” service message. Available in private chats only. + * + * @var WebAppInfo|null + */ + protected $webApp; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return KeyboardButtonRequestUsers|null + */ + public function getRequestUsers() + { + return $this->requestUsers; + } + + /** + * @param KeyboardButtonRequestUsers|null $requestUsers + * @return void + */ + public function setRequestUsers($requestUsers) + { + $this->requestUsers = $requestUsers; + } + + /** + * @return KeyboardButtonRequestChat|null + */ + public function getRequestChat() + { + return $this->requestChat; + } + + /** + * @param KeyboardButtonRequestChat|null $requestChat + * @return void + */ + public function setRequestChat($requestChat) + { + $this->requestChat = $requestChat; + } + + /** + * @return bool|null + */ + public function getRequestContact() + { + return $this->requestContact; + } + + /** + * @param bool|null $requestContact + * @return void + */ + public function setRequestContact($requestContact) + { + $this->requestContact = $requestContact; + } + + /** + * @return bool|null + */ + public function getRequestLocation() + { + return $this->requestLocation; + } + + /** + * @param bool|null $requestLocation + * @return void + */ + public function setRequestLocation($requestLocation) + { + $this->requestLocation = $requestLocation; + } + + /** + * @return KeyboardButtonPollType|null + */ + public function getRequestPoll() + { + return $this->requestPoll; + } + + /** + * @param KeyboardButtonPollType|null $requestPoll + * @return void + */ + public function setRequestPoll($requestPoll) + { + $this->requestPoll = $requestPoll; + } + + /** + * @return WebAppInfo|null + */ + public function getWebApp() + { + return $this->webApp; + } + + /** + * @param WebAppInfo|null $webApp + * @return void + */ + public function setWebApp($webApp) + { + $this->webApp = $webApp; + } +} diff --git a/src/Types/KeyboardButtonPollType.php b/src/Types/KeyboardButtonPollType.php new file mode 100644 index 00000000..2fa8c507 --- /dev/null +++ b/src/Types/KeyboardButtonPollType.php @@ -0,0 +1,50 @@ + true, + ]; + + /** + * Optional. If quiz is passed, the user will be allowed to create only polls in the quiz mode. + * If regular is passed, only regular polls will be allowed. + * Otherwise, the user will be allowed to create a poll of any type. + * + * @var string|null + */ + protected $type; + + /** + * @return string|null + */ + public function getType() + { + return $this->type; + } + + /** + * @param string|null $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } +} diff --git a/src/Types/KeyboardButtonRequestChat.php b/src/Types/KeyboardButtonRequestChat.php new file mode 100644 index 00000000..6e77522f --- /dev/null +++ b/src/Types/KeyboardButtonRequestChat.php @@ -0,0 +1,307 @@ + true, + 'chat_is_channel' => true, + 'chat_is_forum' => true, + 'chat_has_username' => true, + 'chat_is_created' => true, + 'user_administrator_rights' => ChatAdministratorRights::class, + 'bot_administrator_rights' => ChatAdministratorRights::class, + 'bot_is_member' => true, + 'request_title' => true, + 'request_username' => true, + 'request_photo' => true, + ]; + + /** + * Signed 32-bit identifier of the request, which will be received back in the ChatShared object. Must be unique within the message + * + * @var int + */ + protected $requestId; + + /** + * Pass True to request a channel chat, pass False to request a group or a supergroup chat. + * + * @var bool + */ + protected $chatIsChannel; + + /** + * Optional. Pass True to request a forum supergroup, pass False to request a non-forum chat. If not specified, no additional restrictions are applied. + * + * @var bool|null + */ + protected $chatIsForum; + + /** + * Optional. Pass True to request a supergroup or a channel with a username, pass False to request a chat without a username. If not specified, no additional restrictions are applied. + * + * @var bool|null + */ + protected $chatHasUsername; + + /** + * Optional. Pass True to request a chat owned by the user. Otherwise, no additional restrictions are applied. + * + * @var bool|null + */ + protected $chatIsCreated; + + /** + * Optional. A JSON-serialized object listing the required administrator rights of the user in the chat. The rights must be a superset of bot_administrator_rights. If not specified, no additional restrictions are applied. + * + * @var ChatAdministratorRights|null + */ + protected $userAdministratorRights; + + /** + * Optional. A JSON-serialized object listing the required administrator rights of the bot in the chat. The rights must be a subset of user_administrator_rights. If not specified, no additional restrictions are applied. + * + * @var ChatAdministratorRights|null + */ + protected $botAdministratorRights; + + /** + * Optional. Pass True to request a chat with the bot as a member. Otherwise, no additional restrictions are applied. + * + * @var bool|null + */ + protected $botIsMember; + + /** + * Optional. Pass True to request the chat's title. + * + * @var bool|null + */ + protected $requestTitle; + + /** + * Optional. Pass True to request the chat's username. + * + * @var bool|null + */ + protected $requestUsername; + + /** + * Optional. Pass True to request the chat's photo. + * + * @var bool|null + */ + protected $requestPhoto; + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @param int $requestId + * @return void + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + } + + /** + * @return bool + */ + public function getChatIsChannel() + { + return $this->chatIsChannel; + } + + /** + * @param bool $chatIsChannel + * @return void + */ + public function setChatIsChannel($chatIsChannel) + { + $this->chatIsChannel = $chatIsChannel; + } + + /** + * @return bool|null + */ + public function getChatIsForum() + { + return $this->chatIsForum; + } + + /** + * @param bool|null $chatIsForum + * @return void + */ + public function setChatIsForum($chatIsForum) + { + $this->chatIsForum = $chatIsForum; + } + + /** + * @return bool|null + */ + public function getChatHasUsername() + { + return $this->chatHasUsername; + } + + /** + * @param bool|null $chatHasUsername + * @return void + */ + public function setChatHasUsername($chatHasUsername) + { + $this->chatHasUsername = $chatHasUsername; + } + + /** + * @return bool|null + */ + public function getChatIsCreated() + { + return $this->chatIsCreated; + } + + /** + * @param bool|null $chatIsCreated + * @return void + */ + public function setChatIsCreated($chatIsCreated) + { + $this->chatIsCreated = $chatIsCreated; + } + + /** + * @return ChatAdministratorRights|null + */ + public function getUserAdministratorRights() + { + return $this->userAdministratorRights; + } + + /** + * @param ChatAdministratorRights|null $userAdministratorRights + * @return void + */ + public function setUserAdministratorRights($userAdministratorRights) + { + $this->userAdministratorRights = $userAdministratorRights; + } + + /** + * @return ChatAdministratorRights|null + */ + public function getBotAdministratorRights() + { + return $this->botAdministratorRights; + } + + /** + * @param ChatAdministratorRights|null $botAdministratorRights + * @return void + */ + public function setBotAdministratorRights($botAdministratorRights) + { + $this->botAdministratorRights = $botAdministratorRights; + } + + /** + * @return bool|null + */ + public function getBotIsMember() + { + return $this->botIsMember; + } + + /** + * @param bool|null $botIsMember + * @return void + */ + public function setBotIsMember($botIsMember) + { + $this->botIsMember = $botIsMember; + } + + /** + * @return bool|null + */ + public function getRequestTitle() + { + return $this->requestTitle; + } + + /** + * @param bool|null $requestTitle + * @return void + */ + public function setRequestTitle($requestTitle) + { + $this->requestTitle = $requestTitle; + } + + /** + * @return bool|null + */ + public function getRequestUsername() + { + return $this->requestUsername; + } + + /** + * @param bool|null $requestUsername + * @return void + */ + public function setRequestUsername($requestUsername) + { + $this->requestUsername = $requestUsername; + } + + /** + * @return bool|null + */ + public function getRequestPhoto() + { + return $this->requestPhoto; + } + + /** + * @param bool|null $requestPhoto + * @return void + */ + public function setRequestPhoto($requestPhoto) + { + $this->requestPhoto = $requestPhoto; + } +} diff --git a/src/Types/KeyboardButtonRequestUsers.php b/src/Types/KeyboardButtonRequestUsers.php new file mode 100644 index 00000000..4cf02c76 --- /dev/null +++ b/src/Types/KeyboardButtonRequestUsers.php @@ -0,0 +1,206 @@ + true, + 'user_is_bot' => true, + 'user_is_premium' => true, + 'max_quantity' => true, + 'request_name' => true, + 'request_username' => true, + 'request_photo' => true, + ]; + + /** + * Signed 32-bit identifier of the request that will be received back in the UsersShared object. Must be unique within the message + * + * @var int + */ + protected $requestId; + + /** + * Optional. Pass True to request bots, pass False to request regular users. If not specified, no additional restrictions are applied. + * + * @var bool|null + */ + protected $userIsBot; + + /** + * Optional. Pass True to request premium users, pass False to request non-premium users. If not specified, no additional restrictions are applied. + * + * @var bool|null + */ + protected $userIsPremium; + + /** + * Optional. The maximum number of users to be selected; 1-10. Defaults to 1. + * + * @var int|null + */ + protected $maxQuantity; + + /** + * Optional. Pass True to request the users' first and last names. + * + * @var bool|null + */ + protected $requestName; + + /** + * Optional. Pass True to request the users' usernames. + * + * @var bool|null + */ + protected $requestUsername; + + /** + * Optional. Pass True to request the users' photos. + * + * @var bool|null + */ + protected $requestPhoto; + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @param int $requestId + * @return void + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + } + + /** + * @return bool|null + */ + public function getUserIsBot() + { + return $this->userIsBot; + } + + /** + * @param bool|null $userIsBot + * @return void + */ + public function setUserIsBot($userIsBot) + { + $this->userIsBot = $userIsBot; + } + + /** + * @return bool|null + */ + public function getUserIsPremium() + { + return $this->userIsPremium; + } + + /** + * @param bool|null $userIsPremium + * @return void + */ + public function setUserIsPremium($userIsPremium) + { + $this->userIsPremium = $userIsPremium; + } + + /** + * @return int|null + */ + public function getMaxQuantity() + { + return $this->maxQuantity; + } + + /** + * @param int|null $maxQuantity + * @return void + */ + public function setMaxQuantity($maxQuantity) + { + $this->maxQuantity = $maxQuantity; + } + + /** + * @return bool|null + */ + public function getRequestName() + { + return $this->requestName; + } + + /** + * @param bool|null $requestName + * @return void + */ + public function setRequestName($requestName) + { + $this->requestName = $requestName; + } + + /** + * @return bool|null + */ + public function getRequestUsername() + { + return $this->requestUsername; + } + + /** + * @param bool|null $requestUsername + * @return void + */ + public function setRequestUsername($requestUsername) + { + $this->requestUsername = $requestUsername; + } + + /** + * @return bool|null + */ + public function getRequestPhoto() + { + return $this->requestPhoto; + } + + /** + * @param bool|null $requestPhoto + * @return void + */ + public function setRequestPhoto($requestPhoto) + { + $this->requestPhoto = $requestPhoto; + } +} diff --git a/src/Types/LinkPreviewOptions.php b/src/Types/LinkPreviewOptions.php new file mode 100644 index 00000000..e12175c6 --- /dev/null +++ b/src/Types/LinkPreviewOptions.php @@ -0,0 +1,148 @@ + true, + 'url' => true, + 'prefer_small_media' => true, + 'prefer_large_media' => true, + 'show_above_text' => true, + ]; + + /** + * Optional. True, if the link preview is disabled + * + * @var bool|null + */ + protected $isDisabled; + + /** + * Optional. URL to use for the link preview. If empty, then the first URL found in the message text will be used + * + * @var string|null + */ + protected $url; + + /** + * Optional. True, if the media in the link preview is supposed to be shrunk; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview + * + * @var bool|null + */ + protected $preferSmallMedia; + + /** + * Optional. True, if the media in the link preview is supposed to be enlarged; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview + * + * @var bool|null + */ + protected $preferLargeMedia; + + /** + * Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text + * + * @var bool|null + */ + protected $showAboveText; + + /** + * @return bool|null + */ + public function getIsDisabled() + { + return $this->isDisabled; + } + + /** + * @param bool|null $isDisabled + * @return void + */ + public function setIsDisabled($isDisabled) + { + $this->isDisabled = $isDisabled; + } + + /** + * @return string|null + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string|null $url + * @return void + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * @return bool|null + */ + public function getPreferSmallMedia() + { + return $this->preferSmallMedia; + } + + /** + * @param bool|null $preferSmallMedia + * @return void + */ + public function setPreferSmallMedia($preferSmallMedia) + { + $this->preferSmallMedia = $preferSmallMedia; + } + + /** + * @return bool|null + */ + public function getPreferLargeMedia() + { + return $this->preferLargeMedia; + } + + /** + * @param bool|null $preferLargeMedia + * @return void + */ + public function setPreferLargeMedia($preferLargeMedia) + { + $this->preferLargeMedia = $preferLargeMedia; + } + + /** + * @return bool|null + */ + public function getShowAboveText() + { + return $this->showAboveText; + } + + /** + * @param bool|null $showAboveText + * @return void + */ + public function setShowAboveText($showAboveText) + { + $this->showAboveText = $showAboveText; + } +} diff --git a/src/Types/Location.php b/src/Types/Location.php index 19a17f8f..9237858a 100644 --- a/src/Types/Location.php +++ b/src/Types/Location.php @@ -57,8 +57,7 @@ class Location extends BaseType implements TypeInterface protected $horizontalAccuracy; /** - * Optional. Time relative to the message sending date, during which the location can be updated, in seconds. For - * active live locations only. + * Optional. Time relative to the message sending date, during which the location can be updated, in seconds. For active live locations only. * * @var int|null */ @@ -72,8 +71,7 @@ class Location extends BaseType implements TypeInterface protected $heading; /** - * Optional. Maximum distance for proximity alerts about approaching another chat member, in meters. For sent live - * locations only. + * Optional. Maximum distance for proximity alerts about approaching another chat member, in meters. For sent live locations only. * * @var int|null */ @@ -88,7 +86,7 @@ public function getLatitude() } /** - * @param mixed $latitude + * @param float $latitude * @return void * @throws InvalidArgumentException */ @@ -110,7 +108,7 @@ public function getLongitude() } /** - * @param mixed $longitude + * @param float $longitude * @return void * @throws InvalidArgumentException */ @@ -132,7 +130,7 @@ public function getHorizontalAccuracy() } /** - * @param mixed $horizontalAccuracy + * @param float|null $horizontalAccuracy * @return void * @throws InvalidArgumentException */ @@ -154,7 +152,7 @@ public function getLivePeriod() } /** - * @param int $livePeriod + * @param int|null $livePeriod * @return void */ public function setLivePeriod($livePeriod) @@ -171,7 +169,7 @@ public function getHeading() } /** - * @param int $heading + * @param int|null $heading * @return void */ public function setHeading($heading) @@ -188,7 +186,7 @@ public function getProximityAlertRadius() } /** - * @param int $proximityAlertRadius + * @param int|null $proximityAlertRadius * @return void */ public function setProximityAlertRadius($proximityAlertRadius) diff --git a/src/Types/MaybeInaccessibleMessage.php b/src/Types/MaybeInaccessibleMessage.php new file mode 100644 index 00000000..505b07d7 --- /dev/null +++ b/src/Types/MaybeInaccessibleMessage.php @@ -0,0 +1,26 @@ + true, + 'message_thread_id' => true, 'from' => User::class, + 'sender_chat' => Chat::class, + 'sender_boost_count' => true, + 'sender_business_bot' => User::class, 'date' => true, + 'business_connection_id' => true, 'chat' => Chat::class, - 'forward_from' => User::class, - 'forward_from_chat' => Chat::class, - 'forward_from_message_id' => true, - 'forward_date' => true, - 'forward_signature' => true, - 'forward_sender_name' => true, - 'reply_to_message' => Message::class, + 'forward_origin' => MessageOrigin::class, + 'is_topic_message' => true, + 'is_automatic_forward' => true, + 'reply_to_message' => self::class, + 'external_reply' => ExternalReplyInfo::class, + 'quote' => TextQuote::class, + 'reply_to_story' => Story::class, 'via_bot' => User::class, 'edit_date' => true, + 'has_protected_content' => true, + 'is_from_offline' => true, 'media_group_id' => true, 'author_signature' => true, 'text' => true, 'entities' => ArrayOfMessageEntity::class, - 'caption_entities' => ArrayOfMessageEntity::class, + 'link_preview_options' => LinkPreviewOptions::class, + 'effect_id' => true, + 'animation' => Animation::class, 'audio' => Audio::class, 'document' => Document::class, - 'animation' => Animation::class, 'photo' => ArrayOfPhotoSize::class, 'sticker' => Sticker::class, + 'story' => Story::class, 'video' => Video::class, 'video_note' => VideoNote::class, 'voice' => Voice::class, 'caption' => true, + 'caption_entities' => ArrayOfMessageEntity::class, + 'show_caption_above_media' => true, + 'has_media_spoiler' => true, 'contact' => Contact::class, - 'location' => Location::class, - 'venue' => Venue::class, - 'poll' => Poll::class, 'dice' => Dice::class, + 'game' => Game::class, + 'poll' => Poll::class, + 'venue' => Venue::class, + 'location' => Location::class, 'new_chat_members' => ArrayOfUser::class, 'left_chat_member' => User::class, 'new_chat_title' => true, @@ -64,104 +83,159 @@ class Message extends BaseType implements TypeInterface 'group_chat_created' => true, 'supergroup_chat_created' => true, 'channel_chat_created' => true, + 'message_auto_delete_timer_changed' => MessageAutoDeleteTimerChanged::class, 'migrate_to_chat_id' => true, 'migrate_from_chat_id' => true, - 'pinned_message' => Message::class, + 'pinned_message' => MaybeInaccessibleMessage::class, 'invoice' => Invoice::class, 'successful_payment' => SuccessfulPayment::class, + 'users_shared' => UsersShared::class, + 'chat_shared' => ChatShared::class, 'connected_website' => true, + 'write_access_allowed' => WriteAccessAllowed::class, + // 'passport_data' => PassportData::class, + 'proximity_alert_triggered' => ProximityAlertTriggered::class, + 'boost_added' => ChatBoostAdded::class, + 'chat_background_set' => ChatBackground::class, 'forum_topic_created' => ForumTopicCreated::class, + 'forum_topic_edited' => ForumTopicEdited::class, 'forum_topic_closed' => ForumTopicClosed::class, 'forum_topic_reopened' => ForumTopicReopened::class, - 'is_topic_message' => true, - 'message_thread_id' => true, + 'general_forum_topic_hidden' => GeneralForumTopicHidden::class, + 'general_forum_topic_unhidden' => GeneralForumTopicUnhidden::class, + 'giveaway_created' => GiveawayCreated::class, + 'giveaway' => Giveaway::class, + 'giveaway_winners' => GiveawayWinners::class, + 'giveaway_completed' => GiveawayCompleted::class, + 'video_chat_scheduled' => VideoChatScheduled::class, + 'video_chat_started' => VideoChatStarted::class, + 'video_chat_ended' => VideoChatEnded::class, + 'video_chat_participants_invited' => VideoChatParticipantsInvited::class, 'web_app_data' => WebAppData::class, 'reply_markup' => InlineKeyboardMarkup::class, ]; /** - * Unique message identifier + * Unique message identifier inside this chat * - * @var int|float + * @var int */ protected $messageId; /** - * Optional. Sender name. Can be empty for messages sent to channels + * Optional. Unique identifier of a message thread to which the message belongs; for supergroups only + * + * @var int|null + */ + protected $messageThreadId; + + /** + * Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, + * the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. * * @var \TelegramBot\Api\Types\User|null */ protected $from; /** - * Date the message was sent in Unix time + * Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts, + * the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. + * For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. + * + * @var \TelegramBot\Api\Types\Chat|null + */ + protected $senderChat; + + /** + * Optional. If the sender of the message boosted the chat, the number of boosts added by the user + * + * @var int|null + */ + protected $senderBoostCount; + + /** + * Optional. The bot that actually sent the message on behalf of the business account. + * Available only for outgoing messages sent on behalf of the connected business account. + * + * @var \TelegramBot\Api\Types\User|null + */ + protected $senderBusinessBot; + + /** + * Date the message was sent in Unix time. It is always a positive number, representing a valid date. * * @var int */ protected $date; /** - * Conversation the message belongs to — user in case of a private message, GroupChat in case of a group + * Optional. Unique identifier of the business connection from which the message was received. + * If non-empty, the message belongs to a chat of the corresponding business account that is independent + * from any potential bot chat which might share the same identifier. + * + * @var string|null + */ + protected $businessConnectionId; + + /** + * Chat the message belongs to * * @var \TelegramBot\Api\Types\Chat */ protected $chat; /** - * Optional. For forwarded messages, sender of the original message + * Optional. Information about the original message for forwarded messages * - * @var \TelegramBot\Api\Types\User|null + * @var \TelegramBot\Api\Types\MessageOrigin|null */ - protected $forwardFrom; + protected $forwardOrigin; /** - * Optional. For messages forwarded from channels, information about - * the original channel + * Optional. True, if the message is sent to a forum topic * - * @var \TelegramBot\Api\Types\Chat|null + * @var bool|null */ - protected $forwardFromChat; + protected $isTopicMessage; /** - * Optional. For messages forwarded from channels, identifier of - * the original message in the channel + * Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group * - * @var int|null + * @var bool|null */ - protected $forwardFromMessageId; + protected $isAutomaticForward; /** - * Optional. For messages forwarded from channels, signature of the post author if present + * Optional. For replies in the same chat and message thread, the original message. + * Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. * - * @var string|null + * @var \TelegramBot\Api\Types\Message|null */ - protected $forwardSignature; + protected $replyToMessage; /** - * Optional. Sender's name for messages forwarded from users who disallow adding a link to their account - * in forwarded messages + * Optional. Information about the message that is being replied to, which may come from another chat or forum topic * - * @var string|null + * @var \TelegramBot\Api\Types\ExternalReplyInfo|null */ - protected $forwardSenderName; + protected $externalReply; /** - * Optional. For forwarded messages, date the original message was sent in Unix time + * Optional. For replies that quote part of the original message, the quoted part of the message * - * @var int|null + * @var \TelegramBot\Api\Types\TextQuote|null */ - protected $forwardDate; + protected $quote; /** - * Optional. For replies, the original message. Note that the Message object in this field will not contain further - * reply_to_message fields even if it itself is a reply. + * Optional. For replies to a story, the original story * - * @var \TelegramBot\Api\Types\Message|null + * @var \TelegramBot\Api\Types\Story|null */ - protected $replyToMessage; + protected $replyToStory; /** - * Optional. Bot through which the message was sent. + * Optional. Bot through which the message was sent * * @var \TelegramBot\Api\Types\User|null */ @@ -175,15 +249,29 @@ class Message extends BaseType implements TypeInterface protected $editDate; /** - * Optional. The unique identifier of a media message group - * this message belongs to + * Optional. True, if the message can't be forwarded * - * @var int|null + * @var bool|null + */ + protected $hasProtectedContent; + + /** + * Optional. True, if the message was sent by an implicit action, for example, as an away or a greeting business message, + * or as a scheduled message + * + * @var bool|null + */ + protected $isFromOffline; + + /** + * Optional. The unique identifier of a media message group this message belongs to + * + * @var string|null */ protected $mediaGroupId; /** - * Optional. Signature of the post author for messages in channels + * Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator * * @var string|null */ @@ -197,20 +285,33 @@ class Message extends BaseType implements TypeInterface protected $text; /** - * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. - * array of \TelegramBot\Api\Types\MessageEntity + * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text * - * @var array|null + * @var \TelegramBot\Api\Types\ArrayOfMessageEntity|null */ protected $entities; /** - * Optional. For messages with a caption, special entities like usernames, - * URLs, bot commands, etc. that appear in the caption + * Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed * - * @var ArrayOfMessageEntity|null + * @var \TelegramBot\Api\Types\LinkPreviewOptions|null */ - protected $captionEntities; + protected $linkPreviewOptions; + + /** + * Optional. Unique identifier of the message effect added to the message + * + * @var string|null + */ + protected $effectId; + + /** + * Optional. Message is an animation, information about the animation. + * For backward compatibility, when this field is set, the document field will also be set + * + * @var \TelegramBot\Api\Types\Animation|null + */ + protected $animation; /** * Optional. Message is an audio file, information about the file @@ -226,18 +327,10 @@ class Message extends BaseType implements TypeInterface */ protected $document; - /** - * Optional. Message is a animation, information about the animation - * - * @var \TelegramBot\Api\Types\Animation|null - */ - protected $animation; - /** * Optional. Message is a photo, available sizes of the photo - * array of \TelegramBot\Api\Types\Photo * - * @var array|null + * @var \TelegramBot\Api\Types\ArrayOfPhotoSize|null */ protected $photo; @@ -248,6 +341,13 @@ class Message extends BaseType implements TypeInterface */ protected $sticker; + /** + * Optional. Message is a forwarded story + * + * @var \TelegramBot\Api\Types\Story|null + */ + protected $story; + /** * Optional. Message is a video, information about the video * @@ -270,12 +370,33 @@ class Message extends BaseType implements TypeInterface protected $voice; /** - * Optional. Text description of the video (usually empty) + * Optional. Caption for the animation, audio, document, photo, video or voice * * @var string|null */ protected $caption; + /** + * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption + * + * @var \TelegramBot\Api\Types\ArrayOfMessageEntity|null + */ + protected $captionEntities; + + /** + * Optional. True, if the caption must be shown above the message media + * + * @var bool|null + */ + protected $showCaptionAboveMedia; + + /** + * Optional. True, if the message media is covered by a spoiler animation + * + * @var bool|null + */ + protected $hasMediaSpoiler; + /** * Optional. Message is a shared contact, information about the contact * @@ -284,18 +405,18 @@ class Message extends BaseType implements TypeInterface protected $contact; /** - * Optional. Message is a shared location, information about the location + * Optional. Message is a dice with random value * - * @var \TelegramBot\Api\Types\Location|null + * @var \TelegramBot\Api\Types\Dice|null */ - protected $location; + protected $dice; /** - * Optional. Message is a venue, information about the venue + * Optional. Message is a game, information about the game * - * @var \TelegramBot\Api\Types\Venue|null + * @var \TelegramBot\Api\Types\Game|null */ - protected $venue; + protected $game; /** * Optional. Message is a native poll, information about the poll @@ -305,166 +426,300 @@ class Message extends BaseType implements TypeInterface protected $poll; /** - * Optional. Message is a dice with random value from 1 to 6 + * Optional. Message is a venue, information about the venue. + * For backward compatibility, when this field is set, the location field will also be set * - * @var \TelegramBot\Api\Types\Dice|null + * @var \TelegramBot\Api\Types\Venue|null */ - protected $dice; + protected $venue; + + /** + * Optional. Message is a shared location, information about the location + * + * @var \TelegramBot\Api\Types\Location|null + */ + protected $location; /** * Optional. New members that were added to the group or supergroup and information about them * (the bot itself may be one of these members) - * array of \TelegramBot\Api\Types\User * - * @var \TelegramBot\Api\Types\User[]|null + * @var \TelegramBot\Api\Types\ArrayOfUser|null */ protected $newChatMembers; /** - * Optional. A member was removed from the group, information about them (this member may be bot itself) + * Optional. A member was removed from the group, information about them (this member may be the bot itself) * * @var \TelegramBot\Api\Types\User|null */ protected $leftChatMember; /** - * Optional. A group title was changed to this value + * Optional. A chat title was changed to this value * * @var string|null */ protected $newChatTitle; /** - * Optional. A group photo was change to this value + * Optional. A chat photo was change to this value * - * @var PhotoSize[]|null + * @var \TelegramBot\Api\Types\ArrayOfPhotoSize|null */ protected $newChatPhoto; /** - * Optional. Informs that the group photo was deleted + * Optional. Service message: the chat photo was deleted * * @var bool|null */ protected $deleteChatPhoto; /** - * Optional. Informs that the group has been created + * Optional. Service message: the group has been created * * @var bool|null */ protected $groupChatCreated; /** - * Optional. Service message: the supergroup has been created + * Optional. Service message: the supergroup has been created. + * This field can't be received in a message coming through updates, + * because bot can't be a member of a supergroup when it is created. + * It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup. * * @var bool|null */ protected $supergroupChatCreated; /** - * Optional. Service message: the channel has been created + * Optional. Service message: the channel has been created. + * This field can't be received in a message coming through updates, + * because bot can't be a member of a channel when it is created. + * It can only be found in reply_to_message if someone replies to a very first message in a channel. * * @var bool|null */ protected $channelChatCreated; /** - * Optional. The group has been migrated to a supergroup with the specified identifier, - * not exceeding 1e13 by absolute value + * Optional. Service message: auto-delete timer settings changed in the chat + * + * @var \TelegramBot\Api\Types\MessageAutoDeleteTimerChanged|null + */ + protected $messageAutoDeleteTimerChanged; + + /** + * Optional. The group has been migrated to a supergroup with the specified identifier. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. * * @var int|null */ protected $migrateToChatId; /** - * Optional. The supergroup has been migrated from a group with the specified identifier, - * not exceeding 1e13 by absolute value + * Optional. The supergroup has been migrated from a group with the specified identifier. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. * * @var int|null */ protected $migrateFromChatId; /** - * Optional. Specified message was pinned.Note that the Message object in this field - * will not contain further reply_to_message fields even if it is itself a reply. + * Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. * - * @var Message|null + * @var \TelegramBot\Api\Types\MaybeInaccessibleMessage|null */ protected $pinnedMessage; /** - * Optional. Message is an invoice for a payment, information about the invoice. + * Optional. Message is an invoice for a payment, information about the invoice * - * @var Invoice|null + * @var Invoice */ protected $invoice; /** - * Optional. Message is a service message about a successful payment, information about the payment. + * Optional. Message is a service message about a successful payment, information about the payment * - * @var SuccessfulPayment|null + * @var SuccessfulPayment */ protected $successfulPayment; /** - * Optional. The domain name of the website on which the user has logged in. + * Optional. Service message: users were shared with the bot + * + * @var \TelegramBot\Api\Types\UsersShared|null + */ + protected $usersShared; + + /** + * Optional. Service message: a chat was shared with the bot + * + * @var \TelegramBot\Api\Types\ChatShared|null + */ + protected $chatShared; + + /** + * Optional. The domain name of the website on which the user has logged in * * @var string|null */ protected $connectedWebsite; /** - * Optional. Service message: data sent by a Web App + * Optional. Service message: the user allowed the bot to write messages after adding it to the attachment or side menu, + * launching a Web App from a link, or accepting an explicit request from a Web App sent by the method requestWriteAccess * - * @var WebAppData|null + * @var \TelegramBot\Api\Types\WriteAccessAllowed|null */ - protected $webAppData; + protected $writeAccessAllowed; /** - * Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. + * Optional. Telegram Passport data * - * @var InlineKeyboardMarkup|null + * @var \TelegramBot\Api\Types\PassportData|null */ - protected $replyMarkup; + protected $passportData; + + /** + * Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live Location + * + * @var \TelegramBot\Api\Types\ProximityAlertTriggered|null + */ + protected $proximityAlertTriggered; + + /** + * Optional. Service message: user boosted the chat + * + * @var \TelegramBot\Api\Types\ChatBoostAdded|null + */ + protected $boostAdded; + + /** + * Optional. Service message: chat background set + * + * @var \TelegramBot\Api\Types\ChatBackground|null + */ + protected $chatBackgroundSet; /** * Optional. Service message: forum topic created * - * @var ForumTopicCreated|null + * @var \TelegramBot\Api\Types\ForumTopicCreated|null */ protected $forumTopicCreated; + /** + * Optional. Service message: forum topic edited + * + * @var \TelegramBot\Api\Types\ForumTopicEdited|null + */ + protected $forumTopicEdited; + /** * Optional. Service message: forum topic closed * - * @var ForumTopicReopened|null + * @var \TelegramBot\Api\Types\ForumTopicClosed|null */ - protected $forumTopicReopened; + protected $forumTopicClosed; /** * Optional. Service message: forum topic reopened * - * @var ForumTopicClosed|null + * @var \TelegramBot\Api\Types\ForumTopicReopened|null */ - protected $forumTopicClosed; + protected $forumTopicReopened; /** - * Optional. True, if the message is sent to a forum topic + * Optional. Service message: the 'General' forum topic hidden * - * @var bool|null + * @var \TelegramBot\Api\Types\GeneralForumTopicHidden|null */ - protected $isTopicMessage; + protected $generalForumTopicHidden; /** - * Optional. Unique identifier of a message thread to which the message belongs; for supergroups only + * Optional. Service message: the 'General' forum topic unhidden * - * @var int|null + * @var \TelegramBot\Api\Types\GeneralForumTopicUnhidden|null */ - protected $messageThreadId; + protected $generalForumTopicUnhidden; + + /** + * Optional. Service message: a scheduled giveaway was created + * + * @var \TelegramBot\Api\Types\GiveawayCreated|null + */ + protected $giveawayCreated; + + /** + * Optional. The message is a scheduled giveaway message + * + * @var \TelegramBot\Api\Types\Giveaway|null + */ + protected $giveaway; + + /** + * Optional. A giveaway with public winners was completed + * + * @var \TelegramBot\Api\Types\GiveawayWinners|null + */ + protected $giveawayWinners; + + /** + * Optional. Service message: a giveaway without public winners was completed + * + * @var \TelegramBot\Api\Types\GiveawayCompleted|null + */ + protected $giveawayCompleted; + + /** + * Optional. Service message: video chat scheduled + * + * @var \TelegramBot\Api\Types\VideoChatScheduled|null + */ + protected $videoChatScheduled; + + /** + * Optional. Service message: video chat started + * + * @var \TelegramBot\Api\Types\VideoChatStarted|null + */ + protected $videoChatStarted; + + /** + * Optional. Service message: video chat ended + * + * @var \TelegramBot\Api\Types\VideoChatEnded|null + */ + protected $videoChatEnded; + + /** + * Optional. Service message: new participants invited to a video chat + * + * @var \TelegramBot\Api\Types\VideoChatParticipantsInvited|null + */ + protected $videoChatParticipantsInvited; + + /** + * Optional. Service message: data sent by a Web App + * + * @var \TelegramBot\Api\Types\WebAppData|null + */ + protected $webAppData; + + /** + * Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons + * + * @var \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup|null + */ + protected $replyMarkup; /** - * @return int|float + * @return int */ public function getMessageId() { @@ -485,6 +740,23 @@ public function setMessageId($messageId) } } + /** + * @return int|null + */ + public function getMessageThreadId() + { + return $this->messageThreadId; + } + + /** + * @param int|null $messageThreadId + * @return void + */ + public function setMessageThreadId($messageThreadId) + { + $this->messageThreadId = $messageThreadId; + } + /** * @return User|null */ @@ -503,20 +775,52 @@ public function setFrom(User $from) } /** - * @return Chat + * @return Chat|null */ - public function getChat() + public function getSenderChat() { - return $this->chat; + return $this->senderChat; } /** - * @param Chat $chat + * @param Chat $senderChat * @return void */ - public function setChat(Chat $chat) + public function setSenderChat(Chat $senderChat) { - $this->chat = $chat; + $this->senderChat = $senderChat; + } + + /** + * @return int|null + */ + public function getSenderBoostCount() + { + return $this->senderBoostCount; + } + + /** + * @param int|null $senderBoostCount + */ + public function setSenderBoostCount($senderBoostCount) + { + $this->senderBoostCount = $senderBoostCount; + } + + /** + * @return User|null + */ + public function getSenderBusinessBot() + { + return $this->senderBusinessBot; + } + + /** + * @param User|null $senderBusinessBot + */ + public function setSenderBusinessBot($senderBusinessBot) + { + $this->senderBusinessBot = $senderBusinessBot; } /** @@ -530,139 +834,160 @@ public function getDate() /** * @param mixed $date * @return void - * @throws InvalidArgumentException + * @throws InvalidArgumentException + */ + public function setDate($date) + { + if (is_int($date)) { + $this->date = $date; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return string|null + */ + public function getBusinessConnectionId() + { + return $this->businessConnectionId; + } + + /** + * @param string|null $businessConnectionId + */ + public function setBusinessConnectionId($businessConnectionId) + { + $this->businessConnectionId = $businessConnectionId; + } + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void */ - public function setDate($date) + public function setChat(Chat $chat) { - if (is_int($date)) { - $this->date = $date; - } else { - throw new InvalidArgumentException(); - } + $this->chat = $chat; } /** - * @return User|null + * @return MessageOrigin|null */ - public function getForwardFrom() + public function getForwardOrigin() { - return $this->forwardFrom; + return $this->forwardOrigin; } /** - * @param User $forwardFrom - * @return void + * @param MessageOrigin|null $forwardOrigin */ - public function setForwardFrom(User $forwardFrom) + public function setForwardOrigin($forwardOrigin) { - $this->forwardFrom = $forwardFrom; + $this->forwardOrigin = $forwardOrigin; } /** - * @return Chat|null + * @return bool|null */ - public function getForwardFromChat() + public function getIsTopicMessage() { - return $this->forwardFromChat; + return $this->isTopicMessage; } /** - * @param Chat $forwardFromChat - * @return void + * @param bool|null $isTopicMessage */ - public function setForwardFromChat(Chat $forwardFromChat) + public function setIsTopicMessage($isTopicMessage) { - $this->forwardFromChat = $forwardFromChat; + $this->isTopicMessage = $isTopicMessage; } /** - * @return int|null + * @return bool|null */ - public function getForwardFromMessageId() + public function getIsAutomaticForward() { - return $this->forwardFromMessageId; + return $this->isAutomaticForward; } /** - * @param int $forwardFromMessageId - * @return void + * @param bool|null $isAutomaticForward */ - public function setForwardFromMessageId($forwardFromMessageId) + public function setIsAutomaticForward($isAutomaticForward) { - $this->forwardFromMessageId = $forwardFromMessageId; + $this->isAutomaticForward = $isAutomaticForward; } /** - * @return null|string + * @return Message|null */ - public function getForwardSignature() + public function getReplyToMessage() { - return $this->forwardSignature; + return $this->replyToMessage; } /** - * @param string $forwardSignature - * @return void + * @param Message|null $replyToMessage */ - public function setForwardSignature($forwardSignature) + public function setReplyToMessage($replyToMessage) { - $this->forwardSignature = $forwardSignature; + $this->replyToMessage = $replyToMessage; } /** - * @return null|string + * @return ExternalReplyInfo|null */ - public function getForwardSenderName() + public function getExternalReply() { - return $this->forwardSenderName; + return $this->externalReply; } /** - * @param string $forwardSenderName - * @return void + * @param ExternalReplyInfo|null $externalReply */ - public function setForwardSenderName($forwardSenderName) + public function setExternalReply($externalReply) { - $this->forwardSenderName = $forwardSenderName; + $this->externalReply = $externalReply; } /** - * @return int|null + * @return TextQuote|null */ - public function getForwardDate() + public function getQuote() { - return $this->forwardDate; + return $this->quote; } /** - * @param mixed $forwardDate - * @return void - * @throws InvalidArgumentException + * @param TextQuote|null $quote */ - public function setForwardDate($forwardDate) + public function setQuote($quote) { - if (is_int($forwardDate)) { - $this->forwardDate = $forwardDate; - } else { - throw new InvalidArgumentException(); - } + $this->quote = $quote; } /** - * @return null|self + * @return Story|null */ - public function getReplyToMessage() + public function getReplyToStory() { - return $this->replyToMessage; + return $this->replyToStory; } /** - * @param Message $replyToMessage - * @return void + * @param Story|null $replyToStory */ - public function setReplyToMessage(Message $replyToMessage) + public function setReplyToStory($replyToStory) { - $this->replyToMessage = $replyToMessage; + $this->replyToStory = $replyToStory; } /** @@ -674,10 +999,9 @@ public function getViaBot() } /** - * @param User $viaBot - * @return void + * @param User|null $viaBot */ - public function setViaBot(User $viaBot) + public function setViaBot($viaBot) { $this->viaBot = $viaBot; } @@ -705,7 +1029,39 @@ public function setEditDate($editDate) } /** - * @return int|null + * @return bool|null + */ + public function getHasProtectedContent() + { + return $this->hasProtectedContent; + } + + /** + * @param bool|null $hasProtectedContent + */ + public function setHasProtectedContent($hasProtectedContent) + { + $this->hasProtectedContent = $hasProtectedContent; + } + + /** + * @return bool|null + */ + public function getIsFromOffline() + { + return $this->isFromOffline; + } + + /** + * @param bool|null $isFromOffline + */ + public function setIsFromOffline($isFromOffline) + { + $this->isFromOffline = $isFromOffline; + } + + /** + * @return string|null */ public function getMediaGroupId() { @@ -713,8 +1069,7 @@ public function getMediaGroupId() } /** - * @param int $mediaGroupId - * @return void + * @param string|null $mediaGroupId */ public function setMediaGroupId($mediaGroupId) { @@ -722,7 +1077,7 @@ public function setMediaGroupId($mediaGroupId) } /** - * @return null|string + * @return string|null */ public function getAuthorSignature() { @@ -730,8 +1085,7 @@ public function getAuthorSignature() } /** - * @param string $authorSignature - * @return void + * @param string|null $authorSignature */ public function setAuthorSignature($authorSignature) { @@ -739,7 +1093,7 @@ public function setAuthorSignature($authorSignature) } /** - * @return null|string + * @return string|null */ public function getText() { @@ -747,25 +1101,20 @@ public function getText() } /** - * @param string $text - * @return void + * @param string|null $text */ public function setText($text) { $this->text = $text; } - /** - * @return array|null - */ public function getEntities() { return $this->entities; } /** - * @param array $entities - * @return void + * @param array|null $entities */ public function setEntities($entities) { @@ -773,86 +1122,94 @@ public function setEntities($entities) } /** - * @return ArrayOfMessageEntity|null + * @return LinkPreviewOptions|null */ - public function getCaptionEntities() + public function getLinkPreviewOptions() { - return $this->captionEntities; + return $this->linkPreviewOptions; } /** - * @param ArrayOfMessageEntity $captionEntities - * @return void + * @param LinkPreviewOptions|null $linkPreviewOptions */ - public function setCaptionEntities($captionEntities) + public function setLinkPreviewOptions($linkPreviewOptions) { - $this->captionEntities = $captionEntities; + $this->linkPreviewOptions = $linkPreviewOptions; } /** - * @return Audio|null + * @return string|null */ - public function getAudio() + public function getEffectId() { - return $this->audio; + return $this->effectId; } /** - * @param Audio $audio - * @return void + * @param string|null $effectId */ - public function setAudio(Audio $audio) + public function setEffectId($effectId) { - $this->audio = $audio; + $this->effectId = $effectId; } /** - * @return Document|null + * @return Animation|null */ - public function getDocument() + public function getAnimation() { - return $this->document; + return $this->animation; } /** - * @param Document $document - * @return void + * @param Animation|null $animation */ - public function setDocument($document) + public function setAnimation($animation) { - $this->document = $document; + $this->animation = $animation; } /** - * @return Animation|null + * @return Audio|null */ - public function getAnimation() + public function getAudio() { - return $this->animation; + return $this->audio; } /** - * @param Animation $animation - * @return void + * @param Audio|null $audio */ - public function setAnimation(Animation $animation) + public function setAudio($audio) { - $this->animation = $animation; + $this->audio = $audio; + } + + /** + * @return Document|null + */ + public function getDocument() + { + return $this->document; } /** - * @return array|null + * @param Document|null $document */ + public function setDocument($document) + { + $this->document = $document; + } + public function getPhoto() { return $this->photo; } /** - * @param array $photo - * @return void + * @param array|null $photo */ - public function setPhoto(array $photo) + public function setPhoto($photo) { $this->photo = $photo; } @@ -866,14 +1223,29 @@ public function getSticker() } /** - * @param Sticker $sticker - * @return void + * @param Sticker|null $sticker */ - public function setSticker(Sticker $sticker) + public function setSticker($sticker) { $this->sticker = $sticker; } + /** + * @return Story|null + */ + public function getStory() + { + return $this->story; + } + + /** + * @param Story|null $story + */ + public function setStory($story) + { + $this->story = $story; + } + /** * @return Video|null */ @@ -882,6 +1254,14 @@ public function getVideo() return $this->video; } + /** + * @param Video|null $video + */ + public function setVideo($video) + { + $this->video = $video; + } + /** * @return VideoNote|null */ @@ -892,22 +1272,12 @@ public function getVideoNote() /** * @param VideoNote|null $videoNote - * @return void */ public function setVideoNote($videoNote) { $this->videoNote = $videoNote; } - /** - * @param Video $video - * @return void - */ - public function setVideo(Video $video) - { - $this->video = $video; - } - /** * @return Voice|null */ @@ -917,8 +1287,7 @@ public function getVoice() } /** - * @param Voice $voice - * @return void + * @param Voice|null $voice */ public function setVoice($voice) { @@ -934,14 +1303,61 @@ public function getCaption() } /** - * @param string $caption - * @return void + * @param string|null $caption */ public function setCaption($caption) { $this->caption = $caption; } + /** + * @return ArrayOfMessageEntity|null + */ + public function getCaptionEntities() + { + return $this->captionEntities; + } + + /** + * @param ArrayOfMessageEntity|null $captionEntities + */ + public function setCaptionEntities($captionEntities) + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getShowCaptionAboveMedia() + { + return $this->showCaptionAboveMedia; + } + + /** + * @param bool|null $showCaptionAboveMedia + */ + public function setShowCaptionAboveMedia($showCaptionAboveMedia) + { + $this->showCaptionAboveMedia = $showCaptionAboveMedia; + } + + /** + * @return bool|null + */ + public function getHasMediaSpoiler() + { + return $this->hasMediaSpoiler; + } + + /** + * @param bool|null $hasMediaSpoiler + */ + public function setHasMediaSpoiler($hasMediaSpoiler) + { + $this->hasMediaSpoiler = $hasMediaSpoiler; + } + /** * @return Contact|null */ @@ -951,46 +1367,43 @@ public function getContact() } /** - * @param Contact $contact - * @return void + * @param Contact|null $contact */ - public function setContact(Contact $contact) + public function setContact($contact) { $this->contact = $contact; } /** - * @return Location|null + * @return Dice|null */ - public function getLocation() + public function getDice() { - return $this->location; + return $this->dice; } /** - * @param Location $location - * @return void + * @param Dice|null $dice */ - public function setLocation(Location $location) + public function setDice($dice) { - $this->location = $location; + $this->dice = $dice; } /** - * @return Venue|null + * @return Game|null */ - public function getVenue() + public function getGame() { - return $this->venue; + return $this->game; } /** - * @param Venue $venue - * @return void + * @param Game|null $game */ - public function setVenue($venue) + public function setGame($game) { - $this->venue = $venue; + $this->game = $game; } /** @@ -1002,8 +1415,7 @@ public function getPoll() } /** - * @param Poll $poll - * @return void + * @param Poll|null $poll */ public function setPoll($poll) { @@ -1011,25 +1423,37 @@ public function setPoll($poll) } /** - * @return Dice|null + * @return Venue|null */ - public function getDice() + public function getVenue() { - return $this->dice; + return $this->venue; } /** - * @param Dice $dice - * @return void + * @param Venue|null $venue */ - public function setDice(Dice $dice) + public function setVenue($venue) { - $this->dice = $dice; + $this->venue = $venue; + } + + /** + * @return Location|null + */ + public function getLocation() + { + return $this->location; } /** - * @return \TelegramBot\Api\Types\User[]|null + * @param Location|null $location */ + public function setLocation($location) + { + $this->location = $location; + } + public function getNewChatMembers() { return $this->newChatMembers; @@ -1078,9 +1502,6 @@ public function setNewChatTitle($newChatTitle) $this->newChatTitle = $newChatTitle; } - /** - * @return PhotoSize[]|null - */ public function getNewChatPhoto() { return $this->newChatPhoto; @@ -1197,9 +1618,6 @@ public function setMigrateFromChatId($migrateFromChatId) $this->migrateFromChatId = $migrateFromChatId; } - /** - * @return null|self - */ public function getPinnedMessage() { return $this->pinnedMessage; @@ -1215,8 +1633,6 @@ public function setPinnedMessage($pinnedMessage) } /** - * @author MY - * * @return Invoice|null */ public function getInvoice() @@ -1225,7 +1641,6 @@ public function getInvoice() } /** - * @author MY * @param Invoice $invoice * @return void */ @@ -1235,8 +1650,6 @@ public function setInvoice($invoice) } /** - * @author MY - * * @return SuccessfulPayment|null */ public function getSuccessfulPayment() @@ -1245,7 +1658,6 @@ public function getSuccessfulPayment() } /** - * @author MY * @param SuccessfulPayment $successfulPayment * @return void */ @@ -1355,38 +1767,4 @@ public function setForumTopicReopened($forumTopicReopened) { $this->forumTopicReopened = $forumTopicReopened; } - - /** - * @return bool|null - */ - public function getIsTopicMessage() - { - return $this->isTopicMessage; - } - - /** - * @param bool $isTopicMessage - * @return void - */ - public function setIsTopicMessage($isTopicMessage) - { - $this->isTopicMessage = $isTopicMessage; - } - - /** - * @return int|null - */ - public function getMessageThreadId() - { - return $this->messageThreadId; - } - - /** - * @param int|null $messageThreadId - * @return void - */ - public function setMessageThreadId($messageThreadId) - { - $this->messageThreadId = $messageThreadId; - } } diff --git a/src/Types/MessageAutoDeleteTimerChanged.php b/src/Types/MessageAutoDeleteTimerChanged.php new file mode 100644 index 00000000..9e662d94 --- /dev/null +++ b/src/Types/MessageAutoDeleteTimerChanged.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * New auto-delete time for messages in the chat; in seconds + * + * @var int + */ + protected $messageAutoDeleteTime; + + /** + * @return int + */ + public function getMessageAutoDeleteTime() + { + return $this->messageAutoDeleteTime; + } + + /** + * @param int $messageAutoDeleteTime + * @return void + */ + public function setMessageAutoDeleteTime($messageAutoDeleteTime) + { + $this->messageAutoDeleteTime = $messageAutoDeleteTime; + } +} diff --git a/src/Types/MessageEntity.php b/src/Types/MessageEntity.php index 54eb90db..a1499da1 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -1,10 +1,4 @@ messageId = $messageId; } } diff --git a/src/Types/MessageOrigin.php b/src/Types/MessageOrigin.php new file mode 100644 index 00000000..394bfce3 --- /dev/null +++ b/src/Types/MessageOrigin.php @@ -0,0 +1,45 @@ + true, + 'date' => true, + ]; + + protected $type; + protected $date; + + public function getType() + { + return $this->type; + } + + public function setType($type) + { + $this->type = $type; + } + + public function getDate() + { + return $this->date; + } + + public function setDate($date) + { + $this->date = $date; + } +} diff --git a/src/Types/MessageOriginChannel.php b/src/Types/MessageOriginChannel.php new file mode 100644 index 00000000..2e78834f --- /dev/null +++ b/src/Types/MessageOriginChannel.php @@ -0,0 +1,56 @@ + true, + 'date' => true, + 'chat' => Chat::class, + 'message_id' => true, + 'author_signature' => true, + ]; + + protected $chat; + protected $messageId; + protected $authorSignature; + + public function getChat(): ?Chat + { + return $this->chat; + } + + public function setChat($chat): void + { + $this->chat = $chat; + } + + public function getMessageId(): ?int + { + return $this->messageId; + } + + public function setMessageId($messageId): void + { + $this->messageId = $messageId; + } + + public function getAuthorSignature(): ?string + { + return $this->authorSignature; + } + + public function setAuthorSignature($authorSignature): void + { + $this->authorSignature = $authorSignature; + } +} diff --git a/src/Types/MessageOriginChat.php b/src/Types/MessageOriginChat.php new file mode 100644 index 00000000..3027b6f6 --- /dev/null +++ b/src/Types/MessageOriginChat.php @@ -0,0 +1,44 @@ + true, + 'date' => true, + 'sender_chat' => Chat::class, + 'author_signature' => true, + ]; + + protected $senderChat; + protected $authorSignature; + + public function getSenderChat() + { + return $this->senderChat; + } + + public function setSenderChat(Chat $senderChat) + { + $this->senderChat = $senderChat; + } + + public function getAuthorSignature() + { + return $this->authorSignature; + } + + public function setAuthorSignature($authorSignature) + { + $this->authorSignature = $authorSignature; + } +} diff --git a/src/Types/MessageOriginHiddenUser.php b/src/Types/MessageOriginHiddenUser.php new file mode 100644 index 00000000..3e37b750 --- /dev/null +++ b/src/Types/MessageOriginHiddenUser.php @@ -0,0 +1,32 @@ + true, + 'date' => true, + 'sender_user_name' => true, + ]; + + protected $senderUserName; + + public function getSenderUserName() + { + return $this->senderUserName; + } + + public function setSenderUserName(User $senderUserName) + { + $this->senderUserName = $senderUserName; + } +} diff --git a/src/Types/MessageOriginUser.php b/src/Types/MessageOriginUser.php new file mode 100644 index 00000000..d68aaa7d --- /dev/null +++ b/src/Types/MessageOriginUser.php @@ -0,0 +1,32 @@ + true, + 'date' => true, + 'sender_user' => User::class, + ]; + + protected $senderUser; + + public function getSenderUser() + { + return $this->senderUser; + } + + public function setSenderUser(User $senderUser) + { + $this->senderUser = $senderUser; + } +} diff --git a/src/Types/MessageReactionCountUpdated.php b/src/Types/MessageReactionCountUpdated.php new file mode 100644 index 00000000..b768a919 --- /dev/null +++ b/src/Types/MessageReactionCountUpdated.php @@ -0,0 +1,124 @@ + Chat::class, + 'message_id' => true, + 'date' => true, + 'reactions' => ArrayOfReactionType::class, + ]; + + /** + * The chat containing the message + * + * @var Chat + */ + protected $chat; + + /** + * Unique message identifier inside the chat + * + * @var int + */ + protected $messageId; + + /** + * Date of the change in Unix time + * + * @var int + */ + protected $date; + + /** + * List of reactions that are present on the message + * + * @var array + */ + protected $reactions; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return array + */ + public function getReactions() + { + return $this->reactions; + } + + /** + * @param array $reactions + * @return void + */ + public function setReactions($reactions) + { + $this->reactions = $reactions; + } +} diff --git a/src/Types/MessageReactionUpdated.php b/src/Types/MessageReactionUpdated.php new file mode 100644 index 00000000..350ae560 --- /dev/null +++ b/src/Types/MessageReactionUpdated.php @@ -0,0 +1,199 @@ + Chat::class, + 'message_id' => true, + 'user' => User::class, + 'actor_chat' => Chat::class, + 'date' => true, + 'old_reaction' => ArrayOfReactionType::class, + 'new_reaction' => ArrayOfReactionType::class, + ]; + + /** + * The chat containing the message the user reacted to + * + * @var Chat + */ + protected $chat; + + /** + * Unique identifier of the message inside the chat + * + * @var int + */ + protected $messageId; + + /** + * Optional. The user that changed the reaction, if the user isn't anonymous + * + * @var User|null + */ + protected $user; + + /** + * Optional. The chat on behalf of which the reaction was changed, if the user is anonymous + * + * @var Chat|null + */ + protected $actorChat; + + /** + * Date of the change in Unix time + * + * @var int + */ + protected $date; + + /** + * Previous list of reaction types that were set by the user + * + * @var array + */ + protected $oldReaction; + + /** + * New list of reaction types that have been set by the user + * + * @var array + */ + protected $newReaction; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } + + /** + * @return User|null + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User|null $user + * @return void + */ + public function setUser($user) + { + $this->user = $user; + } + + /** + * @return Chat|null + */ + public function getActorChat() + { + return $this->actorChat; + } + + /** + * @param Chat|null $actorChat + * @return void + */ + public function setActorChat($actorChat) + { + $this->actorChat = $actorChat; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return array + */ + public function getOldReaction() + { + return $this->oldReaction; + } + + /** + * @param array $oldReaction + * @return void + */ + public function setOldReaction($oldReaction) + { + $this->oldReaction = $oldReaction; + } + + /** + * @return array + */ + public function getNewReaction() + { + return $this->newReaction; + } + + /** + * @param array $newReaction + * @return void + */ + public function setNewReaction($newReaction) + { + $this->newReaction = $newReaction; + } +} diff --git a/src/Types/PhotoSize.php b/src/Types/PhotoSize.php index 50c69063..07144621 100644 --- a/src/Types/PhotoSize.php +++ b/src/Types/PhotoSize.php @@ -35,12 +35,19 @@ class PhotoSize extends BaseType implements TypeInterface ]; /** - * Unique identifier for this file + * Identifier for this file, which can be used to download or reuse the file * * @var string */ protected $fileId; + /** + * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + * + * @var string + */ + protected $fileUniqueId; + /** * Photo width * @@ -56,19 +63,12 @@ class PhotoSize extends BaseType implements TypeInterface protected $height; /** - * Optional. File size + * Optional. File size in bytes * * @var int|null */ protected $fileSize; - /** - * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. - * - * @var string - */ - protected $fileUniqueId; - /** * @return string */ @@ -87,44 +87,39 @@ public function setFileId($fileId) } /** - * @return int|null + * @return string */ - public function getFileSize() + public function getFileUniqueId() { - return $this->fileSize; + return $this->fileUniqueId; } /** - * @param mixed $fileSize + * @param string $fileUniqueId * @return void - * @throws InvalidArgumentException */ - public function setFileSize($fileSize) + public function setFileUniqueId($fileUniqueId) { - if (is_integer($fileSize)) { - $this->fileSize = $fileSize; - } else { - throw new InvalidArgumentException(); - } + $this->fileUniqueId = $fileUniqueId; } /** * @return int */ - public function getHeight() + public function getWidth() { - return $this->height; + return $this->width; } /** - * @param mixed $height + * @param int $width * @return void * @throws InvalidArgumentException */ - public function setHeight($height) + public function setWidth($width) { - if (is_integer($height)) { - $this->height = $height; + if (is_integer($width)) { + $this->width = $width; } else { throw new InvalidArgumentException(); } @@ -133,39 +128,44 @@ public function setHeight($height) /** * @return int */ - public function getWidth() + public function getHeight() { - return $this->width; + return $this->height; } /** - * @param mixed $width + * @param int $height * @return void * @throws InvalidArgumentException */ - public function setWidth($width) + public function setHeight($height) { - if (is_integer($width)) { - $this->width = $width; + if (is_integer($height)) { + $this->height = $height; } else { throw new InvalidArgumentException(); } } /** - * @return string + * @return int|null */ - public function getFileUniqueId() + public function getFileSize() { - return $this->fileUniqueId; + return $this->fileSize; } /** - * @param string $fileUniqueId + * @param int|null $fileSize * @return void + * @throws InvalidArgumentException */ - public function setFileUniqueId($fileUniqueId) + public function setFileSize($fileSize) { - $this->fileUniqueId = $fileUniqueId; + if (is_integer($fileSize) || is_null($fileSize)) { + $this->fileSize = $fileSize; + } else { + throw new InvalidArgumentException(); + } } } diff --git a/src/Types/Poll.php b/src/Types/Poll.php index 2f59f611..b8bbb90b 100644 --- a/src/Types/Poll.php +++ b/src/Types/Poll.php @@ -37,6 +37,7 @@ class Poll extends BaseType implements TypeInterface protected static $map = [ 'id' => true, 'question' => true, + 'question_entities' => ArrayOfMessageEntity::class, 'options' => ArrayOfPollOption::class, 'total_voter_count' => true, 'is_closed' => true, @@ -44,6 +45,10 @@ class Poll extends BaseType implements TypeInterface 'type' => true, 'allows_multiple_answers' => true, 'correct_option_id' => true, + 'explanation' => true, + 'explanation_entities' => ArrayOfMessageEntity::class, + 'open_period' => true, + 'close_date' => true, ]; /** @@ -54,12 +59,19 @@ class Poll extends BaseType implements TypeInterface protected $id; /** - * Poll question, 1-255 characters + * Poll question, 1-300 characters * * @var string */ protected $question; + /** + * Optional. Special entities that appear in the question. Currently, only custom emoji entities are allowed in poll questions. + * + * @var array|null + */ + protected $questionEntities; + /** * List of poll options * Array of \TelegramBot\Api\Types\PollOption @@ -112,6 +124,34 @@ class Poll extends BaseType implements TypeInterface */ protected $correctOptionId; + /** + * Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters + * + * @var string|null + */ + protected $explanation; + + /** + * Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation + * + * @var array|null + */ + protected $explanationEntities; + + /** + * Optional. Amount of time in seconds the poll will be active after creation + * + * @var int|null + */ + protected $openPeriod; + + /** + * Optional. Point in time (Unix timestamp) when the poll will be automatically closed + * + * @var int|null + */ + protected $closeDate; + /** * @return string */ @@ -146,6 +186,23 @@ public function setQuestion($question) $this->question = $question; } + /** + * @return array|null + */ + public function getQuestionEntities() + { + return $this->questionEntities; + } + + /** + * @param array|null $questionEntities + * @return void + */ + public function setQuestionEntities($questionEntities) + { + $this->questionEntities = $questionEntities; + } + /** * @return array */ @@ -264,4 +321,72 @@ public function setCorrectOptionId($correctOptionId) { $this->correctOptionId = $correctOptionId; } + + /** + * @return string|null + */ + public function getExplanation() + { + return $this->explanation; + } + + /** + * @param string|null $explanation + * @return void + */ + public function setExplanation($explanation) + { + $this->explanation = $explanation; + } + + /** + * @return array|null + */ + public function getExplanationEntities() + { + return $this->explanationEntities; + } + + /** + * @param array|null $explanationEntities + * @return void + */ + public function setExplanationEntities($explanationEntities) + { + $this->explanationEntities = $explanationEntities; + } + + /** + * @return int|null + */ + public function getOpenPeriod() + { + return $this->openPeriod; + } + + /** + * @param int|null $openPeriod + * @return void + */ + public function setOpenPeriod($openPeriod) + { + $this->openPeriod = $openPeriod; + } + + /** + * @return int|null + */ + public function getCloseDate() + { + return $this->closeDate; + } + + /** + * @param int|null $closeDate + * @return void + */ + public function setCloseDate($closeDate) + { + $this->closeDate = $closeDate; + } } diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php index 5ae68123..69f19c52 100644 --- a/src/Types/PollAnswer.php +++ b/src/Types/PollAnswer.php @@ -11,7 +11,6 @@ * * This object represents an answer of a user in a non-anonymous poll. * - * * @package TelegramBot\Api\Types */ class PollAnswer extends BaseType @@ -21,7 +20,7 @@ class PollAnswer extends BaseType * * @var array */ - protected static $requiredParams = ['poll_id', 'option_ids', 'user']; + protected static $requiredParams = ['poll_id', 'option_ids']; /** * {@inheritdoc} @@ -29,22 +28,36 @@ class PollAnswer extends BaseType * @var array */ protected static $map = [ - 'option_ids' => true, - 'user' => User::class, 'poll_id' => true, + 'voter_chat' => Chat::class, + 'user' => User::class, + 'option_ids' => true, ]; /** - * @var \TelegramBot\Api\Types\User + * Unique poll identifier + * + * @var string */ - protected $user; + protected $pollId; /** - * @var string + * Optional. The chat that changed the answer to the poll, if the voter is anonymous + * + * @var Chat|null */ - protected $pollId; + protected $voterChat; + + /** + * Optional. The user that changed the answer to the poll, if the voter isn't anonymous + * + * @var User|null + */ + protected $user; /** + * 0-based identifiers of chosen answer options. May be empty if the vote was retracted + * * @var int[] */ protected $optionIds; @@ -58,41 +71,46 @@ public function getPollId() } /** - * @param string $id + * @param string $pollId * @return void */ - public function setPollId($id) + public function setPollId($pollId) { - $this->pollId = $id; + $this->pollId = $pollId; } /** - * @return User + * @return Chat|null */ - public function getUser() + public function getVoterChat() { - return $this->user; + return $this->voterChat; } /** - * @param User $from + * @param Chat|null $voterChat * @return void */ - public function setUser(User $from) + public function setVoterChat($voterChat) { - $this->user = $from; + $this->voterChat = $voterChat; } /** - * @deprecated - * - * @return User + * @return User|null */ - public function getFrom() + public function getUser() { - @trigger_error(sprintf('Access user with %s is deprecated, use "%s::getUser" method', __METHOD__, __CLASS__), \E_USER_DEPRECATED); + return $this->user; + } - return $this->getUser(); + /** + * @param User|null $user + * @return void + */ + public function setUser($user) + { + $this->user = $user; } /** @@ -107,7 +125,7 @@ public function getOptionIds() * @param int[] $optionIds * @return void */ - public function setOptionIds($optionIds) + public function setOptionIds(array $optionIds) { $this->optionIds = $optionIds; } diff --git a/src/Types/PollOption.php b/src/Types/PollOption.php index 45beabb6..f9b70304 100644 --- a/src/Types/PollOption.php +++ b/src/Types/PollOption.php @@ -27,7 +27,8 @@ class PollOption extends BaseType implements TypeInterface */ protected static $map = [ 'text' => true, - 'voter_count' => true + 'voter_count' => true, + 'text_entities' => ArrayOfMessageEntity::class ]; /** @@ -44,6 +45,13 @@ class PollOption extends BaseType implements TypeInterface */ protected $voterCount; + /** + * Optional. Special entities that appear in the option text. Currently, only custom emoji entities are allowed in poll option texts + * + * @var array|null + */ + protected $textEntities; + /** * @return string */ @@ -77,4 +85,21 @@ public function setVoterCount($voterCount) { $this->voterCount = $voterCount; } + + /** + * @return array|null + */ + public function getTextEntities() + { + return $this->textEntities; + } + + /** + * @param array|null $textEntities + * @return void + */ + public function setTextEntities($textEntities) + { + $this->textEntities = $textEntities; + } } diff --git a/src/Types/ProximityAlertTriggered.php b/src/Types/ProximityAlertTriggered.php new file mode 100644 index 00000000..837c4d50 --- /dev/null +++ b/src/Types/ProximityAlertTriggered.php @@ -0,0 +1,105 @@ + User::class, + 'watcher' => User::class, + 'distance' => true, + ]; + + /** + * User that triggered the alert + * + * @var User + */ + protected $traveler; + + /** + * User that set the alert + * + * @var User + */ + protected $watcher; + + /** + * The distance between the users + * + * @var int + */ + protected $distance; + + /** + * @return User + */ + public function getTraveler() + { + return $this->traveler; + } + + /** + * @param User $traveler + * @return void + */ + public function setTraveler(User $traveler) + { + $this->traveler = $traveler; + } + + /** + * @return User + */ + public function getWatcher() + { + return $this->watcher; + } + + /** + * @param User $watcher + * @return void + */ + public function setWatcher(User $watcher) + { + $this->watcher = $watcher; + } + + /** + * @return int + */ + public function getDistance() + { + return $this->distance; + } + + /** + * @param int $distance + * @return void + */ + public function setDistance($distance) + { + $this->distance = $distance; + } +} diff --git a/src/Types/ReactionCount.php b/src/Types/ReactionCount.php new file mode 100644 index 00000000..be6f62b9 --- /dev/null +++ b/src/Types/ReactionCount.php @@ -0,0 +1,74 @@ + ReactionType::class, + 'total_count' => true, + ]; + + /** + * Type of the reaction + * + * @var ReactionType + */ + protected $type; + + /** + * Number of times the reaction was added + * + * @var int + */ + protected $totalCount; + + /** + * @return ReactionType + */ + public function getType() + { + return $this->type; + } + + /** + * @param ReactionType $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return int + */ + public function getTotalCount() + { + return $this->totalCount; + } + + /** + * @param int $totalCount + * @return void + */ + public function setTotalCount($totalCount) + { + $this->totalCount = $totalCount; + } +} diff --git a/src/Types/ReactionType.php b/src/Types/ReactionType.php new file mode 100644 index 00000000..983473e7 --- /dev/null +++ b/src/Types/ReactionType.php @@ -0,0 +1,36 @@ +type; + } + + /** + * Set the type of the reaction. + * + * @param string $type + */ + protected function setType($type) + { + $this->type = $type; + } +} diff --git a/src/Types/ReactionTypeCustomEmoji.php b/src/Types/ReactionTypeCustomEmoji.php new file mode 100644 index 00000000..6e7c7b74 --- /dev/null +++ b/src/Types/ReactionTypeCustomEmoji.php @@ -0,0 +1,56 @@ + true, + 'custom_emoji_id' => true, + ]; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['type', 'custom_emoji_id']; + + /** + * Custom emoji identifier + * + * @var string + */ + protected $customEmojiId; + + /** + * Get the custom emoji identifier. + * + * @return string + */ + public function getCustomEmojiId() + { + return $this->customEmojiId; + } + + /** + * Set the custom emoji identifier. + * + * @param string $customEmojiId + */ + protected function setCustomEmojiId($customEmojiId) + { + $this->customEmojiId = $customEmojiId; + } +} diff --git a/src/Types/ReactionTypeEmoji.php b/src/Types/ReactionTypeEmoji.php new file mode 100644 index 00000000..9fec8892 --- /dev/null +++ b/src/Types/ReactionTypeEmoji.php @@ -0,0 +1,55 @@ + true, + 'emoji' => true, + ]; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['type', 'emoji']; + /** + * Reaction emoji + * + * @var string + */ + protected $emoji; + + /** + * Get the reaction emoji. + * + * @return string + */ + public function getEmoji() + { + return $this->emoji; + } + + /** + * Set the reaction emoji. + * + * @param string $emoji + */ + protected function setEmoji($emoji) + { + $this->emoji = $emoji; + } +} diff --git a/src/Types/ReplyParameters.php b/src/Types/ReplyParameters.php new file mode 100644 index 00000000..5275bb33 --- /dev/null +++ b/src/Types/ReplyParameters.php @@ -0,0 +1,205 @@ + true, + 'chat_id' => true, + 'allow_sending_without_reply' => true, + 'quote' => true, + 'quote_parse_mode' => true, + 'quote_entities' => ArrayOfMessageEntity::class, + 'quote_position' => true, + ]; + + /** + * Identifier of the message that will be replied to in the current chat, or in the chat chat_id if it is specified + * + * @var int + */ + protected $messageId; + + /** + * Optional. If the message to be replied to is from a different chat, unique identifier for the chat or username of the channel (in the format @channelusername). Not supported for messages sent on behalf of a business account. + * + * @var int|string|null + */ + protected $chatId; + + /** + * Optional. Pass True if the message should be sent even if the specified message to be replied to is not found. Always False for replies in another chat or forum topic. Always True for messages sent on behalf of a business account. + * + * @var bool|null + */ + protected $allowSendingWithoutReply; + + /** + * Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing. The quote must be an exact substring of the message to be replied to, including bold, italic, underline, strikethrough, spoiler, and custom_emoji entities. The message will fail to send if the quote isn't found in the original message. + * + * @var string|null + */ + protected $quote; + + /** + * Optional. Mode for parsing entities in the quote. See formatting options for more details. + * + * @var string|null + */ + protected $quoteParseMode; + + /** + * Optional. A JSON-serialized list of special entities that appear in the quote. It can be specified instead of quote_parse_mode. + * + * @var ArrayOfMessageEntity|null + */ + protected $quoteEntities; + + /** + * Optional. Position of the quote in the original message in UTF-16 code units + * + * @var int|null + */ + protected $quotePosition; + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } + + /** + * @return int|string|null + */ + public function getChatId() + { + return $this->chatId; + } + + /** + * @param int|string|null $chatId + * @return void + */ + public function setChatId($chatId) + { + $this->chatId = $chatId; + } + + /** + * @return bool|null + */ + public function getAllowSendingWithoutReply() + { + return $this->allowSendingWithoutReply; + } + + /** + * @param bool|null $allowSendingWithoutReply + * @return void + */ + public function setAllowSendingWithoutReply($allowSendingWithoutReply) + { + $this->allowSendingWithoutReply = $allowSendingWithoutReply; + } + + /** + * @return string|null + */ + public function getQuote() + { + return $this->quote; + } + + /** + * @param string|null $quote + * @return void + */ + public function setQuote($quote) + { + $this->quote = $quote; + } + + /** + * @return string|null + */ + public function getQuoteParseMode() + { + return $this->quoteParseMode; + } + + /** + * @param string|null $quoteParseMode + * @return void + */ + public function setQuoteParseMode($quoteParseMode) + { + $this->quoteParseMode = $quoteParseMode; + } + + /** + * @return ArrayOfMessageEntity|null + */ + public function getQuoteEntities() + { + return $this->quoteEntities; + } + + /** + * @param ArrayOfMessageEntity|null $quoteEntities + * @return void + */ + public function setQuoteEntities($quoteEntities) + { + $this->quoteEntities = $quoteEntities; + } + + /** + * @return int|null + */ + public function getQuotePosition() + { + return $this->quotePosition; + } + + /** + * @param int|null $quotePosition + * @return void + */ + public function setQuotePosition($quotePosition) + { + $this->quotePosition = $quotePosition; + } +} diff --git a/src/Types/ResponseParameters.php b/src/Types/ResponseParameters.php new file mode 100644 index 00000000..7cc3bf24 --- /dev/null +++ b/src/Types/ResponseParameters.php @@ -0,0 +1,78 @@ + true, + 'retry_after' => true + ]; + + /** + * The group has been migrated to a supergroup with the specified identifier + * + * @var int|null + */ + protected $migrateToChatId; + + /** + * In case of exceeding flood control, the number of seconds left to wait before the request can be repeated + * + * @var int|null + */ + protected $retryAfter; + + /** + * @return int|null + */ + public function getMigrateToChatId() + { + return $this->migrateToChatId; + } + + /** + * @param int|null $migrateToChatId + */ + public function setMigrateToChatId($migrateToChatId) + { + $this->migrateToChatId = $migrateToChatId; + } + + /** + * @return int|null + */ + public function getRetryAfter() + { + return $this->retryAfter; + } + + /** + * @param int|null $retryAfter + */ + public function setRetryAfter($retryAfter) + { + $this->retryAfter = $retryAfter; + } +} diff --git a/src/Types/SharedUser.php b/src/Types/SharedUser.php new file mode 100644 index 00000000..21f9a1fd --- /dev/null +++ b/src/Types/SharedUser.php @@ -0,0 +1,155 @@ + true, + 'first_name' => true, + 'last_name' => true, + 'username' => true, + 'photo' => ArrayOfPhotoSize::class + ]; + + /** + * Identifier of the shared user + * + * @var int + */ + protected $userId; + + /** + * Optional. First name of the user, if the name was requested by the bot + * + * @var string|null + */ + protected $firstName; + + /** + * Optional. Last name of the user, if the name was requested by the bot + * + * @var string|null + */ + protected $lastName; + + /** + * Optional. Username of the user, if the username was requested by the bot + * + * @var string|null + */ + protected $username; + + /** + * Optional. Available sizes of the chat photo, if the photo was requested by the bot + * + * @var array|null + */ + protected $photo; + + /** + * @return int + */ + public function getUserId() + { + return $this->userId; + } + + /** + * @param int $userId + * @return void + */ + public function setUserId($userId) + { + $this->userId = $userId; + } + + /** + * @return string|null + */ + public function getFirstName() + { + return $this->firstName; + } + + /** + * @param string|null $firstName + * @return void + */ + public function setFirstName($firstName) + { + $this->firstName = $firstName; + } + + /** + * @return string|null + */ + public function getLastName() + { + return $this->lastName; + } + + /** + * @param string|null $lastName + * @return void + */ + public function setLastName($lastName) + { + $this->lastName = $lastName; + } + + /** + * @return string|null + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param string|null $username + * @return void + */ + public function setUsername($username) + { + $this->username = $username; + } + + /** + * @return array|null + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param array|null $photo + * @return void + */ + public function setPhoto($photo) + { + $this->photo = $photo; + } +} diff --git a/src/Types/Story.php b/src/Types/Story.php new file mode 100644 index 00000000..42683884 --- /dev/null +++ b/src/Types/Story.php @@ -0,0 +1,85 @@ + Chat::class, + 'id' => true, + ]; + + /** + * Chat that posted the story + * + * @var Chat + */ + protected $chat; + + /** + * Unique identifier for the story in the chat + * + * @var int + */ + protected $id; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat(Chat $chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * @return void + */ + public function setId($id) + { + if (is_integer($id)) { + $this->id = $id; + } else { + throw new InvalidArgumentException(); + } + } +} diff --git a/src/Types/TextQuote.php b/src/Types/TextQuote.php new file mode 100644 index 00000000..d7202bfa --- /dev/null +++ b/src/Types/TextQuote.php @@ -0,0 +1,131 @@ + true, + 'entities' => ArrayOfMessageEntity::class, + 'position' => true, + 'is_manual' => true, + ]; + + /** + * Text of the quoted part of a message that is replied to by the given message + * + * @var string + */ + protected $text; + + /** + * Optional. Special entities that appear in the quote. Currently, only bold, italic, underline, strikethrough, + * spoiler, and custom_emoji entities are kept in quotes. + * + * @var array|null + */ + protected $entities; + + /** + * Approximate quote position in the original message in UTF-16 code units as specified by the sender + * + * @var int + */ + protected $position; + + /** + * Optional. True, if the quote was chosen manually by the message sender. Otherwise, the quote was added automatically by the server. + * + * @var bool|null + */ + protected $isManual; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return array|null + */ + public function getEntities() + { + return $this->entities; + } + + /** + * @param array|null $entities + * @return void + */ + public function setEntities($entities) + { + $this->entities = $entities; + } + + /** + * @return int + */ + public function getPosition() + { + return $this->position; + } + + /** + * @param int $position + * @return void + */ + public function setPosition($position) + { + $this->position = $position; + } + + /** + * @return bool|null + */ + public function getIsManual() + { + return $this->isManual; + } + + /** + * @param bool|null $isManual + * @return void + */ + public function setIsManual($isManual) + { + $this->isManual = $isManual; + } +} diff --git a/src/Types/User.php b/src/Types/User.php index 34a8be78..cd8faa72 100644 --- a/src/Types/User.php +++ b/src/Types/User.php @@ -32,12 +32,13 @@ class User extends BaseType implements TypeInterface 'last_name' => true, 'username' => true, 'language_code' => true, + 'is_bot' => true, 'is_premium' => true, 'added_to_attachment_menu' => true, 'can_join_groups' => true, 'can_read_all_group_messages' => true, 'supports_inline_queries' => true, - 'is_bot' => true + 'can_connect_to_business' => true ]; /** @@ -118,207 +119,132 @@ class User extends BaseType implements TypeInterface protected $supportsInlineQueries; /** - * @return string + * Optional. True, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in getMe. + * + * @var bool|null */ - public function getFirstName() + protected $canConnectToBusiness; + + public function getId(): int { - return $this->firstName; + return $this->id; } - /** - * @param string $firstName - * - * @return void - */ - public function setFirstName($firstName) + public function setId($id): void { - $this->firstName = $firstName; + if (!is_int($id) && !is_float($id)) { + throw new InvalidArgumentException('ID must be an integer or float'); + } + $this->id = $id; } - /** - * @return int|float - */ - public function getId() + public function getFirstName(): string { - return $this->id; + return $this->firstName; } - /** - * @param mixed $id - * - * @throws InvalidArgumentException - * - * @return void - */ - public function setId($id) + public function setFirstName($firstName): void { - if (is_integer($id) || is_float($id)) { - $this->id = $id; - } else { - throw new InvalidArgumentException(); - } + $this->firstName = $firstName; } - /** - * @return null|string - */ - public function getLastName() + public function getLastName(): ?string { return $this->lastName; } - /** - * @param string $lastName - * - * @return void - */ - public function setLastName($lastName) + public function setLastName($lastName): void { $this->lastName = $lastName; } - /** - * @return null|string - */ - public function getUsername() + public function getUsername(): ?string { return $this->username; } - /** - * @param string $username - * - * @return void - */ - public function setUsername($username) + public function setUsername($username): void { $this->username = $username; } - /** - * @return null|string - */ public function getLanguageCode() { return $this->languageCode; } - /** - * @param string $languageCode - * - * @return void - */ - public function setLanguageCode($languageCode) + public function setLanguageCode($languageCode): void { $this->languageCode = $languageCode; } - /** - * @return bool - */ - public function isBot() + public function isBot(): bool { return $this->isBot; } - /** - * @param bool $isBot - * - * @return void - */ - public function setIsBot($isBot) + public function setIsBot($isBot): void { $this->isBot = $isBot; } - /** - * @param bool $isPremium - * - * @return void - */ - public function setIsPremium($isPremium) + public function getIsPremium(): ?bool + { + return $this->isPremium; + } + + public function setIsPremium($isPremium): void { $this->isPremium = $isPremium; } - /** - * @return bool|null - */ - public function getIsPremium() + public function getAddedToAttachmentMenu(): ?bool { - return $this->isPremium; + return $this->addedToAttachmentMenu; } - /** - * @param bool $addedToAttachmentMenu - * - * @return void - */ - public function setAddedToAttachmentMenu($addedToAttachmentMenu) + public function setAddedToAttachmentMenu($addedToAttachmentMenu): void { $this->addedToAttachmentMenu = $addedToAttachmentMenu; } - /** - * @return bool|null - */ - public function getAddedToAttachmentMenu() + public function getCanJoinGroups(): ?bool { - return $this->addedToAttachmentMenu; + return $this->canJoinGroups; } - /** - * @param bool $canJoinGroups - * - * @return void - */ - public function setCanJoinGroups($canJoinGroups) + public function setCanJoinGroups($canJoinGroups): void { $this->canJoinGroups = $canJoinGroups; } - /** - * @return bool|null - */ - public function getCanJoinGroups() + public function getCanReadAllGroupMessages(): ?bool { - return $this->canJoinGroups; + return $this->canReadAllGroupMessages; } - /** - * @param bool $canReadAllGroupMessages - * - * @return void - */ - public function setCanReadAllGroupMessages($canReadAllGroupMessages) + public function setCanReadAllGroupMessages($canReadAllGroupMessages): void { $this->canReadAllGroupMessages = $canReadAllGroupMessages; } - /** - * @return bool|null - */ - public function getCanReadAllGroupMessages() + public function getSupportsInlineQueries(): ?bool { - return $this->canReadAllGroupMessages; + return $this->supportsInlineQueries; } - /** - * @param bool $supportsInlineQueries - * - * @return void - */ - public function setSupportsInlineQueries($supportsInlineQueries) + public function setSupportsInlineQueries($supportsInlineQueries): void { $this->supportsInlineQueries = $supportsInlineQueries; } - /** - * @return bool|null - */ - public function getSupportsInlineQueries() + public function getCanConnectToBusiness(): ?bool { - return $this->supportsInlineQueries; + return $this->canConnectToBusiness; } + public function setCanConnectToBusiness($canConnectToBusiness): void + { + $this->canConnectToBusiness = $canConnectToBusiness; + } } diff --git a/src/Types/UserChatBoosts.php b/src/Types/UserChatBoosts.php new file mode 100644 index 00000000..5543b587 --- /dev/null +++ b/src/Types/UserChatBoosts.php @@ -0,0 +1,54 @@ + ArrayOfChatBoost::class + ]; + + /** + * The list of boosts added to the chat by the user + * + * @var ArrayOfChatBoost + */ + protected $boosts; + + /** + * @return ArrayOfChatBoost + */ + public function getBoosts() + { + return $this->boosts; + } + + /** + * @param ArrayOfChatBoost $boosts + */ + public function setBoosts($boosts): void + { + $this->boosts = $boosts; + } +} diff --git a/src/Types/UsersShared.php b/src/Types/UsersShared.php new file mode 100644 index 00000000..818b5950 --- /dev/null +++ b/src/Types/UsersShared.php @@ -0,0 +1,81 @@ + true, + 'users' => ArrayOfSharedUser::class + ]; + + /** + * Identifier of the request + * + * @var int + */ + protected $requestId; + + /** + * Information about users shared with the bot + * Array of \TelegramBot\Api\Types\SharedUser + * + * @var array + */ + protected $users; + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @param int $requestId + * @return void + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + } + + /** + * @return array + */ + public function getUsers() + { + return $this->users; + } + + /** + * @param array $users + * @return void + */ + public function setUsers($users) + { + $this->users = $users; + } +} diff --git a/src/Types/Venue.php b/src/Types/Venue.php index 38718f64..2ffd125c 100644 --- a/src/Types/Venue.php +++ b/src/Types/Venue.php @@ -1,10 +1,4 @@ true, + ]; + + /** + * Video chat duration in seconds + * + * @var int + */ + protected $duration; + + /** + * @return int + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param int $duration + * @return void + */ + public function setDuration($duration) + { + $this->duration = $duration; + } +} diff --git a/src/Types/VideoChatParticipantsInvited.php b/src/Types/VideoChatParticipantsInvited.php new file mode 100644 index 00000000..934b3ad5 --- /dev/null +++ b/src/Types/VideoChatParticipantsInvited.php @@ -0,0 +1,55 @@ + ArrayOfUser::class, + ]; + + /** + * New members that were invited to the video chat + * + * @var array + */ + protected $users; + + /** + * @return array + */ + public function getUsers() + { + return $this->users; + } + + /** + * @param array $users + * @return void + */ + public function setUsers($users) + { + $this->users = $users; + } +} diff --git a/src/Types/VideoChatScheduled.php b/src/Types/VideoChatScheduled.php new file mode 100644 index 00000000..d329f52f --- /dev/null +++ b/src/Types/VideoChatScheduled.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * Point in time (Unix timestamp) when the video chat is supposed to be started by a chat administrator + * + * @var int + */ + protected $startDate; + + /** + * @return int + */ + public function getStartDate() + { + return $this->startDate; + } + + /** + * @param int $startDate + * @return void + */ + public function setStartDate($startDate) + { + $this->startDate = $startDate; + } +} diff --git a/src/Types/VideoChatStarted.php b/src/Types/VideoChatStarted.php new file mode 100644 index 00000000..f67914c7 --- /dev/null +++ b/src/Types/VideoChatStarted.php @@ -0,0 +1,10 @@ + true, 'file_unique_id' => true, diff --git a/src/Types/WebAppInfo.php b/src/Types/WebAppInfo.php new file mode 100644 index 00000000..d33ea0a5 --- /dev/null +++ b/src/Types/WebAppInfo.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps + * + * @var string + */ + protected $url; + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + * @return void + */ + public function setUrl($url) + { + $this->url = $url; + } +} diff --git a/src/Types/WriteAccessAllowed.php b/src/Types/WriteAccessAllowed.php new file mode 100644 index 00000000..243de7b1 --- /dev/null +++ b/src/Types/WriteAccessAllowed.php @@ -0,0 +1,98 @@ + true, + 'web_app_name' => true, + 'from_attachment_menu' => true, + ]; + + /** + * Optional. True, if the access was granted after the user accepted an explicit request from a Web App sent by the method requestWriteAccess + * + * @var bool|null + */ + protected $fromRequest; + + /** + * Optional. Name of the Web App, if the access was granted when the Web App was launched from a link + * + * @var string|null + */ + protected $webAppName; + + /** + * Optional. True, if the access was granted when the bot was added to the attachment or side menu + * + * @var bool|null + */ + protected $fromAttachmentMenu; + + /** + * @return bool|null + */ + public function isFromRequest() + { + return $this->fromRequest; + } + + /** + * @param bool|null $fromRequest + * @return void + */ + public function setFromRequest($fromRequest) + { + $this->fromRequest = $fromRequest; + } + + /** + * @return string|null + */ + public function getWebAppName() + { + return $this->webAppName; + } + + /** + * @param string|null $webAppName + * @return void + */ + public function setWebAppName($webAppName) + { + $this->webAppName = $webAppName; + } + + /** + * @return bool|null + */ + public function isFromAttachmentMenu() + { + return $this->fromAttachmentMenu; + } + + /** + * @param bool|null $fromAttachmentMenu + * @return void + */ + public function setFromAttachmentMenu($fromAttachmentMenu) + { + $this->fromAttachmentMenu = $fromAttachmentMenu; + } +} diff --git a/tests/BotApiTest.php b/tests/BotApiTest.php index 823292d3..43e351bf 100644 --- a/tests/BotApiTest.php +++ b/tests/BotApiTest.php @@ -143,6 +143,6 @@ private function createHttpClient() private function createBotApi(HttpClientInterface $httpClient) { - return new BotApi('token', null, $httpClient); + return new BotApi('token', $httpClient); } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index bc0737e5..14a70371 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -136,10 +136,9 @@ public function testGetInlineQueryChecker($update) public function testBadMethodCallException() { $this->expectException(BadMethodCallException::class); - $this->expectErrorMessage('Method testMethod not exists'); + $this->expectExceptionMessage('Method testMethod not exists'); $item = new Client('testToken'); - $item->testMethod(); } diff --git a/tests/Collection/CollectionTest.php b/tests/Collection/CollectionTest.php index c8aceb99..48994aab 100644 --- a/tests/Collection/CollectionTest.php +++ b/tests/Collection/CollectionTest.php @@ -88,20 +88,4 @@ public function testCantAddMoreThenMaxLimit() $media->addItem(new InputMediaPhoto('link')); $media->addItem(new InputMediaPhoto('link')); } - - public function testCanOutputItemsAsArray() - { - $media = new ArrayOfInputMedia(); - $media->addItem(new InputMediaPhoto('link')); - - $this->assertSame($this->itemsOutput, $media->toJson(true)); - } - - public function testCanOutputItemsAsJson() - { - $media = new ArrayOfInputMedia(); - $media->addItem(new InputMediaPhoto('link')); - - $this->assertSame(json_encode($this->itemsOutput), $media->toJson()); - } } diff --git a/tests/Events/EventCollectionTest.php b/tests/Events/EventCollectionTest.php index a66ac5d9..a5e18d8b 100644 --- a/tests/Events/EventCollectionTest.php +++ b/tests/Events/EventCollectionTest.php @@ -3,7 +3,6 @@ namespace TelegramBot\Api\Test\Events; use PHPUnit\Framework\TestCase; -use TelegramBot\Api\Botan; use TelegramBot\Api\Events\Event; use TelegramBot\Api\Events\EventCollection; use TelegramBot\Api\Types\Update; @@ -92,38 +91,6 @@ public function testAdd2($action) } } - /** - * @param \Closure $action - * @param \Closure $checker - * @param Update $update - * - * @dataProvider data - */ - public function testHandle1($action, $checker, $update) - { - $item = new EventCollection('testToken'); - $name = 'test'; - $item->add($action, function ($update) use ($name) { - return true; - }); - - $mockedTracker = $this->getMockBuilder(Botan::class) - ->disableOriginalConstructor() - ->getMock(); - - // Configure the stub. - - $mockedTracker->expects($this->once())->method('track')->willReturn(null); - - $reflection = new \ReflectionClass($item); - $reflectionProperty = $reflection->getProperty('tracker'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($item, $mockedTracker); - $reflectionProperty->setAccessible(false); - - $item->handle($update); - } - /** * @param \Closure $action * @param \Closure $checker @@ -139,16 +106,11 @@ public function testHandle2($action, $checker, $update) return true; }); - $mockedTracker = $this->getMockBuilder(Botan::class) - ->disableOriginalConstructor() - ->getMock(); - $mockedEvent = $this->getMockBuilder(Event::class) ->disableOriginalConstructor() ->getMock(); // Configure the stub. - $mockedTracker->expects($this->exactly(0))->method('track')->willReturn(null); $mockedEvent->expects($this->once())->method('executeChecker')->willReturn(true); $mockedEvent->expects($this->once())->method('executeAction')->willReturn(true); diff --git a/tests/Types/ChatMemberTest.php b/tests/Types/ChatMemberTest.php deleted file mode 100644 index 6fd4018d..00000000 --- a/tests/Types/ChatMemberTest.php +++ /dev/null @@ -1,105 +0,0 @@ - UserTest::getMinResponse(), - 'status' => 'member', - ]; - } - - public static function getFullResponse() - { - return [ - 'user' => UserTest::getMinResponse(), - 'status' => 'member', - 'until_date' => 1682343644, - 'can_be_edited' => true, - 'can_change_info' => true, - 'can_post_messages' => true, - 'can_edit_messages' => true, - 'can_delete_messages' => true, - 'can_invite_users' => true, - 'can_restrict_members' => true, - 'can_pin_messages' => true, - 'can_promote_members' => true, - 'can_send_messages' => true, - 'can_send_media_messages' => true, - 'can_send_other_messages' => true, - 'can_add_web_page_previews' => true, - 'can_manage_topics' => true, - 'is_anonymous' => true, - 'custom_title' => 'custom_title', - 'can_manage_chat' => true, - 'can_send_polls' => true, - ]; - } - - /** - * @param ChatMember $item - * @return void - */ - protected function assertMinItem($item) - { - $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); - $this->assertEquals('member', $item->getStatus()); - $this->assertNull($item->getUntilDate()); - $this->assertNull($item->getCanBeEdited()); - $this->assertNull($item->getCanChangeInfo()); - $this->assertNull($item->getCanPostMessages()); - $this->assertNull($item->getCanEditMessages()); - $this->assertNull($item->getCanDeleteMessages()); - $this->assertNull($item->getCanInviteUsers()); - $this->assertNull($item->getCanRestrictMembers()); - $this->assertNull($item->getCanPinMessages()); - $this->assertNull($item->getCanPromoteMembers()); - $this->assertNull($item->getCanSendMessages()); - $this->assertNull($item->getCanSendMediaMessages()); - $this->assertNull($item->getCanSendOtherMessages()); - $this->assertNull($item->getCanAddWebPagePreviews()); - $this->assertNull($item->getCanManageTopics()); - $this->assertNull($item->getIsAnonymous()); - $this->assertNull($item->getCustomTitle()); - $this->assertNull($item->getCanManageChat()); - $this->assertNull($item->getCanSendPolls()); - } - - /** - * @param ChatMember $item - * @return void - */ - protected function assertFullItem($item) - { - $this->assertEquals(1682343644, $item->getUntilDate()); - $this->assertTrue($item->getCanBeEdited()); - $this->assertTrue($item->getCanChangeInfo()); - $this->assertTrue($item->getCanPostMessages()); - $this->assertTrue($item->getCanEditMessages()); - $this->assertTrue($item->getCanDeleteMessages()); - $this->assertTrue($item->getCanInviteUsers()); - $this->assertTrue($item->getCanRestrictMembers()); - $this->assertTrue($item->getCanPinMessages()); - $this->assertTrue($item->getCanPromoteMembers()); - $this->assertTrue($item->getCanSendMessages()); - $this->assertTrue($item->getCanSendMediaMessages()); - $this->assertTrue($item->getCanSendOtherMessages()); - $this->assertTrue($item->getCanAddWebPagePreviews()); - $this->assertTrue($item->getCanManageTopics()); - $this->assertTrue($item->getIsAnonymous()); - $this->assertEquals('custom_title', $item->getCustomTitle()); - $this->assertTrue($item->getCanManageChat()); - $this->assertTrue($item->getCanSendPolls()); - } -} diff --git a/tests/Types/ChatMemberUpdatedTest.php b/tests/Types/ChatMemberUpdatedTest.php deleted file mode 100644 index 8f80f995..00000000 --- a/tests/Types/ChatMemberUpdatedTest.php +++ /dev/null @@ -1,68 +0,0 @@ - ChatTest::getMinResponse(), - 'from' => UserTest::getMinResponse(), - 'date' => 100500, - 'old_chat_member' => ChatMemberTest::getMinResponse(), - 'new_chat_member' => ChatMemberTest::getMinResponse(), - ]; - } - - public static function getFullResponse() - { - return [ - 'chat' => ChatTest::getMinResponse(), - 'from' => UserTest::getMinResponse(), - 'date' => 100500, - 'old_chat_member' => ChatMemberTest::getMinResponse(), - 'new_chat_member' => ChatMemberTest::getMinResponse(), - 'invite_link' => ChatInviteLinkTest::getMinResponse(), - 'via_chat_folder_invite_link' => true, - ]; - } - - /** - * @param ChatMemberUpdated $item - * @return void - */ - protected function assertMinItem($item) - { - $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); - $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); - $this->assertEquals(100500, $item->getDate()); - $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getOldChatMember()); - $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getNewChatMember()); - $this->assertNull($item->getInviteLink()); - $this->assertNull($item->getViaChatFolderInviteLink()); - } - - /** - * @param ChatMemberUpdated $item - * @return void - */ - protected function assertFullItem($item) - { - $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); - $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); - $this->assertEquals(100500, $item->getDate()); - $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getOldChatMember()); - $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getNewChatMember()); - $this->assertEquals(ChatInviteLinkTest::createMinInstance(), $item->getInviteLink()); - $this->assertTrue($item->getViaChatFolderInviteLink()); - } -} diff --git a/tests/Types/ChatTest.php b/tests/Types/ChatTest.php index 1ea4634d..54ab521c 100644 --- a/tests/Types/ChatTest.php +++ b/tests/Types/ChatTest.php @@ -65,29 +65,10 @@ protected function assertMinItem($item) $this->assertEquals('private', $item->getType()); $this->assertNull($item->getTitle()); - $this->assertNull($item->getInviteLink()); $this->assertNull($item->getFirstName()); $this->assertNull($item->getLastName()); $this->assertNull($item->getUsername()); - $this->assertNull($item->getBio()); - $this->assertNull($item->getDescription()); - $this->assertNull($item->getSlowModeDelay()); - $this->assertNull($item->getStickerSetName()); - $this->assertNull($item->getCanSetStickerSet()); - $this->assertNull($item->getLinkedChatId()); - $this->assertNull($item->getJoinToSendMessages()); - $this->assertNull($item->getJoinByRequest()); - $this->assertNull($item->getMessageAutoDeleteTime()); - $this->assertNull($item->getHasProtectedContent()); $this->assertNull($item->getIsForum()); - $this->assertNull($item->getActiveUsernames()); - $this->assertNull($item->getEmojiStatusCustomEmojiId()); - $this->assertNull($item->getHasPrivateForwards()); - $this->assertNull($item->getHasRestrictedVoiceAndVideoMessages()); - $this->assertNull($item->getPhoto()); - $this->assertNull($item->getPinnedMessage()); - $this->assertNull($item->getPermissions()); - $this->assertNull($item->getLocation()); } /** @@ -99,29 +80,9 @@ protected function assertFullItem($item) $this->assertEquals(123456, $item->getId()); $this->assertEquals('private', $item->getType()); $this->assertEquals('title', $item->getTitle()); - $this->assertEquals('invite_link', $item->getInviteLink()); $this->assertEquals('Ilya', $item->getFirstName()); $this->assertEquals('Gusev', $item->getLastName()); $this->assertEquals('iGusev', $item->getUsername()); - $this->assertEquals('PHP Telegram Bot API', $item->getBio()); - $this->assertEquals('description', $item->getDescription()); - $this->assertEquals(10, $item->getSlowModeDelay()); - $this->assertEquals('sticker_set_name', $item->getStickerSetName()); - $this->assertEquals(true, $item->getCanSetStickerSet()); - $this->assertEquals(2, $item->getLinkedChatId()); - $this->assertEquals(true, $item->getJoinToSendMessages()); - $this->assertEquals(true, $item->getJoinByRequest()); - $this->assertEquals(10000, $item->getMessageAutoDeleteTime()); - $this->assertEquals(true, $item->getHasProtectedContent()); - $this->assertEquals(true, $item->getIsForum()); - $this->assertEquals(['username'], $item->getActiveUsernames()); - $this->assertEquals('emoji_status_custom_emoji_id', $item->getEmojiStatusCustomEmojiId()); - $this->assertEquals(true, $item->getHasPrivateForwards()); - $this->assertEquals(true, $item->getHasRestrictedVoiceAndVideoMessages()); - $this->assertEquals(ChatPhotoTest::createMinInstance(), $item->getPhoto()); - $this->assertEquals(MessageTest::createMinInstance(), $item->getPinnedMessage()); - $this->assertEquals(ChatPermissionsTest::createFullInstance(), $item->getPermissions()); - $this->assertEquals(ChatLocationTest::createMinInstance(), $item->getLocation()); } public function testSet64bitId() diff --git a/tests/Types/MessageOriginChannelTest.php b/tests/Types/MessageOriginChannelTest.php new file mode 100644 index 00000000..c6c0db3b --- /dev/null +++ b/tests/Types/MessageOriginChannelTest.php @@ -0,0 +1,74 @@ + 'channel', + 'date' => 1640908800, + 'chat' => [ + 'id' => 123456, + 'type' => 'private', + ], + 'message_id' => 12345, + ]; + } + + public static function getFullResponse() + { + return [ + 'type' => 'channel', + 'date' => 1640908800, + 'chat' => [ + 'id' => 123456, + 'type' => 'private', + ], + 'message_id' => 12345, + 'author_signature' => 'John Doe', + ]; + } + + /** + * @param MessageOriginChannel $item + */ + protected function assertMinItem($item) + { + $this->assertEquals('channel', $item->getType()); + $this->assertEquals(1640908800, $item->getDate()); + $this->assertEquals(12345, $item->getMessageId()); + $this->assertNull($item->getAuthorSignature()); + + $chat = $item->getChat(); + $this->assertInstanceOf(Chat::class, $chat); + $this->assertEquals(123456, $chat->getId()); + $this->assertEquals('private', $chat->getType()); + } + + /** + * @param MessageOriginChannel $item + */ + protected function assertFullItem($item) + { + $this->assertEquals('channel', $item->getType()); + $this->assertEquals(1640908800, $item->getDate()); + $this->assertEquals(12345, $item->getMessageId()); + $this->assertEquals('John Doe', $item->getAuthorSignature()); + + $chat = $item->getChat(); + $this->assertInstanceOf(Chat::class, $chat); + $this->assertEquals(123456, $chat->getId()); + $this->assertEquals('private', $chat->getType()); + } +} diff --git a/tests/Types/MessageTest.php b/tests/Types/MessageTest.php index b15472d4..ae4f470c 100644 --- a/tests/Types/MessageTest.php +++ b/tests/Types/MessageTest.php @@ -106,12 +106,6 @@ protected function assertMinItem($item) $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); $this->assertNull($item->getFrom()); - $this->assertNull($item->getForwardFrom()); - $this->assertNull($item->getForwardFromChat()); - $this->assertNull($item->getForwardFromMessageId()); - $this->assertNull($item->getForwardDate()); - $this->assertNull($item->getForwardSignature()); - $this->assertNull($item->getForwardSenderName()); $this->assertNull($item->getReplyToMessage()); $this->assertNull($item->getViaBot()); $this->assertNull($item->getEditDate()); @@ -168,12 +162,6 @@ protected function assertFullItem($item) $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); - $this->assertEquals(UserTest::createMinInstance(), $item->getForwardFrom()); - $this->assertEquals(ChatTest::createMinInstance(), $item->getForwardFromChat()); - $this->assertEquals(2, $item->getForwardFromMessageId()); - $this->assertEquals(1682343645, $item->getForwardDate()); - $this->assertEquals('forward_signature', $item->getForwardSignature()); - $this->assertEquals('forward_sender_name', $item->getForwardSenderName()); $this->assertEquals(MessageTest::createMinInstance(), $item->getReplyToMessage()); $this->assertEquals(UserTest::createMinInstance(), $item->getViaBot()); $this->assertEquals(1682343643, $item->getEditDate()); @@ -250,14 +238,6 @@ public function testSetEditDateException() $item->setEditDate('s'); } - public function testSetForwardDateException() - { - $this->expectException(InvalidArgumentException::class); - - $item = new Message(); - $item->setForwardDate('s'); - } - public function testToJson1() { $data = [ diff --git a/tests/Types/PollAnswerTest.php b/tests/Types/PollAnswerTest.php index 4c3b0ce1..ed08dbd4 100644 --- a/tests/Types/PollAnswerTest.php +++ b/tests/Types/PollAnswerTest.php @@ -34,7 +34,6 @@ protected function assertMinItem($item) { $this->assertEquals(123456789, $item->getPollId()); $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); - $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); $this->assertEquals([1,2,3,4,5,6], $item->getOptionIds()); } diff --git a/tests/Types/ReactionTypeCustomEmojiTest.php b/tests/Types/ReactionTypeCustomEmojiTest.php new file mode 100644 index 00000000..bab97bd5 --- /dev/null +++ b/tests/Types/ReactionTypeCustomEmojiTest.php @@ -0,0 +1,46 @@ + 'custom_emoji', + 'custom_emoji_id' => 'custom_emoji_123' + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ReactionTypeCustomEmoji $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('custom_emoji', $item->getType()); + $this->assertEquals('custom_emoji_123', $item->getCustomEmojiId()); + } + + /** + * @param ReactionTypeCustomEmoji $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/MessageIdTest.php b/tests/Types/ReactionTypeEmojiTest.php similarity index 58% rename from tests/Types/MessageIdTest.php rename to tests/Types/ReactionTypeEmojiTest.php index 65f1f590..6c192f8e 100644 --- a/tests/Types/MessageIdTest.php +++ b/tests/Types/ReactionTypeEmojiTest.php @@ -3,19 +3,20 @@ namespace TelegramBot\Api\Test\Types; use TelegramBot\Api\Test\AbstractTypeTest; -use TelegramBot\Api\Types\MessageId; +use TelegramBot\Api\Types\ReactionTypeEmoji; -class MessageIdTest extends AbstractTypeTest +class ReactionTypeEmojiTest extends AbstractTypeTest { protected static function getType() { - return MessageId::class; + return ReactionTypeEmoji::class; } public static function getMinResponse() { return [ - 'message_id' => 100, + 'type' => 'emoji', + 'emoji' => '👍' ]; } @@ -25,16 +26,17 @@ public static function getFullResponse() } /** - * @param MessageId $item + * @param ReactionTypeEmoji $item * @return void */ protected function assertMinItem($item) { - $this->assertEquals(100, $item->getMessageId()); + $this->assertEquals('emoji', $item->getType()); + $this->assertEquals('👍', $item->getEmoji()); } /** - * @param MessageId $item + * @param ReactionTypeEmoji $item * @return void */ protected function assertFullItem($item) diff --git a/tests/Types/UpdateTest.php b/tests/Types/UpdateTest.php index 73852b3d..0af8523a 100644 --- a/tests/Types/UpdateTest.php +++ b/tests/Types/UpdateTest.php @@ -38,8 +38,6 @@ public static function getFullResponse() 'pre_checkout_query' => PreCheckoutQueryTest::getMinResponse(), 'poll_answer' => PollAnswerTest::getMinResponse(), 'poll' => PollTest::getMinResponse(), - 'my_chat_member' => ChatMemberUpdatedTest::getMinResponse(), - 'chat_member' => ChatMemberUpdatedTest::getMinResponse(), 'chat_join_request' => ChatJoinRequestTest::getMinResponse(), ]; } @@ -85,8 +83,6 @@ protected function assertFullItem($item) $this->assertEquals(PreCheckoutQueryTest::createMinInstance(), $item->getPreCheckoutQuery()); $this->assertEquals(PollAnswerTest::createMinInstance(), $item->getPollAnswer()); $this->assertEquals(PollTest::createMinInstance(), $item->getPoll()); - $this->assertEquals(ChatMemberUpdatedTest::createMinInstance(), $item->getMyChatMember()); - $this->assertEquals(ChatMemberUpdatedTest::createMinInstance(), $item->getChatMember()); $this->assertEquals(ChatJoinRequestTest::createMinInstance(), $item->getChatJoinRequest()); } } diff --git a/tests/Types/UserTest.php b/tests/Types/UserTest.php index de3b485c..61a29f00 100644 --- a/tests/Types/UserTest.php +++ b/tests/Types/UserTest.php @@ -114,4 +114,74 @@ public function testFromResponseException2() ]); } + public function testSetAndGetFirstName() + { + $item = new User(); + $item->setFirstName('John'); + $this->assertEquals('John', $item->getFirstName()); + } + + public function testSetAndGetLastName() + { + $item = new User(); + $item->setLastName('Doe'); + $this->assertEquals('Doe', $item->getLastName()); + } + + public function testSetAndGetUsername() + { + $item = new User(); + $item->setUsername('johndoe'); + $this->assertEquals('johndoe', $item->getUsername()); + } + + public function testSetAndGetLanguageCode() + { + $item = new User(); + $item->setLanguageCode('en'); + $this->assertEquals('en', $item->getLanguageCode()); + } + + public function testSetAndGetIsBot() + { + $item = new User(); + $item->setIsBot(true); + $this->assertTrue($item->isBot()); + } + + public function testSetAndGetIsPremium() + { + $item = new User(); + $item->setIsPremium(true); + $this->assertTrue($item->getIsPremium()); + } + + public function testSetAndGetAddedToAttachmentMenu() + { + $item = new User(); + $item->setAddedToAttachmentMenu(true); + $this->assertTrue($item->getAddedToAttachmentMenu()); + } + + public function testSetAndGetCanJoinGroups() + { + $item = new User(); + $item->setCanJoinGroups(true); + $this->assertTrue($item->getCanJoinGroups()); + } + + public function testSetAndGetCanReadAllGroupMessages() + { + $item = new User(); + $item->setCanReadAllGroupMessages(true); + $this->assertTrue($item->getCanReadAllGroupMessages()); + } + + public function testSetAndGetSupportsInlineQueries() + { + $item = new User(); + $item->setSupportsInlineQueries(true); + $this->assertTrue($item->getSupportsInlineQueries()); + } + } From c56a42e97697a6beebeb37f890cb23b83e5bb111 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Tue, 9 Jul 2024 15:23:25 +0300 Subject: [PATCH 123/130] Psalm and type fixes --- CHANGELOG.md | 3 +- psalm.xml | 9 ++++++ src/BotApi.php | 7 +++-- src/Http/CurlHttpClient.php | 4 +-- src/Types/CallbackQuery.php | 6 ++-- src/Types/ChatBoostSource.php | 3 ++ src/Types/ChatBoostSourceGiveaway.php | 2 ++ src/Types/ChatMember.php | 6 +--- src/Types/ExternalReplyInfo.php | 40 -------------------------- src/Types/InputMedia/InputMedia.php | 2 ++ src/Types/MaybeInaccessibleMessage.php | 3 ++ src/Types/Message.php | 32 ++++++++++----------- src/Types/MessageOrigin.php | 20 +++++++++++++ src/Types/User.php | 4 +-- tests/Types/UserTest.php | 2 +- 15 files changed, 70 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca400033..3d24ae09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file -## 2.6.0 - YYYY-MM-DD +## 3.0.0 - YYYY-MM-DD - Add `\TelegramBot\Api\Types\Update::$myChatMember` field - Add `\TelegramBot\Api\Types\Update::$chatMember` field - Add `\TelegramBot\Api\Types\Update::$chatJoinRequest` field @@ -15,6 +15,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Add support for local bot API server - Add method `\TelegramBot\Api\BotApi::validateWebAppData` to validate `window.Telegram.WebApp.initData` - Add `\TelegramBot\Api\Types\Message::$videoNote` field +- Drop php < 8.1 ## 2.5.0 - 2023-08-09 diff --git a/psalm.xml b/psalm.xml index 4cfcea27..238ab766 100644 --- a/psalm.xml +++ b/psalm.xml @@ -23,5 +23,14 @@ + + + + + + + + + diff --git a/src/BotApi.php b/src/BotApi.php index e1d472e1..6e5fd307 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -12,6 +12,7 @@ use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\BotCommand; use TelegramBot\Api\Types\Chat; +use TelegramBot\Api\Types\ChatFullInfo; use TelegramBot\Api\Types\ChatInviteLink; use TelegramBot\Api\Types\ChatMember; use TelegramBot\Api\Types\File; @@ -278,7 +279,7 @@ public function downloadFile($fileId) * * Response validation * - * @param resource $curl + * @param \CurlHandle $curl * @param string|false|null $response * * @throws HttpException @@ -2254,12 +2255,12 @@ public function unpinChatMessage($chatId, $messageId = null) * @param string|int $chatId Unique identifier for the target chat or username of the target channel * (in the format @channelusername) * - * @return Chat + * @return ChatFullInfo * @throws Exception */ public function getChat($chatId) { - return Chat::fromResponse($this->call('getChat', [ + return ChatFullInfo::fromResponse($this->call('getChat', [ 'chat_id' => $chatId ])); } diff --git a/src/Http/CurlHttpClient.php b/src/Http/CurlHttpClient.php index 6a8a6e8d..0df69e57 100644 --- a/src/Http/CurlHttpClient.php +++ b/src/Http/CurlHttpClient.php @@ -92,7 +92,7 @@ class CurlHttpClient extends AbstractHttpClient /** * CURL object * - * @var resource + * @var \CurlHandle */ private $curl; @@ -178,7 +178,7 @@ private static function jsonValidate($jsonString) } /** - * @param resource $curl + * @param \CurlHandle $curl * @param string|null $response * @return void * @throws HttpException diff --git a/src/Types/CallbackQuery.php b/src/Types/CallbackQuery.php index f2bbea3f..c3d946b0 100644 --- a/src/Types/CallbackQuery.php +++ b/src/Types/CallbackQuery.php @@ -58,7 +58,7 @@ class CallbackQuery extends BaseType * Note that message content and message date will not be available * if the message is too old * - * @var \TelegramBot\Api\Types\MaybeInaccessibleMessage|null + * @var Message|InaccessibleMessage|null */ protected $message; @@ -129,7 +129,7 @@ public function setFrom(User $from) } /** - * @return MaybeInaccessibleMessage|null + * @return Message|InaccessibleMessage|null */ public function getMessage() { @@ -137,7 +137,7 @@ public function getMessage() } /** - * @param MaybeInaccessibleMessage $message + * @param Message|InaccessibleMessage|null $message * @return void */ public function setMessage($message) diff --git a/src/Types/ChatBoostSource.php b/src/Types/ChatBoostSource.php index bb3a0917..d07c4221 100644 --- a/src/Types/ChatBoostSource.php +++ b/src/Types/ChatBoostSource.php @@ -31,6 +31,9 @@ class ChatBoostSource extends BaseType implements TypeInterface 'user' => User::class, ]; + /** + * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType + */ public static function fromResponse($data) { self::validate($data); diff --git a/src/Types/ChatBoostSourceGiveaway.php b/src/Types/ChatBoostSourceGiveaway.php index 941e45a8..39f00ad6 100644 --- a/src/Types/ChatBoostSourceGiveaway.php +++ b/src/Types/ChatBoostSourceGiveaway.php @@ -54,6 +54,8 @@ public static function fromResponse($data) protected $giveawayMessageId; /** + * @psalm-suppress NonInvariantDocblockPropertyType + * * Optional. User that won the prize in the giveaway if any * * @var User|null diff --git a/src/Types/ChatMember.php b/src/Types/ChatMember.php index f8df0915..5c1f69d2 100644 --- a/src/Types/ChatMember.php +++ b/src/Types/ChatMember.php @@ -16,11 +16,7 @@ abstract class ChatMember extends BaseType implements TypeInterface protected static $requiredParams = ['status', 'user']; /** - * Factory method to create a concrete ChatMember instance - * - * @param array $data - * @return ChatMember - * @throws InvalidArgumentException + * @psalm-suppress MoreSpecificReturnType,LessSpecificImplementedReturnType,LessSpecificReturnStatement */ public static function fromResponse($data) { diff --git a/src/Types/ExternalReplyInfo.php b/src/Types/ExternalReplyInfo.php index 0a760c82..3afe124b 100644 --- a/src/Types/ExternalReplyInfo.php +++ b/src/Types/ExternalReplyInfo.php @@ -604,43 +604,3 @@ public function setVenue($venue) $this->venue = $venue; } } - -/** - * Class ArrayOfPhotoSize - * Represents an array of PhotoSize objects. - * - * @package TelegramBot\Api\Types - */ -class ArrayOfPhotoSize extends BaseType implements TypeInterface -{ - /** - * {@inheritdoc} - * - * @var array - */ - protected static $map = [ - 'photos' => PhotoSize::class, - ]; - - /** - * @var array - */ - protected $photos; - - /** - * @return array - */ - public function getPhotos() - { - return $this->photos; - } - - /** - * @param array $photos - * @return void - */ - public function setPhotos($photos) - { - $this->photos = $photos; - } -} diff --git a/src/Types/InputMedia/InputMedia.php b/src/Types/InputMedia/InputMedia.php index e3f5bb75..e783a273 100644 --- a/src/Types/InputMedia/InputMedia.php +++ b/src/Types/InputMedia/InputMedia.php @@ -17,6 +17,8 @@ class InputMedia extends BaseType implements TypeInterface, CollectionItemInterface { /** + * @psalm-suppress LessSpecificImplementedReturnType + * * Factory method to create an instance of the appropriate InputMedia subclass based on the type. * * @param array $data diff --git a/src/Types/MaybeInaccessibleMessage.php b/src/Types/MaybeInaccessibleMessage.php index 505b07d7..e53b5b91 100644 --- a/src/Types/MaybeInaccessibleMessage.php +++ b/src/Types/MaybeInaccessibleMessage.php @@ -14,6 +14,9 @@ */ class MaybeInaccessibleMessage extends BaseType implements TypeInterface { + /** + * @psalm-suppress MoreSpecificReturnType,LessSpecificReturnStatement + */ public static function fromResponse($data) { self::validate($data); diff --git a/src/Types/Message.php b/src/Types/Message.php index 50377d70..0098262d 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -118,7 +118,7 @@ class Message extends BaseType implements TypeInterface /** * Unique message identifier inside this chat * - * @var int + * @var int|float */ protected $messageId; @@ -287,7 +287,7 @@ class Message extends BaseType implements TypeInterface /** * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text * - * @var \TelegramBot\Api\Types\ArrayOfMessageEntity|null + * @var MessageEntity[]|null */ protected $entities; @@ -330,7 +330,7 @@ class Message extends BaseType implements TypeInterface /** * Optional. Message is a photo, available sizes of the photo * - * @var \TelegramBot\Api\Types\ArrayOfPhotoSize|null + * @var PhotoSize[]|null */ protected $photo; @@ -379,7 +379,7 @@ class Message extends BaseType implements TypeInterface /** * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption * - * @var \TelegramBot\Api\Types\ArrayOfMessageEntity|null + * @var MessageEntity[]|null */ protected $captionEntities; @@ -444,7 +444,7 @@ class Message extends BaseType implements TypeInterface * Optional. New members that were added to the group or supergroup and information about them * (the bot itself may be one of these members) * - * @var \TelegramBot\Api\Types\ArrayOfUser|null + * @var User[]|null */ protected $newChatMembers; @@ -465,7 +465,7 @@ class Message extends BaseType implements TypeInterface /** * Optional. A chat photo was change to this value * - * @var \TelegramBot\Api\Types\ArrayOfPhotoSize|null + * @var PhotoSize[]|null */ protected $newChatPhoto; @@ -531,7 +531,7 @@ class Message extends BaseType implements TypeInterface /** * Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. * - * @var \TelegramBot\Api\Types\MaybeInaccessibleMessage|null + * @var Message|InaccessibleMessage|null */ protected $pinnedMessage; @@ -578,12 +578,12 @@ class Message extends BaseType implements TypeInterface */ protected $writeAccessAllowed; - /** - * Optional. Telegram Passport data - * - * @var \TelegramBot\Api\Types\PassportData|null - */ - protected $passportData; + // /** + // * Optional. Telegram Passport data + // * + // * @var \TelegramBot\Api\Types\PassportData|null + // */ + // protected $passportData; /** * Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live Location @@ -719,7 +719,7 @@ class Message extends BaseType implements TypeInterface protected $replyMarkup; /** - * @return int + * @return int|float */ public function getMessageId() { @@ -1311,7 +1311,7 @@ public function setCaption($caption) } /** - * @return ArrayOfMessageEntity|null + * @return MessageEntity[]|null */ public function getCaptionEntities() { @@ -1319,7 +1319,7 @@ public function getCaptionEntities() } /** - * @param ArrayOfMessageEntity|null $captionEntities + * @param MessageEntity[]|null $captionEntities */ public function setCaptionEntities($captionEntities) { diff --git a/src/Types/MessageOrigin.php b/src/Types/MessageOrigin.php index 394bfce3..c7daa670 100644 --- a/src/Types/MessageOrigin.php +++ b/src/Types/MessageOrigin.php @@ -23,6 +23,26 @@ class MessageOrigin extends BaseType implements TypeInterface protected $type; protected $date; + /** + * @psalm-suppress MoreSpecificReturnType,LessSpecificReturnStatement + */ + public static function fromResponse($data) + { + self::validate($data); + $class = match ($data['type']) { + 'user' => MessageOriginUser::class, + 'hidden_user' => MessageOriginHiddenUser::class, + 'chat' => MessageOriginChat::class, + 'channel' => MessageOriginChannel::class, + default => MessageOrigin::class + }; + + $instance = new $class(); + $instance->map($data); + + return $instance; + } + public function getType() { return $this->type; diff --git a/src/Types/User.php b/src/Types/User.php index cd8faa72..0ea3ea55 100644 --- a/src/Types/User.php +++ b/src/Types/User.php @@ -125,7 +125,7 @@ class User extends BaseType implements TypeInterface */ protected $canConnectToBusiness; - public function getId(): int + public function getId(): int|float { return $this->id; } @@ -180,7 +180,7 @@ public function setLanguageCode($languageCode): void public function isBot(): bool { - return $this->isBot; + return (bool) $this->isBot; } public function setIsBot($isBot): void diff --git a/tests/Types/UserTest.php b/tests/Types/UserTest.php index 61a29f00..d024c374 100644 --- a/tests/Types/UserTest.php +++ b/tests/Types/UserTest.php @@ -55,7 +55,7 @@ protected function assertMinItem($item) $this->assertNull($item->getCanJoinGroups()); $this->assertNull($item->getCanReadAllGroupMessages()); $this->assertNull($item->getSupportsInlineQueries()); - $this->assertNull($item->isBot()); + $this->assertFalse($item->isBot()); } /** From ae151c2e2020468e89a7f7d6ecf3a7a637b5ab45 Mon Sep 17 00:00:00 2001 From: Bernard Ngandu <31113941+bernard-ng@users.noreply.github.com> Date: Sat, 3 Aug 2024 04:45:03 +0200 Subject: [PATCH 124/130] #465 add full support for bot api 7.0 (#480) * feat: #465 add full reactions support as defined in api 7.0 * feat: #465 add Link Preview Customization support as defined in api 7.0 * feat: #465 add Multiple Message Actions support as defined in api 7.0 * feat: #465 add Chat Boost as defined in api 7.0 * feat: #465 add Giveaway as defined in api 7.0 --- CHANGELOG.md | 11 + src/BaseType.php | 3 +- src/BotApi.php | 516 ++++++++++++++++-- src/Types/ArrayOfReactionType.php | 2 +- src/Types/GiveawayCreated.php | 5 + src/Types/Inline/InputMessageContent/Text.php | 44 +- src/Types/Update.php | 107 ++++ tests/Types/ArrayOfChatTest.php | 39 ++ tests/Types/ArrayOfReactionTypeTest.php | 40 ++ tests/Types/ChatBoostRemovedTest.php | 50 ++ tests/Types/ChatBoostSourceTest.php | 42 ++ tests/Types/ChatBoostTest.php | 50 ++ tests/Types/ChatBoostUpdatedTest.php | 42 ++ tests/Types/GiveawayCompletedTest.php | 42 ++ tests/Types/GiveawayCreatedTest.php | 32 ++ tests/Types/GiveawayTest.php | 66 +++ tests/Types/GiveawayWinnersTest.php | 74 +++ .../Types/MessageReactionCountUpdatedTest.php | 54 ++ tests/Types/MessageReactionUpdatedTest.php | 68 +++ tests/Types/UpdateTest.php | 12 + 20 files changed, 1242 insertions(+), 57 deletions(-) create mode 100644 tests/Types/ArrayOfChatTest.php create mode 100644 tests/Types/ArrayOfReactionTypeTest.php create mode 100644 tests/Types/ChatBoostRemovedTest.php create mode 100644 tests/Types/ChatBoostSourceTest.php create mode 100644 tests/Types/ChatBoostTest.php create mode 100644 tests/Types/ChatBoostUpdatedTest.php create mode 100644 tests/Types/GiveawayCompletedTest.php create mode 100644 tests/Types/GiveawayCreatedTest.php create mode 100644 tests/Types/GiveawayTest.php create mode 100644 tests/Types/GiveawayWinnersTest.php create mode 100644 tests/Types/MessageReactionCountUpdatedTest.php create mode 100644 tests/Types/MessageReactionUpdatedTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d24ae09..60817072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,17 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file - Add method `\TelegramBot\Api\BotApi::validateWebAppData` to validate `window.Telegram.WebApp.initData` - Add `\TelegramBot\Api\Types\Message::$videoNote` field - Drop php < 8.1 +- Add `\TelegramBot\Api\Types\Update::$messageReaction` field +- Add `\TelegramBot\Api\Types\Update::$messageReactionCount` field +- Add `\TelegramBot\Api\BotApi::setMessageReaction` api method +- Add `\TelegramBot\Api\BotApi::deleteMessages` api method +- Add `\TelegramBot\Api\BotApi::copyMessages` api method +- Add `\TelegramBot\Api\BotApi::forwardMessages` api method +- Add `\TelegramBot\Api\BotApi::getUserChatBoosts` api method + +### Deprecated +- Deprecate `reply_to_message_id` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods. Use `reply_parameters` instead. +- Deprecate `disable_web_page_preview` parameter to `\TelegramBot\Api\BotApi` methods. Use `link_preview_options` instead. ## 2.5.0 - 2023-08-09 diff --git a/src/BaseType.php b/src/BaseType.php index f02e0eca..f7f2f9ee 100644 --- a/src/BaseType.php +++ b/src/BaseType.php @@ -39,7 +39,8 @@ public static function validate($data) return true; } - throw new InvalidArgumentException(); + $missingParams = implode(', ', array_diff(static::$requiredParams, array_keys($data))); + throw new InvalidArgumentException(sprintf('%s Validation failed. Missing required parameters: %s', static::class, $missingParams)); } /** diff --git a/src/BotApi.php b/src/BotApi.php index 6e5fd307..ef9ddccd 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -3,8 +3,12 @@ namespace TelegramBot\Api; use TelegramBot\Api\Http\CurlHttpClient; +use TelegramBot\Api\Types\UserChatBoosts; +use TelegramBot\Api\Types\ReplyParameters; use TelegramBot\Api\Http\HttpClientInterface; use TelegramBot\Api\Types\ArrayOfBotCommand; +use TelegramBot\Api\Types\LinkPreviewOptions; +use TelegramBot\Api\Types\ArrayOfReactionType; use TelegramBot\Api\Types\ArrayOfChatMemberEntity; use TelegramBot\Api\Types\ArrayOfMessageEntity; use TelegramBot\Api\Types\ArrayOfMessages; @@ -337,6 +341,8 @@ public static function jsonValidate($jsonString, $asArray) * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * @param LinkPreviewOptions|null $linkPreviewOptions Link preview generation options for the message. * * @return Message * @throws InvalidArgumentException @@ -352,19 +358,42 @@ public function sendMessage( $disableNotification = false, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $replyParameters = null, + $linkPreviewOptions = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + if (null === $linkPreviewOptions && false !== $disablePreview) { + @trigger_error('setting $disablePreview is now deprecated use $linkPreviewOptions instead', E_USER_DEPRECATED); + + $linkPreviewOptions = new LinkPreviewOptions(); + $linkPreviewOptions->map([ + 'is_disabled' => $disablePreview + ]); + } + return Message::fromResponse($this->call('sendMessage', [ 'chat_id' => $chatId, 'text' => $text, 'message_thread_id' => $messageThreadId, 'parse_mode' => $parseMode, - 'disable_web_page_preview' => $disablePreview, - 'reply_to_message_id' => (int) $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson(), + 'link_preview_options' => is_null($linkPreviewOptions) ? $linkPreviewOptions : $linkPreviewOptions->toJson() ])); } @@ -381,6 +410,7 @@ public function sendMessage( * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param int|null $messageThreadId * @param bool|null $protectContent + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return MessageId * @throws Exception @@ -399,8 +429,22 @@ public function copyMessage( $allowSendingWithoutReply = false, $replyMarkup = null, $messageThreadId = null, - $protectContent = null + $protectContent = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return MessageId::fromResponse($this->call('copyMessage', [ 'chat_id' => $chatId, 'from_chat_id' => $fromChatId, @@ -410,10 +454,9 @@ public function copyMessage( 'caption_entities' => $captionEntities, 'disable_notification' => (bool) $disableNotification, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => (int) $replyToMessageId, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -430,6 +473,7 @@ public function copyMessage( * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws Exception @@ -444,19 +488,32 @@ public function sendContact( $disableNotification = false, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendContact', [ 'chat_id' => $chatId, 'phone_number' => $phoneNumber, 'first_name' => $firstName, 'last_name' => $lastName, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -636,6 +693,7 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @@ -651,19 +709,32 @@ public function sendLocation( $livePeriod = null, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendLocation', [ 'chat_id' => $chatId, 'latitude' => $latitude, 'longitude' => $longitude, 'live_period' => $livePeriod, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -753,6 +824,7 @@ public function stopMessageLiveLocation( * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws Exception @@ -769,8 +841,22 @@ public function sendVenue( $disableNotification = false, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendVenue', [ 'chat_id' => $chatId, 'latitude' => $latitude, @@ -779,11 +865,10 @@ public function sendVenue( 'address' => $address, 'foursquare_id' => $foursquareId, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -798,6 +883,7 @@ public function sendVenue( * @param bool $protectContent Protects the contents of the sent message from forwarding and saving * @param bool $allowSendingWithoutReply Pass True if the message should be sent even if the specified replied-to message is not found * @param string|null $messageThreadId + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws InvalidArgumentException @@ -811,17 +897,30 @@ public function sendSticker( $disableNotification = false, $protectContent = false, $allowSendingWithoutReply = false, - $messageThreadId = null + $messageThreadId = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendSticker', [ 'chat_id' => $chatId, 'sticker' => $sticker, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -1060,6 +1159,7 @@ public function setStickerSetThumb($name, $userId, $thumb = null) * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws InvalidArgumentException @@ -1078,22 +1178,35 @@ public function sendVideo( $messageThreadId = null, $protectContent = null, $allowSendingWithoutReply = null, - $thumbnail = null + $thumbnail = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendVideo', [ 'chat_id' => $chatId, 'video' => $video, 'duration' => $duration, 'caption' => $caption, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'supports_streaming' => (bool) $supportsStreaming, 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -1114,6 +1227,7 @@ public function sendVideo( * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws InvalidArgumentException @@ -1131,21 +1245,34 @@ public function sendAnimation( $messageThreadId = null, $protectContent = null, $allowSendingWithoutReply = null, - $thumbnail = null + $thumbnail = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendAnimation', [ 'chat_id' => $chatId, 'animation' => $animation, 'duration' => $duration, 'caption' => $caption, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -1169,6 +1296,7 @@ public function sendAnimation( * @param string|null $parseMode * @param int|null $messageThreadId * @param bool|null $protectContent + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws InvalidArgumentException @@ -1185,20 +1313,33 @@ public function sendVoice( $allowSendingWithoutReply = false, $parseMode = null, $messageThreadId = null, - $protectContent = null + $protectContent = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendVoice', [ 'chat_id' => $chatId, 'voice' => $voice, 'caption' => $caption, 'duration' => $duration, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, - 'allow_sending_without_reply' => $allowSendingWithoutReply, 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -1260,6 +1401,7 @@ public function forwardMessage( * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws InvalidArgumentException @@ -1281,21 +1423,34 @@ public function sendAudio( $parseMode = null, $protectContent = null, $allowSendingWithoutReply = null, - $thumbnail = null + $thumbnail = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendAudio', [ 'chat_id' => $chatId, 'audio' => $audio, 'duration' => $duration, 'performer' => $performer, 'title' => $title, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -1312,6 +1467,7 @@ public function sendAudio( * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws InvalidArgumentException @@ -1327,19 +1483,32 @@ public function sendPhoto( $parseMode = null, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendPhoto', [ 'chat_id' => $chatId, 'photo' => $photo, 'caption' => $caption, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -1358,6 +1527,7 @@ public function sendPhoto( * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws InvalidArgumentException @@ -1374,20 +1544,33 @@ public function sendDocument( $messageThreadId = null, $protectContent = null, $allowSendingWithoutReply = null, - $thumbnail = null + $thumbnail = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendDocument', [ 'chat_id' => $chatId, 'document' => $document, 'caption' => $caption, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'parse_mode' => $parseMode, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -1612,6 +1795,7 @@ public function getMyCommands() * @param string|null $parseMode * @param bool $disablePreview * @param InlineKeyboardMarkup|null $replyMarkup + * @param LinkPreviewOptions|null $linkPreviewOptions Link preview generation options for the message. * * @return Message|true * @throws Exception @@ -1623,8 +1807,18 @@ public function editMessageText( $parseMode = null, $disablePreview = false, $replyMarkup = null, - $inlineMessageId = null + $inlineMessageId = null, + $linkPreviewOptions = null ) { + if (null === $linkPreviewOptions && false !== $disablePreview) { + @trigger_error('setting $disablePreview is now deprecated use $linkPreviewOptions instead', E_USER_DEPRECATED); + + $linkPreviewOptions = new LinkPreviewOptions(); + $linkPreviewOptions->map([ + 'is_disabled' => $disablePreview + ]); + } + $response = $this->call('editMessageText', [ 'chat_id' => $chatId, 'message_id' => $messageId, @@ -1804,6 +1998,7 @@ public function deleteMessage($chatId, $messageId) * @param int|null $messageThreadId * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws Exception @@ -1834,8 +2029,22 @@ public function sendInvoice( $sendEmailToProvider = false, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendInvoice', [ 'chat_id' => $chatId, 'title' => $title, @@ -1855,14 +2064,13 @@ public function sendInvoice( 'need_email' => $needEmail, 'need_shipping_address' => $needShippingAddress, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'provider_data' => $providerData, 'send_phone_number_to_provider' => (bool) $sendPhoneNumberToProvider, 'send_email_to_provider' => (bool) $sendEmailToProvider, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -2371,6 +2579,7 @@ public function getChatAdministrators($chatId) * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws InvalidArgumentException @@ -2387,20 +2596,33 @@ public function sendVideoNote( $messageThreadId = null, $protectContent = null, $allowSendingWithoutReply = null, - $thumbnail = null + $thumbnail = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendVideoNote', [ 'chat_id' => $chatId, 'video_note' => $videoNote, 'duration' => $duration, 'length' => $length, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -2416,6 +2638,7 @@ public function sendVideoNote( * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply * @param array $attachments Attachments to use in attach:// + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message[] * @throws Exception @@ -2428,16 +2651,29 @@ public function sendMediaGroup( $messageThreadId = null, $protectContent = null, $allowSendingWithoutReply = null, - $attachments = [] + $attachments = [], + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return ArrayOfMessages::fromResponse($this->call('sendMediaGroup', [ 'chat_id' => $chatId, 'media' => $media->toJson(), 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => (int) $replyToMessageId, 'disable_notification' => (bool) $disableNotification, 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ] + $attachments)); } @@ -2463,6 +2699,7 @@ public function sendMediaGroup( * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only * @param bool|null $protectContent * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws Exception @@ -2483,8 +2720,22 @@ public function sendPoll( $replyMarkup = null, $messageThreadId = null, $protectContent = null, - $allowSendingWithoutReply = null + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendPoll', [ 'chat_id' => $chatId, 'question' => $question, @@ -2496,10 +2747,9 @@ public function sendPoll( 'is_closed' => (bool) $isClosed, 'disable_notification' => (bool) $disableNotification, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => (int) $replyToMessageId, 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), 'protect_content' => (bool) $protectContent, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -2522,6 +2772,7 @@ public function sendPoll( * keyboard or to force a reply from the user. * @param int|null $messageThreadId * @param bool|null $protectContent + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message * @throws Exception @@ -2536,17 +2787,30 @@ public function sendDice( $allowSendingWithoutReply = false, $replyMarkup = null, $messageThreadId = null, - $protectContent = null + $protectContent = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendDice', [ 'chat_id' => $chatId, 'emoji' => $emoji, 'disable_notification' => (bool) $disableNotification, 'message_thread_id' => $messageThreadId, - 'reply_to_message_id' => (int) $replyToMessageId, - 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply, 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -2771,6 +3035,152 @@ public function setProxy($proxyString = '', $socks5 = false) return $this; } + /** + * Use this method to change the chosen reactions on a message. + * Service messages can't be reacted to. + * Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $messageId Identifier of the target message. + * @param ArrayOfReactionType $reaction A list of reaction types to set on the message. + * @param bool $isBig Pass `true` to set the reaction with a big animation + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function setMessageReaction($chatId, $messageId, $reaction, $isBig = false) + { + return $this->call('setMessageReaction', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'reaction' => $reaction, + 'is_big' => $isBig + ]); + } + + /** + * Use this method to delete multiple messages simultaneously. + * If some of the specified messages can't be found, they are skipped. + * Returns True on success. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int[] $messageIds A JSON-serialized list of 1-100 identifiers of messages to delete. See deleteMessage for limitations on which messages can be deleted + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function deleteMessages($chatId, $messageIds) + { + return $this->call('deleteMessages', [ + 'chat_id' => $chatId, + 'message_ids' => $messageIds + ]); + } + + /** + * Use this method to forward multiple messages of any kind. + * If some of the specified messages can't be found or forwarded, they are skipped. + * Service messages and messages with protected content can't be forwarded. + * Album grouping is kept for forwarded messages. + * On success, an array of MessageId of the sent messages is returned. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param string|int $fromChatId Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) + * @param int[] $messageIds A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order. + * @param bool $disableNotification Sends the messages silently. Users will receive a notification with no sound. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool $protectContent Protects the contents of the forwarded messages from forwarding and saving + * + * @return int[] + * @throws Exception + * + * @author bernard-ng + */ + public function forwardMessages( + $chatId, + $fromChatId, + $messageIds, + $messageThreadId = null, + $disableNotification = false, + $protectContent = false + ) { + return $this->call('forwardMessages', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_ids' => $messageIds, + 'message_thread_id' => $messageThreadId, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent + ]); + } + + /** + * Use this method to copy messages of any kind. + * If some of the specified messages can't be found or copied, they are skipped. + * Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied + * + * A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. + * The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. + * + * On success, an array of MessageId of the sent messages is returned. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param string|int $fromChatId Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) + * @param int[] $messageIds A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool $disableNotification Sends the messages silently. Users will receive a notification with no sound. + * @param bool $protectContent Protects the contents of the copied messages from forwarding and saving + * @param bool $removeCaption Pass True to copy the messages without their captions + * + * @return int[] + * @throws Exception + * + * @author bernard-ng + */ + public function copyMessages( + $chatId, + $fromChatId, + $messageIds, + $messageThreadId, + $disableNotification = false, + $protectContent = false, + $removeCaption = false + ) { + return $this->call('copyMessages', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_ids' => $messageIds, + 'message_thread_id' => $messageThreadId, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'remove_caption' => (bool) $removeCaption + ]); + } + + /** + * Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. + * Returns a UserChatBoosts object. + * + * @param string|int $chatId Unique identifier for the chat or username of the channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * + * @return UserChatBoosts + * @throws Exception + * + * @author bernard-ng + */ + public function getUserChatBoosts($chatId, $userId) + { + return UserChatBoosts::fromResponse($this->call('getUserChatBoosts', [ + 'chat_id' => $chatId, + 'user_id' => $userId + ])); + } + /** * Set an option for a cURL transfer * diff --git a/src/Types/ArrayOfReactionType.php b/src/Types/ArrayOfReactionType.php index afc13ecd..48fc3177 100644 --- a/src/Types/ArrayOfReactionType.php +++ b/src/Types/ArrayOfReactionType.php @@ -15,7 +15,7 @@ public static function fromResponse($data) { $arrayOfReactionTypes = []; foreach ($data as $reactionTypeData) { - // В зависимости от типа реакции, создаем соответствующий объект + // Depending on the type of reaction, create an appropriate object if ($reactionTypeData['type'] === 'emoji') { $arrayOfReactionTypes[] = ReactionTypeEmoji::fromResponse($reactionTypeData); } elseif ($reactionTypeData['type'] === 'custom_emoji') { diff --git a/src/Types/GiveawayCreated.php b/src/Types/GiveawayCreated.php index 61bb8cf8..cd50ea4d 100644 --- a/src/Types/GiveawayCreated.php +++ b/src/Types/GiveawayCreated.php @@ -5,6 +5,11 @@ use TelegramBot\Api\BaseType; use TelegramBot\Api\TypeInterface; +/** + * Class GiveawayCreated. + * This object represents a service message about the creation of a scheduled giveaway. + * Currently holds no information. + */ class GiveawayCreated extends BaseType implements TypeInterface { } diff --git a/src/Types/Inline/InputMessageContent/Text.php b/src/Types/Inline/InputMessageContent/Text.php index bc725828..fafc89fe 100644 --- a/src/Types/Inline/InputMessageContent/Text.php +++ b/src/Types/Inline/InputMessageContent/Text.php @@ -9,6 +9,8 @@ namespace TelegramBot\Api\Types\Inline\InputMessageContent; use TelegramBot\Api\TypeInterface; +use TelegramBot\Api\Types\LinkPreviewOptions; +use TelegramBot\Api\Types\ArrayOfMessageEntity; use TelegramBot\Api\Types\Inline\InputMessageContent; /** @@ -35,7 +37,9 @@ class Text extends InputMessageContent implements TypeInterface protected static $map = [ 'message_text' => true, 'parse_mode' => true, - 'disable_web_page_preview' => true, + 'entities' => ArrayOfMessageEntity::class, + 'disable_web_page_preview' => true, // @todo: remove as deprecated with bot api 7.0 + 'link_preview_options' => LinkPreviewOptions::class ]; /** @@ -54,23 +58,42 @@ class Text extends InputMessageContent implements TypeInterface protected $parseMode; /** + * @deprecated use $linkPreviewOptions instead * Optional. Disables link previews for links in the sent message * * @var bool|null */ protected $disableWebPagePreview; + /** + * Link preview generation options for the message + * + * @var LinkPreviewOptions|null + */ + protected $linkPreviewOptions; + /** * Text constructor. + * * @param string $messageText * @param string|null $parseMode * @param bool $disableWebPagePreview + * @param LinkPreviewOptions|null $linkPreviewOptions Link preview generation options for the message. */ - public function __construct($messageText, $parseMode = null, $disableWebPagePreview = false) + public function __construct($messageText, $parseMode = null, $disableWebPagePreview = false, $linkPreviewOptions = null) { $this->messageText = $messageText; $this->parseMode = $parseMode; $this->disableWebPagePreview = $disableWebPagePreview; + + if (null === $linkPreviewOptions && false !== $disableWebPagePreview) { + @trigger_error('setting $disableWebPagePreview is now deprecated use $linkPreviewOptions instead', E_USER_DEPRECATED); + + $this->linkPreviewOptions = new LinkPreviewOptions(); + $this->linkPreviewOptions->map([ + 'is_disabled' => $disableWebPagePreview + ]); + } } /** @@ -126,4 +149,21 @@ public function setDisableWebPagePreview($disableWebPagePreview) { $this->disableWebPagePreview = $disableWebPagePreview; } + + /** + * @return LinkPreviewOptions|null + */ + public function getLinkPreviewOptions() + { + return $this->linkPreviewOptions; + } + + /** + * @param LinkPreviewOptions|null $linkPreviewOptions + * @return void + */ + public function setLinkPreviewOptions($linkPreviewOptions) + { + $this->linkPreviewOptions = $linkPreviewOptions; + } } diff --git a/src/Types/Update.php b/src/Types/Update.php index 4138ed07..5ad03a9c 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -46,6 +46,10 @@ class Update extends BaseType implements TypeInterface 'my_chat_member' => ChatMemberUpdated::class, 'chat_member' => ChatMemberUpdated::class, 'chat_join_request' => ChatJoinRequest::class, + 'message_reaction' => MessageReactionUpdated::class, + 'message_reaction_count' => MessageReactionCountUpdated::class, + 'chat_boost' => ChatBoostUpdated::class, + 'chat_boost_removed' => ChatBoostRemoved::class, ]; /** @@ -159,6 +163,41 @@ class Update extends BaseType implements TypeInterface */ protected $chatJoinRequest; + /** + * Optional. A reaction to a message was changed by a user. + * The bot must be an administrator in the chat and must explicitly specify 'message_reaction' + * in the list of allowed_updates to receive these updates. The update isn't received for reactions set by bots. + * + * @var MessageReactionUpdated|null + */ + protected $messageReaction; + + /** + * Optional. Reactions to a message with anonymous reactions were changed. + * The bot must be an administrator in the chat and must explicitly specify 'message_reaction_count' + * in the list of allowed_updates to receive these updates. + * The updates are grouped and can be sent with delay up to a few minutes. + * + * @var MessageReactionCountUpdated|null + */ + protected $messageReactionCount; + + /** + * Optional. A chat boost was added or changed. + * The bot must be an administrator in the chat to receive these updates. + * + * @var ChatBoostUpdated|null + */ + protected $chatBoost; + + /** + * Optional. A boost was removed from a chat. + * The bot must be an administrator in the chat to receive these updates. + * + * @var ChatBoostRemoved|null + */ + protected $removedChatBoost; + /** * @return int */ @@ -433,4 +472,72 @@ public function setChatJoinRequest($chatJoinRequest) { $this->chatJoinRequest = $chatJoinRequest; } + + /** + * @return MessageReactionUpdated|null + */ + public function getMessageReaction() + { + return $this->messageReaction; + } + + /** + * @param MessageReactionUpdated|null $messageReaction + * @return void + */ + public function setMessageReaction(?MessageReactionUpdated $messageReaction) + { + $this->messageReaction = $messageReaction; + } + + /** + * @return MessageReactionCountUpdated|null + */ + public function getMessageReactionCount() + { + return $this->messageReactionCount; + } + + /** + * @param MessageReactionCountUpdated|null $messageReactionCount + * @return void + */ + public function setMessageReactionCount(?MessageReactionCountUpdated $messageReactionCount) + { + $this->messageReactionCount = $messageReactionCount; + } + + /** + * @return ChatBoostUpdated|null + */ + public function getChatBoost() + { + return $this->chatBoost; + } + + /** + * @param ChatBoostUpdated|null $chatBoost + * @return void + */ + public function setChatBoost($chatBoost) + { + $this->chatBoost = $chatBoost; + } + + /** + * @return ChatBoostRemoved|null + */ + public function getChatBoostRemoved() + { + return $this->removedChatBoost; + } + + /** + * @param ChatBoostRemoved|null $removedChatBoost + * @return void + */ + public function setChatBoostRemoved($removedChatBoost) + { + $this->removedChatBoost = $removedChatBoost; + } } diff --git a/tests/Types/ArrayOfChatTest.php b/tests/Types/ArrayOfChatTest.php new file mode 100644 index 00000000..94776250 --- /dev/null +++ b/tests/Types/ArrayOfChatTest.php @@ -0,0 +1,39 @@ + 123456789, + 'type' => 'group', + ], + [ + 'id' => 123456788, + 'type' => 'private', + ] + ]); + + $expected = [ + Chat::fromResponse([ + 'id' => 123456789, + 'type' => 'group', + ]), + Chat::fromResponse([ + 'id' => 123456788, + 'type' => 'private', + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfReactionTypeTest.php b/tests/Types/ArrayOfReactionTypeTest.php new file mode 100644 index 00000000..47fff3e8 --- /dev/null +++ b/tests/Types/ArrayOfReactionTypeTest.php @@ -0,0 +1,40 @@ + '👍', + 'type' => 'emoji' + ], + [ + 'custom_emoji_id' => 'custom_emoji_123', + 'type' => 'custom_emoji' + ] + ]); + + $expected = [ + ReactionTypeEmoji::fromResponse([ + 'emoji' => '👍', + 'type' => 'emoji' + ]), + ReactionTypeCustomEmoji::fromResponse([ + 'custom_emoji_id' => 'custom_emoji_123', + 'type' => 'custom_emoji' + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ChatBoostRemovedTest.php b/tests/Types/ChatBoostRemovedTest.php new file mode 100644 index 00000000..1fb18e80 --- /dev/null +++ b/tests/Types/ChatBoostRemovedTest.php @@ -0,0 +1,50 @@ + ChatTest::getMinResponse(), + 'boost_id' => 1, + 'remove_date' => 1682343643, + 'source' => ChatBoostSourceTest::getMinResponse() + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'boost_id' => 1, + 'remove_date' => 1682343643, + 'source' => ChatBoostSourceTest::getMinResponse() + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getBoostId()); + $this->assertEquals(1682343643, $item->getRemoveDate()); + $this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getBoostId()); + $this->assertEquals(1682343643, $item->getRemoveDate()); + $this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource()); + } +} diff --git a/tests/Types/ChatBoostSourceTest.php b/tests/Types/ChatBoostSourceTest.php new file mode 100644 index 00000000..35e21646 --- /dev/null +++ b/tests/Types/ChatBoostSourceTest.php @@ -0,0 +1,42 @@ + 'premium', + 'user' => UserTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'source' => 'premium', + 'user' => UserTest::getMinResponse(), + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('premium', $item->getSource()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('premium', $item->getSource()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + } +} diff --git a/tests/Types/ChatBoostTest.php b/tests/Types/ChatBoostTest.php new file mode 100644 index 00000000..2a8fa88f --- /dev/null +++ b/tests/Types/ChatBoostTest.php @@ -0,0 +1,50 @@ + 1, + 'add_date' => 1682343643, + 'expiration_date' => 1725042370, + 'source' => ChatBoostSourceTest::getMinResponse() + ]; + } + + public static function getFullResponse() + { + return [ + 'boost_id' => 1, + 'add_date' => 1682343643, + 'expiration_date' => 1725042370, + 'source' => ChatBoostSourceTest::getMinResponse() + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getBoostId()); + $this->assertEquals(1682343643, $item->getAddDate()); + $this->assertEquals(1725042370, $item->getExpirationDate()); + $this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getBoostId()); + $this->assertEquals(1682343643, $item->getAddDate()); + $this->assertEquals(1725042370, $item->getExpirationDate()); + $this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource()); + } +} diff --git a/tests/Types/ChatBoostUpdatedTest.php b/tests/Types/ChatBoostUpdatedTest.php new file mode 100644 index 00000000..1dc8bb74 --- /dev/null +++ b/tests/Types/ChatBoostUpdatedTest.php @@ -0,0 +1,42 @@ + ChatTest::getMinResponse(), + 'boost' => ChatBoostTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'boost' => ChatBoostTest::getMinResponse(), + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(ChatBoostTest::createMinInstance(), $item->getBoost()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(ChatBoostTest::createMinInstance(), $item->getBoost()); + } +} diff --git a/tests/Types/GiveawayCompletedTest.php b/tests/Types/GiveawayCompletedTest.php new file mode 100644 index 00000000..633b6127 --- /dev/null +++ b/tests/Types/GiveawayCompletedTest.php @@ -0,0 +1,42 @@ + 1 + ]; + } + + public static function getFullResponse() + { + return [ + 'winner_count' => 1, + 'unclaimed_prize_count' => 1, + 'giveaway_message' => MessageTest::getMinResponse() + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getWinnerCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals(1, $item->getUnclaimedPrizeCount()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getGiveawayMessage()); + } +} diff --git a/tests/Types/GiveawayCreatedTest.php b/tests/Types/GiveawayCreatedTest.php new file mode 100644 index 00000000..90e948ff --- /dev/null +++ b/tests/Types/GiveawayCreatedTest.php @@ -0,0 +1,32 @@ + [ + ChatTest::getMinResponse() + ], + 'winners_selection_date' => 1682343643, + 'winner_count' => 1, + ]; + } + + public static function getFullResponse() + { + return [ + 'chats' => [ + ChatTest::getMinResponse() + ], + 'winners_selection_date' => 1682343643, + 'winner_count' => 1, + 'only_new_members' => true, + 'has_public_winners' => true, + 'prize_description' => 'prize', + 'country_codes' => ['RU'], + 'premium_subscription_month_count' => 1, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals(1682343643, $item->getWinnersSelectionDate()); + $this->assertIsArray($item->getChats()); + + $this->assertNull($item->getOnlyNewMembers()); + $this->assertNull($item->getHasPublicWinners()); + $this->assertNull($item->getPrizeDescription()); + $this->assertNull($item->getCountryCodes()); + $this->assertNull($item->getPremiumSubscriptionMonthCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals(1682343643, $item->getWinnersSelectionDate()); + $this->assertIsArray($item->getChats()); + $this->assertTrue($item->getOnlyNewMembers()); + $this->assertTrue($item->getHasPublicWinners()); + $this->assertEquals('prize', $item->getPrizeDescription()); + $this->assertIsArray($item->getCountryCodes()); + $this->assertEquals(1, $item->getPremiumSubscriptionMonthCount()); + } +} diff --git a/tests/Types/GiveawayWinnersTest.php b/tests/Types/GiveawayWinnersTest.php new file mode 100644 index 00000000..aac8e408 --- /dev/null +++ b/tests/Types/GiveawayWinnersTest.php @@ -0,0 +1,74 @@ + ChatTest::getMinResponse(), + 'giveaway_message_id' => 1, + 'winners_selection_date' => 1682343643, + 'winner_count' => 1, + 'winners' => [ + UserTest::getMinResponse() + ], + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'giveaway_message_id' => 1, + 'winners_selection_date' => 1682343643, + 'winner_count' => 1, + 'winners' => [ + UserTest::getMinResponse() + ], + 'additional_chat_count' => 1, + 'premium_subscription_month_count' => 1, + 'unclaimed_prize_count' => 0, + 'only_new_members' => true, + 'was_refunded' => true, + 'prize_description' => 'prize', + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getGiveawayMessageId()); + $this->assertEquals(1682343643, $item->getWinnersSelectionDate()); + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals([UserTest::createMinInstance()], $item->getWinners()); + $this->assertNull($item->getAdditionalChatCount()); + $this->assertNull($item->getPremiumSubscriptionMonthCount()); + $this->assertNull($item->getUnclaimedPrizeCount()); + $this->assertNull($item->getOnlyNewMembers()); + $this->assertNull($item->getWasRefunded()); + $this->assertNull($item->getPrizeDescription()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getGiveawayMessageId()); + $this->assertEquals(1682343643, $item->getWinnersSelectionDate()); + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals([UserTest::createMinInstance()], $item->getWinners()); + $this->assertEquals(1, $item->getAdditionalChatCount()); + $this->assertEquals(1, $item->getPremiumSubscriptionMonthCount()); + $this->assertEquals(0, $item->getUnclaimedPrizeCount()); + $this->assertTrue($item->getOnlyNewMembers()); + $this->assertTrue($item->getWasRefunded()); + $this->assertEquals('prize', $item->getPrizeDescription()); + } +} diff --git a/tests/Types/MessageReactionCountUpdatedTest.php b/tests/Types/MessageReactionCountUpdatedTest.php new file mode 100644 index 00000000..5216c7ed --- /dev/null +++ b/tests/Types/MessageReactionCountUpdatedTest.php @@ -0,0 +1,54 @@ + ChatTest::getMinResponse(), + 'message_id' => 1, + 'date' => 1682343644, + 'reactions' => [ + ReactionTypeEmojiTest::getMinResponse() + ] + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getFullResponse(), + 'message_id' => 1, + 'date' => 1682343644, + 'reactions' => [ + ReactionTypeEmojiTest::getFullResponse() + ] + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getReactions()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createFullInstance(), $item->getChat()); + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals([ReactionTypeEmojiTest::createFullInstance()], $item->getReactions()); + } +} diff --git a/tests/Types/MessageReactionUpdatedTest.php b/tests/Types/MessageReactionUpdatedTest.php new file mode 100644 index 00000000..5f5da651 --- /dev/null +++ b/tests/Types/MessageReactionUpdatedTest.php @@ -0,0 +1,68 @@ + ChatTest::getMinResponse(), + 'message_id' => 1, + 'date' => 1682343644, + 'old_reaction' => [ + ReactionTypeEmojiTest::getMinResponse() + ], + 'new_reaction' => [ + ReactionTypeCustomEmojiTest::getMinResponse() + ] + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'message_id' => 1, + 'user' => UserTest::getMinResponse(), + 'actor_chat' => ChatTest::getMinResponse(), + 'date' => 1682343644, + 'old_reaction' => [ + ReactionTypeEmojiTest::getMinResponse() + ], + 'new_reaction' => [ + ReactionTypeCustomEmojiTest::getMinResponse() + ] + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getOldReaction()); + $this->assertEquals([ReactionTypeCustomEmojiTest::createMinInstance()], $item->getNewReaction()); + + $this->assertNull($item->getUser()); + $this->assertNull($item->getActorChat()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + $this->assertEquals(ChatTest::createMinInstance(), $item->getActorChat()); + $this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getOldReaction()); + $this->assertEquals([ReactionTypeCustomEmojiTest::createMinInstance()], $item->getNewReaction()); + } +} diff --git a/tests/Types/UpdateTest.php b/tests/Types/UpdateTest.php index 0af8523a..fb730af2 100644 --- a/tests/Types/UpdateTest.php +++ b/tests/Types/UpdateTest.php @@ -39,6 +39,10 @@ public static function getFullResponse() 'poll_answer' => PollAnswerTest::getMinResponse(), 'poll' => PollTest::getMinResponse(), 'chat_join_request' => ChatJoinRequestTest::getMinResponse(), + 'message_reaction' => MessageReactionUpdatedTest::getMinResponse(), + 'message_reaction_count' => MessageReactionCountUpdatedTest::getMinResponse(), + 'chat_boost' => ChatBoostUpdatedTest::getMinResponse(), + 'chat_boost_removed' => ChatBoostRemovedTest::getMinResponse(), ]; } @@ -63,6 +67,10 @@ protected function assertMinItem($item) $this->assertNull($item->getMyChatMember()); $this->assertNull($item->getChatMember()); $this->assertNull($item->getChatJoinRequest()); + $this->assertNull($item->getMessageReaction()); + $this->assertNull($item->getMessageReactionCount()); + $this->assertNull($item->getChatBoost()); + $this->assertNull($item->getChatBoostRemoved()); } /** @@ -84,5 +92,9 @@ protected function assertFullItem($item) $this->assertEquals(PollAnswerTest::createMinInstance(), $item->getPollAnswer()); $this->assertEquals(PollTest::createMinInstance(), $item->getPoll()); $this->assertEquals(ChatJoinRequestTest::createMinInstance(), $item->getChatJoinRequest()); + $this->assertEquals(MessageReactionUpdatedTest::createMinInstance(), $item->getMessageReaction()); + $this->assertEquals(MessageReactionCountUpdatedTest::createMinInstance(), $item->getMessageReactionCount()); + $this->assertEquals(ChatBoostUpdatedTest::createMinInstance(), $item->getChatBoost()); + $this->assertEquals(ChatBoostRemovedTest::createMinInstance(), $item->getChatBoostRemoved()); } } From 57b338ecd81170dee9f85d6b8d14484e4f720c2a Mon Sep 17 00:00:00 2001 From: BoShurik Date: Wed, 14 Aug 2024 11:09:32 +0300 Subject: [PATCH 125/130] Fix Update. Rename $removedChatBoost to $chatBoostRemoved --- src/Types/Update.php | 10 +++++----- tests/AbstractTypeTest.php | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Types/Update.php b/src/Types/Update.php index 5ad03a9c..0294b71e 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -196,7 +196,7 @@ class Update extends BaseType implements TypeInterface * * @var ChatBoostRemoved|null */ - protected $removedChatBoost; + protected $chatBoostRemoved; /** * @return int @@ -529,15 +529,15 @@ public function setChatBoost($chatBoost) */ public function getChatBoostRemoved() { - return $this->removedChatBoost; + return $this->chatBoostRemoved; } /** - * @param ChatBoostRemoved|null $removedChatBoost + * @param ChatBoostRemoved|null $chatBoostRemoved * @return void */ - public function setChatBoostRemoved($removedChatBoost) + public function setChatBoostRemoved($chatBoostRemoved) { - $this->removedChatBoost = $removedChatBoost; + $this->chatBoostRemoved = $chatBoostRemoved; } } diff --git a/tests/AbstractTypeTest.php b/tests/AbstractTypeTest.php index de0a4926..ce9b0253 100644 --- a/tests/AbstractTypeTest.php +++ b/tests/AbstractTypeTest.php @@ -58,6 +58,10 @@ public function testFromResponseFull() $this->assertInstanceOf(static::getType(), $item); $this->assertFullItem($item); + + $innerJson = $item->toJson(); + + $this->assertIsString($innerJson); } /** From 4da59732e824a4b631853cebe59be1d83da0b713 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Thu, 29 Aug 2024 17:08:06 +0300 Subject: [PATCH 126/130] Fix MessageOriginHiddenUser::setSenderUserName --- src/Types/MessageOriginHiddenUser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Types/MessageOriginHiddenUser.php b/src/Types/MessageOriginHiddenUser.php index 3e37b750..5adee031 100644 --- a/src/Types/MessageOriginHiddenUser.php +++ b/src/Types/MessageOriginHiddenUser.php @@ -25,7 +25,7 @@ public function getSenderUserName() return $this->senderUserName; } - public function setSenderUserName(User $senderUserName) + public function setSenderUserName(string $senderUserName) { $this->senderUserName = $senderUserName; } From fee16552382002e7fb26193552cac4c28bce552d Mon Sep 17 00:00:00 2001 From: Ilya Gusev Date: Fri, 23 May 2025 11:04:23 +0700 Subject: [PATCH 127/130] Add GitHub Actions workflow for tests (#504) --- .github/workflows/phpunit.yml | 23 ++++ src/Types/AcceptedGiftTypes.php | 63 ++++++++++ src/Types/ArrayOfGift.php | 23 ++++ src/Types/ArrayOfOwnedGift.php | 23 ++++ src/Types/Gift.php | 91 ++++++++++++++ src/Types/GiftInfo.php | 111 +++++++++++++++++ src/Types/Gifts.php | 27 ++++ src/Types/OwnedGift.php | 92 ++++++++++++++ src/Types/OwnedGiftRegular.php | 122 +++++++++++++++++++ src/Types/OwnedGiftUnique.php | 62 ++++++++++ src/Types/OwnedGifts.php | 51 ++++++++ src/Types/StarAmount.php | 39 ++++++ src/Types/UniqueGift.php | 87 +++++++++++++ src/Types/UniqueGiftBackdrop.php | 51 ++++++++ src/Types/UniqueGiftBackdropColors.php | 63 ++++++++++ src/Types/UniqueGiftInfo.php | 63 ++++++++++ src/Types/UniqueGiftModel.php | 51 ++++++++ src/Types/UniqueGiftSymbol.php | 51 ++++++++ tests/Types/AcceptedGiftTypesTest.php | 42 +++++++ tests/Types/GiftInfoTest.php | 59 +++++++++ tests/Types/GiftTest.php | 55 +++++++++ tests/Types/GiftsTest.php | 44 +++++++ tests/Types/OwnedGiftRegularTest.php | 67 ++++++++++ tests/Types/OwnedGiftUniqueTest.php | 57 +++++++++ tests/Types/OwnedGiftsTest.php | 45 +++++++ tests/Types/StarAmountTest.php | 41 +++++++ tests/Types/UniqueGiftBackdropColorsTest.php | 42 +++++++ tests/Types/UniqueGiftBackdropTest.php | 40 ++++++ tests/Types/UniqueGiftInfoTest.php | 48 ++++++++ tests/Types/UniqueGiftModelTest.php | 40 ++++++ tests/Types/UniqueGiftSymbolTest.php | 40 ++++++ tests/Types/UniqueGiftTest.php | 46 +++++++ 32 files changed, 1759 insertions(+) create mode 100644 .github/workflows/phpunit.yml create mode 100644 src/Types/AcceptedGiftTypes.php create mode 100644 src/Types/ArrayOfGift.php create mode 100644 src/Types/ArrayOfOwnedGift.php create mode 100644 src/Types/Gift.php create mode 100644 src/Types/GiftInfo.php create mode 100644 src/Types/Gifts.php create mode 100644 src/Types/OwnedGift.php create mode 100644 src/Types/OwnedGiftRegular.php create mode 100644 src/Types/OwnedGiftUnique.php create mode 100644 src/Types/OwnedGifts.php create mode 100644 src/Types/StarAmount.php create mode 100644 src/Types/UniqueGift.php create mode 100644 src/Types/UniqueGiftBackdrop.php create mode 100644 src/Types/UniqueGiftBackdropColors.php create mode 100644 src/Types/UniqueGiftInfo.php create mode 100644 src/Types/UniqueGiftModel.php create mode 100644 src/Types/UniqueGiftSymbol.php create mode 100644 tests/Types/AcceptedGiftTypesTest.php create mode 100644 tests/Types/GiftInfoTest.php create mode 100644 tests/Types/GiftTest.php create mode 100644 tests/Types/GiftsTest.php create mode 100644 tests/Types/OwnedGiftRegularTest.php create mode 100644 tests/Types/OwnedGiftUniqueTest.php create mode 100644 tests/Types/OwnedGiftsTest.php create mode 100644 tests/Types/StarAmountTest.php create mode 100644 tests/Types/UniqueGiftBackdropColorsTest.php create mode 100644 tests/Types/UniqueGiftBackdropTest.php create mode 100644 tests/Types/UniqueGiftInfoTest.php create mode 100644 tests/Types/UniqueGiftModelTest.php create mode 100644 tests/Types/UniqueGiftSymbolTest.php create mode 100644 tests/Types/UniqueGiftTest.php diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 00000000..e57d5d4d --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,23 @@ +name: Run tests + +on: + push: + branches: ["*"] + pull_request: + +jobs: + phpunit: + runs-on: ubuntu-latest + strategy: + matrix: + php: ["8.1", "8.2"] + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-interaction + - name: Run tests + run: composer test diff --git a/src/Types/AcceptedGiftTypes.php b/src/Types/AcceptedGiftTypes.php new file mode 100644 index 00000000..45f9c80e --- /dev/null +++ b/src/Types/AcceptedGiftTypes.php @@ -0,0 +1,63 @@ + true, + 'limited_gifts' => true, + 'unique_gifts' => true, + 'premium_subscription' => true, + ]; + + protected $unlimitedGifts; + protected $limitedGifts; + protected $uniqueGifts; + protected $premiumSubscription; + + public function getUnlimitedGifts() + { + return $this->unlimitedGifts; + } + + public function setUnlimitedGifts($unlimitedGifts) + { + $this->unlimitedGifts = $unlimitedGifts; + } + + public function getLimitedGifts() + { + return $this->limitedGifts; + } + + public function setLimitedGifts($limitedGifts) + { + $this->limitedGifts = $limitedGifts; + } + + public function getUniqueGifts() + { + return $this->uniqueGifts; + } + + public function setUniqueGifts($uniqueGifts) + { + $this->uniqueGifts = $uniqueGifts; + } + + public function getPremiumSubscription() + { + return $this->premiumSubscription; + } + + public function setPremiumSubscription($premiumSubscription) + { + $this->premiumSubscription = $premiumSubscription; + } +} diff --git a/src/Types/ArrayOfGift.php b/src/Types/ArrayOfGift.php new file mode 100644 index 00000000..140827cc --- /dev/null +++ b/src/Types/ArrayOfGift.php @@ -0,0 +1,23 @@ + true, + 'sticker' => Sticker::class, + 'star_count' => true, + 'upgrade_star_count' => true, + 'total_count' => true, + 'remaining_count' => true, + ]; + + protected $id; + protected $sticker; + protected $starCount; + protected $upgradeStarCount; + protected $totalCount; + protected $remainingCount; + + public function getId() + { + return $this->id; + } + + public function setId($id) + { + $this->id = $id; + } + + public function getSticker() + { + return $this->sticker; + } + + public function setSticker($sticker) + { + $this->sticker = $sticker; + } + + public function getStarCount() + { + return $this->starCount; + } + + public function setStarCount($starCount) + { + $this->starCount = $starCount; + } + + public function getUpgradeStarCount() + { + return $this->upgradeStarCount; + } + + public function setUpgradeStarCount($upgradeStarCount) + { + $this->upgradeStarCount = $upgradeStarCount; + } + + public function getTotalCount() + { + return $this->totalCount; + } + + public function setTotalCount($totalCount) + { + $this->totalCount = $totalCount; + } + + public function getRemainingCount() + { + return $this->remainingCount; + } + + public function setRemainingCount($remainingCount) + { + $this->remainingCount = $remainingCount; + } +} diff --git a/src/Types/GiftInfo.php b/src/Types/GiftInfo.php new file mode 100644 index 00000000..2b74bc5e --- /dev/null +++ b/src/Types/GiftInfo.php @@ -0,0 +1,111 @@ + Gift::class, + 'owned_gift_id' => true, + 'convert_star_count' => true, + 'prepaid_upgrade_star_count' => true, + 'can_be_upgraded' => true, + 'text' => true, + 'entities' => ArrayOfMessageEntity::class, + 'is_private' => true, + ]; + + protected $gift; + protected $ownedGiftId; + protected $convertStarCount; + protected $prepaidUpgradeStarCount; + protected $canBeUpgraded; + protected $text; + protected $entities; + protected $isPrivate; + + public function getGift() + { + return $this->gift; + } + + public function setGift($gift) + { + $this->gift = $gift; + } + + public function getOwnedGiftId() + { + return $this->ownedGiftId; + } + + public function setOwnedGiftId($ownedGiftId) + { + $this->ownedGiftId = $ownedGiftId; + } + + public function getConvertStarCount() + { + return $this->convertStarCount; + } + + public function setConvertStarCount($convertStarCount) + { + $this->convertStarCount = $convertStarCount; + } + + public function getPrepaidUpgradeStarCount() + { + return $this->prepaidUpgradeStarCount; + } + + public function setPrepaidUpgradeStarCount($prepaidUpgradeStarCount) + { + $this->prepaidUpgradeStarCount = $prepaidUpgradeStarCount; + } + + public function getCanBeUpgraded() + { + return $this->canBeUpgraded; + } + + public function setCanBeUpgraded($canBeUpgraded) + { + $this->canBeUpgraded = $canBeUpgraded; + } + + public function getText() + { + return $this->text; + } + + public function setText($text) + { + $this->text = $text; + } + + public function getEntities() + { + return $this->entities; + } + + public function setEntities($entities) + { + $this->entities = $entities; + } + + public function getIsPrivate() + { + return $this->isPrivate; + } + + public function setIsPrivate($isPrivate) + { + $this->isPrivate = $isPrivate; + } +} diff --git a/src/Types/Gifts.php b/src/Types/Gifts.php new file mode 100644 index 00000000..d1e2507c --- /dev/null +++ b/src/Types/Gifts.php @@ -0,0 +1,27 @@ + ArrayOfGift::class, + ]; + + protected $gifts; + + public function getGifts() + { + return $this->gifts; + } + + public function setGifts($gifts) + { + $this->gifts = $gifts; + } +} diff --git a/src/Types/OwnedGift.php b/src/Types/OwnedGift.php new file mode 100644 index 00000000..1017dba8 --- /dev/null +++ b/src/Types/OwnedGift.php @@ -0,0 +1,92 @@ + true, + 'gift' => true, + 'owned_gift_id' => true, + 'sender_user' => User::class, + 'send_date' => true, + ]; + + protected $type; + protected $gift; + protected $ownedGiftId; + protected $senderUser; + protected $sendDate; + + /** + * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType + */ + public static function fromResponse($data) + { + self::validate($data); + switch ($data['type']) { + case 'regular': + return OwnedGiftRegular::fromResponse($data); + case 'unique': + return OwnedGiftUnique::fromResponse($data); + default: + throw new InvalidArgumentException('Unknown owned gift type: ' . $data['type']); + } + } + + public function getType() + { + return $this->type; + } + + public function setType($type) + { + $this->type = $type; + } + + public function getGift() + { + return $this->gift; + } + + public function setGift($gift) + { + $this->gift = $gift; + } + + public function getOwnedGiftId() + { + return $this->ownedGiftId; + } + + public function setOwnedGiftId($ownedGiftId) + { + $this->ownedGiftId = $ownedGiftId; + } + + public function getSenderUser() + { + return $this->senderUser; + } + + public function setSenderUser($senderUser) + { + $this->senderUser = $senderUser; + } + + public function getSendDate() + { + return $this->sendDate; + } + + public function setSendDate($sendDate) + { + $this->sendDate = $sendDate; + } +} diff --git a/src/Types/OwnedGiftRegular.php b/src/Types/OwnedGiftRegular.php new file mode 100644 index 00000000..b9fac8ec --- /dev/null +++ b/src/Types/OwnedGiftRegular.php @@ -0,0 +1,122 @@ + true, + 'gift' => Gift::class, + 'owned_gift_id' => true, + 'sender_user' => User::class, + 'send_date' => true, + 'text' => true, + 'entities' => ArrayOfMessageEntity::class, + 'is_private' => true, + 'is_saved' => true, + 'can_be_upgraded' => true, + 'was_refunded' => true, + 'convert_star_count' => true, + 'prepaid_upgrade_star_count' => true, + ]; + + protected $text; + protected $entities; + protected $isPrivate; + protected $isSaved; + protected $canBeUpgraded; + protected $wasRefunded; + protected $convertStarCount; + protected $prepaidUpgradeStarCount; + protected $type = 'regular'; + + public static function fromResponse($data) + { + self::validate($data); + $instance = new static(); + $instance->map($data); + return $instance; + } + + public function getText() + { + return $this->text; + } + + public function setText($text) + { + $this->text = $text; + } + + public function getEntities() + { + return $this->entities; + } + + public function setEntities($entities) + { + $this->entities = $entities; + } + + public function getIsPrivate() + { + return $this->isPrivate; + } + + public function setIsPrivate($isPrivate) + { + $this->isPrivate = $isPrivate; + } + + public function getIsSaved() + { + return $this->isSaved; + } + + public function setIsSaved($isSaved) + { + $this->isSaved = $isSaved; + } + + public function getCanBeUpgraded() + { + return $this->canBeUpgraded; + } + + public function setCanBeUpgraded($canBeUpgraded) + { + $this->canBeUpgraded = $canBeUpgraded; + } + + public function getWasRefunded() + { + return $this->wasRefunded; + } + + public function setWasRefunded($wasRefunded) + { + $this->wasRefunded = $wasRefunded; + } + + public function getConvertStarCount() + { + return $this->convertStarCount; + } + + public function setConvertStarCount($convertStarCount) + { + $this->convertStarCount = $convertStarCount; + } + + public function getPrepaidUpgradeStarCount() + { + return $this->prepaidUpgradeStarCount; + } + + public function setPrepaidUpgradeStarCount($prepaidUpgradeStarCount) + { + $this->prepaidUpgradeStarCount = $prepaidUpgradeStarCount; + } +} diff --git a/src/Types/OwnedGiftUnique.php b/src/Types/OwnedGiftUnique.php new file mode 100644 index 00000000..0fc7a78d --- /dev/null +++ b/src/Types/OwnedGiftUnique.php @@ -0,0 +1,62 @@ + true, + 'gift' => UniqueGift::class, + 'owned_gift_id' => true, + 'sender_user' => User::class, + 'send_date' => true, + 'is_saved' => true, + 'can_be_transferred' => true, + 'transfer_star_count' => true, + ]; + + protected $isSaved; + protected $canBeTransferred; + protected $transferStarCount; + protected $type = 'unique'; + + public static function fromResponse($data) + { + self::validate($data); + $instance = new static(); + $instance->map($data); + return $instance; + } + + public function getIsSaved() + { + return $this->isSaved; + } + + public function setIsSaved($isSaved) + { + $this->isSaved = $isSaved; + } + + public function getCanBeTransferred() + { + return $this->canBeTransferred; + } + + public function setCanBeTransferred($canBeTransferred) + { + $this->canBeTransferred = $canBeTransferred; + } + + public function getTransferStarCount() + { + return $this->transferStarCount; + } + + public function setTransferStarCount($transferStarCount) + { + $this->transferStarCount = $transferStarCount; + } +} diff --git a/src/Types/OwnedGifts.php b/src/Types/OwnedGifts.php new file mode 100644 index 00000000..88d50a47 --- /dev/null +++ b/src/Types/OwnedGifts.php @@ -0,0 +1,51 @@ + true, + 'gifts' => ArrayOfOwnedGift::class, + 'next_offset' => true, + ]; + + protected $totalCount; + protected $gifts; + protected $nextOffset; + + public function getTotalCount() + { + return $this->totalCount; + } + + public function setTotalCount($totalCount) + { + $this->totalCount = $totalCount; + } + + public function getGifts() + { + return $this->gifts; + } + + public function setGifts($gifts) + { + $this->gifts = $gifts; + } + + public function getNextOffset() + { + return $this->nextOffset; + } + + public function setNextOffset($nextOffset) + { + $this->nextOffset = $nextOffset; + } +} diff --git a/src/Types/StarAmount.php b/src/Types/StarAmount.php new file mode 100644 index 00000000..d1ead7d1 --- /dev/null +++ b/src/Types/StarAmount.php @@ -0,0 +1,39 @@ + true, + 'nanostar_amount' => true, + ]; + + protected $amount; + protected $nanostarAmount; + + public function getAmount() + { + return $this->amount; + } + + public function setAmount($amount) + { + $this->amount = $amount; + } + + public function getNanostarAmount() + { + return $this->nanostarAmount; + } + + public function setNanostarAmount($nanostarAmount) + { + $this->nanostarAmount = $nanostarAmount; + } +} diff --git a/src/Types/UniqueGift.php b/src/Types/UniqueGift.php new file mode 100644 index 00000000..30b515dd --- /dev/null +++ b/src/Types/UniqueGift.php @@ -0,0 +1,87 @@ + true, + 'name' => true, + 'number' => true, + 'model' => UniqueGiftModel::class, + 'symbol' => UniqueGiftSymbol::class, + 'backdrop' => UniqueGiftBackdrop::class, + ]; + + protected $baseName; + protected $name; + protected $number; + protected $model; + protected $symbol; + protected $backdrop; + + public function getBaseName() + { + return $this->baseName; + } + + public function setBaseName($baseName) + { + $this->baseName = $baseName; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getNumber() + { + return $this->number; + } + + public function setNumber($number) + { + $this->number = $number; + } + + public function getModel() + { + return $this->model; + } + + public function setModel($model) + { + $this->model = $model; + } + + public function getSymbol() + { + return $this->symbol; + } + + public function setSymbol($symbol) + { + $this->symbol = $symbol; + } + + public function getBackdrop() + { + return $this->backdrop; + } + + public function setBackdrop($backdrop) + { + $this->backdrop = $backdrop; + } +} diff --git a/src/Types/UniqueGiftBackdrop.php b/src/Types/UniqueGiftBackdrop.php new file mode 100644 index 00000000..b81af9e8 --- /dev/null +++ b/src/Types/UniqueGiftBackdrop.php @@ -0,0 +1,51 @@ + true, + 'colors' => UniqueGiftBackdropColors::class, + 'rarity_per_mille' => true, + ]; + + protected $name; + protected $colors; + protected $rarityPerMille; + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getColors() + { + return $this->colors; + } + + public function setColors($colors) + { + $this->colors = $colors; + } + + public function getRarityPerMille() + { + return $this->rarityPerMille; + } + + public function setRarityPerMille($rarityPerMille) + { + $this->rarityPerMille = $rarityPerMille; + } +} diff --git a/src/Types/UniqueGiftBackdropColors.php b/src/Types/UniqueGiftBackdropColors.php new file mode 100644 index 00000000..f9f55e32 --- /dev/null +++ b/src/Types/UniqueGiftBackdropColors.php @@ -0,0 +1,63 @@ + true, + 'edge_color' => true, + 'symbol_color' => true, + 'text_color' => true, + ]; + + protected $centerColor; + protected $edgeColor; + protected $symbolColor; + protected $textColor; + + public function getCenterColor() + { + return $this->centerColor; + } + + public function setCenterColor($centerColor) + { + $this->centerColor = $centerColor; + } + + public function getEdgeColor() + { + return $this->edgeColor; + } + + public function setEdgeColor($edgeColor) + { + $this->edgeColor = $edgeColor; + } + + public function getSymbolColor() + { + return $this->symbolColor; + } + + public function setSymbolColor($symbolColor) + { + $this->symbolColor = $symbolColor; + } + + public function getTextColor() + { + return $this->textColor; + } + + public function setTextColor($textColor) + { + $this->textColor = $textColor; + } +} diff --git a/src/Types/UniqueGiftInfo.php b/src/Types/UniqueGiftInfo.php new file mode 100644 index 00000000..92cce222 --- /dev/null +++ b/src/Types/UniqueGiftInfo.php @@ -0,0 +1,63 @@ + UniqueGift::class, + 'origin' => true, + 'owned_gift_id' => true, + 'transfer_star_count' => true, + ]; + + protected $gift; + protected $origin; + protected $ownedGiftId; + protected $transferStarCount; + + public function getGift() + { + return $this->gift; + } + + public function setGift($gift) + { + $this->gift = $gift; + } + + public function getOrigin() + { + return $this->origin; + } + + public function setOrigin($origin) + { + $this->origin = $origin; + } + + public function getOwnedGiftId() + { + return $this->ownedGiftId; + } + + public function setOwnedGiftId($ownedGiftId) + { + $this->ownedGiftId = $ownedGiftId; + } + + public function getTransferStarCount() + { + return $this->transferStarCount; + } + + public function setTransferStarCount($transferStarCount) + { + $this->transferStarCount = $transferStarCount; + } +} diff --git a/src/Types/UniqueGiftModel.php b/src/Types/UniqueGiftModel.php new file mode 100644 index 00000000..a1525f03 --- /dev/null +++ b/src/Types/UniqueGiftModel.php @@ -0,0 +1,51 @@ + true, + 'sticker' => Sticker::class, + 'rarity_per_mille' => true, + ]; + + protected $name; + protected $sticker; + protected $rarityPerMille; + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getSticker() + { + return $this->sticker; + } + + public function setSticker($sticker) + { + $this->sticker = $sticker; + } + + public function getRarityPerMille() + { + return $this->rarityPerMille; + } + + public function setRarityPerMille($rarityPerMille) + { + $this->rarityPerMille = $rarityPerMille; + } +} diff --git a/src/Types/UniqueGiftSymbol.php b/src/Types/UniqueGiftSymbol.php new file mode 100644 index 00000000..1b1c5261 --- /dev/null +++ b/src/Types/UniqueGiftSymbol.php @@ -0,0 +1,51 @@ + true, + 'sticker' => Sticker::class, + 'rarity_per_mille' => true, + ]; + + protected $name; + protected $sticker; + protected $rarityPerMille; + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getSticker() + { + return $this->sticker; + } + + public function setSticker($sticker) + { + $this->sticker = $sticker; + } + + public function getRarityPerMille() + { + return $this->rarityPerMille; + } + + public function setRarityPerMille($rarityPerMille) + { + $this->rarityPerMille = $rarityPerMille; + } +} diff --git a/tests/Types/AcceptedGiftTypesTest.php b/tests/Types/AcceptedGiftTypesTest.php new file mode 100644 index 00000000..ddd84e52 --- /dev/null +++ b/tests/Types/AcceptedGiftTypesTest.php @@ -0,0 +1,42 @@ + true, + 'limited_gifts' => true, + 'unique_gifts' => true, + 'premium_subscription' => true, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertTrue($item->getUnlimitedGifts()); + $this->assertTrue($item->getLimitedGifts()); + $this->assertTrue($item->getUniqueGifts()); + $this->assertTrue($item->getPremiumSubscription()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/GiftInfoTest.php b/tests/Types/GiftInfoTest.php new file mode 100644 index 00000000..e69d936e --- /dev/null +++ b/tests/Types/GiftInfoTest.php @@ -0,0 +1,59 @@ + GiftTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'gift' => GiftTest::getMinResponse(), + 'owned_gift_id' => 'id', + 'convert_star_count' => 1, + 'prepaid_upgrade_star_count' => 2, + 'can_be_upgraded' => true, + 'text' => 'hi', + 'entities' => [MessageEntityTest::getMinResponse()], + 'is_private' => true, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(GiftTest::createMinInstance(), $item->getGift()); + $this->assertNull($item->getOwnedGiftId()); + $this->assertNull($item->getConvertStarCount()); + $this->assertNull($item->getPrepaidUpgradeStarCount()); + $this->assertNull($item->getCanBeUpgraded()); + $this->assertNull($item->getText()); + $this->assertNull($item->getEntities()); + $this->assertNull($item->getIsPrivate()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(GiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('id', $item->getOwnedGiftId()); + $this->assertEquals(1, $item->getConvertStarCount()); + $this->assertEquals(2, $item->getPrepaidUpgradeStarCount()); + $this->assertTrue($item->getCanBeUpgraded()); + $this->assertEquals('hi', $item->getText()); + $this->assertEquals([MessageEntityTest::createMinInstance()], $item->getEntities()); + $this->assertTrue($item->getIsPrivate()); + } +} diff --git a/tests/Types/GiftTest.php b/tests/Types/GiftTest.php new file mode 100644 index 00000000..416f0078 --- /dev/null +++ b/tests/Types/GiftTest.php @@ -0,0 +1,55 @@ + 'gift1', + 'sticker' => StickerTest::getMinResponse(), + 'star_count' => 10, + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 'gift1', + 'sticker' => StickerTest::getMinResponse(), + 'star_count' => 10, + 'upgrade_star_count' => 5, + 'total_count' => 100, + 'remaining_count' => 50, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('gift1', $item->getId()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(10, $item->getStarCount()); + $this->assertNull($item->getUpgradeStarCount()); + $this->assertNull($item->getTotalCount()); + $this->assertNull($item->getRemainingCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('gift1', $item->getId()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(10, $item->getStarCount()); + $this->assertEquals(5, $item->getUpgradeStarCount()); + $this->assertEquals(100, $item->getTotalCount()); + $this->assertEquals(50, $item->getRemainingCount()); + } +} diff --git a/tests/Types/GiftsTest.php b/tests/Types/GiftsTest.php new file mode 100644 index 00000000..5944bb60 --- /dev/null +++ b/tests/Types/GiftsTest.php @@ -0,0 +1,44 @@ + [ + GiftTest::getMinResponse(), + ], + ]; + } + + public static function getFullResponse() + { + return [ + 'gifts' => [ + GiftTest::getFullResponse(), + ], + ]; + } + + protected function assertMinItem($item) + { + $this->assertIsArray($item->getGifts()); + $this->assertEquals([GiftTest::createMinInstance()], $item->getGifts()); + } + + protected function assertFullItem($item) + { + $this->assertIsArray($item->getGifts()); + $this->assertEquals([GiftTest::createFullInstance()], $item->getGifts()); + } +} diff --git a/tests/Types/OwnedGiftRegularTest.php b/tests/Types/OwnedGiftRegularTest.php new file mode 100644 index 00000000..1b6a7bf8 --- /dev/null +++ b/tests/Types/OwnedGiftRegularTest.php @@ -0,0 +1,67 @@ + 'regular', + 'gift' => GiftTest::getMinResponse(), + 'send_date' => 1682343643, + ]; + } + + public static function getFullResponse() + { + return [ + 'type' => 'regular', + 'gift' => GiftTest::getMinResponse(), + 'owned_gift_id' => 'id', + 'sender_user' => UserTest::getMinResponse(), + 'send_date' => 1682343643, + 'text' => 'hi', + 'entities' => [MessageEntityTest::getMinResponse()], + 'is_private' => true, + 'is_saved' => true, + 'can_be_upgraded' => true, + 'was_refunded' => true, + 'convert_star_count' => 1, + 'prepaid_upgrade_star_count' => 2, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('regular', $item->getType()); + $this->assertEquals(GiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals(1682343643, $item->getSendDate()); + $this->assertNull($item->getOwnedGiftId()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('regular', $item->getType()); + $this->assertEquals(GiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('id', $item->getOwnedGiftId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getSenderUser()); + $this->assertEquals(1682343643, $item->getSendDate()); + $this->assertEquals('hi', $item->getText()); + $this->assertEquals([MessageEntityTest::createMinInstance()], $item->getEntities()); + $this->assertTrue($item->getIsPrivate()); + $this->assertTrue($item->getIsSaved()); + $this->assertTrue($item->getCanBeUpgraded()); + $this->assertTrue($item->getWasRefunded()); + $this->assertEquals(1, $item->getConvertStarCount()); + $this->assertEquals(2, $item->getPrepaidUpgradeStarCount()); + } +} diff --git a/tests/Types/OwnedGiftUniqueTest.php b/tests/Types/OwnedGiftUniqueTest.php new file mode 100644 index 00000000..ebee3c67 --- /dev/null +++ b/tests/Types/OwnedGiftUniqueTest.php @@ -0,0 +1,57 @@ + 'unique', + 'gift' => UniqueGiftTest::getMinResponse(), + 'send_date' => 1682343643, + ]; + } + + public static function getFullResponse() + { + return [ + 'type' => 'unique', + 'gift' => UniqueGiftTest::getMinResponse(), + 'owned_gift_id' => 'id', + 'sender_user' => UserTest::getMinResponse(), + 'send_date' => 1682343643, + 'is_saved' => true, + 'can_be_transferred' => true, + 'transfer_star_count' => 3, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('unique', $item->getType()); + $this->assertEquals(UniqueGiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals(1682343643, $item->getSendDate()); + $this->assertNull($item->getOwnedGiftId()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('unique', $item->getType()); + $this->assertEquals(UniqueGiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('id', $item->getOwnedGiftId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getSenderUser()); + $this->assertEquals(1682343643, $item->getSendDate()); + $this->assertTrue($item->getIsSaved()); + $this->assertTrue($item->getCanBeTransferred()); + $this->assertEquals(3, $item->getTransferStarCount()); + } +} diff --git a/tests/Types/OwnedGiftsTest.php b/tests/Types/OwnedGiftsTest.php new file mode 100644 index 00000000..81fc4858 --- /dev/null +++ b/tests/Types/OwnedGiftsTest.php @@ -0,0 +1,45 @@ + 1, + 'gifts' => [OwnedGiftRegularTest::getMinResponse()], + ]; + } + + public static function getFullResponse() + { + return [ + 'total_count' => 2, + 'gifts' => [OwnedGiftRegularTest::getMinResponse()], + 'next_offset' => '1', + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getTotalCount()); + $this->assertEquals([OwnedGiftRegularTest::createMinInstance()], $item->getGifts()); + $this->assertNull($item->getNextOffset()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(2, $item->getTotalCount()); + $this->assertEquals([OwnedGiftRegularTest::createMinInstance()], $item->getGifts()); + $this->assertEquals('1', $item->getNextOffset()); + } +} diff --git a/tests/Types/StarAmountTest.php b/tests/Types/StarAmountTest.php new file mode 100644 index 00000000..327bf350 --- /dev/null +++ b/tests/Types/StarAmountTest.php @@ -0,0 +1,41 @@ + 1, + ]; + } + + public static function getFullResponse() + { + return [ + 'amount' => 2, + 'nanostar_amount' => 100, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getAmount()); + $this->assertNull($item->getNanostarAmount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(2, $item->getAmount()); + $this->assertEquals(100, $item->getNanostarAmount()); + } +} diff --git a/tests/Types/UniqueGiftBackdropColorsTest.php b/tests/Types/UniqueGiftBackdropColorsTest.php new file mode 100644 index 00000000..f78b1410 --- /dev/null +++ b/tests/Types/UniqueGiftBackdropColorsTest.php @@ -0,0 +1,42 @@ + 1, + 'edge_color' => 2, + 'symbol_color' => 3, + 'text_color' => 4, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getCenterColor()); + $this->assertEquals(2, $item->getEdgeColor()); + $this->assertEquals(3, $item->getSymbolColor()); + $this->assertEquals(4, $item->getTextColor()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UniqueGiftBackdropTest.php b/tests/Types/UniqueGiftBackdropTest.php new file mode 100644 index 00000000..c5955493 --- /dev/null +++ b/tests/Types/UniqueGiftBackdropTest.php @@ -0,0 +1,40 @@ + 'backdrop', + 'colors' => UniqueGiftBackdropColorsTest::getMinResponse(), + 'rarity_per_mille' => 1, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals('backdrop', $item->getName()); + $this->assertEquals(UniqueGiftBackdropColorsTest::createMinInstance(), $item->getColors()); + $this->assertEquals(1, $item->getRarityPerMille()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UniqueGiftInfoTest.php b/tests/Types/UniqueGiftInfoTest.php new file mode 100644 index 00000000..a56e0de8 --- /dev/null +++ b/tests/Types/UniqueGiftInfoTest.php @@ -0,0 +1,48 @@ + UniqueGiftTest::getMinResponse(), + 'origin' => 'upgrade', + ]; + } + + public static function getFullResponse() + { + return [ + 'gift' => UniqueGiftTest::getMinResponse(), + 'origin' => 'upgrade', + 'owned_gift_id' => 'id', + 'transfer_star_count' => 3, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(UniqueGiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('upgrade', $item->getOrigin()); + $this->assertNull($item->getOwnedGiftId()); + $this->assertNull($item->getTransferStarCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(UniqueGiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('upgrade', $item->getOrigin()); + $this->assertEquals('id', $item->getOwnedGiftId()); + $this->assertEquals(3, $item->getTransferStarCount()); + } +} diff --git a/tests/Types/UniqueGiftModelTest.php b/tests/Types/UniqueGiftModelTest.php new file mode 100644 index 00000000..11863a8e --- /dev/null +++ b/tests/Types/UniqueGiftModelTest.php @@ -0,0 +1,40 @@ + 'model', + 'sticker' => StickerTest::getMinResponse(), + 'rarity_per_mille' => 1, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals('model', $item->getName()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(1, $item->getRarityPerMille()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UniqueGiftSymbolTest.php b/tests/Types/UniqueGiftSymbolTest.php new file mode 100644 index 00000000..fb58e7d9 --- /dev/null +++ b/tests/Types/UniqueGiftSymbolTest.php @@ -0,0 +1,40 @@ + 'symbol', + 'sticker' => StickerTest::getMinResponse(), + 'rarity_per_mille' => 1, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals('symbol', $item->getName()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(1, $item->getRarityPerMille()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UniqueGiftTest.php b/tests/Types/UniqueGiftTest.php new file mode 100644 index 00000000..e7004fe6 --- /dev/null +++ b/tests/Types/UniqueGiftTest.php @@ -0,0 +1,46 @@ + 'gift', + 'name' => 'unique1', + 'number' => 1, + 'model' => UniqueGiftModelTest::getMinResponse(), + 'symbol' => UniqueGiftSymbolTest::getMinResponse(), + 'backdrop' => UniqueGiftBackdropTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals('gift', $item->getBaseName()); + $this->assertEquals('unique1', $item->getName()); + $this->assertEquals(1, $item->getNumber()); + $this->assertEquals(UniqueGiftModelTest::createMinInstance(), $item->getModel()); + $this->assertEquals(UniqueGiftSymbolTest::createMinInstance(), $item->getSymbol()); + $this->assertEquals(UniqueGiftBackdropTest::createMinInstance(), $item->getBackdrop()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} From 074eba8d9cc47546fd93a1e308735a4fae27997d Mon Sep 17 00:00:00 2001 From: philipp-kolesnikov Date: Thu, 10 Jul 2025 20:25:14 +1000 Subject: [PATCH 128/130] Clean PHP 8.4 related warnings (#502) - Implicitly marking parameter as nullable is deprecated, the explicit nullable type must be used instead --- .github/workflows/tests.yaml | 6 ++++-- src/BotApi.php | 2 +- src/Client.php | 4 ++-- src/Events/Event.php | 2 +- src/Http/AbstractHttpClient.php | 4 ++-- src/Http/CurlHttpClient.php | 2 +- src/Http/HttpClientInterface.php | 2 +- src/Http/PsrHttpClient.php | 2 +- src/Http/SymfonyHttpClient.php | 2 +- 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 76cd14fe..6b8ab6fd 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -15,10 +15,12 @@ jobs: php: - "8.1" - "8.2" + - "8.3" + - "8.4" steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install PHP @@ -33,7 +35,7 @@ jobs: - name: Cache dependencies installed with composer - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.COMPOSER_CACHE_DIR }} key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/src/BotApi.php b/src/BotApi.php index ef9ddccd..0fb6e323 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -177,7 +177,7 @@ class BotApi * @param HttpClientInterface|null $httpClient * @param string|null $endpoint */ - public function __construct($token, HttpClientInterface $httpClient = null, $endpoint = null) + public function __construct($token, ?HttpClientInterface $httpClient = null, $endpoint = null) { $this->token = $token; $this->endpoint = ($endpoint ?: self::URL_PREFIX) . $token; diff --git a/src/Client.php b/src/Client.php index b9da94ba..5109cfba 100644 --- a/src/Client.php +++ b/src/Client.php @@ -43,7 +43,7 @@ class Client * @param HttpClientInterface|null $httpClient * @param string|null $endpoint */ - public function __construct($token, HttpClientInterface $httpClient = null, $endpoint = null) + public function __construct($token, ?HttpClientInterface $httpClient = null, $endpoint = null) { $this->api = new BotApi($token, $httpClient, $endpoint); $this->events = new EventCollection(); @@ -135,7 +135,7 @@ public function preCheckoutQuery(Closure $action) * * @return \TelegramBot\Api\Client */ - public function on(Closure $event, Closure $checker = null) + public function on(Closure $event, ?Closure $checker = null) { $this->events->add($event, $checker); diff --git a/src/Events/Event.php b/src/Events/Event.php index fd7a45f3..1b668e27 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -22,7 +22,7 @@ class Event * @param \Closure $action * @param \Closure|null $checker */ - public function __construct(\Closure $action, \Closure $checker = null) + public function __construct(\Closure $action, ?\Closure $checker = null) { $this->action = $action; $this->checker = $checker; diff --git a/src/Http/AbstractHttpClient.php b/src/Http/AbstractHttpClient.php index 6c04bcc2..c98bce74 100644 --- a/src/Http/AbstractHttpClient.php +++ b/src/Http/AbstractHttpClient.php @@ -6,7 +6,7 @@ abstract class AbstractHttpClient implements HttpClientInterface { - public function request($url, array $data = null) + public function request($url, ?array $data = null) { $response = $this->doRequest($url, $data); @@ -27,7 +27,7 @@ public function download($url) * @param array|null $data * @return array */ - abstract protected function doRequest($url, array $data = null); + abstract protected function doRequest($url, ?array $data = null); /** * @param string $url diff --git a/src/Http/CurlHttpClient.php b/src/Http/CurlHttpClient.php index 0df69e57..352e1b97 100644 --- a/src/Http/CurlHttpClient.php +++ b/src/Http/CurlHttpClient.php @@ -110,7 +110,7 @@ public function __construct(array $options = []) /** * @inheritDoc */ - protected function doRequest($url, array $data = null) + protected function doRequest($url, ?array $data = null) { $options = $this->options + [ CURLOPT_URL => $url, diff --git a/src/Http/HttpClientInterface.php b/src/Http/HttpClientInterface.php index 7503c14c..ed374daa 100644 --- a/src/Http/HttpClientInterface.php +++ b/src/Http/HttpClientInterface.php @@ -15,7 +15,7 @@ interface HttpClientInterface * @return mixed * @throws Exception */ - public function request($url, array $data = null); + public function request($url, ?array $data = null); /** * Get file contents diff --git a/src/Http/PsrHttpClient.php b/src/Http/PsrHttpClient.php index 912d711e..ad04ae51 100644 --- a/src/Http/PsrHttpClient.php +++ b/src/Http/PsrHttpClient.php @@ -40,7 +40,7 @@ public function __construct( /** * @inheritDoc */ - protected function doRequest($url, array $data = null) + protected function doRequest($url, ?array $data = null) { if ($data) { $method = 'POST'; diff --git a/src/Http/SymfonyHttpClient.php b/src/Http/SymfonyHttpClient.php index 7dea7df1..007e287f 100644 --- a/src/Http/SymfonyHttpClient.php +++ b/src/Http/SymfonyHttpClient.php @@ -24,7 +24,7 @@ public function __construct(SymfonyHttpClientInterface $http) /** * @inheritDoc */ - protected function doRequest($url, array $data = null) + protected function doRequest($url, ?array $data = null) { $options = []; if ($data) { From 8f83d0ed3c93e7210c1e5d246633cc1e4e4483dd Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Thu, 10 Jul 2025 13:58:27 +0300 Subject: [PATCH 129/130] Fix workflow (#505) --- .github/workflows/cs.yaml | 2 +- .github/workflows/psalm.yaml | 2 +- src/Types/AcceptedGiftTypes.php | 6 +++--- src/Types/Gift.php | 6 +++--- src/Types/GiftInfo.php | 6 +++--- src/Types/Gifts.php | 6 +++--- src/Types/OwnedGift.php | 12 ++++++++---- src/Types/OwnedGiftRegular.php | 2 +- src/Types/OwnedGiftUnique.php | 2 +- src/Types/OwnedGifts.php | 6 +++--- src/Types/StarAmount.php | 6 +++--- src/Types/UniqueGift.php | 6 +++--- src/Types/UniqueGiftBackdrop.php | 6 +++--- src/Types/UniqueGiftBackdropColors.php | 6 +++--- src/Types/UniqueGiftInfo.php | 6 +++--- src/Types/UniqueGiftModel.php | 6 +++--- src/Types/UniqueGiftSymbol.php | 6 +++--- 17 files changed, 48 insertions(+), 44 deletions(-) diff --git a/.github/workflows/cs.yaml b/.github/workflows/cs.yaml index 83d50663..fcdf786c 100644 --- a/.github/workflows/cs.yaml +++ b/.github/workflows/cs.yaml @@ -32,7 +32,7 @@ jobs: - name: Cache dependencies installed with composer - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.COMPOSER_CACHE_DIR }} key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/.github/workflows/psalm.yaml b/.github/workflows/psalm.yaml index ceccd1a3..8cdc4b52 100644 --- a/.github/workflows/psalm.yaml +++ b/.github/workflows/psalm.yaml @@ -32,7 +32,7 @@ jobs: - name: Cache dependencies installed with composer - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.COMPOSER_CACHE_DIR }} key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/src/Types/AcceptedGiftTypes.php b/src/Types/AcceptedGiftTypes.php index 45f9c80e..ff77e02c 100644 --- a/src/Types/AcceptedGiftTypes.php +++ b/src/Types/AcceptedGiftTypes.php @@ -1,9 +1,9 @@ Date: Thu, 10 Jul 2025 15:31:50 +0300 Subject: [PATCH 130/130] Explicit nullable in BotApi::call (#506) --- src/BotApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BotApi.php b/src/BotApi.php index 0fb6e323..1ac21e00 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -244,7 +244,7 @@ public function setModeObject($mode = true) * @throws HttpException * @throws InvalidJsonException */ - public function call($method, array $data = null, $timeout = null) + public function call($method, ?array $data = null, $timeout = null) { if ($timeout !== null) { @trigger_error(sprintf('Passing $timeout parameter in %s::%s is deprecated. Use http client options', __CLASS__, __METHOD__), \E_USER_DEPRECATED);