From ed41bcea2f1b6f724f1ae6344711da800b60e237 Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 23 Apr 2023 14:42:51 -0400 Subject: [PATCH] Added object `\TgBotLib\Objects\Telegram > InputTextMessageContent` to represent the content of a text message to be sent as the result of an inline query. --- .idea/php.xml | 3 +- CHANGELOG.md | 3 + .../Telegram/InputTextMessageContent.php | 127 ++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/TgBotLib/Objects/Telegram/InputTextMessageContent.php diff --git a/.idea/php.xml b/.idea/php.xml index a8ba4b8..14e3c93 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -9,12 +9,13 @@ + - + diff --git a/CHANGELOG.md b/CHANGELOG.md index 0df67ee..f208e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This update accompanies the release of the [Telegram Bot API 6.7](https://core.telegram.org/bots/api#april-21-2023). +### Added + * Added object `\TgBotLib\Objects\Telegram > InputTextMessageContent` to represent the content of a text message to be sent as the result of an inline query. + ## [6.6.0] - 2023-04-10 diff --git a/src/TgBotLib/Objects/Telegram/InputTextMessageContent.php b/src/TgBotLib/Objects/Telegram/InputTextMessageContent.php new file mode 100644 index 0000000..f7ba609 --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/InputTextMessageContent.php @@ -0,0 +1,127 @@ +message_text; + } + + /** + * Optional. Mode for parsing entities in the message text. + * + * @see https://core.telegram.org/bots/api#formatting-options + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parse_mode; + } + + /** + * Optional. List of special entities that appear in message text, which can be specified instead of parse_mode + * + * @return MessageEntity[]|null + */ + public function getEntities(): ?array + { + return $this->entities; + } + + /** + * Optional. Disables link previews for links in the sent message + * + * @return bool + */ + public function isDisableWebPagePreview(): bool + { + return $this->disable_web_page_preview; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + $message_entities = null; + + if($this->entities !== null) + { + /** @var MessageEntity $entity */ + foreach($this->entities as $entity) + { + if($entity instanceof MessageEntity) + { + $message_entities[] = $entity->toArray(); + } + } + + } + + + return [ + 'message_text' => $this->message_text, + 'parse_mode' => $this->parse_mode, + 'entities' => $message_entities, + 'disable_web_page_preview' => $this->disable_web_page_preview, + ]; + } + + /** + * Constructs object from an array representation + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + + $object->message_text = $data['message_text'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->disable_web_page_preview = (bool)$data['disable_web_page_preview'] ?? false; + + if(isset($data['entities'])) + { + foreach($data['entities'] as $entity) + { + $object->entities[] = MessageEntity::fromArray($entity); + } + } + + return $object; + } + } \ No newline at end of file