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

https://git.n64.cc/nosial/libs/tgbot/-/issues/3
This commit is contained in:
Netkas 2023-04-24 19:10:04 -04:00
parent 22a99eb06a
commit c0b25c7b0e
2 changed files with 237 additions and 0 deletions

View file

@ -29,6 +29,7 @@ input objects for methods that require input objects.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument`, see [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultLocation`, see [InlineQueryResultLocation](https://core.telegram.org/bots/api#inlinequeryresultlocation) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVenue`, see [InlineQueryResultVenue](https://core.telegram.org/bots/api#inlinequeryresultvenue) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact`, see [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact) for more information.
### Changed
* 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,236 @@
<?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\InputInvoiceMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputLocationMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputTextMessageContent;
use TgBotLib\Objects\Telegram\InputMessageContent\InputVenueMessageContent;
class InlineQueryResultContact implements ObjectTypeInterface
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $phone_number;
/**
* @var string
*/
private $first_name;
/**
* @var string|null
*/
private $last_name;
/**
* @var string|null
*/
private $vcard;
/**
* @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;
/**
* InlineQueryResultContact constructor.
*/
public function __construct()
{
$this->type = 'contact';
}
/**
* Type of the result, must be contact
*
* @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;
}
/**
* Contact's phone number
*
* @return string
*/
public function getPhoneNumber(): string
{
return $this->phone_number;
}
/**
* Contact's first name
*
* @return string
*/
public function getFirstName(): string
{
return $this->first_name;
}
/**
* Optional. Contact's last name
*
* @return string|null
*/
public function getLastName(): ?string
{
return $this->last_name;
}
/**
* Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes
*
* @return string|null
*/
public function getVcard(): ?string
{
return $this->vcard;
}
/**
* 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 contact
*
* @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 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,
'phone_number' => $this->phone_number,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'vcard' => $this->vcard,
'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null,
'input_message_content' => ($this->input_message_content instanceof ObjectTypeInterface) ? $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->id = $data['id'] ?? null;
$object->phone_number = $data['phone_number'] ?? null;
$object->first_name = $data['first_name'] ?? null;
$object->last_name = $data['last_name'] ?? null;
$object->vcard = $data['vcard'] ?? null;
$object->reply_markup = isset($data['reply_markup']) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null;
$object->input_message_content = isset($data['input_message_content']) ? InputMessageContent::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;
}
}