├── docs ├── SOMTHING.md └── 01-logging.md ├── .env.example ├── logo.png ├── src ├── Entities │ ├── InputMedia │ │ ├── InputMedia.php │ │ ├── InputMediaPhoto.php │ │ ├── InputMediaAudio.php │ │ └── InputMediaDocument.php │ ├── InlineQuery │ │ ├── InlineQueryResult.php │ │ ├── InlineEntity.php │ │ ├── InlineQueryResultGame.php │ │ ├── InlineQueryResultCachedSticker.php │ │ ├── InlineQueryResultCachedAudio.php │ │ ├── InlineQueryResultCachedVoice.php │ │ ├── InlineQueryResultCachedGif.php │ │ ├── InlineQueryResultCachedMpeg4Gif.php │ │ ├── InlineQueryResultVoice.php │ │ ├── InlineQueryResultCachedVideo.php │ │ ├── InlineQueryResultCachedPhoto.php │ │ ├── InlineQueryResultArticle.php │ │ ├── InlineQueryResultCachedDocument.php │ │ ├── InlineQueryResultContact.php │ │ └── InlineQueryResultAudio.php │ ├── BotCommandScope │ │ ├── BotCommandScope.php │ │ ├── BotCommandScopeDefault.php │ │ ├── BotCommandScopeAllGroupChats.php │ │ ├── BotCommandScopeAllPrivateChats.php │ │ ├── BotCommandScopeAllChatAdministrators.php │ │ ├── BotCommandScopeChat.php │ │ ├── BotCommandScopeChatAdministrators.php │ │ └── BotCommandScopeChatMember.php │ ├── InputMessageContent │ │ ├── InputMessageContent.php │ │ ├── InputContactMessageContent.php │ │ ├── InputTextMessageContent.php │ │ ├── InputVenueMessageContent.php │ │ └── InputLocationMessageContent.php │ ├── MenuButton │ │ ├── MenuButtonNotImplemented.php │ │ ├── MenuButtonDefault.php │ │ ├── MenuButtonCommands.php │ │ ├── MenuButton.php │ │ ├── Factory.php │ │ └── MenuButtonWebApp.php │ ├── TelegramPassport │ │ ├── PassportElementError │ │ │ ├── PassportElementError.php │ │ │ ├── PassportElementErrorUnspecified.php │ │ │ ├── PassportElementErrorFile.php │ │ │ ├── PassportElementErrorSelfie.php │ │ │ ├── PassportElementErrorFiles.php │ │ │ ├── PassportElementErrorReverseSide.php │ │ │ ├── PassportElementErrorFrontSide.php │ │ │ ├── PassportElementErrorDataField.php │ │ │ ├── PassportElementErrorTranslationFile.php │ │ │ └── PassportElementErrorTranslationFiles.php │ │ ├── PassportFile.php │ │ ├── EncryptedCredentials.php │ │ ├── PassportData.php │ │ └── EncryptedPassportElement.php │ ├── ChannelPost.php │ ├── EditedMessage.php │ ├── EditedChannelPost.php │ ├── ChatMember │ │ ├── ChatMember.php │ │ ├── ChatMemberNotImplemented.php │ │ ├── ChatMemberLeft.php │ │ ├── ChatMemberMember.php │ │ ├── ChatMemberBanned.php │ │ ├── Factory.php │ │ ├── ChatMemberOwner.php │ │ ├── ChatMemberRestricted.php │ │ └── ChatMemberAdministrator.php │ ├── VoiceChatStarted.php │ ├── VideoChatStarted.php │ ├── Games │ │ ├── CallbackGame.php │ │ ├── GameHighScore.php │ │ └── Game.php │ ├── VideoChatEnded.php │ ├── VoiceChatEnded.php │ ├── InlineKeyboard.php │ ├── VideoChatScheduled.php │ ├── PollOption.php │ ├── VoiceChatScheduled.php │ ├── MessageAutoDeleteTimerChanged.php │ ├── BotCommand.php │ ├── Dice.php │ ├── Payments │ │ ├── LabeledPrice.php │ │ ├── ShippingAddress.php │ │ ├── ShippingOption.php │ │ ├── Invoice.php │ │ ├── OrderInfo.php │ │ ├── SuccessfulPayment.php │ │ ├── ShippingQuery.php │ │ └── PreCheckoutQuery.php │ ├── Contact.php │ ├── VideoChatParticipantsInvited.php │ ├── ReplyToMessage.php │ ├── VoiceChatParticipantsInvited.php │ ├── PhotoSize.php │ ├── File.php │ ├── ChatLocation.php │ ├── Voice.php │ ├── PollAnswer.php │ ├── ProximityAlertTriggered.php │ ├── SentWebAppMessage.php │ ├── WebAppInfo.php │ ├── MaskPosition.php │ ├── KeyboardButtonPollType.php │ ├── WebAppData.php │ ├── StickerSet.php │ ├── ChatPhoto.php │ ├── Location.php │ ├── ChatJoinRequest.php │ ├── Document.php │ ├── Venue.php │ ├── VideoNote.php │ ├── User.php │ ├── ChosenInlineResult.php │ ├── WebAppUser.php │ ├── UserProfilePhotos.php │ ├── LoginUrl.php │ ├── Video.php │ ├── Audio.php │ ├── MessageEntity.php │ ├── ChatPermissions.php │ ├── Sticker.php │ ├── ChatMemberUpdated.php │ ├── WebhookInfo.php │ ├── Animation.php │ ├── ChatInviteLink.php │ ├── CallbackQuery.php │ ├── InlineQuery.php │ ├── Poll.php │ ├── Response.php │ └── ChatAdministratorRights.php ├── Exception │ ├── TelegramException.php │ ├── TelegramLogException.php │ └── InvalidBotTokenException.php ├── Interfaces │ ├── PluginInterface.php │ ├── HandlerInterface.php │ └── PluginEventsInterface.php ├── Util │ ├── Database.php │ └── Toolkit.php ├── Traits │ ├── HandlerTrait.php │ ├── EnvironmentsTrait.php │ ├── WebhookTrait.php │ ├── PluginEventsTrait.php │ └── PluginTrait.php ├── Enums │ ├── ParseMode.php │ └── ChatAction.php ├── Factory.php └── Plugin.php ├── .gitignore ├── phpunit.setup.php ├── .github ├── SECURITY.md ├── CONTRIBUTING.md ├── CODE_OF_CONDUCT.md └── workflows │ └── ci.yml ├── tests ├── PluginTest.php ├── TelegramTest.php ├── Examples │ └── EchoBot │ │ ├── Handler.php │ │ └── Plugins │ │ └── MainPlugin.php ├── Methods │ └── SendPhotoTest.php ├── ProcessUpdateTest.php ├── CrashTest.php ├── RequestTest.php ├── WebhookTest.php └── HandlerTest.php ├── .scrutinizer.yml ├── .editorconfig ├── phpunit.xml ├── LICENSE └── composer.json /docs/SOMTHING.md: -------------------------------------------------------------------------------- 1 | # Something -------------------------------------------------------------------------------- /docs/01-logging.md: -------------------------------------------------------------------------------- 1 | ## Logging 2 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | TELEGRAM_BOT_TOKEN= -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-php/core/HEAD/logo.png -------------------------------------------------------------------------------- /src/Entities/InputMedia/InputMedia.php: -------------------------------------------------------------------------------- 1 | load(__DIR__ . '/.env'); 5 | 6 | -------------------------------------------------------------------------------- /src/Entities/InputMessageContent/InputMessageContent.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /src/Entities/EditedMessage.php: -------------------------------------------------------------------------------- 1 | load(__DIR__ . '/../.env'); 14 | } 15 | 16 | public function test_nothing() 17 | { 18 | $this->assertTrue(true); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMemberNotImplemented.php: -------------------------------------------------------------------------------- 1 | getText()); 13 | Assert::assertEquals(1, $update_id); 14 | yield; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/Entities/VoiceChatScheduled.php: -------------------------------------------------------------------------------- 1 | [User::class], 24 | ]; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Interfaces/HandlerInterface.php: -------------------------------------------------------------------------------- 1 | MenuButtonCommands::class, 14 | 'web_app' => MenuButtonWebApp::class, 15 | 'default' => MenuButtonDefault::class, 16 | ]; 17 | 18 | if (!isset($type[$data['type'] ?? ''])) { 19 | return new MenuButtonNotImplemented($data); 20 | } 21 | 22 | $class = $type[$data['type']]; 23 | return new $class($data); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/Entities/ReplyToMessage.php: -------------------------------------------------------------------------------- 1 | User::class, 26 | ]; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMemberMember.php: -------------------------------------------------------------------------------- 1 | User::class, 26 | ]; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/VoiceChatParticipantsInvited.php: -------------------------------------------------------------------------------- 1 | [User::class], 26 | ]; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/Payments/ShippingAddress.php: -------------------------------------------------------------------------------- 1 | / to get the file. 16 | */ 17 | class File extends Entity 18 | { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/Entities/Games/GameHighScore.php: -------------------------------------------------------------------------------- 1 | User::class, 29 | ]; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/Payments/ShippingOption.php: -------------------------------------------------------------------------------- 1 | [LabeledPrice::class], 28 | ]; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/Entities/ChatLocation.php: -------------------------------------------------------------------------------- 1 | Location::class, 27 | ]; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | tests/ 18 | 19 | 20 | 21 | 22 | tests/ 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Entities/Payments/Invoice.php: -------------------------------------------------------------------------------- 1 | User::class, 28 | ]; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/Entities/PollAnswer.php: -------------------------------------------------------------------------------- 1 | User::class, 29 | ]; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/Factory.php: -------------------------------------------------------------------------------- 1 | ChatMemberOwner::class, 14 | 'administrator' => ChatMemberAdministrator::class, 15 | 'member' => ChatMemberMember::class, 16 | 'restricted' => ChatMemberRestricted::class, 17 | 'left' => ChatMemberLeft::class, 18 | 'kicked' => ChatMemberBanned::class, 19 | ]; 20 | 21 | if (!isset($type[$data['status'] ?? ''])) { 22 | return new ChatMemberNotImplemented($data); 23 | } 24 | 25 | $class = $type[$data['status']]; 26 | return new $class($data); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMemberOwner.php: -------------------------------------------------------------------------------- 1 | User::class, 28 | ]; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/Entities/Payments/OrderInfo.php: -------------------------------------------------------------------------------- 1 | ShippingAddress::class, 29 | ]; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/ProximityAlertTriggered.php: -------------------------------------------------------------------------------- 1 | User::class, 29 | 'watcher' => User::class, 30 | ]; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/Entities/SentWebAppMessage.php: -------------------------------------------------------------------------------- 1 | $data]; 26 | } 27 | 28 | parent::__construct($data); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /tests/Methods/SendPhotoTest.php: -------------------------------------------------------------------------------- 1 | $_ENV['TEST_USER_ID'], 17 | 'photo' => __DIR__ . '/../../logo.png' 18 | ]; 19 | 20 | $request = Request::create('sendPhoto', $requestData); 21 | 22 | $this->assertEquals('https://api.telegram.org/bot' . $_ENV['TELEGRAM_BOT_TOKEN'] . '/sendPhoto', $request['url']); 23 | 24 | $response = Request::send('sendPhoto', $requestData); 25 | 26 | $this->assertTrue($response->isOk()); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/Entities/MaskPosition.php: -------------------------------------------------------------------------------- 1 | [EncryptedPassportElement::class], 27 | 'credentials' => EncryptedCredentials::class, 28 | ]; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/Entities/BotCommandScope/BotCommandScopeChat.php: -------------------------------------------------------------------------------- 1 | 13 | * $data = [ 14 | * 'chat_id' => '123456' 15 | * ]; 16 | * 17 | * 18 | * @method string getType() Scope type, must be chat 19 | * @method string getChatId() Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 20 | * 21 | * @method $this setChatId(string $chat_id) Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 22 | */ 23 | class BotCommandScopeChat extends Entity implements BotCommandScope 24 | { 25 | 26 | public function __construct(array $data = []) 27 | { 28 | $data['type'] = 'chat'; 29 | parent::__construct($data); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/MenuButton/MenuButtonWebApp.php: -------------------------------------------------------------------------------- 1 | User::class, 30 | ]; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/Plugin.php: -------------------------------------------------------------------------------- 1 | hook->stop(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/Entities/StickerSet.php: -------------------------------------------------------------------------------- 1 | [Sticker::class], 30 | 'thumb' => PhotoSize::class, 31 | ]; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Entities/ChatPhoto.php: -------------------------------------------------------------------------------- 1 | 13 | * $data = [ 14 | * 'chat_id' => '123456' 15 | * ]; 16 | * 17 | * 18 | * @method string getType() Scope type, must be chat_administrators 19 | * @method string getChatId() Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 20 | * 21 | * @method $this setChatId(string $chat_id) Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 22 | */ 23 | class BotCommandScopeChatAdministrators extends Entity implements BotCommandScope 24 | { 25 | 26 | public function __construct(array $data = []) 27 | { 28 | $data['type'] = 'chat_administrators'; 29 | parent::__construct($data); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/Location.php: -------------------------------------------------------------------------------- 1 | Chat::class, 30 | 'from' => User::class, 31 | 'invite_link' => ChatInviteLink::class, 32 | ]; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/Entities/Document.php: -------------------------------------------------------------------------------- 1 | PhotoSize::class, 29 | ]; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/Venue.php: -------------------------------------------------------------------------------- 1 | Location::class, 31 | ]; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Entities/VideoNote.php: -------------------------------------------------------------------------------- 1 | PhotoSize::class, 30 | ]; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Shahrad Elahi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Entities/User.php: -------------------------------------------------------------------------------- 1 | User::class, 28 | 'location' => Location::class, 29 | ]; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/BotCommandScope/BotCommandScopeChatMember.php: -------------------------------------------------------------------------------- 1 | 13 | * $data = [ 14 | * 'chat_id' => '123456', 15 | * 'user_id' => 987654, 16 | * ]; 17 | * 18 | * 19 | * @method string getType() Scope type, must be chat_member 20 | * @method string getChatId() Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 21 | * @method int getUserId() Unique identifier of the target user 22 | * 23 | * @method $this setChatId(string $chat_id) Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 24 | * @method $this setUserId(int $user_id) Unique identifier of the target user 25 | */ 26 | class BotCommandScopeChatMember extends Entity implements BotCommandScope 27 | { 28 | 29 | public function __construct(array $data = []) 30 | { 31 | $data['type'] = 'chat_member'; 32 | parent::__construct($data); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/Entities/WebAppUser.php: -------------------------------------------------------------------------------- 1 | getProperty('photos')) { 30 | foreach ($these_photos as $photos) { 31 | $all_photos[] = array_map(function ($photo) { 32 | return new PhotoSize($photo); 33 | }, $photos); 34 | } 35 | } 36 | 37 | return $all_photos; 38 | } 39 | 40 | /** 41 | * {@inheritdoc} 42 | */ 43 | protected function subEntities(): array 44 | { 45 | return [ 46 | 'photos' => PhotoSize::class, 47 | ]; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorReverseSide.php: -------------------------------------------------------------------------------- 1 | OrderInfo::class, 32 | ]; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/Entities/LoginUrl.php: -------------------------------------------------------------------------------- 1 | 13 | * $data = [ 14 | * 'phone_number' => '', 15 | * 'first_name' => '', 16 | * 'last_name' => '', 17 | * 'vcard' => '', 18 | * ]; 19 | * 20 | * 21 | * @method string getPhoneNumber() Contact's phone number 22 | * @method string getFirstName() Contact's first name 23 | * @method string getLastName() Optional. Contact's last name 24 | * @method string getVcard() Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes 25 | * 26 | * @method $this setPhoneNumber(string $phone_number) Contact's phone number 27 | * @method $this setFirstName(string $first_name) Contact's first name 28 | * @method $this setLastName(string $last_name) Optional. Contact's last name 29 | * @method $this setVcard(string $vcard) Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes 30 | */ 31 | class InputContactMessageContent extends InlineEntity implements InputMessageContent 32 | { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Entities/Video.php: -------------------------------------------------------------------------------- 1 | PhotoSize::class, 33 | ]; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorDataField.php: -------------------------------------------------------------------------------- 1 | get_fake_update(); 15 | 16 | $this->assertEquals($update->getCallbackQuery()->getData(), 'tasks-settings'); 17 | 18 | $this->assertEquals($update->getCallbackQuery()->getId(), '1115664380233733737'); 19 | 20 | $this->assertEquals($update->getCallbackQuery()->getInlineMessageId(), null); 21 | } 22 | 23 | private function get_fake_update(): Update 24 | { 25 | return Telegram::processUpdate('{"update_id":226394498,"callback_query":{"id":"1115664380233733737","from":{"id":259760855,"is_bot":false,"first_name":"Shahrad","last_name":"Elahi","username":"ShahradElahi","language_code":"en"},"message":{"message_id":4071,"from":{"id":1861977284,"is_bot":true,"first_name":"Earnomi","username":"EarnomiBot"},"chat":{"id":259760855,"first_name":"Shahrad","last_name":"Elahi","username":"ShahradElahi","type":"private"},"date":1651775842,"text":"Choose an option below to change your settings","reply_markup":{"inline_keyboard":[[{"text":"Task Alerts","callback_data":"tasks-settings"}]]}},"chat_instance":"7764778060035751380","data":"tasks-settings"}}'); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /src/Entities/Audio.php: -------------------------------------------------------------------------------- 1 | PhotoSize::class, 32 | ]; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/Entities/MessageEntity.php: -------------------------------------------------------------------------------- 1 | User::class, 30 | ]; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/Entities/ChatPermissions.php: -------------------------------------------------------------------------------- 1 | PhotoSize::class, 34 | 'mask_position' => MaskPosition::class, 35 | ]; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/ChatMemberUpdated.php: -------------------------------------------------------------------------------- 1 | Chat::class, 33 | 'from' => User::class, 34 | 'old_chat_member' => ChatMemberFactory::class, 35 | 'new_chat_member' => ChatMemberFactory::class, 36 | 'invite_link' => ChatInviteLink::class, 37 | ]; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/Payments/ShippingQuery.php: -------------------------------------------------------------------------------- 1 | $this->getId(), 37 | 'ok' => $ok, 38 | ], $data)); 39 | } 40 | 41 | /** 42 | * {@inheritdoc} 43 | */ 44 | protected function subEntities(): array 45 | { 46 | return [ 47 | 'from' => User::class, 48 | 'shipping_address' => ShippingAddress::class, 49 | ]; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultGame.php: -------------------------------------------------------------------------------- 1 | 13 | * $data = [ 14 | * 'id' => '', 15 | * 'game_short_name' => '', 16 | * 'reply_markup' => , 17 | * ]; 18 | * 19 | * 20 | * @method string getType() Type of the result, must be game 21 | * @method string getId() Unique identifier for this result, 1-64 bytes 22 | * @method string getGameShortName() Short name of the game 23 | * @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message 24 | * 25 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 26 | * @method $this setGameShortName(string $game_short_name) Short name of the game 27 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. Inline keyboard attached to the message 28 | */ 29 | class InlineQueryResultGame extends InlineEntity implements InlineQueryResult 30 | { 31 | 32 | /** 33 | * InlineQueryResultGame constructor 34 | * 35 | * @param array $data 36 | */ 37 | public function __construct(array $data = []) 38 | { 39 | $data['type'] = 'game'; 40 | parent::__construct($data); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/Entities/WebhookInfo.php: -------------------------------------------------------------------------------- 1 | .env 47 | 48 | - name: Run test suite 49 | run: composer run-script test 50 | -------------------------------------------------------------------------------- /src/Entities/Animation.php: -------------------------------------------------------------------------------- 1 | PhotoSize::class, 34 | ]; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/CrashTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(259760855, Telegram::getAdminId()); 21 | } 22 | 23 | public function __process(Update $update): void { 24 | CrashPad::sendCrash( 25 | Telegram::getAdminId(), 26 | new \Exception('test'), 27 | json_encode($update->getRawData(), JSON_PRETTY_PRINT) 28 | ); 29 | CrashPad::clearCrashLogs(); 30 | } 31 | 32 | }; 33 | 34 | TelegramTest::loadEnvironment(); 35 | (new UpdateHandler())-> 36 | addPlugins($plugin)-> 37 | resolve(Telegram::processUpdate( 38 | '{"update_id":1,"message":{"message_id":1,"from":{"id":1,"is_bot":false,"first_name":"First","last_name":"Last","username":"username","language_code":"en"},"chat":{"id":1,"first_name":"First","last_name":"Last","username":"username","type":"private"},"date":1546300800,"text":"Hello World!"}}', 39 | $_ENV['TELEGRAM_BOT_TOKEN'] 40 | )); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/Entities/ChatInviteLink.php: -------------------------------------------------------------------------------- 1 | User::class, 35 | ]; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/Games/Game.php: -------------------------------------------------------------------------------- 1 | [PhotoSize::class], 34 | 'text_entities' => [MessageEntity::class], 35 | 'animation' => Animation::class, 36 | ]; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/RequestTest.php: -------------------------------------------------------------------------------- 1 | '259760855', 19 | 'text' => 'text', 20 | 'parse_mode' => 'Markdown', 21 | ]); 22 | 23 | $expected = [ 24 | 'url' => "https://api.telegram.org/bot{$_ENV['TELEGRAM_BOT_TOKEN']}/sendMessage", 25 | 'method' => 'GET', 26 | 'options' => [ 27 | 'headers' => [ 28 | 'Accept' => 'application/json', 29 | 'User-Agent' => 'TelegramBot-PHP/v1.0.0' 30 | ], 31 | 'query' => [ 32 | 'chat_id' => '259760855', 33 | 'text' => 'text', 34 | 'parse_mode' => 'Markdown', 35 | ], 36 | ], 37 | ]; 38 | 39 | $this->assertEquals($expected, $result); 40 | } 41 | 42 | public function test_send_message(): void 43 | { 44 | TelegramTest::loadEnvironment(); 45 | Telegram::setToken($_ENV['TELEGRAM_BOT_TOKEN']); 46 | 47 | $response = Request::sendMessage([ 48 | 'chat_id' => 259760855, 49 | 'text' => 'Hello World', 50 | ]); 51 | 52 | $this->assertTrue($response->isOk()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /tests/WebhookTest.php: -------------------------------------------------------------------------------- 1 | getText()); 19 | yield; 20 | } 21 | 22 | }; 23 | 24 | $message = DummyUpdate::message(); 25 | $message->set('text', 'Hello World!'); 26 | 27 | (new UpdateHandler())->addPlugins($plugin)->resolve(new Update([ 28 | 'update_id' => 1, 29 | 'message' => $message->getRawData(), 30 | ])); 31 | } 32 | 33 | public function testFilterIncomingUpdates() { 34 | 35 | $plugin = new class() extends Plugin { 36 | public function __process(Update $update): void { 37 | Assert::fail('This should not be called'); 38 | } 39 | }; 40 | 41 | $handler = (new UpdateHandler())->addPlugins($plugin); 42 | 43 | $handler->filterIncomingUpdates([ 44 | Update::TYPE_MESSAGE 45 | ]); 46 | 47 | $handler->resolve(new Update([ 48 | 'update_id' => 1, 49 | 'message' => DummyUpdate::message()->getRawData(), 50 | ])); 51 | 52 | $this->assertTrue(true); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/Enums/ChatAction.php: -------------------------------------------------------------------------------- 1 | =8.2", 35 | "ext-curl": "*", 36 | "ext-json": "*", 37 | "ext-mbstring": "*", 38 | "guzzlehttp/guzzle": "^7.8", 39 | "symfony/dotenv": "^v7.1" 40 | }, 41 | "require-dev": { 42 | "fakerphp/faker": "^1.23", 43 | "phpunit/phpunit": "^11.2", 44 | "psr/log": "^1.1|^2.0|^3.0" 45 | }, 46 | "autoload": { 47 | "psr-4": { 48 | "TelegramBot\\": "src/" 49 | } 50 | }, 51 | "autoload-dev": { 52 | "psr-4": { 53 | "TelegramBotTest\\": "tests/" 54 | } 55 | }, 56 | "config": { 57 | "sort-packages": true, 58 | "optimize-autoloader": true 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Entities/Payments/PreCheckoutQuery.php: -------------------------------------------------------------------------------- 1 | $this->getId(), 40 | 'ok' => $ok, 41 | ], $data)); 42 | } 43 | 44 | /** 45 | * {@inheritdoc} 46 | */ 47 | protected function subEntities(): array 48 | { 49 | return [ 50 | 'from' => User::class, 51 | 'order_info' => OrderInfo::class, 52 | ]; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /tests/HandlerTest.php: -------------------------------------------------------------------------------- 1 | resolve(Telegram::processUpdate( 17 | '{"update_id":1,"message":{"message_id":1,"from":{"id":1,"is_bot":false,"first_name":"First","last_name":"Last","username":"username","language_code":"en"},"chat":{"id":1,"first_name":"First","last_name":"Last","username":"username","type":"private"},"date":1546300800,"text":"Hello World!"}}', 18 | '1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' 19 | )); 20 | 21 | $this->assertTrue(true); 22 | } 23 | 24 | public function test_single_plugin(): void { 25 | $plugin = new class($this) extends Plugin { 26 | 27 | public function __construct(private TestCase $class) { 28 | 29 | } 30 | 31 | public function __process(Update $update): void { 32 | $this->class->assertEquals(1, $update->getUpdateId()); 33 | } 34 | 35 | }; 36 | 37 | TelegramTest::loadEnvironment(); 38 | 39 | (new UpdateHandler())->addPlugins($plugin)->resolve(Telegram::processUpdate( 40 | '{"update_id":1,"message":{"message_id":1,"from":{"id":1,"is_bot":false,"first_name":"First","last_name":"Last","username":"username","language_code":"en"},"chat":{"id":1,"first_name":"First","last_name":"Last","username":"username","type":"private"},"date":1546300800,"text":"Hello World!"}}', 41 | $_ENV['TELEGRAM_BOT_TOKEN'] 42 | )); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/Entities/CallbackQuery.php: -------------------------------------------------------------------------------- 1 | $this->getId(), 35 | ], $data)); 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | */ 41 | protected function subEntities(): array 42 | { 43 | return [ 44 | 'from' => User::class, 45 | 'message' => Message::class, 46 | ]; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery.php: -------------------------------------------------------------------------------- 1 | $this->getId(), 36 | 'results' => $results, 37 | ], $data)); 38 | } 39 | 40 | /** 41 | * {@inheritdoc} 42 | */ 43 | protected function subEntities(): array 44 | { 45 | return [ 46 | 'from' => User::class, 47 | 'location' => Location::class, 48 | ]; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/Entities/InputMessageContent/InputTextMessageContent.php: -------------------------------------------------------------------------------- 1 | 14 | * $data = [ 15 | * 'message_text' => '', 16 | * 'parse_mode' => '', 17 | * 'disable_web_page_preview' => true, 18 | * ]; 19 | * 20 | * 21 | * @method string getMessageText() Text of the message to be sent, 1-4096 characters. 22 | * @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. 23 | * @method MessageEntity[] getEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 24 | * @method bool getDisableWebPagePreview() Optional. Disables link previews for links in the sent message 25 | * 26 | * @method $this setMessageText(string $message_text) Text of the message to be sent, 1-4096 characters. 27 | * @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. 28 | * @method $this setEntities(array $entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 29 | * @method $this setDisableWebPagePreview(bool $disable_web_page_preview) Optional. Disables link previews for links in the sent message 30 | */ 31 | class InputTextMessageContent extends InlineEntity implements InputMessageContent 32 | { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMemberRestricted.php: -------------------------------------------------------------------------------- 1 | User::class, 38 | ]; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultCachedSticker.php: -------------------------------------------------------------------------------- 1 | 14 | * $data = [ 15 | * 'id' => '', 16 | * 'sticker_file_id' => '', 17 | * 'reply_markup' => , 18 | * 'input_message_content' => , 19 | * ]; 20 | * 21 | * 22 | * @method string getType() Type of the result, must be sticker 23 | * @method string getId() Unique identifier for this result, 1-64 bytes 24 | * @method string getStickerFileId() A valid file identifier of the sticker 25 | * @method InlineKeyboard getReplyMarkup() Optional. An Inline keyboard attached to the message 26 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the sticker 27 | * 28 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 29 | * @method $this setStickerFileId(string $sticker_file_id) A valid file identifier of the sticker 30 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. An Inline keyboard attached to the message 31 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the sticker 32 | */ 33 | class InlineQueryResultCachedSticker extends InlineEntity implements InlineQueryResult 34 | { 35 | 36 | /** 37 | * InlineQueryResultCachedSticker constructor 38 | * 39 | * @param array $data 40 | */ 41 | public function __construct(array $data = []) 42 | { 43 | $data['type'] = 'sticker'; 44 | parent::__construct($data); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/Traits/EnvironmentsTrait.php: -------------------------------------------------------------------------------- 1 | load($envPath); 51 | } 52 | } 53 | 54 | /** 55 | * Set the admin chat id 56 | * 57 | * @return int 58 | */ 59 | public static function getAdminId(): int 60 | { 61 | return static::$adminId; 62 | } 63 | 64 | /** 65 | * Set the admin chat id 66 | * 67 | * @param int $adminId 68 | */ 69 | public static function setAdminId(int $adminId): void 70 | { 71 | static::$adminId = $adminId; 72 | } 73 | 74 | /** 75 | * Get token from env file. 76 | * 77 | * @param string $file 78 | * @return string|null 79 | */ 80 | protected function getEnvToken(string $file): string|null 81 | { 82 | if (!file_exists($file)) return null; 83 | return $_ENV['TELEGRAM_BOT_TOKEN'] ?? null; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/Entities/Poll.php: -------------------------------------------------------------------------------- 1 | [PollOption::class], 39 | 'explanation_entities' => [MessageEntity::class], 40 | ]; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/Traits/WebhookTrait.php: -------------------------------------------------------------------------------- 1 | isOk()) { 50 | throw new TelegramException( 51 | 'Webhook was not set! Error: ' . $result->getErrorCode() . ' ' . $result->getDescription() 52 | ); 53 | } 54 | 55 | return $result; 56 | } 57 | 58 | /** 59 | * Delete any assigned webhook 60 | * 61 | * @param array $data 62 | * @return Response 63 | * @throws TelegramException 64 | */ 65 | public function deleteWebhook(array $data = []): Response 66 | { 67 | $result = Request::deleteWebhook($data); 68 | 69 | if (!$result->isOk()) { 70 | throw new TelegramException(sprintf( 71 | 'Webhook was not deleted! Error: %s %s', 72 | $result->getErrorCode(), 73 | $result->getDescription() 74 | )); 75 | } 76 | 77 | return $result; 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/Entities/InputMedia/InputMediaPhoto.php: -------------------------------------------------------------------------------- 1 | 14 | * $data = [ 15 | * 'media' => '123abc', 16 | * 'caption' => '*Photo* caption', 17 | * 'parse_mode' => 'markdown', 18 | * ]; 19 | * 20 | * 21 | * @method string getType() Type of the result, must be photo 22 | * @method string getMedia() File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. 23 | * @method string getCaption() Optional. Caption of the photo to be sent, 0-200 characters 24 | * @method string getParseMode() Optional. Mode for parsing entities in the photo caption 25 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 26 | * 27 | * @method $this setMedia(string $media) File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. 28 | * @method $this setCaption(string $caption) Optional. Caption of the photo to be sent, 0-200 characters 29 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the photo caption 30 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 31 | */ 32 | class InputMediaPhoto extends Entity implements InputMedia 33 | { 34 | 35 | /** 36 | * InputMediaPhoto constructor 37 | * 38 | * @param array $data 39 | */ 40 | public function __construct(array $data = []) 41 | { 42 | $data['type'] = 'photo'; 43 | parent::__construct($data); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/Entities/InputMessageContent/InputVenueMessageContent.php: -------------------------------------------------------------------------------- 1 | 13 | * $data = [ 14 | * 'latitude' => 36.0338, 15 | * 'longitude' => 71.8601, 16 | * 'title' => '', 17 | * 'address' => '', 18 | * 'foursquare_id' => '', 19 | * 'foursquare_type' => '', 20 | * ]; 21 | * 22 | * 23 | * @method float getLatitude() Latitude of the location in degrees 24 | * @method float getLongitude() Longitude of the location in degrees 25 | * @method string getTitle() Name of the venue 26 | * @method string getAddress() Address of the venue 27 | * @method string getFoursquareId() Optional. Foursquare identifier of the venue, if known 28 | * @method string getFoursquareType() Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) 29 | * @method string getGooglePlaceId() Optional. Google Places identifier of the venue 30 | * @method string getGooglePlaceType() Optional. Google Places type of the venue 31 | * 32 | * @method $this setLatitude(float $latitude) Latitude of the location in degrees 33 | * @method $this setLongitude(float $longitude) Longitude of the location in degrees 34 | * @method $this setTitle(string $title) Name of the venue 35 | * @method $this setAddress(string $address) Address of the venue 36 | * @method $this setFoursquareId(string $foursquare_id) Optional. Foursquare identifier of the venue, if known 37 | * @method $this setFoursquareType(string $foursquare_type) Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) 38 | * @method $this setGooglePlaceId(string $google_place_id) Optional. Google Places identifier of the venue 39 | * @method $this setGooglePlaceType(string $google_place_type) Optional. Google Places type of the venue 40 | */ 41 | class InputVenueMessageContent extends InlineEntity implements InputMessageContent 42 | { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/Util/Toolkit.php: -------------------------------------------------------------------------------- 1 | getMessage(), $e->getCode(), $e); 86 | } 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMemberAdministrator.php: -------------------------------------------------------------------------------- 1 | User::class, 42 | ]; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/Entities/InputMessageContent/InputLocationMessageContent.php: -------------------------------------------------------------------------------- 1 | 13 | * $data = [ 14 | * 'latitude' => 36.0338, 15 | * 'longitude' => 71.8601, 16 | * 'horizontal_accuracy' => 36.9, 17 | * 'live_period' => 900, 18 | * 'heading' => 88, 19 | * 'proximity_alert_radius' => 300, 20 | * ]; 21 | * 22 | * @method float getLatitude() Latitude of the location in degrees 23 | * @method float getLongitude() Longitude of the location in degrees 24 | * @method float getHorizontalAccuracy() Optional. The radius of uncertainty for the location, measured in meters; 25 | * 0-1500 26 | * @method int getLivePeriod() Optional. Period in seconds for which the location can be updated, should be between 60 and 86400. 27 | * @method int getHeading() Optional. For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. 28 | * @method int getProximityAlertRadius() Optional. For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. 29 | * 30 | * @method $this setLatitude(float $latitude) Latitude of the location in degrees 31 | * @method $this setLongitude(float $longitude) Longitude of the location in degrees 32 | * @method $this setHorizontalAccuracy(float $horizontal_accuracy) Optional. The radius of uncertainty for the location, measured in meters; 33 | * 0-1500 34 | * @method $this setLivePeriod(int $live_period) Optional. Period in seconds for which the location can be updated, should be between 60 and 86400. 35 | * @method $this setHeading(int $heading) Optional. For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. 36 | * @method $this setProximityAlertRadius(int $proximity_alert_radius) Optional. For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. 37 | */ 38 | class InputLocationMessageContent extends InlineEntity implements InputMessageContent 39 | { 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/Entities/Response.php: -------------------------------------------------------------------------------- 1 | response = $data; 44 | 45 | $is_ok = (bool)($data['ok'] ?? false); 46 | $result = $data['result'] ?? null; 47 | 48 | if ($is_ok) { 49 | foreach ($this->requiredFields as $field) { 50 | if (!isset($data[$field])) { 51 | throw new \InvalidArgumentException("The field '{$field}' is required."); 52 | } 53 | } 54 | } 55 | 56 | parent::__construct($data); 57 | } 58 | 59 | /** 60 | * If response is ok 61 | * 62 | * @return bool 63 | */ 64 | public function isOk(): bool 65 | { 66 | return $this->getOk(); 67 | } 68 | 69 | /** 70 | * Print error 71 | * 72 | * @see https://secure.php.net/manual/en/function.print-r.php 73 | * 74 | * @param bool $return 75 | * @return bool|string 76 | */ 77 | public function printError(bool $return = false): bool|string 78 | { 79 | $error = sprintf('Error N: %s, Description: %s', $this->getErrorCode(), $this->getDescription()); 80 | 81 | if ($return) { 82 | return $error; 83 | } 84 | 85 | echo $error; 86 | 87 | return true; 88 | } 89 | 90 | /** 91 | * Check if array is associative 92 | * 93 | * @param array $array 94 | * @return bool 95 | */ 96 | protected function isAssoc(array $array): bool 97 | { 98 | return count(array_filter(array_keys($array), 'is_string')) > 0; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/Traits/PluginEventsTrait.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'audio_file_id' => '', 18 | * 'caption' => '', 19 | * 'reply_markup' => , 20 | * 'input_message_content' => , 21 | * ]; 22 | * 23 | * 24 | * @method string getType() Type of the result, must be audio 25 | * @method string getId() Unique identifier for this result, 1-64 bytes 26 | * @method string getAudioFileId() A valid file identifier for the audio file 27 | * @method string getCaption() Optional. Caption, 0-200 characters 28 | * @method string getParseMode() Optional. Mode for parsing entities in the audio caption 29 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 30 | * @method InlineKeyboard getReplyMarkup() Optional. An Inline keyboard attached to the message 31 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the audio 32 | * 33 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 34 | * @method $this setAudioFileId(string $audio_file_id) A valid file identifier for the audio file 35 | * @method $this setCaption(string $caption) Optional. Caption, 0-200 characters 36 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the audio caption 37 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 38 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. An Inline keyboard attached to the message 39 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the audio 40 | */ 41 | class InlineQueryResultCachedAudio extends InlineEntity implements InlineQueryResult 42 | { 43 | 44 | /** 45 | * InlineQueryResultCachedAudio constructor 46 | * 47 | * @param array $data 48 | */ 49 | public function __construct(array $data = []) 50 | { 51 | $data['type'] = 'audio'; 52 | parent::__construct($data); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultCachedVoice.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'voice_file_id' => '', 18 | * 'title' => '', 19 | * 'caption' => '', 20 | * 'reply_markup' => , 21 | * 'input_message_content' => , 22 | * ]; 23 | * 24 | * 25 | * @method string getType() Type of the result, must be voice 26 | * @method string getId() Unique identifier for this result, 1-64 bytes 27 | * @method string getVoiceFileId() A valid file identifier for the voice message 28 | * @method string getTitle() Voice message title 29 | * @method string getCaption() Optional. Caption, 0-200 characters 30 | * @method string getParseMode() Optional. Mode for parsing entities in the voice caption 31 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 32 | * @method InlineKeyboard getReplyMarkup() Optional. An Inline keyboard attached to the message 33 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the voice message 34 | * 35 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 36 | * @method $this setVoiceFileId(string $voice_file_id) A valid file identifier for the voice message 37 | * @method $this setTitle(string $title) Voice message title 38 | * @method $this setCaption(string $caption) Optional. Caption, 0-200 characters 39 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the voice caption 40 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 41 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. An Inline keyboard attached to the message 42 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the voice message 43 | */ 44 | class InlineQueryResultCachedVoice extends InlineEntity implements InlineQueryResult 45 | { 46 | 47 | /** 48 | * InlineQueryResultCachedVoice constructor 49 | * 50 | * @param array $data 51 | */ 52 | public function __construct(array $data = []) 53 | { 54 | $data['type'] = 'voice'; 55 | parent::__construct($data); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultCachedGif.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'gif_file_id' => '', 18 | * 'title' => '', 19 | * 'caption' => '', 20 | * 'reply_markup' => , 21 | * 'input_message_content' => , 22 | * ]; 23 | * 24 | * 25 | * @method string getType() Type of the result, must be gif 26 | * @method string getId() Unique identifier for this result, 1-64 bytes 27 | * @method string getGifFileId() A valid file identifier for the GIF file 28 | * @method string getTitle() Optional. Title for the result 29 | * @method string getCaption() Optional. Caption of the GIF file to be sent, 0-200 characters 30 | * @method string getParseMode() Optional. Mode for parsing entities in the caption 31 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 32 | * @method InlineKeyboard getReplyMarkup() Optional. An Inline keyboard attached to the message 33 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the GIF animation 34 | * 35 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 36 | * @method $this setGifFileId(string $gif_file_id) A valid file identifier for the GIF file 37 | * @method $this setTitle(string $title) Optional. Title for the result 38 | * @method $this setCaption(string $caption) Optional. Caption of the GIF file to be sent, 0-200 characters 39 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the caption 40 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 41 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. An Inline keyboard attached to the message 42 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the GIF animation 43 | */ 44 | class InlineQueryResultCachedGif extends InlineEntity implements InlineQueryResult 45 | { 46 | 47 | /** 48 | * InlineQueryResultCachedGif constructor 49 | * 50 | * @param array $data 51 | */ 52 | public function __construct(array $data = []) 53 | { 54 | $data['type'] = 'gif'; 55 | parent::__construct($data); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultCachedMpeg4Gif.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'mpeg4_file_id' => '', 18 | * 'title' => '', 19 | * 'caption' => '', 20 | * 'reply_markup' => , 21 | * 'input_message_content' => , 22 | * ]; 23 | * 24 | * 25 | * @method string getType() Type of the result, must be mpeg4_gif 26 | * @method string getId() Unique identifier for this result, 1-64 bytes 27 | * @method string getMpeg4FileId() A valid file identifier for the MP4 file 28 | * @method string getTitle() Optional. Title for the result 29 | * @method string getCaption() Optional. Caption of the MPEG-4 file to be sent, 0-200 characters 30 | * @method string getParseMode() Optional. Mode for parsing entities in the caption 31 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 32 | * @method InlineKeyboard getReplyMarkup() Optional. An Inline keyboard attached to the message 33 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the video animation 34 | * 35 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 36 | * @method $this setMpeg4FileId(string $mpeg4_file_id) A valid file identifier for the MP4 file 37 | * @method $this setTitle(string $title) Optional. Title for the result 38 | * @method $this setCaption(string $caption) Optional. Caption of the MPEG-4 file to be sent, 0-200 characters 39 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the caption 40 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 41 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. An Inline keyboard attached to the message 42 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the video animation 43 | */ 44 | class InlineQueryResultCachedMpeg4Gif extends InlineEntity implements InlineQueryResult 45 | { 46 | 47 | /** 48 | * InlineQueryResultCachedMpeg4Gif constructor 49 | * 50 | * @param array $data 51 | */ 52 | public function __construct(array $data = []) 53 | { 54 | $data['type'] = 'mpeg4_gif'; 55 | parent::__construct($data); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/Traits/PluginTrait.php: -------------------------------------------------------------------------------- 1 | hook = $receiver; 45 | 46 | if (method_exists($this, '__process')) { 47 | $this->__process($update); 48 | } 49 | 50 | if (method_exists($this, 'onReceivedUpdate')) { 51 | $return = $this->onUpdate($update); 52 | $this->__checkExit($return); 53 | } 54 | 55 | $type = $this->__identify($update); 56 | if (method_exists($this, ($method = 'on' . $type)) && $type !== null) { 57 | $this->__checkExit($this->__callEvent($method, $update)); 58 | } 59 | } 60 | 61 | /** 62 | * Check for the exit of the plugin. 63 | * 64 | * @param \Generator $return 65 | * @return void 66 | */ 67 | private function __checkExit(\Generator $return): void { 68 | if ($return->valid()) { 69 | if ($return->current() !== null && $this->KILL_ON_YIELD === true) { 70 | if ($return->current() instanceof Response) { 71 | $this->stop(); 72 | } 73 | } 74 | } 75 | 76 | if ($return->valid()) { 77 | $return->next(); 78 | $this->__checkExit($return); 79 | } 80 | } 81 | 82 | /** 83 | * Identify the update type. e.g. Message, EditedMessage, etc. 84 | * 85 | * @param Update $update 86 | * @return string|null 87 | */ 88 | private function __identify(Update $update): ?string { 89 | $type = $update->getUpdateType(); 90 | 91 | if ($type === null) { 92 | return null; 93 | } 94 | 95 | return str_replace('_', '', ucwords($type, '_')); 96 | } 97 | 98 | /** 99 | * Pass data to the method. 100 | * 101 | * @param string $method The method name. 102 | * @param Update $update The update object. 103 | * @return \Generator 104 | */ 105 | private function __callEvent(string $method, Update $update): \Generator { 106 | $upperName = 'get' . ucfirst(substr($method, 2)); 107 | return match ($method) { 108 | 'onWebAppData' => $this->onWebAppData($update->getWebAppData()), 109 | default => $this->$method($update->getUpdateId(), $update->$upperName()), 110 | }; 111 | } 112 | 113 | } -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/EncryptedPassportElement.php: -------------------------------------------------------------------------------- 1 | [PassportFile::class], 36 | 'front_side' => PassportFile::class, 37 | 'reverse_side' => PassportFile::class, 38 | 'selfie' => PassportFile::class, 39 | 'translation' => [PassportFile::class], 40 | ]; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultVoice.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'voice_url' => '', 18 | * 'title' => '', 19 | * 'caption' => '', 20 | * 'voice_duration' => 123, 21 | * 'reply_markup' => , 22 | * 'input_message_content' => , 23 | * ]; 24 | * 25 | * 26 | * @method string getType() Type of the result, must be voice 27 | * @method string getId() Unique identifier for this result, 1-64 bytes 28 | * @method string getVoiceUrl() A valid URL for the voice recording 29 | * @method string getTitle() Recording title 30 | * @method string getCaption() Optional. Caption, 0-200 characters 31 | * @method string getParseMode() Optional. Mode for parsing entities in the voice caption 32 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 33 | * @method int getVoiceDuration() Optional. Recording duration in seconds 34 | * @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message 35 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the voice recording 36 | * 37 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 38 | * @method $this setVoiceUrl(string $voice_url) A valid URL for the voice recording 39 | * @method $this setTitle(string $title) Recording title 40 | * @method $this setCaption(string $caption) Optional. Caption, 0-200 characters 41 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the voice caption 42 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 43 | * @method $this setVoiceDuration(int $voice_duration) Optional. Recording duration in seconds 44 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. Inline keyboard attached to the message 45 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the voice recording 46 | */ 47 | class InlineQueryResultVoice extends InlineEntity implements InlineQueryResult 48 | { 49 | 50 | /** 51 | * InlineQueryResultVoice constructor 52 | * 53 | * @param array $data 54 | */ 55 | public function __construct(array $data = []) 56 | { 57 | $data['type'] = 'voice'; 58 | parent::__construct($data); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultCachedVideo.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'video_file_id' => '', 18 | * 'title' => '', 19 | * 'description' => '', 20 | * 'caption' => '', 21 | * 'reply_markup' => , 22 | * 'input_message_content' => , 23 | * ]; 24 | * 25 | * 26 | * @method string getType() Type of the result, must be video 27 | * @method string getId() Unique identifier for this result, 1-64 bytes 28 | * @method string getVideoFileId() A valid file identifier for the video file 29 | * @method string getTitle() Title for the result 30 | * @method string getDescription() Optional. Short description of the result 31 | * @method string getCaption() Optional. Caption of the video to be sent, 0-200 characters 32 | * @method string getParseMode() Optional. Mode for parsing entities in the video caption 33 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 34 | * @method InlineKeyboard getReplyMarkup() Optional. An Inline keyboard attached to the message 35 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the video 36 | * 37 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 38 | * @method $this setVideoFileId(string $video_file_id) A valid file identifier for the video file 39 | * @method $this setTitle(string $title) Title for the result 40 | * @method $this setDescription(string $description) Optional. Short description of the result 41 | * @method $this setCaption(string $caption) Optional. Caption of the video to be sent, 0-200 characters 42 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the video caption 43 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 44 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. An Inline keyboard attached to the message 45 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the video 46 | */ 47 | class InlineQueryResultCachedVideo extends InlineEntity implements InlineQueryResult 48 | { 49 | 50 | /** 51 | * InlineQueryResultCachedVideo constructor 52 | * 53 | * @param array $data 54 | */ 55 | public function __construct(array $data = []) 56 | { 57 | $data['type'] = 'video'; 58 | parent::__construct($data); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultCachedPhoto.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'photo_file_id' => '', 18 | * 'title' => '', 19 | * 'description' => '', 20 | * 'caption' => '', 21 | * 'reply_markup' => , 22 | * 'input_message_content' => , 23 | * ]; 24 | * 25 | * 26 | * @method string getType() Type of the result, must be photo 27 | * @method string getId() Unique identifier for this result, 1-64 bytes 28 | * @method string getPhotoFileId() A valid file identifier of the photo 29 | * @method string getTitle() Optional. Title for the result 30 | * @method string getDescription() Optional. Short description of the result 31 | * @method string getCaption() Optional. Caption of the photo to be sent, 0-200 characters 32 | * @method string getParseMode() Optional. Mode for parsing entities in the photo caption 33 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 34 | * @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message 35 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the photo 36 | * 37 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 38 | * @method $this setPhotoFileId(string $photo_file_id) A valid file identifier of the photo 39 | * @method $this setTitle(string $title) Optional. Title for the result 40 | * @method $this setDescription(string $description) Optional. Short description of the result 41 | * @method $this setCaption(string $caption) Optional. Caption of the photo to be sent, 0-200 characters 42 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the photo caption 43 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 44 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. Inline keyboard attached to the message 45 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the photo 46 | */ 47 | class InlineQueryResultCachedPhoto extends InlineEntity implements InlineQueryResult 48 | { 49 | 50 | /** 51 | * InlineQueryResultCachedPhoto constructor 52 | * 53 | * @param array $data 54 | */ 55 | public function __construct(array $data = []) 56 | { 57 | $data['type'] = 'photo'; 58 | parent::__construct($data); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultArticle.php: -------------------------------------------------------------------------------- 1 | 14 | * $data = [ 15 | * 'id' => '', 16 | * 'title' => '', 17 | * 'input_message_content' => , 18 | * 'reply_markup' => , 19 | * 'url' => '', 20 | * 'hide_url' => true, 21 | * 'description' => '', 22 | * 'thumb_url' => '', 23 | * 'thumb_width' => 30, 24 | * 'thumb_height' => 30, 25 | * ]; 26 | * 27 | * 28 | * @method string getType() Type of the result, must be article 29 | * @method string getId() Unique identifier for this result, 1-64 Bytes 30 | * @method string getTitle() Title of the result 31 | * @method InputMessageContent getInputMessageContent() Content of the message to be sent 32 | * @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message 33 | * @method string getUrl() Optional. URL of the result 34 | * @method bool getHideUrl() Optional. Pass True, if you don't want the URL to be shown in the message 35 | * @method string getDescription() Optional. Short description of the result 36 | * @method string getThumbUrl() Optional. Url of the thumbnail for the result 37 | * @method int getThumbWidth() Optional. Thumbnail width 38 | * @method int getThumbHeight() Optional. Thumbnail height 39 | * 40 | * @method $this setId(string $id) Unique identifier for this result, 1-64 Bytes 41 | * @method $this setTitle(string $title) Title of the result 42 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Content of the message to be sent 43 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. Inline keyboard attached to the message 44 | * @method $this setUrl(string $url) Optional. URL of the result 45 | * @method $this setHideUrl(bool $hide_url) Optional. Pass True, if you don't want the URL to be shown in the message 46 | * @method $this setDescription(string $description) Optional. Short description of the result 47 | * @method $this setThumbUrl(string $thumb_url) Optional. Url of the thumbnail for the result 48 | * @method $this setThumbWidth(int $thumb_width) Optional. Thumbnail width 49 | * @method $this setThumbHeight(int $thumb_height) Optional. Thumbnail height 50 | */ 51 | class InlineQueryResultArticle extends InlineEntity implements InlineQueryResult 52 | { 53 | 54 | /** 55 | * InlineQueryResultArticle constructor 56 | * 57 | * @param array $data 58 | */ 59 | public function __construct(array $data = []) 60 | { 61 | $data['type'] = 'article'; 62 | parent::__construct($data); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultCachedDocument.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'title' => '', 18 | * 'document_file_id' => '', 19 | * 'description' => '', 20 | * 'caption' => '', 21 | * 'reply_markup' => , 22 | * 'input_message_content' => , 23 | * ]; 24 | * 25 | * 26 | * @method string getType() Type of the result, must be document 27 | * @method string getId() Unique identifier for this result, 1-64 bytes 28 | * @method string getTitle() Title for the result 29 | * @method string getDocumentFileId() A valid file identifier for the file 30 | * @method string getDescription() Optional. Short description of the result 31 | * @method string getCaption() Optional. Caption of the document to be sent, 0-200 characters 32 | * @method string getParseMode() Optional. Mode for parsing entities in the document caption 33 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 34 | * @method InlineKeyboard getReplyMarkup() Optional. An Inline keyboard attached to the message 35 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the file 36 | * 37 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 38 | * @method $this setTitle(string $title) Title for the result 39 | * @method $this setDocumentFileId(string $document_file_id) A valid file identifier for the file 40 | * @method $this setDescription(string $description) Optional. Short description of the result 41 | * @method $this setCaption(string $caption) Optional. Caption of the document to be sent, 0-200 characters 42 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the document caption 43 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 44 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. An Inline keyboard attached to the message 45 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the file 46 | */ 47 | class InlineQueryResultCachedDocument extends InlineEntity implements InlineQueryResult 48 | { 49 | 50 | /** 51 | * InlineQueryResultCachedDocument constructor 52 | * 53 | * @param array $data 54 | */ 55 | public function __construct(array $data = []) 56 | { 57 | $data['type'] = 'document'; 58 | parent::__construct($data); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultContact.php: -------------------------------------------------------------------------------- 1 | 14 | * $data = [ 15 | * 'id' => '', 16 | * 'phone_number' => '', 17 | * 'first_name' => '', 18 | * 'last_name' => '', 19 | * 'reply_markup' => , 20 | * 'input_message_content' => , 21 | * 'thumb_url' => '', 22 | * 'thumb_width' => 30, 23 | * 'thumb_height' => 30, 24 | * ]; 25 | * 26 | * 27 | * @method string getType() Type of the result, must be contact 28 | * @method string getId() Unique identifier for this result, 1-64 Bytes 29 | * @method string getPhoneNumber() Contact's phone number 30 | * @method string getFirstName() Contact's first name 31 | * @method string getLastName() Optional. Contact's last name 32 | * @method string getVcard() Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes 33 | * @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message 34 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the contact 35 | * @method string getThumbUrl() Optional. Url of the thumbnail for the result 36 | * @method int getThumbWidth() Optional. Thumbnail width 37 | * @method int getThumbHeight() Optional. Thumbnail height 38 | * 39 | * @method $this setId(string $id) Unique identifier for this result, 1-64 Bytes 40 | * @method $this setPhoneNumber(string $phone_number) Contact's phone number 41 | * @method $this setFirstName(string $first_name) Contact's first name 42 | * @method $this setLastName(string $last_name) Optional. Contact's last name 43 | * @method $this setVcard(string $vcard) Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes 44 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. Inline keyboard attached to the message 45 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the contact 46 | * @method $this setThumbUrl(string $thumb_url) Optional. Url of the thumbnail for the result 47 | * @method $this setThumbWidth(int $thumb_width) Optional. Thumbnail width 48 | * @method $this setThumbHeight(int $thumb_height) Optional. Thumbnail height 49 | */ 50 | class InlineQueryResultContact extends InlineEntity implements InlineQueryResult 51 | { 52 | 53 | /** 54 | * InlineQueryResultContact constructor 55 | * 56 | * @param array $data 57 | */ 58 | public function __construct(array $data = []) 59 | { 60 | $data['type'] = 'contact'; 61 | parent::__construct($data); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultAudio.php: -------------------------------------------------------------------------------- 1 | 15 | * $data = [ 16 | * 'id' => '', 17 | * 'audio_url' => '', 18 | * 'title' => '', 19 | * 'caption' => '', 20 | * 'performer' => '', 21 | * 'audio_duration' => 123, 22 | * 'reply_markup' => , 23 | * 'input_message_content' => , 24 | * ]; 25 | * 26 | * 27 | * @method string getType() Type of the result, must be audio 28 | * @method string getId() Unique identifier for this result, 1-64 bytes 29 | * @method string getAudioUrl() A valid URL for the audio file 30 | * @method string getTitle() Title 31 | * @method string getCaption() Optional. Caption, 0-200 characters 32 | * @method string getParseMode() Optional. Mode for parsing entities in the audio caption 33 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 34 | * @method string getPerformer() Optional. Performer 35 | * @method int getAudioDuration() Optional. Audio duration in seconds 36 | * @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message 37 | * @method InputMessageContent getInputMessageContent() Optional. Content of the message to be sent instead of the audio 38 | * 39 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 40 | * @method $this setAudioUrl(string $audio_url) A valid URL for the audio file 41 | * @method $this setTitle(string $title) Title 42 | * @method $this setCaption(string $caption) Optional. Caption, 0-200 characters 43 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the audio caption 44 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 45 | * @method $this setPerformer(string $performer) Optional. Performer 46 | * @method $this setAudioDuration(int $audio_duration) Optional. Audio duration in seconds 47 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. Inline keyboard attached to the message 48 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the audio 49 | */ 50 | class InlineQueryResultAudio extends InlineEntity implements InlineQueryResult 51 | { 52 | 53 | /** 54 | * InlineQueryResultAudio constructor 55 | * 56 | * @param array $data 57 | */ 58 | public function __construct(array $data = []) 59 | { 60 | $data['type'] = 'audio'; 61 | parent::__construct($data); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/Interfaces/PluginEventsInterface.php: -------------------------------------------------------------------------------- 1 | 14 | * $data = [ 15 | * 'media' => '123abc', 16 | * 'thumb' => '456def', 17 | * 'caption' => '*Audio* caption', 18 | * 'parse_mode' => 'markdown', 19 | * 'duration' => 42, 20 | * 'performer' => 'John Doe', 21 | * 'title' => 'The Song', 22 | * ]; 23 | * 24 | * 25 | * @method string getType() Type of the result, must be audio 26 | * @method string getMedia() File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. 27 | * @method string getThumb() Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . More info on Sending Files » 28 | * @method string getCaption() Optional. Caption of the audio to be sent, 0-200 characters 29 | * @method string getParseMode() Optional. Mode for parsing entities in the audio caption 30 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 31 | * @method int getDuration() Optional. Duration of the audio in seconds 32 | * @method string getPerformer() Optional. Performer of the audio 33 | * @method string getTitle() Optional. Title of the audio 34 | * 35 | * @method $this setMedia(string $media) File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. 36 | * @method $this setThumb(string $thumb) Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . More info on Sending Files » 37 | * @method $this setCaption(string $caption) Optional. Caption of the audio to be sent, 0-200 characters 38 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the audio caption 39 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 40 | * @method $this setDuration(int $duration) Optional. Duration of the audio in seconds 41 | * @method $this setPerformer(string $performer) Optional. Performer of the audio 42 | * @method $this setTitle(string $title) Optional. Title of the audio 43 | */ 44 | class InputMediaAudio extends Entity implements InputMedia 45 | { 46 | 47 | /** 48 | * InputMediaAudio constructor 49 | * 50 | * @param array $data 51 | */ 52 | public function __construct(array $data = []) 53 | { 54 | $data['type'] = 'audio'; 55 | parent::__construct($data); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/Entities/InputMedia/InputMediaDocument.php: -------------------------------------------------------------------------------- 1 | 14 | * $data = [ 15 | * 'media' => '123abc', 16 | * 'thumb' => '456def', 17 | * 'caption' => '*Document* caption', 18 | * 'parse_mode' => 'markdown', 19 | * ]; 20 | * 21 | * 22 | * @method string getType() Type of the result, must be document 23 | * @method string getMedia() File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. 24 | * @method string getThumb() Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . More info on Sending Files » 25 | * @method string getCaption() Optional. Caption of the document to be sent, 0-200 characters 26 | * @method string getParseMode() Optional. Mode for parsing entities in the document caption 27 | * @method MessageEntity[] getCaptionEntities() Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 28 | * @method bool getDisableContentTypeDetection() Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data. Always true, if the document is sent as part of an album. 29 | * 30 | * @method $this setMedia(string $media) File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://" to upload a new one using multipart/form-data under name. 31 | * @method $this setThumb(string $thumb) Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . More info on Sending Files » 32 | * @method $this setCaption(string $caption) Optional. Caption of the document to be sent, 0-200 characters 33 | * @method $this setParseMode(string $parse_mode) Optional. Mode for parsing entities in the document caption 34 | * @method $this setCaptionEntities(array $caption_entities) Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode 35 | * @method $this setDisableContentTypeDetection(bool $disable_content_type_detection) Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data. Always true, if the document is sent as part of an album. 36 | */ 37 | class InputMediaDocument extends Entity implements InputMedia 38 | { 39 | 40 | /** 41 | * InputMediaDocument constructor 42 | * 43 | * @param array $data 44 | */ 45 | public function __construct(array $data = []) 46 | { 47 | $data['type'] = 'document'; 48 | parent::__construct($data); 49 | } 50 | 51 | } 52 | --------------------------------------------------------------------------------