From 0626df6a35d2157695be24ddf44d52f6112e1476 Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 12 Feb 2023 16:34:51 -0500 Subject: [PATCH] Added \TgBotLib\Objects > MessageEntity --- src/TgBotLib/Objects/MessageEntity.php | 161 +++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 src/TgBotLib/Objects/MessageEntity.php diff --git a/src/TgBotLib/Objects/MessageEntity.php b/src/TgBotLib/Objects/MessageEntity.php new file mode 100644 index 0000000..9b23003 --- /dev/null +++ b/src/TgBotLib/Objects/MessageEntity.php @@ -0,0 +1,161 @@ +type; + } + + /** + * Offset in UTF-16 code units to the start of the entity + * + * @see https://telegram.org/blog/edit#new-mentions + * @return int + */ + public function getOffset(): int + { + return $this->offset; + } + + /** + * Offset in UTF-16 code units to the start of the entity + * + * @see https://core.telegram.org/api/entities#entity-length + * @return int + */ + public function getLength(): int + { + return $this->length; + } + + /** + * Optional. For “text_link” only, URL that will be opened after user taps on the text + * + * @return string|null + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * Optional. For “text_mention” only, the mentioned user + * + * @return User|null + */ + public function getUser(): ?User + { + return $this->user; + } + + /** + * Optional. For “pre” only, the programming language of the entity text + * + * @return string|null + */ + public function getLanguage(): ?string + { + return $this->language; + } + + /** + * Optional. For “custom_emoji” only, unique identifier of the custom emoji. Use getCustomEmojiStickers to get + * full information about the sticker + * + * @see https://core.telegram.org/bots/api#getcustomemojistickers + * @return string|null + */ + public function getCustomEmojiId(): ?string + { + return $this->custom_emoji_id; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'type' => $this->type ?? null, + 'offset' => $this->offset ?? null, + 'length' => $this->length ?? null, + 'url' => $this->url ?? null, + 'user' => ($this->user instanceof User) ? $this->user->toArray() : null, + 'language' => $this->language ?? null, + 'custom_emoji_id' => $this->custom_emoji_id ?? 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->offset = $data['offset'] ?? null; + $object->length = $data['length'] ?? null; + $object->url = $data['url'] ?? null; + $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; + $object->language = $data['language'] ?? null; + $object->custom_emoji_id = $data['custom_emoji_id'] ?? null; + + return $object; + } + } \ No newline at end of file