Updated InlineQuery objects

This commit is contained in:
netkas 2024-10-03 19:55:48 -04:00
parent 58849813e9
commit 669ec19f46
17 changed files with 422 additions and 1647 deletions

View file

@ -0,0 +1,356 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline;
use InvalidArgumentException;
use TgBotLib\Classes\Validate;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\CallbackGame;
use TgBotLib\Objects\LoginUrl;
use TgBotLib\Objects\WebAppInfo;
class InlineKeyboardButton implements ObjectTypeInterface
{
/**
* @var string
*/
private $text;
/**
* @var string|null
*/
private $url;
/**
* @var string|null
*/
private $callback_data;
/**
* @var WebAppInfo|null
*/
private $web_app;
/**
* @var LoginUrl|null
*/
private $login_url;
/**
* @var string|null
*/
private $switch_inline_query;
/**
* @var string|null
*/
private $switch_inline_query_current_chat;
/**
* @var CallbackGame|null
*/
private $callback_game;
/**
* @var bool
*/
private $pay;
/**
* Label text on the button
*
* @return string
*/
public function getText(): string
{
return $this->text;
}
/**
* Label text on the button
*
* @param string $text
* @return $this
*/
public function setText(string $text): self
{
$this->text = $text;
return $this;
}
/**
* Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?id=<user_id> can be
* used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
*
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
/**
* Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?id=<user_id> can be used
* to mention a user by their ID without using a username, if this is allowed by their privacy settings.
*
* @param string|null $url
* @return $this
*/
public function setUrl(?string $url): self
{
if(!Validate::url($url))
throw new InvalidArgumentException(sprintf('Invalid url: %s', $url));
$this->url = $url;
return $this;
}
/**
* Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
*
* @see https://core.telegram.org/bots/api#callbackquery
* @return string|null
*/
public function getCallbackData(): ?string
{
return $this->callback_data;
}
/**
* Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
*
* @param string|null $callbackData
* @return $this
*/
public function setCallbackData(?string $callbackData): self
{
if($callbackData == null)
{
$this->callback_data = null;
return $this;
}
if(!Validate::length($callbackData, 1, 64))
throw new InvalidArgumentException(sprintf('Invalid callback data length: %s', $callbackData));
$this->callback_data = $callbackData;
return $this;
}
/**
* Optional. Description of the Web App that will be launched when the user presses the button. The Web App will
* be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only
* in private chats between a user and the bot.
*
* @return WebAppInfo|null
*/
public function getWebApp(): ?WebAppInfo
{
return $this->web_app;
}
/**
* Optional. Description of the Web App that will be launched when the user presses the button. The Web App will
* be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only
* in private chats between a user and the bot.
*
* @param WebAppInfo|null $webApp
* @return $this
*/
public function setWebApp(?WebAppInfo $webApp): self
{
$this->web_app = $webApp;
return $this;
}
/**
* Optional. An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the
* Telegram Login Widget.
*
* @return LoginUrl|null
*/
public function getLoginUrl(): ?LoginUrl
{
return $this->login_url;
}
/**
* Optional. An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the
* Telegram Login Widget.
*
* @param LoginUrl|null $loginUrl
* @return $this
*/
public function setLoginUrl(?LoginUrl $loginUrl): self
{
if(!Validate::url($loginUrl->getUrl()))
throw new InvalidArgumentException(sprintf('Invalid login url: %s', $loginUrl->getUrl()));
if(!Validate::isHttps($loginUrl->getUrl()))
throw new InvalidArgumentException(sprintf('The login url must be https: %s', $loginUrl->getUrl()));
$this->login_url = $loginUrl;
return $this;
}
/**
* Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and
* insert the bot's username and the specified inline query in the input field. May be empty, in which case just
* the bot's username will be inserted.
*
* Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a
* private chat with it. Especially useful when combined with switch_pm… actions - in this case the user will be
* automatically returned to the chat they switched from, skipping the chat selection screen.
*
* @see https://core.telegram.org/bots/api#answerinlinequery
* @return string|null
*/
public function getSwitchInlineQuery(): ?string
{
return $this->switch_inline_query;
}
/**
* Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and
* insert the bot's username and the specified inline query in the input field. May be empty, in which case just
* the bot's username will be inserted.
*
* Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a
* private chat with it. Especially useful when combined with switch_pm… actions - in this case the user will be
* automatically returned to the chat they switched from, skipping the chat selection screen.
*
* @param string|null $switchInlineQuery
* @return $this
*/
public function setSwitchInlineQuery(?string $switchInlineQuery): self
{
$this->switch_inline_query = $switchInlineQuery;
return $this;
}
/**
* Optional. If set, pressing the button will insert the bot's username and the specified inline query in
* the current chat's input field. May be empty, in which case only the bot's username will be inserted.
*
* This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting
* something from multiple options.
*
* @return string|null
*/
public function getSwitchInlineQueryCurrentChat(): ?string
{
return $this->switch_inline_query_current_chat;
}
/**
* Optional. If set, pressing the button will insert the bot's username and the specified inline query in the
* current chat's input field. May be empty, in which case only the bot's username will be inserted.
*
* This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting
* something from multiple options.
*
* @param string|null $switchInlineQueryCurrentChat
* @return $this
*/
public function setSwitchInlineQueryCurrentChat(?string $switchInlineQueryCurrentChat): self
{
$this->switch_inline_query_current_chat = $switchInlineQueryCurrentChat;
return $this;
}
/**
* Optional. Description of the game that will be launched when the user presses the button.
* NOTE: This type of button must always be the first button in the first row.
*
* @return CallbackGame|null
*/
public function getCallbackGame(): ?CallbackGame
{
return $this->callback_game;
}
/*
* Optional. If set, pressing the button will insert the bot's username and the specified inline query in the
* current chat's input field. May be empty, in which case only the bots username will be inserted.
*
* This offers a quick way for the user to open your bot in inline mode in the same chat -
* good for selecting something from multiple options.
*/
public function setCallbackGame(?CallbackGame $callbackGame): self
{
$this->callback_game = $callbackGame;
return $this;
}
/**
* Optional. Specify True, to send a Pay button.
* NOTE: This type of button must always be the first button in the first row and can only be used in invoice messages.
*
* @see https://core.telegram.org/bots/api#payments
* @return bool
*/
public function isPay(): bool
{
return $this->pay;
}
/**
* Optional. Specify True, to send a Pay button.
*
* NOTE: This type of button must always be the first button in the first row and can only be used in invoice
* messages.
*
* @param bool $pay
* @return $this
*/
public function setPay(bool $pay): self
{
$this->pay = $pay;
return $this;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'text' => $this->text ?? null,
'url' => $this->url ?? null,
'callback_data' => $this->callback_data ?? null,
'web_app' => ($this->web_app instanceof ObjectTypeInterface) ? $this->web_app->toArray() : null,
'login_url' => ($this->login_url instanceof ObjectTypeInterface) ? $this->login_url->toArray() : null,
'switch_inline_query' => $this->switch_inline_query ?? null,
'switch_inline_query_current_chat' => $this->switch_inline_query_current_chat ?? null,
'callback_game' => ($this->callback_game instanceof ObjectTypeInterface) ? $this->callback_game->toArray() : null,
'pay' => $this->pay ?? null
];
}
/**
* Constructs a new InlineKeyboardButton object from an array
*
* @param array $data
* @return InlineKeyboardButton
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->text = $data['text'] ?? null;
$object->url = $data['url'] ?? null;
$object->callback_data = $data['callback_data'] ?? null;
$object->web_app = isset($data['web_app']) && is_array($data['web_app']) ? WebAppInfo::fromArray($data['web_app']) : null;
$object->login_url = isset($data['login_url']) && is_array($data['login_url']) ? LoginUrl::fromArray($data['login_url']) : null;
$object->switch_inline_query = $data['switch_inline_query'] ?? null;
$object->switch_inline_query_current_chat = $data['switch_inline_query_current_chat'] ?? null;
$object->callback_game = isset($data['callback_game']) && is_array($data['callback_game']) ? CallbackGame::fromArray($data['callback_game']) : null;
$object->pay = $data['pay'] ?? null;
return $object;
}
}

View file

@ -0,0 +1,92 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline;
use TgBotLib\Interfaces\ObjectTypeInterface;
class InlineKeyboardMarkup implements ObjectTypeInterface
{
/**
* @var InlineKeyboardButton[][]
*/
private $inline_keyboard;
/**
* Array of button rows, each represented by an Array of InlineKeyboardButton objects
*
* @see https://core.telegram.org/bots/api#inlinekeyboardmarkup
* @return InlineKeyboardButton[][]
*/
public function getInlineKeyboard(): array
{
return $this->inline_keyboard;
}
/**
* Adds a row of buttons
*
* @param InlineKeyboardButton ...$buttons
* @return $this
*/
public function addRow(InlineKeyboardButton ...$buttons): self
{
$this->inline_keyboard[] = $buttons;
return $this;
}
/**
* Removes a row of buttons by index
*
* @param int $index
* @return $this
*/
public function removeRow(int $index): self
{
unset($this->inline_keyboard[$index]);
return $this;
}
/**
* Returns an array representation of the object
*
* @return array[][]
*/
public function toArray(): array
{
$data = [];
if ($this->inline_keyboard !== null)
{
/** @var InlineKeyboardButton $item */
foreach ($this->inline_keyboard as $item)
{
$data[][] = $item->toArray();
}
}
return $data;
}
/**
* Constructs the object from an array representation
*
* @param array $data
* @return InlineKeyboardMarkup
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->inline_keyboard = [];
foreach($data as $item)
{
$object->inline_keyboard[] = InlineKeyboardButton::fromArray($item);
}
return $object;
}
}

View file

@ -0,0 +1,142 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Location;
use TgBotLib\Objects\User;
class InlineQuery implements ObjectTypeInterface
{
/**
* @var string
*/
private $id;
/**
* @var User
*/
private $from;
/**
* @var string
*/
private $query;
/**
* @var string
*/
private $offset;
/**
* @var string|null
*/
private $chat_type;
/**
* @var Location|null
*/
private $location;
/**
* Unique identifier for this query
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* Sender
*
* @return User
*/
public function getFrom(): User
{
return $this->from;
}
/**
* Text of the query (up to 256 characters)
*
* @return string
*/
public function getQuery(): string
{
return $this->query;
}
/**
* Offset of the results to be returned, can be controlled by the bot
*
* @return string
*/
public function getOffset(): string
{
return $this->offset;
}
/**
* Optional. Type of the chat from which the inline query was sent. Can be either “sender” for a private chat
* with the inline query sender, “private”, “group”, “supergroup”, or “channel”. The chat type should be always
* known for requests sent from official clients and most third-party clients, unless the request was sent from
* a secret chat
*
* @return string|null
*/
public function getChatType(): ?string
{
return $this->chat_type;
}
/**
* Optional. Sender location, only for bots that request user location
*
* @return Location|null
*/
public function getLocation(): ?Location
{
return $this->location;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : $this->from,
'query' => $this->query,
'offset' => $this->offset,
'chat_type' => $this->chat_type,
'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : $this->location,
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return InlineQuery
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->id = $data['id'];
$object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : $data['from'];
$object->query = $data['query'];
$object->offset = $data['offset'];
$object->chat_type = $data['chat_type'] ?? null;
$object->location = isset($data['location']) && is_array($data['location']) ? Location::fromArray($data['location']) : $data['location'];
return $object;
}
}

View file

@ -0,0 +1,78 @@
<?php
namespace TgBotLib\Objects\Inline;
use InvalidArgumentException;
use TgBotLib\Classes\Validate;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Exceptions\NotImplementedException;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultArticle;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultAudio;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultContact;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultDocument;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultGame;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultGif;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultLocation;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultMpeg4Gif;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultPhoto;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultVenue;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultVideo;
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultVoice;
abstract class InlineQueryResult implements ObjectTypeInterface
{
protected InlineQueryResultType $type;
protected string $id;
/**
* Type of the result
*
* @return InlineQueryResultType
*/
public function getType(): InlineQueryResultType
{
return $this->type;
}
/**
* Unique identifier for this result, 1-64 Bytes
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* Sets the Unique Identifier for this result, must be 1-64 characters
*
* @param string $id The ID to set
* @throws InvalidArgumentException If the size of the ID is empty or over 64 characters long
* @return $this
*/
public function setId(string $id): InlineQueryResult
{
if(!Validate::length($id, 1, 64))
{
throw new InvalidArgumentException(sprintf('id must be between 1 and 64 characters long, got %s characters', $id));
}
$this->id = $id;
return $this;
}
/**
* @inheritDoc
*/
public abstract function toArray(): array;
/**
* @inheritDoc
*/
public static function fromArray(array $data): ObjectTypeInterface
{
// TODO: Implement this
}
}

View file

@ -0,0 +1,282 @@
<?php
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Classes\Validate;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
class InlineQueryResultArticle extends InlineQueryResult implements ObjectTypeInterface
{
private string $title;
private InputMessageContent $input_message_content;
private ?InlineKeyboardMarkup $reply_markup;
private ?string $url;
private bool $hide_url;
private ?string $description;
private ?string $thumbnail_url;
private ?int $thumbnail_width;
private ?int $thumbnail_height;
/**
* Title of the result
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets the value of the 'title' field.
* Title of the result
*
* @param string $title
* @return $this
*/
public function setTitle(string $title): InlineQueryResultArticle
{
$this->title = $title;
return $this;
}
/**
* Content of the message to be sent
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the value of the 'input_message_content' field.
* Content of the message to be sent
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultArticle
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the value of the 'reply_markup' field.
* Optional. Inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultArticle
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. URL of the result
*
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
/**
* Sets the value of the 'url' field.
* Optional. URL of the result
*
* @param string|null $url
* @return $this
*/
public function setUrl(?string $url): InlineQueryResultArticle
{
if(!Validate::url($url))
{
throw new InvalidArgumentException(sprintf('url is not a valid url: %s', $url));
}
$this->url = $url;
return $this;
}
/**
* 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;
}
/**
* Sets the value of the 'hide_url' field.
* Optional. Pass True if you don't want the URL to be shown in the message
*
* @param bool $hide_url
* @return $this
*/
public function setHideUrl(bool $hide_url): InlineQueryResultArticle
{
$this->hide_url = $hide_url;
return $this;
}
/**
* Optional. Short description of the result
*
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* Sets the value of the 'description' field.
* Optional. Short description of the result
*
* @param string|null $description
* @return $this
*/
public function setDescription(?string $description): InlineQueryResultArticle
{
$this->description = $description;
return $this;
}
/**
* Optional. Url of the thumbnail for the result
*
* @return string|null
*/
public function getThumbnailUrl(): ?string
{
return $this->thumbnail_url;
}
/**
* Sets the value of the 'thumbnail_url' field.
* Optional. Url of the thumbnail for the result
*
* @param string|null $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(?string $thumbnail_url): InlineQueryResultArticle
{
if(!Validate::url($thumbnail_url))
{
throw new InvalidArgumentException(sprintf('thumbnail_url is not a valid url: %s', $thumbnail_url));
}
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Optional. Thumbnail width
*
* @return int|null
*/
public function getThumbnailWidth(): ?int
{
return $this->thumbnail_width;
}
/**
* Sets the value of the 'thumbnail_width' field.
* Optional. Thumbnail width
*
* @param int|null $thumbnail_width
* @return $this
*/
public function setThumbnailWidth(?int $thumbnail_width): InlineQueryResultArticle
{
$this->thumbnail_width = $thumbnail_width;
return $this;
}
/**
* Optional. Thumbnail height
*
* @return int|null
*/
public function getThumbnailHeight(): ?int
{
return $this->thumbnail_height;
}
/**
* Sets the value of the 'thumbnail_height' field.
* Optional. Thumbnail height
*
* @param int|null $thumbnail_height
* @return $this
*/
public function setThumbnailHeight(?int $thumbnail_height): InlineQueryResultArticle
{
$this->thumbnail_height = $thumbnail_height;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'id' => $this->id,
'title' => $this->title,
'input_message_content' => $this->input_message_content?->toArray(),
'reply_markup' => $this->reply_markup?->toArray(),
'url' => $this->url,
'hide_url' => $this->hide_url,
'description' => $this->description,
'thumbnail_url' => $this->thumbnail_url,
'thumbnail_width' => $this->thumbnail_width,
'thumbnail_height' => $this->thumbnail_height
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultArticle
{
$object = new self();
$object->type = InlineQueryResultType::ARTICLE;
$object->id = $data['id'] ?? null;
$object->title = $data['title'] ?? null;
$object->input_message_content = isset($data['input_message_content']) ? InputMessageContent::fromArray($data['input_message_content']) : null;
$object->reply_markup = isset($data['reply_markup']) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null;
$object->url = $data['url'] ?? null;
$object->hide_url = $data['hide_url'] ?? null;
$object->description = $data['description'] ?? null;
$object->thumbnail_url = $data['thumbnail_url'] ?? null;
$object->thumbnail_width = is_null($data['thumbnail_width']) ? null : (int)$data['thumbnail_width'];
$object->thumbnail_height = is_null($data['thumbnail_height']) ? null : (int)$data['thumbnail_height'];
return $object;
}
}

View file

@ -0,0 +1,332 @@
<?php
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Classes\Validate;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\MessageEntity;
class InlineQueryResultAudio extends InlineQueryResult implements ObjectTypeInterface
{
private string $audio_url;
private string $title;
private ?string $caption;
private ?string $parse_mode;
/**
* @var MessageEntity[]|null
*/
private ?array $caption_entities;
private ?string $performer;
private ?int $audio_duration;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputMessageContent $input_message_content;
/**
* A valid URL for the audio file
*
* @return string
*/
public function getAudioUrl(): string
{
return $this->audio_url;
}
/**
* Sets the value of 'audio_url' property
* A valid URL for the audio file
*
* @param string $audio_url
* @return $this
*/
public function setAudioUrl(string $audio_url): InlineQueryResultAudio
{
if(!Validate::url($audio_url))
{
throw new InvalidArgumentException(sprintf('audio_url is not a valid URL: %s', $audio_url));
}
$this->audio_url = $audio_url;
return $this;
}
/**
* Title
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets the value of 'title' property
* Title
*
* @param string $title
* @return $this
*/
public function setTitle(string $title): InlineQueryResultAudio
{
$this->title = $title;
return $this;
}
/**
* Optional. Caption, 0-1024 characters after entities parsing
*
* @return string|null
*/
public function getCaption(): ?string
{
return $this->caption;
}
/**
* Sets the value of 'caption' property
* Optional. Caption, 0-1024 characters after entities parsing
*
* @param string|null $caption
* @return $this
*/
public function setCaption(?string $caption): InlineQueryResultAudio
{
if($caption === null)
{
$this->caption = null;
return $this;
}
if(!Validate::length($caption, 0, 1024))
{
throw new InvalidArgumentException(sprintf('caption must be between 0 and 1024 characters long, got %s characters', $caption));
}
$this->caption = $caption;
return $this;
}
/**
* 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;
}
/**
* Sets the value of 'parse_mode' property
* Optional. Mode for parsing entities in the audio caption. See formatting options for more details.
*
* @param string|null $parse_mode
* @return $this
*/
public function setParseMode(?string $parse_mode): InlineQueryResultAudio
{
if($parse_mode === null)
{
$this->parse_mode = null;
return $this;
}
if(!in_array(strtolower($parse_mode), ['markdown', 'html']))
{
throw new InvalidArgumentException(sprintf('parse_mode must be one of Markdown, HTML, got %s', $parse_mode));
}
$this->parse_mode = $parse_mode;
return $this;
}
/**
* 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;
}
/**
* Sets the value of 'caption_entities' property
* Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
*
* @param MessageEntity[]|null $caption_entities
* @return $this
*/
public function setCaptionEntities(?array $caption_entities): InlineQueryResultAudio
{
if($caption_entities === null)
{
$this->caption_entities = null;
return $this;
}
$this->caption_entities = [];
foreach($caption_entities as $entity)
{
if(!$entity instanceof MessageEntity)
{
throw new InvalidArgumentException(sprintf('caption_entities must be array of MessageEntity, got %s', gettype($entity)));
}
$this->caption_entities[] = $entity;
}
return $this;
}
/**
* Optional. Performer
*
* @return string|null
*/
public function getPerformer(): ?string
{
return $this->performer;
}
/**
* Sets the value of 'performer' property
* Optional. Performer
*
* @param string|null $performer
* @return $this
*/
public function setPerformer(?string $performer): InlineQueryResultAudio
{
if($performer === null)
{
$this->performer = null;
return $this;
}
$this->performer = $performer;
return $this;
}
/**
* Optional. Audio duration in seconds
*
* @return int|null
*/
public function getAudioDuration(): ?int
{
return $this->audio_duration;
}
/**
* Sets the value of 'audio_duration' property
* Optional. Audio duration in seconds
*
* @param int|null $audio_duration
* @return $this
*/
public function setAudioDuration(?int $audio_duration): InlineQueryResultAudio
{
if($audio_duration === null)
{
$this->audio_duration = null;
return $this;
}
$this->audio_duration = $audio_duration;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the value of 'reply_markup' property
* Optional. Inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultAudio
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the audio
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the value of 'input_message_content' property
* Optional. Content of the message to be sent instead of the audio
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultAudio
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'id' => $this->id,
'audio_url' => $this->audio_url,
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parse_mode,
'caption_entities' => array_map(fn(MessageEntity $messageEntity) => $messageEntity->toArray(), $this->caption_entities),
'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,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultAudio
{
$object = new self();
$object->type = InlineQueryResultType::AUDIO;
$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 = isset($data['caption_entities']) ? array_map(fn(array $messageEntity) => 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;
}
}

View file

@ -0,0 +1,280 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Classes\Validate;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
class InlineQueryResultContact extends InlineQueryResult implements ObjectTypeInterface
{
private string $phone_number;
private string $first_name;
private ?string $last_name;
private ?string $vcard;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputMessageContent $input_message_content;
private ?string $thumbnail_url;
private ?int $thumbnail_width;
private ?int $thumbnail_height;
/**
* Contact's phone number
*
* @return string
*/
public function getPhoneNumber(): string
{
return $this->phone_number;
}
/**
* Sets the value of 'phone_number' property
* Contact's phone number
*
* @param string $phone_number
* @return $this
*/
public function setPhoneNumber(string $phone_number): self
{
$this->phone_number = $phone_number;
return $this;
}
/**
* Contact's first name
*
* @return string
*/
public function getFirstName(): string
{
return $this->first_name;
}
/**
* Sets the value of 'first_name' property
* Contact's first name
*
* @param string $first_name
* @return $this
*/
public function setFirstName(string $first_name): self
{
$this->first_name = $first_name;
return $this;
}
/**
* Optional. Contact's last name
*
* @return string|null
*/
public function getLastName(): ?string
{
return $this->last_name;
}
/**
* Sets the value of 'last_name' property
* Optional. Contact's last name
*
* @param string|null $last_name
* @return $this
*/
public function setLastName(?string $last_name): self
{
$this->last_name = $last_name;
return $this;
}
/**
* 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;
}
/**
* Sets the value of 'vcard' property
* Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes
*
* @param string|null $vcard
* @return $this
*/
public function setVcard(?string $vcard): self
{
if(!Validate::length($vcard, 0, 2048))
{
throw new InvalidArgumentException('vcard should be between 0-2048 characters');
}
$this->vcard = $vcard;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the value of 'reply_markup' property
* Optional. Inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): self
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the contact
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the value of 'input_message_content' property
* Optional. Content of the message to be sent instead of the contact
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): self
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* Optional. Url of the thumbnail for the result
*
* @return string|null
*/
public function getThumbnailUrl(): ?string
{
return $this->thumbnail_url;
}
/**
* Sets the value of 'thumbnail_url' property
* Optional. Url of the thumbnail for the result
*
* @param string|null $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(?string $thumbnail_url): self
{
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Optional. Thumbnail width
*
* @return int|null
*/
public function getThumbnailWidth(): ?int
{
return $this->thumbnail_width;
}
/**
* Sets the value of 'thumbnail_width' property
* Optional. Thumbnail width
*
* @param int|null $thumbnail_width
* @return $this
*/
public function setThumbnailWidth(?int $thumbnail_width): self
{
$this->thumbnail_width = $thumbnail_width;
return $this;
}
/**
* Optional. Thumbnail height
*
* @return int|null
*/
public function getThumbnailHeight(): ?int
{
return $this->thumbnail_height;
}
/**
* Sets the value of 'thumbnail_height' property
* Optional. Thumbnail height
*
* @param int|null $thumbnail_height
* @return $this
*/
public function setThumbnailHeight(?int $thumbnail_height): self
{
$this->thumbnail_height = $thumbnail_height;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'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?->toArray(),
'input_message_content' => $this->input_message_content?->toArray(),
'thumbnail_url' => $this->thumbnail_url,
'thumbnail_width' => $this->thumbnail_width,
'thumbnail_height' => $this->thumbnail_height
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultContact
{
$object = new self();
$object->type = InlineQueryResultType::CONTACT;
$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;
}
}

View file

@ -0,0 +1,404 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Classes\Validate;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\InputMessageContent\InputVenueMessageContent;
use TgBotLib\Objects\MessageEntity;
class InlineQueryResultDocument extends InlineQueryResult implements ObjectTypeInterface
{
private string $title;
private ?string $caption;
private ?string $parse_mode;
/**
* @var MessageEntity[]|null
*/
private ?array $caption_entities;
private string $document_url;
private string $mime_type;
private ?string $description;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputMessageContent $input_message_content;
private ?string $thumbnail_url;
private ?int $thumbnail_width;
private ?int $thumbnail_height;
/**
* Title for the result
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets the value of the 'title' field.
* Title for the result
*
* @param string $title
* @return $this
*/
public function setTitle(string $title): InlineQueryResultDocument
{
$this->title = $title;
return $this;
}
/**
* Optional. Caption of the document to be sent, 0-1024 characters after entities parsing
*
* @return string|null
*/
public function getCaption(): ?string
{
return $this->caption;
}
/**
* Sets the value of the 'caption' field.
* Optional. Caption of the document to be sent, 0-1024 characters after entities parsing
*
* @param string|null $caption
* @return $this
*/
public function setCaption(?string $caption): InlineQueryResultDocument
{
if($caption == null)
{
$this->caption = null;
return $this;
}
if(!Validate::length($caption, 0, 1024))
{
throw new InvalidArgumentException("Caption must be between 0 and 1024 characters");
}
$this->caption = $caption;
return $this;
}
/**
* 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;
}
/**
* Sets the value of the 'parse_mode' field.
* Optional. Mode for parsing entities in the document caption. See formatting options for more details.
*
* @param string|null $parse_mode
* @return $this
*/
public function setParseMode(?string $parse_mode): InlineQueryResultDocument
{
if($parse_mode == null)
{
$this->parse_mode = null;
return $this;
}
if(!in_array(strtolower($parse_mode), ['markdown', 'html']))
{
throw new InvalidArgumentException("Parse mode must be either Markdown or HTML");
}
$this->parse_mode = $parse_mode;
return $this;
}
/**
* 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;
}
/**
* Sets the value of the 'caption_entities' field.
* Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
*
* @param MessageEntity[]|null $caption_entities
* @return $this
*/
public function setCaptionEntities(?array $caption_entities): InlineQueryResultDocument
{
if($caption_entities == null)
{
$this->caption_entities = null;
return $this;
}
foreach($caption_entities as $entity)
{
if(!($entity instanceof MessageEntity))
{
throw new InvalidArgumentException("Caption entities must be an array of MessageEntity");
}
}
$this->caption_entities = $caption_entities;
return $this;
}
/**
* A valid URL for the file
*
* @return string
*/
public function getDocumentUrl(): string
{
return $this->document_url;
}
/**
* Sets the value of the 'document_url' field.
* A valid URL for the file
*
* @param string $document_url
* @return $this
*/
public function setDocumentUrl(string $document_url): InlineQueryResultDocument
{
if(!Validate::url($document_url))
{
throw new InvalidArgumentException("Document URL must be a valid URL");
}
$this->document_url = $document_url;
return $this;
}
/**
* MIME type of the content of the file, either “application/pdf” or “application/zip”
*
* @return string
*/
public function getMimeType(): string
{
return $this->mime_type;
}
/**
* Sets the value of the 'mime_type' field.
* MIME type of the content of the file, either “application/pdf” or “application/zip”
*
* @param string $mime_type
* @return $this
*/
public function setMimeType(string $mime_type): InlineQueryResultDocument
{
$this->mime_type = $mime_type;
return $this;
}
/**
* Optional. Short description of the result
*
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* Sets the value of the 'description' field.
* Optional. Short description of the result
*
* @param string|null $description
* @return $this
*/
public function setDescription(?string $description): InlineQueryResultDocument
{
$this->description = $description;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the value of the 'reply_markup' field.
* Optional. Inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultDocument
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the file
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the value of the 'input_message_content' field.
* Optional. Content of the message to be sent instead of the file
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultDocument
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* Optional. URL of the thumbnail (JPEG only) for the file
*
* @return string|null
*/
public function getThumbnailUrl(): ?string
{
return $this->thumbnail_url;
}
/**
* Sets the value of the 'thumbnail_url' field.
* Optional. URL of the thumbnail (JPEG only) for the file
*
* @param string|null $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(?string $thumbnail_url): InlineQueryResultDocument
{
if($thumbnail_url != null && !Validate::url($thumbnail_url))
{
throw new InvalidArgumentException("Thumbnail URL must be a valid URL");
}
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Optional. Thumbnail width
*
* @return int|null
*/
public function getThumbnailWidth(): ?int
{
return $this->thumbnail_width;
}
/**
* Sets the value of the 'thumbnail_width' field.
* Optional. Thumbnail width
*
* @param int|null $thumbnail_width
* @return $this
*/
public function setThumbnailWidth(?int $thumbnail_width): InlineQueryResultDocument
{
$this->thumbnail_width = $thumbnail_width;
return $this;
}
/**
* Optional. Thumbnail height
*
* @return int|null
*/
public function getThumbnailHeight(): ?int
{
return $this->thumbnail_height;
}
/**
* Sets the value of the 'thumbnail_height' field.
* Optional. Thumbnail height
*
* @param int|null $thumbnail_height
* @return $this
*/
public function setThumbnailHeight(?int $thumbnail_height): InlineQueryResultDocument
{
$this->thumbnail_height = $thumbnail_height;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'id' => $this->id,
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parse_mode,
'caption_entities' => array_map(fn(MessageEntity $entity) => $entity->toArray(), $this->caption_entities),
'document_url' => $this->document_url,
'mime_type' => $this->mime_type,
'description' => $this->description,
'reply_markup' => $this->reply_markup?->toArray(),
'input_message_content' => $this->input_message_content?->toArray(),
'thumbnail_url' => $this->thumbnail_url,
'thumbnail_width' => $this->thumbnail_width,
'thumbnail_height' => $this->thumbnail_height,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultDocument
{
$object = new self();
$object->type = InlineQueryResultType::DOCUMENT;
$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 = isset($data['caption_entities']) ? array_map(fn(array $entity) => MessageEntity::fromArray($entity), $data['caption_entities']) : null;
$object->document_url = $data['document_url'] ?? null;
$object->mime_type = $data['mime_type'] ?? null;
$object->description = $data['description'] ?? null;
$object->reply_markup = isset($data['reply_markup']) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null;
$object->input_message_content = isset($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;
}
}

View file

@ -0,0 +1,102 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
class InlineQueryResultGame extends InlineQueryResult implements ObjectTypeInterface
{
private string $game_short_name;
private ?InlineKeyboardMarkup $reply_markup;
/**
* Sets the value of the 'id' field
* Unique identifier for this result, 1-64 bytes
*
* @param string $id
* @return InlineQueryResultGame
*/
public function setId(string $id): InlineQueryResultGame
{
$this->id = $id;
return $this;
}
/**
* Short name of the game
*
* @return string
*/
public function getGameShortName(): string
{
return $this->game_short_name;
}
/**
* Sets the value of the 'game_short_name' field
* Short name of the game
*
* @param string $game_short_name
* @return InlineQueryResultGame
*/
public function setGameShortName(string $game_short_name): InlineQueryResultGame
{
$this->game_short_name = $game_short_name;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Optional. Inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return InlineQueryResultGame
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultGame
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'id' => $this->id,
'game_short_name' => $this->game_short_name,
'reply_markup' => $this->reply_markup?->toArray()
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultGame
{
$object = new self();
$object->type = InlineQueryResultType::GAME;
$object->id = $data['id'] ?? null;
$object->game_short_name = $data['game_short_name'] ?? null;
$object->reply_markup = isset($data['reply_markup']) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null;
return $object;
}
}

View file

@ -0,0 +1,413 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Classes\Validate;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Enums\Types\ThumbnailMimeType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\MessageEntity;
class InlineQueryResultGif extends InlineQueryResult implements ObjectTypeInterface
{
private string $gif_url;
private ?int $gif_width;
private ?int $gif_height;
private ?int $gif_duration;
private ?string $thumbnail_url;
private ?ThumbnailMimeType $thumbnail_mime_type;
private ?string $title;
private ?string $caption;
private ?string $parse_mode;
/**
* @var MessageEntity[]|null
*/
private ?array $caption_entities;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputMessageContent $input_message_content;
/**
* A valid URL for the GIF file. File size must not exceed 1MB
*
* @return string
*/
public function getGifUrl(): string
{
return $this->gif_url;
}
/**
* Sets the value of the 'gif_url' field.
* A valid URL for the GIF file. File size must not exceed 1MB
*
* @param string $gif_url
* @return $this
*/
public function setGifUrl(string $gif_url): InlineQueryResultGif
{
if(!Validate::url($gif_url))
{
throw new InvalidArgumentException(sprintf('"%s" is not a valid url', $gif_url));
}
$this->gif_url = $gif_url;
return $this;
}
/**
* Optional. Width of the GIF
*
* @return int|null
*/
public function getGifWidth(): ?int
{
return $this->gif_width;
}
/**
* Sets the value of the 'gif_width' field.
* Optional. Width of the GIF
*
* @param int $gif_width
* @return $this
*/
public function setGifWidth(int $gif_width): InlineQueryResultGif
{
$this->gif_width = $gif_width;
return $this;
}
/**
* Optional. Height of the GIF
*
* @return int|null
*/
public function getGifHeight(): ?int
{
return $this->gif_height;
}
/**
* Sets the value of the 'gif_height' field.
* Optional. Height of the GIF
*
* @param int|null $gif_height
* @return $this
*/
public function setGifHeight(?int $gif_height): InlineQueryResultGif
{
if(is_null($gif_height))
{
$this->gif_height = null;
return $this;
}
$this->gif_height = $gif_height;
return $this;
}
/**
* Optional. Duration of the GIF in seconds
*
* @return int|null
*/
public function getGifDuration(): ?int
{
return $this->gif_duration;
}
/**
* Sets the value of the 'gif_duration' field.
* Optional. Duration of the GIF in seconds
*
* @param int|null $gif_duration
* @return $this
*/
public function setGifDuration(?int $gif_duration): InlineQueryResultGif
{
if(is_null($gif_duration))
{
$this->gif_duration = null;
return $this;
}
$this->gif_duration = $gif_duration;
return $this;
}
/**
* URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result
*
* @return string|null
*/
public function getThumbnailUrl(): ?string
{
return $this->thumbnail_url;
}
/**
* Sets the value of the 'thumbnail_url' field.
* URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result
*
* @param string $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(string $thumbnail_url): InlineQueryResultGif
{
if(!Validate::url($thumbnail_url))
{
throw new InvalidArgumentException(sprintf('"%s" is not a valid url', $thumbnail_url));
}
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Optional. MIME type of the thumbnail must be one of “image/jpeg, “image/gif”, or “video/mp4”. Defaults to “image/jpeg”
*
* @return ThumbnailMimeType|null
*/
public function getThumbnailMimeType(): ?ThumbnailMimeType
{
return $this->thumbnail_mime_type;
}
/**
* Sets the value of the 'thumbnail_mime_type' field.
* Optional. MIME type of the thumbnail must be one of “image/jpeg, “image/gif”, or “video/mp4”. Defaults to “image/jpeg”
*
* @param string|ThumbnailMimeType|null $thumbnail_mime_type
* @return $this
*/
public function setThumbnailMimeType(string|ThumbnailMimeType|null $thumbnail_mime_type): InlineQueryResultGif
{
if(is_null($thumbnail_mime_type))
{
$this->thumbnail_mime_type = null;
return $this;
}
if(is_string($thumbnail_mime_type))
{
$thumbnail_mime_type = ThumbnailMimeType::tryFrom($thumbnail_mime_type);
}
if($thumbnail_mime_type === null)
{
throw new InvalidArgumentException('Unexpected type for ThumbnailMimeType');
}
$this->thumbnail_mime_type = $thumbnail_mime_type;
return $this;
}
/**
* Optional. Title for the result
*
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* Sets the value of the 'title' field.
* Optional. Title for the result
*
* @param string|null $title
* @return $this
*/
public function setTitle(?string $title): InlineQueryResultGif
{
$this->title = $title;
return $this;
}
/**
* Optional. Caption of the GIF file to be sent, 0-1024 characters after entities parsing
*
* @return string|null
*/
public function getCaption(): ?string
{
return $this->caption;
}
/**
* Sets the value of the 'caption' field.
* Optional. Caption of the GIF file to be sent, 0-1024 characters after entities parsing
*
* @param string|null $caption
* @return $this
*/
public function setCaption(?string $caption): InlineQueryResultGif
{
$this->caption = $caption;
return $this;
}
/**
* Optional. Mode for parsing entities in the caption. See formatting options for more details.
*
* @return string|null
*/
public function getParseMode(): ?string
{
return $this->parse_mode;
}
/**
* Sets the value of the 'parse_mode' field.
* Optional. Mode for parsing entities in the caption. See formatting options for more details.
*
* @param string|null $parse_mode
* @return $this
*/
public function setParseMode(?string $parse_mode): InlineQueryResultGif
{
$this->parse_mode = $parse_mode;
return $this;
}
/**
* 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;
}
/**
* Sets the value of the 'caption_entities' field.
* Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
*
* @param MessageEntity[]|null $caption_entities
* @return $this
* @noinspection DuplicatedCode
*/
public function setCaptionEntities(?array $caption_entities): InlineQueryResultGif
{
if($caption_entities === null)
{
$this->caption_entities = null;
return $this;
}
$this->caption_entities = [];
foreach($caption_entities as $entity)
{
if(!$entity instanceof MessageEntity)
{
throw new InvalidArgumentException(sprintf('caption_entities must be array of MessageEntity, got %s', gettype($entity)));
}
$this->caption_entities[] = $entity;
}
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the value of the 'reply_markup' field.
* Optional. Inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultGif
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the GIF animation
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the value of the 'input_message_content' field.
* Optional. Content of the message to be sent instead of the GIF animation
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultGif
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'id' => $this->id ?? null,
'gif_url' => $this->gif_url ?? null,
'gif_width' => $this->gif_width ?? null,
'gif_height' => $this->gif_height ?? null,
'gif_duration' => $this->gif_duration ?? null,
'thumbnail_url' => $this->thumbnail_url ?? null,
'thumbnail_mime_type' => $this->thumbnail_mime_type ?? null,
'title' => $this->title ?? null,
'caption' => $this->caption ?? null,
'parse_mode' => $this->parse_mode ?? null,
'caption_entities' => array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
'reply_markup' => $this->reply_markup?->toArray(),
'input_message_content' => $this->input_message_content?->toArray()
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultGif
{
$object = new self();
$object->type = InlineQueryResultType::GIF;
$object->id = $data['id'] ?? null;
$object->gif_url = $data['gif_url'] ?? null;
$object->gif_width = $data['gif_width'] ?? null;
$object->gif_height = $data['gif_height'] ?? null;
$object->gif_duration = $data['gif_duration'] ?? null;
$object->thumbnail_url = $data['thumbnail_url'] ?? null;
$object->thumbnail_mime_type = $data['thumbnail_mime_type'] ?? null;
$object->title = $data['title'] ?? null;
$object->caption = $data['caption'] ?? null;
$object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = isset($data['caption_entities']) ? array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities']) : null;
$object->reply_markup = isset($data['reply_markup']) ? array_map(fn(array $items) => InlineKeyboardMarkup::fromArray($items), $data['reply_markup']) : null;
$object->input_message_content = isset($data['input_message_content']) ? InputMessageContent::fromArray($data['input_message_content']) : null;
return $object;
}
}

View file

@ -0,0 +1,362 @@
<?php /** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\InputMessageContent\InputContactMessageContent;
class InlineQueryResultLocation extends InlineQueryResult implements ObjectTypeInterface
{
private float $latitude;
private float $longitude;
private string $title;
private ?float $horizontal_accuracy;
private ?int $live_period;
private ?int $heading;
private ?int $proximity_alert_radius;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputMessageContent $input_message_content;
private ?string $thumbnail_url;
private ?int $thumbnail_width;
private ?int $thumbnail_height;
/**
* Location latitude in degrees
*
* @return float
*/
public function getLatitude(): float
{
return $this->latitude;
}
/**
* Sets the location latitude in degrees
*
* @param float $latitude
* @return $this
*/
public function setLatitude(float $latitude): InlineQueryResultLocation
{
$this->latitude = $latitude;
return $this;
}
/**
* Location longitude in degrees
*
* @return float
*/
public function getLongitude(): float
{
return $this->longitude;
}
/**
* Sets the location longitude in degrees
*
* @param float $longitude
* @return $this
*/
public function setLongitude(float $longitude): InlineQueryResultLocation
{
$this->longitude = $longitude;
return $this;
}
/**
* Location title
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets the location title
*
* @param string $title
* @return $this
*/
public function setTitle(string $title): InlineQueryResultLocation
{
$this->title = $title;
return $this;
}
/**
* Optional. The radius of uncertainty for the location, measured in meters; 0-1500
*
* @return float|null
*/
public function getHorizontalAccuracy(): ?float
{
return $this->horizontal_accuracy;
}
/**
* Sets the radius of uncertainty for the location, measured in meters; 0-1500
*
* @param float|null $horizontal_accuracy
* @return $this
*/
public function setHorizontalAccuracy(?float $horizontal_accuracy): InlineQueryResultLocation
{
if($horizontal_accuracy < 0 || $horizontal_accuracy > 1500)
{
throw new InvalidArgumentException('horizontal_accuracy should be between 0 and 1500');
}
$this->horizontal_accuracy = $horizontal_accuracy;
return $this;
}
/**
* Optional. The Period in seconds for which the location can be updated should be between 60 and 86400.
*
* @return int|null
*/
public function getLivePeriod(): ?int
{
return $this->live_period;
}
/**
* Sets the period in seconds for which the location can be updated should be between 60 and 86400.
*
* @param int|null $live_period
* @return $this
*/
public function setLivePeriod(?int $live_period): InlineQueryResultLocation
{
if($live_period < 60 || $live_period > 86400)
{
throw new InvalidArgumentException('live_period should be between 60 and 86400');
}
$this->live_period = $live_period;
return $this;
}
/**
* Optional. For live locations, the direction in which the user is moving, in degrees. It Must be between 1 and 360 if specified.
*
* @return int|null
*/
public function getHeading(): ?int
{
return $this->heading;
}
/**
* Sets the direction in which the user is moving, in degrees. It Must be between 1 and 360 if specified.
*
* @param int|null $heading
* @return $this
*/
public function setHeading(?int $heading): InlineQueryResultLocation
{
if($heading < 1 || $heading > 360)
{
throw new InvalidArgumentException('heading should be between 1 and 360');
}
$this->heading = $heading;
return $this;
}
/**
* Optional. For live locations, a maximum distance for proximity alerts about
* approaching another chat member, in meters. It Must be between 1 and 100000 if specified.
*
* @return int|null
*/
public function getProximityAlertRadius(): ?int
{
return $this->proximity_alert_radius;
}
/**
* Sets the maximum distance for proximity alerts about approaching another chat member, in meters.
*
* @param int|null $proximity_alert_radius
* @return $this
*/
public function setProximityAlertRadius(?int $proximity_alert_radius): InlineQueryResultLocation
{
if($proximity_alert_radius < 1 || $proximity_alert_radius > 100000)
{
throw new InvalidArgumentException('proximity_alert_radius should be between 1 and 100000');
}
$this->proximity_alert_radius = $proximity_alert_radius;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultLocation
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the location
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the content of the message to be sent instead of the location
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultLocation
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* Optional. Url of the thumbnail for the result
*
* @return string|null
*/
public function getThumbnailUrl(): ?string
{
return $this->thumbnail_url;
}
/**
* Sets the url of the thumbnail for the result
*
* @param string|null $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(?string $thumbnail_url): InlineQueryResultLocation
{
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Optional. Thumbnail width
*
* @return int|null
*/
public function getThumbnailWidth(): ?int
{
return $this->thumbnail_width;
}
/**
* Sets the thumbnail width
*
* @param int|null $thumbnail_width
* @return $this
*/
public function setThumbnailWidth(?int $thumbnail_width): InlineQueryResultLocation
{
$this->thumbnail_width = $thumbnail_width;
return $this;
}
/**
* Optional. Thumbnail height
*
* @return int|null
*/
public function getThumbnailHeight(): ?int
{
return $this->thumbnail_height;
}
/**
* Sets the thumbnail height
*
* @param int|null $thumbnail_height
* @return $this
*/
public function setThumbnailHeight(?int $thumbnail_height): InlineQueryResultLocation
{
$this->thumbnail_height = $thumbnail_height;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'id' => $this->id,
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'title' => $this->title,
'horizontal_accuracy' => $this->horizontal_accuracy,
'live_period' => $this->live_period,
'heading' => $this->heading,
'proximity_alert_radius' => $this->proximity_alert_radius,
'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null,
'input_message_content' => ($this->input_message_content instanceof InputContactMessageContent) ? $this->input_message_content->toArray() : null,
'thumbnail_url' => $this->thumbnail_url,
'thumbnail_width' => $this->thumbnail_width,
'thumbnail_height' => $this->thumbnail_height,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultLocation
{
$object = new self();
$object->type = InlineQueryResultType::LOCATION;
$object->id = $data['id'] ?? null;
$object->latitude = $data['latitude'] ?? null;
$object->longitude = $data['longitude'] ?? null;
$object->title = $data['title'] ?? null;
$object->horizontal_accuracy = $data['horizontal_accuracy'] ?? null;
$object->live_period = $data['live_period'] ?? null;
$object->heading = $data['heading'] ?? null;
$object->proximity_alert_radius = $data['proximity_alert_radius'] ?? 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;
}
}

View file

@ -0,0 +1,345 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\InputMessageContent\InputVenueMessageContent;
use TgBotLib\Objects\MessageEntity;
class InlineQueryResultMpeg4Gif extends InlineQueryResult implements ObjectTypeInterface
{
private string $mpeg4_url;
private ?int $mpeg4_width;
private ?int $mpeg4_height;
private ?int $mpeg4_duration;
private string $thumbnail_url;
private ?string $thumbnail_mime_type;
private ?string $title;
private ?string $caption;
private ?string $parse_mode;
/**
* @var MessageEntity[]|null
*/
private ?array $caption_entities;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputMessageContent $input_message_content;
/**
* A valid URL for the MPEG4 file. File size must not exceed 1MB
*
* @return string
*/
public function getMpeg4Url(): string
{
return $this->mpeg4_url;
}
/**
*
*
* @param string $mpeg4_url
* @return $this
*/
public function setMpeg4Url(string $mpeg4_url): InlineQueryResultMpeg4Gif
{
$this->mpeg4_url = $mpeg4_url;
return $this;
}
/**
* Optional. Video width
*
* @return int|null
*/
public function getMpeg4Width(): ?int
{
return $this->mpeg4_width;
}
/**
* Optional. Video width
*
* @param int|null $mpeg4_width
* @return $this
*/
public function setMpeg4Width(?int $mpeg4_width): InlineQueryResultMpeg4Gif
{
$this->mpeg4_width = $mpeg4_width;
return $this;
}
/**
* Optional. Video height
*
* @return int|null
*/
public function getMpeg4Height(): ?int
{
return $this->mpeg4_height;
}
/**
* Optional. Video height
*
* @param int|null $mpeg4_height
* @return $this
*/
public function setMpeg4Height(?int $mpeg4_height): InlineQueryResultMpeg4Gif
{
$this->mpeg4_height = $mpeg4_height;
return $this;
}
/**
* Optional. Video duration in seconds
*
* @return int|null
*/
public function getMpeg4Duration(): ?int
{
return $this->mpeg4_duration;
}
/**
* Optional. Video duration in seconds
*
* @param int|null $mpeg4_duration
* @return $this
*/
public function setMpeg4Duration(?int $mpeg4_duration): InlineQueryResultMpeg4Gif
{
$this->mpeg4_duration = $mpeg4_duration;
return $this;
}
/**
* URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result
*
* @return string
*/
public function getThumbnailUrl(): string
{
return $this->thumbnail_url;
}
/**
* URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result
*
* @param string $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(string $thumbnail_url): InlineQueryResultMpeg4Gif
{
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Optional. MIME type of the thumbnail must be one of “image/jpeg”, “image/gif”, or “video/mp4”. Defaults to “image/jpeg”
*
* @return string|null
*/
public function getThumbnailMimeType(): ?string
{
return $this->thumbnail_mime_type;
}
/**
* Optional. MIME type of the thumbnail must be one of “image/jpeg”, “image/gif”, or “video/mp4”. Defaults to “image/jpeg”
*
* @param string|null $thumbnail_mime_type
* @return $this
*/
public function setThumbnailMimeType(?string $thumbnail_mime_type): InlineQueryResultMpeg4Gif
{
$this->thumbnail_mime_type = $thumbnail_mime_type;
return $this;
}
/**
* Optional. Title for the result
*
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* Optional. Title for the result
*
* @param string|null $title
* @return $this
*/
public function setTitle(?string $title): InlineQueryResultMpeg4Gif
{
$this->title = $title;
return $this;
}
/**
* Optional. Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing
*
* @return string|null
*/
public function getCaption(): ?string
{
return $this->caption;
}
/**
* Optional. Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing
*
* @param string|null $caption
* @return $this
*/
public function setCaption(?string $caption): InlineQueryResultMpeg4Gif
{
$this->caption = $caption;
return $this;
}
/**
* Optional. Mode for parsing entities in the caption. See formatting options for more details.
*
* @return string|null
*/
public function getParseMode(): ?string
{
return $this->parse_mode;
}
/**
* Optional. Mode for parsing entities in the caption. See formatting options for more details.
*
* @param string|null $parse_mode
* @return $this
*/
public function setParseMode(?string $parse_mode): InlineQueryResultMpeg4Gif
{
$this->parse_mode = $parse_mode;
return $this;
}
/**
* 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. List of special entities that appear in the caption, which can be specified instead of parse_mode
*
* @param MessageEntity[]|null $caption_entities
* @return $this
*/
public function setCaptionEntities(?array $caption_entities): InlineQueryResultMpeg4Gif
{
$this->caption_entities = $caption_entities;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Optional. Inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultMpeg4Gif
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the video animation
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Optional. Content of the message to be sent instead of the video animation
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultMpeg4Gif
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type ?? null,
'id' => $this->id ?? null,
'mpeg4_url' => $this->mpeg4_url ?? null,
'mpeg4_width' => $this->mpeg4_width ?? null,
'mpeg4_height' => $this->mpeg4_height ?? null,
'mpeg4_duration' => $this->mpeg4_duration ?? null,
'thumbnail_url' => $this->thumbnail_url ?? null,
'thumbnail_mime_type' => $this->thumbnail_mime_type ?? null,
'title' => $this->title ?? null,
'caption' => $this->caption ?? null,
'parse_mode' => $this->parse_mode ?? null,
'caption_entities' => is_null($this->caption_entities) ? array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities) : null,
'reply_markup' => ($this->reply_markup ?? null) ? $this->reply_markup->toArray() : null,
'input_message_content' => ($this->input_message_content ?? null) ? $this->input_message_content->toArray() : null,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultMpeg4Gif
{
$object = new self();
$object->type = InlineQueryResultType::MPEG_4_GIF;
$object->id = $data['id'] ?? null;
$object->mpeg4_url = $data['mpeg4_url'] ?? null;
$object->mpeg4_width = $data['mpeg4_width'] ?? null;
$object->mpeg4_height = $data['mpeg4_height'] ?? null;
$object->mpeg4_duration = $data['mpeg4_duration'] ?? null;
$object->thumbnail_url = $data['thumbnail_url'] ?? null;
$object->thumbnail_mime_type = $data['thumbnail_mime_type'] ?? null;
$object->title = $data['title'] ?? null;
$object->caption = $data['caption'] ?? null;
$object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = isset($data['caption_entities']) ? array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities']) : null;
$object->reply_markup = ($data['reply_markup'] ?? null) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null;
$object->input_message_content = ($data['input_message_content'] ?? null) ? InputVenueMessageContent::fromArray($data['input_message_content']) : null;
return $object;
}
}

View file

@ -0,0 +1,325 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\InputMessageContent\InputTextMessageContent;
use TgBotLib\Objects\MessageEntity;
class InlineQueryResultPhoto extends InlineQueryResult implements ObjectTypeInterface
{
private string $photo_url;
private string $thumbnail_url;
private ?int $photo_width;
private ?int $photo_height;
private ?string $title;
private ?string $description;
private ?string $caption;
private ?string $parse_mode;
/**
* @var MessageEntity[]|null
*/
private ?array $caption_entities;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputTextMessageContent $input_message_content;
/**
* A valid URL of the photo. Photo must be in JPEG format. Photo size must not exceed 5MB
*
* @return string
*/
public function getPhotoUrl(): string
{
return $this->photo_url;
}
/**
* Sets the value of the 'photo_url' field
*
* @param string $photo_url
* @return $this
*/
public function setPhotoUrl(string $photo_url): InlineQueryResultPhoto
{
$this->photo_url = $photo_url;
return $this;
}
/**
* URL of the thumbnail for the photo
*
* @return string
*/
public function getThumbnailUrl(): string
{
return $this->thumbnail_url;
}
/**
* Sets the value of the 'thumbnail_url' field
*
* @param string $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(string $thumbnail_url): InlineQueryResultPhoto
{
if(!filter_var($thumbnail_url, FILTER_VALIDATE_URL))
{
throw new InvalidArgumentException('thumbnail_url must be a valid URL');
}
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Optional. Width of the photo
*
* @return int|null
*/
public function getPhotoWidth(): ?int
{
return $this->photo_width;
}
/**
* Sets the value of the 'photo_width' field
*
* @param int|null $photo_width
* @return $this
*/
public function setPhotoWidth(?int $photo_width): InlineQueryResultPhoto
{
$this->photo_width = $photo_width;
return $this;
}
/**
* Optional. Height of the photo
*
* @return int|null
*/
public function getPhotoHeight(): ?int
{
return $this->photo_height;
}
/**
* Sets the value of the 'photo_height' field
*
* @param int|null $photo_height
* @return $this
*/
public function setPhotoHeight(?int $photo_height): InlineQueryResultPhoto
{
$this->photo_height = $photo_height;
return $this;
}
/**
* Optional. Title for the result
*
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* Sets the value of the 'title' field
*
* @param string|null $title
* @return $this
*/
public function setTitle(?string $title): InlineQueryResultPhoto
{
$this->title = $title;
return $this;
}
/**
* Optional. Short description of the result
*
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* Sets the value of the 'description' field
*
* @param string|null $description
* @return $this
*/
public function setDescription(?string $description): InlineQueryResultPhoto
{
$this->description = $description;
return $this;
}
/**
* Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing
*
* @return string|null
*/
public function getCaption(): ?string
{
return $this->caption;
}
/**
* Sets the value of the 'caption' field
*
* @param string|null $caption
* @return $this
*/
public function setCaption(?string $caption): InlineQueryResultPhoto
{
$this->caption = $caption;
return $this;
}
/**
* Optional. Mode for parsing entities in the photo caption. See formatting options for more details.
*
* @return string|null
* @link https://core.telegram.org/bots/api#formatting-options
*/
public function getParseMode(): ?string
{
return $this->parse_mode;
}
/**
* Sets the value of the 'parse_mode' field
*
* @param string|null $parse_mode
* @return $this
*/
public function setParseMode(?string $parse_mode): InlineQueryResultPhoto
{
$this->parse_mode = $parse_mode;
return $this;
}
/**
* 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;
}
/**
* Sets the value of the 'caption_entities' field
*
* @param array|null $caption_entities
* @return $this
*/
public function setCaptionEntities(?array $caption_entities): InlineQueryResultPhoto
{
$this->caption_entities = $caption_entities;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the value of the 'reply_markup' field
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultPhoto
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the photo
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the value of the 'input_message_content' field
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultPhoto
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type,
'id' => $this->id,
'photo_url' => $this->photo_url,
'thumbnail_url' => $this->thumbnail_url,
'photo_width' => $this->photo_width ?? null,
'photo_height' => $this->photo_height ?? null,
'title' => $this->title ?? null,
'description' => $this->description ?? null,
'caption' => $this->caption ?? null,
'parse_mode' => $this->parse_mode ?? null,
'caption_entities' => isset($data['caption_entities']) ? array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities) : null,
'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultPhoto
{
$object = new self();
$object->type = InlineQueryResultType::PHOTO;
$object->id = $data['id'] ?? null;
$object->photo_url = $data['photo_url'] ?? null;
$object->thumbnail_url = $data['thumbnail_url'] ?? null;
$object->photo_width = $data['photo_width'] ?? null;
$object->photo_height = $data['photo_height'] ?? null;
$object->title = $data['title'] ?? null;
$object->description = $data['description'] ?? null;
$object->caption = $data['caption'] ?? null;
$object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = isset($data['caption_entities']) ? array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities']) : null;
$object->reply_markup = ($data['reply_markup'] !== null) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null;
$object->input_message_content = $data['input_message_content'] ?? null;
return $object;
}
}

View file

@ -0,0 +1,366 @@
<?php /** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\InputMessageContent\InputVenueMessageContent;
class InlineQueryResultVenue extends InlineQueryResult implements ObjectTypeInterface
{
private float $latitude;
private float $longitude;
private string $title;
private string $address;
private ?string $foursquare_id;
private ?string $foursquare_type;
private ?string $google_place_id;
private ?string $google_place_type;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputMessageContent $input_message_content;
private ?string $thumbnail_url;
private ?int $thumbnail_width;
private ?int $thumbnail_height;
/**
* Latitude of the venue location in degrees
*
* @return float
*/
public function getLatitude(): float
{
return $this->latitude;
}
/**
* Sets the latitude of the venue location in degrees
*
* @param float $latitude
* @return $this
*/
public function setLatitude(float $latitude): InlineQueryResultVenue
{
$this->latitude = $latitude;
return $this;
}
/**
* Longitude of the venue location in degrees
*
* @return float
*/
public function getLongitude(): float
{
return $this->longitude;
}
/**
* Sets the longitude of the venue location in degrees
*
* @param float $longitude
* @return $this
*/
public function setLongitude(float $longitude): InlineQueryResultVenue
{
$this->longitude = $longitude;
return $this;
}
/**
* Title of the venue
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets the title of the venue
*
* @param string $title
* @return $this
*/
public function setTitle(string $title): InlineQueryResultVenue
{
$this->title = $title;
return $this;
}
/**
* Address of the venue
*
* @return string
*/
public function getAddress(): string
{
return $this->address;
}
/**
* Sets the address of the venue
*
* @param string $address
* @return $this
*/
public function setAddress(string $address): InlineQueryResultVenue
{
$this->address = $address;
return $this;
}
/**
* Optional. Foursquare identifier of the venue if known
*
* @return string|null
*/
public function getFoursquareId(): ?string
{
return $this->foursquare_id;
}
/**
* Sets the foursquare identifier of the venue if known
*
* @param string|null $foursquare_id
* @return $this
*/
public function setFoursquareId(?string $foursquare_id): InlineQueryResultVenue
{
$this->foursquare_id = $foursquare_id;
return $this;
}
/**
* Optional. Foursquare type of the venue, if known.
* (For example, “arts_entertainment/default, “arts_entertainment/aquarium” or “food/icecream”.)
*
* @return string|null
*/
public function getFoursquareType(): ?string
{
return $this->foursquare_type;
}
/**
* Sets the foursquare type of the venue, if known.
*
* @param string|null $foursquare_type
* @return $this
*/
public function setFoursquareType(?string $foursquare_type): InlineQueryResultVenue
{
$this->foursquare_type = $foursquare_type;
return $this;
}
/**
* Optional. Google Places identifier of the venue
*
* @return string|null
*/
public function getGooglePlaceId(): ?string
{
return $this->google_place_id;
}
/**
* Sets the google places identifier of the venue
*
* @param string|null $google_place_id
* @return $this
*/
public function setGooglePlaceId(?string $google_place_id): InlineQueryResultVenue
{
$this->google_place_id = $google_place_id;
return $this;
}
/**
* Optional. Google Places type of the venue.
*
* @see https://developers.google.com/places/web-service/supported_types
* @return string|null
*/
public function getGooglePlaceType(): ?string
{
return $this->google_place_type;
}
/**
* Sets the google places type of the venue.
*
* @param string|null $google_place_type
* @return $this
*/
public function setGooglePlaceType(?string $google_place_type): InlineQueryResultVenue
{
$this->google_place_type = $google_place_type;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultVenue
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the venue
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the content of the message to be sent instead of the venue
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultVenue
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* Optional. Url of the thumbnail for the result
*
* @return string|null
*/
public function getThumbnailUrl(): ?string
{
return $this->thumbnail_url;
}
/**
* Sets the url of the thumbnail for the result
*
* @param string|null $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(?string $thumbnail_url): InlineQueryResultVenue
{
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Optional. Thumbnail width
*
* @return int|null
*/
public function getThumbnailWidth(): ?int
{
return $this->thumbnail_width;
}
/**
* Sets the thumbnail width
*
* @param int|null $thumbnail_width
* @return $this
*/
public function setThumbnailWidth(?int $thumbnail_width): InlineQueryResultVenue
{
$this->thumbnail_width = $thumbnail_width;
return $this;
}
/**
* Optional. Thumbnail height
*
* @return int|null
*/
public function getThumbnailHeight(): ?int
{
return $this->thumbnail_height;
}
/**
* Sets the thumbnail height
*
* @param int|null $thumbnail_height
* @return $this
*/
public function setThumbnailHeight(?int $thumbnail_height): InlineQueryResultVenue
{
$this->thumbnail_height = $thumbnail_height;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'id' => $this->id,
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'title' => $this->title,
'address' => $this->address,
'foursquare_id' => $this->foursquare_id,
'foursquare_type' => $this->foursquare_type,
'google_place_id' => $this->google_place_id,
'google_place_type' => $this->google_place_type,
'reply_markup' => $this->reply_markup?->toArray(),
'input_message_content' => $this->input_message_content?->toArray(),
'thumbnail_url' => $this->thumbnail_url,
'thumbnail_width' => $this->thumbnail_width,
'thumbnail_height' => $this->thumbnail_height
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultVenue
{
$object = new self();
$object->type = InlineQueryResultType::VENUE;
$object->id = $data['id'] ?? null;
$object->latitude = $data['latitude'] ?? null;
$object->longitude = $data['longitude'] ?? null;
$object->title = $data['title'] ?? null;
$object->address = $data['address'] ?? null;
$object->foursquare_id = $data['foursquare_id'] ?? null;
$object->foursquare_type = $data['foursquare_type'] ?? null;
$object->google_place_id = $data['google_place_id'] ?? null;
$object->google_place_type = $data['google_place_type'] ?? null;
$object->reply_markup = isset($data['reply_markup']) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null;
$object->input_message_content = isset($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;
}
}

View file

@ -0,0 +1,380 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\MessageEntity;
class InlineQueryResultVideo extends InlineQueryResult implements ObjectTypeInterface
{
private string $video_url;
private string $mime_type;
private string $thumbnail_url;
private string $title;
private ?string $caption;
private ?string $parse_mode;
/**
* @var MessageEntity[]|null
*/
private ?array $caption_entities;
private ?int $video_width;
private ?int $video_height;
private ?int $video_duration;
private ?string $description;
private ?InlineKeyboardMarkup $reply_markup;
private ?InputMessageContent $input_message_content;
/**
* A valid URL for the embedded video player or video file
*
* @return string
*/
public function getVideoUrl(): string
{
return $this->video_url;
}
/**
* Sets a valid URL for the embedded video player or video file
*
* @param string $video_url
* @return $this
*/
public function setVideoUrl(string $video_url): InlineQueryResultVideo
{
if(!filter_var($video_url, FILTER_VALIDATE_URL))
{
throw new InvalidArgumentException('Video URL must be a valid URL');
}
$this->video_url = $video_url;
return $this;
}
/**
* MIME type of the content of the video URL, “text/html” or “video/mp4”
*
* @return string
*/
public function getMimeType(): string
{
return $this->mime_type;
}
/**
* Sets the MIME type of the content of the video URL, “text/html” or “video/mp4”
*
* @param string $mime_type
* @return $this
*/
public function setMimeType(string $mime_type): InlineQueryResultVideo
{
$this->mime_type = $mime_type;
return $this;
}
/**
* URL of the thumbnail (JPEG only) for the video
*
* @return string
*/
public function getThumbnailUrl(): string
{
return $this->thumbnail_url;
}
/**
* Sets the URL of the thumbnail (JPEG only) for the video
*
* @param string $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(string $thumbnail_url): InlineQueryResultVideo
{
if(!filter_var($thumbnail_url, FILTER_VALIDATE_URL))
{
throw new InvalidArgumentException('Thumbnail URL must be a valid URL');
}
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/**
* Title for the result
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets the title for the result
*
* @param string $title
* @return $this
*/
public function setTitle(string $title): InlineQueryResultVideo
{
$this->title = $title;
return $this;
}
/**
* Optional. Caption of the video to be sent, 0-1024 characters after entities parsing
*
* @return string|null
*/
public function getCaption(): ?string
{
return $this->caption;
}
/**
* Sets the caption of the video to be sent, 0-1024 characters after entities parsing
*
* @param string $caption
* @return $this
*/
public function setCaption(string $caption): InlineQueryResultVideo
{
$this->caption = $caption;
return $this;
}
/**
* Optional. Mode for parsing entities in the video caption. See formatting options for more details.
*
* @return string|null
*/
public function getParseMode(): ?string
{
return $this->parse_mode;
}
/**
* Sets the mode for parsing entities in the video caption. See formatting options for more details.
*
* @param string|null $parse_mode
* @return $this
*/
public function setParseMode(?string $parse_mode): InlineQueryResultVideo
{
$this->parse_mode = $parse_mode;
return $this;
}
/**
* 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;
}
/**
* Sets the list of special entities that appear in the caption, which can be specified instead of parse_mode
*
* @param array|null $caption_entities
* @return $this
*/
public function setCaptionEntities(?array $caption_entities): InlineQueryResultVideo
{
$this->caption_entities = $caption_entities;
return $this;
}
/**
* Optional. Video width
*
* @return int|null
*/
public function getVideoWidth(): ?int
{
return $this->video_width;
}
/**
* Sets the video width
*
* @param int|null $video_width
* @return $this
*/
public function setVideoWidth(?int $video_width): InlineQueryResultVideo
{
$this->video_width = $video_width;
return $this;
}
/**
* Optional. Video height
*
* @return int|null
*/
public function getVideoHeight(): ?int
{
return $this->video_height;
}
/**
* Sets the video height
*
* @param int|null $video_height
* @return $this
*/
public function setVideoHeight(?int $video_height): InlineQueryResultVideo
{
$this->video_height = $video_height;
return $this;
}
/**
* Optional. Video duration in seconds
*
* @return int|null
*/
public function getVideoDuration(): ?int
{
return $this->video_duration;
}
/**
* Sets the video duration in seconds
*
* @param int|null $video_duration
* @return $this
*/
public function setVideoDuration(?int $video_duration): InlineQueryResultVideo
{
$this->video_duration = $video_duration;
return $this;
}
/**
* Optional. Short description of the result
*
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* Sets the short description of the result
*
* @param string|null $description
* @return $this
*/
public function setDescription(?string $description): InlineQueryResultVideo
{
$this->description = $description;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultVideo
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* Optional. Content of the message to be sent instead of the video. This field is required if
* InlineQueryResultVideo is used to send an HTML-page as a result (e.g., a YouTube video).
*
* @return InputMessageContent|null
*/
public function getInputMessageContent(): ?InputMessageContent
{
return $this->input_message_content;
}
/**
* Sets the content of the message to be sent instead of the video. This field is required if
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): static
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type,
'id' => $this->id,
'video_url' => $this->video_url,
'mime_type' => $this->mime_type,
'thumbnail_url' => $this->thumbnail_url,
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parse_mode,
'caption_entities' => is_null($this->caption_entities) ? null : array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
'video_width' => $this->video_width,
'video_height' => $this->video_height,
'video_duration' => $this->video_duration,
'description' => $this->description,
'reply_markup' => ($this->reply_markup ?? null) ? $this->reply_markup->toArray() : null,
'input_message_content' => $this->input_message_content,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): ObjectTypeInterface
{
$object = new self();
$object->type = InlineQueryResultType::VIDEO;
$object->id = $data['id'] ?? null;
$object->video_url = $data['video_url'] ?? null;
$object->mime_type = $data['mime_type'] ?? null;
$object->thumbnail_url = $data['thumbnail_url'] ?? null;
$object->title = $data['title'] ?? null;
$object->caption = $data['caption'] ?? null;
$object->parse_mode = $data['parse_mode'] ?? null;
$object->caption_entities = isset($data['caption_entities']) ? array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities']) : null;
$object->video_width = $data['video_width'] ?? null;
$object->video_height = $data['video_height'] ?? null;
$object->video_duration = $data['video_duration'] ?? null;
$object->description = $data['description'] ?? 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;
return $object;
}
}

View file

@ -0,0 +1,251 @@
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Objects\Inline\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Enums\Types\InlineQueryResultType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\InlineKeyboardMarkup;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InputMessageContent;
use TgBotLib\Objects\MessageEntity;
class InlineQueryResultVoice extends InlineQueryResult implements ObjectTypeInterface
{
private string $voice_url;
private string $title;
private ?string $caption;
private ?string $parse_mode;
/**
* @var MessageEntity[]|null
*/
private ?array $caption_entities;
private ?int $voice_duration;
private ?InlineKeyboardMarkup $reply_markup;
private $input_message_content;
/**
* A valid URL for the voice recording
*
* @return string
* @noinspection PhpUnused
*/
public function getVoiceUrl(): string
{
return $this->voice_url;
}
/**
* Sets the voice_url of the result.
*
* @param string $voice_url
* @return $this
*/
public function setVoiceUrl(string $voice_url): InlineQueryResultVoice
{
if(!filter_var($voice_url, FILTER_VALIDATE_URL))
{
throw new InvalidArgumentException('voice_url must be a valid URL');
}
$this->voice_url = $voice_url;
return $this;
}
/**
* Recording title
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Sets the title of the result.
*
* @param string $title
* @return $this
*/
public function setTitle(string $title): InlineQueryResultVoice
{
$this->title = $title;
return $this;
}
/**
* Optional. Caption, 0-1024 characters after entities parsing
*
* @return string|null
*/
public function getCaption(): ?string
{
return $this->caption;
}
/**
* Sets the caption of the result.
*
* @param string|null $caption
* @return $this
*/
public function setCaption(?string $caption): InlineQueryResultVoice
{
$this->caption = $caption;
return $this;
}
/**
* 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;
}
/**
* Sets the parse_mode of the result.
*
* @param string|null $parse_mode
* @return $this
*/
public function setParseMode(?string $parse_mode): InlineQueryResultVoice
{
$this->parse_mode = $parse_mode;
return $this;
}
/**
* 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;
}
/**
* Sets the caption_entities of the result.
*
* @param array|null $caption_entities
* @return $this
*/
public function setCaptionEntities(?array $caption_entities): InlineQueryResultVoice
{
$this->caption_entities = $caption_entities;
return $this;
}
/**
* Optional. Recording duration in seconds
*
* @return int|null
* @noinspection PhpUnused
*/
public function getVoiceDuration(): ?int
{
return $this->voice_duration;
}
/**
* Sets the voice_duration of the result.
*
* @param int|null $voice_duration
* @return $this
*/
public function setVoiceDuration(?int $voice_duration): InlineQueryResultVoice
{
$this->voice_duration = $voice_duration;
return $this;
}
/**
* Optional. Inline keyboard attached to the message
*
* @return InlineKeyboardMarkup|null
*/
public function getReplyMarkup(): ?InlineKeyboardMarkup
{
return $this->reply_markup;
}
/**
* Sets the reply_markup of the result.
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultVoice
{
$this->reply_markup = $reply_markup;
return $this;
}
/**
* 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;
}
/**
* Sets the input_message_content of the result.
*
* @param InputMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(?InputMessageContent $input_message_content): InlineQueryResultVoice
{
$this->input_message_content = $input_message_content;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'type' => $this->type->value,
'id' => $this->id,
'voice_url' => $this->voice_url,
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => $this->parse_mode,
'caption_entities' => is_null($this->caption_entities) ? null : array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
'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 ObjectTypeInterface) ? $this->input_message_content->toArray() : null,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): InlineQueryResultVoice
{
$object = new self();
$object->type = InlineQueryResultType::VOICE;
$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 = array_map(fn(array $items) => MessageEntity::fromArray($items), $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;
}
}