diff --git a/CHANGELOG.md b/CHANGELOG.md index 310a1c1..46d99b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ input objects for methods that require input objects. * Added object `\TgBotLib\Objects\Telegram\InputMessageContent > InputInvoiceMessageContent` to represent the content of an invoice message to be sent as the result of an inline query. * Added new exception class `NotImplementedException` to represent the case when a method is not implemented yet or the method is not applicable to the current object. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultArticle`, see [InlineQueryResultArticle](https://core.telegram.org/bots/api#inlinequeryresultarticle) for more information. - * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultPhoto`, see [InlineQueryResultPhoto](https://core.telegram.org/bots/api#inlinequeryresultphoto) for more information. + * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultPhoto`, see [InlineQueryResultPhoto](hthttps://git.n64.cc/nosial/libs/tgbot/-/issues/3https://git.n64.cc/nosial/libs/tgbot/-/issues/3tps://core.telegram.org/bots/api#inlinequeryresultphoto) for more information. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGif`, see [InlineQueryResultGif](https://core.telegram.org/bots/api#inlinequeryresultgif) for more information. * Added abstract class `\TgBotLib\Abstracts\ThumbnailMimeType` to represent the mime type of thumbnail, photo, or a file / sticker thumbnail. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultMpeg4Gif`, see [InlineQueryResultMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif) for more information. @@ -27,6 +27,7 @@ input objects for methods that require input objects. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultAudio`, see [InlineQueryResultAudio](https://core.telegram.org/bots/api#inlinequeryresultaudio) for more information. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVoice`, see [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice) for more information. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument`, see [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument) for more information. + * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultLocation`, see [InlineQueryResultLocation](https://core.telegram.org/bots/api#inlinequeryresultlocation) for more information. ### Changed * Refactored InputMessageContent types to its own namespace so InputMessageContent can always return the correct InputMessageContent object type when calling `fromArray()` diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultLocation.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultLocation.php new file mode 100644 index 0000000..437fc63 --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultLocation.php @@ -0,0 +1,288 @@ +type = 'location'; + } + + /** + * Type of the result, must be location + * + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * Unique identifier for this result, 1-64 Bytes + * + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * Location latitude in degrees + * + * @return float + */ + public function getLatitude(): float + { + return $this->latitude; + } + + /** + * Location longitude in degrees + * + * @return float + */ + public function getLongitude(): float + { + return $this->longitude; + } + + /** + * Location title + * + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + * + * @return float|null + */ + public function getHorizontalAccuracy(): ?float + { + return $this->horizontal_accuracy; + } + + /** + * Optional. Period in seconds for which the location can be updated, should be between 60 and 86400. + * + * @return int|null + */ + public function getLivePeriod(): ?int + { + return $this->live_period; + } + + /** + * Optional. For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. + * + * @return int|null + */ + public function getHeading(): ?int + { + return $this->heading; + } + + /** + * Optional. For live locations, a maximum distance for proximity alerts about + * approaching another chat member, in meters. Must be between 1 and 100000 if specified. + * + * @return int|null + */ + public function getProximityAlertRadius(): ?int + { + return $this->proximity_alert_radius; + } + + /** + * Optional. Inline keyboard attached to the message + * + * @return InlineKeyboardMarkup|null + */ + public function getReplyMarkup(): ?InlineKeyboardMarkup + { + return $this->reply_markup; + } + + /** + * Optional. Content of the message to be sent instead of the location + * + * @return InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null + */ + public function getInputMessageContent(): InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null + { + return $this->input_message_content; + } + + /** + * Optional. Url of the thumbnail for the result + * + * @return string|null + */ + public function getThumbnailUrl(): ?string + { + return $this->thumbnail_url; + } + + /** + * Optional. Thumbnail width + * + * @return int|null + */ + public function getThumbnailWidth(): ?int + { + return $this->thumbnail_width; + } + + /** + * Optional. Thumbnail height + * + * @return int|null + */ + public function getThumbnailHeight(): ?int + { + return $this->thumbnail_height; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'id' => $this->id, + 'latitude' => $this->latitude, + 'longitude' => $this->longitude, + 'title' => $this->title, + 'horizontal_accuracy' => $this->horizontal_accuracy, + 'live_period' => $this->live_period, + 'heading' => $this->heading, + 'proximity_alert_radius' => $this->proximity_alert_radius, + 'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null, + 'input_message_content' => ($this->input_message_content instanceof InputContactMessageContent) ? $this->input_message_content->toArray() : null, + 'thumbnail_url' => $this->thumbnail_url, + 'thumbnail_width' => $this->thumbnail_width, + 'thumbnail_height' => $this->thumbnail_height, + ]; + } + + /** + * Constructs the object from an array representation. + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + + $object->type = $data['type'] ?? null; + $object->id = $data['id'] ?? null; + $object->latitude = $data['latitude'] ?? null; + $object->longitude = $data['longitude'] ?? null; + $object->title = $data['title'] ?? null; + $object->horizontal_accuracy = $data['horizontal_accuracy'] ?? null; + $object->live_period = $data['live_period'] ?? null; + $object->heading = $data['heading'] ?? null; + $object->proximity_alert_radius = $data['proximity_alert_radius'] ?? null; + $object->reply_markup = ($data['reply_markup'] ?? null) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null; + $object->input_message_content = ($data['input_message_content'] ?? null) ? InputContactMessageContent::fromArray($data['input_message_content']) : null; + $object->thumbnail_url = $data['thumbnail_url'] ?? null; + $object->thumbnail_width = $data['thumbnail_width'] ?? null; + $object->thumbnail_height = $data['thumbnail_height'] ?? null; + + return $object; + } + } \ No newline at end of file