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] #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()); } }