From 2beb260eb33e5f365b102a096fb0160c85f1ef24 Mon Sep 17 00:00:00 2001 From: Netkas Date: Mon, 13 Feb 2023 23:08:54 -0500 Subject: [PATCH] Added InputMedia --- src/TgBotLib/Objects/InputMedia.php | 302 ++++++++++++++++++ .../InputMedia/InputMediaAnimation.php | 258 +++++++++++++++ .../Objects/InputMedia/InputMediaAudio.php | 239 ++++++++++++++ .../Objects/InputMedia/InputMediaDocument.php | 205 ++++++++++++ .../Objects/InputMedia/InputMediaPhoto.php | 189 +++++++++++ .../Objects/InputMedia/InputMediaVideo.php | 278 ++++++++++++++++ 6 files changed, 1471 insertions(+) create mode 100644 src/TgBotLib/Objects/InputMedia.php create mode 100644 src/TgBotLib/Objects/InputMedia/InputMediaAnimation.php create mode 100644 src/TgBotLib/Objects/InputMedia/InputMediaAudio.php create mode 100644 src/TgBotLib/Objects/InputMedia/InputMediaDocument.php create mode 100644 src/TgBotLib/Objects/InputMedia/InputMediaPhoto.php create mode 100644 src/TgBotLib/Objects/InputMedia/InputMediaVideo.php diff --git a/src/TgBotLib/Objects/InputMedia.php b/src/TgBotLib/Objects/InputMedia.php new file mode 100644 index 0000000..85e486d --- /dev/null +++ b/src/TgBotLib/Objects/InputMedia.php @@ -0,0 +1,302 @@ +type; + } + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an + * HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new + * one using multipart/form-data under name. + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported + * server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and + * height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails + * can't be reused and can be only uploaded as a new file, so you can pass “attach://” + * if the thumbnail was uploaded using multipart/form-data under . + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string|null + */ + public function getThumb(): ?string + { + return $this->thumb; + } + + /** + * Optional. Caption of the video 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 video caption. + * + * @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 the caption, which can be specified instead of parse_mode + * + * @return MessageEntity[]|null + */ + public function getCaptionEntities(): ?array + { + return $this->caption_entities; + } + + /** + * Optional. Video width + * + * @return int|null + */ + public function getWidth(): ?int + { + return $this->width; + } + + /** + * Optional. Video height + * + * @return int|null + */ + public function getHeight(): ?int + { + return $this->height; + } + + /** + * Optional. Video duration in seconds + * + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * Optional. Performer of the audio + * + * @return string|null + */ + public function getPerformer(): ?string + { + return $this->performer; + } + + /** + * Optional. Title of the audio + * + * @return string|null + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * Optional. Pass True if the uploaded video is suitable for streaming + * + * @return bool + */ + public function isSupportsStreaming(): bool + { + return $this->supports_streaming; + } + + /** + * Optional. Pass True if the video needs to be covered with a spoiler animation + * + * @return bool + */ + public function isHasSpoiler(): bool + { + return $this->has_spoiler; + } + + /** + * Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data. + * Always True, if the document is sent as part of an album. + * + * @return bool + */ + public function isDisableContentTypeDetection(): bool + { + return $this->disable_content_type_detection; + } + + /** + * Returns an array representation of the object. + * + * @return array + */ + public function toArray(): array + { + $caption_entities = null; + if($this->caption_entities !== null) + { + $caption_entities = []; + foreach($this->caption_entities as $entity) + { + $caption_entities[] = $entity->toArray(); + } + } + + return [ + 'type' => $this->type, + 'media' => $this->media, + 'thumb' => $this->thumb, + 'caption' => $this->caption, + 'parse_mode' => $this->parse_mode, + 'caption_entities' => $caption_entities, + 'width' => $this->width, + 'height' => $this->height, + 'duration' => $this->duration, + 'performer' => $this->performer, + 'title' => $this->title, + 'supports_streaming' => $this->supports_streaming, + 'has_spoiler' => $this->has_spoiler, + 'disable_content_type_detection' => $this->disable_content_type_detection, + ]; + } + + /** + * Constructs a new object from an array representation. + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $caption_entities = null; + if($data['caption_entities'] !== null) + { + $caption_entities = []; + foreach($data['caption_entities'] as $entity) + { + $caption_entities[] = MessageEntity::fromArray($entity); + } + } + + $object = new self(); + $object->type = $data['type']; + $object->media = $data['media']; + $object->thumb = @$data['thumb'] ?? null; + $object->caption = @$data['caption'] ?? null; + $object->parse_mode = @$data['parse_mode'] ?? null; + $object->caption_entities = $caption_entities; + $object->width = @$data['width'] ?? null; + $object->height = @$data['height'] ?? null; + $object->duration = @$data['duration'] ?? null; + $object->performer = @$data['performer'] ?? null; + $object->title = @$data['title'] ?? null; + $object->supports_streaming = @$data['supports_streaming'] ?? false; + $object->has_spoiler = @$data['has_spoiler'] ?? false; + $object->disable_content_type_detection = @$data['disable_content_type_detection'] ?? false; + + return $object; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaAnimation.php b/src/TgBotLib/Objects/InputMedia/InputMediaAnimation.php new file mode 100644 index 0000000..3b17727 --- /dev/null +++ b/src/TgBotLib/Objects/InputMedia/InputMediaAnimation.php @@ -0,0 +1,258 @@ +type; + } + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP + * URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one + * using multipart/form-data under name. + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported + * server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and + * height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't + * be reused and can be only uploaded as a new file, so you can pass “attach://” if the + * thumbnail was uploaded using multipart/form-data under . + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string|null + */ + public function getThumb(): ?string + { + return $this->thumb; + } + + /** + * Optional. Caption of the animation to be sent, 0-1024 characters after entities parsing + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * Optional. Mode for parsing entities in the animation caption. + * + * @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 the caption, which can be specified instead of parse_mode + * + * @return MessageEntity[]|null + */ + public function getCaptionEntities(): ?array + { + return $this->caption_entities; + } + + /** + * Optional. Animation width + * + * @return int|null + */ + public function getWidth(): ?int + { + return $this->width; + } + + /** + * Optional. Animation height + * + * @return int|null + */ + public function getHeight(): ?int + { + return $this->height; + } + + /** + * Optional. Animation duration in seconds + * + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * Optional. Pass True if the animation needs to be covered with a spoiler animation + * + * @return bool + */ + public function isHasSpoiler(): bool + { + return $this->has_spoiler; + } + + /** + * Returns an array representation of the object. + * + * @return array + */ + public function toArray(): array + { + $caption_entities = null; + if ($this->caption_entities) + { + $caption_entities = []; + foreach ($this->caption_entities as $caption_entity) + { + $caption_entities[] = $caption_entity->toArray(); + } + } + + return [ + 'type' => $this->type, + 'media' => $this->media, + 'thumb' => $this->thumb, + 'caption' => $this->caption, + 'parse_mode' => $this->parse_mode, + 'caption_entities' => $caption_entities, + 'width' => $this->width, + 'height' => $this->height, + 'duration' => $this->duration, + 'has_spoiler' => $this->has_spoiler, + ]; + } + + /** + * Constructs object from an array representation. + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $caption_entities = null; + if ($data['caption_entities']) + { + $caption_entities = []; + foreach ($data['caption_entities'] as $caption_entity) + { + $caption_entities[] = MessageEntity::fromArray($caption_entity); + } + } + + $object = new static(); + $object->type = $data['type']; + $object->media = $data['media']; + $object->thumb = $data['thumb']; + $object->caption = $data['caption']; + $object->parse_mode = $data['parse_mode']; + $object->caption_entities = $caption_entities; + $object->width = $data['width']; + $object->height = $data['height']; + $object->duration = $data['duration']; + $object->has_spoiler = $data['has_spoiler']; + + return $object; + } + + /** + * Constructs object from InputMedia + * + * @param InputMedia $inputMedia + * @return InputMediaAnimation + */ + public static function fromInputMedia(InputMedia $inputMedia): InputMediaAnimation + { + $object = new static(); + + $object->type = $inputMedia->getType(); + $object->media = $inputMedia->getMedia(); + $object->thumb = $inputMedia->getThumb(); + $object->caption = $inputMedia->getCaption(); + $object->parse_mode = $inputMedia->getParseMode(); + $object->caption_entities = $inputMedia->getCaptionEntities(); + $object->width = $inputMedia->getWidth(); + $object->height = $inputMedia->getHeight(); + $object->duration = $inputMedia->getDuration(); + $object->has_spoiler = $inputMedia->isHasSpoiler(); + + return $object; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaAudio.php b/src/TgBotLib/Objects/InputMedia/InputMediaAudio.php new file mode 100644 index 0000000..b8f4a93 --- /dev/null +++ b/src/TgBotLib/Objects/InputMedia/InputMediaAudio.php @@ -0,0 +1,239 @@ +type; + } + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP + * URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one + * using multipart/form-data under name. + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported + * server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and + * height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't + * be reused and can be only uploaded as a new file, so you can pass “attach://” if the + * thumbnail was uploaded using multipart/form-data under . + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string|null + */ + public function getThumb(): ?string + { + return $this->thumb; + } + + /** + * Optional. Caption of the audio 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 audio caption. + * + * @return string|null + */ + 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. Duration of the audio in seconds + * + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * Optional. Performer of the audio + * + * @return string|null + */ + public function getPerformer(): ?string + { + return $this->performer; + } + + /** + * Optional. Title of the audio + * + * @return string|null + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + $caption_entities = null; + if ($this->caption_entities) + { + $caption_entities = []; + foreach ($this->caption_entities as $caption_entity) + { + $caption_entities[] = $caption_entity->toArray(); + } + } + + return [ + 'type' => $this->type, + 'media' => $this->media, + 'thumb' => $this->thumb, + 'caption' => $this->caption, + 'parse_mode' => $this->parse_mode, + 'caption_entities' => $caption_entities, + 'duration' => $this->duration, + 'performer' => $this->performer, + 'title' => $this->title + ]; + } + + /** + * Constructs object from an array representation + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $caption_entities = null; + if ($data['caption_entities']) + { + $caption_entities = []; + foreach ($data['caption_entities'] as $caption_entity) + { + $caption_entities[] = MessageEntity::fromArray($caption_entity); + } + } + + $object = new InputMediaAudio(); + $object->type = $data['type']; + $object->media = $data['media']; + $object->thumb = $data['thumb']; + $object->caption = $data['caption']; + $object->parse_mode = $data['parse_mode']; + $object->caption_entities = $caption_entities; + $object->duration = $data['duration']; + $object->performer = $data['performer']; + $object->title = $data['title']; + + return $object; + } + + /** + * Constructs object from an InputMedia object + * + * @param InputMedia $inputMedia + * @return InputMediaAudio + */ + public static function fromInputMedia(InputMedia $inputMedia): InputMediaAudio + { + $object = new InputMediaAudio(); + $object->type = $inputMedia->getType(); + $object->media = $inputMedia->getMedia(); + $object->thumb = $inputMedia->getThumb(); + $object->caption = $inputMedia->getCaption(); + $object->parse_mode = $inputMedia->getParseMode(); + $object->caption_entities = $inputMedia->getCaptionEntities(); + $object->duration = $inputMedia->getDuration(); + $object->performer = $inputMedia->getPerformer(); + $object->title = $inputMedia->getTitle(); + + return $object; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaDocument.php b/src/TgBotLib/Objects/InputMedia/InputMediaDocument.php new file mode 100644 index 0000000..12b66c2 --- /dev/null +++ b/src/TgBotLib/Objects/InputMedia/InputMediaDocument.php @@ -0,0 +1,205 @@ +type; + } + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP + * URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one + * using multipart/form-data under name. + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported + * server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and + * height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't + * be reused and can be only uploaded as a new file, so you can pass “attach://” if the + * thumbnail was uploaded using multipart/form-data under . + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string|null + */ + public function getThumb(): ?string + { + return $this->thumb; + } + + /** + * Optional. Caption of the document 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 document caption. + * + * @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 the caption, which can be specified instead of parse_mode + * + * @return MessageEntity[]|null + */ + public function getCaptionEntities(): ?array + { + return $this->caption_entities; + } + + /** + * Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data. + * Always True, if the document is sent as part of an album. + * + * @return bool + */ + public function isDisableContentTypeDetection(): bool + { + return $this->disable_content_type_detection; + } + + /** + * Returns an array representation of the object. + * + * @return array + */ + public function toArray(): array + { + $caption_entities = null; + if ($this->caption_entities) + { + $caption_entities = []; + foreach ($this->caption_entities as $caption_entity) + { + $caption_entities[] = $caption_entity->toArray(); + } + } + + return [ + 'type' => $this->type, + 'media' => $this->media, + 'thumb' => $this->thumb, + 'caption' => $this->caption, + 'parse_mode' => $this->parse_mode, + 'caption_entities' => $caption_entities, + 'disable_content_type_detection' => $this->disable_content_type_detection, + ]; + } + + /** + * Constructs object from an array representation. + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $caption_entities = null; + if (isset($data['caption_entities'])) + { + $caption_entities = []; + foreach ($data['caption_entities'] as $caption_entity) + { + $caption_entities[] = MessageEntity::fromArray($caption_entity); + } + } + + $object = new InputMediaDocument(); + $object->type = $data['type']; + $object->media = $data['media']; + $object->thumb = $data['thumb'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->caption_entities = $caption_entities; + $object->disable_content_type_detection = $data['disable_content_type_detection']; + + return $object; + } + + /** + * Constructs object from an InputMedia object. + * + * @param InputMedia $inputMedia + * @return InputMediaDocument + */ + public static function fromInputMedia(InputMedia $inputMedia): InputMediaDocument + { + $object = new InputMediaDocument(); + $object->type = $inputMedia->getType(); + $object->media = $inputMedia->getMedia(); + $object->thumb = $inputMedia->getThumb(); + $object->caption = $inputMedia->getCaption(); + $object->parse_mode = $inputMedia->getParseMode(); + $object->caption_entities = $inputMedia->getCaptionEntities(); + $object->disable_content_type_detection = $inputMedia->isDisableContentTypeDetection(); + + return $object; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaPhoto.php b/src/TgBotLib/Objects/InputMedia/InputMediaPhoto.php new file mode 100644 index 0000000..64863ea --- /dev/null +++ b/src/TgBotLib/Objects/InputMedia/InputMediaPhoto.php @@ -0,0 +1,189 @@ +type; + } + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP + * URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one + * using multipart/form-data under name. + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * 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 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 the caption, which can be specified instead of parse_mode + * + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->caption_entities; + } + + /** + * Optional. Pass True if the photo needs to be covered with a spoiler animation + * + * @return bool + */ + public function isHasSpoiler(): bool + { + return $this->has_spoiler; + } + + /** + * Returns an array representation of the object. + * + * @return array + */ + public function toArray(): array + { + $caption_entities = null; + if ($this->caption_entities) + { + $caption_entities = []; + foreach ($this->caption_entities as $caption_entity) + { + $caption_entities[] = $caption_entity->toArray(); + } + } + + return [ + 'type' => $this->type, + 'media' => $this->media, + 'caption' => $this->caption, + 'parse_mode' => $this->parse_mode, + 'caption_entities' => $caption_entities, + 'has_spoiler' => $this->has_spoiler, + ]; + } + + /** + * Constructs the object from an array + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + + $object->type = $data['type']; + $object->media = $data['media']; + $object->caption = $data['caption']; + $object->parse_mode = $data['parse_mode']; + $object->has_spoiler = $data['has_spoiler']; + + if (isset($data['caption_entities'])) + { + $object->caption_entities = []; + foreach ($data['caption_entities'] as $caption_entity) + { + $object->caption_entities[] = MessageEntity::fromArray($caption_entity); + } + } + + return $object; + } + + /** + * Constructs object from InputMedia + * + * @param InputMedia $inputMedia + * @return InputMediaPhoto + */ + public static function fromInputMedia(InputMedia $inputMedia): InputMediaPhoto + { + $object = new self(); + + $object->type = $inputMedia->getType(); + $object->media = $inputMedia->getMedia(); + $object->caption = $inputMedia->getCaption(); + $object->parse_mode = $inputMedia->getParseMode(); + $object->has_spoiler = $inputMedia->isHasSpoiler(); + + if ($inputMedia->getCaptionEntities()) + { + $object->caption_entities = []; + foreach ($inputMedia->getCaptionEntities() as $caption_entity) + { + $object->caption_entities[] = MessageEntity::fromArray($caption_entity); + } + } + + return $object; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/InputMedia/InputMediaVideo.php b/src/TgBotLib/Objects/InputMedia/InputMediaVideo.php new file mode 100644 index 0000000..53bd21c --- /dev/null +++ b/src/TgBotLib/Objects/InputMedia/InputMediaVideo.php @@ -0,0 +1,278 @@ +type; + } + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP + * URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one + * using multipart/form-data under name. + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported + * server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and + * height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't + * be reused and can be only uploaded as a new file, so you can pass “attach://” if the + * thumbnail was uploaded using multipart/form-data under . + * + * @see https://core.telegram.org/bots/api#sending-files + * @return string|null + */ + public function getThumb(): ?string + { + return $this->thumb; + } + + /** + * Optional. Caption of the video 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 video caption. + * + * @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 the caption, which can be specified instead of parse_mode + * + * @return MessageEntity[]|null + */ + public function getCaptionEntities(): ?array + { + return $this->caption_entities; + } + + /** + * Optional. Video width + * + * @return int|null + */ + public function getWidth(): ?int + { + return $this->width; + } + + /** + * Optional. Video height + * + * @return int|null + */ + public function getHeight(): ?int + { + return $this->height; + } + + /** + * Optional. Video duration in seconds + * + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * Optional. Pass True if the uploaded video is suitable for streaming + * + * @return bool + */ + public function isSupportsStreaming(): bool + { + return $this->supports_streaming; + } + + /** + * Optional. Pass True if the video needs to be covered with a spoiler animation + * + * @return bool + */ + public function isHasSpoiler(): bool + { + return $this->has_spoiler; + } + + /** + * Returns an array representation of the object. + * + * @return array + */ + public function toArray(): array + { + $caption_entities = null; + if($this->getCaptionEntities() !== null) + { + $caption_entities = []; + foreach ($this->getCaptionEntities() as $caption_entity) + { + $caption_entities[] = $caption_entity->toArray(); + } + } + + return [ + 'type' => $this->type, + 'media' => $this->media, + 'thumb' => $this->thumb, + 'caption' => $this->caption, + 'parse_mode' => $this->parse_mode, + 'caption_entities' => $caption_entities, + 'width' => $this->width, + 'height' => $this->height, + 'duration' => $this->duration, + 'supports_streaming' => $this->supports_streaming, + 'has_spoiler' => $this->has_spoiler, + ]; + } + + /** + * Constructs object from an array representation. + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $caption_entities = null; + if($data['caption_entities'] !== null) + { + $caption_entities = []; + foreach ($data['caption_entities'] as $caption_entity) + { + $caption_entities[] = MessageEntity::fromArray($caption_entity); + } + } + + $object = new InputMediaVideo(); + + $object->type = $data['type']; + $object->media = $data['media']; + $object->thumb = @$data['thumb'] ?? null; + $object->caption = @$data['caption'] ?? null; + $object->parse_mode = @$data['parse_mode'] ?? null; + $object->caption_entities = $caption_entities; + $object->width = @$data['width'] ?? null; + $object->height = @$data['height'] ?? null; + $object->duration = @$data['duration'] ?? null; + $object->supports_streaming = @$data['supports_streaming'] ?? false; + $object->has_spoiler = @$data['has_spoiler'] ?? false; + + return $object; + } + + /** + * Constructs object from an InputMedia object. + * + * @param InputMedia $inputMedia + * @return InputMediaVideo + */ + public static function fromInputMedia(InputMedia $inputMedia): InputMediaVideo + { + $object = new InputMediaVideo(); + + $object->type = $inputMedia->getType(); + $object->media = $inputMedia->getMedia(); + $object->thumb = $inputMedia->getThumb(); + $object->caption = $inputMedia->getCaption(); + $object->parse_mode = $inputMedia->getParseMode(); + $object->caption_entities = $inputMedia->getCaptionEntities(); + $object->width = $inputMedia->getWidth(); + $object->height = $inputMedia->getHeight(); + $object->duration = $inputMedia->getDuration(); + $object->supports_streaming = $inputMedia->isSupportsStreaming(); + $object->has_spoiler = $inputMedia->isHasSpoiler(); + + return $object; + } + } \ No newline at end of file