Added object \TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument, see [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument) for more information.

https://git.n64.cc/nosial/libs/tgbot/-/issues/3
This commit is contained in:
Netkas 2023-04-24 14:01:22 -04:00
parent 9deb9e2c00
commit 05b877d38a
2 changed files with 303 additions and 0 deletions

View file

@ -26,6 +26,7 @@ input objects for methods that require input objects.
* 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\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\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. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVoice`, see [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument`, see [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument) for more information.
### Changed ### Changed
* Refactored InputMessageContent types to its own namespace so InputMessageContent can always return the correct InputMessageContent object type when calling `fromArray()` * Refactored InputMessageContent types to its own namespace so InputMessageContent can always return the correct InputMessageContent object type when calling `fromArray()`

View file

@ -0,0 +1,302 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Telegram\InlineQueryResult;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Telegram\InlineKeyboardMarkup;
use TgBotLib\Objects\Telegram\InputMessageContent\InputContactMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputInvoiceMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputLocationMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputTextMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputVenueMessageContent;
use TgBotLib\Objects\Telegram\MessageEntity;
class InlineQueryResultDocument implements ObjectTypeInterface
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $title;
/**
* @var string|null
*/
private $caption;
/**
* @var string|null
*/
private $parse_mode;
/**
* @var MessageEntity[]|null
*/
private $caption_entities;
/**
* @var string
*/
private $document_url;
/**
* @var string
*/
private $mime_type;
/**
* @var string|null
*/
private $description;
/**
* @var InlineKeyboardMarkup|null
*/
private $reply_markup;
/**
* @var InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null
*/
private $input_message_content;
/**
* @var string|null
*/
private $thumbnail_url;
/**
* @var int|null
*/
private $thumbnail_width;
/**
* @var int|null
*/
private $thumbnail_height;
/**
* InlineQueryResultDocument constructor.
*/
public function __construct()
{
$this->type = 'document';
}
/**
* Type of the result, must be document
*
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* Unique identifier for this result, 1-64 bytes
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* Title for the result
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* 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 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;
}
/**
* A valid URL for the file
*
* @return string
*/
public function getDocumentUrl(): string
{
return $this->document_url;
}
/**
* MIME type of the content of the file, either “application/pdf” or “application/zip”
*
* @return string
*/
public function getMimeType(): string
{
return $this->mime_type;
}
/**
* Optional. Short description of the result
*
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* 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 file
*
* @return InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null
*/
public function getInputMessageContent(): InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null
{
return $this->input_message_content;
}
/**
* Optional. URL of the thumbnail (JPEG only) for the file
*
* @return string|null
*/
public function getThumbnailUrl(): ?string
{
return $this->thumbnail_url;
}
/**
* Optional. Thumbnail width
*
* @return int|null
*/
public function getThumbnailWidth(): ?int
{
return $this->thumbnail_width;
}
/**
* Optional. Thumbnail height
*
* @return int|null
*/
public function getThumbnailHeight(): ?int
{
return $this->thumbnail_height;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'type' => $this->type,
'id' => $this->id,
'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 ?? []),
'document_url' => $this->document_url,
'mime_type' => $this->mime_type,
'description' => $this->description,
'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null,
'input_message_content' => ($this->input_message_content instanceof InputVenueMessageContent) ? $this->input_message_content->toArray() : null,
'thumbnail_url' => $this->thumbnail_url,
'thumbnail_width' => $this->thumbnail_width,
'thumbnail_height' => $this->thumbnail_height,
];
}
/**
* 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->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->document_url = $data['document_url'] ?? null;
$object->mime_type = $data['mime_type'] ?? null;
$object->description = $data['description'] ?? null;
$object->reply_markup = ($data['reply_markup'] ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null);
$object->input_message_content = ($data['input_message_content'] ? InputVenueMessageContent::fromArray($data['input_message_content']) : null);
$object->thumbnail_url = $data['thumbnail_url'] ?? null;
$object->thumbnail_width = $data['thumbnail_width'] ?? null;
$object->thumbnail_height = $data['thumbnail_height'] ?? null;
return $object;
}
}