diff --git a/src/BotApi.php b/src/BotApi.php index 62070a21..7b65fdb5 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -6,15 +6,25 @@ 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; +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\Sticker; +use TelegramBot\Api\Types\StickerSet; use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\User; use TelegramBot\Api\Types\UserProfilePhotos; @@ -150,7 +160,7 @@ class BotApi /** * Botan tracker * - * @var \TelegramBot\Api\Botan + * @var Botan */ protected $tracker; @@ -173,6 +183,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) { @@ -206,9 +217,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) { @@ -253,7 +264,7 @@ public function call($method, array $data = null, $timeout = 10) * * @return string * - * @throws \TelegramBot\Api\HttpException + * @throws HttpException */ protected function executeCurl(array $options) { @@ -294,7 +305,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) { @@ -314,20 +325,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 @@ -335,6 +347,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, @@ -351,10 +364,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 @@ -369,6 +382,7 @@ public function copyMessage( $parseMode = null, $captionEntities = null, $disableNotification = false, + $messageThreadId = null, $replyToMessageId = null, $allowSendingWithoutReply = false, $replyMarkup = null @@ -381,6 +395,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(), @@ -394,19 +409,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 @@ -416,6 +432,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, @@ -438,7 +455,7 @@ public function sendContact( * @param string $action * * @return bool - * @throws \TelegramBot\Api\Exception + * @throws Exception */ public function sendChatAction($chatId, $action) { @@ -455,8 +472,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) { @@ -476,27 +493,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 + * @throws 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 + * @throws 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]); } /** @@ -504,9 +554,9 @@ public function deleteWebhook() * 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() { @@ -517,9 +567,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() { @@ -539,8 +589,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) { @@ -562,21 +612,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 * - * @param null|int $livePeriod - * @return \TelegramBot\Api\Types\Message + * @return Message + * + * @throws Exception */ public function sendLocation( $chatId, $latitude, $longitude, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -587,6 +641,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, @@ -601,9 +656,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, @@ -630,9 +687,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, @@ -657,13 +716,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, @@ -672,6 +731,7 @@ public function sendVenue( $title, $address, $foursquareId = null, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false @@ -683,6 +743,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, @@ -695,30 +756,216 @@ 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 bool $disableNotification + * @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 + $disableNotification = false, + $protectContent = false, + $allowSendingWithoutReply = false ) { 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, + ])); + } + + /** + * @param string $name Name of the sticker set + * + * @throws InvalidArgumentException + * @throws 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 InvalidArgumentException + * @throws Exception + * + * @author bernard-ng + */ + 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 InvalidArgumentException + * @throws 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 MaskPosition|null $maskPosition A JSON-serialized object for position where the mask should be placed on faces + * + * @throws InvalidArgumentException + * @throws Exception + * + * @author bernard-ng + */ + 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 InvalidArgumentException + * @throws 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 InvalidArgumentException + * @throws 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 InvalidArgumentException + * @throws 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). @@ -728,22 +975,23 @@ public function sendSticker( * @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, @@ -755,6 +1003,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, @@ -772,21 +1021,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, @@ -797,6 +1047,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, @@ -812,27 +1063,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, @@ -844,6 +1096,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, @@ -853,23 +1106,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, ])); } @@ -886,24 +1151,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, @@ -935,20 +1199,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, @@ -958,6 +1223,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, @@ -972,20 +1238,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, @@ -995,6 +1262,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, @@ -1013,9 +1281,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) { @@ -1029,7 +1297,8 @@ public function getFile($fileId) * * @return string * - * @throws \TelegramBot\Api\HttpException + * @throws HttpException + * @throws Exception */ public function downloadFile($fileId) { @@ -1098,6 +1367,7 @@ public function answerInlineQuery( * they are considered to be banned forever * * @return bool + * @throws Exception */ public function kickChatMember($chatId, $userId, $untilDate = null) { @@ -1118,6 +1388,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) { @@ -1138,6 +1409,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) { @@ -1174,7 +1446,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 @@ -1193,9 +1466,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, @@ -1223,14 +1497,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, @@ -1264,6 +1537,7 @@ public function editMessageCaption( * @param string|null $inlineMessageId * @param string|null $replyMarkup * @return bool|Message + * * @throws Exception * @throws HttpException * @throws InvalidJsonException @@ -1289,11 +1563,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, @@ -1321,6 +1595,7 @@ public function editMessageReplyMarkup( * @param int $messageId * * @return bool + * @throws Exception */ public function deleteMessage($chatId, $messageId) { @@ -1355,10 +1630,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') { @@ -1376,10 +1651,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') { @@ -1399,6 +1674,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 @@ -1407,16 +1683,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, @@ -1436,6 +1712,7 @@ public function sendInvoice( $needPhoneNumber = false, $needEmail = false, $needShippingAddress = false, + $messageThreadId = null, $replyToMessageId = null, $replyMarkup = null, $disableNotification = false, @@ -1481,7 +1758,7 @@ public function sendInvoice( * @param null|string $errorMessage * * @return bool - * + * @throws Exception */ public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null) { @@ -1502,6 +1779,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) { @@ -1532,6 +1810,7 @@ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMe * implies can_send_media_messages * * @return bool + * @throws Exception */ public function restrictChatMember( $chatId, @@ -1571,8 +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, @@ -1584,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, @@ -1596,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 ]); } @@ -1607,6 +1895,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) { @@ -1624,6 +1913,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) { @@ -1641,6 +1931,7 @@ public function setChatPhoto($chatId, $photo) * (in the format @channelusername) * * @return bool + * @throws Exception */ public function deleteChatPhoto($chatId) { @@ -1658,6 +1949,7 @@ public function deleteChatPhoto($chatId) * @param string $title New chat title, 1-255 characters * * @return bool + * @throws Exception */ public function setChatTitle($chatId, $title) { @@ -1676,6 +1968,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) { @@ -1695,6 +1988,7 @@ public function setChatDescription($chatId, $description = null) * @param bool $disableNotification * * @return bool + * @throws Exception */ public function pinChatMessage($chatId, $messageId, $disableNotification = false) { @@ -1713,6 +2007,7 @@ public function pinChatMessage($chatId, $messageId, $disableNotification = false * (in the format @channelusername) * * @return bool + * @throws Exception */ public function unpinChatMessage($chatId) { @@ -1729,6 +2024,7 @@ public function unpinChatMessage($chatId) * (in the format @channelusername) * * @return Chat + * @throws Exception */ public function getChat($chatId) { @@ -1745,6 +2041,7 @@ public function getChat($chatId) * @param int $userId * * @return ChatMember + * @throws Exception */ public function getChatMember($chatId, $userId) { @@ -1761,6 +2058,7 @@ public function getChatMember($chatId, $userId) * (in the format @channelusername) * * @return bool + * @throws Exception */ public function leaveChat($chatId) { @@ -1776,6 +2074,7 @@ public function leaveChat($chatId) * (in the format @channelusername) * * @return int + * @throws Exception */ public function getChatMembersCount($chatId) { @@ -1793,7 +2092,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) { @@ -1816,20 +2117,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 @@ -1839,6 +2141,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 @@ -1851,21 +2154,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 ])); @@ -1911,12 +2217,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 @@ -1930,6 +2237,7 @@ public function sendPoll( $allowsMultipleAnswers = false, $correctOptionId = null, $isClosed = false, + $messageThreadId = null, $disableNotification = false, $replyToMessageId = null, $replyMarkup = null @@ -1944,6 +2252,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(), ])); @@ -1960,8 +2269,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 @@ -1976,6 +2286,7 @@ public function sendDice( $chatId, $emoji, $disableNotification = false, + $messageThreadId = null, $replyToMessageId = null, $allowSendingWithoutReply = false, $replyMarkup = null @@ -1984,6 +2295,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(), @@ -1996,11 +2308,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, @@ -2014,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/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/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, + '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..26497d4d 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,74 @@ 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 messages from the chat can't be forwarded to other chats. Returned only in getChat. + * + * @var bool + */ + protected $hasProtectedContent; + + /** + * Optional. True, if the supergroup chat is a forum (has topics enabled) + * + * @var bool + */ + 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[] + */ + protected $activeUsernames; + + /** + * Optional. Custom emoji identifier of emoji status of the other party in a private chat. Returned only in getChat. + * + * @var string + */ + 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 + */ + 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 + */ + protected $hasRestrictedVoiceAndVideoMessages; + /** * @return int|string */ @@ -396,7 +473,7 @@ public function setStickerSetName($stickerSetName) /** * @return bool */ - public function isCanSetStickerSet() + public function getCanSetStickerSet() { return $this->canSetStickerSet; } @@ -440,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/Document.php b/src/Types/Document.php index d84d2c49..afba5ad6 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, @@ -33,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 @@ -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/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 new file mode 100644 index 00000000..c895cae8 --- /dev/null +++ b/src/Types/MaskPosition.php @@ -0,0 +1,119 @@ + + */ +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..69dedf21 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -68,6 +68,12 @@ 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, + 'reply_markup' => InlineKeyboardMarkup::class ]; /** @@ -405,6 +411,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 +1210,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/MessageEntity.php b/src/Types/MessageEntity.php index 33bf0ea0..16e9d025 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -11,6 +11,12 @@ use TelegramBot\Api\BaseType; use TelegramBot\Api\TypeInterface; +/** + * class MessageEntity. + * This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. + * + * @package TelegramBot\Api\Types + */ class MessageEntity extends BaseType implements TypeInterface { @@ -29,6 +35,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 +56,7 @@ class MessageEntity extends BaseType implements TypeInterface 'url' => true, 'user' => User::class, 'language' => true, + 'custom_emoji_id' => true, ]; /** @@ -97,6 +105,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 $customEmojiId; + /** * @return string */ @@ -192,4 +208,20 @@ public function setLanguage($language) { $this->language = $language; } + + /** + * @return string + */ + public function getCustomEmojiId() + { + return $this->customEmojiId; + } + + /** + * @param string $customEmojiId + */ + public function setCustomEmojiId($customEmojiId) + { + $this->customEmojiId = $customEmojiId; + } } 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/Sticker.php b/src/Types/Sticker.php index 4de6d803..36dd136b 100644 --- a/src/Types/Sticker.php +++ b/src/Types/Sticker.php @@ -19,7 +19,15 @@ class Sticker extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'width', 'height']; + static protected $requiredParams = [ + 'file_id', + 'file_unique_id', + 'type', + 'width', + 'height', + 'is_animated', + 'is_video' + ]; /** * {@inheritdoc} @@ -32,6 +40,15 @@ class Sticker extends BaseType implements TypeInterface 'height' => 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..10487c8d --- /dev/null +++ b/src/Types/StickerSet.php @@ -0,0 +1,199 @@ + + */ +class StickerSet extends BaseType implements TypeInterface +{ + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['name', 'title', 'sticker_type', 'is_animated', 'is_video', 'stickers']; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'name' => 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; + } +} diff --git a/src/Types/User.php b/src/Types/User.php index aa84bb34..ac8709b9 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 + */ + protected $isPremium; + + /** + * Optional. True, if this user added the bot to the attachment menu + * + * @var bool + */ + protected $addedToAttachmentMenu; + + /** + * Optional. True, if the bot can be invited to groups. Returned only in getMe. + * + * @var bool + */ + protected $canJoinGroups; + + /** + * Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. + * + * @var bool + */ + protected $canReadAllGroupMessages; + + /** + * Optional. True, if the bot supports inline queries. Returned only in getMe. + * + * @var bool + */ + protected $supportsInlineQueries; + /** * @return string */ @@ -178,4 +218,86 @@ public function setIsBot($isBot) { $this->isBot = $isBot; } + + /** + * @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/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; + } +} 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/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/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() 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/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()); } /** 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 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()); }