diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b3c24d..6bb1340 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ input objects for methods that require input objects. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultMpeg4Gif`, see [InlineQueryResultMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif) for more information. * 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. ### 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/InlineQueryResultAudio.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultAudio.php new file mode 100644 index 0000000..3d73208 --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultAudio.php @@ -0,0 +1,233 @@ +type; + } + + /** + * Unique identifier for this result, 1-64 bytes + * + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * A valid URL for the audio file + * + * @return string + */ + public function getAudioUrl(): string + { + return $this->audio_url; + } + + /** + * 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 audio 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. Performer + * + * @return string|null + */ + public function getPerformer(): ?string + { + return $this->performer; + } + + /** + * Optional. Audio duration in seconds + * + * @return int|null + */ + public function getAudioDuration(): ?int + { + return $this->audio_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 audio + * + * @return InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null + */ + public function getInputMessageContent(): InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null + { + return $this->input_message_content; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'id' => $this->id, + 'audio_url' => $this->audio_url, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parse_mode, + 'caption_entities' => ($this->caption_entities) ? array_map(function (MessageEntity $messageEntity) { + return $messageEntity->toArray(); + }, $this->caption_entities) : null, + 'performer' => $this->performer, + 'audio_duration' => $this->audio_duration, + 'reply_markup' => ($this->reply_markup) ? $this->reply_markup->toArray() : null, + 'input_message_content' => $this->input_message_content, + ]; + } + + /** + * 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->audio_url = $data['audio_url'] ?? null; + $object->title = $data['title'] ?? null; + $object->caption = $data['caption'] ?? null; + $object->parse_mode = $data['parse_mode'] ?? null; + $object->caption_entities = ($data['caption_entities']) ? array_map(function (array $messageEntity) { + return MessageEntity::fromArray($messageEntity); + }, $data['caption_entities']) : null; + $object->performer = $data['performer'] ?? null; + $object->audio_duration = $data['audio_duration'] ?? null; + $object->reply_markup = ($data['reply_markup']) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null; + $object->input_message_content = $data['input_message_content'] ?? null; + + return $object; + } + } \ No newline at end of file