diff --git a/src/Telegram/BotCommandScope.php b/src/Telegram/BotCommandScope.php index 67e10ec..0013add 100644 --- a/src/Telegram/BotCommandScope.php +++ b/src/Telegram/BotCommandScope.php @@ -13,4 +13,18 @@ abstract class BotCommandScope extends \Tii\Telepath\Type { /** Scope type */ public string $type; + + + public static function factory(array $data): static + { + return match($data['type']) { + 'default' => new BotCommandScopeDefault($data) + 'all_private_chats' => new BotCommandScopeAllPrivateChats($data) + 'all_group_chats' => new BotCommandScopeAllGroupChats($data) + 'all_chat_administrators' => new BotCommandScopeAllChatAdministrators($data) + 'chat' => new BotCommandScopeChat($data) + 'chat_administrators' => new BotCommandScopeChatAdministrators($data) + 'chat_member' => new BotCommandScopeChatMember($data) + }; + } } diff --git a/src/Telegram/ChatMember.php b/src/Telegram/ChatMember.php index d524d7d..52a1f83 100644 --- a/src/Telegram/ChatMember.php +++ b/src/Telegram/ChatMember.php @@ -16,4 +16,17 @@ abstract class ChatMember extends \Tii\Telepath\Type /** Information about the user */ public User $user; + + + public static function factory(array $data): static + { + return match($data['status']) { + 'creator' => new ChatMemberOwner($data) + 'administrator' => new ChatMemberAdministrator($data) + 'member' => new ChatMemberMember($data) + 'restricted' => new ChatMemberRestricted($data) + 'left' => new ChatMemberLeft($data) + 'kicked' => new ChatMemberBanned($data) + }; + } } diff --git a/src/Telegram/InlineQueryResult.php b/src/Telegram/InlineQueryResult.php index bcfc287..bf70b56 100644 --- a/src/Telegram/InlineQueryResult.php +++ b/src/Telegram/InlineQueryResult.php @@ -19,4 +19,24 @@ abstract class InlineQueryResult extends \Tii\Telepath\Type /** Optional. Inline keyboard attached to the message */ public ?InlineKeyboardMarkup $reply_markup = null; + + + public static function factory(array $data): static + { + return match($data['type']) { + 'audio' => new InlineQueryResultAudio($data) + 'document' => new InlineQueryResultDocument($data) + 'gif' => new InlineQueryResultGif($data) + 'mpeg4_gif' => new InlineQueryResultMpeg4Gif($data) + 'photo' => new InlineQueryResultPhoto($data) + 'sticker' => new InlineQueryResultCachedSticker($data) + 'video' => new InlineQueryResultVideo($data) + 'voice' => new InlineQueryResultVoice($data) + 'article' => new InlineQueryResultArticle($data) + 'contact' => new InlineQueryResultContact($data) + 'game' => new InlineQueryResultGame($data) + 'location' => new InlineQueryResultLocation($data) + 'venue' => new InlineQueryResultVenue($data) + }; + } } diff --git a/src/Telegram/InputMedia.php b/src/Telegram/InputMedia.php index 4d40d53..5049f51 100644 --- a/src/Telegram/InputMedia.php +++ b/src/Telegram/InputMedia.php @@ -28,4 +28,16 @@ abstract class InputMedia extends \Tii\Telepath\Type * @var MessageEntity[] */ public ?array $caption_entities = null; + + + public static function factory(array $data): static + { + return match($data['type']) { + 'animation' => new InputMediaAnimation($data) + 'document' => new InputMediaDocument($data) + 'audio' => new InputMediaAudio($data) + 'photo' => new InputMediaPhoto($data) + 'video' => new InputMediaVideo($data) + }; + } } diff --git a/src/Telegram/InputMessageContent.php b/src/Telegram/InputMessageContent.php index 49c97d9..52a255f 100644 --- a/src/Telegram/InputMessageContent.php +++ b/src/Telegram/InputMessageContent.php @@ -11,4 +11,10 @@ */ abstract class InputMessageContent extends \Tii\Telepath\Type { + public static function factory(array $data): static + { + return match($data[null]) { + '' => new InputInvoiceMessageContent($data) + }; + } } diff --git a/src/Telegram/MenuButton.php b/src/Telegram/MenuButton.php index 72ac297..7c348ab 100644 --- a/src/Telegram/MenuButton.php +++ b/src/Telegram/MenuButton.php @@ -13,4 +13,14 @@ abstract class MenuButton extends \Tii\Telepath\Type { /** Type of the button */ public string $type; + + + public static function factory(array $data): static + { + return match($data['type']) { + 'commands' => new MenuButtonCommands($data) + 'web_app' => new MenuButtonWebApp($data) + 'default' => new MenuButtonDefault($data) + }; + } } diff --git a/src/Telegram/PassportElementError.php b/src/Telegram/PassportElementError.php index 8ab0c7e..06fda95 100644 --- a/src/Telegram/PassportElementError.php +++ b/src/Telegram/PassportElementError.php @@ -19,4 +19,20 @@ abstract class PassportElementError extends \Tii\Telepath\Type /** Error message */ public string $message; + + + public static function factory(array $data): static + { + return match($data['source']) { + 'data' => new PassportElementErrorDataField($data) + 'front_side' => new PassportElementErrorFrontSide($data) + 'reverse_side' => new PassportElementErrorReverseSide($data) + 'selfie' => new PassportElementErrorSelfie($data) + 'file' => new PassportElementErrorFile($data) + 'files' => new PassportElementErrorFiles($data) + 'translation_file' => new PassportElementErrorTranslationFile($data) + 'translation_files' => new PassportElementErrorTranslationFiles($data) + 'unspecified' => new PassportElementErrorUnspecified($data) + }; + } } diff --git a/telepathy b/telepathy index 8817790..88db91f 100755 Binary files a/telepathy and b/telepathy differ