2023-02-14 20:02:45 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2024-10-03 19:55:48 -04:00
|
|
|
namespace TgBotLib\Objects\Inline;
|
2023-02-14 20:02:45 -05:00
|
|
|
|
2024-10-04 00:18:19 -04:00
|
|
|
use TgBotLib\Enums\Types\ChatType;
|
2023-02-14 20:02:45 -05:00
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
2024-10-03 19:55:48 -04:00
|
|
|
use TgBotLib\Objects\Location;
|
|
|
|
use TgBotLib\Objects\User;
|
2023-02-14 20:02:45 -05:00
|
|
|
|
|
|
|
class InlineQuery implements ObjectTypeInterface
|
|
|
|
{
|
2024-10-04 00:18:19 -04:00
|
|
|
private string $id;
|
|
|
|
private User $from;
|
|
|
|
private string $query;
|
|
|
|
private string $offset;
|
|
|
|
private ?ChatType $chat_type;
|
|
|
|
private ?Location $location;
|
2023-02-14 20:02:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unique identifier for this query
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getId(): string
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sender
|
|
|
|
*
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function getFrom(): User
|
|
|
|
{
|
|
|
|
return $this->from;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text of the query (up to 256 characters)
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getQuery(): string
|
|
|
|
{
|
|
|
|
return $this->query;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Offset of the results to be returned, can be controlled by the bot
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getOffset(): string
|
|
|
|
{
|
|
|
|
return $this->offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional. Type of the chat from which the inline query was sent. Can be either “sender” for a private chat
|
|
|
|
* with the inline query sender, “private”, “group”, “supergroup”, or “channel”. The chat type should be always
|
|
|
|
* known for requests sent from official clients and most third-party clients, unless the request was sent from
|
|
|
|
* a secret chat
|
|
|
|
*
|
2024-10-04 00:18:19 -04:00
|
|
|
* @return ChatType|null
|
2023-02-14 20:02:45 -05:00
|
|
|
*/
|
2024-10-04 00:18:19 -04:00
|
|
|
public function getChatType(): ?ChatType
|
2023-02-14 20:02:45 -05:00
|
|
|
{
|
|
|
|
return $this->chat_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional. Sender location, only for bots that request user location
|
|
|
|
*
|
|
|
|
* @return Location|null
|
|
|
|
*/
|
|
|
|
public function getLocation(): ?Location
|
|
|
|
{
|
|
|
|
return $this->location;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-04 00:18:19 -04:00
|
|
|
* @inheritDoc
|
2023-02-14 20:02:45 -05:00
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
2024-11-03 18:07:06 -05:00
|
|
|
'from' => $this->from->toArray(),
|
2023-02-14 20:02:45 -05:00
|
|
|
'query' => $this->query,
|
|
|
|
'offset' => $this->offset,
|
2024-10-04 00:18:19 -04:00
|
|
|
'chat_type' => $this->chat_type?->value,
|
|
|
|
'location' => $this->location?->toArray()
|
2023-02-14 20:02:45 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-04 00:18:19 -04:00
|
|
|
* @inheritDoc
|
2023-02-14 20:02:45 -05:00
|
|
|
*/
|
2024-10-03 21:14:27 -04:00
|
|
|
public static function fromArray(?array $data): ?InlineQuery
|
2023-02-14 20:02:45 -05:00
|
|
|
{
|
2024-10-03 21:14:27 -04:00
|
|
|
if($data === null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2023-02-14 20:02:45 -05:00
|
|
|
|
2024-10-03 21:14:27 -04:00
|
|
|
$object = new self();
|
2023-02-14 20:02:45 -05:00
|
|
|
$object->id = $data['id'];
|
2024-10-04 00:18:19 -04:00
|
|
|
$object->from = isset($data['from']) ? User::fromArray($data['from']) : null;
|
2023-02-14 20:02:45 -05:00
|
|
|
$object->query = $data['query'];
|
|
|
|
$object->offset = $data['offset'];
|
|
|
|
$object->chat_type = $data['chat_type'] ?? null;
|
2024-10-04 00:18:19 -04:00
|
|
|
$object->location = isset($data['location']) ? Location::fromArray($data['location']) : null;
|
2023-02-14 20:02:45 -05:00
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|