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

https://git.n64.cc/nosial/libs/tgbot/-/issues/3
This commit is contained in:
Netkas 2023-04-23 17:46:09 -04:00
parent 8ca48b008e
commit f518ca0030
2 changed files with 229 additions and 1 deletions

View file

@ -1,7 +1,6 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
@ -18,6 +17,7 @@ input objects for methods that require input objects.
* Added object `\TgBotLib\Objects\Telegram\InputMessageContent > InputContactMessageContent` to represent the content of a contact message to be sent as the result of an inline query. * Added object `\TgBotLib\Objects\Telegram\InputMessageContent > InputContactMessageContent` to represent the content of a contact message to be sent as the result of an inline query.
* Added object `\TgBotLib\Objects\Telegram\InputMessageContent > InputInvoiceMessageContent` to represent the content of an invoice message to be sent as the result of an inline query. * Added object `\TgBotLib\Objects\Telegram\InputMessageContent > InputInvoiceMessageContent` to represent the content of an invoice message to be sent as the result of an inline query.
* Added new exception class `NotImplementedException` to represent the case when a method is not implemented yet or the method is not applicable to the current object. * Added new exception class `NotImplementedException` to represent the case when a method is not implemented yet or the method is not applicable to the current object.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultArticle`, see [InlineQueryResultArticle](https://core.telegram.org/bots/api#inlinequeryresultarticle) 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,228 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Telegram\InlineQueryResult;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Telegram\InlineKeyboardMarkup;
use TgBotLib\Objects\Telegram\InputMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputContactMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputLocationMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputTextMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputVenueMessageContent;
class InlineQueryResultArticle implements ObjectTypeInterface
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $title;
/**
* @var InputTextMessageContent|InputLocationMessageContent|InputVenueMessageContent|InputContactMessageContent|null
*/
private $input_message_content;
/**
* @var InlineKeyboardMarkup|null
*/
private $reply_markup;
/**
* @var string|null
*/
private $url;
/**
* @var bool
*/
private $hide_url;
/**
* @var string|null
*/
private $description;
/**
* @var string|null
*/
private $thumbnail_url;
/**
* @var int|null
*/
private $thumbnail_width;
/**
* @var int|null
*/
private $thumbnail_height;
/**
* Type of the result, must be article
*
* @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 of the result
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Content of the message to be sent
*
* @return InputContactMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null
*/
public function getInputMessageContent(): InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|null
{
return $this->input_message_content;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Optional. URL of the result
*
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
/**
* Optional. Pass True if you don't want the URL to be shown in the message
*
* @return bool
*/
public function isHideUrl(): bool
{
return $this->hide_url;
}
/**
* Optional. Short description of the result
*
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* Optional. Url of the thumbnail for the result
*
* @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,
'input_message_content' => ($this->input_message_content instanceof ObjectTypeInterface) ? $this->input_message_content->toArray() : null,
'reply_markup' => ($this->reply_markup instanceof ObjectTypeInterface) ? $this->reply_markup->toArray() : null,
'url' => $this->url,
'hide_url' => $this->hide_url,
'description' => $this->description,
'thumb_url' => $this->thumbnail_url,
'thumb_width' => $this->thumbnail_width,
'thumb_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->input_message_content = InputMessageContent::fromArray($data['input_message_content'] ?? []);
$object->reply_markup = InlineKeyboardMarkup::fromArray($data['reply_markup'] ?? []);
$object->url = $data['url'] ?? null;
$object->hide_url = $data['hide_url'] ?? null;
$object->description = $data['description'] ?? null;
$object->thumbnail_url = $data['thumb_url'] ?? null;
$object->thumbnail_width = (int)$data['thumb_width'] ?? null;
$object->thumbnail_height = (int)$data['thumb_height'] ?? null;
return $object;
}
}