Initial ugly commit of the refactored Entities.

parent ae619a1b
......@@ -10,122 +10,19 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Audio
*
* @link https://core.telegram.org/bots/api#audio
*
* @method string getFileId() Unique identifier for this file
* @method int getDuration() Duration of the audio in seconds as defined by sender
* @method string getPerformer() Optional. Performer of the audio as defined by sender or by audio tags
* @method string getTitle() Optional. Title of the audio as defined by sender or by audio tags
* @method string getMimeType() Optional. MIME type of the file as defined by sender
* @method int getFileSize() Optional. File size
*/
class Audio extends Entity
{
/**
* @var mixed|null
*/
protected $file_id;
/**
* @var mixed|null
*/
protected $duration;
/**
* @var mixed|null
*/
protected $performer;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $mime_type;
/**
* @var mixed|null
*/
protected $file_size;
/**
* Audio constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
}
$this->duration = isset($data['duration']) ? $data['duration'] : null;
if ($this->duration === '' || $this->duration === null) {
throw new TelegramException('duration is empty!');
}
$this->performer = isset($data['performer']) ? $data['performer'] : null;
$this->title = isset($data['title']) ? $data['title'] : null;
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
}
/**
* Get file id
*
* @return mixed|null
*/
public function getFileId()
{
return $this->file_id;
}
/**
* Get duration
*
* @return mixed|null
*/
public function getDuration()
{
return $this->duration;
}
/**
* Get performer
*
* @return mixed|null
*/
public function getPerformer()
{
return $this->performer;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get mime type
*
* @return mixed|null
*/
public function getMimeType()
{
return $this->mime_type;
}
/**
* Get file size
*
* @return mixed|null
*/
public function getFileSize()
{
return $this->file_size;
}
}
......@@ -10,114 +10,27 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class CallbackQuery.
*
* @link https://core.telegram.org/bots/api#callbackquery
*
* @method string getId() Unique identifier for this query
* @method User getFrom() Sender
* @method Message getMessage() Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
* @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query
* @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field
*/
class CallbackQuery extends Entity
{
/**
* @var mixed|null
*/
protected $id;
/**
* @var \Longman\TelegramBot\Entities\User
*/
protected $from;
/**
* @var \Longman\TelegramBot\Entities\Message
*/
protected $message;
/**
* @var mixed|null
*/
protected $inline_message_id;
/**
* @var mixed|null
*/
protected $data;
/**
* CallbackQuery constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->id = isset($data['id']) ? $data['id'] : null;
if (empty($this->id)) {
throw new TelegramException('id is empty!');
}
$this->from = isset($data['from']) ? $data['from'] : null;
if (empty($this->from)) {
throw new TelegramException('from is empty!');
}
$this->from = new User($this->from);
$this->message = isset($data['message']) ? $data['message'] : null;
if (!empty($this->message)) {
$this->message = new Message($this->message, $this->getBotName());
}
$this->inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null;
$this->data = isset($data['data']) ? $data['data'] : null;
if (empty($this->data)) {
throw new TelegramException('data is empty!');
}
}
/**
* Get id
*
* @return mixed|null
*/
public function getId()
{
return $this->id;
}
/**
* Get from
*
* @return \Longman\TelegramBot\Entities\User
*/
public function getFrom()
{
return $this->from;
}
/**
* Get message
*
* @return \Longman\TelegramBot\Entities\Message
*/
public function getMessage()
{
return $this->message;
}
/**
* Get inline message id
*
* @return mixed|null
*/
public function getInlineMessageId()
{
return $this->inline_message_id;
}
/**
* Get data
*
* @return mixed|null
* {@inheritdoc}
*/
public function getData()
public function subEntities()
{
return $this->data;
return [
'from' => User::class,
'message' => Message::class,
];
}
}
......@@ -10,198 +10,98 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Chat
*
* @link https://core.telegram.org/bots/api#chat
*
* @property int $id Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
* @property string $type Type of chat, can be either "private", "group", "supergroup" or "channel"
* @property string $title Optional. Title, for channels and group chats
* @property string $username Optional. Username, for private chats, supergroups and channels if available
* @property string $first_name Optional. First name of the other party in a private chat
* @property string $last_name Optional. Last name of the other party in a private chat
* @method int getId() Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
* @method string getType() Type of chat, can be either "private ", "group", "supergroup" or "channel"
* @method string getTitle() Optional. Title, for channels and group chats
* @method string getUsername() Optional. Username, for private chats, supergroups and channels if available
* @method string getFirstName() Optional. First name of the other party in a private chat
* @method string getLastName() Optional. Last name of the other party in a private chat
*/
class Chat extends Entity
{
/**
* @var mixed|null
*/
protected $id;
/**
* @var null
*/
protected $type;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $username;
/**
* @var mixed|null
*/
protected $first_name;
public function __construct($data)
{
parent::__construct($data);
/**
* @var mixed|null
*/
protected $last_name;
if (!$this->getType()) {
if ($this->getId() > 0) {
$this->type = 'private';
} elseif ($this->getId() < 0) {
$this->type = 'group';
}
}
}
/**
* Chat constructor.
* Try mention
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
* @return string|null
*/
public function __construct(array $data)
public function tryMention()
{
$this->id = isset($data['id']) ? $data['id'] : null;
if (empty($this->id)) {
throw new TelegramException('id is empty!');
}
if ($this->isPrivateChat()) {
if ($this->username === null) {
if ($this->last_name !== null) {
return $this->first_name . ' ' . $this->last_name;
}
if (isset($data['type'])) {
$this->type = $data['type'];
} else {
if ($this->id > 0) {
$this->type = 'private';
} elseif ($this->id < 0) {
$this->type = 'group';
} else {
$this->type = null;
return $this->first_name;
}
return '@' . $this->username;
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->first_name = isset($data['first_name']) ? $data['first_name'] : null;
$this->last_name = isset($data['last_name']) ? $data['last_name'] : null;
$this->username = isset($data['username']) ? $data['username'] : null;
return $this->getTitle();
}
/**
* Check if is group chat
* Check if this is a group chat
*
* @return bool
*/
public function isGroupChat()
{
if ($this->type == 'group' || $this->id < 0) {
return true;
}
return false;
return $this->type === 'group' || $this->id < 0;
}
/**
* Check if is private chat
* Check if this is a private chat
*
* @return bool
*/
public function isPrivateChat()
{
if ($this->type == 'private') {
return true;
}
return false;
return $this->type === 'private';
}
/**
* Check if is super group
* Check if this is a super group
*
* @return bool
*/
public function isSuperGroup()
{
if ($this->type == 'supergroup') {
return true;
}
return false;
return $this->type === 'supergroup';
}
/**
* Check if is channel
* Check if this is a channel
*
* @return bool
*/
public function isChannel()
{
if ($this->type == 'channel') {
return true;
}
return false;
}
/**
* Get id
*
* @return mixed|null
*/
public function getId()
{
return $this->id;
}
/**
* Get type
*
* @return null
*/
public function getType()
{
return $this->type;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get first name
*
* @return mixed|null
*/
public function getFirstName()
{
return $this->first_name;
}
/**
* Get last name
*
* @return mixed|null
*/
public function getLastName()
{
return $this->last_name;
}
/**
* Get username
*
* @return mixed|null
*/
public function getUsername()
{
return $this->username;
}
/**
* Try mention
*
* @return mixed|null|string
*/
public function tryMention()
{
if ($this->isPrivateChat()) {
if (is_null($this->username)) {
if (!is_null($this->last_name)) {
return $this->first_name . ' ' . $this->last_name;
}
return $this->first_name;
}
return '@' . $this->username;
}
return $this->getTitle();
return $this->type === 'channel';
}
}
......@@ -10,57 +10,23 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class ChatMember
*
* @link https://core.telegram.org/bots/api#chatmember
*
* @method User getUser() Information about the user.
* @method string getStatus() The member's status in the chat. Can be "creator", "administrator", "member", "left" or "kicked"
*/
class ChatMember extends Entity
{
/**
* @var \Longman\TelegramBot\Entities\User
*/
protected $user;
/**
* @var mixed|null
*/
protected $status;
/**
* ChatMember constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->user = isset($data['user']) ? $data['user'] : null;
if (empty($this->user)) {
throw new TelegramException('user is empty!');
}
$this->user = new User($data['user']);
$this->status = isset($data['status']) ? $data['status'] : null;
if ($this->status === '') {
throw new TelegramException('status is empty!');
}
}
/**
* Get user
*
* @return \Longman\TelegramBot\Entities\User
*/
public function getUser()
{
return $this->user;
}
/**
* Get status
*
* @return mixed|null
* {@inheritdoc}
*/
public function getStatus()
public function subEntities()
{
return $this->status;
return [
'user' => User::class,
];
}
}
......@@ -10,110 +10,27 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class ChosenInlineResult
*
* @link https://core.telegram.org/bots/api#choseninlineresult
*
* @method string getResultId() The unique identifier for the result that was chosen
* @method User getFrom() The user that chose the result
* @method Location getLocation() Optional. Sender location, only for bots that require user location
* @method string getInlineMessageId() Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message.
* @method string getQuery() The query that was used to obtain the result
*/
class ChosenInlineResult extends Entity
{
/**
* @var mixed|null
*/
protected $result_id;
/**
* @var \Longman\TelegramBot\Entities\User
*/
protected $from;
/**
* @var \Longman\TelegramBot\Entities\Location
*/
protected $location;
/**
* @var mixed|null
*/
protected $inline_message_id;
/**
* @var mixed|null
*/
protected $query;
/**
* ChosenInlineResult constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->result_id = isset($data['result_id']) ? $data['result_id'] : null;
if (empty($this->result_id)) {
throw new TelegramException('result_id is empty!');
}
$this->from = isset($data['from']) ? $data['from'] : null;
if (empty($this->from)) {
throw new TelegramException('from is empty!');
}
$this->from = new User($this->from);
$this->location = isset($data['location']) ? $data['location'] : null;
if (!empty($this->location)) {
$this->location = new Location($this->location);
}
$this->inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null;
$this->query = isset($data['query']) ? $data['query'] : null;
}
/**
* Ger result id
*
* @return mixed|null
*/
public function getResultId()
{
return $this->result_id;
}
/**
* Get from
*
* @return \Longman\TelegramBot\Entities\User
*/
public function getFrom()
{
return $this->from;
}
/**
* Get location
*
* @return \Longman\TelegramBot\Entities\Location
*/
public function getLocation()
{
return $this->location;
}
/**
* Get inline message id
*
* @return mixed|null
*/
public function getInlineMessageId()
{
return $this->inline_message_id;
}
/**
* Get query
*
* @return mixed|null
* {@inheritdoc}
*/
public function getQuery()
protected function subEntities()
{
return $this->query;
return [
'from' => User::class,
'location' => Location::class,
];
}
}
......@@ -10,89 +10,17 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Contact
*
* @link https://core.telegram.org/bots/api#contact
*
* @method string getPhoneNumber() Contact's phone number
* @method string getFirstName() Contact's first name
* @method string getLastName() Optional. Contact's last name
* @method int getUserId() Optional. Contact's user identifier in Telegram
*/
class Contact extends Entity
{
/**
* @var mixed|null
*/
protected $phone_number;
/**
* @var mixed|null
*/
protected $first_name;
/**
* @var mixed|null
*/
protected $last_name;
/**
* @var mixed|null
*/
protected $user_id;
/**
* Contact constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->phone_number = isset($data['phone_number']) ? $data['phone_number'] : null;
if (empty($this->phone_number)) {
throw new TelegramException('phone_number is empty!');
}
$this->first_name = isset($data['first_name']) ? $data['first_name'] : null;
if (empty($this->first_name)) {
throw new TelegramException('first_name is empty!');
}
$this->last_name = isset($data['last_name']) ? $data['last_name'] : null;
$this->user_id = isset($data['user_id']) ? $data['user_id'] : null;
}
/**
* Get phone number
*
* @return mixed|null
*/
public function getPhoneNumber()
{
return $this->phone_number;
}
/**
* Get first name
*
* @return mixed|null
*/
public function getFirstName()
{
return $this->first_name;
}
/**
* Get last name
*
* @return mixed|null
*/
public function getLastName()
{
return $this->last_name;
}
/**
* Get user id
*
* @return mixed|null
*/
public function getUserId()
{
return $this->user_id;
}
}
......@@ -10,105 +10,26 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Document
*
* @link https://core.telegram.org/bots/api#document
*
* @method string getFileId() Unique file identifier
* @method PhotoSize getThumb() Optional. Document thumbnail as defined by sender
* @method string getFileName() Optional. Original filename as defined by sender
* @method string getMimeType() Optional. MIME type of the file as defined by sender
* @method int getFileSize() Optional. File size
*/
class Document extends Entity
{
/**
* @var mixed|null
*/
protected $file_id;
/**
* @var \Longman\TelegramBot\Entities\PhotoSize
*/
protected $thumb;
/**
* @var mixed|null
*/
protected $file_name;
/**
* @var mixed|null
*/
protected $mime_type;
/**
* @var mixed|null
*/
protected $file_size;
/**
* Document constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
}
$this->thumb = isset($data['thumb']) ? $data['thumb'] : null;
if (!empty($this->thumb)) {
$this->thumb = new PhotoSize($this->thumb);
}
$this->file_name = isset($data['file_name']) ? $data['file_name'] : null;
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
}
/**
* Get file id
*
* @return mixed|null
*/
public function getFileId()
{
return $this->file_id;
}
/**
* Get thumb
*
* @return \Longman\TelegramBot\Entities\PhotoSize
*/
public function getThumb()
{
return $this->thumb;
}
/**
* Get file name
*
* @return mixed|null
*/
public function getFileName()
{
return $this->file_name;
}
/**
* Get mime type
*
* @return mixed|null
*/
public function getMimeType()
{
return $this->mime_type;
}
/**
* Get file size
*
* @return mixed|null
* {@inheritdoc}
*/
public function getFileSize()
protected function subEntities()
{
return $this->file_size;
return [
'thumb' => PhotoSize::class,
];
}
}
......@@ -10,7 +10,10 @@
namespace Longman\TelegramBot\Entities;
class InputMessageContent extends Entity
/**
* {@inheritdoc}
*/
class EditedMessage extends Message
{
}
......@@ -10,8 +10,14 @@
namespace Longman\TelegramBot\Entities;
use Exception;
use ReflectionObject;
/**
* Class Entity
*
* This is the base class for all entities.
*/
class Entity
{
/**
......@@ -29,6 +35,23 @@ class Entity
return $this->bot_name;
}
/**
* Entity constructor.
*
* @todo Get rid of the $bot_name, it shouldn't be here!
*
* @param $data
* @param string $bot_name
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct($data, $bot_name = '')
{
$this->assignMemberVariables($data);
$this->validate();
$this->bot_name = $bot_name;
}
/**
* Perform to json
*
......@@ -36,21 +59,19 @@ class Entity
*/
public function toJson()
{
$fields = $this->reflect($this);
$json = json_encode($fields);
return $json;
return json_encode($this->reflect($this));
}
/**
* Reflect
*
* @param null $object
*
* @return array
*/
public function reflect($object = null)
{
if ($object == null) {
if ($object === null) {
$object = $this;
}
......@@ -61,7 +82,7 @@ class Entity
foreach ($properties as $property) {
$name = $property->getName();
if ($name == 'bot_name') {
if ($name === 'bot_name') {
continue;
}
......@@ -107,13 +128,14 @@ class Entity
} else {
$property->setAccessible(true);
$value = $property->getValue($object);
if (is_null($value)) {
if (null === $value) {
continue;
}
$fields[$name] = $value;
}
}
}
return $fields;
}
......@@ -126,4 +148,113 @@ class Entity
{
return $this->toJson();
}
/**
* Helper to set member variables
*
* @param array $data
*/
protected function assignMemberVariables(array $data)
{
foreach ($data as $key => $value) {
$this->$key = $value;
}
}
/**
* Get the list of the properties that are themselves Entities
*
* @return array
*/
protected function subEntities()
{
return [];
}
/**
* Perform any special entity validation
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
protected function validate()
{
}
/**
* Get a property from the current Entity
*
* @param mixed $property
* @param mixed $default
*
* @return mixed
*/
public function getProperty($property, $default = null)
{
if (isset($this->$property)) {
return $this->$property;
}
return $default;
}
/**
* Return the variable for the called getter
*
* @param $method
* @param $args
*
* @return mixed|null
*/
public function __call($method, $args)
{
$action = substr($method, 0, 3);
if ($action === 'get') {
//Convert method to snake_case (which is the name of the property)
$property_name = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', substr($method, 3))), '_');
$property = $this->getProperty($property_name);
if ($property !== null) {
//Get all sub-Entities of the current Entity
$sub_entities = $this->subEntities();
if (isset($sub_entities[$property_name])) {
return new $sub_entities[$property_name]($property);
}
return $property;
}
}
return null;
}
/**
* Return an array of nice objects from an array of object arrays
*
* This method is used to generate pretty object arrays
* mainly for PhotoSize and Entities object arrays.
*
* @param string $class
* @param string $property
*
* @return array
*/
protected function makePrettyObjectArray($class, $property)
{
$new_objects = [];
try {
if ($objects = $this->getProperty($property)) {
foreach ($objects as $object) {
if (!empty($object)) {
$new_objects[] = new $class($object);
}
}
}
} catch (Exception $e) {
$new_objects = [];
}
return $new_objects;
}
}
......@@ -10,70 +10,16 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class File
*
* @link https://core.telegram.org/bots/api#file
*
* @method string getFileId() Unique identifier for this file
* @method int getFileSize() Optional. File size, if known
* @method string getFilePath() Optional. File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file.
*/
class File extends Entity
{
/**
* @var mixed|null
*/
protected $file_id;
/**
* @var mixed|null
*/
protected $file_size;
/**
* @var mixed|null
*/
protected $file_path;
/**
* File constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
}
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
$this->file_path = isset($data['file_path']) ? $data['file_path'] : null;
}
/**
* Get file id
*
* @return mixed|null
*/
public function getFileId()
{
return $this->file_id;
}
/**
* Get file size
*
* @return mixed|null
*/
public function getFileSize()
{
return $this->file_size;
}
/**
* Get file path
*
* @return mixed|null
*/
public function getFilePath()
{
return $this->file_path;
}
}
......@@ -12,45 +12,26 @@ namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class InlineKeyboardButton
*
* @link https://core.telegram.org/bots/api#inlinekeyboardbutton
*
* @method string getText() Label text on the button
* @method string getUrl() Optional. HTTP url to be opened when button is pressed
* @method string getCallbackData() Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
* @method string getSwitchInlineQuery() 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. Can be empty, in which case just the bot’s username will be inserted.
*/
class InlineKeyboardButton extends Entity
{
/**
* @var mixed|null
*/
protected $text;
/**
* @var string
*/
protected $url;
/**
* @var mixed
* {@inheritdoc}
*/
protected $callback_data;
/**
* @var mixed
*/
protected $switch_inline_query;
/**
* InlineKeyboardButton constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
protected function validate()
{
$this->text = isset($data['text']) ? $data['text'] : null;
if (empty($this->text)) {
throw new TelegramException('text is empty!');
}
$num_params = 0;
foreach (['url', 'callback_data', 'switch_inline_query'] as $param) {
if (!empty($data[$param])) {
$this->$param = $data[$param];
if (!empty($this->getProperty($param))) {
$num_params++;
}
}
......
......@@ -12,6 +12,11 @@ namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class InlineKeyboardMarkup
*
* @link https://core.telegram.org/bots/api#inlinekeyboardmarkup
*/
class InlineKeyboardMarkup extends Entity
{
/**
......
......@@ -10,110 +10,27 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class InlineQuery
*
* @link https://core.telegram.org/bots/api#inlinequery
*
* @method string getId() Unique identifier for this query
* @method User getFrom() Sender
* @method Location getLocation() Optional. Sender location, only for bots that request user location
* @method string getQuery() Text of the query (up to 512 characters)
* @method string getOffset() Offset of the results to be returned, can be controlled by the bot
*/
class InlineQuery extends Entity
{
/**
* @var mixed|null
*/
protected $id;
/**
* @var \Longman\TelegramBot\Entities\User
*/
protected $from;
/**
* @var \Longman\TelegramBot\Entities\Location
*/
protected $location;
/**
* @var mixed|null
*/
protected $query;
/**
* @var mixed|null
*/
protected $offset;
/**
* InlineQuery constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->id = isset($data['id']) ? $data['id'] : null;
if (empty($this->id)) {
throw new TelegramException('id is empty!');
}
$this->from = isset($data['from']) ? $data['from'] : null;
if (empty($this->from)) {
throw new TelegramException('from is empty!');
}
$this->from = new User($this->from);
$this->location = isset($data['location']) ? $data['location'] : null;
if (!empty($this->location)) {
$this->location = new Location($this->location);
}
$this->query = isset($data['query']) ? $data['query'] : null;
$this->offset = isset($data['offset']) ? $data['offset'] : null;
}
/**
* Get id
*
* @return mixed|null
*/
public function getId()
{
return $this->id;
}
/**
* Get from
*
* @return \Longman\TelegramBot\Entities\User
*/
public function getFrom()
{
return $this->from;
}
/**
* Get location
*
* @return \Longman\TelegramBot\Entities\Location
*/
public function getLocation()
{
return $this->location;
}
/**
* Get query
*
* @return mixed|null
*/
public function getQuery()
{
return $this->query;
}
/**
* Get offset
*
* @return mixed|null
* {@inheritdoc}
*/
public function getOffset()
protected function subEntities()
{
return $this->offset;
return [
'from' => User::class,
'location' => Location::class,
];
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\Entity;
abstract class InlineEntity extends Entity
{
/**
* Magic method to set properties dynamically
*
* @param $method
* @param $args
*
* @return \Longman\TelegramBot\Entities\InlineQuery\InlineEntity
*/
public function __call($method, $args)
{
$action = substr($method, 0, 3);
if ($action === 'set') {
//Convert method to snake_case (which is the name of the property)
$property_name = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', substr($method, 3))), '_');
$this->$property_name = $args[0];
}
return $this;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
/**
* Class InlineQueryResultArticle
*
* @link https://core.telegram.org/bots/api#inlinequeryresultarticle
*
* <code>
* $data = [
* 'id' => '',
* 'title' => '',
* 'input_message_content' => <InputMessageContent>,
* 'reply_markup' => <InlineKeyboardMarkup>,
* 'url' => '',
* 'hide_url' => true,
* 'description' => '',
* 'thumb_url' => '',
* 'thumb_width' => 30,
* 'thumb_height' => 30,
* ];
* </code>
*
* @method string getType() Type of the result, must be article
* @method string getId() Unique identifier for this result, 1-64 Bytes
* @method string getTitle() Title of the result
* @method InputMessageContent getInputMessageContent() Content of the message to be sent
* @method InlineKeyboardMarkup getReplyMarkup() Optional. Inline keyboard attached to the message
* @method string getUrl() Optional. URL of the result
* @method bool getHideUrl() Optional. Pass True, if you don't want the URL to be shown in the message
* @method string getDescription() Optional. Short description of the result
* @method string getThumbUrl() Optional. Url of the thumbnail for the result
* @method int getThumbWidth() Optional. Thumbnail width
* @method int getThumbHeight() Optional. Thumbnail height
*
* @method $this setId(string $id) Unique identifier for this result, 1-64 Bytes
* @method $this setTitle(string $title) Title of the result
* @method $this setInputMessageContent(InputMessageContent $input_message_content) Content of the message to be sent
* @method $this setReplyMarkup(InlineKeyboardMarkup $reply_markup) Optional. Inline keyboard attached to the message
* @method $this setUrl(string $url) Optional. URL of the result
* @method $this setHideUrl(bool $hide_url) Optional. Pass True, if you don't want the URL to be shown in the message
* @method $this setDescription(string $description) Optional. Short description of the result
* @method $this setThumbUrl(string $thumb_url) Optional. Url of the thumbnail for the result
* @method $this setThumbWidth(int $thumb_width) Optional. Thumbnail width
* @method $this setThumbHeight(int $thumb_height) Optional. Thumbnail height
*/
class InlineQueryResultArticle extends InlineEntity
{
/**
* InlineQueryResultArticle constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'article';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
/**
* Class InlineQueryResultAudio
*
* @link https://core.telegram.org/bots/api#inlinequeryresultaudio
*
* <code>
* $data = [
* 'id' => '',
* 'audio_url' => '',
* 'title' => '',
* 'performer' => '',
* 'audio_duration' => 123,
* 'reply_markup' => <InlineKeyboardMarkup>,
* 'input_message_content' => <InputMessageContent>,
* ];
* </code>
*
* @method string getType() Type of the result, must be audio
* @method string getId() Unique identifier for this result, 1-64 bytes
* @method string getAudioUrl() A valid URL for the audio file
* @method string getTitle() Title
* @method string getPerformer() Optional. Performer
* @method int getAudioDuration() Optional. Audio duration in seconds
* @method InlineKeyboardMarkup getReplyMarkup() Optional. Inline keyboard attached to the message
* @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the audio
*
* @method $this setId(string $id) Unique identifier for this result, 1-64 bytes
* @method $this setAudioUrl(string $audio_url) A valid URL for the audio file
* @method $this setTitle(string $title) Title
* @method $this setPerformer(string $performer) Optional. Performer
* @method $this setAudioDuration(int $audio_duration) Optional. Audio duration in seconds
* @method $this setReplyMarkup(InlineKeyboardMarkup $reply_markup) Optional. Inline keyboard attached to the message
* @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the photo
*/
class InlineQueryResultAudio extends InlineEntity
{
/**
* InlineQueryResultAudio constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'audio';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
/**
* Class InlineQueryResultCachedAudio
*
* @link https://core.telegram.org/bots/api#inlinequeryresultcachedaudio
*
* <code>
* $data = [
* 'id' => '',
* 'audio_file_id' => '',
* 'reply_markup' => <InlineKeyboardMarkup>,
* 'input_message_content' => <InputMessageContent>,
* ];
* </code>
*
* @method string getType() Type of the result, must be audio
* @method string getId() Unique identifier for this result, 1-64 bytes
* @method string getAudioFileId() A valid file identifier for the audio file
* @method InlineKeyboardMarkup getReplyMarkup() Optional. An Inline keyboard attached to the message
* @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the audio
*
* @method $this setId(string $id) Unique identifier for this result, 1-64 bytes
* @method $this setAudioFileId(string $audio_file_id) A valid file identifier for the audio file
* @method $this setReplyMarkup(InlineKeyboardMarkup $reply_markup) Optional. Inline keyboard attached to the message
* @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the photo
*/
class InlineQueryResultCachedAudio extends InlineEntity
{
/**
* InlineQueryResultCachedAudio constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'audio';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
/**
* Class InlineQueryResultCachedDocument
*
* @link https://core.telegram.org/bots/api#inlinequeryresultcacheddocument
*
* <code>
* $data = [
* 'id' => '',
* 'title' => '',
* 'document_file_id' => '',
* 'description' => '',
* 'caption' => '',
* 'reply_markup' => <InlineKeyboardMarkup>,
* 'input_message_content' => <InputMessageContent>,
* ];
* </code>
*
* @method string getType() Type of the result, must be document
* @method string getId() Unique identifier for this result, 1-64 bytes
* @method string getTitle() Title for the result
* @method string getDocumentFileId() A valid file identifier for the file
* @method string getDescription() Optional. Short description of the result
* @method string getCaption() Optional. Caption of the document to be sent, 0-200 characters
* @method InlineKeyboardMarkup getReplyMarkup() Optional. An Inline keyboard attached to the message
* @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the file
*
* @method $this setId(string $id) Unique identifier for this result, 1-64 bytes
* @method $this setTitle(string $title) Title for the result
* @method $this setDocumentFileId(string $document_file_id) A valid file identifier for the file
* @method $this setDescription(string $description) Optional. Short description of the result
* @method $this setCaption(string $caption) Optional. Caption of the document to be sent, 0-200 characters
* @method $this setReplyMarkup(InlineKeyboardMarkup $reply_markup) Optional. Inline keyboard attached to the message
* @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the file
*/
class InlineQueryResultCachedDocument extends InlineEntity
{
/**
* InlineQueryResultCachedDocument constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'document';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
/**
* Class InlineQueryResultCachedGif
*
* @link https://core.telegram.org/bots/api#inlinequeryresultcachedgif
*
* <code>
* $data = [
* 'id' => '',
* 'gif_file_id' => '',
* 'title' => '',
* 'caption' => '',
* 'reply_markup' => <InlineKeyboardMarkup>,
* 'input_message_content' => <InputMessageContent>,
* ];
* </code>
*
* @method string getType() Type of the result, must be gif
* @method string getId() Unique identifier for this result, 1-64 bytes
* @method string getGifFileId() A valid file identifier for the GIF file
* @method string getTitle() Optional. Title for the result
* @method string getCaption() Optional. Caption of the GIF file to be sent, 0-200 characters
* @method InlineKeyboardMarkup getReplyMarkup() Optional. An Inline keyboard attached to the message
* @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the GIF animation
*
* @method $this setId(string $id) Unique identifier for this result, 1-64 bytes
* @method $this setGifFileId(string $gif_file_id) A valid file identifier for the GIF file
* @method $this setTitle(string $title) Optional. Title for the result
* @method $this setCaption(string $caption) Optional. Caption of the GIF file to be sent, 0-200 characters
* @method $this setReplyMarkup(InlineKeyboardMarkup $reply_markup) Optional. Inline keyboard attached to the message
* @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the photo
*/
class InlineQueryResultCachedGif extends InlineEntity
{
/**
* InlineQueryResultCachedGif constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'gif';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
/**
* Class InlineQueryResultCachedMpeg4Gif
*
* @link https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif
*
* <code>
* $data = [
* 'id' => '',
* 'mpeg4_file_id' => '',
* 'title' => '',
* 'caption' => '',
* 'reply_markup' => <InlineKeyboardMarkup>,
* 'input_message_content' => <InputMessageContent>,
* ];
* </code>
*
* @method String getType() Type of the result, must be mpeg4_gif
* @method String getId() Unique identifier for this result, 1-64 bytes
* @method String getMpeg4FileId() A valid file identifier for the MP4 file
* @method String getTitle() Optional. Title for the result
* @method String getCaption() Optional. Caption of the MPEG-4 file to be sent, 0-200 characters
* @method InlineKeyboardMarkup getReplyMarkup() Optional. An Inline keyboard attached to the message
* @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the video animation
*
* @method $this setId(string $id) Unique identifier for this result, 1-64 bytes
* @method $this setMpeg4FileId(string $mpeg4_file_id) A valid file identifier for the MP4 file
* @method $this setTitle(string $title) Optional. Title for the result
* @method $this setCaption(string $caption) Optional. Caption of the MPEG-4 file to be sent, 0-200 characters
* @method $this setReplyMarkup(InlineKeyboardMarkup $reply_markup) Optional. Inline keyboard attached to the message
* @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the video animation
*/
class InlineQueryResultCachedMpeg4Gif extends InlineEntity
{
/**
* InlineQueryResultCachedMpeg4Gif constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'mpeg4_gif';
parent::__construct($data);
}
}
......@@ -8,42 +8,20 @@
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedAudio extends InlineQueryResult
class InlineQueryResultCachedPhoto extends InlineEntity
{
/**
* @var mixed|null
*/
protected $audio_file_id;
/**
* InlineQueryResultCachedAudio constructor.
* InlineQueryResultCachedPhoto constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
public function __construct(array $data = [])
{
$data['type'] = 'photo';
parent::__construct($data);
$this->type = 'audio';
$this->audio_file_id = isset($data['audio_file_id']) ? $data['audio_file_id'] : null;
if (empty($this->audio_file_id)) {
throw new TelegramException('audio_file_id is empty!');
}
}
/**
* Get audio file id
*
* @return mixed|null
*/
public function getAudioFileId()
{
return $this->audio_file_id;
}
}
......@@ -8,42 +8,20 @@
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedSticker extends InlineQueryResult
class InlineQueryResultCachedSticker extends InlineEntity
{
/**
* @var mixed|null
*/
protected $sticker_file_id;
/**
* InlineQueryResultCachedSticker constructor.
* InlineQueryResultCachedSticker constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
public function __construct(array $data = [])
{
$data['type'] = 'sticker';
parent::__construct($data);
$this->type = 'sticker';
$this->photo_file_id = isset($data['sticker_file_id']) ? $data['sticker_file_id'] : null;
if (empty($this->sticker_file_id)) {
throw new TelegramException('sticker_file_id is empty!');
}
}
/**
* Get sticker file id
*
* @return mixed|null
*/
public function getStickerFileId()
{
return $this->sticker_file_id;
}
}
......@@ -8,38 +8,20 @@
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Exception\TelegramException;
class InputLocationMessageContent extends InputMessageContent
class InlineQueryResultCachedVideo extends InlineEntity
{
/**
* @var mixed|null
*/
protected $latitude;
/**
* @var mixed|null
*/
protected $longitude;
/**
* InputLocationMessageContent constructor.
* InlineQueryResultCachedVideo constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
public function __construct(array $data = [])
{
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
$data['type'] = 'video';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultCachedVoice extends InlineEntity
{
/**
* InlineQueryResultCachedVoice constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'voice';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultContact extends InlineEntity
{
/**
* InlineQueryResultContact constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'contact';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultDocument extends InlineEntity
{
/**
* InlineQueryResultDocument constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'document';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultGif extends InlineEntity
{
/**
* InlineQueryResultGif constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'gif';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultLocation extends InlineEntity
{
/**
* InlineQueryResultLocation constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'location';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultMpeg4Gif extends InlineEntity
{
/**
* InlineQueryResultMpeg4Gif constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'mpeg4_gif';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultPhoto extends InlineEntity
{
/**
* InlineQueryResultPhoto constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'photo';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultVenue extends InlineEntity
{
/**
* InlineQueryResultVenue constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'venue';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultVideo extends InlineEntity
{
/**
* InlineQueryResultVideo constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'video';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
class InlineQueryResultVoice extends InlineEntity
{
/**
* InlineQueryResultVoice constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'voice';
parent::__construct($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResult extends Entity
{
/**
* @var string
*/
protected $type;
/**
* @var mixed|null
*/
protected $id;
/**
* @var mixed|null
*/
protected $input_message_content;
/**
* @var mixed|null
*/
protected $reply_markup;
/**
* InlineQueryResult constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->type = null;
$this->id = isset($data['id']) ? $data['id'] : null;
if (empty($this->id)) {
throw new TelegramException('id is empty!');
}
$this->input_message_content = isset($data['input_message_content']) ? $data['input_message_content'] : null;
$this->reply_markup = isset($data['reply_markup']) ? $data['reply_markup'] : null;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Get id
*
* @return mixed|null
*/
public function getId()
{
return $this->id;
}
/**
* Get input message content
*
* @return mixed|null
*/
public function getInputMessageContent()
{
return $this->input_message_content;
}
/**
* Get reply markup
*
* @return mixed|null
*/
public function getReplyMarkup()
{
return $this->reply_markup;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultArticle extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $input_message_content;
/**
* @var mixed|null
*/
protected $url;
/**
* @var mixed|null
*/
protected $hide_url;
/**
* @var mixed|null
*/
protected $description;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $thumb_width;
/**
* @var mixed|null
*/
protected $thumb_height;
/**
* InlineQueryResultArticle constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'article';
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->input_message_content = isset($data['input_message_content']) ? $data['input_message_content'] : null;
if (empty($this->input_message_content)) {
throw new TelegramException('input_message_content is empty!');
}
$this->url = isset($data['url']) ? $data['url'] : null;
$this->hide_url = isset($data['hide_url']) ? $data['hide_url'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get input message content
*
* @return mixed|null
*/
public function getInputMessageContent()
{
return $this->input_message_content;
}
/**
* Get url
*
* @return mixed|null
*/
public function getUrl()
{
return $this->url;
}
/**
* Get hide url
*
* @return mixed|null
*/
public function getHideUrl()
{
return $this->hide_url;
}
/**
* Get description
*
* @return mixed|null
*/
public function getDescription()
{
return $this->description;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get thumb width
*
* @return mixed|null
*/
public function getThumbWidth()
{
return $this->thumb_width;
}
/**
* Get thumb height
*
* @return mixed|null
*/
public function getThumbHeight()
{
return $this->thumb_height;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultAudio extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $audio_url;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $performer;
/**
* @var mixed|null
*/
protected $audio_duration;
/**
* InlineQueryResultAudio constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'audio';
$this->audio_url = isset($data['audio_url']) ? $data['audio_url'] : null;
if (empty($this->audio_url)) {
throw new TelegramException('audio_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->performer = isset($data['performer']) ? $data['performer'] : null;
$this->audio_duration = isset($data['audio_duration']) ? $data['audio_duration'] : null;
}
/**
* Get audio url
*
* @return mixed|null
*/
public function getAudioUrl()
{
return $this->audio_url;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get performer
*
* @return mixed|null
*/
public function getPerformer()
{
return $this->performer;
}
/**
* Get audio duration
*
* @return mixed|null
*/
public function getAudioDuration()
{
return $this->audio_duration;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedDocument extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $document_file_id;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $description;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultCachedDocument constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'document';
$this->document_file_id = isset($data['document_file_id']) ? $data['document_file_id'] : null;
if (empty($this->document_file_id)) {
throw new TelegramException('document_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get document file id
*
* @return mixed|null
*/
public function getDocumentFileId()
{
return $this->document_file_id;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get description
*
* @return mixed|null
*/
public function getDescription()
{
return $this->description;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedGif extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $gif_file_id;
/**
* @var mixed|null
*/
protected $title;
/**
* @var
*/
protected $description;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultCachedGif constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'gif';
$this->gif_file_id = isset($data['gif_file_id']) ? $data['gif_file_id'] : null;
if (empty($this->gif_file_id)) {
throw new TelegramException('gif_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get gif file id
*
* @return mixed|null
*/
public function getGifFileId()
{
return $this->gif_file_id;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedMpeg4Gif extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $mpeg4_file_id;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultCachedMpeg4Gif constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'mpeg4_gif';
$this->mpeg4_file_id = isset($data['mpeg4_file_id']) ? $data['mpeg4_file_id'] : null;
if (empty($this->mpeg4_file_id)) {
throw new TelegramException('mpeg4_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get mp4 file id
*
* @return mixed|null
*/
public function getMpeg4FileId()
{
return $this->mpeg4_file_id;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedPhoto extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $photo_file_id;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $description;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultCachedPhoto constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'photo';
$this->photo_file_id = isset($data['photo_file_id']) ? $data['photo_file_id'] : null;
if (empty($this->photo_file_id)) {
throw new TelegramException('photo_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get photo file id
*
* @return mixed|null
*/
public function getPhotoFileId()
{
return $this->photo_file_id;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get description
*
* @return mixed|null
*/
public function getDescription()
{
return $this->description;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedVideo extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $video_file_id;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $description;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultCachedVideo constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'photo';
$this->video_file_id = isset($data['video_file_id']) ? $data['video_file_id'] : null;
if (empty($this->video_file_id)) {
throw new TelegramException('video_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get video file id
*
* @return mixed|null
*/
public function getVideoFileId()
{
return $this->video_file_id;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get description
*
* @return mixed|null
*/
public function getDescription()
{
return $this->description;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedVoice extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $voice_file_id;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $description;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultCachedVoice constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'voice';
$this->voice_file_id = isset($data['voice_file_id']) ? $data['voice_file_id'] : null;
if (empty($this->voice_file_id)) {
throw new TelegramException('voice_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get voice file id
*
* @return mixed|null
*/
public function getVoiceFileId()
{
return $this->voice_file_id;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get description
*
* @return mixed|null
*/
public function getDescription()
{
return $this->description;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultContact extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $phone_number;
/**
* @var mixed|null
*/
protected $first_name;
/**
* @var mixed|null
*/
protected $last_name;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $thumb_width;
/**
* @var mixed|null
*/
protected $thumb_height;
/**
* InlineQueryResultContact constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'contact';
$this->phone_number = isset($data['phone_number']) ? $data['phone_number'] : null;
if (empty($this->phone_number)) {
throw new TelegramException('phone_number is empty!');
}
$this->first_name = isset($data['first_name']) ? $data['first_name'] : null;
if (empty($this->first_name)) {
throw new TelegramException('first_name is empty!');
}
$this->last_name = isset($data['last_name']) ? $data['last_name'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
/**
* Get phone number
*
* @return mixed|null
*/
public function getPhoneNumber()
{
return $this->phone_number;
}
/**
* Get first name
*
* @return mixed|null
*/
public function getFirstName()
{
return $this->first_name;
}
/**
* Get last name
*
* @return mixed|null
*/
public function getLastName()
{
return $this->last_name;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get thumb width
*
* @return mixed|null
*/
public function getThumbWidth()
{
return $this->thumb_width;
}
/**
* Get thumb height
*
* @return mixed|null
*/
public function getThumbHeight()
{
return $this->thumb_height;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultDocument extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $caption;
/**
* @var mixed|null
*/
protected $document_url;
/**
* @var mixed|null
*/
protected $mime_type;
/**
* @var mixed|null
*/
protected $description;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $thumb_width;
/**
* @var mixed|null
*/
protected $thumb_height;
/**
* InlineQueryResultDocument constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'document';
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->caption = isset($data['caption']) ? $data['caption'] : null;
$this->document_url = isset($data['document_url']) ? $data['document_url'] : null;
if (empty($this->document_url)) {
throw new TelegramException('document_url is empty!');
}
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
if (empty($this->mime_type)) {
throw new TelegramException('mime_type is empty!');
}
$this->description = isset($data['description']) ? $data['description'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
/**
* Get document url
*
* @return mixed|null
*/
public function getDocumentUrl()
{
return $this->document_url;
}
/**
* Get mime type
*
* @return mixed|null
*/
public function getMimeType()
{
return $this->mime_type;
}
/**
* Get description
*
* @return mixed|null
*/
public function getDescription()
{
return $this->description;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get thumb width
*
* @return mixed|null
*/
public function getThumbWidth()
{
return $this->thumb_width;
}
/**
* Get thumb height
*
* @return mixed|null
*/
public function getThumbHeight()
{
return $this->thumb_height;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultGif extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $gif_url;
/**
* @var mixed|null
*/
protected $gif_width;
/**
* @var mixed|null
*/
protected $gif_height;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultGif constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'gif';
$this->gif_url = isset($data['gif_url']) ? $data['gif_url'] : null;
if (empty($this->gif_url)) {
throw new TelegramException('gif_url is empty!');
}
$this->gif_width = isset($data['gif_width']) ? $data['gif_width'] : null;
$this->gif_height = isset($data['gif_height']) ? $data['gif_height'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
if (empty($this->thumb_url)) {
throw new TelegramException('thumb_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get gif url
*
* @return mixed|null
*/
public function getGifUrl()
{
return $this->gif_url;
}
/**
* Get gif width
*
* @return mixed|null
*/
public function getGifWidth()
{
return $this->gif_width;
}
/**
* Get gif height
*
* @return mixed|null
*/
public function getGifHeight()
{
return $this->gif_height;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultLocation extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $latitude;
/**
* @var mixed|null
*/
protected $longitude;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $thumb_width;
/**
* @var mixed|null
*/
protected $thumb_height;
/**
* InlineQueryResultLocation constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'location';
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
/**
* Get latitude
*
* @return mixed|null
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Get longitude
*
* @return mixed|null
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get thumb width
*
* @return mixed|null
*/
public function getThumbWidth()
{
return $this->thumb_width;
}
/**
* Get thumb height
*
* @return mixed|null
*/
public function getThumbHeight()
{
return $this->thumb_height;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultMpeg4Gif extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $mpeg4_url;
/**
* @var mixed|null
*/
protected $mpeg4_width;
/**
* @var mixed|null
*/
protected $mpeg4_height;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultMpeg4Gif constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'mpeg4_gif';
$this->mpeg4_url = isset($data['mpeg4_url']) ? $data['mpeg4_url'] : null;
if (empty($this->mpeg4_url)) {
throw new TelegramException('mpeg4_url is empty!');
}
$this->mpeg4_width = isset($data['mpeg4_width']) ? $data['mpeg4_width'] : null;
$this->mpeg4_height = isset($data['mpeg4_height']) ? $data['mpeg4_height'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
if (empty($this->thumb_url)) {
throw new TelegramException('thumb_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get mp4 url
*
* @return mixed|null
*/
public function getMpeg4Url()
{
return $this->mpeg4_url;
}
/**
* Get mp4 width
*
* @return mixed|null
*/
public function getMpeg4Width()
{
return $this->mpeg4_width;
}
/**
* Get mp4 height
*
* @return mixed|null
*/
public function getMpeg4Height()
{
return $this->mpeg4_height;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultPhoto extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $photo_url;
/**
* @var mixed|null
*/
protected $photo_width;
/**
* @var mixed|null
*/
protected $photo_height;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $description;
/**
* @var mixed|null
*/
protected $caption;
/**
* InlineQueryResultPhoto constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'photo';
$this->photo_url = isset($data['photo_url']) ? $data['photo_url'] : null;
if (empty($this->photo_url)) {
throw new TelegramException('photo_url is empty!');
}
$this->photo_width = isset($data['photo_width']) ? $data['photo_width'] : null;
$this->photo_height = isset($data['photo_height']) ? $data['photo_height'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
if (empty($this->thumb_url)) {
throw new TelegramException('thumb_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
/**
* Get photo url
*
* @return mixed|null
*/
public function getPhotoUrl()
{
return $this->photo_url;
}
/**
* Get photo width
*
* @return mixed|null
*/
public function getPhotoWidth()
{
return $this->photo_width;
}
/**
* Get photo height
*
* @return mixed|null
*/
public function getPhotoHeight()
{
return $this->photo_height;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get description
*
* @return mixed|null
*/
public function getDescription()
{
return $this->description;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultVenue extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $latitude;
/**
* @var mixed|null
*/
protected $longitude;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $address;
/**
* @var mixed|null
*/
protected $foursquare_id;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $thumb_width;
/**
* @var mixed|null
*/
protected $thumb_height;
/**
* InlineQueryResultVenue constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'venue';
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->address = isset($data['address']) ? $data['address'] : null;
if (empty($this->address)) {
throw new TelegramException('address is empty!');
}
$this->foursquare_id = isset($data['foursquare_id']) ? $data['foursquare_id'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
/**
* Get latitude
*
* @return mixed|null
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Get longitude
*
* @return mixed|null
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get address
*
* @return mixed|null
*/
public function getAddress()
{
return $this->address;
}
/**
* Get forsquare id
*
* @return mixed|null
*/
public function getFoursquareId()
{
return $this->foursquare_id;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get thumb width
*
* @return mixed|null
*/
public function getThumbWidth()
{
return $this->thumb_width;
}
/**
* Get thumb height
*
* @return mixed|null
*/
public function getThumbHeight()
{
return $this->thumb_height;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultVideo extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $video_url;
/**
* @var mixed|null
*/
protected $mime_type;
/**
* @var mixed|null
*/
protected $thumb_url;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $caption;
/**
* @var mixed|null
*/
protected $video_width;
/**
* @var mixed|null
*/
protected $video_height;
/**
* @var mixed|null
*/
protected $video_duration;
/**
* @var mixed|null
*/
protected $description;
/**
* InlineQueryResultVideo constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'video';
$this->video_url = isset($data['video_url']) ? $data['video_url'] : null;
if (empty($this->video_url)) {
throw new TelegramException('video_url is empty!');
}
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
if (empty($this->mime_type)) {
throw new TelegramException('mime_type is empty!');
}
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
if (empty($this->thumb_url)) {
throw new TelegramException('thumb_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
$this->video_width = isset($data['video_width']) ? $data['video_width'] : null;
$this->video_height = isset($data['video_height']) ? $data['video_height'] : null;
$this->video_duration = isset($data['video_duration']) ? $data['video_duration'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
}
/**
* Get video url
*
* @return mixed|null
*/
public function getVideoUrl()
{
return $this->video_url;
}
/**
* Get mime type
*
* @return mixed|null
*/
public function getMimeType()
{
return $this->mime_type;
}
/**
* Get thumb url
*
* @return mixed|null
*/
public function getThumbUrl()
{
return $this->thumb_url;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get caption
*
* @return mixed|null
*/
public function getCaption()
{
return $this->caption;
}
/**
* Get video width
*
* @return mixed|null
*/
public function getVideoWidth()
{
return $this->video_width;
}
/**
* Get video height
*
* @return mixed|null
*/
public function getVideoHeight()
{
return $this->video_height;
}
/**
* Get video duration
*
* @return mixed|null
*/
public function getVideoDuration()
{
return $this->video_duration;
}
/**
* Get description
*
* @return mixed|null
*/
public function getDescription()
{
return $this->description;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultVoice extends InlineQueryResult
{
/**
* @var mixed|null
*/
protected $voice_url;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $voice_duration;
/**
* InlineQueryResultVoice constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'voice';
$this->voice_url = isset($data['voice_url']) ? $data['voice_url'] : null;
if (empty($this->voice_url)) {
throw new TelegramException('voice_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->voice_duration = isset($data['voice_duration']) ? $data['voice_duration'] : null;
}
/**
* Get voice url
*
* @return mixed|null
*/
public function getVoiceUrl()
{
return $this->voice_url;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get voice duration
*
* @return mixed|null
*/
public function getVoiceDuration()
{
return $this->voice_duration;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InputContactMessageContent extends InputMessageContent
{
/**
* @var mixed|null
*/
protected $phone_number;
/**
* @var mixed|null
*/
protected $first_name;
/**
* @var mixed|null
*/
protected $last_name;
/**
* InputContactMessageContent constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->phone_number = isset($data['phone_number']) ? $data['phone_number'] : null;
if (empty($this->phone_number)) {
throw new TelegramException('phone_number is empty!');
}
$this->first_name = isset($data['first_name']) ? $data['first_name'] : null;
if (empty($this->first_name)) {
throw new TelegramException('first_name is empty!');
}
$this->last_name = isset($data['last_name']) ? $data['last_name'] : null;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InputMessageContent;
use Longman\TelegramBot\Entities\InlineQuery\InlineEntity;
/**
* Class InputContactMessageContent
*
* @link https://core.telegram.org/bots/api#inputcontactmessagecontent
*
* <code>
* $data = [
* 'phone_number' => '',
* 'first_name' => '',
* 'last_name' => '',
* ];
* </code>
*
* @method string getPhoneNumber() Contact's phone number
* @method string getFirstName() Contact's first name
* @method string getLastName() Optional. Contact's last name
*
* @method $this setPhoneNumber(string $phone_number) Contact's phone number
* @method $this setFirstName(string $first_name) Contact's first name
* @method $this setLastName(string $last_name) Optional. Contact's last name
*/
class InputContactMessageContent extends InlineEntity implements InputMessageContent
{
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InputMessageContent;
use Longman\TelegramBot\Entities\InlineQuery\InlineEntity;
/**
* Class InputLocationMessageContent
*
* @link https://core.telegram.org/bots/api#inputlocationmessagecontent
*
* <code>
* $data = [
* 'latitude' => 36.0338,
* 'longitude' => 71.8601,
* ];
*
* @method float getLatitude() Latitude of the location in degrees
* @method float getLongitude() Longitude of the location in degrees
*
* @method $this setLatitude(float $latitude) Latitude of the location in degrees
* @method $this setLongitude(float $longitude) Longitude of the location in degrees
*/
class InputLocationMessageContent extends InlineEntity implements InputMessageContent
{
}
<?php
namespace Longman\TelegramBot\Entities\InputMessageContent;
interface InputMessageContent
{
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InputMessageContent;
use Longman\TelegramBot\Entities\InlineQuery\InlineEntity;
/**
* Class InputTextMessageContent
*
* @link https://core.telegram.org/bots/api#inputtextmessagecontent
*
* <code>
* $data = [
* 'message_text' => '',
* 'parse_mode' => '',
* 'disable_web_page_preview' => true,
* ];
* </code>
*
* @method string getMessageText() Text of the message to be sent, 1-4096 characters.
* @method string getParseMode() Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
* @method bool getDisableWebPagePreview() Optional. Disables link previews for links in the sent message
*
* @method $this setMessageText(string $message_text) Text of the message to be sent, 1-4096 characters.
* @method $this setParseMode(string $parse_mode) Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
* @method $this setDisableWebPagePreview(bool $disable_web_page_preview) Optional. Disables link previews for links in the sent message
*/
class InputTextMessageContent extends InlineEntity implements InputMessageContent
{
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InputMessageContent;
use Longman\TelegramBot\Entities\InlineQuery\InlineEntity;
/**
* Class InputVenueMessageContent
*
* @link https://core.telegram.org/bots/api#inputvenuemessagecontent
*
* <code>
* $data = [
* 'latitude' => 36.0338,
* 'longitude' => 71.8601,
* 'title' => '',
* 'address' => '',
* 'foursquare_id' => '',
* ];
* </code>
*
* @method float getLatitude() Latitude of the location in degrees
* @method float getLongitude() Longitude of the location in degrees
* @method string getTitle() Name of the venue
* @method string getAddress() Address of the venue
* @method string getFoursquareIdTitle() Optional. Foursquare identifier of the venue, if known
*
* @method $this setLatitude(float $latitude) Latitude of the location in degrees
* @method $this setLongitude(float $longitude) Longitude of the location in degrees
* @method $this setTitle(string $title) Name of the venue
* @method $this setAddress(string $address) Address of the venue
* @method $this setFoursquareIdTitle(string $foursquare_id_title) Optional. Foursquare identifier of the venue, if known
*/
class InputVenueMessageContent extends InlineEntity implements InputMessageContent
{
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InputTextMessageContent extends InputMessageContent
{
/**
* @var mixed|null
*/
protected $message_text;
/**
* @var mixed|null
*/
protected $parse_mode;
/**
* @var mixed|null
*/
protected $disable_web_page_preview;
/**
* InputTextMessageContent constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->message_text = isset($data['message_text']) ? $data['message_text'] : null;
if (empty($this->message_text)) {
throw new TelegramException('message_text is empty!');
}
$this->parse_mode = isset($data['parse_mode']) ? $data['parse_mode'] : null;
$this->disable_web_page_preview = isset($data['disable_web_page_preview']) ? $data['disable_web_page_preview'] : null;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InputVenueMessageContent extends InputMessageContent
{
/**
* @var mixed|null
*/
protected $latitude;
/**
* @var mixed|null
*/
protected $longitude;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $address;
/**
* @var mixed|null
*/
protected $foursquare_id;
/**
* InputVenueMessageContent constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->address = isset($data['address']) ? $data['address'] : null;
if (empty($this->address)) {
throw new TelegramException('address is empty!');
}
$this->foursquare_id = isset($data['foursquare_id']) ? $data['foursquare_id'] : null;
}
}
......@@ -10,56 +10,15 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Location
*
* @link https://core.telegram.org/bots/api#location
*
* @method float getLongitude() Longitude as defined by sender
* @method float getLatitude() Latitude as defined by sender
*/
class Location extends Entity
{
/**
* @var mixed|null
*/
protected $longitude;
/**
* @var mixed|null
*/
protected $latitude;
/**
* Location constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
}
/**
* Get longitude
*
* @return mixed|null
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Get latitude
*
* @return mixed|null
*/
public function getLatitude()
{
return $this->latitude;
}
}
......@@ -10,402 +10,140 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Message
*
* @link https://core.telegram.org/bots/api#message
*
* @method int getMessageId() Unique message identifier
* @method User getFrom() Optional. Sender, can be empty for messages sent to channels
* @method int getDate() Date the message was sent in Unix time
* @method Chat getChat() Conversation the message belongs to
* @method User getForwardFrom() Optional. For forwarded messages, sender of the original message
* @method Chat getForwardFromChat() Optional. For messages forwarded from a channel, information about the original channel
* @method int getForwardDate() Optional. For forwarded messages, date the original message was sent in Unix time
* @method Message getReplyToMessage() Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
* @method int getEditDate() Optional. Date the message was last edited in Unix time
* @method Audio getAudio() Optional. Message is an audio file, information about the file
* @method Document getDocument() Optional. Message is a general file, information about the file
* @method Sticker getSticker() Optional. Message is a sticker, information about the sticker
* @method Video getVideo() Optional. Message is a video, information about the video
* @method Voice getVoice() Optional. Message is a voice message, information about the file
* @method string getCaption() Optional. Caption for the document, photo or video, 0-200 characters
* @method Contact getContact() Optional. Message is a shared contact, information about the contact
* @method Location getLocation() Optional. Message is a shared location, information about the location
* @method Venue getVenue() Optional. Message is a venue, information about the venue
* @method User getNewChatMember() Optional. A new member was added to the group, information about them (this member may be the bot itself)
* @method User getLeftChatMember() Optional. A member was removed from the group, information about them (this member may be the bot itself)
* @method string getNewChatTitle() Optional. A chat title was changed to this value
* @method bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted
* @method bool getGroupChatCreated() Optional. Service message: the group has been created
* @method bool getSupergroupChatCreated() Optional. Service message: the supergroup has been created. This field can't be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
* @method bool getChannelChatCreated() Optional. Service message: the channel has been created. This field can't be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.
* @method int getMigrateToChatId() Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
* @method int getMigrateFromChatId() Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
* @method Message getPinnedMessage() Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
*/
class Message extends Entity
{
/**
* @var mixed|null
*/
protected $message_id;
/**
* @var \Longman\TelegramBot\Entities\User|null
*/
protected $from;
/**
* @var mixed|null
*/
protected $date;
/**
* @var \Longman\TelegramBot\Entities\Chat|null
*/
protected $chat;
/**
* @var \Longman\TelegramBot\Entities\User|null
*/
protected $forward_from;
/**
* @var \Longman\TelegramBot\Entities\Chat|null
*/
protected $forward_from_chat;
/**
* @var mixed|null
*/
protected $forward_date;
/**
* @var mixed|null
*/
protected $edit_date;
/**
* @var \Longman\TelegramBot\Entities\ReplyToMessage
*/
protected $reply_to_message;
/**
* @var string|null
*/
protected $text;
/**
* @var \Longman\TelegramBot\Entities\Audio|null
*/
protected $audio;
/**
* @var \Longman\TelegramBot\Entities\Document|null
*/
protected $document;
/**
* @var array|null
*/
protected $photo;
/**
* @var \Longman\TelegramBot\Entities\Sticker|null
*/
protected $sticker;
/**
* @var \Longman\TelegramBot\Entities\Video|null
*/
protected $video;
/**
* @var \Longman\TelegramBot\Entities\Voice|null
*/
protected $voice;
/**
* @var mixed|null
*/
protected $caption;
/**
* @var \Longman\TelegramBot\Entities\Contact|null
*/
protected $contact;
/**
* @var \Longman\TelegramBot\Entities\Location|null
*/
protected $location;
/**
* @var mixed|null
*/
protected $venue;
/**
* @var \Longman\TelegramBot\Entities\User|null
*/
protected $new_chat_member;
/**
* @var \Longman\TelegramBot\Entities\User|null
*/
protected $left_chat_member;
/**
* @var mixed|null
*/
protected $new_chat_title;
/**
* @var mixed|null
*/
protected $new_chat_photo;
/**
* @var mixed|null
* {@inheritdoc}
*/
protected $delete_chat_photo;
/**
* @var mixed|null
*/
protected $group_chat_created;
/**
* @var mixed|null
*/
protected $supergroup_chat_created;
/**
* @var mixed|null
*/
protected $channel_chat_created;
/**
* @var mixed|null
*/
protected $migrate_to_chat_id;
/**
* @var mixed|null
*/
protected $migrate_from_chat_id;
/**
* @var mixed|null
*/
protected $pinned_message;
/**
* @var mixed|null
*/
protected $entities;
/**
* @var mixed|null
*/
private $command;
/**
* @var mixed|null
*/
private $type;
/**
* Message constructor.
*
* @param array $data
* @param $bot_name
*/
public function __construct(array $data, $bot_name)
protected function subEntities()
{
$this->reply_to_message = isset($data['reply_to_message']) ? $data['reply_to_message'] : null;
if (!empty($this->reply_to_message)) {
$this->reply_to_message = new ReplyToMessage($this->reply_to_message, $bot_name);
}
$this->init($data, $bot_name);
return [
'from' => User::class,
'chat' => Chat::class,
'forward_from' => User::class,
'forward_from_chat' => User::class,
'reply_to_message' => self::class,
'entities' => MessageEntity::class,
'audio' => Audio::class,
'document' => Document::class,
'photo' => PhotoSize::class,
'sticker' => Sticker::class,
'video' => Video::class,
'voice' => Voice::class,
'contact' => Contact::class,
'location' => Location::class,
'venue' => Venue::class,
'new_chat_member' => User::class,
'left_chat_member' => User::class,
'new_chat_photo' => PhotoSize::class,
'pinned_message' => Message::class,
];
}
/**
* Common init to Message and ReplyToMessage
* Message constructor
*
* @param array $data
* @param string $bot_name
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
protected function init(array &$data, $bot_name)
public function __construct(array $data, $bot_name = '')
{
$this->bot_name = $bot_name;
$this->type = 'Message';
$this->message_id = isset($data['message_id']) ? $data['message_id'] : null;
if (empty($this->message_id)) {
throw new TelegramException('message_id is empty!');
}
$this->from = isset($data['from']) ? $data['from'] : null;
if (!empty($this->from)) {
$this->from = new User($this->from);
}
$this->chat = isset($data['chat']) ? $data['chat'] : null;
if (empty($this->chat)) {
throw new TelegramException('chat is empty!');
}
$this->chat = new Chat($this->chat);
$this->date = isset($data['date']) ? $data['date'] : null;
if (empty($this->date)) {
throw new TelegramException('date is empty!');
}
$this->forward_from = isset($data['forward_from']) ? $data['forward_from'] : null;
if (!empty($this->forward_from)) {
$this->forward_from = new User($this->forward_from);
}
$this->forward_from_chat = isset($data['forward_from_chat']) ? $data['forward_from_chat'] : null;
if (!empty($this->forward_from_chat)) {
$this->forward_from_chat = new Chat($this->forward_from_chat);
}
$this->forward_date = isset($data['forward_date']) ? $data['forward_date'] : null;
$this->edit_date = isset($data['edit_date']) ? $data['edit_date'] : null;
$this->text = isset($data['text']) ? $data['text'] : null;
$command = $this->getCommand();
if (!empty($command)) {
$this->type = 'command';
}
$this->audio = isset($data['audio']) ? $data['audio'] : null;
if (!empty($this->audio)) {
$this->audio = new Audio($this->audio);
$this->type = 'Audio';
}
$this->document = isset($data['document']) ? $data['document'] : null;
if (!empty($this->document)) {
$this->document = new Document($this->document);
$this->type = 'Document';
}
$this->photo = isset($data['photo']) ? $data['photo'] : null; //array of photosize
if (!empty($this->photo)) {
foreach ($this->photo as $photo) {
if (!empty($photo)) {
$photos[] = new PhotoSize($photo);
}
}
$this->photo = $photos;
$this->type = 'Photo';
}
$this->sticker = isset($data['sticker']) ? $data['sticker'] : null;
if (!empty($this->sticker)) {
$this->sticker = new Sticker($this->sticker);
$this->type = 'Sticker';
}
$this->video = isset($data['video']) ? $data['video'] : null;
if (!empty($this->video)) {
$this->video = new Video($this->video);
$this->type = 'Video';
}
$this->voice = isset($data['voice']) ? $data['voice'] : null;
if (!empty($this->voice)) {
$this->voice = new Voice($this->voice);
$this->type = 'Voice';
}
$this->caption = isset($data['caption']) ? $data['caption'] : null;//string
$this->contact = isset($data['contact']) ? $data['contact'] : null;
if (!empty($this->contact)) {
$this->contact = new Contact($this->contact);
}
$this->location = isset($data['location']) ? $data['location'] : null;
if (!empty($this->location)) {
$this->location = new Location($this->location);
$this->type = 'Location';
}
$this->venue = isset($data['venue']) ? $data['venue'] : null;
if (!empty($this->venue)) {
$this->venue = new Venue($this->venue);
$this->type = 'Venue';
}
//retrocompatibility
//Retro-compatibility
if (isset($data['new_chat_participant'])) {
$data['new_chat_member'] = $data['new_chat_participant'];
unset($data['new_chat_participant']);
}
if (isset($data['left_chat_participant'])) {
$data['left_chat_member'] = $data['left_chat_participant'];
unset($data['left_chat_participant']);
}
$this->new_chat_member = isset($data['new_chat_member']) ? $data['new_chat_member'] : null;
if (!empty($this->new_chat_member)) {
$this->new_chat_member = new User($this->new_chat_member);
$this->type = 'new_chat_member';
}
$this->left_chat_member = isset($data['left_chat_member']) ? $data['left_chat_member'] : null;
if (!empty($this->left_chat_member)) {
$this->left_chat_member = new User($this->left_chat_member);
$this->type = 'left_chat_member';
}
$this->new_chat_title = isset($data['new_chat_title']) ? $data['new_chat_title'] : null;
if (!is_null($this->new_chat_title)) {
$this->type = 'new_chat_title';
}
$this->new_chat_photo = isset($data['new_chat_photo']) ? $data['new_chat_photo'] : null; //array of photosize
if (!empty($this->new_chat_photo)) {
foreach ($this->new_chat_photo as $photo) {
if (!empty($photo)) {
$photos[] = new PhotoSize($photo);
}
}
$this->new_chat_photo = $photos;
$this->type = 'new_chat_photo';
}
$this->delete_chat_photo = isset($data['delete_chat_photo']) ? $data['delete_chat_photo'] : null;
if ($this->delete_chat_photo) {
$this->type = 'delete_chat_photo';
}
$this->group_chat_created = isset($data['group_chat_created']) ? $data['group_chat_created'] : null;
if ($this->group_chat_created) {
$this->type = 'group_chat_created';
}
$this->supergroup_chat_created = isset($data['supergroup_chat_created']) ? $data['supergroup_chat_created'] : null;
if ($this->supergroup_chat_created) {
$this->type = 'supergroup_chat_created';
}
$this->channel_chat_created = isset($data['channel_chat_created']) ? $data['channel_chat_created'] : null;
if ($this->channel_chat_created) {
$this->type = 'channel_chat_created';
}
$this->migrate_to_chat_id = isset($data['migrate_to_chat_id']) ? $data['migrate_to_chat_id'] : null;
if ($this->migrate_to_chat_id) {
$this->type = 'migrate_to_chat_id';
}
parent::__construct($data, $bot_name);
}
$this->migrate_from_chat_id = isset($data['migrate_from_chat_id']) ? $data['migrate_from_chat_id'] : null;
if ($this->migrate_from_chat_id) {
$this->type = 'migrate_from_chat_id';
}
/**
* Optional. Message is a photo, available sizes of the photo
*
* This method overrides the default getPhoto method
* and returns a nice array of PhotoSize objects.
*
* @return array
*/
public function getPhoto()
{
return $this->makePrettyObjectArray(PhotoSize::class, 'photo');
}
$this->pinned_message = isset($data['pinned_message']) ? $data['pinned_message'] : null;
if ($this->pinned_message) {
$this->pinned_message = new Message($this->pinned_message, $this->getBotName());
}
/**
* Optional. A chat photo was changed to this value
*
* This method overrides the default getNewChatPhoto method
* and returns a nice array of PhotoSize objects.
*
* @return array
*/
public function getNewChatPhoto()
{
return $this->makePrettyObjectArray(PhotoSize::class, 'new_chat_photo');
}
$this->entities = isset($data['entities']) ? $data['entities'] : null;
if (!empty($this->entities)) {
foreach ($this->entities as $entity) {
if (!empty($entity)) {
$entities[] = new MessageEntity($entity);
}
}
$this->entities = $entities;
}
/**
* Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
*
* This method overrides the default getEntities method
* and returns a nice array of MessageEntity objects.
*
* @return array
*/
public function getEntities()
{
return $this->makePrettyObjectArray(MessageEntity::class, 'entities');
}
/**
* return the entire command like /echo or /echo@bot1 if specified
*
* @return string|void
* @return string|null
*/
public function getFullCommand()
{
if (substr($this->text, 0, 1) === '/') {
if (strpos($this->text, '/') === 0) {
$no_EOL = strtok($this->text, PHP_EOL);
$no_space = strtok($this->text, ' ');
......@@ -416,7 +154,7 @@ class Message extends Entity
return $no_EOL;
}
} else {
return;
return null;
}
}
......@@ -433,14 +171,14 @@ class Message extends Entity
$cmd = $this->getFullCommand();
if (substr($cmd, 0, 1) === '/') {
if (strpos($cmd, '/') === 0) {
$cmd = substr($cmd, 1);
//check if command is follow by botname
$split_cmd = explode('@', $cmd);
if (isset($split_cmd[1])) {
//command is followed by name check if is addressed to me
if (strtolower($split_cmd[1]) == strtolower($this->bot_name)) {
if (strtolower($split_cmd[1]) === strtolower($this->bot_name)) {
return $this->command = $split_cmd[0];
}
} else {
......@@ -453,99 +191,10 @@ class Message extends Entity
}
/**
* Get message id
*
* @return mixed
*/
public function getMessageId()
{
return $this->message_id;
}
/**
* Get User object related to the message
*
* @return \Longman\TelegramBot\Entities\User
*/
public function getFrom()
{
return $this->from;
}
/**
* Get date
*
* @return mixed
*/
public function getDate()
{
return $this->date;
}
/**
* Get User object related to the message
*
* @return \Longman\TelegramBot\Entities\Chat
*/
public function getChat()
{
return $this->chat;
}
/**
* Get User object related to the forwarded message
*
* @return \Longman\TelegramBot\Entities\User
*/
public function getForwardFrom()
{
return $this->forward_from;
}
/**
* Get User object related to the message
*
* @return \Longman\TelegramBot\Entities\Chat
*/
public function getForwardFromChat()
{
return $this->forward_from_chat;
}
/**
* Get forward date
*
* @return mixed
*/
public function getForwardDate()
{
return $this->forward_date;
}
/**
* Get edit date
*
* @return mixed
*/
public function getEditDate()
{
return $this->edit_date;
}
/**
* Get reply to message
*
* @return \Longman\TelegramBot\Entities\ReplyToMessage
*/
public function getReplyToMessage()
{
return $this->reply_to_message;
}
/**
* Get text
* For text messages, the actual UTF-8 text of the message, 0-4096 characters.
*
* @param bool $without_cmd
*
* @return string
*/
public function getText($without_cmd = false)
......@@ -563,226 +212,6 @@ class Message extends Entity
return $text;
}
/**
* Get audio
*
* @return \Longman\TelegramBot\Entities\Audio
*/
public function getAudio()
{
return $this->audio;
}
/**
* Get document
*
* @return \Longman\TelegramBot\Entities\Document
*/
public function getDocument()
{
return $this->document;
}
/**
* Get photo
*
* @return array
*/
public function getPhoto()
{
return $this->photo;
}
/**
* Get sticker
*
* @return \Longman\TelegramBot\Entities\Sticker
*/
public function getSticker()
{
return $this->sticker;
}
/**
* Get video
*
* @return \Longman\TelegramBot\Entities\Video
*/
public function getVideo()
{
return $this->video;
}
/**
* Get voice
*
* @return \Longman\TelegramBot\Entities\Voice
*/
public function getVoice()
{
return $this->voice;
}
/**
* Get caption
*
* @return mixed
*/
public function getCaption()
{
return $this->caption;
}
/**
* Get content
*
* @return \Longman\TelegramBot\Entities\Contact
*/
public function getContact()
{
return $this->contact;
}
/**
* Get location
*
* @return \Longman\TelegramBot\Entities\Location
*/
public function getLocation()
{
return $this->location;
}
/**
* Get venue
*
* @return mixed
*/
public function getVenue()
{
return $this->venue;
}
/**
* Get new chat participant
*
* @return mixed
*/
public function getNewChatParticipant()
{
return $this->new_chat_member;
}
/**
* Get left chat participant
*
* @return mixed
*/
public function getLeftChatParticipant()
{
return $this->left_chat_member;
}
/**
* Get User object related to the new member
*
* @return \Longman\TelegramBot\Entities\User
*/
public function getNewChatMember()
{
return $this->new_chat_member;
}
/**
* Get User object related to the left member
*
* @return \Longman\TelegramBot\Entities\User
*/
public function getLeftChatMember()
{
return $this->left_chat_member;
}
/**
* Get new chat title
*
* @return mixed
*/
public function getNewChatTitle()
{
return $this->new_chat_title;
}
/**
* Get new chat photo
*
* @return mixed
*/
public function getNewChatPhoto()
{
return $this->new_chat_photo;
}
/**
* Get delete chat photo
*
* @return mixed
*/
public function getDeleteChatPhoto()
{
return $this->delete_chat_photo;
}
/**
* Get group chat created
*
* @return mixed
*/
public function getGroupChatCreated()
{
return $this->group_chat_created;
}
/**
* Get supergroup chat created
*
* @return mixed
*/
public function getSupergroupChatCreated()
{
return $this->supergroup_chat_created;
}
/**
* Get channel chat created
*
* @return mixed
*/
public function getChannelChatCreated()
{
return $this->channel_chat_created;
}
/**
* Get migrate to chat id
*
* @return mixed
*/
public function getMigrateToChatId()
{
return $this->migrate_to_chat_id;
}
/**
* Get migrate from chat id
*
* @return mixed
*/
public function getMigrateFromChatId()
{
return $this->migrate_from_chat_id;
}
/**
* Bot added in chat
*
......@@ -791,7 +220,7 @@ class Message extends Entity
public function botAddedInChat()
{
if (!empty($this->new_chat_member)) {
if ($this->new_chat_member->getUsername() == $this->getBotName()) {
if ($this->new_chat_member->getUsername() === $this->getBotName()) {
return true;
}
}
......@@ -800,32 +229,46 @@ class Message extends Entity
}
/**
* Get type
* Detect type based on properties.
*
* @return mixed
* @return string|null
*/
public function getType()
{
return $this->type;
}
$types = [
'text',
'audio',
'document',
'photo',
'sticker',
'video',
'voice',
'contact',
'location',
'venue',
'new_chat_member',
'left_chat_member',
'new_chat_title',
'new_chat_photo',
'delete_chat_photo',
'group_chat_created',
'supergroup_chat_created',
'channel_chat_created',
'migrate_to_chat_id',
'migrate_from_chat_id',
'pinned_message',
];
foreach ($types as $type) {
if ($this->getProperty($type)) {
if ($type === 'text' && $this->getCommand()) {
return 'command';
}
/**
* Get pinned message
*
* @return mixed
*/
public function getPinnedMessage()
{
return $this->pinned_message;
}
return $type;
}
}
/**
* Get entities
*
* @return mixed
*/
public function getEntities()
{
return $this->entities;
return 'message';
}
}
......@@ -10,111 +10,26 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class MessageEntity
*
* @link https://core.telegram.org/bots/api#messageentity
*
* @method string getType() Type of the entity. Can be mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)
* @method int getOffset() Offset in UTF-16 code units to the start of the entity
* @method int getLength() Length of the entity in UTF-16 code units
* @method string getUrl() Optional. For "text_link" only, url that will be opened after user taps on the text
* @method User getUser() Optional. For "text_mention" only, the mentioned user
*/
class MessageEntity extends Entity
{
/**
* @var mixed|null
*/
protected $type;
/**
* @var mixed|null
*/
protected $offset;
/**
* @var mixed|null
*/
protected $length;
/**
* @var mixed|null
*/
protected $url;
/**
* @var \Longman\TelegramBot\Entities\User|null
*/
protected $user;
/**
* MessageEntity constructor.
*
* @TODO check for type value from this list: https://core.telegram.org/bots/api#messageentity
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->type = isset($data['type']) ? $data['type'] : null;
if (empty($this->type)) {
throw new TelegramException('type is empty!');
}
$this->offset = isset($data['offset']) ? $data['offset'] : null;
if ($this->offset === '') {
throw new TelegramException('offset is empty!');
}
$this->length = isset($data['length']) ? $data['length'] : null;
if ($this->length === '') {
throw new TelegramException('length is empty!');
}
$this->url = isset($data['url']) ? $data['url'] : null;
$this->user = isset($data['user']) ? new User($data['user']) : null;
}
/**
* Get type
*
* @return mixed|null
*/
public function getType()
{
return $this->type;
}
/**
* Get offset
*
* @return mixed|null
*/
public function getOffset()
{
return $this->offset;
}
/**
* Get length
*
* @return mixed|null
*/
public function getLength()
{
return $this->length;
}
/**
* Get url
*
* @return mixed|null
*/
public function getUrl()
{
return $this->url;
}
/**
* Get user
*
* @return \Longman\TelegramBot\Entities\User|null
* {@inheritdoc}
*/
public function getUser()
protected function subEntities()
{
return $this->user;
return [
'user' => User::class,
];
}
}
......@@ -10,94 +10,17 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class PhotoSize
*
* @link https://core.telegram.org/bots/api#photosize
*
* @method string getFileId() Unique identifier for this file
* @method int getWidth() Photo width
* @method int getHeight() Photo height
* @method int getFileSize() Optional. File size
*/
class PhotoSize extends Entity
{
/**
* @var mixed|null
*/
protected $file_id;
/**
* @var mixed|null
*/
protected $width;
/**
* @var mixed|null
*/
protected $height;
/**
* @var mixed|null
*/
protected $file_size;
/**
* PhotoSize constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
}
$this->width = isset($data['width']) ? $data['width'] : null;
if (empty($this->width)) {
throw new TelegramException('width is empty!');
}
$this->height = isset($data['height']) ? $data['height'] : null;
if (empty($this->height)) {
throw new TelegramException('height is empty!');
}
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
}
/**
* Get file id
*
* @return mixed|null
*/
public function getFileId()
{
return $this->file_id;
}
/**
* Get width
*
* @return mixed|null
*/
public function getWidth()
{
return $this->width;
}
/**
* Get height
*
* @return mixed|null
*/
public function getHeight()
{
return $this->height;
}
/**
* Get file size
*
* @return mixed|null
*/
public function getFileSize()
{
return $this->file_size;
}
}
......@@ -19,7 +19,7 @@ class ReplyToMessage extends Message
* @param array $data
* @param string $bot_name
*/
public function __construct(array $data, $bot_name)
public function __construct(array $data, $bot_name = '')
{
//As explained in the documentation
......
......@@ -10,132 +10,27 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Sticker
*
* @link https://core.telegram.org/bots/api#sticker
*
* @method string getFileId() Unique identifier for this file
* @method int getWidth() Sticker width
* @method int getHeight() Sticker height
* @method PhotoSize getThumb() Optional. Sticker thumbnail in .webp or .jpg format
* @method string getEmoji() Optional. Emoji associated with the sticker
* @method int getFileSize() Optional. File size
*/
class Sticker extends Entity
{
/**
* @var mixed|null
*/
protected $file_id;
/**
* @var mixed|null
*/
protected $width;
/**
* @var mixed|null
*/
protected $height;
/**
* @var \Longman\TelegramBot\Entities\PhotoSize
*/
protected $thumb;
/**
* @var mixed|null
*/
protected $emoji;
/**
* @var mixed|null
*/
protected $file_size;
/**
* Sticker constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
}
$this->width = isset($data['width']) ? $data['width'] : null;
if (empty($this->width)) {
throw new TelegramException('width is empty!');
}
$this->height = isset($data['height']) ? $data['height'] : null;
if (empty($this->height)) {
throw new TelegramException('height is empty!');
}
$this->thumb = isset($data['thumb']) ? $data['thumb'] : null;
if (empty($this->thumb)) {
throw new TelegramException('thumb is empty!');
}
$this->thumb = new PhotoSize($this->thumb);
$this->emoji = isset($data['emoji']) ? $data['emoji'] : null;
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
}
/**
* Get file id
*
* @return mixed|null
*/
public function getFileId()
{
return $this->file_id;
}
/**
* Get width
*
* @return mixed|null
*/
public function getWidth()
{
return $this->width;
}
/**
* Get height
*
* @return mixed|null
*/
public function getHeight()
{
return $this->height;
}
/**
* Get thumb
*
* @return \Longman\TelegramBot\Entities\PhotoSize
*/
public function getThumb()
{
return $this->thumb;
}
/**
* Get emoji
*
* @return mixed|null
*/
public function getEmoji()
{
return $this->emoji;
}
/**
* Get file size
*
* @return mixed|null
* {@inheritdoc}
*/
public function getFileSize()
protected function subEntities()
{
return $this->file_size;
return [
'thumb' => PhotoSize::class,
];
}
}
......@@ -10,183 +10,71 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Update
*
* @link https://core.telegram.org/bots/api#update
*
* @method int getUpdateId() The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
* @method Message getMessage() Optional. New incoming message of any kind — text, photo, sticker, etc.
* @method Message getEditedMessage() Optional. New version of a message that is known to the bot and was edited
* @method InlineQuery getInlineQuery() Optional. New incoming inline query
* @method ChosenInlineResult getChosenInlineResult() Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
* @method CallbackQuery getCallbackQuery() Optional. New incoming callback query
*/
class Update extends Entity
{
/**
* @var mixed|null
*/
protected $update_id;
/**
* @var \Longman\TelegramBot\Entities\Message
*/
protected $message;
/**
* @var \Longman\TelegramBot\Entities\Message
* {@inheritdoc}
*/
protected $edited_message;
/**
* @var \Longman\TelegramBot\Entities\InlineQuery
*/
protected $inline_query;
/**
* @var \Longman\TelegramBot\Entities\ChosenInlineResult
*/
protected $chosen_inline_result;
/**
* @var \Longman\TelegramBot\Entities\CallbackQuery
*/
protected $callback_query;
/**
* @var string
*/
private $update_type;
/**
* Update constructor.
*
* @param array $data
* @param $bot_name
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data, $bot_name)
protected function subEntities()
{
$this->bot_name = $bot_name;
$update_id = isset($data['update_id']) ? $data['update_id'] : null;
$this->update_id = $update_id;
$this->message = isset($data['message']) ? $data['message'] : null;
if (!empty($this->message)) {
$this->message = new Message($this->message, $bot_name);
$this->update_type = 'message';
}
$this->edited_message = isset($data['edited_message']) ? $data['edited_message'] : null;
if (!empty($this->edited_message)) {
$this->edited_message = new Message($this->edited_message, $bot_name);
$this->update_type = 'edited_message';
}
if (empty($update_id)) {
throw new TelegramException('update_id is empty!');
}
$this->inline_query = isset($data['inline_query']) ? $data['inline_query'] : null;
if (!empty($this->inline_query)) {
$this->inline_query = new InlineQuery($this->inline_query);
$this->update_type = 'inline_query';
}
$this->chosen_inline_result = isset($data['chosen_inline_result']) ? $data['chosen_inline_result'] : null;
if (!empty($this->chosen_inline_result)) {
$this->chosen_inline_result = new ChosenInlineResult($this->chosen_inline_result);
$this->update_type = 'chosen_inline_result';
}
$this->callback_query = isset($data['callback_query']) ? $data['callback_query'] : null;
if (!empty($this->callback_query)) {
$this->callback_query = new CallbackQuery($this->callback_query);
$this->update_type = 'callback_query';
}
return [
'message' => Message::class,
'edited_message' => EditedMessage::class,
'inline_query' => InlineQuery::class,
'chosen_inline_result' => ChosenInlineResult::class,
'callback_query' => CallbackQuery::class,
];
}
/**
* Get update id
* Get the update type based on the set properties
*
* @return mixed|null
*/
public function getUpdateId()
{
return $this->update_id;
}
/**
* Get message
*
* @return \Longman\TelegramBot\Entities\Message
*/
public function getMessage()
{
return $this->message;
}
/**
* Get edited message
*
* @return \Longman\TelegramBot\Entities\Message
*/
public function getEditedMessage()
{
return $this->edited_message;
}
/**
* Get inline query
*
* @return \Longman\TelegramBot\Entities\InlineQuery
*/
public function getInlineQuery()
{
return $this->inline_query;
}
/**
* Get callback query
*
* @return \Longman\TelegramBot\Entities\CallbackQuery
*/
public function getCallbackQuery()
{
return $this->callback_query;
}
/**
* Get chosen inline result
*
* @return \Longman\TelegramBot\Entities\ChosenInlineResult
*/
public function getChosenInlineResult()
{
return $this->chosen_inline_result;
}
/**
* Get update type
*
* @return string
* @return string|null
*/
public function getUpdateType()
{
return $this->update_type;
$types = [
'message',
'edited_message',
'inline_query',
'chosen_inline_result',
'callback_query',
];
foreach ($types as $type) {
if ($this->getProperty($type)) {
return $type;
}
}
return null;
}
/**
* Get update content
*
* @return \Longman\TelegramBot\Entities\CallbackQuery
* |\Longman\TelegramBot\Entities\ChosenInlineResult
* |\Longman\TelegramBot\Entities\InlineQuery
* |\Longman\TelegramBot\Entities\Message
* |\Longman\TelegramBot\Entities\ChosenInlineResult
* |\Longman\TelegramBot\Entities\InlineQuery
* |\Longman\TelegramBot\Entities\Message
*/
public function getUpdateContent()
{
if ($this->update_type == 'message') {
return $this->getMessage();
} elseif ($this->update_type == 'inline_query') {
return $this->getInlineQuery();
} elseif ($this->update_type == 'chosen_inline_result') {
return $this->getChosenInlineResult();
} elseif ($this->update_type == 'callback_query') {
return $this->getCallbackQuery();
if ($update_type = $this->getUpdateType()) {
return $this->getProperty($update_type);
}
return null;
}
}
......@@ -10,99 +10,32 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class User
*
* @link https://core.telegram.org/bots/api#user
*
* @property int $id Unique identifier for this user or bot
* @property string $first_name User's or bot’s first name
* @property string $last_name Optional. User's or bot’s last name
* @property string $username Optional. User's or bot’s username
*
* @method int getId() Unique identifier for this user or bot
* @method string getFirstName() User's or bot’s first name
* @method string getLastName() Optional. User's or bot’s last name
* @method string getUsername() Optional. User's or bot’s username
*/
class User extends Entity
{
/**
* @var mixed|null
*/
protected $id;
/**
* @var mixed|null
*/
protected $first_name;
/**
* @var mixed|null
*/
protected $last_name;
/**
* @var mixed|null
*/
protected $username;
/**
* User constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->id = isset($data['id']) ? $data['id'] : null;
if (empty($this->id)) {
throw new TelegramException('id is empty!');
}
$this->first_name = isset($data['first_name']) ? $data['first_name'] : null;
$this->last_name = isset($data['last_name']) ? $data['last_name'] : null;
$this->username = isset($data['username']) ? $data['username'] : null;
}
/**
* Get id
*
* @return mixed|null
*/
public function getId()
{
return $this->id;
}
/**
* Get first name
*
* @return mixed|null
*/
public function getFirstName()
{
return $this->first_name;
}
/**
* Get last name
*
* @return mixed|null
*/
public function getLastName()
{
return $this->last_name;
}
/**
* Get username
*
* @return mixed|null
*/
public function getUsername()
{
return $this->username;
}
/**
* Try nebtion
* Try mention
*
* @return mixed|null|string
* @return string|null
*/
public function tryMention()
{
if (is_null($this->username)) {
if (!is_null($this->last_name)) {
if ($this->username === null) {
if ($this->last_name !== null) {
return $this->first_name . ' ' . $this->last_name;
}
return $this->first_name;
......
......@@ -10,69 +10,46 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class UserProfilePhotos
*
* @link https://core.telegram.org/bots/api#userprofilephotos
*
* @method int getTotalCount() Total number of profile pictures the target user has
*/
class UserProfilePhotos extends Entity
{
/**
* @var mixed|null
*/
protected $total_count;
/**
* @var array
* {@inheritdoc}
*/
protected $photos;
/**
* UserProfilePhotos constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
protected function subEntities()
{
$this->total_count = isset($data['total_count']) ? $data['total_count'] : null;
if ($this->total_count === null || !is_numeric($this->total_count)) {
throw new TelegramException('total_count is empty!');
}
$this->photos = isset($data['photos']) ? $data['photos'] : null;
if ($this->photos === null || !is_array($data['photos'])) {
throw new TelegramException('photos is empty!');
}
$photos = [];
foreach ($this->photos as $key => $photo) {
if (is_array($photo)) {
foreach ($photo as $photo_size) {
$photos[$key][] = new PhotoSize($photo_size);
}
} else {
throw new TelegramException('photo is not an array!');
}
}
$this->photos = $photos;
return [
'photos' => PhotoSize::class,
];
}
/**
* Get total count
* Requested profile pictures (in up to 4 sizes each)
*
* @return mixed|null
*/
public function getTotalCount()
{
return $this->total_count;
}
/**
* Get photos
* This method overrides the default getPhotos method and returns a nice array
*
* @return array
*/
public function getPhotos()
{
return $this->photos;
$all_photos = [];
if ($these_photos = $this->getProperty('photos')) {
foreach ($these_photos as $photos) {
$new_photos = [];
foreach ($photos as $photo) {
$new_photos[] = new PhotoSize($photo);
}
$all_photos[] = $new_photos;
}
}
return $all_photos;
}
}
......@@ -10,135 +10,25 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Venue
*
* @link https://core.telegram.org/bots/api#venue
*
* @method Location getLocation() Venue location
* @method string getTitle() Name of the venue
* @method string getAddress() Address of the venue
* @method string getFoursquareId() Optional. Foursquare identifier of the venue
*/
class Venue extends Entity
{
/**
* @var \Longman\TelegramBot\Entities\Location
*/
protected $location;
/**
* @var mixed|null
*/
protected $latitude;
/**
* @var mixed|null
*/
protected $longitude;
/**
* @var mixed|null
*/
protected $title;
/**
* @var mixed|null
*/
protected $address;
/**
* @var mixed|null
*/
protected $foursquare_id;
/**
* Venue constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->location = isset($data['location']) ? $data['location'] : null;
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
// Venue can either contain location object or just latitude and longitude fields, check accordingly
if (!empty($this->location)) {
$this->location = new Location($this->location);
} else {
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->address = isset($data['address']) ? $data['address'] : null;
if (empty($this->address)) {
throw new TelegramException('address is empty!');
}
$this->foursquare_id = isset($data['foursquare_id']) ? $data['foursquare_id'] : null;
}
/**
* Get location
*
* @return \Longman\TelegramBot\Entities\Location
*/
public function getLocation()
{
return $this->location;
}
/**
* Get longitude
*
* @return mixed|null
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Get latitude
*
* @return mixed|null
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Get title
*
* @return mixed|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Get address
*
* @return mixed|null
*/
public function getAddress()
{
return $this->address;
}
/**
* Get forsquare id
*
* @return mixed|null
* {@inheritdoc}
*/
public function getFoursquareId()
protected function subEntities()
{
return $this->foursquare_id;
return [
'location' => Location::class,
];
}
}
......@@ -10,149 +10,28 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Video
*
* @link https://core.telegram.org/bots/api#video
*
* @method string getFileId() Unique identifier for this file
* @method int getWidth() Video width as defined by sender
* @method int getHeight() Video height as defined by sender
* @method int getDuration() Duration of the video in seconds as defined by sender
* @method PhotoSize getThumb() Optional. Video thumbnail
* @method string getMimeType() Optional. Mime type of a file as defined by sender
* @method int getFileSize() Optional. File size
*/
class Video extends Entity
{
/**
* @var mixed|null
*/
protected $file_id;
/**
* @var mixed|null
*/
protected $width;
/**
* @var mixed|null
*/
protected $height;
/**
* @var mixed|null
*/
protected $duration;
/**
* @var \Longman\TelegramBot\Entities\PhotoSize
*/
protected $thumb;
/**
* @var mixed|null
*/
protected $mime_type;
/**
* @var mixed|null
*/
protected $file_size;
/**
* Video constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
}
$this->width = isset($data['width']) ? $data['width'] : null;
if (empty($this->width)) {
throw new TelegramException('width is empty!');
}
$this->height = isset($data['height']) ? $data['height'] : null;
if (empty($this->height)) {
throw new TelegramException('height is empty!');
}
$this->duration = isset($data['duration']) ? $data['duration'] : null;
if ($this->duration === '' || $this->duration === null) {
throw new TelegramException('duration is empty!');
}
$this->thumb = isset($data['thumb']) ? $data['thumb'] : null;
if (empty($this->thumb)) {
throw new TelegramException('thumb is empty!');
}
$this->thumb = new PhotoSize($this->thumb);
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
}
/**
* Get file id
*
* @return mixed|null
*/
public function getFileId()
{
return $this->file_id;
}
/**
* Get width
*
* @return mixed|null
*/
public function getWidth()
{
return $this->width;
}
/**
* Get height
*
* @return mixed|null
*/
public function getHeight()
{
return $this->height;
}
/**
* Get duration
*
* @return mixed|null
*/
public function getDuration()
{
return $this->duration;
}
/**
* Get thumb
*
* @return \Longman\TelegramBot\Entities\PhotoSize
*/
public function getThumb()
{
return $this->thumb;
}
/**
* Get mime type
*
* @return mixed|null
*/
public function getMimeType()
{
return $this->mime_type;
}
/**
* Get file size
*
* @return mixed|null
* {@inheritdoc}
*/
public function getFileSize()
protected function subEntities()
{
return $this->file_size;
return [
'thumb' => PhotoSize::class,
];
}
}
......@@ -10,89 +10,17 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Voice
*
* @link https://core.telegram.org/bots/api#voice
*
* @method string getFileId() Unique identifier for this file
* @method int getDuration() Duration of the audio in seconds as defined by sender
* @method string getMimeType() Optional. MIME type of the file as defined by sender
* @method int getFileSize() Optional. File size
*/
class Voice extends Entity
{
/**
* @var mixed|null
*/
protected $file_id;
/**
* @var mixed|null
*/
protected $duration;
/**
* @var mixed|null
*/
protected $mime_type;
/**
* @var mixed|null
*/
protected $file_size;
/**
* Voice constructor.
*
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
}
$this->duration = isset($data['duration']) ? $data['duration'] : null;
if ($this->duration === '' || $this->duration === null) {
throw new TelegramException('duration is empty!');
}
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
}
/**
* Get file id
*
* @return mixed|null
*/
public function getFileId()
{
return $this->file_id;
}
/**
* Get duration
*
* @return mixed|null
*/
public function getDuration()
{
return $this->duration;
}
/**
* Get mime type
*
* @return mixed|null
*/
public function getMimeType()
{
return $this->mime_type;
}
/**
* Get file size
*
* @return mixed|null
*/
public function getFileSize()
{
return $this->file_size;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment