├── CHANGELOG.md ├── CONTRIBUTING.md ├── CREDITS ├── LICENSE ├── README.md ├── SECURITY.md ├── composer.json ├── doc └── 01-utils.md ├── logo.png ├── src ├── ChatAction.php ├── Commands │ ├── AdminCommand.php │ ├── AdminCommands │ │ ├── ChatsCommand.php │ │ ├── CleanupCommand.php │ │ ├── DebugCommand.php │ │ ├── SendtoallCommand.php │ │ ├── SendtochannelCommand.php │ │ └── WhoisCommand.php │ ├── Command.php │ ├── SystemCommand.php │ ├── SystemCommands │ │ ├── CallbackqueryCommand.php │ │ ├── GenericCommand.php │ │ ├── GenericmessageCommand.php │ │ └── InlinequeryCommand.php │ ├── UserCommand.php │ └── UserCommands │ │ └── StartCommand.php ├── Conversation.php ├── ConversationDB.php ├── DB.php ├── Entities │ ├── Animation.php │ ├── Audio.php │ ├── BotCommand.php │ ├── BotCommandScope │ │ ├── BotCommandScope.php │ │ ├── BotCommandScopeAllChatAdministrators.php │ │ ├── BotCommandScopeAllGroupChats.php │ │ ├── BotCommandScopeAllPrivateChats.php │ │ ├── BotCommandScopeChat.php │ │ ├── BotCommandScopeChatAdministrators.php │ │ ├── BotCommandScopeChatMember.php │ │ └── BotCommandScopeDefault.php │ ├── BotDescription.php │ ├── BotName.php │ ├── BotShortDescription.php │ ├── CallbackQuery.php │ ├── ChannelPost.php │ ├── Chat.php │ ├── ChatAdministratorRights.php │ ├── ChatBoost.php │ ├── ChatBoostAdded.php │ ├── ChatBoostRemoved.php │ ├── ChatBoostSource │ │ ├── ChatBoostSource.php │ │ ├── ChatBoostSourceGiftCode.php │ │ ├── ChatBoostSourceGiveaway.php │ │ ├── ChatBoostSourceNotImplemented.php │ │ ├── ChatBoostSourcePremium.php │ │ └── Factory.php │ ├── ChatBoostUpdated.php │ ├── ChatInviteLink.php │ ├── ChatJoinRequest.php │ ├── ChatLocation.php │ ├── ChatMember │ │ ├── ChatMember.php │ │ ├── ChatMemberAdministrator.php │ │ ├── ChatMemberBanned.php │ │ ├── ChatMemberLeft.php │ │ ├── ChatMemberMember.php │ │ ├── ChatMemberNotImplemented.php │ │ ├── ChatMemberOwner.php │ │ ├── ChatMemberRestricted.php │ │ └── Factory.php │ ├── ChatMemberUpdated.php │ ├── ChatPermissions.php │ ├── ChatPhoto.php │ ├── ChatShared.php │ ├── ChosenInlineResult.php │ ├── Contact.php │ ├── Dice.php │ ├── Document.php │ ├── EditedChannelPost.php │ ├── EditedMessage.php │ ├── Entity.php │ ├── ExternalReplyInfo.php │ ├── Factory.php │ ├── File.php │ ├── Games │ │ ├── CallbackGame.php │ │ ├── Game.php │ │ └── GameHighScore.php │ ├── Giveaway │ │ ├── Giveaway.php │ │ ├── GiveawayCompleted.php │ │ ├── GiveawayCreated.php │ │ └── GiveawayWinners.php │ ├── InlineKeyboard.php │ ├── InlineKeyboardButton.php │ ├── InlineQuery.php │ ├── InlineQuery │ │ ├── InlineEntity.php │ │ ├── InlineQueryResult.php │ │ ├── InlineQueryResultArticle.php │ │ ├── InlineQueryResultAudio.php │ │ ├── InlineQueryResultCachedAudio.php │ │ ├── InlineQueryResultCachedDocument.php │ │ ├── InlineQueryResultCachedGif.php │ │ ├── InlineQueryResultCachedMpeg4Gif.php │ │ ├── InlineQueryResultCachedPhoto.php │ │ ├── InlineQueryResultCachedSticker.php │ │ ├── InlineQueryResultCachedVideo.php │ │ ├── InlineQueryResultCachedVoice.php │ │ ├── InlineQueryResultContact.php │ │ ├── InlineQueryResultDocument.php │ │ ├── InlineQueryResultGame.php │ │ ├── InlineQueryResultGif.php │ │ ├── InlineQueryResultLocation.php │ │ ├── InlineQueryResultMpeg4Gif.php │ │ ├── InlineQueryResultPhoto.php │ │ ├── InlineQueryResultVenue.php │ │ ├── InlineQueryResultVideo.php │ │ └── InlineQueryResultVoice.php │ ├── InlineQueryResultsButton.php │ ├── InputMedia │ │ ├── InputMedia.php │ │ ├── InputMediaAnimation.php │ │ ├── InputMediaAudio.php │ │ ├── InputMediaDocument.php │ │ ├── InputMediaPhoto.php │ │ └── InputMediaVideo.php │ ├── InputMessageContent │ │ ├── InputContactMessageContent.php │ │ ├── InputInvoiceMessageContent.php │ │ ├── InputLocationMessageContent.php │ │ ├── InputMessageContent.php │ │ ├── InputTextMessageContent.php │ │ └── InputVenueMessageContent.php │ ├── InputSticker.php │ ├── Keyboard.php │ ├── KeyboardButton.php │ ├── KeyboardButtonPollType.php │ ├── KeyboardButtonRequestChat.php │ ├── KeyboardButtonRequestUsers.php │ ├── LinkPreviewOptions.php │ ├── Location.php │ ├── LoginUrl.php │ ├── MaskPosition.php │ ├── MenuButton │ │ ├── Factory.php │ │ ├── MenuButton.php │ │ ├── MenuButtonCommands.php │ │ ├── MenuButtonDefault.php │ │ ├── MenuButtonNotImplemented.php │ │ └── MenuButtonWebApp.php │ ├── Message.php │ ├── Message │ │ ├── Factory.php │ │ ├── InaccessibleMessage.php │ │ └── MaybeInaccessibleMessage.php │ ├── MessageAutoDeleteTimerChanged.php │ ├── MessageEntity.php │ ├── MessageOrigin │ │ ├── Factory.php │ │ ├── MessageOrigin.php │ │ ├── MessageOriginChannel.php │ │ ├── MessageOriginChat.php │ │ ├── MessageOriginHiddenUser.php │ │ ├── MessageOriginNotImplemented.php │ │ └── MessageOriginUser.php │ ├── MessageReactionCountUpdated.php │ ├── MessageReactionUpdated.php │ ├── Payments │ │ ├── Invoice.php │ │ ├── LabeledPrice.php │ │ ├── OrderInfo.php │ │ ├── PreCheckoutQuery.php │ │ ├── ShippingAddress.php │ │ ├── ShippingOption.php │ │ ├── ShippingQuery.php │ │ └── SuccessfulPayment.php │ ├── PhotoSize.php │ ├── Poll.php │ ├── PollAnswer.php │ ├── PollOption.php │ ├── ProximityAlertTriggered.php │ ├── ReactionCount.php │ ├── ReactionType │ │ ├── Factory.php │ │ ├── ReactionType.php │ │ ├── ReactionTypeCustomEmoji.php │ │ ├── ReactionTypeEmoji.php │ │ └── ReactionTypeNotImplemented.php │ ├── ReplyParameters.php │ ├── ReplyToMessage.php │ ├── SentWebAppMessage.php │ ├── ServerResponse.php │ ├── Sticker.php │ ├── StickerSet.php │ ├── Story.php │ ├── SwitchInlineQueryChosenChat.php │ ├── TelegramPassport │ │ ├── EncryptedCredentials.php │ │ ├── EncryptedPassportElement.php │ │ ├── PassportData.php │ │ ├── PassportElementError │ │ │ ├── PassportElementError.php │ │ │ ├── PassportElementErrorDataField.php │ │ │ ├── PassportElementErrorFile.php │ │ │ ├── PassportElementErrorFiles.php │ │ │ ├── PassportElementErrorFrontSide.php │ │ │ ├── PassportElementErrorReverseSide.php │ │ │ ├── PassportElementErrorSelfie.php │ │ │ ├── PassportElementErrorTranslationFile.php │ │ │ ├── PassportElementErrorTranslationFiles.php │ │ │ └── PassportElementErrorUnspecified.php │ │ └── PassportFile.php │ ├── TextQuote.php │ ├── Topics │ │ ├── ForumTopicClosed.php │ │ ├── ForumTopicCreated.php │ │ ├── ForumTopicEdited.php │ │ ├── ForumTopicReopened.php │ │ ├── GeneralForumTopicHidden.php │ │ └── GeneralForumTopicUnhidden.php │ ├── Update.php │ ├── User.php │ ├── UserChatBoosts.php │ ├── UserProfilePhotos.php │ ├── UsersShared.php │ ├── Venue.php │ ├── Video.php │ ├── VideoChatEnded.php │ ├── VideoChatParticipantsInvited.php │ ├── VideoChatScheduled.php │ ├── VideoChatStarted.php │ ├── VideoNote.php │ ├── Voice.php │ ├── WebAppData.php │ ├── WebAppInfo.php │ ├── WebhookInfo.php │ └── WriteAccessAllowed.php ├── Exception │ ├── InvalidBotTokenException.php │ ├── TelegramException.php │ └── TelegramLogException.php ├── Request.php ├── Telegram.php └── TelegramLog.php ├── structure.sql └── utils ├── db-schema-update ├── 0.44.1-0.45.0.sql ├── 0.47.1-0.48.0.sql ├── 0.50.0-0.51.0.sql ├── 0.52.0-0.53.0.sql ├── 0.53.0-0.54.0.sql ├── 0.54.1-0.55.0.sql ├── 0.56.0-0.57.0.sql ├── 0.57.0-0.58.0.sql ├── 0.60.0-0.61.0.sql ├── 0.61.1-0.62.0.sql ├── 0.62.0-0.63.0.sql ├── 0.64.0-0.70.0.sql ├── 0.71.0-0.72.0.sql ├── 0.72.0-0.73.0.sql ├── 0.74.0-0.75.0.sql ├── 0.76.1-0.77.0.sql ├── 0.77.1-0.78.0.sql ├── 0.79.0-0.80.0.sql ├── 0.80.0-0.81.0.sql ├── 0.81.0-0.82.0.sql └── 0.82.0-0.83.0.sql └── importFromLog.php /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | The easiest way to contribute is to work on a checkout of your own fork. 4 | When working on the `core` repository, it makes sense to rename your fork to `php-telegram-bot`. 5 | 6 | Before you contribute code, please make sure it conforms to the PSR-12 coding standard and that the unit tests still pass. 7 | You can run the following commands to check if everything is ready to submit: 8 | 9 | ```bash 10 | cd php-telegram-bot 11 | composer install 12 | composer check-code 13 | ``` 14 | 15 | Which should give you no output, indicating that there are no coding standard errors. 16 | And then (remember to set up your test database!): 17 | 18 | ```bash 19 | composer test 20 | ``` 21 | 22 | Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools. 23 | 24 | ## Pushing 25 | 26 | Development is based on the git flow branching model (see http://nvie.com/posts/a-successful-git-branching-model/) 27 | If you fix a bug please push in hotfix branch. 28 | If you develop a new feature please create a new branch. 29 | 30 | ## Version 31 | 32 | Version number: 0.#version.#hotfix 33 | 34 | ## Further code convention adopted 35 | 36 | - Each method and class is documented with a docblock 37 | 38 | Example for a function or method: 39 | ```php 40 | /** 41 | * Get formatted date 42 | * 43 | * @param string $location 44 | * 45 | * @return string 46 | */ 47 | ``` 48 | 49 | - Each file is provided with the following header: 50 | ```php 51 | /** 52 | * This file is part of the TelegramBot package. 53 | * 54 | * (c) Avtandil Kikabidze aka LONGMAN 55 | * 56 | * For the full copyright and license information, please view the LICENSE 57 | * file that was distributed with this source code. 58 | */ 59 | ``` 60 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | This is at least a partial credits-file of people that have 2 | contributed to the current project. It is sorted by name and 3 | formatted to allow easy grepping and beautification by 4 | scripts. The fields are: name (N), email (E), web-address 5 | (W) and description (D). 6 | Thanks, 7 | 8 | Avtandil Kikabidze 9 | ---------- 10 | 11 | N: Avtandil Kikabidze aka LONGMAN 12 | E: akalongman@gmail.com 13 | W: http://longman.me 14 | D: Project owner, Maintainer 15 | 16 | N: Marco Boretto 17 | E: marco.bore@gmail.com 18 | D: Maintainer and Collaborator 19 | 20 | N: Armando Lüscher 21 | E: armando@noplanman.ch 22 | W: http://noplanman.ch 23 | D: Maintainer and Collaborator 24 | 25 | N: Jack'lul (alias) 26 | E: jacklulcat@gmail.com 27 | D: Maintainer and Collaborator 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The [MIT License](http://opensource.org/licenses/mit-license.php) 2 | 3 | Copyright (c) 2015 [Avtandil Kikabidze aka LONGMAN](https://github.com/akalongman) 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 | 23 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "longman/telegram-bot", 3 | "type": "library", 4 | "description": "PHP Telegram bot", 5 | "keywords": ["telegram", "bot", "api"], 6 | "license": "MIT", 7 | "homepage": "https://github.com/php-telegram-bot/core", 8 | "support": { 9 | "issues": "https://github.com/php-telegram-bot/core/issues", 10 | "source": "https://github.com/php-telegram-bot/core" 11 | }, 12 | "authors": [ 13 | { 14 | "name": "Avtandil Kikabidze aka LONGMAN", 15 | "email": "akalongman@gmail.com", 16 | "homepage": "http://longman.me", 17 | "role": "Developer" 18 | }, 19 | { 20 | "name": "Armando Lüscher", 21 | "email": "armando@noplanman.ch", 22 | "homepage": "https://noplanman.ch", 23 | "role": "Developer" 24 | }, 25 | { 26 | "name": "PHP Telegram Bot Team", 27 | "homepage": "https://github.com/php-telegram-bot/core/graphs/contributors", 28 | "role": "Developer" 29 | } 30 | ], 31 | "require": { 32 | "php": "^8.1", 33 | "ext-pdo": "*", 34 | "ext-curl": "*", 35 | "ext-json": "*", 36 | "ext-mbstring": "*", 37 | "psr/log": "^1.1|^2.0|^3.0", 38 | "guzzlehttp/guzzle": "^6.0|^7.0" 39 | }, 40 | "require-dev": { 41 | "phpunit/phpunit": "^9.5", 42 | "squizlabs/php_codesniffer": "^3.6", 43 | "dms/phpunit-arraysubset-asserts": "^0.2", 44 | "monolog/monolog": "^2.1" 45 | }, 46 | "autoload": { 47 | "psr-4": { 48 | "Longman\\TelegramBot\\": "src" 49 | } 50 | }, 51 | "autoload-dev": { 52 | "psr-4": { 53 | "Longman\\TelegramBot\\Tests\\Unit\\": "tests/Unit" 54 | } 55 | }, 56 | "scripts": { 57 | "check-code": [ 58 | "\"vendor/bin/phpcs\"" 59 | ], 60 | "test": [ 61 | "\"vendor/bin/phpunit\"" 62 | ], 63 | "test-cov": [ 64 | "XDEBUG_MODE=coverage \"vendor/bin/phpunit\" --coverage-clover clover.xml" 65 | ], 66 | "test-cov-upload": [ 67 | "@php ocular.phar code-coverage:upload --format=php-clover clover.xml" 68 | ] 69 | }, 70 | "config": { 71 | "optimize-autoloader": true, 72 | "preferred-install": "dist", 73 | "sort-packages": true, 74 | "process-timeout": 3600 75 | }, 76 | "extra": { 77 | "branch-alias": { 78 | "dev-develop": "0.83.x-dev" 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /doc/01-utils.md: -------------------------------------------------------------------------------- 1 | ## Logging 2 | PHP Telegram Bot library features [PSR-3] compatible logging to store logs. 3 | 4 | You can find a list of compatible packages that can be used on [Packagist][PSR-3-providers]. 5 | 6 | Logs are divided into the following streams: 7 | - `error`: Collects all the exceptions thrown by the library. 8 | - `debug`: Stores requests made to the Telegram API, useful for debugging. 9 | - `update`: Incoming raw updates (JSON string from Webhook and getUpdates). 10 | 11 | ### Initialisation 12 | To initialise the logger, you can pass any `LoggerInterface` objects to the `TelegramLog::initialize` method. 13 | 14 | The first parameter is the main logger, the second one is used for the raw updates. 15 | 16 | (in this example we're using [Monolog]) 17 | ```php 18 | use Longman\TelegramBot\TelegramLog; 19 | use Monolog\Formatter\LineFormatter; 20 | use Monolog\Handler\StreamHandler; 21 | use Monolog\Logger; 22 | 23 | TelegramLog::initialize( 24 | // Main logger that handles all 'debug' and 'error' logs. 25 | new Logger('telegram_bot', [ 26 | (new StreamHandler('/path/to/debug_log_file', Logger::DEBUG))->setFormatter(new LineFormatter(null, null, true)), 27 | (new StreamHandler('/path/to/error_log_file', Logger::ERROR))->setFormatter(new LineFormatter(null, null, true)), 28 | ]), 29 | // Updates logger for raw updates. 30 | new Logger('telegram_bot_updates', [ 31 | (new StreamHandler('/path/to/updates_log_file', Logger::INFO))->setFormatter(new LineFormatter('%message%' . PHP_EOL)), 32 | ]) 33 | ); 34 | ``` 35 | 36 | ### Raw data 37 | Why do I need to log the raw updates? 38 | Telegram API changes continuously and it often happens that the database schema is not up to date with new entities/features. So it can happen that your table schema doesn't allow storing new valuable information coming from Telegram. 39 | 40 | If you store the raw data you can import all updates on the newest table schema by simply using [this script](../utils/importFromLog.php). 41 | Remember to always backup first!! 42 | 43 | ### Always log request and response data 44 | If you'd like to always log the request and response data to the debug log, even for successful requests, you can set the appropriate variable: 45 | ```php 46 | \Longman\TelegramBot\TelegramLog::$always_log_request_and_response = true; 47 | ``` 48 | 49 | ### Hiding API token from the log 50 | By default, the API token is removed from the log, to prevent any mistaken leakage when posting logs online. 51 | This behaviour can be changed by setting the appropriate variable: 52 | ```php 53 | \Longman\TelegramBot\TelegramLog::$remove_bot_token = false; 54 | ``` 55 | 56 | [PSR-3]: https://www.php-fig.org/psr/psr-3 57 | [PSR-3-providers]: https://packagist.org/providers/psr/log-implementation 58 | [Monolog]: https://github.com/Seldaek/monolog 59 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-telegram-bot/core/96bf360dbe65db72c5996f34a72e8af9a0ce1f43/logo.png -------------------------------------------------------------------------------- /src/ChatAction.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot; 13 | 14 | class ChatAction 15 | { 16 | /** 17 | * Typing chat action 18 | */ 19 | public const TYPING = 'typing'; 20 | 21 | /** 22 | * Upload Photo chat action 23 | */ 24 | public const UPLOAD_PHOTO = 'upload_photo'; 25 | 26 | /** 27 | * Record Video chat action 28 | */ 29 | public const RECORD_VIDEO = 'record_video'; 30 | 31 | /** 32 | * Upload Video chat action 33 | */ 34 | public const UPLOAD_VIDEO = 'upload_video'; 35 | 36 | /** 37 | * Record Voice chat action 38 | */ 39 | public const RECORD_VOICE = 'record_voice'; 40 | 41 | /** 42 | * Upload Voice chat action 43 | */ 44 | public const UPLOAD_VOICE = 'upload_voice'; 45 | 46 | /** 47 | * Upload Document chat action 48 | */ 49 | public const UPLOAD_DOCUMENT = 'upload_document'; 50 | 51 | /** 52 | * Choose Sticker chat action 53 | */ 54 | public const CHOOSE_STICKER = 'choose_sticker'; 55 | 56 | /** 57 | * Find Location chat action 58 | */ 59 | public const FIND_LOCATION = 'find_location'; 60 | 61 | /** 62 | * Record Video Note chat action 63 | */ 64 | public const RECORD_VIDEO_NOTE = 'record_video_note'; 65 | 66 | /** 67 | * Upload Video note chat action 68 | */ 69 | public const UPLOAD_VIDEO_NOTE = 'upload_video_note'; 70 | } 71 | -------------------------------------------------------------------------------- /src/Commands/AdminCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Commands; 13 | 14 | abstract class AdminCommand extends Command 15 | { 16 | /** 17 | * @var bool 18 | */ 19 | protected $private_only = true; 20 | } 21 | -------------------------------------------------------------------------------- /src/Commands/SystemCommands/CallbackqueryCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Commands\SystemCommands; 13 | 14 | use Longman\TelegramBot\Commands\SystemCommand; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | 17 | /** 18 | * Callback query command 19 | */ 20 | class CallbackqueryCommand extends SystemCommand 21 | { 22 | /** 23 | * @var callable[] 24 | */ 25 | protected static $callbacks = []; 26 | 27 | /** 28 | * @var string 29 | */ 30 | protected $name = 'callbackquery'; 31 | 32 | /** 33 | * @var string 34 | */ 35 | protected $description = 'Reply to callback query'; 36 | 37 | /** 38 | * @var string 39 | */ 40 | protected $version = '1.0.0'; 41 | 42 | /** 43 | * Command execute method 44 | * 45 | * @return ServerResponse 46 | */ 47 | public function execute(): ServerResponse 48 | { 49 | //$callback_query = $this->getCallbackQuery(); 50 | //$user_id = $callback_query->getFrom()->getId(); 51 | //$query_id = $callback_query->getId(); 52 | //$query_data = $callback_query->getData(); 53 | 54 | $answer = null; 55 | $callback_query = $this->getCallbackQuery(); 56 | 57 | // Call all registered callbacks. 58 | foreach (self::$callbacks as $callback) { 59 | $answer = $callback($callback_query); 60 | } 61 | 62 | return ($answer instanceof ServerResponse) ? $answer : $callback_query->answer(); 63 | } 64 | 65 | /** 66 | * Add a new callback handler for callback queries. 67 | * 68 | * @param $callback 69 | */ 70 | public static function addCallbackHandler($callback): void 71 | { 72 | self::$callbacks[] = $callback; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Commands/SystemCommands/GenericCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Commands\SystemCommands; 13 | 14 | use Longman\TelegramBot\Commands\SystemCommand; 15 | 16 | /** 17 | * Generic command 18 | */ 19 | class GenericCommand extends SystemCommand 20 | { 21 | /** 22 | * @var string 23 | */ 24 | protected $name = 'generic'; 25 | 26 | /** 27 | * @var string 28 | */ 29 | protected $description = 'Handles generic commands or is executed by default when a command is not found'; 30 | 31 | /** 32 | * @var string 33 | */ 34 | protected $version = '1.1.0'; 35 | } 36 | -------------------------------------------------------------------------------- /src/Commands/SystemCommands/GenericmessageCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Commands\SystemCommands; 13 | 14 | use Longman\TelegramBot\Commands\SystemCommand; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | use Longman\TelegramBot\Exception\TelegramException; 17 | use Longman\TelegramBot\Request; 18 | use Longman\TelegramBot\Telegram; 19 | 20 | /** 21 | * Generic message command 22 | */ 23 | class GenericmessageCommand extends SystemCommand 24 | { 25 | /** 26 | * @var string 27 | */ 28 | protected $name = Telegram::GENERIC_MESSAGE_COMMAND; 29 | 30 | /** 31 | * @var string 32 | */ 33 | protected $description = 'Handle generic message'; 34 | 35 | /** 36 | * @var string 37 | */ 38 | protected $version = '1.2.0'; 39 | 40 | /** 41 | * @var bool 42 | */ 43 | protected $need_mysql = true; 44 | 45 | /** 46 | * Execution if MySQL is required but not available 47 | * 48 | * @return ServerResponse 49 | * @throws TelegramException 50 | */ 51 | public function executeNoDb(): ServerResponse 52 | { 53 | // Try to execute any deprecated system commands. 54 | if (self::$execute_deprecated && $deprecated_system_command_response = $this->executeDeprecatedSystemCommand()) { 55 | return $deprecated_system_command_response; 56 | } 57 | 58 | return Request::emptyResponse(); 59 | } 60 | 61 | /** 62 | * Execute command 63 | * 64 | * @return ServerResponse 65 | * @throws TelegramException 66 | */ 67 | public function execute(): ServerResponse 68 | { 69 | // Try to continue any active conversation. 70 | if ($active_conversation_response = $this->executeActiveConversation()) { 71 | return $active_conversation_response; 72 | } 73 | 74 | // Try to execute any deprecated system commands. 75 | if (self::$execute_deprecated && $deprecated_system_command_response = $this->executeDeprecatedSystemCommand()) { 76 | return $deprecated_system_command_response; 77 | } 78 | 79 | return Request::emptyResponse(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Commands/SystemCommands/InlinequeryCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Commands\SystemCommands; 13 | 14 | use Longman\TelegramBot\Commands\SystemCommand; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | 17 | /** 18 | * Inline query command 19 | */ 20 | class InlinequeryCommand extends SystemCommand 21 | { 22 | /** 23 | * @var string 24 | */ 25 | protected $name = 'inlinequery'; 26 | 27 | /** 28 | * @var string 29 | */ 30 | protected $description = 'Reply to inline query'; 31 | 32 | /** 33 | * @var string 34 | */ 35 | protected $version = '1.0.1'; 36 | 37 | /** 38 | * Command execute method 39 | * 40 | * @return mixed 41 | */ 42 | public function execute(): ServerResponse 43 | { 44 | //$inline_query = $this->getInlineQuery(); 45 | //$user_id = $inline_query->getFrom()->getId(); 46 | //$query = $inline_query->getQuery(); 47 | 48 | return $this->getInlineQuery()->answer([]); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Commands/UserCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Commands; 13 | 14 | abstract class UserCommand extends Command 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/Commands/UserCommands/StartCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Commands\UserCommands; 13 | 14 | use Longman\TelegramBot\Commands\UserCommand; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | use Longman\TelegramBot\Request; 17 | 18 | /** 19 | * Start command 20 | */ 21 | class StartCommand extends UserCommand 22 | { 23 | /** 24 | * @var string 25 | */ 26 | protected $name = 'start'; 27 | 28 | /** 29 | * @var string 30 | */ 31 | protected $description = 'Start command'; 32 | 33 | /** 34 | * @var string 35 | */ 36 | protected $usage = '/start'; 37 | 38 | /** 39 | * @var string 40 | */ 41 | protected $version = '1.2.0'; 42 | 43 | /** 44 | * Command execute method 45 | * 46 | * @return ServerResponse 47 | */ 48 | public function execute(): ServerResponse 49 | { 50 | //$message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); 51 | //$chat_id = $message->getChat()->getId(); 52 | //$user_id = $message->getFrom()->getId(); 53 | 54 | return Request::emptyResponse(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Entities/Animation.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Animation 16 | * 17 | * You can provide an animation for your game so that it looks stylish in chats (check out Lumberjack for an example). This object represents an animation file to be displayed in the message containing a game. 18 | * 19 | * @link https://core.telegram.org/bots/api#animation 20 | * 21 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 22 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 23 | * @method int getWidth() Video width as defined by sender 24 | * @method int getHeight() Video height as defined by sender 25 | * @method int getDuration() Duration of the video in seconds as defined by sender 26 | * @method PhotoSize getThumbnail() Optional. Animation thumbnail as defined by sender 27 | * @method string getFileName() Optional. Original animation filename as defined by sender 28 | * @method string getMimeType() Optional. MIME type of the file as defined by sender 29 | * @method int getFileSize() Optional. File size 30 | **/ 31 | class Animation extends Entity 32 | { 33 | /** 34 | * {@inheritdoc} 35 | */ 36 | protected function subEntities(): array 37 | { 38 | return [ 39 | 'thumbnail' => PhotoSize::class, 40 | ]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Entities/Audio.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Audio 16 | * 17 | * @link https://core.telegram.org/bots/api#audio 18 | * 19 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 20 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method int getDuration() Duration of the audio in seconds as defined by sender 22 | * @method string getPerformer() Optional. Performer of the audio as defined by sender or by audio tags 23 | * @method string getTitle() Optional. Title of the audio as defined by sender or by audio tags 24 | * @method string getFileName() Optional. Original filename as defined by sender 25 | * @method string getMimeType() Optional. MIME type of the file as defined by sender 26 | * @method int getFileSize() Optional. File size 27 | * @method PhotoSize getThumbnail() Optional. Thumbnail of the album cover to which the music file belongs 28 | */ 29 | class Audio extends Entity 30 | { 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | protected function subEntities(): array 35 | { 36 | return [ 37 | 'thumbnail' => PhotoSize::class, 38 | ]; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/BotCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class BotCommand 16 | * 17 | * This entity represents a bot command. 18 | * 19 | * @link https://core.telegram.org/bots/api#botcommand 20 | * 21 | * @method string getCommand() Text of the command, 1-32 characters. Can contain only lowercase English letters, digits and underscores. 22 | * @method string getDescription() Description of the command, 3-256 characters. 23 | */ 24 | class BotCommand extends Entity 25 | { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/BotCommandScope/BotCommandScope.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 | public function __construct(array $data = []) 26 | { 27 | $data['type'] = 'chat'; 28 | parent::__construct($data); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Entities/BotCommandScope/BotCommandScopeChatAdministrators.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 | public function __construct(array $data = []) 26 | { 27 | $data['type'] = 'chat_administrators'; 28 | parent::__construct($data); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /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 | public function __construct(array $data = []) 29 | { 30 | $data['type'] = 'chat_member'; 31 | parent::__construct($data); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entities/BotCommandScope/BotCommandScopeDefault.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | use Longman\TelegramBot\Entities\Message\Factory as MaybeInaccessibleMessageFactory; 15 | use Longman\TelegramBot\Entities\Message\MaybeInaccessibleMessage; 16 | use Longman\TelegramBot\Request; 17 | 18 | /** 19 | * Class CallbackQuery. 20 | * 21 | * @link https://core.telegram.org/bots/api#callbackquery 22 | * 23 | * @method string getId() Unique identifier for this query 24 | * @method User getFrom() Sender 25 | * @method MaybeInaccessibleMessage getMessage() Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old 26 | * @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query 27 | * @method string getChatInstance() Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games. 28 | * @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field 29 | * @method string getGameShortName() Optional. Short name of a Game to be returned, serves as the unique identifier for the game 30 | */ 31 | class CallbackQuery extends Entity 32 | { 33 | /** 34 | * {@inheritdoc} 35 | */ 36 | protected function subEntities(): array 37 | { 38 | return [ 39 | 'from' => User::class, 40 | 'message' => MaybeInaccessibleMessageFactory::class, 41 | ]; 42 | } 43 | 44 | /** 45 | * Answer this callback query. 46 | * 47 | * @param array $data 48 | * 49 | * @return ServerResponse 50 | */ 51 | public function answer(array $data = []): ServerResponse 52 | { 53 | return Request::answerCallbackQuery(array_merge([ 54 | 'callback_query_id' => $this->getId(), 55 | ], $data)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Entities/ChannelPost.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | class ChannelPost extends Message 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/Entities/ChatBoost.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | use Longman\TelegramBot\Entities\ChatBoostSource\Factory as ChatBoostSourceFactory; 15 | 16 | /** 17 | * This object contains information about a chat boost. 18 | * 19 | * @link https://core.telegram.org/bots/api#chatboost 20 | * 21 | * @method string getBoostId() Unique identifier of the boost 22 | * @method int getAddDate() Point in time (Unix timestamp) when the chat was boosted 23 | * @method int getExpirationDate() Point in time (Unix timestamp) when the boost will automatically expire, unless the booster's Telegram Premium subscription is prolonged 24 | * @method ChatBoostSource getSource() Source of the added boost 25 | */ 26 | class ChatBoost extends Entity 27 | { 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function subEntities(): array 32 | { 33 | return [ 34 | 'source' => ChatBoostSourceFactory::class, 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Entities/ChatBoostAdded.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * This object represents a service message about a user boosting a chat. 16 | * 17 | * @link https://core.telegram.org/bots/api#chatboostadded 18 | * 19 | * @method int getBoostCount() Number of boosts added by the user 20 | */ 21 | class ChatBoostAdded extends Entity 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/Entities/ChatBoostRemoved.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | use Longman\TelegramBot\Entities\ChatBoostSource\Factory as ChatBoostSourceFactory; 15 | 16 | /** 17 | * This object represents a boost removed from a chat. 18 | * 19 | * @link https://core.telegram.org/bots/api#chatboostremoved 20 | * 21 | * @method Chat getChat() Chat which was boosted 22 | * @method string getBoostId() Unique identifier of the boost 23 | * @method int getRemoveDate() Point in time (Unix timestamp) when the boost was removed 24 | * @method ChatBoostSource getSource() Source of the removed boost 25 | */ 26 | class ChatBoostRemoved extends Entity 27 | { 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function subEntities(): array 32 | { 33 | return [ 34 | 'chat' => Chat::class, 35 | 'source' => ChatBoostSourceFactory::class, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/ChatBoostSource/ChatBoostSource.php: -------------------------------------------------------------------------------- 1 | User::class, 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/ChatBoostSource/ChatBoostSourceGiveaway.php: -------------------------------------------------------------------------------- 1 | User::class, 27 | ]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/ChatBoostSource/ChatBoostSourceNotImplemented.php: -------------------------------------------------------------------------------- 1 | User::class, 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/ChatBoostSource/Factory.php: -------------------------------------------------------------------------------- 1 | ChatBoostSourcePremium::class, 13 | 'gift_code' => ChatBoostSourceGiftCode::class, 14 | 'giveaway' => ChatBoostSourceGiveaway::class, 15 | ]; 16 | 17 | if (!isset($type[$data['source'] ?? ''])) { 18 | return new ChatBoostSourceNotImplemented($data, $bot_username); 19 | } 20 | 21 | $class = $type[$data['source']]; 22 | return new $class($data, $bot_username); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Entities/ChatBoostUpdated.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * This object represents a boost added to a chat or changed. 16 | * 17 | * @link https://core.telegram.org/bots/api#chatboostupdated 18 | * 19 | * @method Chat getChat() Chat which was boosted 20 | * @method ChatBoost getBoost() Information about the chat boost 21 | */ 22 | class ChatBoostUpdated extends Entity 23 | { 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | protected function subEntities(): array 28 | { 29 | return [ 30 | 'chat' => Chat::class, 31 | 'chat_boost' => ChatBoost::class, 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Entities/ChatInviteLink.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class ChatInviteLink 16 | * 17 | * Represents an invite link for a chat 18 | * 19 | * @link https://core.telegram.org/bots/api#chatinvitelink 20 | * 21 | * @method string getInviteLink() The invite link. If the link was created by another chat administrator, then the second part of the link will be replaced with “…” 22 | * @method User getCreator() Creator of the link 23 | * @method bool getCreatesJoinRequest() True, if users joining the chat via the link need to be approved by chat administrators 24 | * @method bool getIsPrimary() True, if the link is primary 25 | * @method bool getIsRevoked() True, if the link is revoked 26 | * @method string getName() Optional. Invite link name 27 | * @method int getExpireDate() Optional. Point in time (Unix timestamp) when the link will expire or has been expired 28 | * @method int getMemberLimit() Optional. Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 29 | * @method int getPendingJoinRequestCount() Optional. Number of pending join requests created using this link 30 | */ 31 | class ChatInviteLink extends Entity 32 | { 33 | /** 34 | * {@inheritdoc} 35 | */ 36 | protected function subEntities(): array 37 | { 38 | return [ 39 | 'creator' => User::class, 40 | ]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Entities/ChatJoinRequest.php: -------------------------------------------------------------------------------- 1 | Chat::class, 25 | 'from' => User::class, 26 | 'invite_link' => ChatInviteLink::class, 27 | ]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/ChatLocation.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class ChatLocation 16 | * 17 | * Represents a location to which a chat is connected. 18 | * 19 | * @link https://core.telegram.org/bots/api#chatlocation 20 | * 21 | * @method Location getLocation() The location to which the supergroup is connected. Can't be a live location. 22 | * @method string getAddress() Location address; 1-64 characters, as defined by the chat owner 23 | */ 24 | class ChatLocation extends Entity 25 | { 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | protected function subEntities(): array 30 | { 31 | return [ 32 | 'location' => Location::class, 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMember.php: -------------------------------------------------------------------------------- 1 | User::class, 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMemberLeft.php: -------------------------------------------------------------------------------- 1 | User::class, 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMemberMember.php: -------------------------------------------------------------------------------- 1 | User::class, 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/ChatMemberNotImplemented.php: -------------------------------------------------------------------------------- 1 | User::class, 27 | ]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/ChatMember/Factory.php: -------------------------------------------------------------------------------- 1 | ChatMemberOwner::class, 13 | 'administrator' => ChatMemberAdministrator::class, 14 | 'member' => ChatMemberMember::class, 15 | 'restricted' => ChatMemberRestricted::class, 16 | 'left' => ChatMemberLeft::class, 17 | 'kicked' => ChatMemberBanned::class, 18 | ]; 19 | 20 | if (!isset($type[$data['status'] ?? ''])) { 21 | return new ChatMemberNotImplemented($data, $bot_username); 22 | } 23 | 24 | $class = $type[$data['status']]; 25 | return new $class($data, $bot_username); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/ChatMemberUpdated.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | use Longman\TelegramBot\Entities\ChatMember\ChatMember; 15 | use Longman\TelegramBot\Entities\ChatMember\Factory as ChatMemberFactory; 16 | 17 | /** 18 | * Class ChatMemberUpdated 19 | * 20 | * Represents changes in the status of a chat member 21 | * 22 | * @link https://core.telegram.org/bots/api#chatmemberupdated 23 | * 24 | * @method Chat getChat() Chat the user belongs to 25 | * @method User getFrom() Performer of the action, which resulted in the change 26 | * @method int getDate() Date the change was done in Unix time 27 | * @method ChatMember getOldChatMember() Previous information about the chat member 28 | * @method ChatMember getNewChatMember() New information about the chat member 29 | * @method ChatInviteLink getInviteLink() Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events only. 30 | * @method bool getViaChatFolderInviteLink() Optional. True, if the user joined the chat via a chat folder invite link 31 | */ 32 | class ChatMemberUpdated extends Entity 33 | { 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | protected function subEntities(): array 38 | { 39 | return [ 40 | 'chat' => Chat::class, 41 | 'from' => User::class, 42 | 'old_chat_member' => ChatMemberFactory::class, 43 | 'new_chat_member' => ChatMemberFactory::class, 44 | 'invite_link' => ChatInviteLink::class, 45 | ]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Entities/ChatPhoto.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class ChatPhoto 16 | * 17 | * @link https://core.telegram.org/bots/api#chatphoto 18 | * 19 | * @method string getSmallFileId() File identifier of small (160x160) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed. 20 | * @method string getSmallFileUniqueId() Unique file identifier of small (160x160) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method string getBigFileId() File identifier of big (640x640) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed. 22 | * @method string getBigFileUniqueId() Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 23 | */ 24 | class ChatPhoto extends Entity 25 | { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/ChatShared.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class ChosenInlineResult 16 | * 17 | * @link https://core.telegram.org/bots/api#choseninlineresult 18 | * 19 | * @method string getResultId() The unique identifier for the result that was chosen 20 | * @method User getFrom() The user that chose the result 21 | * @method Location getLocation() Optional. Sender location, only for bots that require user location 22 | * @method string getInlineMessageId() Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message. 23 | * @method string getQuery() The query that was used to obtain the result 24 | */ 25 | class ChosenInlineResult extends Entity 26 | { 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | protected function subEntities(): array 31 | { 32 | return [ 33 | 'from' => User::class, 34 | 'location' => Location::class, 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Entities/Contact.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Contact 16 | * 17 | * @link https://core.telegram.org/bots/api#contact 18 | * 19 | * @method string getPhoneNumber() Contact's phone number 20 | * @method string getFirstName() Contact's first name 21 | * @method string getLastName() Optional. Contact's last name 22 | * @method int getUserId() Optional. Contact's user identifier in Telegram 23 | * @method string getVcard() Optional. Additional data about the contact in the form of a vCard 24 | */ 25 | class Contact extends Entity 26 | { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/Entities/Dice.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Dice 16 | * 17 | * This entity represents a dice with random value from 1 to 6. 18 | * 19 | * @link https://core.telegram.org/bots/api#dice 20 | * 21 | * @method string getEmoji() Emoji on which the dice throw animation is based 22 | * @method int getValue() Value of the dice, 1-6 for “🎲” and “🎯” base emoji, 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji 23 | */ 24 | class Dice extends Entity 25 | { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/Document.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Document 16 | * 17 | * @link https://core.telegram.org/bots/api#document 18 | * 19 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 20 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method PhotoSize getThumbnail() Optional. Document thumbnail as defined by sender 22 | * @method string getFileName() Optional. Original filename as defined by sender 23 | * @method string getMimeType() Optional. MIME type of the file as defined by sender 24 | * @method int getFileSize() Optional. File size 25 | */ 26 | class Document extends Entity 27 | { 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function subEntities(): array 32 | { 33 | return [ 34 | 'thumbnail' => PhotoSize::class, 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Entities/EditedChannelPost.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | class EditedChannelPost extends Message 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/Entities/EditedMessage.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | class EditedMessage extends Message 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/Entities/Factory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class File 16 | * 17 | * @link https://core.telegram.org/bots/api#file 18 | * 19 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 20 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method int getFileSize() Optional. File size, if known 22 | * @method string getFilePath() Optional. File path. Use https://api.telegram.org/file/bot/ to get the file. 23 | */ 24 | class File extends Entity 25 | { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/Games/CallbackGame.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Games; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class CallbackGame 18 | * 19 | * A placeholder, currently holds no information. Use BotFather to set up your game. 20 | * 21 | * @link https://core.telegram.org/bots/api#callbackgame 22 | **/ 23 | class CallbackGame extends Entity 24 | { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/Entities/Games/Game.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Games; 13 | 14 | use Longman\TelegramBot\Entities\Animation; 15 | use Longman\TelegramBot\Entities\Entity; 16 | use Longman\TelegramBot\Entities\MessageEntity; 17 | use Longman\TelegramBot\Entities\PhotoSize; 18 | 19 | /** 20 | * Class Game 21 | * 22 | * This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. 23 | * 24 | * @link https://core.telegram.org/bots/api#game 25 | * 26 | * @method string getTitle() Title of the game 27 | * @method string getDescription() Description of the game 28 | * @method PhotoSize[] getPhoto() Photo that will be displayed in the game message in chats. 29 | * @method string getText() Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. 30 | * @method MessageEntity[] getTextEntities() Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. 31 | * @method Animation getAnimation() Optional. Animation that will be displayed in the game message in chats. Upload via BotFather 32 | **/ 33 | class Game extends Entity 34 | { 35 | /** 36 | * {@inheritdoc} 37 | */ 38 | protected function subEntities(): array 39 | { 40 | return [ 41 | 'photo' => [PhotoSize::class], 42 | 'text_entities' => [MessageEntity::class], 43 | 'animation' => Animation::class, 44 | ]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Entities/Games/GameHighScore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Games; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | use Longman\TelegramBot\Entities\User; 16 | 17 | /** 18 | * Class GameHighScore 19 | * 20 | * This object represents one row of the high scores table for a game. 21 | * 22 | * @link https://core.telegram.org/bots/api#gamehighscore 23 | * 24 | * @method int getPosition() Position in high score table for the game 25 | * @method User getUser() User 26 | * @method int getScore() Score 27 | **/ 28 | class GameHighScore extends Entity 29 | { 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function subEntities(): array 34 | { 35 | return [ 36 | 'user' => User::class, 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Entities/Giveaway/Giveaway.php: -------------------------------------------------------------------------------- 1 | getChats() The list of chats which the user must join to participate in the giveaway 14 | * @method int getWinnersSelectionDate() Point in time (Unix timestamp) when winners of the giveaway will be selected 15 | * @method int getWinnerCount() The number of users which are supposed to be selected as winners of the giveaway 16 | * @method bool getOnlyNewMembers() Optional. True, if only users who join the chats after the giveaway started should be eligible to win 17 | * @method bool getHasPublicWinners() Optional. True, if the list of giveaway winners will be visible to everyone 18 | * @method string getPrizeDescription() Optional. Description of additional giveaway prize 19 | * @method array getCountryCodes() Optional. A list of two-letter ISO 3166-1 alpha-2 country codes indicating the countries from which eligible users for the giveaway must come. If empty, then all users can participate in the giveaway. Users with a phone number that was bought on Fragment can always participate in giveaways. 20 | * @method int getPremiumSubscriptionMonthCount() Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for 21 | */ 22 | class Giveaway extends Entity 23 | { 24 | protected function subEntities(): array 25 | { 26 | return [ 27 | 'chats' => [Chat::class], 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Entities/Giveaway/GiveawayCompleted.php: -------------------------------------------------------------------------------- 1 | Message::class, 23 | ]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Entities/Giveaway/GiveawayCreated.php: -------------------------------------------------------------------------------- 1 | getWinners() List of up to 100 winners of the giveaway 19 | * @method int getAdditionalChatCount() Optional. The number of other chats the user had to join in order to be eligible for the giveaway 20 | * @method int getPremiumSubscriptionMonthCount() Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for 21 | * @method int getUnclaimedPrizeCount() Optional. Number of undistributed prizes 22 | * @method bool getOnlyNewMembers() Optional. True, if only users who had joined the chats after the giveaway started were eligible to win 23 | * @method bool getWasRefunded() Optional. True, if the giveaway was canceled because the payment for it was refunded 24 | * @method string getPrizeDescription() Optional. Description of additional giveaway prize 25 | */ 26 | class GiveawayWinners extends Entity 27 | { 28 | protected function subEntities(): array 29 | { 30 | return [ 31 | 'chat' => Chat::class, 32 | 'winners' => [User::class], 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Entities/InlineKeyboard.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class InlineKeyboard 16 | * 17 | * @link https://core.telegram.org/bots/api#inlinekeyboardmarkup 18 | */ 19 | class InlineKeyboard extends Keyboard 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResult; 15 | use Longman\TelegramBot\Request; 16 | 17 | /** 18 | * Class InlineQuery 19 | * 20 | * @link https://core.telegram.org/bots/api#inlinequery 21 | * 22 | * @method string getId() Unique identifier for this query 23 | * @method User getFrom() Sender 24 | * @method Location getLocation() Optional. Sender location, only for bots that request user location 25 | * @method string getQuery() Text of the query (up to 512 characters) 26 | * @method string getOffset() Offset of the results to be returned, can be controlled by the bot 27 | * @method string getChatType() Optional. Type of the chat, from which the inline query was sent. Can be either “sender” for a private chat with the inline query sender, “private”, “group”, “supergroup”, or “channel”. The chat type should be always known for requests sent from official clients and most third-party clients, unless the request was sent from a secret chat 28 | */ 29 | class InlineQuery extends Entity 30 | { 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | protected function subEntities(): array 35 | { 36 | return [ 37 | 'from' => User::class, 38 | 'location' => Location::class, 39 | ]; 40 | } 41 | 42 | /** 43 | * Answer this inline query with the passed results. 44 | * 45 | * @param InlineQueryResult[] $results 46 | * @param array $data 47 | * 48 | * @return ServerResponse 49 | */ 50 | public function answer(array $results, array $data = []): ServerResponse 51 | { 52 | return Request::answerInlineQuery(array_merge([ 53 | 'inline_query_id' => $this->getId(), 54 | 'results' => $results, 55 | ], $data)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineEntity.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\InlineQuery; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class InlineEntity 18 | * 19 | * This is the base class for all inline entities. 20 | */ 21 | abstract class InlineEntity extends Entity 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResult.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\InlineQuery; 13 | 14 | use Longman\TelegramBot\Entities\InlineKeyboard; 15 | use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; 16 | 17 | /** 18 | * Class InlineQueryResultCachedSticker 19 | * 20 | * @link https://core.telegram.org/bots/api#inlinequeryresultcachedsticker 21 | * 22 | * 23 | * $data = [ 24 | * 'id' => '', 25 | * 'sticker_file_id' => '', 26 | * 'reply_markup' => , 27 | * 'input_message_content' => , 28 | * ]; 29 | * 30 | * 31 | * @method string getType() Type of the result, must be sticker 32 | * @method string getId() Unique identifier for this result, 1-64 bytes 33 | * @method string getStickerFileId() A valid file identifier of the sticker 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 sticker 36 | * 37 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 38 | * @method $this setStickerFileId(string $sticker_file_id) A valid file identifier of the sticker 39 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. An Inline keyboard attached to the message 40 | * @method $this setInputMessageContent(InputMessageContent $input_message_content) Optional. Content of the message to be sent instead of the sticker 41 | */ 42 | class InlineQueryResultCachedSticker extends InlineEntity implements InlineQueryResult 43 | { 44 | /** 45 | * InlineQueryResultCachedSticker constructor 46 | * 47 | * @param array $data 48 | */ 49 | public function __construct(array $data = []) 50 | { 51 | $data['type'] = 'sticker'; 52 | parent::__construct($data); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Entities/InlineQuery/InlineQueryResultGame.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\InlineQuery; 13 | 14 | use Longman\TelegramBot\Entities\InlineKeyboard; 15 | 16 | /** 17 | * Class InlineQueryResultGame 18 | * 19 | * @link https://core.telegram.org/bots/api#inlinequeryresultgame 20 | * 21 | * 22 | * $data = [ 23 | * 'id' => '', 24 | * 'game_short_name' => '', 25 | * 'reply_markup' => , 26 | * ]; 27 | * 28 | * 29 | * @method string getType() Type of the result, must be game 30 | * @method string getId() Unique identifier for this result, 1-64 bytes 31 | * @method string getGameShortName() Short name of the game 32 | * @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message 33 | * 34 | * @method $this setId(string $id) Unique identifier for this result, 1-64 bytes 35 | * @method $this setGameShortName(string $game_short_name) Short name of the game 36 | * @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. Inline keyboard attached to the message 37 | */ 38 | class InlineQueryResultGame extends InlineEntity implements InlineQueryResult 39 | { 40 | /** 41 | * InlineQueryResultGame constructor 42 | * 43 | * @param array $data 44 | */ 45 | public function __construct(array $data = []) 46 | { 47 | $data['type'] = 'game'; 48 | parent::__construct($data); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Entities/InlineQueryResultsButton.php: -------------------------------------------------------------------------------- 1 | WebAppInfo::class, 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/InputMedia/InputMedia.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\InputMessageContent; 13 | 14 | use Longman\TelegramBot\Entities\InlineQuery\InlineEntity; 15 | 16 | /** 17 | * Class InputContactMessageContent 18 | * 19 | * @link https://core.telegram.org/bots/api#inputcontactmessagecontent 20 | * 21 | * 22 | * $data = [ 23 | * 'phone_number' => '', 24 | * 'first_name' => '', 25 | * 'last_name' => '', 26 | * 'vcard' => '', 27 | * ]; 28 | * 29 | * 30 | * @method string getPhoneNumber() Contact's phone number 31 | * @method string getFirstName() Contact's first name 32 | * @method string getLastName() Optional. Contact's last name 33 | * @method string getVcard() Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes 34 | * 35 | * @method $this setPhoneNumber(string $phone_number) Contact's phone number 36 | * @method $this setFirstName(string $first_name) Contact's first name 37 | * @method $this setLastName(string $last_name) Optional. Contact's last name 38 | * @method $this setVcard(string $vcard) Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes 39 | */ 40 | class InputContactMessageContent extends InlineEntity implements InputMessageContent 41 | { 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/Entities/InputMessageContent/InputLocationMessageContent.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\InputMessageContent; 13 | 14 | use Longman\TelegramBot\Entities\InlineQuery\InlineEntity; 15 | 16 | /** 17 | * Class InputLocationMessageContent 18 | * 19 | * @link https://core.telegram.org/bots/api#inputlocationmessagecontent 20 | * 21 | * 22 | * $data = [ 23 | * 'latitude' => 36.0338, 24 | * 'longitude' => 71.8601, 25 | * 'horizontal_accuracy' => 36.9, 26 | * 'live_period' => 900, 27 | * 'heading' => 88, 28 | * 'proximity_alert_radius' => 300, 29 | * ]; 30 | * 31 | * @method float getLatitude() Latitude of the location in degrees 32 | * @method float getLongitude() Longitude of the location in degrees 33 | * @method float getHorizontalAccuracy() Optional. The radius of uncertainty for the location, measured in meters; 0-1500 34 | * @method int getLivePeriod() Optional. Period in seconds for which the location can be updated, should be between 60 and 86400. 35 | * @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. 36 | * @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. 37 | * 38 | * @method $this setLatitude(float $latitude) Latitude of the location in degrees 39 | * @method $this setLongitude(float $longitude) Longitude of the location in degrees 40 | * @method $this setHorizontalAccuracy(float $horizontal_accuracy) Optional. The radius of uncertainty for the location, measured in meters; 0-1500 41 | * @method $this setLivePeriod(int $live_period) Optional. Period in seconds for which the location can be updated, should be between 60 and 86400. 42 | * @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. 43 | * @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. 44 | */ 45 | class InputLocationMessageContent extends InlineEntity implements InputMessageContent 46 | { 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/Entities/InputMessageContent/InputMessageContent.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\InputMessageContent; 13 | 14 | use Longman\TelegramBot\Entities\InlineQuery\InlineEntity; 15 | 16 | /** 17 | * Represents the content of a text message to be sent as the result of an inline query. 18 | * 19 | * @link https://core.telegram.org/bots/api#inputtextmessagecontent 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 LinkPreviewOptions getLinkPreviewOptions() Optional. Link preview generation options for the 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 setLinkPreviewOptions(LinkPreviewOptions $link_preview_options) Optional. Link preview generation options for the message 30 | */ 31 | class InputTextMessageContent extends InlineEntity implements InputMessageContent 32 | { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Entities/InputMessageContent/InputVenueMessageContent.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\InputMessageContent; 13 | 14 | use Longman\TelegramBot\Entities\InlineQuery\InlineEntity; 15 | 16 | /** 17 | * Class InputVenueMessageContent 18 | * 19 | * @link https://core.telegram.org/bots/api#inputvenuemessagecontent 20 | * 21 | * 22 | * $data = [ 23 | * 'latitude' => 36.0338, 24 | * 'longitude' => 71.8601, 25 | * 'title' => '', 26 | * 'address' => '', 27 | * 'foursquare_id' => '', 28 | * 'foursquare_type' => '', 29 | * ]; 30 | * 31 | * 32 | * @method float getLatitude() Latitude of the location in degrees 33 | * @method float getLongitude() Longitude of the location in degrees 34 | * @method string getTitle() Name of the venue 35 | * @method string getAddress() Address of the venue 36 | * @method string getFoursquareId() Optional. Foursquare identifier of the venue, if known 37 | * @method string getFoursquareType() Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) 38 | * @method string getGooglePlaceId() Optional. Google Places identifier of the venue 39 | * @method string getGooglePlaceType() Optional. Google Places type of the venue 40 | * 41 | * @method $this setLatitude(float $latitude) Latitude of the location in degrees 42 | * @method $this setLongitude(float $longitude) Longitude of the location in degrees 43 | * @method $this setTitle(string $title) Name of the venue 44 | * @method $this setAddress(string $address) Address of the venue 45 | * @method $this setFoursquareId(string $foursquare_id) Optional. Foursquare identifier of the venue, if known 46 | * @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”.) 47 | * @method $this setGooglePlaceId(string $google_place_id) Optional. Google Places identifier of the venue 48 | * @method $this setGooglePlaceType(string $google_place_type) Optional. Google Places type of the venue 49 | */ 50 | class InputVenueMessageContent extends InlineEntity implements InputMessageContent 51 | { 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/Entities/InputSticker.php: -------------------------------------------------------------------------------- 1 | ” to upload a new one using multipart/form-data under name. Animated and video stickers can't be uploaded via HTTP URL. More information on Sending Files » 13 | * @method string[] getEmojiList() List of 1-20 emoji associated with the sticker 14 | * @method MaskPosition getMaskPosition() Optional. Position where the mask should be placed on faces. For “mask” stickers only. 15 | * @method string[] getKeywords() Optional. List of 0-20 search keywords for the sticker with total length of up to 64 characters. For “regular” and “custom_emoji” stickers only. 16 | */ 17 | class InputSticker extends Entity 18 | { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/Entities/KeyboardButtonPollType.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class KeyboardButtonPollType 16 | * 17 | * This entity represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed. 18 | * 19 | * @link https://core.telegram.org/bots/api#keyboardbutton 20 | * 21 | * @method string getType() Optional. If 'quiz' is passed, the user will be allowed to create only polls in the quiz mode. If 'regular' is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type. 22 | * 23 | * @method $this setType(string $type) Optional. If 'quiz' is passed, the user will be allowed to create only polls in the quiz mode. If 'regular' is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type. 24 | */ 25 | class KeyboardButtonPollType extends Entity 26 | { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/Entities/KeyboardButtonRequestUsers.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Describes the options used for link preview generation. 16 | * 17 | * @link https://core.telegram.org/bots/api#linkpreviewoptions 18 | * 19 | * @method bool getIsDisabled() Optional. True, if the link preview is disabled 20 | * @method string getUrl() Optional. URL to use for the link preview. If empty, then the first URL found in the message text will be used 21 | * @method bool getPreferSmallMedia() Optional. True, if the media in the link preview is supposed to be shrunk; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview 22 | * @method bool getPreferLargeMedia() Optional. True, if the media in the link preview is supposed to be enlarged; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview 23 | * @method bool getShowAboveText() Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text * 24 | */ 25 | class LinkPreviewOptions extends Entity 26 | { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/Entities/Location.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Location 16 | * 17 | * @link https://core.telegram.org/bots/api#location 18 | * 19 | * @method float getLongitude() Longitude as defined by sender 20 | * @method float getLatitude() Latitude as defined by sender 21 | * @method float getHorizontalAccuracy() Optional. The radius of uncertainty for the location, measured in meters; 0-1500 22 | * @method int getLivePeriod() Optional. Time relative to the message sending date, during which the location can be updated, in seconds. For active live locations only. 23 | * @method int getHeading() Optional. The direction in which user is moving, in degrees; 1-360. For active live locations only. 24 | * @method int getProximityAlertRadius() Optional. Maximum distance for proximity alerts about approaching another chat member, in meters. For sent live locations only. 25 | */ 26 | class Location extends Entity 27 | { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/LoginUrl.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class LoginUrl 16 | * 17 | * This object represents a parameter of the inline keyboard button used to automatically authorize a user. 18 | * 19 | * @link https://core.telegram.org/bots/api#loginurl 20 | * 21 | * @method string getUrl() An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. If the user refuses to provide authorization data, the original URL without information about the user will be opened. The data added is the same as described in Receiving authorization data. 22 | * @method string getForwardText() Optional. New text of the button in forwarded messages. 23 | * @method string getBotUsername() Optional. Username of a bot, which will be used for user authorization. See Setting up a bot for more details. If not specified, the current bot's username will be assumed. The url's domain must be the same as the domain linked with the bot. See Linking your domain to the bot for more details. 24 | * @method bool getRequestWriteAccess() Optional. Pass True to request the permission for your bot to send messages to the user. 25 | */ 26 | class LoginUrl extends Entity 27 | { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/MaskPosition.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class MaskPosition 16 | * 17 | * @link https://core.telegram.org/bots/api#maskposition 18 | * 19 | * @method string getPoint() The part of the face relative to which the mask should be placed. One of “forehead”, “eyes”, “mouth”, or “chin”. 20 | * @method float getXShift() Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example, choosing -1.0 will place mask just to the left of the default mask position. 21 | * @method float getYShift() Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example, 1.0 will place the mask just below the default mask position. 22 | * @method float getScale() Mask scaling coefficient. For example, 2.0 means double size. 23 | */ 24 | class MaskPosition extends Entity 25 | { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/MenuButton/Factory.php: -------------------------------------------------------------------------------- 1 | MenuButtonCommands::class, 13 | 'web_app' => MenuButtonWebApp::class, 14 | 'default' => MenuButtonDefault::class, 15 | ]; 16 | 17 | if (! isset($type[$data['type'] ?? ''])) { 18 | return new MenuButtonNotImplemented($data, $bot_username); 19 | } 20 | 21 | $class = $type[$data['type']]; 22 | return new $class($data, $bot_username); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Entities/MenuButton/MenuButton.php: -------------------------------------------------------------------------------- 1 | WebAppInfo::class, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Entities/Message/Factory.php: -------------------------------------------------------------------------------- 1 | Chat::class, 19 | ]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Entities/Message/MaybeInaccessibleMessage.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class MessageAutoDeleteTimerChanged 16 | * 17 | * Represents a service message about a change in auto-delete timer settings 18 | * 19 | * @link https://core.telegram.org/bots/api#messageautodeletetimerchanged 20 | * 21 | * @method int getMessageAutoDeleteTime() New auto-delete time for messages in the chat 22 | */ 23 | class MessageAutoDeleteTimerChanged extends Entity 24 | { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/Entities/MessageEntity.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class MessageEntity 16 | * 17 | * @link https://core.telegram.org/bots/api#messageentity 18 | * 19 | * @method string getType() Type of the entity. Currently, can be “mention” (@username), “hashtag” (#hashtag), “cashtag” ($USD), “bot_command” (/start@jobs_bot), “url” (https://telegram.org), “email” (do-not-reply@telegram.org), “phone_number” (+1-212-555-0123), “bold” (bold text), “italic” (italic text), “underline” (underlined text), “strikethrough” (strikethrough text), “spoiler” (spoiler message), “code” (monowidth string), “pre” (monowidth block), “text_link” (for clickable text URLs), “text_mention” (for users without usernames), “custom_emoji” (for inline custom emoji stickers) 20 | * @method int getOffset() Offset in UTF-16 code units to the start of the entity 21 | * @method int getLength() Length of the entity in UTF-16 code units 22 | * @method string getUrl() Optional. For "text_link" only, url that will be opened after user taps on the text 23 | * @method User getUser() Optional. For "text_mention" only, the mentioned user 24 | * @method string getLanguage() Optional. For "pre" only, the programming language of the entity text 25 | * @method string getCustomEmojiId() Optional. For “custom_emoji” only, unique identifier of the custom emoji. Use getCustomEmojiStickers to get full information about the sticker 26 | */ 27 | class MessageEntity extends Entity 28 | { 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | protected function subEntities(): array 33 | { 34 | return [ 35 | 'user' => User::class, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/MessageOrigin/Factory.php: -------------------------------------------------------------------------------- 1 | MessageOriginUser::class, 13 | 'hidden_user' => MessageOriginHiddenUser::class, 14 | 'chat' => MessageOriginChat::class, 15 | 'channel' => MessageOriginChannel::class, 16 | ]; 17 | 18 | if (!isset($type[$data['type'] ?? ''])) { 19 | return new MessageOriginNotImplemented($data, $bot_username); 20 | } 21 | 22 | $class = $type[$data['type']]; 23 | return new $class($data, $bot_username); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Entities/MessageOrigin/MessageOrigin.php: -------------------------------------------------------------------------------- 1 | Chat::class, 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/MessageOrigin/MessageOriginChat.php: -------------------------------------------------------------------------------- 1 | Chat::class, 24 | ]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Entities/MessageOrigin/MessageOriginHiddenUser.php: -------------------------------------------------------------------------------- 1 | User::class, 23 | ]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Entities/MessageReactionCountUpdated.php: -------------------------------------------------------------------------------- 1 | Chat::class, 21 | 'reactions' => [ReactionCount::class], 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Entities/MessageReactionUpdated.php: -------------------------------------------------------------------------------- 1 | Chat::class, 27 | 'user' => User::class, 28 | 'actor_chat' => Chat::class, 29 | 'old_reaction' => [ReactionTypeFactory::class], 30 | 'new_reaction' => [ReactionTypeFactory::class], 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entities/Payments/Invoice.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Payments; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class Invoice 18 | * 19 | * This object contains basic information about an invoice. 20 | * 21 | * @link https://core.telegram.org/bots/api#invoice 22 | * 23 | * @method string getTitle() Product name 24 | * @method string getDescription() Product description 25 | * @method string getStartParameter() Unique bot deep-linking parameter that can be used to generate this invoice 26 | * @method string getCurrency() Three-letter ISO 4217 currency code 27 | * @method int getTotalAmount() Total price in the smallest units of the currency (integer, not float/double). 28 | **/ 29 | class Invoice extends Entity 30 | { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/Payments/LabeledPrice.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Payments; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class LabeledPrice 18 | * 19 | * This object represents a portion of the price for goods or services. 20 | * 21 | * @link https://core.telegram.org/bots/api#labeledprice 22 | * 23 | * @method string getLabel() Portion label 24 | * @method int getAmount() Price of the product in the smallest units of the currency (integer, not float/double). 25 | **/ 26 | class LabeledPrice extends Entity 27 | { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Entities/Payments/OrderInfo.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Payments; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class OrderInfo 18 | * 19 | * This object represents information about an order. 20 | * 21 | * @link https://core.telegram.org/bots/api#orderinfo 22 | * 23 | * @method string getName() Optional. User name 24 | * @method string getPhoneNumber() Optional. User's phone number 25 | * @method string getEmail() Optional. User email 26 | * @method ShippingAddress getShippingAddress() Optional. User shipping address 27 | **/ 28 | class OrderInfo extends Entity 29 | { 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function subEntities(): array 34 | { 35 | return [ 36 | 'shipping_address' => ShippingAddress::class, 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Entities/Payments/PreCheckoutQuery.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Payments; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | use Longman\TelegramBot\Entities\User; 17 | use Longman\TelegramBot\Request; 18 | 19 | /** 20 | * Class PreCheckoutQuery 21 | * 22 | * This object contains information about an incoming pre-checkout query. 23 | * 24 | * @link https://core.telegram.org/bots/api#precheckoutquery 25 | * 26 | * @method string getId() Unique query identifier 27 | * @method User getFrom() User who sent the query 28 | * @method string getCurrency() Three-letter ISO 4217 currency code 29 | * @method int getTotalAmount() Total price in the smallest units of the currency (integer, not float/double). 30 | * @method string getInvoicePayload() Bot specified invoice payload 31 | * @method string getShippingOptionId() Optional. Identifier of the shipping option chosen by the user 32 | * @method OrderInfo getOrderInfo() Optional. Order info provided by the user 33 | **/ 34 | class PreCheckoutQuery extends Entity 35 | { 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | protected function subEntities(): array 40 | { 41 | return [ 42 | 'from' => User::class, 43 | 'order_info' => OrderInfo::class, 44 | ]; 45 | } 46 | 47 | /** 48 | * Answer this pre-checkout query. 49 | * 50 | * @param bool $ok 51 | * @param array $data 52 | * 53 | * @return ServerResponse 54 | */ 55 | public function answer(bool $ok, array $data = []): ServerResponse 56 | { 57 | return Request::answerPreCheckoutQuery(array_merge([ 58 | 'pre_checkout_query_id' => $this->getId(), 59 | 'ok' => $ok, 60 | ], $data)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Entities/Payments/ShippingAddress.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Payments; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class ShippingAddress 18 | * 19 | * This object represents a shipping address. 20 | * 21 | * @link https://core.telegram.org/bots/api#shippingaddress 22 | * 23 | * @method string getCountryCode() ISO 3166-1 alpha-2 country code 24 | * @method string getState() State, if applicable 25 | * @method string getCity() City 26 | * @method string getStreetLine1() First line for the address 27 | * @method string getStreetLine2() Second line for the address 28 | * @method string getPostCode() Address post code 29 | **/ 30 | class ShippingAddress extends Entity 31 | { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/Entities/Payments/ShippingOption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Payments; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class ShippingOption 18 | * 19 | * This object represents one shipping option. 20 | * 21 | * @link https://core.telegram.org/bots/api#shippingoption 22 | * 23 | * @method string getId() Shipping option identifier 24 | * @method string getTitle() Option title 25 | * @method LabeledPrice[] getPrices() List of price portions 26 | **/ 27 | class ShippingOption extends Entity 28 | { 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | protected function subEntities(): array 33 | { 34 | return [ 35 | 'prices' => [LabeledPrice::class], 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/Payments/ShippingQuery.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Payments; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | use Longman\TelegramBot\Entities\ServerResponse; 16 | use Longman\TelegramBot\Entities\User; 17 | use Longman\TelegramBot\Request; 18 | 19 | /** 20 | * Class ShippingQuery 21 | * 22 | * This object contains information about an incoming shipping query. 23 | * 24 | * @link https://core.telegram.org/bots/api#shippingquery 25 | * 26 | * @method string getId() Unique query identifier 27 | * @method User getFrom() User who sent the query 28 | * @method string getInvoicePayload() Bot specified invoice payload 29 | * @method ShippingAddress getShippingAddress() User specified shipping address 30 | **/ 31 | class ShippingQuery extends Entity 32 | { 33 | /** 34 | * {@inheritdoc} 35 | */ 36 | protected function subEntities(): array 37 | { 38 | return [ 39 | 'from' => User::class, 40 | 'shipping_address' => ShippingAddress::class, 41 | ]; 42 | } 43 | 44 | /** 45 | * Answer this shipping query. 46 | * 47 | * @param bool $ok 48 | * @param array $data 49 | * 50 | * @return ServerResponse 51 | */ 52 | public function answer(bool $ok, array $data = []): ServerResponse 53 | { 54 | return Request::answerShippingQuery(array_merge([ 55 | 'shipping_query_id' => $this->getId(), 56 | 'ok' => $ok, 57 | ], $data)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Entities/Payments/SuccessfulPayment.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\Payments; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class SuccessfulPayment 18 | * 19 | * This object contains basic information about a successful payment. 20 | * 21 | * @link https://core.telegram.org/bots/api#successfulpayment 22 | * 23 | * @method string getCurrency() Three-letter ISO 4217 currency code 24 | * @method int getTotalAmount() Total price in the smallest units of the currency (integer, not float/double). 25 | * @method string getInvoicePayload() Bot specified invoice payload 26 | * @method string getShippingOptionId() Optional. Identifier of the shipping option chosen by the user 27 | * @method OrderInfo getOrderInfo() Optional. Order info provided by the user 28 | * @method string getTelegramPaymentChargeId() Telegram payment identifier 29 | * @method string getProviderPaymentChargeId() Provider payment identifier 30 | **/ 31 | class SuccessfulPayment extends Entity 32 | { 33 | /** 34 | * {@inheritdoc} 35 | */ 36 | protected function subEntities(): array 37 | { 38 | return [ 39 | 'order_info' => OrderInfo::class, 40 | ]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Entities/PhotoSize.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class PhotoSize 16 | * 17 | * @link https://core.telegram.org/bots/api#photosize 18 | * 19 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 20 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method int getWidth() Photo width 22 | * @method int getHeight() Photo height 23 | * @method int getFileSize() Optional. File size 24 | */ 25 | class PhotoSize extends Entity 26 | { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/Entities/Poll.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Poll 16 | * 17 | * This entity contains information about a poll. 18 | * 19 | * @link https://core.telegram.org/bots/api#poll 20 | * 21 | * @method string getId() Unique poll identifier 22 | * @method string getQuestion() Poll question, 1-255 characters 23 | * @method PollOption[] getOptions() List of poll options 24 | * @method int getTotalVoterCount() Total number of users that voted in the poll 25 | * @method bool getIsClosed() True, if the poll is closed 26 | * @method bool getIsAnonymous() True, if the poll is anonymous 27 | * @method string getType() Poll type, currently can be “regular” or “quiz” 28 | * @method bool getAllowsMultipleAnswers() True, if the poll allows multiple answers 29 | * @method int getCorrectOptionId() Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot. 30 | * @method string getExplanation() Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters 31 | * @method MessageEntity[] getExplanationEntities() Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation 32 | * @method int getOpenPeriod() Optional. Amount of time in seconds the poll will be active after creation 33 | * @method int getCloseDate() Optional. Point in time (Unix timestamp) when the poll will be automatically closed 34 | */ 35 | class Poll extends Entity 36 | { 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | protected function subEntities(): array 41 | { 42 | return [ 43 | 'options' => [PollOption::class], 44 | 'explanation_entities' => [MessageEntity::class], 45 | ]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Entities/PollAnswer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class PollAnswer 16 | * 17 | * This entity represents an answer of a user in a non-anonymous poll. 18 | * 19 | * @link https://core.telegram.org/bots/api#pollanswer 20 | * 21 | * @method string getPollId() Unique poll identifier 22 | * @method Chat getVoterChat() Optional. The chat that changed the answer to the poll, if the voter is anonymous 23 | * @method User getUser() Optional. The user, who changed the answer to the poll 24 | * @method array getOptionIds() 0-based identifiers of answer options, chosen by the user. May be empty if the user retracted their vote. 25 | */ 26 | class PollAnswer extends Entity 27 | { 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function subEntities(): array 32 | { 33 | return [ 34 | 'voter_chat' => Chat::class, 35 | 'user' => User::class, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/PollOption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class PollOption 16 | * 17 | * This entity contains information about one answer option in a poll. 18 | * 19 | * @link https://core.telegram.org/bots/api#polloption 20 | * 21 | * @method string getText() Option text, 1-100 characters 22 | * @method int getVoterCount() Number of users that voted for this option 23 | */ 24 | class PollOption extends Entity 25 | { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Entities/ProximityAlertTriggered.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class ProximityAlertTriggered 16 | * 17 | * Represents the content of a service message, sent whenever a user in the chat triggers a proximity alert set by another user. 18 | * 19 | * @link https://core.telegram.org/bots/api#proximityalerttriggered 20 | * 21 | * @method User getTraveler() User that triggered the alert 22 | * @method User getWatcher() User that set the alert 23 | * @method int getDistance() The distance between the users 24 | */ 25 | class ProximityAlertTriggered extends Entity 26 | { 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | protected function subEntities(): array 31 | { 32 | return [ 33 | 'traveler' => User::class, 34 | 'watcher' => User::class, 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Entities/ReactionCount.php: -------------------------------------------------------------------------------- 1 | ReactionTypeFactory::class, 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Entities/ReactionType/Factory.php: -------------------------------------------------------------------------------- 1 | ReactionTypeEmoji::class, 13 | 'custom_emoji' => ReactionTypeCustomEmoji::class, 14 | ]; 15 | 16 | if (!isset($type[$data['type'] ?? ''])) { 17 | return new ReactionTypeNotImplemented($data, $bot_username); 18 | } 19 | 20 | $class = $type[$data['type']]; 21 | return new $class($data, $bot_username); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entities/ReactionType/ReactionType.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Describes reply parameters for the message that is being sent. 16 | * 17 | * @link https://core.telegram.org/bots/api#replyparameters 18 | * 19 | * @method int getMessageId() Identifier of the message that will be replied to in the current chat, or in the chat chat_id if it is specified 20 | * @method int|string getChatId() Optional. If the message to be replied to is from a different chat, unique identifier for the chat or username of the channel (in the format @channelusername) 21 | * @method bool getAllowSendingWithoutReply() Optional. Pass True if the message should be sent even if the specified message to be replied to is not found; can be used only for replies in the same chat and forum topic. 22 | * @method string getQuote() Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing. The quote must be an exact substring of the message to be replied to, including bold, italic, underline, strikethrough, spoiler, and custom_emoji entities. The message will fail to send if the quote isn't found in the original message. 23 | * @method string getQuoteParseMode() Optional. Mode for parsing entities in the quote. See formatting options for more details. 24 | * @method MessageEntity[] getQuoteEntities() Optional. A JSON-serialized list of special entities that appear in the quote. It can be specified instead of quote_parse_mode. 25 | * @method int getQuotePosition() Optional. Position of the quote in the original message in UTF-16 code units 26 | */ 27 | class ReplyParameters extends Entity 28 | { 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | protected function subEntities(): array 33 | { 34 | return [ 35 | 'quote_entities' => [MessageEntity::class], 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/ReplyToMessage.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class ReplyToMessage 16 | * 17 | * @todo Is this even required?! 18 | */ 19 | class ReplyToMessage extends Message 20 | { 21 | /** 22 | * ReplyToMessage constructor. 23 | * 24 | * @param array $data 25 | * @param string $bot_username 26 | */ 27 | public function __construct(array $data, string $bot_username = '') 28 | { 29 | //As explained in the documentation 30 | //Reply to message can't contain other reply to message entities 31 | unset($data['reply_to_message']); 32 | 33 | parent::__construct($data, $bot_username); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Entities/SentWebAppMessage.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Sticker 16 | * 17 | * @link https://core.telegram.org/bots/api#sticker 18 | * 19 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 20 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method string getType() Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”. The type of the sticker is independent from its format, which is determined by the fields is_animated and is_video. 22 | * @method int getWidth() Sticker width 23 | * @method int getHeight() Sticker height 24 | * @method bool getIsAnimated() True, if the sticker is animated 25 | * @method bool getIsVideo() True, if the sticker is a video sticker 26 | * @method PhotoSize getThumbnail() Optional. Sticker thumbnail in .webp or .jpg format 27 | * @method string getEmoji() Optional. Emoji associated with the sticker 28 | * @method string getSetName() Optional. Name of the sticker set to which the sticker belongs 29 | * @method File getPremiumAnimation() Optional. Premium animation for the sticker, if the sticker is premium 30 | * @method MaskPosition getMaskPosition() Optional. For mask stickers, the position where the mask should be placed 31 | * @method string getCustomEmojiId() Optional. For custom emoji stickers, unique identifier of the custom emoji 32 | * @method bool getNeedsRepainting() Optional. True, if the sticker must be repainted to a text color in messages, the color of the Telegram Premium badge in emoji status, white color on chat photos, or another appropriate color in other places 33 | * @method int getFileSize() Optional. File size 34 | */ 35 | class Sticker extends Entity 36 | { 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | protected function subEntities(): array 41 | { 42 | return [ 43 | 'thumbnail' => PhotoSize::class, 44 | 'premium_animation' => File::class, 45 | 'mask_position' => MaskPosition::class, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Entities/StickerSet.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class StickerSet 16 | * 17 | * @link https://core.telegram.org/bots/api#stickerset 18 | * 19 | * @method string getName() Sticker set name 20 | * @method string getTitle() Sticker set title 21 | * @method string getStickerType() Type of stickers in the set, currently one of “regular”, “mask”, “custom_emoji” 22 | * @method bool getIsAnimated() True, if the sticker set contains animated stickers 23 | * @method bool getIsVideo() True, if the sticker set contains video stickers 24 | * @method Sticker[] getStickers() List of all set stickers 25 | * @method PhotoSize getThumbnail() Optional. Sticker set thumbnail in the .WEBP or .TGS format 26 | */ 27 | class StickerSet extends Entity 28 | { 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | protected function subEntities(): array 33 | { 34 | return [ 35 | 'stickers' => [Sticker::class], 36 | 'thumbnail' => PhotoSize::class, 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Entities/Story.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Story 16 | * 17 | * @link https://core.telegram.org/bots/api#story 18 | * 19 | * @method Chat getChat() Chat that posted the story 20 | * @method int getId() Unique identifier for the story in the chat 21 | */ 22 | class Story extends Entity 23 | { 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | protected function subEntities(): array 28 | { 29 | return [ 30 | 'chat' => Chat::class, 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entities/SwitchInlineQueryChosenChat.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\TelegramPassport; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class EncryptedCredentials 18 | * 19 | * Contains data required for decrypting and authenticating EncryptedCredentials. See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes. 20 | * 21 | * @link https://core.telegram.org/bots/api#encryptedcredentials 22 | * 23 | * @method string getData() Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for EncryptedPassportElement decryption and authentication 24 | * @method string getHash() Base64-encoded data hash for data authentication 25 | * @method string getSecret() Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption 26 | **/ 27 | class EncryptedCredentials extends Entity 28 | { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportData.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\TelegramPassport; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportData 18 | * 19 | * Contains information about Telegram Passport data shared with the bot by the user. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportdata 22 | * 23 | * @method EncryptedPassportElement[] getData() Array with information about documents and other Telegram Passport elements that was shared with the bot 24 | * @method EncryptedCredentials getCredentials() Encrypted credentials required to decrypt the data 25 | **/ 26 | class PassportData extends Entity 27 | { 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function subEntities(): array 32 | { 33 | return [ 34 | 'data' => [EncryptedPassportElement::class], 35 | 'credentials' => EncryptedCredentials::class, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementError.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | interface PassportElementError 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorDataField.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorDataField 18 | * 19 | * Represents an issue in one of the data fields that was provided by the user. The error is considered resolved when the field's value changes. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrordatafield 22 | * 23 | * @method string getSource() Error source, must be data 24 | * @method string getType() The section of the user's Telegram Passport which has the error, one of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address” 25 | * @method string getFieldName() Name of the data field which has the error 26 | * @method string getDataHash() Base64-encoded data hash 27 | * @method string getMessage() Error message 28 | */ 29 | class PassportElementErrorDataField extends Entity implements PassportElementError 30 | { 31 | /** 32 | * PassportElementErrorDataField constructor 33 | * 34 | * @param array $data 35 | */ 36 | public function __construct(array $data = []) 37 | { 38 | $data['source'] = 'data'; 39 | parent::__construct($data); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFile.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorFile 18 | * 19 | * Represents an issue with a document scan. The error is considered resolved when the file with the document scan changes. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrorfile 22 | * 23 | * @method string getSource() Error source, must be file 24 | * @method string getType() The section of the user's Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration” 25 | * @method string getFileHash() Base64-encoded file hash 26 | * @method string getMessage() Error message 27 | */ 28 | class PassportElementErrorFile extends Entity implements PassportElementError 29 | { 30 | /** 31 | * PassportElementErrorFile constructor 32 | * 33 | * @param array $data 34 | */ 35 | public function __construct(array $data = []) 36 | { 37 | $data['source'] = 'file'; 38 | parent::__construct($data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFiles.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorFiles 18 | * 19 | * Represents an issue with a list of scans. The error is considered resolved when the list of files containing the scans changes. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrorfiles 22 | * 23 | * @method string getSource() Error source, must be files 24 | * @method string getType() The section of the user's Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration” 25 | * @method string[] getFileHashes() List of base64-encoded file hashes 26 | * @method string getMessage() Error message 27 | */ 28 | class PassportElementErrorFiles extends Entity implements PassportElementError 29 | { 30 | /** 31 | * PassportElementErrorFiles constructor 32 | * 33 | * @param array $data 34 | */ 35 | public function __construct(array $data = []) 36 | { 37 | $data['source'] = 'files'; 38 | parent::__construct($data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFrontSide.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorFrontSide 18 | * 19 | * Represents an issue with the front side of a document. The error is considered resolved when the file with the front side of the document changes. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrorfrontside 22 | * 23 | * @method string getSource() Error source, must be front_side 24 | * @method string getType() The section of the user's Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport” 25 | * @method string getFileHash() Base64-encoded hash of the file with the front side of the document 26 | * @method string getMessage() Error message 27 | */ 28 | class PassportElementErrorFrontSide extends Entity implements PassportElementError 29 | { 30 | /** 31 | * PassportElementErrorFrontSide constructor 32 | * 33 | * @param array $data 34 | */ 35 | public function __construct(array $data = []) 36 | { 37 | $data['source'] = 'front_side'; 38 | parent::__construct($data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorReverseSide.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorReverseSide 18 | * 19 | * Represents an issue with the reverse side of a document. The error is considered resolved when the file with reverse side of the document changes. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrorreverseside 22 | * 23 | * @method string getSource() Error source, must be reverse_side 24 | * @method string getType() The section of the user's Telegram Passport which has the issue, one of “driver_license”, “identity_card” 25 | * @method string getFileHash() Base64-encoded hash of the file with the reverse side of the document 26 | * @method string getMessage() Error message 27 | */ 28 | class PassportElementErrorReverseSide extends Entity implements PassportElementError 29 | { 30 | /** 31 | * PassportElementErrorReverseSide constructor 32 | * 33 | * @param array $data 34 | */ 35 | public function __construct(array $data = []) 36 | { 37 | $data['source'] = 'reverse_side'; 38 | parent::__construct($data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorSelfie.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorSelfie 18 | * 19 | * Represents an issue with the selfie with a document. The error is considered resolved when the file with the selfie changes. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrorselfie 22 | * 23 | * @method string getSource() Error source, must be selfie 24 | * @method string getType() The section of the user's Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport” 25 | * @method string getFileHash() Base64-encoded hash of the file with the selfie 26 | * @method string getMessage() Error message 27 | */ 28 | class PassportElementErrorSelfie extends Entity implements PassportElementError 29 | { 30 | /** 31 | * PassportElementErrorSelfie constructor 32 | * 33 | * @param array $data 34 | */ 35 | public function __construct(array $data = []) 36 | { 37 | $data['source'] = 'selfie'; 38 | parent::__construct($data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFile.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorTranslationFile 18 | * 19 | * Represents an issue with one of the files that constitute the translation of a document. The error is considered resolved when the file changes. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrortranslationfile 22 | * 23 | * @method string getSource() Error source, must be translation_file 24 | * @method string getType() Type of element of the user's Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration” 25 | * @method string getFileHash() Base64-encoded translation_file hash 26 | * @method string getMessage() Error message 27 | */ 28 | class PassportElementErrorTranslationFile extends Entity implements PassportElementError 29 | { 30 | /** 31 | * PassportElementErrorTranslationFile constructor 32 | * 33 | * @param array $data 34 | */ 35 | public function __construct(array $data = []) 36 | { 37 | $data['source'] = 'translation_file'; 38 | parent::__construct($data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFiles.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorTranslationFiles 18 | * 19 | * Represents an issue with a list of scans. The error is considered resolved when the list of files containing the scans changes. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrortranslationfiles 22 | * 23 | * @method string getSource() Error source, must be translation_files 24 | * @method string getType() Type of element of the user's Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration” 25 | * @method string[] getFileHashes() List of base64-encoded file hashes 26 | * @method string getMessage() Error message 27 | */ 28 | class PassportElementErrorTranslationFiles extends Entity implements PassportElementError 29 | { 30 | /** 31 | * PassportElementErrorTranslationFiles constructor 32 | * 33 | * @param array $data 34 | */ 35 | public function __construct(array $data = []) 36 | { 37 | $data['source'] = 'translation_files'; 38 | parent::__construct($data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportElementError/PassportElementErrorUnspecified.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Entities\TelegramPassport\PassportElementError; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportElementErrorUnspecified 18 | * 19 | * Represents an issue in an unspecified place. The error is considered resolved when new data is added. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportelementerrorunspecified 22 | * 23 | * @method string getSource() Error source, must be unspecified 24 | * @method string getType() Type of element of the user's Telegram Passport which has the issue 25 | * @method string getElementHash() Base64-encoded element hash 26 | * @method string getMessage() Error message 27 | */ 28 | class PassportElementErrorUnspecified extends Entity implements PassportElementError 29 | { 30 | /** 31 | * PassportElementErrorUnspecified constructor 32 | * 33 | * @param array $data 34 | */ 35 | public function __construct(array $data = []) 36 | { 37 | $data['source'] = 'unspecified'; 38 | parent::__construct($data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/TelegramPassport/PassportFile.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities\TelegramPassport; 13 | 14 | use Longman\TelegramBot\Entities\Entity; 15 | 16 | /** 17 | * Class PassportFile 18 | * 19 | * This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB. 20 | * 21 | * @link https://core.telegram.org/bots/api#passportfile 22 | * 23 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 24 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 25 | * @method int getFileSize() File size 26 | * @method int getFileDate() Unix time when the file was uploaded 27 | **/ 28 | class PassportFile extends Entity 29 | { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/Entities/TextQuote.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * This object contains information about the quoted part of a message that is replied to by the given message. 16 | * 17 | * @link https://core.telegram.org/bots/api#textquote 18 | * 19 | * @method string getText() Text of the quoted part of a message that is replied to by the given message 20 | * @method MessageEntity[] getEntities() Optional. Special entities that appear in the quote. Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are kept in quotes. 21 | * @method int getPosition() Approximate quote position in the original message in UTF-16 code units as specified by the sender 22 | * @method bool getIsManual() Optional. True, if the quote was chosen manually by the message sender. Otherwise, the quote was added automatically by the server. 23 | */ 24 | class TextQuote extends Entity 25 | { 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | protected function subEntities(): array 30 | { 31 | return [ 32 | 'entities' => [MessageEntity::class], 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Entities/Topics/ForumTopicClosed.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class User 16 | * 17 | * @link https://core.telegram.org/bots/api#user 18 | * 19 | * @method int getId() Unique identifier for this user or bot 20 | * @method bool getIsBot() True, if this user is a bot 21 | * @method string getFirstName() User's or bot’s first name 22 | * @method string getLastName() Optional. User's or bot’s last name 23 | * @method string getUsername() Optional. User's or bot’s username 24 | * @method string getLanguageCode() Optional. IETF language tag of the user's language 25 | * @method bool getIsPremium() Optional. True, if this user is a Telegram Premium user 26 | * @method bool getAddedToAttachmentMenu() Optional. True, if this user added the bot to the attachment menu 27 | * @method bool getCanJoinGroups() Optional. True, if the bot can be invited to groups. Returned only in getMe. 28 | * @method bool getCanReadAllGroupMessages() Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. 29 | * @method bool getSupportsInlineQueries() Optional. True, if the bot supports inline queries. Returned only in getMe. 30 | */ 31 | class User extends Entity 32 | { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Entities/UserChatBoosts.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * This object represents a list of boosts added to a chat by a user. 16 | * 17 | * @link https://core.telegram.org/bots/api#userchatboosts 18 | * 19 | * @method ChatBoost[] getBoosts() The list of boosts added to the chat by the user 20 | */ 21 | class UserChatBoosts extends Entity 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | protected function subEntities(): array 27 | { 28 | return [ 29 | 'boosts' => [ChatBoost::class], 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/UserProfilePhotos.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class UserProfilePhotos 16 | * 17 | * @link https://core.telegram.org/bots/api#userprofilephotos 18 | * 19 | * @method int getTotalCount() Total number of profile pictures the target user has 20 | */ 21 | class UserProfilePhotos extends Entity 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | protected function subEntities(): array 27 | { 28 | return [ 29 | 'photos' => PhotoSize::class, 30 | ]; 31 | } 32 | 33 | /** 34 | * Requested profile pictures (in up to 4 sizes each) 35 | * 36 | * This method overrides the default getPhotos method and returns a nice array 37 | * 38 | * @return PhotoSize[][] 39 | */ 40 | public function getPhotos(): array 41 | { 42 | $all_photos = []; 43 | 44 | if ($these_photos = $this->getProperty('photos')) { 45 | foreach ($these_photos as $photos) { 46 | $all_photos[] = array_map(function ($photo) { 47 | return new PhotoSize($photo); 48 | }, $photos); 49 | } 50 | } 51 | 52 | return $all_photos; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Entities/UsersShared.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Venue 16 | * 17 | * @link https://core.telegram.org/bots/api#venue 18 | * 19 | * @method Location getLocation() Venue location 20 | * @method string getTitle() Name of the venue 21 | * @method string getAddress() Address of the venue 22 | * @method string getFoursquareId() Optional. Foursquare identifier of the venue 23 | * @method string getFoursquareType() Optional. Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) 24 | * @method string getGooglePlaceId() Optional. Google Places identifier of the venue 25 | * @method string getGooglePlaceType() Optional. Google Places type of the venue 26 | */ 27 | class Venue extends Entity 28 | { 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | protected function subEntities(): array 33 | { 34 | return [ 35 | 'location' => Location::class, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Entities/Video.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Video 16 | * 17 | * @link https://core.telegram.org/bots/api#video 18 | * 19 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 20 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method int getWidth() Video width as defined by sender 22 | * @method int getHeight() Video height as defined by sender 23 | * @method int getDuration() Duration of the video in seconds as defined by sender 24 | * @method PhotoSize getThumbnail() Optional. Video thumbnail 25 | * @method string getFileName() Optional. Original filename as defined by sender 26 | * @method string getMimeType() Optional. Mime type of a file as defined by sender 27 | * @method int getFileSize() Optional. File size 28 | */ 29 | class Video extends Entity 30 | { 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | protected function subEntities(): array 35 | { 36 | return [ 37 | 'thumbnail' => PhotoSize::class, 38 | ]; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entities/VideoChatEnded.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * This object represents a service message about a video chat ended in the chat. 16 | * 17 | * @link https://core.telegram.org/bots/api#videochatended 18 | * 19 | * @method int getDuration() Video chat duration in seconds 20 | */ 21 | class VideoChatEnded extends Entity 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/Entities/VideoChatParticipantsInvited.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * This object represents a service message about new members invited to a video chat. 16 | * 17 | * @link https://core.telegram.org/bots/api#videochatparticipantsinvited 18 | * 19 | * @method User[] getUsers() New members that were invited to the video chat 20 | */ 21 | class VideoChatParticipantsInvited extends Entity 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | protected function subEntities(): array 27 | { 28 | return [ 29 | 'users' => [User::class], 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/VideoChatScheduled.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * This object represents a service message about a video chat scheduled in the chat. 16 | * 17 | * @link https://core.telegram.org/bots/api#videochatscheduled 18 | * 19 | * @method int getStartDate() Point in time (Unix timestamp) when the video chat is supposed to be started by a chat administrator 20 | */ 21 | class VideoChatScheduled extends Entity 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/Entities/VideoChatStarted.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * This object represents a service message about a video chat started in the chat. Currently holds no information. 16 | * 17 | * @link https://core.telegram.org/bots/api#videochatstarted 18 | */ 19 | class VideoChatStarted extends Entity 20 | { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/Entities/VideoNote.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class VideoNote 16 | * 17 | * @link https://core.telegram.org/bots/api#videonote 18 | * 19 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 20 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method int getLength() Video width and height as defined by sender 22 | * @method int getDuration() Duration of the audio in seconds as defined by sender 23 | * @method PhotoSize getThumbnail() Optional. Video thumbnail as defined by sender 24 | * @method int getFileSize() Optional. File size 25 | */ 26 | class VideoNote extends Entity 27 | { 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function subEntities(): array 32 | { 33 | return [ 34 | 'thumbnail' => PhotoSize::class, 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Entities/Voice.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class Voice 16 | * 17 | * @link https://core.telegram.org/bots/api#voice 18 | * 19 | * @method string getFileId() Identifier for this file, which can be used to download or reuse the file 20 | * @method string getFileUniqueId() Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. 21 | * @method int getDuration() Duration of the audio in seconds as defined by sender 22 | * @method string getMimeType() Optional. MIME type of the file as defined by sender 23 | * @method int getFileSize() Optional. File size 24 | */ 25 | class Voice extends Entity 26 | { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/Entities/WebAppData.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Entities; 13 | 14 | /** 15 | * Class WebhookInfo 16 | * 17 | * @link https://core.telegram.org/bots/api#webhookinfo 18 | * 19 | * @method string getUrl() Webhook URL, may be empty if webhook is not set up 20 | * @method bool getHasCustomCertificate() True, if a custom certificate was provided for webhook certificate checks 21 | * @method int getPendingUpdateCount() Number of updates awaiting delivery 22 | * @method string getIpAddress() Optional. Currently used webhook IP address 23 | * @method int getLastErrorDate() Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook 24 | * @method string getLastErrorMessage() Optional. Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook 25 | * @method int getLastSynchronizationErrorDate() Optional. Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters 26 | * @method int getMaxConnections() Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery 27 | * @method string[] getAllowedUpdates() Optional. A list of update types the bot is subscribed to. Defaults to all update types 28 | */ 29 | class WebhookInfo extends Entity 30 | { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Entities/WriteAccessAllowed.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Exception; 13 | 14 | /** 15 | * Thrown when bot token is invalid 16 | */ 17 | class InvalidBotTokenException extends TelegramException 18 | { 19 | /** 20 | * InvalidBotTokenException constructor 21 | */ 22 | public function __construct() 23 | { 24 | parent::__construct('Invalid bot token!'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Exception/TelegramException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Exception; 13 | 14 | use Exception; 15 | 16 | /** 17 | * Main exception class used for exception handling 18 | */ 19 | class TelegramException extends Exception 20 | { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/Exception/TelegramLogException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Longman\TelegramBot\Exception; 13 | 14 | /** 15 | * Main exception class used for exception handling 16 | */ 17 | class TelegramLogException extends TelegramException 18 | { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.44.1-0.45.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `user` ADD COLUMN `language_code` CHAR(10) DEFAULT NULL COMMENT 'User''s system language' AFTER `username`; 2 | ALTER TABLE `message` ADD COLUMN `video_note` TEXT COMMENT 'VoiceNote Object. Message is a Video Note, information about the Video Note' AFTER `voice`; 3 | ALTER TABLE `message` ADD COLUMN `new_chat_members` TEXT COMMENT 'List of unique user identifiers, new member(s) were added to the group, information about them (one of these members may be the bot itself)' AFTER `new_chat_member`; 4 | UPDATE `message` SET `new_chat_members` = `new_chat_member`; 5 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.47.1-0.48.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `user` ADD COLUMN `is_bot` tinyint(1) DEFAULT 0 COMMENT 'True if this user is a bot' AFTER `id`; 2 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.50.0-0.51.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` ADD COLUMN `media_group_id` TEXT COMMENT 'The unique identifier of a media message group this message belongs to' AFTER `reply_to_message`; 2 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.52.0-0.53.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` ADD COLUMN `connected_website` TEXT NULL COMMENT 'The domain name of the website on which the user has logged in.' AFTER `pinned_message`; 2 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.53.0-0.54.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` ADD COLUMN `game` TEXT NULL COMMENT 'Message is a game, information about the game.' AFTER `document`; 2 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.54.1-0.55.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` ADD COLUMN `animation` TEXT NULL COMMENT 'Message is an animation, information about the animation' AFTER `document`; 2 | ALTER TABLE `message` ADD COLUMN `passport_data` TEXT NULL COMMENT 'Telegram Passport data' AFTER `connected_website`; 3 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.57.0-0.58.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` ADD COLUMN `reply_markup` TEXT NULL COMMENT 'Inline keyboard attached to the message' AFTER `passport_data`; 2 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.60.0-0.61.0.sql: -------------------------------------------------------------------------------- 1 | SET FOREIGN_KEY_CHECKS=0; 2 | 3 | ALTER TABLE `telegram_update` 4 | DROP KEY `message_id`; 5 | 6 | ALTER TABLE `telegram_update` 7 | ADD KEY `message_id` (`message_id`), 8 | ADD KEY `chat_message_id` (`chat_id`, `message_id`); 9 | 10 | SET FOREIGN_KEY_CHECKS=1; 11 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.61.1-0.62.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `poll` ADD COLUMN `total_voter_count` int UNSIGNED COMMENT 'Total number of users that voted in the poll' AFTER `options`; 2 | ALTER TABLE `poll` ADD COLUMN `is_anonymous` tinyint(1) DEFAULT 1 COMMENT 'True, if the poll is anonymous' AFTER `is_closed`; 3 | ALTER TABLE `poll` ADD COLUMN `type` char(255) COMMENT 'Poll type, currently can be “regular” or “quiz”' AFTER `is_anonymous`; 4 | ALTER TABLE `poll` ADD COLUMN `allows_multiple_answers` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll allows multiple answers' AFTER `type`; 5 | ALTER TABLE `poll` ADD COLUMN `correct_option_id` int UNSIGNED COMMENT '0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot.' AFTER `allows_multiple_answers`; 6 | ALTER TABLE `message` ADD COLUMN `dice` TEXT COMMENT 'Message is a dice with random value from 1 to 6' AFTER `poll`; 7 | 8 | CREATE TABLE IF NOT EXISTS `poll_answer` ( 9 | `poll_id` bigint UNSIGNED COMMENT 'Unique poll identifier', 10 | `user_id` bigint NOT NULL COMMENT 'The user, who changed the answer to the poll', 11 | `option_ids` text NOT NULL COMMENT '0-based identifiers of answer options, chosen by the user. May be empty if the user retracted their vote.', 12 | `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', 13 | 14 | PRIMARY KEY (`poll_id`), 15 | FOREIGN KEY (`poll_id`) REFERENCES `poll` (`id`) 16 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; 17 | 18 | ALTER TABLE `telegram_update` ADD COLUMN `poll_answer_poll_id` bigint UNSIGNED DEFAULT NULL COMMENT 'A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.' AFTER `poll_id`; 19 | ALTER TABLE `telegram_update` ADD KEY `poll_answer_poll_id` (`poll_answer_poll_id`); 20 | ALTER TABLE `telegram_update` ADD FOREIGN KEY (`poll_answer_poll_id`) REFERENCES `poll_answer` (`poll_id`); 21 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.62.0-0.63.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `poll` ADD COLUMN `explanation` varchar(255) DEFAULT NULL COMMENT 'Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters' AFTER `correct_option_id`; 2 | ALTER TABLE `poll` ADD COLUMN `explanation_entities` text DEFAULT NULL COMMENT 'Special entities like usernames, URLs, bot commands, etc. that appear in the explanation' AFTER `explanation`; 3 | ALTER TABLE `poll` ADD COLUMN `open_period` int UNSIGNED DEFAULT NULL COMMENT 'Amount of time in seconds the poll will be active after creation' AFTER `explanation_entities`; 4 | ALTER TABLE `poll` ADD COLUMN `close_date` timestamp NULL DEFAULT NULL COMMENT 'Point in time (Unix timestamp) when the poll will be automatically closed' AFTER `open_period`; 5 | 6 | ALTER TABLE `poll_answer` DROP PRIMARY KEY, ADD PRIMARY KEY (`poll_id`, `user_id`); 7 | 8 | ALTER TABLE `message` 9 | DROP FOREIGN KEY IF EXISTS `message_ibfk_6`, 10 | DROP INDEX IF EXISTS `message_ibfk_6`; 11 | 12 | ALTER TABLE `message` 13 | ADD COLUMN `via_bot` bigint NULL DEFAULT NULL COMMENT 'Optional. Bot through which the message was sent' AFTER `reply_to_message`, 14 | ADD KEY `via_bot` (`via_bot`), 15 | ADD FOREIGN KEY (`via_bot`) REFERENCES `user` (`id`); 16 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.64.0-0.70.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` ADD COLUMN `sender_chat_id` bigint COMMENT 'Sender of the message, sent on behalf of a chat' AFTER `chat_id`; 2 | ALTER TABLE `message` ADD COLUMN `proximity_alert_triggered` TEXT NULL COMMENT 'Service message. A user in the chat triggered another user''s proximity alert while sharing Live Location.' AFTER `passport_data`; 3 | ALTER TABLE `poll` MODIFY `question` text NOT NULL COMMENT 'Poll question'; 4 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.71.0-0.72.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` MODIFY `edit_date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was last edited in Unix time'; 2 | 3 | CREATE TABLE IF NOT EXISTS `chat_member_updated` ( 4 | `id` BIGINT UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry', 5 | `chat_id` BIGINT NOT NULL COMMENT 'Chat the user belongs to', 6 | `user_id` BIGINT NOT NULL COMMENT 'Performer of the action, which resulted in the change', 7 | `date` TIMESTAMP NOT NULL COMMENT 'Date the change was done in Unix time', 8 | `old_chat_member` TEXT NOT NULL COMMENT 'Previous information about the chat member', 9 | `new_chat_member` TEXT NOT NULL COMMENT 'New information about the chat member', 10 | `invite_link` TEXT NULL COMMENT 'Chat invite link, which was used by the user to join the chat; for joining by invite link events only', 11 | `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', 12 | 13 | PRIMARY KEY (`id`), 14 | 15 | FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`), 16 | FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) 17 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; 18 | 19 | ALTER TABLE `telegram_update` ADD COLUMN `my_chat_member_updated_id` BIGINT UNSIGNED NULL COMMENT 'The bot''s chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.'; 20 | ALTER TABLE `telegram_update` ADD FOREIGN KEY (`my_chat_member_updated_id`) REFERENCES `chat_member_updated` (`id`); 21 | ALTER TABLE `telegram_update` ADD COLUMN `chat_member_updated_id` BIGINT UNSIGNED NULL COMMENT 'A chat member''s status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowed_updates to receive these updates.'; 22 | ALTER TABLE `telegram_update` ADD FOREIGN KEY (`chat_member_updated_id`) REFERENCES `chat_member_updated` (`id`); 23 | 24 | ALTER TABLE `message` ADD COLUMN `message_auto_delete_timer_changed` TEXT COMMENT 'MessageAutoDeleteTimerChanged object. Message is a service message: auto-delete timer settings changed in the chat' AFTER `channel_chat_created`; 25 | ALTER TABLE `message` ADD COLUMN `voice_chat_started` TEXT COMMENT 'VoiceChatStarted object. Message is a service message: voice chat started' AFTER `proximity_alert_triggered`; 26 | ALTER TABLE `message` ADD COLUMN `voice_chat_ended` TEXT COMMENT 'VoiceChatEnded object. Message is a service message: voice chat ended' AFTER `voice_chat_started`; 27 | ALTER TABLE `message` ADD COLUMN `voice_chat_participants_invited` TEXT COMMENT 'VoiceChatParticipantsInvited object. Message is a service message: new participants invited to a voice chat' AFTER `voice_chat_ended`; 28 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.72.0-0.73.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` ADD COLUMN `voice_chat_scheduled` TEXT COMMENT 'VoiceChatScheduled object. Message is a service message: voice chat scheduled' AFTER `proximity_alert_triggered`; 2 | ALTER TABLE `inline_query` ADD COLUMN `chat_type` CHAR(255) NULL DEFAULT NULL COMMENT 'Optional. Type of the chat, from which the inline query was sent.' AFTER `offset`; 3 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.74.0-0.75.0.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS `chat_join_request` ( 2 | `id` BIGINT UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry', 3 | `chat_id` BIGINT NOT NULL COMMENT 'Chat to which the request was sent', 4 | `user_id` BIGINT NOT NULL COMMENT 'User that sent the join request', 5 | `date` TIMESTAMP NOT NULL COMMENT 'Date the request was sent in Unix time', 6 | `bio` TEXT NULL COMMENT 'Optional. Bio of the user', 7 | `invite_link` TEXT NULL COMMENT 'Optional. Chat invite link that was used by the user to send the join request', 8 | `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', 9 | 10 | PRIMARY KEY (`id`), 11 | 12 | FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`), 13 | FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) 14 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; 15 | 16 | ALTER TABLE `telegram_update` ADD COLUMN `chat_join_request_id` BIGINT UNSIGNED NULL COMMENT 'A request to join the chat has been sent'; 17 | ALTER TABLE `telegram_update` ADD FOREIGN KEY (`chat_join_request_id`) REFERENCES `chat_join_request` (`id`); 18 | 19 | ALTER TABLE `message` ADD COLUMN `is_automatic_forward` tinyint(1) DEFAULT 0 COMMENT 'True, if the message is a channel post that was automatically forwarded to the connected discussion group' AFTER `forward_date`; 20 | ALTER TABLE `message` ADD COLUMN `has_protected_content` tinyint(1) DEFAULT 0 COMMENT 'True, if the message can''t be forwarded' AFTER `edit_date`; 21 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.76.1-0.77.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` ADD COLUMN `web_app_data` TEXT NULL DEFAULT NULL COMMENT 'Service message: data sent by a Web App' AFTER `voice_chat_participants_invited`; 2 | 3 | ALTER TABLE `message` 4 | CHANGE `voice_chat_scheduled` `video_chat_scheduled` TEXT COMMENT 'Service message: video chat scheduled', 5 | CHANGE `voice_chat_started` `video_chat_started` TEXT COMMENT 'Service message: video chat started', 6 | CHANGE `voice_chat_ended` `video_chat_ended` TEXT COMMENT 'Service message: video chat ended', 7 | CHANGE `voice_chat_participants_invited` `video_chat_participants_invited` TEXT COMMENT 'Service message: new participants invited to a video chat'; 8 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.77.1-0.78.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `user` ADD COLUMN `is_premium` tinyint(1) DEFAULT 0 COMMENT 'True, if this user is a Telegram Premium user' AFTER `language_code`; 2 | ALTER TABLE `user` ADD COLUMN `added_to_attachment_menu` tinyint(1) DEFAULT 0 COMMENT 'True, if this user added the bot to the attachment menu' AFTER `is_premium`; 3 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.79.0-0.80.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` 2 | ADD COLUMN `is_topic_message` TINYINT(1) DEFAULT 0 COMMENT 'True, if the message is sent to a forum topic' AFTER `forward_date`, 3 | ADD COLUMN `message_thread_id` BIGINT(20) NULL DEFAULT NULL COMMENT 'Unique identifier of a message thread to which the message belongs; for supergroups only' AFTER `id`, 4 | ADD COLUMN `forum_topic_created` TEXT NULL DEFAULT NULL COMMENT 'Service message: forum topic created' AFTER `proximity_alert_triggered`, 5 | ADD COLUMN `forum_topic_closed` TEXT NULL DEFAULT NULL COMMENT 'Service message: forum topic closed' AFTER `forum_topic_created`, 6 | ADD COLUMN `forum_topic_reopened` TEXT NULL DEFAULT NULL COMMENT 'Service message: forum topic reopened' AFTER `forum_topic_closed`; 7 | 8 | ALTER TABLE `chat` 9 | ADD COLUMN `is_forum` TINYINT(1) DEFAULT 0 COMMENT 'True, if the supergroup chat is a forum (has topics enabled)' AFTER `last_name`; 10 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.80.0-0.81.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` 2 | ADD COLUMN `has_media_spoiler` TINYINT(1) DEFAULT 0 COMMENT 'True, if the message media is covered by a spoiler animation' AFTER `caption`, 3 | ADD COLUMN `write_access_allowed` TEXT DEFAULT NULL COMMENT 'Service message: the user allowed the bot added to the attachment menu to write messages' AFTER `connected_website`, 4 | ADD COLUMN `forum_topic_edited` TEXT DEFAULT NULL COMMENT 'Service message: forum topic edited' AFTER `forum_topic_created`, 5 | ADD COLUMN `general_forum_topic_hidden` TEXT DEFAULT NULL COMMENT 'Service message: the General forum topic hidden' AFTER `forum_topic_reopened`, 6 | ADD COLUMN `general_forum_topic_unhidden` TEXT DEFAULT NULL COMMENT 'Service message: the General forum topic unhidden' AFTER `general_forum_topic_hidden`, 7 | ADD COLUMN `user_shared` TEXT DEFAULT NULL COMMENT 'Optional. Service message: a user was shared with the bot' AFTER `successful_payment`, 8 | ADD COLUMN `chat_shared` TEXT DEFAULT NULL COMMENT 'Optional. Service message: a chat was shared with the bot' AFTER `user_shared`; 9 | -------------------------------------------------------------------------------- /utils/db-schema-update/0.81.0-0.82.0.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE `message` 2 | ADD COLUMN `story` TEXT DEFAULT NULL COMMENT 'Story object. Message is a forwarded story' AFTER `sticker`; 3 | -------------------------------------------------------------------------------- /utils/importFromLog.php: -------------------------------------------------------------------------------- 1 | 'localhost', 26 | 'port' => 3306, // optional 27 | 'user' => 'dbuser', 28 | 'password' => 'dbpass', 29 | 'database' => 'dbname', 30 | ]; 31 | 32 | try { 33 | // Create dummy Telegram API object and connect to MySQL database. 34 | (new Telegram('1:A'))->enableMySql($mysql_credentials); 35 | 36 | // Load the updates log file to iterate over. 37 | $updates_log_file = new SplFileObject($updates_log_file_path); 38 | $updates_log_file->setFlags(SplFileObject::DROP_NEW_LINE | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY); 39 | 40 | foreach ($updates_log_file as $update_json) { 41 | if ($update_arr = json_decode($update_json, true)) { 42 | echo $update_json . PHP_EOL; 43 | 44 | // Get all updates on this line. 45 | $updates_data = array_filter($update_arr['result'] ?? [$update_arr]); 46 | foreach ($updates_data as $update_data) { 47 | $update = new Update($update_data); 48 | printf( 49 | 'Update ID %d %s' . PHP_EOL, 50 | $update->getUpdateId(), 51 | DB::insertRequest($update) ? '(success)' : '(failed) ' . implode(' ', DB::getPdo()->errorInfo()) 52 | ); 53 | } 54 | } 55 | } 56 | } catch (Throwable $e) { 57 | // Output any errors. 58 | echo $e; 59 | } 60 | --------------------------------------------------------------------------------