From d14ee4eae47d171305105796ba69ce56ebfe1a90 Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 23 Apr 2023 20:49:24 -0400 Subject: [PATCH] Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVoice`, see [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice) for more information. https://git.n64.cc/nosial/libs/tgbot/-/issues/3 --- CHANGELOG.md | 1 + .../InlineQueryResultVoice.php | 222 ++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultVoice.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bb1340..0f82fe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ input objects for methods that require input objects. * Added field `via_chat_folder_invite_link` to `\TgBotLib\Objects\Telegram\ChatMemberUpdated` to represent the invite link, which was used by the user to join the chat; for joining by invite link events only. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVideo`, see [InlineQueryResultVideo](https://core.telegram.org/bots/api#inlinequeryresultvideo) for more information. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultAudio`, see [InlineQueryResultAudio](https://core.telegram.org/bots/api#inlinequeryresultaudio) for more information. + * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVoice`, see [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice) 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/InlineQueryResultVoice.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultVoice.php new file mode 100644 index 0000000..376c75e --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultVoice.php @@ -0,0 +1,222 @@ +type; + } + + /** + * Unique identifier for this result, 1-64 bytes + * + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * A valid URL for the voice recording + * + * @return string + */ + public function getVoiceUrl(): string + { + return $this->voice_url; + } + + /** + * Recording title + * + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * Optional. Caption, 0-1024 characters after entities parsing + * + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * Optional. Mode for parsing entities in the voice message caption. See formatting options for more details. + * + * @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. Recording duration in seconds + * + * @return int|null + */ + public function getVoiceDuration(): ?int + { + return $this->voice_duration; + } + + /** + * 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 voice recording + * + * @return InputMessageContent|null + */ + public function getInputMessageContent(): ?InputMessageContent + { + return $this->input_message_content; + } + + /** + * Returns an array representation of the object. + * + * @return array + * @throws \TgBotLib\Exceptions\NotImplementedException + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'id' => $this->id, + 'voice_url' => $this->voice_url, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parse_mode, + 'caption_entities' => (function (array $data) { + $result = []; + foreach ($data as $item) { + $result[] = $item->toArray(); + } + return $result; + })($this->caption_entities ?? null), + 'voice_duration' => $this->voice_duration, + 'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null, + 'input_message_content' => ($this->input_message_content instanceof InputMessageContent) ? $this->input_message_content->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->voice_url = $data['voice_url'] ?? null; + $object->title = $data['title'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->caption_entities = (function (array $data) { + $result = []; + foreach ($data as $item) + { + $result[] = MessageEntity::fromArray($item); + } + return $result; + })($data['caption_entities'] ?? []); + $object->voice_duration = $data['voice_duration'] ?? null; + $object->reply_markup = InlineKeyboardMarkup::fromArray($data['reply_markup'] ?? []); + $object->input_message_content = InputMessageContent::fromArray($data['input_message_content'] ?? []); + + return $object; + } + } \ No newline at end of file