diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f67f6b..681b46a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ # Changelog All notable changes to this project will be documented in this file. - The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). @@ -18,6 +17,7 @@ input objects for methods that require input objects. * Added object `\TgBotLib\Objects\Telegram\InputMessageContent > InputContactMessageContent` to represent the content of a contact message to be sent as the result of an inline query. * 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. ### 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/InlineQueryResultArticle.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultArticle.php new file mode 100644 index 0000000..dad65c1 --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultArticle.php @@ -0,0 +1,228 @@ +type; + } + + /** + * Unique identifier for this result, 1-64 Bytes + * + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * Title of the result + * + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * Content of the message to be sent + * + * @return InputContactMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null + */ + public function getInputMessageContent(): InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|null + { + return $this->input_message_content; + } + + /** + * Optional. Inline keyboard attached to the message + * + * @return InlineKeyboardMarkup|null + */ + public function getReplyMarkup(): ?InlineKeyboardMarkup + { + return $this->reply_markup; + } + + /** + * Optional. URL of the result + * + * @return string|null + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * Optional. Pass True if you don't want the URL to be shown in the message + * + * @return bool + */ + public function isHideUrl(): bool + { + return $this->hide_url; + } + + /** + * Optional. Short description of the result + * + * @return string|null + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * 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, + 'title' => $this->title, + 'input_message_content' => ($this->input_message_content instanceof ObjectTypeInterface) ? $this->input_message_content->toArray() : null, + 'reply_markup' => ($this->reply_markup instanceof ObjectTypeInterface) ? $this->reply_markup->toArray() : null, + 'url' => $this->url, + 'hide_url' => $this->hide_url, + 'description' => $this->description, + 'thumb_url' => $this->thumbnail_url, + 'thumb_width' => $this->thumbnail_width, + 'thumb_height' => $this->thumbnail_height + ]; + } + + /** + * 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->title = $data['title'] ?? null; + $object->input_message_content = InputMessageContent::fromArray($data['input_message_content'] ?? []); + $object->reply_markup = InlineKeyboardMarkup::fromArray($data['reply_markup'] ?? []); + $object->url = $data['url'] ?? null; + $object->hide_url = $data['hide_url'] ?? null; + $object->description = $data['description'] ?? null; + $object->thumbnail_url = $data['thumb_url'] ?? null; + $object->thumbnail_width = (int)$data['thumb_width'] ?? null; + $object->thumbnail_height = (int)$data['thumb_height'] ?? null; + + return $object; + } + } \ No newline at end of file