From 79446bfcbdf74c3f6f2fa181c6ad63d28ae5b61c Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 23 Apr 2023 18:02:54 -0400 Subject: [PATCH] Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultPhoto`, see [InlineQueryResultPhoto](https://core.telegram.org/bots/api#inlinequeryresultphoto) for more information. --- CHANGELOG.md | 1 + .../InlineQueryResultPhoto.php | 268 ++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultPhoto.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 681b46a..1ec669d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +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. ### 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/InlineQueryResultPhoto.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultPhoto.php new file mode 100644 index 0000000..694e0f5 --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultPhoto.php @@ -0,0 +1,268 @@ +type; + } + + /** + * Unique identifier for this result, 1-64 bytes + * + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * A valid URL of the photo. Photo must be in JPEG format. Photo size must not exceed 5MB + * + * @return string + */ + public function getPhotoUrl(): string + { + return $this->photo_url; + } + + /** + * URL of the thumbnail for the photo + * + * @return string + */ + public function getThumbnailUrl(): string + { + return $this->thumbnail_url; + } + + /** + * Optional. Width of the photo + * + * @return int|null + */ + public function getPhotoWidth(): ?int + { + return $this->photo_width; + } + + /** + * Optional. Height of the photo + * + * @return int|null + */ + public function getPhotoHeight(): ?int + { + return $this->photo_height; + } + + /** + * Optional. Title for the result + * + * @return string|null + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * Optional. Short description of the result + * + * @return string|null + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing + * + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * Optional. Mode for parsing entities in the photo caption. See formatting options for more details. + * + * @return string|null + * @link https://core.telegram.org/bots/api#formatting-options + */ + public function getParseMode(): ?string + { + return $this->parse_mode; + } + + /** + * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + * + * @return MessageEntity[]|null + */ + public function getCaptionEntities(): ?array + { + return $this->caption_entities; + } + + /** + * 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 photo + * + * @return InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null + */ + public function getInputMessageContent(): InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null + { + return $this->input_message_content; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'id' => $this->id, + 'photo_url' => $this->photo_url, + 'thumbnail_url' => $this->thumbnail_url, + 'photo_width' => $this->photo_width ?? null, + 'photo_height' => $this->photo_height ?? null, + 'title' => $this->title ?? null, + 'description' => $this->description ?? null, + 'caption' => $this->caption ?? null, + 'parse_mode' => $this->parse_mode ?? null, + 'caption_entities' => ($this->caption_entities !== null) ? array_map(function (MessageEntity $messageEntity) { + return $messageEntity->toArray(); + }, $this->caption_entities) : null, + 'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null, + ]; + } + + /** + * Constructs 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->photo_url = $data['photo_url'] ?? null; + $object->thumbnail_url = $data['thumbnail_url'] ?? null; + $object->photo_width = $data['photo_width'] ?? null; + $object->photo_height = $data['photo_height'] ?? null; + $object->title = $data['title'] ?? null; + $object->description = $data['description'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->caption_entities = ($data['caption_entities'] !== null) ? array_map(function (array $messageEntity) + { + return MessageEntity::fromArray($messageEntity); + }, $data['caption_entities']) : null; + $object->reply_markup = ($data['reply_markup'] !== null) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null; + $object->input_message_content = $data['input_message_content'] ?? null; + + return $object; + } + } \ No newline at end of file