diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult.php index b306e65..de557f1 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult.php @@ -31,7 +31,7 @@ */ public function toArray(): array { - throw new NotImplementedException(sprintf('This object is abstract, you can\'t use it directly, try constructing one of the child classes with fromArray()')); + throw new NotImplementedException('This object is abstract, you can\'t use it directly, try constructing one of the child classes with fromArray()'); } /** @@ -47,34 +47,21 @@ throw new InvalidArgumentException('The type of the InlineQueryResult is not set, this is required!'); } - switch(strtolower($data['type'])) + return match (strtolower($data['type'])) { - case InlineQueryResultType::ARTICLE: - return InlineQueryResultArticle::fromArray($data); - case InlineQueryResultType::PHOTO: - return InlineQueryResultPhoto::fromArray($data); - case InlineQueryResultType::GIF: - return InlineQueryResultGif::fromArray($data); - case InlineQueryResultType::MPEG_4_GIF: - return InlineQueryResultMpeg4Gif::fromArray($data); - case InlineQueryResultType::VIDEO: - return InlineQueryResultVideo::fromArray($data); - case InlineQueryResultType::AUDIO: - return InlineQueryResultAudio::fromArray($data); - case InlineQueryResultType::VOICE: - return InlineQueryResultVoice::fromArray($data); - case InlineQueryResultType::DOCUMENT: - return InlineQueryResultDocument::fromArray($data); - case InlineQueryResultType::LOCATION: - return InlineQueryResultLocation::fromArray($data); - case InlineQueryResultType::VENUE: - return InlineQueryResultVenue::fromArray($data); - case InlineQueryResultType::CONTACT: - return InlineQueryResultContact::fromArray($data); - case InlineQueryResultType::GAME: - return InlineQueryResultGame::fromArray($data); - default: - throw new InvalidArgumentException(sprintf('The type of the InlineQueryResult is invalid, got "%s", expected one of "%s"', $data['type'], implode('", "', InlineQueryResultType::ALL))); - } + InlineQueryResultType::ARTICLE => InlineQueryResultArticle::fromArray($data), + InlineQueryResultType::PHOTO => InlineQueryResultPhoto::fromArray($data), + InlineQueryResultType::GIF => InlineQueryResultGif::fromArray($data), + InlineQueryResultType::MPEG_4_GIF => InlineQueryResultMpeg4Gif::fromArray($data), + InlineQueryResultType::VIDEO => InlineQueryResultVideo::fromArray($data), + InlineQueryResultType::AUDIO => InlineQueryResultAudio::fromArray($data), + InlineQueryResultType::VOICE => InlineQueryResultVoice::fromArray($data), + InlineQueryResultType::DOCUMENT => InlineQueryResultDocument::fromArray($data), + InlineQueryResultType::LOCATION => InlineQueryResultLocation::fromArray($data), + InlineQueryResultType::VENUE => InlineQueryResultVenue::fromArray($data), + InlineQueryResultType::CONTACT => InlineQueryResultContact::fromArray($data), + InlineQueryResultType::GAME => InlineQueryResultGame::fromArray($data), + default => throw new InvalidArgumentException(sprintf('The type of the InlineQueryResult is invalid, got "%s", expected one of "%s"', $data['type'], implode('", "', InlineQueryResultType::ALL))), + }; } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultLocation.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultLocation.php index 98af737..7d7f57c 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultLocation.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultLocation.php @@ -4,6 +4,7 @@ namespace TgBotLib\Objects\Telegram\InlineQueryResult; + use InvalidArgumentException; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\InlineKeyboardMarkup; use TgBotLib\Objects\Telegram\InputMessageContent\InputContactMessageContent; @@ -112,6 +113,23 @@ return $this->id; } + /** + * Sets a unique identifier for this result, 1-64 Bytes + * + * @param string $id + * @return $this + */ + public function setId(string $id): InlineQueryResultLocation + { + if(strlen($id) > 64) + { + throw new InvalidArgumentException('id should be less than 64 characters'); + } + + $this->id = $id; + return $this; + } + /** * Location latitude in degrees * @@ -122,6 +140,18 @@ return $this->latitude; } + /** + * Sets the location latitude in degrees + * + * @param float $latitude + * @return $this + */ + public function setLatitude(float $latitude): InlineQueryResultLocation + { + $this->latitude = $latitude; + return $this; + } + /** * Location longitude in degrees * @@ -132,6 +162,18 @@ return $this->longitude; } + /** + * Sets the location longitude in degrees + * + * @param float $longitude + * @return $this + */ + public function setLongitude(float $longitude): InlineQueryResultLocation + { + $this->longitude = $longitude; + return $this; + } + /** * Location title * @@ -142,6 +184,18 @@ return $this->title; } + /** + * Sets the location title + * + * @param string $title + * @return $this + */ + public function setTitle(string $title): InlineQueryResultLocation + { + $this->title = $title; + return $this; + } + /** * Optional. The radius of uncertainty for the location, measured in meters; 0-1500 * @@ -153,7 +207,25 @@ } /** - * Optional. Period in seconds for which the location can be updated should be between 60 and 86400. + * Sets the radius of uncertainty for the location, measured in meters; 0-1500 + * + * @param float|null $horizontal_accuracy + * @return $this + */ + public function setHorizontalAccuracy(?float $horizontal_accuracy): InlineQueryResultLocation + { + if($horizontal_accuracy < 0 || $horizontal_accuracy > 1500) + { + throw new InvalidArgumentException('horizontal_accuracy should be between 0 and 1500'); + } + + $this->horizontal_accuracy = $horizontal_accuracy; + return $this; + } + + + /** + * Optional. The Period in seconds for which the location can be updated should be between 60 and 86400. * * @return int|null */ @@ -162,6 +234,23 @@ return $this->live_period; } + /** + * Sets the period in seconds for which the location can be updated should be between 60 and 86400. + * + * @param int|null $live_period + * @return $this + */ + public function setLivePeriod(?int $live_period): InlineQueryResultLocation + { + if($live_period < 60 || $live_period > 86400) + { + throw new InvalidArgumentException('live_period should be between 60 and 86400'); + } + + $this->live_period = $live_period; + return $this; + } + /** * Optional. For live locations, the direction in which the user is moving, in degrees. It Must be between 1 and 360 if specified. * @@ -172,6 +261,23 @@ return $this->heading; } + /** + * Sets the direction in which the user is moving, in degrees. It Must be between 1 and 360 if specified. + * + * @param int|null $heading + * @return $this + */ + public function setHeading(?int $heading): InlineQueryResultLocation + { + if($heading < 1 || $heading > 360) + { + throw new InvalidArgumentException('heading should be between 1 and 360'); + } + + $this->heading = $heading; + return $this; + } + /** * Optional. For live locations, a maximum distance for proximity alerts about * approaching another chat member, in meters. It Must be between 1 and 100000 if specified. @@ -183,6 +289,23 @@ return $this->proximity_alert_radius; } + /** + * Sets the maximum distance for proximity alerts about approaching another chat member, in meters. + * + * @param int|null $proximity_alert_radius + * @return $this + */ + public function setProximityAlertRadius(?int $proximity_alert_radius): InlineQueryResultLocation + { + if($proximity_alert_radius < 1 || $proximity_alert_radius > 100000) + { + throw new InvalidArgumentException('proximity_alert_radius should be between 1 and 100000'); + } + + $this->proximity_alert_radius = $proximity_alert_radius; + return $this; + } + /** * Optional. Inline keyboard attached to the message * @@ -193,6 +316,18 @@ return $this->reply_markup; } + /** + * Sets the inline keyboard attached to the message + * + * @param InlineKeyboardMarkup|null $reply_markup + * @return $this + */ + public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultLocation + { + $this->reply_markup = $reply_markup; + return $this; + } + /** * Optional. Content of the message to be sent instead of the location * @@ -203,6 +338,18 @@ return $this->input_message_content; } + /** + * Sets the content of the message to be sent instead of the location + * + * @param InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null $input_message_content + * @return $this + */ + public function setInputMessageContent(null|InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent $input_message_content): InlineQueryResultLocation + { + $this->input_message_content = $input_message_content; + return $this; + } + /** * Optional. Url of the thumbnail for the result * @@ -213,6 +360,18 @@ return $this->thumbnail_url; } + /** + * Sets the url of the thumbnail for the result + * + * @param string|null $thumbnail_url + * @return $this + */ + public function setThumbnailUrl(?string $thumbnail_url): InlineQueryResultLocation + { + $this->thumbnail_url = $thumbnail_url; + return $this; + } + /** * Optional. Thumbnail width * @@ -223,6 +382,18 @@ return $this->thumbnail_width; } + /** + * Sets the thumbnail width + * + * @param int|null $thumbnail_width + * @return $this + */ + public function setThumbnailWidth(?int $thumbnail_width): InlineQueryResultLocation + { + $this->thumbnail_width = $thumbnail_width; + return $this; + } + /** * Optional. Thumbnail height * @@ -233,6 +404,18 @@ return $this->thumbnail_height; } + /** + * Sets the thumbnail height + * + * @param int|null $thumbnail_height + * @return $this + */ + public function setThumbnailHeight(?int $thumbnail_height): InlineQueryResultLocation + { + $this->thumbnail_height = $thumbnail_height; + return $this; + } + /** * Returns an array representation of the object *