Added class \TgBotLib\Objects\Telegram\InlineQueryResult
which is the base class for all inline query results, additionally added \TgBotLib\Abstracts\InlineQueryResultType
to represent the type of inline query result object.
https://git.n64.cc/nosial/libs/tgbot/-/issues/3
This commit is contained in:
parent
6fb6f74406
commit
bcbb742b9f
3 changed files with 162 additions and 0 deletions
|
@ -31,6 +31,7 @@ input objects for methods that require input objects.
|
|||
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVenue`, see [InlineQueryResultVenue](https://core.telegram.org/bots/api#inlinequeryresultvenue) for more information.
|
||||
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact`, see [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact) for more information.
|
||||
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGame`, see [InlineQueryResultGame](https://core.telegram.org/bots/api#inlinequeryresultgame) for more information.
|
||||
* Added class `\TgBotLib\Objects\Telegram\InlineQueryResult` which is the base class for all inline query results, additionally added `\TgBotLib\Abstracts\InlineQueryResultType` to represent the type of inline query result object.
|
||||
|
||||
### Changed
|
||||
* Refactored InputMessageContent types to its own namespace so InputMessageContent can always return the correct InputMessageContent object type when calling `fromArray()`
|
||||
|
|
81
src/TgBotLib/Abstracts/InlineQueryResultType.php
Normal file
81
src/TgBotLib/Abstracts/InlineQueryResultType.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Abstracts;
|
||||
|
||||
abstract class InlineQueryResultType
|
||||
{
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultarticle
|
||||
*/
|
||||
const Article = 'article';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultphoto
|
||||
*/
|
||||
const Photo = 'photo';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultgif
|
||||
*/
|
||||
const Gif = 'gif';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif
|
||||
*/
|
||||
const Mpeg4Gif = 'mpeg4_gif';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultvideompeg4
|
||||
*/
|
||||
const Video = 'video';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultaudio
|
||||
*/
|
||||
const Audio = 'audio';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultvoice
|
||||
*/
|
||||
const Voice = 'voice';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultdocument
|
||||
*/
|
||||
const Document = 'document';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultlocation
|
||||
*/
|
||||
const Location = 'location';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultvenue
|
||||
*/
|
||||
const Venue = 'venue';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultcontact
|
||||
*/
|
||||
const Contact = 'contact';
|
||||
|
||||
/**
|
||||
* @link https://core.telegram.org/bots/api#inlinequeryresultgame
|
||||
*/
|
||||
const Game = 'game';
|
||||
|
||||
const All = [
|
||||
self::Article,
|
||||
self::Photo,
|
||||
self::Gif,
|
||||
self::Mpeg4Gif,
|
||||
self::Video,
|
||||
self::Audio,
|
||||
self::Voice,
|
||||
self::Document,
|
||||
self::Location,
|
||||
self::Venue,
|
||||
self::Contact,
|
||||
self::Game,
|
||||
];
|
||||
}
|
80
src/TgBotLib/Objects/Telegram/InlineQueryResult.php
Normal file
80
src/TgBotLib/Objects/Telegram/InlineQueryResult.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects\Telegram;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TgBotLib\Abstracts\InlineQueryResultType;
|
||||
use TgBotLib\Exceptions\NotImplementedException;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultArticle;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultAudio;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGame;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGif;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultLocation;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultMpeg4Gif;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultPhoto;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVenue;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVideo;
|
||||
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVoice;
|
||||
|
||||
class InlineQueryResult implements ObjectTypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
* @throws NotImplementedException
|
||||
* @deprecated Don't use, use fromArray() instead directly to construct the appropriate child class
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
throw new NotImplementedException(sprintf('This object is abstract, you can\'t use it directly, try constructing one of the child classes with fromArray()'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object constructed from the given array
|
||||
*
|
||||
* @param array $data
|
||||
* @return ObjectTypeInterface
|
||||
*/
|
||||
public static function fromArray(array $data): ObjectTypeInterface
|
||||
{
|
||||
if(!isset($data['type']))
|
||||
{
|
||||
throw new InvalidArgumentException('The type of the InlineQueryResult is not set, this is required!');
|
||||
}
|
||||
|
||||
switch(strtolower($data['type']))
|
||||
{
|
||||
case InlineQueryResultType::Article:
|
||||
return InlineQueryResultArticle::fromArray($data);
|
||||
case InlineQueryResultType::Photo:
|
||||
return InlineQueryResultPhoto::fromArray($data);
|
||||
case InlineQueryResultType::Gif:
|
||||
return InlineQueryResultGif::fromArray($data);
|
||||
case InlineQueryResultType::Mpeg4Gif:
|
||||
return InlineQueryResultMpeg4Gif::fromArray($data);
|
||||
case InlineQueryResultType::Video:
|
||||
return InlineQueryResultVideo::fromArray($data);
|
||||
case InlineQueryResultType::Audio:
|
||||
return InlineQueryResultAudio::fromArray($data);
|
||||
case InlineQueryResultType::Voice:
|
||||
return InlineQueryResultVoice::fromArray($data);
|
||||
case InlineQueryResultType::Document:
|
||||
return InlineQueryResultDocument::fromArray($data);
|
||||
case InlineQueryResultType::Location:
|
||||
return InlineQueryResultLocation::fromArray($data);
|
||||
case InlineQueryResultType::Venue:
|
||||
return InlineQueryResultVenue::fromArray($data);
|
||||
case InlineQueryResultType::Contact:
|
||||
return InlineQueryResultContact::fromArray($data);
|
||||
case InlineQueryResultType::Game:
|
||||
return InlineQueryResultGame::fromArray($data);
|
||||
default:
|
||||
throw new InvalidArgumentException(sprintf('The type of the InlineQueryResult is invalid, got "%s", expected one of "%s"', $data['type'], implode('", "', InlineQueryResultType::All)));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue