diff --git a/.gitattributes b/.gitattributes index b2638710..aacc9b12 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,9 +2,11 @@ # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". -/.gitattributes export-ignore -/.gitignore export-ignore -/.travis.yml export-ignore -/phpunit.xml.dist export-ignore -/.scrutinizer.yml export-ignore -/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.github export-ignore +/.scrutinizer.yml export-ignore +/phpunit.xml.dist export-ignore +/.php-cs-fixer.dist.php export-ignore +/psalm.xml export-ignore +/tests export-ignore diff --git a/.github/workflows/cs.yaml b/.github/workflows/cs.yaml new file mode 100644 index 00000000..fcdf786c --- /dev/null +++ b/.github/workflows/cs.yaml @@ -0,0 +1,55 @@ +on: + - pull_request + - push + +name: CS Check + +jobs: + tests: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + php: + - "8.1" + steps: + - + name: Checkout + uses: actions/checkout@v2 + + - + name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + + - + name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - + name: Cache dependencies installed with composer + uses: actions/cache@v4 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer-latest- + - + name: Update composer + run: composer self-update + + - + name: Remove psalm + run: composer remove vimeo/psalm --dev --no-update + + - + name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - + name: Run php-cs-fixer + run: composer cs-check diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 00000000..e57d5d4d --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,23 @@ +name: Run tests + +on: + push: + branches: ["*"] + pull_request: + +jobs: + phpunit: + runs-on: ubuntu-latest + strategy: + matrix: + php: ["8.1", "8.2"] + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-interaction + - name: Run tests + run: composer test diff --git a/.github/workflows/psalm.yaml b/.github/workflows/psalm.yaml new file mode 100644 index 00000000..8cdc4b52 --- /dev/null +++ b/.github/workflows/psalm.yaml @@ -0,0 +1,55 @@ +on: + - pull_request + - push + +name: Psalm + +jobs: + tests: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + php: + - "8.1" + steps: + - + name: Checkout + uses: actions/checkout@v2 + + - + name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + + - + name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - + name: Cache dependencies installed with composer + uses: actions/cache@v4 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer-latest- + - + name: Update composer + run: composer self-update + + - + name: Remove php-cs-fixer + run: composer remove friendsofphp/php-cs-fixer --dev --no-update + + - + name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - + name: Run Psalm + run: composer psalm diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..6b8ab6fd --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,66 @@ +on: + - pull_request + - push + +name: Tests + +jobs: + tests: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + php: + - "8.1" + - "8.2" + - "8.3" + - "8.4" + steps: + - + name: Checkout + uses: actions/checkout@v4 + + - + name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + + - + name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - + name: Cache dependencies installed with composer + uses: actions/cache@v4 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer-{{ matrix.deps }}- + - + name: Update composer + run: composer self-update + + - + name: Remove php-cs-fixer + run: composer remove friendsofphp/php-cs-fixer --dev --no-update + + - + name: Remove psalm + run: composer remove vimeo/psalm --dev --no-update + + - + name: Remove http client dependencies + run: composer remove psr/http-client psr/http-factory php-http/multipart-stream-builder symfony/http-client symfony/mime guzzlehttp/guzzle --dev --no-update + + - + name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - + name: Run tests with phpunit + run: composer test diff --git a/.gitignore b/.gitignore index 34de0587..0107af84 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ composer.lock docs vendor +.phpunit.result.cache +.php-cs-fixer.cache + ### JetBrains template # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm @@ -55,4 +58,4 @@ crashlytics-build.properties # Composer vendor/ -/*.php \ No newline at end of file +/*.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..0413b8d7 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,34 @@ +in([ + 'src', + 'tests', + ]) + ->name('*.php') +; + +return (new PhpCsFixer\Config()) + ->setFinder($finder) + ->setRules([ + '@PER' => true, + '@PER:risky' => true, + 'visibility_required' => [ + 'elements' => [ + 'property', + 'method', + // 'const', // Not supported in php < 7.1 + ], + ], + 'no_unused_imports' => true, + 'single_quote' => true, + 'no_extra_blank_lines' => true, + 'array_indentation' => true, + 'cast_spaces' => true, + 'phpdoc_align' => [ + 'align' => 'left', + ], + 'binary_operator_spaces' => true, + 'single_line_empty_body' => false, + ]) +; diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 0fbe2943..2bf3b16c 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,26 +1,25 @@ filter: excluded_paths: [tests/*] -checks: - php: - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true +#checks: +# php: +# remove_extra_empty_lines: true +# remove_php_closing_tag: true +# remove_trailing_whitespace: true +# fix_use_statements: +# remove_unused: true +# preserve_multiple: false +# preserve_blanklines: true +# order_alphabetically: true +# fix_php_opening_tag: true +# fix_linefeed: true +# fix_line_ending: true +# fix_identation_4spaces: true +# fix_doc_comments: true build: + dependencies: + override: + - true tests: override: - - - command: 'phpunit --coverage-text --coverage-clover=coverage.clover' - coverage: - file: 'coverage.clover' - format: 'php-clover' \ No newline at end of file + - true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 18950229..00000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: php -dist: trusty - -php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - hhvm - -matrix: - allow_failures: - - php: hhvm - -before_script: - - travis_retry composer self-update - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source - -script: - - php vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 src/ - - phpunit --coverage-text --coverage-clover=coverage.clover \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cb17251..60817072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,19 +2,76 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file -## NEXT - YYYY-MM-DD +## 3.0.0 - YYYY-MM-DD +- Add `\TelegramBot\Api\Types\Update::$myChatMember` field +- Add `\TelegramBot\Api\Types\Update::$chatMember` field +- Add `\TelegramBot\Api\Types\Update::$chatJoinRequest` field +- Add `\TelegramBot\Api\BotApi::createChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::editChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::revokeChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::approveChatJoinRequest` api method +- Add `\TelegramBot\Api\BotApi::declineChatJoinRequest` api method +- Add support for third party http clients (`psr/http-client` and `symfony/http-client`) +- Add support for local bot API server +- Add method `\TelegramBot\Api\BotApi::validateWebAppData` to validate `window.Telegram.WebApp.initData` +- Add `\TelegramBot\Api\Types\Message::$videoNote` field +- Drop php < 8.1 +- Add `\TelegramBot\Api\Types\Update::$messageReaction` field +- Add `\TelegramBot\Api\Types\Update::$messageReactionCount` field +- Add `\TelegramBot\Api\BotApi::setMessageReaction` api method +- Add `\TelegramBot\Api\BotApi::deleteMessages` api method +- Add `\TelegramBot\Api\BotApi::copyMessages` api method +- Add `\TelegramBot\Api\BotApi::forwardMessages` api method +- Add `\TelegramBot\Api\BotApi::getUserChatBoosts` api method + +### Deprecated +- Deprecate `reply_to_message_id` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods. Use `reply_parameters` instead. +- Deprecate `disable_web_page_preview` parameter to `\TelegramBot\Api\BotApi` methods. Use `link_preview_options` instead. + +## 2.5.0 - 2023-08-09 ### Added -- Nothing +- Add missing `protect_content` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods +- Add support `attach://` in `\TelegramBot\Api\BotApi` methods `sendMediaGroup`, `createNewStickerSet`, `addStickerToSet`, `editMessageMedia` +- Rename `thumb` to `thumbnail` parameter in `Animation`, `Document`, `Sticker`, `StickerSet`, `Video`, `VideoNote` types +- Rename `thumb_*` to `thumbnail_*` parameter in `Inline/QueryResult` types +- Add missing phpDoc for `$replyMarkup` parameters +- Fix phpDoc for `\TelegramBot\Api\BotApi::setWebhook` `$allowedUpdates` parameter. Automatically serialize if array passed +- Fix phpDoc for `\TelegramBot\Api\Types\Message::$newChatMembers` +- Add `\TelegramBot\Api\BotApi::getChatMemberCount` method +- Add `\TelegramBot\Api\BotApi::banChatMember` method +- Add `$messageId` to `\TelegramBot\Api\BotApi::unpinChatMessage` +- Add `\TelegramBot\Api\Types\ForceReply::$inputFieldPlaceholder` property ### Deprecated -- Nothing +- Deprecate using `thumb*` methods in `\TelegramBot\Api\BotApi` +- Deprecate method `\TelegramBot\Api\BotApi::setStickerSetThumb`. Use `\TelegramBot\Api\BotApi::setStickerSetThumbnail` instead +- Deprecate `\TelegramBot\Api\Types\ReplyKeyboardHide` class +- Deprecate `\TelegramBot\Api\BotApi::getChatMembersCount`. Use `\TelegramBot\Api\BotApi::getChatMemberCount` instead +- Deprecate `\TelegramBot\Api\BotApi::kickChatMember`. Use `\TelegramBot\Api\BotApi::banChatMember` instead + +## 2.4.0 - 2023-05-11 + +### Added +- Add `\TelegramBot\Api\Types\Venue` mapping (`foursquare_type`, `google_place_id`, `google_place_type`) +- Add `scope` and `languageCode` parameters to `\TelegramBot\Api\BotApi::setMyCommands` +- Add WebApp support: `\TelegramBot\Api\BotApi::answerWebAppQuery` method and `\TelegramBot\Api\Types\Message::$webAppData` property +- Add `\TelegramBot\Api\Types\ReplyKeyboardMarkup::$isPersistent` property +- Add `\TelegramBot\Api\Types\ReplyKeyboardMarkup::$inputFieldPlaceholder` property ### Fixed -- Nothing +- Fix `\TelegramBot\Api\Collection\Collection::addItem` max count constraint (#333) +- Fix `\TelegramBot\Api\Types\StickerSet` mapping +- Fix `\TelegramBot\Api\BotApi::copyMessage` not returning `\TelegramBot\Api\Types\MessageId` +- Fix new `$messageThreadId` parameter in `\TelegramBot\Api\BotApi` methods placed not in the end of the list of parameters -### Removed -- Nothing +### Changed +- `\TelegramBot\Api\BotApi::getMyCommands` now returns instance `\TelegramBot\Api\Types\ArrayOfBotCommand` instead of `\TelegramBot\Api\Types\BotCommand` array +- `\TelegramBot\Api\BotApi::setMyCommands` now accepts instance of `\TelegramBot\Api\Types\ArrayOfBotCommand` instead of `\TelegramBot\Api\Types\BotCommand` array -### Security -- Nothing +### Deprecated +- Deprecate `\TelegramBot\Api\Botan` class +- Deprecate `$trackerToken` parameter in `\TelegramBot\Api\BotApi::__construct` +- Deprecate `$trackerToken` parameter in `\TelegramBot\Api\Events\EventCollection::__construct` +- Deprecate `\TelegramBot\Api\Types\PollAnswer::getFrom` use `\TelegramBot\Api\Types\PollAnswer::getUser` instead +- Deprecate passing array of BotCommand to `\TelegramBot\Api\BotApi::setMyCommands`. Use `\TelegramBot\Api\Types\ArrayOfBotCommand` instead diff --git a/README.md b/README.md index a899d45b..f3b7bf04 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,6 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/telegram-bot/api.svg?style=flat-square)](https://packagist.org/packages/telegram-bot/api) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) -[![Build Status](https://img.shields.io/travis/TelegramBot/Api/master.svg?style=flat-square)](https://travis-ci.org/TelegramBot/Api) -[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/telegrambot/api.svg?style=flat-square)](https://scrutinizer-ci.com/g/telegrambot/api/code-structure) -[![Quality Score](https://img.shields.io/scrutinizer/g/telegrambot/api.svg?style=flat-square)](https://scrutinizer-ci.com/g/telegrambot/api) [![Total Downloads](https://img.shields.io/packagist/dt/telegram-bot/api.svg?style=flat-square)](https://packagist.org/packages/telegram-bot/api) An extended native php wrapper for [Telegram Bot API](https://core.telegram.org/bots/api) without requirements. Supports all methods and types of responses. @@ -17,7 +14,7 @@ An extended native php wrapper for [Telegram Bot API](https://core.telegram.org/ >The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult [Introduction to Bots](https://core.telegram.org/bots) and [Bot FAQ](https://core.telegram.org/bots/faq). -## Install +## Installation Via Composer @@ -29,13 +26,14 @@ $ composer require telegram-bot/api See example [DevAnswerBot](https://github.com/TelegramBot/DevAnswerBot) (russian). -#### API Wrapper +### API Wrapper +#### Send message ``` php $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); $bot->sendMessage($chatId, $messageText); ``` - +#### Send document ```php $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); @@ -43,7 +41,7 @@ $document = new \CURLFile('document.txt'); $bot->sendDocument($chatId, $document); ``` - +#### Send message with reply keyboard ```php $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); @@ -51,7 +49,7 @@ $keyboard = new \TelegramBot\Api\Types\ReplyKeyboardMarkup(array(array("one", "t $bot->sendMessage($chatId, $messageText, null, false, null, $keyboard); ``` - +#### Send message with inline keyboard ```php $bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); @@ -65,6 +63,17 @@ $keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup( $bot->sendMessage($chatId, $messageText, null, false, null, $keyboard); ``` +#### Send media group +```php +$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN'); + +$media = new \TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia(); +$media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaPhoto('https://avatars3.githubusercontent.com/u/9335727')); +$media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaPhoto('https://avatars3.githubusercontent.com/u/9335727')); +// Same for video +// $media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaVideo('http://clips.vorwaerts-gmbh.de/VfE_html5.mp4')); +$bot->sendMediaGroup($chatId, $media); +``` #### Client @@ -73,14 +82,21 @@ require_once "vendor/autoload.php"; try { $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN'); - // or initialize with botan.io tracker api key - // $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY'); - + //Handle /ping command $bot->command('ping', function ($message) use ($bot) { $bot->sendMessage($message->getChat()->getId(), 'pong!'); }); + //Handle text messages + $bot->on(function (\TelegramBot\Api\Types\Update $update) use ($bot) { + $message = $update->getMessage(); + $id = $message->getChat()->getId(); + $bot->sendMessage($id, 'Your message: ' . $message->getText()); + }, function () { + return true; + }); + $bot->run(); } catch (\TelegramBot\Api\Exception $e) { @@ -88,45 +104,26 @@ try { } ``` -### Botan SDK - -[Botan](http://botan.io) is a telegram bot analytics system based on [Yandex.Appmetrica](http://appmetrica.yandex.com/). -In this document you can find how to setup Yandex.Appmetrica account, as well as examples of Botan SDK usage. +#### Local Bot API Server -### Creating an account - * Register at http://appmetrica.yandex.com/ - * After registration you will be prompted to create Application. Please use @YourBotName as a name. - * Save an API key from settings page, you will use it as a token for Botan API calls. - * Download lib for your language, and use it as described below. Don`t forget to insert your token! +For using custom [local bot API server](https://core.telegram.org/bots/api#using-a-local-bot-api-server) -Since we are only getting started, you may discover that some existing reports in AppMetriсa aren't properly working for Telegram bots, like Geography, Gender, Age, Library, Devices, Traffic sources and Network sections. We will polish that later. - -## SDK usage - -#### Standalone - -```php -$tracker = new \TelegramBot\Api\Botan('YOUR_BOTAN_TRACKER_API_KEY'); - -$tracker->track($message, $eventName); -``` - -#### API Wrapper ```php -$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY'); - -$bot->track($message, $eventName); +use TelegramBot\Api\Client; +$token = 'YOUR_BOT_API_TOKEN'; +$bot = new Client($token, null, null, 'http://localhost:8081'); ``` -_You can use method `getUpdates()` and all incoming messages will be automatically tracked as `Message`-event_ +#### Third-party Http Client -#### Client ```php -$bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY'); +use Symfony\Component\HttpClient\HttpClient; +use TelegramBot\Api\BotApi; +use TelegramBot\Api\Http\SymfonyHttpClient; +$token = 'YOUR_BOT_API_TOKEN'; +$bot = new Client($token, null, new SymfonyHttpClient(HttpClient::create());); ``` -_All registered commands are automatically tracked as command name_ - ## Change log Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. diff --git a/composer.json b/composer.json index 80fb1384..c41dbb68 100644 --- a/composer.json +++ b/composer.json @@ -18,12 +18,28 @@ } ], "require": { - "php" : ">=5.5.0" + "php" : ">=8.1", + "ext-curl": "*", + "ext-json": "*" }, "require-dev": { - "phpunit/phpunit" : "~4.0", - "squizlabs/php_codesniffer": "2.*", - "codeception/codeception": "*" + "symfony/phpunit-bridge" : "*", + "friendsofphp/php-cs-fixer": "~3.28.0", + "vimeo/psalm": "^5.9", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", + "php-http/multipart-stream-builder": "^1.0", + "symfony/http-client": "^4.3 | ^5.0 | ^6.0", + "symfony/mime": "^4.3 | ^5.0 | ^6.0", + "guzzlehttp/guzzle": "^7.0" + }, + "suggest": { + "psr/http-client": "To use psr/http-client", + "psr/http-factory": "To use psr/http-client", + "php-http/multipart-stream-builder": "To use psr/http-client", + "guzzlehttp/guzzle": "To use guzzlehttp/guzzle psr implementation", + "symfony/http-client": "To use symfony/http-client", + "symfony/mime": "To use symfony/http-client" }, "autoload": { "psr-4": { @@ -36,11 +52,25 @@ } }, "scripts": { - "test": "phpunit" + "test": "vendor/bin/simple-phpunit --colors=always", + "coverage": "XDEBUG_MODE=coverage vendor/bin/simple-phpunit --coverage-html build/coverage", + "psalm": "vendor/bin/psalm", + "cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi", + "cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run", + "checks": [ + "@cs-fix", + "@psalm", + "@test" + ] }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.6-dev" + } + }, + "config": { + "allow-plugins": { + "php-http/discovery": false } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4abf248a..b8a9042b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,16 +18,8 @@ src/ - - tests/ - vendor/ - - - - - - - - + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..238ab766 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/BadMethodCallException.php b/src/BadMethodCallException.php index 210fdd8d..738087bb 100644 --- a/src/BadMethodCallException.php +++ b/src/BadMethodCallException.php @@ -10,5 +10,4 @@ */ class BadMethodCallException extends Exception { - } diff --git a/src/BaseType.php b/src/BaseType.php index 976e5d03..f7f2f9ee 100644 --- a/src/BaseType.php +++ b/src/BaseType.php @@ -39,13 +39,18 @@ public static function validate($data) return true; } - throw new InvalidArgumentException(); + $missingParams = implode(', ', array_diff(static::$requiredParams, array_keys($data))); + throw new InvalidArgumentException(sprintf('%s Validation failed. Missing required parameters: %s', static::class, $missingParams)); } + /** + * @param array $data + * @return void + */ public function map($data) { foreach (static::$map as $key => $item) { - if (isset($data[$key]) && (!is_array($data[$key]) || (is_array($data[$key]) && !empty($data[$key])))) { + if (isset($data[$key]) && (!is_array($data[$key]) || !empty($data[$key]))) { $method = 'set' . self::toCamelCase($key); if ($item === true) { $this->$method($data[$key]); @@ -56,11 +61,19 @@ public function map($data) } } + /** + * @param string $str + * @return string + */ protected static function toCamelCase($str) { - return str_replace(" ", "", ucwords(str_replace("_", " ", $str))); + return str_replace(' ', '', ucwords(str_replace('_', ' ', $str))); } + /** + * @param bool $inner + * @return array|string + */ public function toJson($inner = false) { $output = []; @@ -70,6 +83,10 @@ public function toJson($inner = false) if (!is_null($this->$property)) { if (is_array($this->$property)) { $output[$key] = array_map( + /** + * @param mixed $v + * @return array|false|string + */ function ($v) { return is_object($v) ? $v->toJson(true) : $v; }, @@ -84,13 +101,15 @@ function ($v) { return $inner === false ? json_encode($output) : $output; } + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ public static function fromResponse($data) { - if ($data === true) { - return true; - } - self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ $instance = new static(); $instance->map($data); diff --git a/src/BotApi.php b/src/BotApi.php index fc8a1fe8..1ac21e00 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -2,15 +2,43 @@ namespace TelegramBot\Api; +use TelegramBot\Api\Http\CurlHttpClient; +use TelegramBot\Api\Types\UserChatBoosts; +use TelegramBot\Api\Types\ReplyParameters; +use TelegramBot\Api\Http\HttpClientInterface; +use TelegramBot\Api\Types\ArrayOfBotCommand; +use TelegramBot\Api\Types\LinkPreviewOptions; +use TelegramBot\Api\Types\ArrayOfReactionType; +use TelegramBot\Api\Types\ArrayOfChatMemberEntity; +use TelegramBot\Api\Types\ArrayOfMessageEntity; +use TelegramBot\Api\Types\ArrayOfMessages; +use TelegramBot\Api\Types\ArrayOfSticker; use TelegramBot\Api\Types\ArrayOfUpdates; +use TelegramBot\Api\Types\BotCommand; use TelegramBot\Api\Types\Chat; +use TelegramBot\Api\Types\ChatFullInfo; +use TelegramBot\Api\Types\ChatInviteLink; use TelegramBot\Api\Types\ChatMember; use TelegramBot\Api\Types\File; +use TelegramBot\Api\Types\ForceReply; +use TelegramBot\Api\Types\ForumTopic; +use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; use TelegramBot\Api\Types\Inline\QueryResult\AbstractInlineQueryResult; +use TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia; +use TelegramBot\Api\Types\InputMedia\InputMedia; +use TelegramBot\Api\Types\MaskPosition; use TelegramBot\Api\Types\Message; +use TelegramBot\Api\Types\MessageId; +use TelegramBot\Api\Types\Poll; +use TelegramBot\Api\Types\ReplyKeyboardMarkup; +use TelegramBot\Api\Types\ReplyKeyboardRemove; +use TelegramBot\Api\Types\SentWebAppMessage; +use TelegramBot\Api\Types\Sticker; +use TelegramBot\Api\Types\StickerSet; use TelegramBot\Api\Types\Update; use TelegramBot\Api\Types\User; use TelegramBot\Api\Types\UserProfilePhotos; +use TelegramBot\Api\Types\WebhookInfo; /** * Class BotApi @@ -20,6 +48,8 @@ class BotApi { /** + * @deprecated + * * HTTP codes * * @var array @@ -91,85 +121,102 @@ class BotApi 511 => 'Network Authentication Required', // RFC6585 ]; + /** + * Url prefixes + */ + const URL_PREFIX = 'https://api.telegram.org/bot'; + + /** + * Url prefix for files + */ + const FILE_URL_PREFIX = 'https://api.telegram.org/file/bot'; /** + * @deprecated + * * Default http status code */ const DEFAULT_STATUS_CODE = 200; /** + * @deprecated + * * Not Modified http status code */ const NOT_MODIFIED_STATUS_CODE = 304; /** + * @deprecated + * * Limits for tracked ids */ const MAX_TRACKED_EVENTS = 200; /** - * Url prefixes - */ - const URL_PREFIX = 'https://api.telegram.org/bot'; - - /** - * Url prefix for files - */ - const FILE_URL_PREFIX = 'https://api.telegram.org/file/bot'; - - /** - * CURL object - * - * @var + * @var HttpClientInterface */ - protected $curl; + private $httpClient; /** - * Bot token - * * @var string */ - protected $token; + private $token; /** - * Botan tracker - * - * @var \TelegramBot\Api\Botan + * @var string */ - protected $tracker; + private $endpoint; /** - * list of event ids - * - * @var array + * @var string|null */ - protected $trackedEvents = []; + private $fileEndpoint; /** - * Check whether return associative array - * - * @var bool + * @param string $token Telegram Bot API token + * @param HttpClientInterface|null $httpClient + * @param string|null $endpoint */ - protected $returnArray = true; + public function __construct($token, ?HttpClientInterface $httpClient = null, $endpoint = null) + { + $this->token = $token; + $this->endpoint = ($endpoint ?: self::URL_PREFIX) . $token; + $this->fileEndpoint = $endpoint ? null : (self::FILE_URL_PREFIX . $token); + $this->httpClient = $httpClient ?: new CurlHttpClient(); + } /** - * Constructor - * - * @param string $token Telegram Bot API token - * @param string|null $trackerToken Yandex AppMetrica application api_key + * @param string $rawData + * @param int|null $authDateDiff + * @return bool */ - public function __construct($token, $trackerToken = null) + public function validateWebAppData($rawData, $authDateDiff = null) { - $this->curl = curl_init(); - $this->token = $token; + parse_str($rawData, $data); + + $sign = $data['hash']; + unset($data['hash']); + + if ($authDateDiff && (time() - $data['auth_date'] > $authDateDiff)) { + return false; + } - if ($trackerToken) { - $this->tracker = new Botan($trackerToken); + ksort($data); + $checkString = ''; + foreach ($data as $k => $v) { + $checkString .= "$k=$v\n"; } + $checkString = trim($checkString); + + $secret = hash_hmac('sha256', $this->token, 'WebAppData', true); + + return bin2hex(hash_hmac('sha256', $checkString, $secret, true)) === $sign; } /** + * @deprecated + * * Set return array * * @param bool $mode @@ -178,91 +225,86 @@ public function __construct($token, $trackerToken = null) */ public function setModeObject($mode = true) { - $this->returnArray = !$mode; + @trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED); return $this; } - /** + * @deprecated + * * Call method * * @param string $method * @param array|null $data + * @param int|null $timeout * * @return mixed - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\HttpException - * @throws \TelegramBot\Api\InvalidJsonException + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException */ - public function call($method, array $data = null) + public function call($method, ?array $data = null, $timeout = null) { - $options = [ - CURLOPT_URL => $this->getUrl().'/'.$method, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_POST => null, - CURLOPT_POSTFIELDS => null, - ]; - - if ($data) { - $options[CURLOPT_POST] = true; - $options[CURLOPT_POSTFIELDS] = $data; + if ($timeout !== null) { + @trigger_error(sprintf('Passing $timeout parameter in %s::%s is deprecated. Use http client options', __CLASS__, __METHOD__), \E_USER_DEPRECATED); } - $response = self::jsonValidate($this->executeCurl($options), $this->returnArray); + $endpoint = $this->endpoint . '/' . $method; - if ($this->returnArray) { - if (!isset($response['ok'])) { - throw new Exception($response['description'], $response['error_code']); - } - - return $response['result']; - } - - if (!$response->ok) { - throw new Exception($response->description, $response->error_code); - } - - return $response->result; + return $this->httpClient->request($endpoint, $data); } /** - * curl_exec wrapper for response validation + * Get file contents via cURL * - * @param array $options + * @param string $fileId * * @return string * - * @throws \TelegramBot\Api\HttpException + * @throws HttpException + * @throws Exception */ - protected function executeCurl(array $options) + public function downloadFile($fileId) { - curl_setopt_array($this->curl, $options); - - $result = curl_exec($this->curl); - self::curlValidate($this->curl, $result); - if ($result === false) { - throw new HttpException(curl_error($this->curl), curl_errno($this->curl)); + $file = $this->getFile($fileId); + if (!$path = $file->getFilePath()) { + throw new Exception('Empty file_path property'); + } + if (!$this->fileEndpoint) { + return file_get_contents($path); } - return $result; + return $this->httpClient->download($this->fileEndpoint . '/' . $path); } /** + * @deprecated + * * Response validation * - * @param resource $curl - * @param string $response + * @param \CurlHandle $curl + * @param string|false|null $response + * * @throws HttpException + * + * @return void */ public static function curlValidate($curl, $response = null) { - $json = json_decode($response, true)?: []; + @trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if ($response) { + $json = json_decode($response, true) ?: []; + } else { + $json = []; + } if (($httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE)) && !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE]) ) { $errorDescription = array_key_exists('description', $json) ? $json['description'] : self::$codes[$httpCode]; - throw new HttpException($errorDescription, $httpCode); + $errorParameters = array_key_exists('parameters', $json) ? $json['parameters'] : []; + throw new HttpException($errorDescription, $httpCode, null, $errorParameters); } } @@ -270,10 +312,10 @@ public static function curlValidate($curl, $response = null) * JSON validation * * @param string $jsonString - * @param boolean $asArray + * @param bool $asArray * * @return object|array - * @throws \TelegramBot\Api\InvalidJsonException + * @throws InvalidJsonException */ public static function jsonValidate($jsonString, $asArray) { @@ -289,17 +331,22 @@ public static function jsonValidate($jsonString, $asArray) /** * Use this method to send text messages. On success, the sent \TelegramBot\Api\Types\Message is returned. * - * @param int|string $chatId + * @param int|float|string $chatId * @param string $text * @param string|null $parseMode * @param bool $disablePreview * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * @param LinkPreviewOptions|null $linkPreviewOptions Link preview generation options for the message. * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendMessage( $chatId, @@ -308,16 +355,108 @@ public function sendMessage( $disablePreview = false, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $replyParameters = null, + $linkPreviewOptions = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + if (null === $linkPreviewOptions && false !== $disablePreview) { + @trigger_error('setting $disablePreview is now deprecated use $linkPreviewOptions instead', E_USER_DEPRECATED); + + $linkPreviewOptions = new LinkPreviewOptions(); + $linkPreviewOptions->map([ + 'is_disabled' => $disablePreview + ]); + } + return Message::fromResponse($this->call('sendMessage', [ 'chat_id' => $chatId, 'text' => $text, + 'message_thread_id' => $messageThreadId, 'parse_mode' => $parseMode, - 'disable_web_page_preview' => $disablePreview, - 'reply_to_message_id' => (int)$replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson(), + 'link_preview_options' => is_null($linkPreviewOptions) ? $linkPreviewOptions : $linkPreviewOptions->toJson() + ])); + } + + /** + * @param int|string $chatId + * @param int|string $fromChatId + * @param int $messageId + * @param string|null $caption + * @param string|null $parseMode + * @param ArrayOfMessageEntity|null $captionEntities + * @param bool $disableNotification + * @param int|null $replyToMessageId + * @param bool $allowSendingWithoutReply + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return MessageId + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function copyMessage( + $chatId, + $fromChatId, + $messageId, + $caption = null, + $parseMode = null, + $captionEntities = null, + $disableNotification = false, + $replyToMessageId = null, + $allowSendingWithoutReply = false, + $replyMarkup = null, + $messageThreadId = null, + $protectContent = null, + $replyParameters = null + ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + return MessageId::fromResponse($this->call('copyMessage', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_id' => (int) $messageId, + 'caption' => $caption, + 'parse_mode' => $parseMode, + 'caption_entities' => $captionEntities, + 'disable_notification' => (bool) $disableNotification, + 'message_thread_id' => $messageThreadId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -329,11 +468,15 @@ public function sendMessage( * @param string $firstName * @param string $lastName * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws Exception */ public function sendContact( $chatId, @@ -342,16 +485,35 @@ public function sendContact( $lastName = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendContact', [ 'chat_id' => $chatId, 'phone_number' => $phoneNumber, 'first_name' => $firstName, 'last_name' => $lastName, - 'reply_to_message_id' => $replyToMessageId, + 'message_thread_id' => $messageThreadId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -371,7 +533,7 @@ public function sendContact( * @param string $action * * @return bool - * @throws \TelegramBot\Api\Exception + * @throws Exception */ public function sendChatAction($chatId, $action) { @@ -388,15 +550,15 @@ public function sendChatAction($chatId, $action) * @param int $offset * @param int $limit * - * @return \TelegramBot\Api\Types\UserProfilePhotos - * @throws \TelegramBot\Api\Exception + * @return UserProfilePhotos + * @throws Exception */ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) { return UserProfilePhotos::fromResponse($this->call('getUserProfilePhotos', [ - 'user_id' => (int)$userId, - 'offset' => (int)$offset, - 'limit' => (int)$limit, + 'user_id' => (int) $userId, + 'offset' => (int) $offset, + 'limit' => (int) $limit, ])); } @@ -409,23 +571,82 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) * @param string $url HTTPS url to send updates to. Use an empty string to remove webhook integration * @param \CURLFile|string $certificate Upload your public key certificate * so that the root certificate in use can be checked + * @param string|null $ipAddress The fixed IP address which will be used to send webhook requests + * instead of the IP address resolved through DNS + * @param int|null $maxConnections The maximum allowed number of simultaneous HTTPS connections to the webhook + * for update delivery, 1-100. Defaults to 40. Use lower values to limit + * the load on your bot's server, and higher values to increase your bot's throughput. + * @param array|string|null $allowedUpdates A JSON-serialized list of the update types you want your bot to receive. + * For example, specify [“message”, “edited_channel_post”, “callback_query”] + * to only receive updates of these types. See Update for a complete list of available update types. + * Specify an empty list to receive all update types except chat_member (default). + * If not specified, the previous setting will be used. + * Please note that this parameter doesn't affect updates created before the call to the setWebhook, + * so unwanted updates may be received for a short period of time. + * @param bool|null $dropPendingUpdates Pass True to drop all pending updates + * @param string|null $secretToken A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, + * 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. + * The header is useful to ensure that the request comes from a webhook set by you. * * @return string * - * @throws \TelegramBot\Api\Exception + * @throws Exception + */ + public function setWebhook( + $url = '', + $certificate = null, + $ipAddress = null, + $maxConnections = 40, + $allowedUpdates = null, + $dropPendingUpdates = false, + $secretToken = null + ) { + return $this->call('setWebhook', [ + 'url' => $url, + 'certificate' => $certificate, + 'ip_address' => $ipAddress, + 'max_connections' => $maxConnections, + 'allowed_updates' => \is_array($allowedUpdates) ? json_encode($allowedUpdates) : $allowedUpdates, + 'drop_pending_updates' => $dropPendingUpdates, + 'secret_token' => $secretToken + ]); + } + + /** + * Use this method to clear webhook and use getUpdates again! + * + * @param bool $dropPendingUpdates Pass True to drop all pending updates + * + * @return mixed + * + * @throws Exception + */ + public function deleteWebhook($dropPendingUpdates = false) + { + return $this->call('deleteWebhook', ['drop_pending_updates' => $dropPendingUpdates]); + } + + /** + * Use this method to get current webhook status. Requires no parameters. + * On success, returns a WebhookInfo object. If the bot is using getUpdates, + * will return an object with the url field empty. + * + * @return WebhookInfo + * @throws Exception + * @throws InvalidArgumentException */ - public function setWebhook($url = '', $certificate = null) + public function getWebhookInfo() { - return $this->call('setWebhook', ['url' => $url, 'certificate' => $certificate]); + return WebhookInfo::fromResponse($this->call('getWebhookInfo')); } /** * A simple method for testing your bot's auth token.Requires no parameters. * Returns basic information about the bot in form of a User object. * - * @return \TelegramBot\Api\Types\User - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\InvalidArgumentException + * @return User + * @throws Exception + * @throws InvalidArgumentException */ public function getMe() { @@ -445,8 +666,8 @@ public function getMe() * @param int $timeout * * @return Update[] - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\InvalidArgumentException + * @throws Exception + * @throws InvalidArgumentException */ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) { @@ -456,27 +677,27 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) 'timeout' => $timeout, ])); - if ($this->tracker instanceof Botan) { - foreach ($updates as $update) { - $this->trackUpdate($update); - } - } - return $updates; } /** * Use this method to send point on the map. On success, the sent Message is returned. * - * @param int $chatId + * @param int|string $chatId * @param float $latitude * @param float $longitude * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param null|int $livePeriod + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\Exception + * @throws Exception */ public function sendLocation( $chatId, @@ -484,18 +705,110 @@ public function sendLocation( $longitude, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $livePeriod = null, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendLocation', [ 'chat_id' => $chatId, 'latitude' => $latitude, 'longitude' => $longitude, - 'reply_to_message_id' => $replyToMessageId, + 'live_period' => $livePeriod, + 'message_thread_id' => $messageThreadId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } + /** + * Use this method to edit live location messages sent by the bot or via the bot (for inline bots). + * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. + * + * @param int|string $chatId + * @param int $messageId + * @param string $inlineMessageId + * @param float $latitude + * @param float $longitude + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * + * @return Message|true + * + * @throws Exception + */ + public function editMessageLiveLocation( + $chatId, + $messageId, + $inlineMessageId, + $latitude, + $longitude, + $replyMarkup = null + ) { + $response = $this->call('editMessageLiveLocation', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'inline_message_id' => $inlineMessageId, + 'latitude' => $latitude, + 'longitude' => $longitude, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); + } + + /** + * Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before + * live_period expires. + * On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned. + * + * @param int|string $chatId + * @param int $messageId + * @param string $inlineMessageId + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * + * @return Message|true + * + * @throws Exception + */ + public function stopMessageLiveLocation( + $chatId, + $messageId, + $inlineMessageId, + $replyMarkup = null + ) { + $response = $this->call('stopMessageLiveLocation', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'inline_message_id' => $inlineMessageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); + } + /** * Use this method to send information about a venue. On success, the sent Message is returned. * @@ -506,11 +819,15 @@ public function sendLocation( * @param string $address * @param string|null $foursquareId * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws Exception */ public function sendVenue( $chatId, @@ -521,8 +838,25 @@ public function sendVenue( $foursquareId = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendVenue', [ 'chat_id' => $chatId, 'latitude' => $latitude, @@ -530,9 +864,11 @@ public function sendVenue( 'title' => $title, 'address' => $address, 'foursquare_id' => $foursquareId, - 'reply_to_message_id' => $replyToMessageId, + 'message_thread_id' => $messageThreadId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -542,122 +878,502 @@ public function sendVenue( * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $sticker * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @param bool $disableNotification + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param bool $protectContent Protects the contents of the sent message from forwarding and saving + * @param bool $allowSendingWithoutReply Pass True if the message should be sent even if the specified replied-to message is not found + * @param string|null $messageThreadId + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendSticker( $chatId, $sticker, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $protectContent = false, + $allowSendingWithoutReply = false, + $messageThreadId = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendSticker', [ 'chat_id' => $chatId, 'sticker' => $sticker, - 'reply_to_message_id' => $replyToMessageId, + 'message_thread_id' => $messageThreadId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } /** - * Use this method to send video files, - * Telegram clients support mp4 videos (other formats may be sent as Document). - * On success, the sent Message is returned. - * - * @param int|string $chatId chat_id or @channel_name - * @param \CURLFile|string $video - * @param int|null $duration - * @param string|null $caption - * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @param bool $disableNotification - * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @param string $name Name of the sticker set + * @return StickerSet + * @throws InvalidArgumentException + * @throws Exception */ - public function sendVideo( - $chatId, - $video, - $duration = null, - $caption = null, - $replyToMessageId = null, - $replyMarkup = null, - $disableNotification = false - ) { - return Message::fromResponse($this->call('sendVideo', [ - 'chat_id' => $chatId, - 'video' => $video, - 'duration' => $duration, - 'caption' => $caption, - 'reply_to_message_id' => $replyToMessageId, - 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + public function getStickerSet($name) + { + return StickerSet::fromResponse($this->call('getStickerSet', [ + 'name' => $name, ])); } /** - * Use this method to send audio files, - * if you want Telegram clients to display the file as a playable voice message. - * For this to work, your audio must be in an .ogg file encoded with OPUS - * (other formats may be sent as Audio or Document). - * On success, the sent Message is returned. - * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. - * - * @param int|string $chatId chat_id or @channel_name - * @param \CURLFile|string $voice - * @param int|null $duration - * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @param bool $disableNotification + * @param array[] $customEmojiIds List of custom emoji identifiers. + * At most 200 custom emoji identifiers can be specified. + * @return StickerSet + * @throws InvalidArgumentException + * @throws Exception * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @author bernard-ng */ - public function sendVoice( - $chatId, - $voice, - $duration = null, - $replyToMessageId = null, - $replyMarkup = null, - $disableNotification = false - ) { - return Message::fromResponse($this->call('sendVoice', [ - 'chat_id' => $chatId, - 'voice' => $voice, - 'duration' => $duration, - 'reply_to_message_id' => $replyToMessageId, - 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + public function getCustomEmojiStickers($customEmojiIds = []) + { + return StickerSet::fromResponse($this->call('getCustomEmojiStickers', [ + 'custom_emoji_ids' => $customEmojiIds, ])); } /** - * Use this method to forward messages of any kind. On success, the sent Message is returned. + * Use this method to create a new sticker set owned by a user. + * The bot will be able to edit the sticker set thus created. + * You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. + * Returns True on success. * - * @param int|string $chatId chat_id or @channel_name - * @param int $fromChatId - * @param int $messageId - * @param bool $disableNotification + * @param int $userId User identifier of created sticker set owner + * @param string $pngSticker PNG image with the sticker, must be up to 512 kilobytes in size, + * dimensions must not exceed 512px, and either width or height must be exactly 512px. + * + * @return File * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @throws InvalidArgumentException + * @throws Exception */ - public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotification = false) + public function uploadStickerFile($userId, $pngSticker) { - return Message::fromResponse($this->call('forwardMessage', [ - 'chat_id' => $chatId, - 'from_chat_id' => $fromChatId, - 'message_id' => (int)$messageId, - 'disable_notification' => (bool)$disableNotification, + return File::fromResponse($this->call('uploadStickerFile', [ + 'user_id' => $userId, + 'png_sticker' => $pngSticker, + ])); + } + + /** + * Use this method to create a new sticker set owned by a user. + * The bot will be able to edit the sticker set thus created. + * You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. Returns True on success. + * + * @param int $userId User identifier of created sticker set owner + * @param string $name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). + * Can contain only english letters, digits and underscores. Must begin with a letter, + * can't contain consecutive underscores and must end in “_by_”. + * is case insensitive. 1-64 characters. + * @param string $title Sticker set title, 1-64 characters + * @param string $pngSticker PNG image with the sticker, must be up to 512 kilobytes in size, + * dimensions must not exceed 512px, and either width or height must be exactly 512px. + * Pass a file_id as a String to send a file that already exists on the Telegram servers, + * pass an HTTP URL as a String for Telegram to get a file from the Internet, + * or upload a new one using multipart/form-data. + * @param string $tgsSticker TGS animation with the sticker, uploaded using multipart/form-data. + * See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements + * @param string $webmSticker WebP animation with the sticker, uploaded using multipart/form-data. + * See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements + * @param string $stickerType Sticker type, one of “png”, “tgs”, or “webp” + * @param string $emojis One or more emoji corresponding to the sticker + * @param MaskPosition|null $maskPosition A JSON-serialized object for position where the mask should be placed on faces + * @param array $attachments Attachments to use in attach:// + * + * @throws InvalidArgumentException + * @throws Exception + * + * @return bool + * + * @author bernard-ng + */ + public function createNewStickerSet( + $userId, + $name, + $title, + $emojis, + $pngSticker, + $tgsSticker = null, + $webmSticker = null, + $stickerType = null, + $maskPosition = null, + $attachments = [] + ) { + return $this->call('createNewStickerSet', [ + 'user_id' => $userId, + 'name' => $name, + 'title' => $title, + 'png_sticker' => $pngSticker, + 'tgs_sticker' => $tgsSticker, + 'webm_sticker' => $webmSticker, + 'sticker_type' => $stickerType, + 'emojis' => $emojis, + 'mask_position' => is_null($maskPosition) ? $maskPosition : $maskPosition->toJson(), + ] + $attachments); + } + + /** + * Use this method to add a new sticker to a set created by the bot. + * You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. + * Animated stickers can be added to animated sticker sets and only to them. + * Animated sticker sets can have up to 50 stickers. + * Static sticker sets can have up to 120 stickers. Returns True on success. + * + * @param string $userId + * @param string $name + * @param string $emojis + * @param string $pngSticker + * @param string|null $tgsSticker + * @param string|null $webmSticker + * @param MaskPosition|null $maskPosition + * @param array $attachments Attachments to use in attach:// + * + * @return bool + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function addStickerToSet( + $userId, + $name, + $emojis, + $pngSticker, + $tgsSticker = null, + $webmSticker = null, + $maskPosition = null, + $attachments = [] + ) { + return $this->call('addStickerToSet', [ + 'user_id' => $userId, + 'name' => $name, + 'png_sticker' => $pngSticker, + 'tgs_sticker' => $tgsSticker, + 'webm_sticker' => $webmSticker, + 'emojis' => $emojis, + 'mask_position' => is_null($maskPosition) ? $maskPosition : $maskPosition->toJson(), + ] + $attachments); + } + + /** + * Use this method to move a sticker in a set created by the bot to a specific position. + * Returns True on success. + * + * @param string $sticker File identifier of the sticker + * @param int $position New sticker position in the set, zero-based + * + * @return bool + * + * @throws InvalidArgumentException + * @throws Exception + */ + public function setStickerPositionInSet($sticker, $position) + { + return $this->call('setStickerPositionInSet', [ + 'sticker' => $sticker, + 'position' => $position, + ]); + } + + /** + * Use this method to delete a sticker from a set created by the bot. + * Returns True on success. + * + * @param string $name Sticker set name + * @param string $userId User identifier of sticker set owner + * @param File|null $thumbnail A PNG image with the thumbnail, + * must be up to 128 kilobytes in size and have width and height exactly 100px, + * or a TGS animation with the thumbnail up to 32 kilobytes in size + * + * @return bool + * + * @throws InvalidArgumentException + * @throws Exception + */ + public function setStickerSetThumbnail($name, $userId, $thumbnail = null) + { + return $this->call('setStickerSetThumb', [ + 'name' => $name, + 'user_id' => $userId, + 'thumbnail' => $thumbnail, + ]); + } + + /** + * @deprecated Use setStickerSetThumbnail + * + * Use this method to delete a sticker from a set created by the bot. + * Returns True on success. + * + * @param string $name Sticker set name + * @param string $userId User identifier of sticker set owner + * @param File|null $thumb A PNG image with the thumbnail, + * must be up to 128 kilobytes in size and have width and height exactly 100px, + * or a TGS animation with the thumbnail up to 32 kilobytes in size + * + * @return bool + * + * @throws InvalidArgumentException + * @throws Exception + */ + public function setStickerSetThumb($name, $userId, $thumb = null) + { + return $this->setStickerSetThumbnail($name, $userId, $thumb); + } + + /** + * Use this method to send video files, + * Telegram clients support mp4 videos (other formats may be sent as Document). + * On success, the sent Message is returned. + * + * @param int|string $chatId chat_id or @channel_name + * @param \CURLFile|string $video + * @param int|null $duration + * @param string|null $caption + * @param int|null $replyToMessageId + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * @param bool $disableNotification + * @param bool $supportsStreaming Pass True, if the uploaded video is suitable for streaming + * @param string|null $parseMode + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message + * @throws InvalidArgumentException + * @throws Exception + */ + public function sendVideo( + $chatId, + $video, + $duration = null, + $caption = null, + $replyToMessageId = null, + $replyMarkup = null, + $disableNotification = false, + $supportsStreaming = false, + $parseMode = null, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $thumbnail = null, + $replyParameters = null + ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + return Message::fromResponse($this->call('sendVideo', [ + 'chat_id' => $chatId, + 'video' => $video, + 'duration' => $duration, + 'caption' => $caption, + 'message_thread_id' => $messageThreadId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'disable_notification' => (bool) $disableNotification, + 'supports_streaming' => (bool) $supportsStreaming, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() + ])); + } + + /** + * Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound), + * On success, the sent Message is returned. + * Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. + * + * @param int|string $chatId chat_id or @channel_name + * @param \CURLFile|string $animation + * @param int|null $duration + * @param string|null $caption + * @param int|null $replyToMessageId + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * @param bool $disableNotification + * @param string|null $parseMode, + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message + * @throws InvalidArgumentException + * @throws Exception + */ + public function sendAnimation( + $chatId, + $animation, + $duration = null, + $caption = null, + $replyToMessageId = null, + $replyMarkup = null, + $disableNotification = false, + $parseMode = null, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $thumbnail = null, + $replyParameters = null + ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + return Message::fromResponse($this->call('sendAnimation', [ + 'chat_id' => $chatId, + 'animation' => $animation, + 'duration' => $duration, + 'caption' => $caption, + 'message_thread_id' => $messageThreadId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() + ])); + } + + /** + * Use this method to send audio files, + * if you want Telegram clients to display the file as a playable voice message. + * For this to work, your audio must be in an .ogg file encoded with OPUS + * (other formats may be sent as Audio or Document). + * On success, the sent Message is returned. + * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. + * + * @param int|string $chatId chat_id or @channel_name + * @param \CURLFile|string $voice + * @param string $caption Voice message caption, 0-1024 characters after entities parsing + * @param int|null $duration + * @param int|null $replyToMessageId + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * @param bool $disableNotification + * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified + * replied-to message is not found + * @param string|null $parseMode + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message + * @throws InvalidArgumentException + * @throws Exception + */ + public function sendVoice( + $chatId, + $voice, + $caption = null, + $duration = null, + $replyToMessageId = null, + $replyMarkup = null, + $disableNotification = false, + $allowSendingWithoutReply = false, + $parseMode = null, + $messageThreadId = null, + $protectContent = null, + $replyParameters = null + ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + return Message::fromResponse($this->call('sendVoice', [ + 'chat_id' => $chatId, + 'voice' => $voice, + 'caption' => $caption, + 'duration' => $duration, + 'message_thread_id' => $messageThreadId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() + ])); + } + + /** + * Use this method to forward messages of any kind. Service messages can't be forwarded. + * On success, the sent Message is returned. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) + * @param string $messageId Message identifier in the chat specified in from_chat_id + * @param bool $protectContent Protects the contents of the forwarded message from forwarding and saving + * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * + * @return Message + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function forwardMessage( + $chatId, + $fromChatId, + $messageId, + $protectContent = false, + $disableNotification = false, + $messageThreadId = null + ) { + return Message::fromResponse($this->call('forwardMessage', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_id' => $messageId, + 'message_thread_id' => $messageThreadId, + 'protect_content' => $protectContent, + 'disable_notification' => (bool) $disableNotification, ])); } @@ -673,22 +1389,27 @@ public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotific * For this to work, the audio must be in an .ogg file encoded with OPUS. * This behavior will be phased out in the future. For sending voice messages, use the sendVoice method instead. * - * @deprecated since 20th February. Removed backward compatibility from the method sendAudio. - * Voice messages now must be sent using the method sendVoice. - * There is no more need to specify a non-empty title or performer while sending the audio by file_id. - * * @param int|string $chatId chat_id or @channel_name * @param \CURLFile|string $audio * @param int|null $duration * @param string|null $performer * @param string|null $title * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param string|null $parseMode + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message + * @throws InvalidArgumentException + * @throws Exception + * @deprecated since 20th February. Removed backward compatibility from the method sendAudio. + * Voice messages now must be sent using the method sendVoice. + * There is no more need to specify a non-empty title or performer while sending the audio by file_id. * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception */ public function sendAudio( $chatId, @@ -698,17 +1419,38 @@ public function sendAudio( $title = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $parseMode = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $thumbnail = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendAudio', [ 'chat_id' => $chatId, 'audio' => $audio, 'duration' => $duration, 'performer' => $performer, 'title' => $title, - 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -719,12 +1461,17 @@ public function sendAudio( * @param \CURLFile|string $photo * @param string|null $caption * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param string|null $parseMode + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendPhoto( $chatId, @@ -732,15 +1479,36 @@ public function sendPhoto( $caption = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $parseMode = null, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendPhoto', [ 'chat_id' => $chatId, 'photo' => $photo, 'caption' => $caption, - 'reply_to_message_id' => $replyToMessageId, + 'message_thread_id' => $messageThreadId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -749,15 +1517,21 @@ public function sendPhoto( * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. * * @param int|string $chatId chat_id or @channel_name - * @param \CURLFile|string $document + * @param \CURLFile|\CURLStringFile|string $document * @param string|null $caption * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param string|null $parseMode + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message + * @throws InvalidArgumentException + * @throws Exception */ public function sendDocument( $chatId, @@ -765,15 +1539,38 @@ public function sendDocument( $caption = null, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $parseMode = null, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $thumbnail = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendDocument', [ 'chat_id' => $chatId, 'document' => $document, 'caption' => $caption, - 'reply_to_message_id' => $replyToMessageId, + 'message_thread_id' => $messageThreadId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'parse_mode' => $parseMode, + 'protect_content' => (bool) $protectContent, + 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -786,39 +1583,17 @@ public function sendDocument( * It is guaranteed that the link will be valid for at least 1 hour. * When the link expires, a new one can be requested by calling getFile again. * - * @param $fileId + * @param string $fileId * - * @return \TelegramBot\Api\Types\File - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return File + * @throws InvalidArgumentException + * @throws Exception */ public function getFile($fileId) { return File::fromResponse($this->call('getFile', ['file_id' => $fileId])); } - /** - * Get file contents via cURL - * - * @param $fileId - * - * @return string - * - * @throws \TelegramBot\Api\HttpException - */ - public function downloadFile($fileId) - { - $file = $this->getFile($fileId); - $options = [ - CURLOPT_HEADER => 0, - CURLOPT_HTTPGET => 1, - CURLOPT_RETURNTRANSFER => 1, - CURLOPT_URL => $this->getFileUrl().'/'.$file->getFilePath(), - ]; - - return $this->executeCurl($options); - } - /** * Use this method to send answers to an inline query. On success, True is returned. * No more than 50 results per query are allowed. @@ -843,10 +1618,19 @@ public function answerInlineQuery( $switchPmText = null, $switchPmParameter = null ) { - $results = array_map(function ($item) { - /* @var AbstractInlineQueryResult $item */ - return json_decode($item->toJson(), true); - }, $results); + $results = array_map( + /** + * @param AbstractInlineQueryResult $item + * @return array + */ + function ($item) { + /** @var array $array */ + $array = $item->toJson(true); + + return $array; + }, + $results + ); return $this->call('answerInlineQuery', [ 'inline_query_id' => $inlineQueryId, @@ -866,16 +1650,19 @@ public function answerInlineQuery( * The bot must be an administrator in the group for this to work. Returns True on success. * * @param int|string $chatId Unique identifier for the target group - * or username of the target supergroup (in the format @supergroupusername) + * or username of the target supergroup (in the format @supergroupusername) * @param int $userId Unique identifier of the target user * @param null|int $untilDate Date when the user will be unbanned, unix time. * If user is banned for more than 366 days or less than 30 seconds from the current time * they are considered to be banned forever * * @return bool + * @throws Exception */ public function kickChatMember($chatId, $userId, $untilDate = null) { + @trigger_error(sprintf('Method "%s::%s" is deprecated. Use "banChatMember"', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + return $this->call('kickChatMember', [ 'chat_id' => $chatId, 'user_id' => $userId, @@ -883,16 +1670,46 @@ public function kickChatMember($chatId, $userId, $untilDate = null) ]); } + /** + * Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, + * the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Returns True on success. + * + * @param int|string $chatId Unique identifier for the target group or username of the + * target supergroup or channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * @param null|int $untilDate Date when the user will be unbanned, unix time. + * If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. + * Applied for supergroups and channels only. + * @param bool|null $revokeMessages Pass True to delete all messages from the chat for the user that is being removed. + * If False, the user will be able to see messages in the group that were sent before the user was removed. + * Always True for supergroups and channels. + * + * @return bool + * @throws Exception + */ + public function banChatMember($chatId, $userId, $untilDate = null, $revokeMessages = null) + { + return $this->call('banChatMember', [ + 'chat_id' => $chatId, + 'user_id' => $userId, + 'until_date' => $untilDate, + 'revoke_messages' => $revokeMessages, + ]); + } + /** * Use this method to unban a previously kicked user in a supergroup. * The user will not return to the group automatically, but will be able to join via link, etc. * The bot must be an administrator in the group for this to work. Returns True on success. * * @param int|string $chatId Unique identifier for the target group - * or username of the target supergroup (in the format @supergroupusername) + * or username of the target supergroup (in the format @supergroupusername) * @param int $userId Unique identifier of the target user * * @return bool + * @throws Exception */ public function unbanChatMember($chatId, $userId) { @@ -906,34 +1723,83 @@ public function unbanChatMember($chatId, $userId) * Use this method to send answers to callback queries sent from inline keyboards. * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. * - * @param $callbackQueryId - * @param null $text + * @param string $callbackQueryId + * @param string|null $text * @param bool $showAlert + * @param string|null $url + * @param int $cacheTime * * @return bool + * @throws Exception */ - public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false) + public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false, $url = null, $cacheTime = 0) { return $this->call('answerCallbackQuery', [ 'callback_query_id' => $callbackQueryId, 'text' => $text, - 'show_alert' => (bool)$showAlert, + 'show_alert' => (bool) $showAlert, + 'url' => $url, + 'cache_time' => $cacheTime ]); } - /** - * Use this method to edit text messages sent by the bot or via the bot + * Use this method to change the list of the bot's commands. Returns True on success. * - * @param int|string $chatId - * @param int $messageId - * @param string $text - * @param string $inlineMessageId - * @param string|null $parseMode - * @param bool $disablePreview - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup - * @return Message - */ + * @param ArrayOfBotCommand|BotCommand[] $commands + * @param string|null $scope + * @param string|null $languageCode + * + * @return mixed + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function setMyCommands($commands, $scope = null, $languageCode = null) + { + if (!$commands instanceof ArrayOfBotCommand) { + @trigger_error(sprintf('Passing array of BotCommand to "%s::%s" is deprecated. Use %s', __CLASS__, __METHOD__, ArrayOfBotCommand::class), \E_USER_DEPRECATED); + $commands = new ArrayOfBotCommand($commands); + } + + return $this->call('setMyCommands', [ + 'commands' => $commands->toJson(), + 'scope' => $scope, + 'language_code' => $languageCode, + ]); + } + + /** + * Use this method to get the current list of the bot's commands. Requires no parameters. + * Returns Array of BotCommand on success. + * + * @return ArrayOfBotCommand + * + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function getMyCommands() + { + return ArrayOfBotCommand::fromResponse($this->call('getMyCommands')); + } + + /** + * Use this method to edit text messages sent by the bot or via the bot + * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. + * + * @param int|string $chatId + * @param int $messageId + * @param string $text + * @param string $inlineMessageId + * @param string|null $parseMode + * @param bool $disablePreview + * @param InlineKeyboardMarkup|null $replyMarkup + * @param LinkPreviewOptions|null $linkPreviewOptions Link preview generation options for the message. + * + * @return Message|true + * @throws Exception + */ public function editMessageText( $chatId, $messageId, @@ -941,9 +1807,19 @@ public function editMessageText( $parseMode = null, $disablePreview = false, $replyMarkup = null, - $inlineMessageId = null + $inlineMessageId = null, + $linkPreviewOptions = null ) { - return Message::fromResponse($this->call('editMessageText', [ + if (null === $linkPreviewOptions && false !== $disablePreview) { + @trigger_error('setting $disablePreview is now deprecated use $linkPreviewOptions instead', E_USER_DEPRECATED); + + $linkPreviewOptions = new LinkPreviewOptions(); + $linkPreviewOptions->map([ + 'is_disabled' => $disablePreview + ]); + } + + $response = $this->call('editMessageText', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'text' => $text, @@ -951,47 +1827,106 @@ public function editMessageText( 'parse_mode' => $parseMode, 'disable_web_page_preview' => $disablePreview, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ])); + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** * Use this method to edit text messages sent by the bot or via the bot + * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param int|string $chatId * @param int $messageId * @param string|null $caption - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|null $replyMarkup * @param string $inlineMessageId + * @param string|null $parseMode * - * @return \TelegramBot\Api\Types\Message - * @throws \TelegramBot\Api\InvalidArgumentException - * @throws \TelegramBot\Api\Exception + * @return Message|true + * @throws InvalidArgumentException + * @throws Exception */ public function editMessageCaption( $chatId, $messageId, $caption = null, $replyMarkup = null, - $inlineMessageId = null + $inlineMessageId = null, + $parseMode = null ) { - return Message::fromResponse($this->call('editMessageCaption', [ + $response = $this->call('editMessageCaption', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, 'caption' => $caption, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ])); + 'parse_mode' => $parseMode + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); + } + + /** + * Use this method to edit animation, audio, document, photo, or video messages. + * If a message is a part of a message album, then it can be edited only to a photo or a video. + * Otherwise, message type can be changed arbitrarily. + * When inline message is edited, new file can't be uploaded. + * Use previously uploaded file via its file_id or specify a URL. + * On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned + * + * @param string $chatId + * @param string $messageId + * @param InputMedia $media + * @param string|null $inlineMessageId + * @param InlineKeyboardMarkup|null $replyMarkup + * @param array $attachments Attachments to use in attach:// + * + * @return Message|true + * + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function editMessageMedia( + $chatId, + $messageId, + InputMedia $media, + $inlineMessageId = null, + $replyMarkup = null, + $attachments = [] + ) { + $response = $this->call('editMessageMedia', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'inline_message_id' => $inlineMessageId, + 'media' => $media->toJson(), + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ] + $attachments); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** * Use this method to edit only the reply markup of messages sent by the bot or via the bot + * On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * * @param int|string $chatId * @param int $messageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|null $replyMarkup * @param string $inlineMessageId * - * @return Message + * @return Message|true + * @throws Exception */ public function editMessageReplyMarkup( $chatId, @@ -999,12 +1934,17 @@ public function editMessageReplyMarkup( $replyMarkup = null, $inlineMessageId = null ) { - return Message::fromResponse($this->call('editMessageReplyMarkup', [ + $response = $this->call('editMessageReplyMarkup', [ 'chat_id' => $chatId, 'message_id' => $messageId, 'inline_message_id' => $inlineMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - ])); + ]); + if ($response === true) { + return true; + } + + return Message::fromResponse($response); } /** @@ -1019,6 +1959,7 @@ public function editMessageReplyMarkup( * @param int $messageId * * @return bool + * @throws Exception */ public function deleteMessage($chatId, $messageId) { @@ -1028,64 +1969,6 @@ public function deleteMessage($chatId, $messageId) ]); } - /** - * Close curl - */ - public function __destruct() - { - $this->curl && curl_close($this->curl); - } - - /** - * @return string - */ - public function getUrl() - { - return self::URL_PREFIX.$this->token; - } - - /** - * @return string - */ - public function getFileUrl() - { - return self::FILE_URL_PREFIX.$this->token; - } - - /** - * @param \TelegramBot\Api\Types\Update $update - * @param string $eventName - * - * @throws \TelegramBot\Api\Exception - */ - public function trackUpdate(Update $update, $eventName = 'Message') - { - if (!in_array($update->getUpdateId(), $this->trackedEvents)) { - $this->trackedEvents[] = $update->getUpdateId(); - - $this->track($update->getMessage(), $eventName); - - if (count($this->trackedEvents) > self::MAX_TRACKED_EVENTS) { - $this->trackedEvents = array_slice($this->trackedEvents, round(self::MAX_TRACKED_EVENTS / 4)); - } - } - } - - /** - * Wrapper for tracker - * - * @param \TelegramBot\Api\Types\Message $message - * @param string $eventName - * - * @throws \TelegramBot\Api\Exception - */ - public function track(Message $message, $eventName = 'Message') - { - if ($this->tracker instanceof Botan) { - $this->tracker->track($message, $eventName); - } - } - /** * Use this method to send invoices. On success, the sent Message is returned. * @@ -1097,6 +1980,7 @@ public function track(Message $message, $eventName = 'Message') * @param string $startParameter * @param string $currency * @param array $prices + * @param bool $isFlexible * @param string|null $photoUrl * @param int|null $photoSize * @param int|null $photoWidth @@ -1105,12 +1989,19 @@ public function track(Message $message, $eventName = 'Message') * @param bool $needPhoneNumber * @param bool $needEmail * @param bool $needShippingAddress - * @param bool $isFlexible * @param int|null $replyToMessageId - * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup * @param bool $disableNotification + * @param string|null $providerData + * @param bool $sendPhoneNumberToProvider + * @param bool $sendEmailToProvider + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. * * @return Message + * @throws Exception */ public function sendInvoice( $chatId, @@ -1132,8 +2023,28 @@ public function sendInvoice( $needShippingAddress = false, $replyToMessageId = null, $replyMarkup = null, - $disableNotification = false + $disableNotification = false, + $providerData = null, + $sendPhoneNumberToProvider = false, + $sendEmailToProvider = false, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $replyParameters = null ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + return Message::fromResponse($this->call('sendInvoice', [ 'chat_id' => $chatId, 'title' => $title, @@ -1152,9 +2063,14 @@ public function sendInvoice( 'need_phone_number' => $needPhoneNumber, 'need_email' => $needEmail, 'need_shipping_address' => $needShippingAddress, - 'reply_to_message_id' => $replyToMessageId, + 'message_thread_id' => $messageThreadId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), - 'disable_notification' => (bool)$disableNotification, + 'disable_notification' => (bool) $disableNotification, + 'provider_data' => $providerData, + 'send_phone_number_to_provider' => (bool) $sendPhoneNumberToProvider, + 'send_email_to_provider' => (bool) $sendEmailToProvider, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() ])); } @@ -1165,18 +2081,18 @@ public function sendInvoice( * * @param string $shippingQueryId * @param bool $ok - * @param array $shipping_options + * @param array $shippingOptions * @param null|string $errorMessage * * @return bool - * + * @throws Exception */ - public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null) + public function answerShippingQuery($shippingQueryId, $ok = true, $shippingOptions = [], $errorMessage = null) { return $this->call('answerShippingQuery', [ 'shipping_query_id' => $shippingQueryId, - 'ok' => (bool)$ok, - 'shipping_options' => json_encode($shipping_options), + 'ok' => (bool) $ok, + 'shipping_options' => json_encode($shippingOptions), 'error_message' => $errorMessage ]); } @@ -1189,13 +2105,14 @@ public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_opti * @param bool $ok * @param null|string $errorMessage * - * @return mixed + * @return bool + * @throws Exception */ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null) { return $this->call('answerPreCheckoutQuery', [ 'pre_checkout_query_id' => $preCheckoutQueryId, - 'ok' => (bool)$ok, + 'ok' => (bool) $ok, 'error_message' => $errorMessage ]); } @@ -1206,11 +2123,11 @@ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMe * Pass True for all boolean parameters to lift restrictions from a user. * * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup - * (in the format @supergroupusername) + * (in the format @supergroupusername) * @param int $userId Unique identifier of the target user * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time. - * If user is restricted for more than 366 days or less than 30 seconds from the current time, - * they are considered to be restricted forever + * If user is restricted for more than 366 days or less than 30 seconds from the current time, + * they are considered to be restricted forever * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos, * video notes and voice notes, implies can_send_messages @@ -1220,6 +2137,7 @@ public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMe * implies can_send_media_messages * * @return bool + * @throws Exception */ public function restrictChatMember( $chatId, @@ -1247,7 +2165,7 @@ public function restrictChatMember( * Pass False for all boolean parameters to demote a user. * * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup - * (in the format @supergroupusername) + * (in the format @supergroupusername) * @param int $userId Unique identifier of the target user * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only @@ -1259,8 +2177,13 @@ public function restrictChatMember( * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his * own privileges or demote administrators that he has promoted,directly or * indirectly (promoted by administrators that were appointed by him) - * + * @param bool $canManageTopics Pass True if the user is allowed to create, rename, close, and reopen forum topics, supergroups only + * @param bool $isAnonymous Pass True if the administrator's presence in the chat is hidden * @return bool + * + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException */ public function promoteChatMember( $chatId, @@ -1272,11 +2195,14 @@ public function promoteChatMember( $canInviteUsers = true, $canRestrictMembers = true, $canPinMessages = true, - $canPromoteMembers = true + $canPromoteMembers = true, + $canManageTopics = true, + $isAnonymous = false ) { return $this->call('promoteChatMember', [ 'chat_id' => $chatId, 'user_id' => $userId, + 'is_anonymous' => $isAnonymous, 'can_change_info' => $canChangeInfo, 'can_post_messages' => $canPostMessages, 'can_edit_messages' => $canEditMessages, @@ -1284,7 +2210,8 @@ public function promoteChatMember( 'can_invite_users' => $canInviteUsers, 'can_restrict_members' => $canRestrictMembers, 'can_pin_messages' => $canPinMessages, - 'can_promote_members' => $canPromoteMembers + 'can_promote_members' => $canPromoteMembers, + 'can_manage_topics' => $canManageTopics ]); } @@ -1295,6 +2222,7 @@ public function promoteChatMember( * @param string|int $chatId Unique identifier for the target chat or username of the target channel * (in the format @channelusername) * @return string + * @throws Exception */ public function exportChatInviteLink($chatId) { @@ -1303,6 +2231,117 @@ public function exportChatInviteLink($chatId) ]); } + /** + * Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat + * for this to work and must have the appropriate administrator rights. + * The link can be revoked using the method revokeChatInviteLink. + * Returns the new invite link as ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string|null $name Invite link name; 0-32 characters + * @param int|null $expireDate Point in time (Unix timestamp) when the link will expire + * @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously + * after joining the chat via this invite link; 1-99999 + * @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators. + * If True, member_limit can't be specified + * @return ChatInviteLink + * @throws Exception + */ + public function createChatInviteLink($chatId, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null) + { + return ChatInviteLink::fromResponse($this->call('createChatInviteLink', [ + 'chat_id' => $chatId, + 'name' => $name, + 'expire_date' => $expireDate, + 'member_limit' => $memberLimit, + 'creates_join_request' => $createsJoinRequest, + ])); + } + + /** + * Use this method to edit a non-primary invite link created by the bot. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Returns the edited invite link as a ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string $inviteLink The invite link to edit + * @param string|null $name Invite link name; 0-32 characters + * @param int|null $expireDate Point in time (Unix timestamp) when the link will expire + * @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously + * after joining the chat via this invite link; 1-99999 + * @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators. + * If True, member_limit can't be specified + * @return ChatInviteLink + * @throws Exception + */ + public function editChatInviteLink($chatId, $inviteLink, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null) + { + return ChatInviteLink::fromResponse($this->call('editChatInviteLink', [ + 'chat_id' => $chatId, + 'invite_link' => $inviteLink, + 'name' => $name, + 'expire_date' => $expireDate, + 'member_limit' => $memberLimit, + 'creates_join_request' => $createsJoinRequest, + ])); + } + + /** + * Use this method to revoke an invite link created by the bot. + * If the primary link is revoked, a new link is automatically generated. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Returns the revoked invite link as ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string $inviteLink The invite link to edit + * @return ChatInviteLink + * @throws Exception + */ + public function revokeChatInviteLink($chatId, $inviteLink) + { + return ChatInviteLink::fromResponse($this->call('revokeChatInviteLink', [ + 'chat_id' => $chatId, + 'invite_link' => $inviteLink, + ])); + } + + /** + * Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and + * must have the can_invite_users administrator right. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * @return bool + * @throws Exception + */ + public function approveChatJoinRequest($chatId, $userId) + { + return $this->call('approveChatJoinRequest', [ + 'chat_id' => $chatId, + 'user_id' => $userId, + ]); + } + + /** + * Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and + * must have the can_invite_users administrator right. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * @return bool + * @throws Exception + */ + public function declineChatJoinRequest($chatId, $userId) + { + return $this->call('declineChatJoinRequest', [ + 'chat_id' => $chatId, + 'user_id' => $userId, + ]); + } + /** * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -1312,6 +2351,7 @@ public function exportChatInviteLink($chatId) * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data * * @return bool + * @throws Exception */ public function setChatPhoto($chatId, $photo) { @@ -1329,6 +2369,7 @@ public function setChatPhoto($chatId, $photo) * (in the format @channelusername) * * @return bool + * @throws Exception */ public function deleteChatPhoto($chatId) { @@ -1346,6 +2387,7 @@ public function deleteChatPhoto($chatId) * @param string $title New chat title, 1-255 characters * * @return bool + * @throws Exception */ public function setChatTitle($chatId, $title) { @@ -1360,10 +2402,11 @@ public function setChatTitle($chatId, $title) * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * @param string|null $description New chat description, 0-255 characters * * @return bool + * @throws Exception */ public function setChatDescription($chatId, $description = null) { @@ -1378,11 +2421,12 @@ public function setChatDescription($chatId, $description = null) * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * @param int $messageId Identifier of a message to pin * @param bool $disableNotification * * @return bool + * @throws Exception */ public function pinChatMessage($chatId, $messageId, $disableNotification = false) { @@ -1398,14 +2442,17 @@ public function pinChatMessage($chatId, $messageId, $disableNotification = false * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) + * @param int|null $messageId Identifier of a message to pin (optional) * * @return bool + * @throws Exception */ - public function unpinChatMessage($chatId) + public function unpinChatMessage($chatId, $messageId = null) { return $this->call('unpinChatMessage', [ - 'chat_id' => $chatId + 'chat_id' => $chatId, + 'message_id' => $messageId, ]); } @@ -1414,13 +2461,14 @@ public function unpinChatMessage($chatId) * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * - * @return Chat + * @return ChatFullInfo + * @throws Exception */ public function getChat($chatId) { - return Chat::fromResponse($this->call('getChat', [ + return ChatFullInfo::fromResponse($this->call('getChat', [ 'chat_id' => $chatId ])); } @@ -1429,10 +2477,11 @@ public function getChat($chatId) * Use this method to get information about a member of a chat. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * @param int $userId * * @return ChatMember + * @throws Exception */ public function getChatMember($chatId, $userId) { @@ -1446,9 +2495,10 @@ public function getChatMember($chatId, $userId) * Use this method for your bot to leave a group, supergroup or channel. * * @param string|int $chatId Unique identifier for the target chat or username of the target channel - * (in the format @channelusername) + * (in the format @channelusername) * * @return bool + * @throws Exception */ public function leaveChat($chatId) { @@ -1456,4 +2506,725 @@ public function leaveChat($chatId) 'chat_id' => $chatId ]); } + + /** + * Use this method to get the number of members in a chat. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return int + * @throws Exception + */ + public function getChatMembersCount($chatId) + { + @trigger_error(sprintf('Method "%s::%s" is deprecated. Use "getChatMemberCount"', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + return $this->call('getChatMembersCount', [ + 'chat_id' => $chatId + ]); + } + + /** + * Use this method to get the number of members in a chat. Returns Int on success. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup or channel + * (in the format @channelusername) + * + * @return int + * @throws Exception + */ + public function getChatMemberCount($chatId) + { + return $this->call('getChatMemberCount', [ + 'chat_id' => $chatId + ]); + } + + /** + * Use this method to get a list of administrators in a chat. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * + * @return ChatMember[] + * @throws InvalidArgumentException + * @throws Exception + */ + public function getChatAdministrators($chatId) + { + return ArrayOfChatMemberEntity::fromResponse( + $this->call( + 'getChatAdministrators', + [ + 'chat_id' => $chatId + ] + ) + ); + } + + /** + * As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. + * Use this method to send video messages. + * On success, the sent Message is returned. + * + * @param int|string $chatId chat_id or @channel_name + * @param \CURLFile|string $videoNote + * @param int|null $duration + * @param int|null $length + * @param int|null $replyToMessageId + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup + * @param bool $disableNotification + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param \CURLFile|\CURLStringFile|string|null $thumbnail + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message + * @throws InvalidArgumentException + * @throws Exception + */ + public function sendVideoNote( + $chatId, + $videoNote, + $duration = null, + $length = null, + $replyToMessageId = null, + $replyMarkup = null, + $disableNotification = false, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $thumbnail = null, + $replyParameters = null + ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + return Message::fromResponse($this->call('sendVideoNote', [ + 'chat_id' => $chatId, + 'video_note' => $videoNote, + 'duration' => $duration, + 'length' => $length, + 'message_thread_id' => $messageThreadId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'thumbnail' => $thumbnail, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() + ])); + } + + /** + * Use this method to send a group of photos or videos as an album. + * On success, the sent \TelegramBot\Api\Types\Message is returned. + * + * @param int|string $chatId + * @param ArrayOfInputMedia $media + * @param bool $disableNotification + * @param int|null $replyToMessageId + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param array $attachments Attachments to use in attach:// + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message[] + * @throws Exception + */ + public function sendMediaGroup( + $chatId, + $media, + $disableNotification = false, + $replyToMessageId = null, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $attachments = [], + $replyParameters = null + ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + return ArrayOfMessages::fromResponse($this->call('sendMediaGroup', [ + 'chat_id' => $chatId, + 'media' => $media->toJson(), + 'message_thread_id' => $messageThreadId, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() + ] + $attachments)); + } + + /** + * Use this method to send a native poll. A native poll can't be sent to a private chat. + * On success, the sent \TelegramBot\Api\Types\Message is returned. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param string $question Poll question, 1-255 characters + * @param array $options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each + * @param bool $isAnonymous True, if the poll needs to be anonymous, defaults to True + * @param string|null $type Poll type, “quiz” or “regular”, defaults to “regular” + * @param bool $allowsMultipleAnswers True, if the poll allows multiple answers, + * ignored for polls in quiz mode, defaults to False + * @param string|null $correctOptionId 0-based identifier of the correct answer option, required for polls in quiz mode + * @param bool $isClosed Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. + * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param int|null $replyToMessageId If the message is a reply, ID of the original message + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, + * custom reply keyboard, instructions to remove reply + * keyboard or to force a reply from the user. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool|null $protectContent + * @param bool|null $allowSendingWithoutReply + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function sendPoll( + $chatId, + $question, + $options, + $isAnonymous = false, + $type = null, + $allowsMultipleAnswers = false, + $correctOptionId = null, + $isClosed = false, + $disableNotification = false, + $replyToMessageId = null, + $replyMarkup = null, + $messageThreadId = null, + $protectContent = null, + $allowSendingWithoutReply = null, + $replyParameters = null + ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + return Message::fromResponse($this->call('sendPoll', [ + 'chat_id' => $chatId, + 'question' => $question, + 'options' => json_encode($options), + 'is_anonymous' => (bool) $isAnonymous, + 'type' => (string) $type, + 'allows_multiple_answers' => (bool) $allowsMultipleAnswers, + 'correct_option_id' => (int) $correctOptionId, + 'is_closed' => (bool) $isClosed, + 'disable_notification' => (bool) $disableNotification, + 'message_thread_id' => $messageThreadId, + 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() + ])); + } + + /** + * Use this method to send a dice, which will have a random value from 1 to 6. + * On success, the sent Message is returned. (Yes, we're aware of the “proper” singular of die. + * But it's awkward, and we decided to help it change. One dice at a time!) + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel + * (in the format @channelusername) + * @param string $emoji Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, + * “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and + * values 1-64 for “🎰”. Defaults to “🎲 + * @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound. + * @param string|null $replyToMessageId If the message is a reply, ID of the original message + * @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to + * message is not found, + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard, + * custom reply keyboard, instructions to remove reply + * keyboard or to force a reply from the user. + * @param int|null $messageThreadId + * @param bool|null $protectContent + * @param ReplyParameters|null $replyParameters Description of the message to reply to. + * + * @return Message + * @throws Exception + * @throws HttpException + * @throws InvalidJsonException + */ + public function sendDice( + $chatId, + $emoji, + $disableNotification = false, + $replyToMessageId = null, + $allowSendingWithoutReply = false, + $replyMarkup = null, + $messageThreadId = null, + $protectContent = null, + $replyParameters = null + ) { + if (null !== $replyToMessageId || null !== $allowSendingWithoutReply) { + @trigger_error( + 'setting $replyToMessageId or $allowSendingWithoutReply is now deprecated use $replyParameters instead', + E_USER_DEPRECATED + ); + + $replyParameters = new ReplyParameters(); + $replyParameters->map([ + 'message_id' => $replyToMessageId, + 'allow_sending_without_reply' => (bool) $allowSendingWithoutReply + ]); + } + + return Message::fromResponse($this->call('sendDice', [ + 'chat_id' => $chatId, + 'emoji' => $emoji, + 'disable_notification' => (bool) $disableNotification, + 'message_thread_id' => $messageThreadId, + 'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(), + 'protect_content' => (bool) $protectContent, + 'reply_parameters' => is_null($replyParameters) ? $replyParameters : $replyParameters->toJson() + ])); + } + + /** + * Use this method to stop a poll which was sent by the bot. + * On success, the stopped \TelegramBot\Api\Types\Poll with the final results is returned. + * + * @param int|string $chatId + * @param int $messageId + * @param InlineKeyboardMarkup|null $replyMarkup + * @return Poll + * @throws InvalidArgumentException + * @throws Exception + */ + public function stopPoll( + $chatId, + $messageId, + $replyMarkup = null + ) { + return Poll::fromResponse($this->call('stopPoll', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(), + ])); + } + + /** + * Use this method to create a topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work + * and must have the can_manage_topics administrator rights. + * Returns information about the created topic as a ForumTopic object. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param string $name Topic name, 1-128 characters + * @param int $iconColor Color of the topic icon in RGB format. + * Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), + * 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F) + * @param int|null $iconCustomEmojiId Unique identifier of the custom emoji shown as the topic icon. + * Use getForumTopicIconStickers to get all allowed custom emoji identifiers. + * + * @return ForumTopic + * + * @throws Exception + * + * @author bernard-ng + */ + public function createForumTopic( + $chatId, + $name, + $iconColor, + $iconCustomEmojiId = null + ) { + return ForumTopic::fromResponse($this->call('createForumTopic', [ + 'chat_id' => $chatId, + 'name' => $name, + 'icon_color' => $iconColor, + 'icon_custom_emoji_id' => $iconCustomEmojiId, + ])); + } + + /** + * Use this method to edit name and icon of a topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, + * unless it is the creator of the topic. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * @param string $name Topic name, 1-128 characters + * @param int|null $iconCustomEmojiId Unique identifier of the custom emoji shown as the topic icon. + * Use getForumTopicIconStickers to get all allowed custom emoji identifiers. + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function editForumTopic( + $chatId, + $messageThreadId, + $name, + $iconCustomEmojiId = null + ) { + return $this->call('editForumTopic', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + 'name' => $name, + 'icon_custom_emoji_id' => $iconCustomEmojiId, + ]); + } + + /** + * Use this method to delete a topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, + * unless it is the creator of the topic. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function closeForumTopic($chatId, $messageThreadId) + { + return $this->call('closeForumTopic', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + ]); + } + + /** + * Use this method to reopen a closed topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, + * unless it is the creator of the topic. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function reopenForumTopic($chatId, $messageThreadId) + { + return $this->call('reopenForumTopic', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + ]); + } + + /** + * Use this method to delete a forum topic along with all its messages in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. + * Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function deleteForumTopic($chatId, $messageThreadId) + { + return $this->call('deleteForumTopic', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + ]); + } + + /** + * Use this method to clear the list of pinned messages in a forum topic. + * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. + * Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param int $messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function unpinAllForumTopicMessages($chatId, $messageThreadId) + { + return $this->call('unpinAllForumTopicMessages', [ + 'chat_id' => $chatId, + 'message_thread_id' => $messageThreadId, + ]); + } + + /** + * Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. + * Requires no parameters. Returns an Array of Sticker objects. + * + * @return Sticker[] + * @throws Exception + * + * @author bernard-ng + */ + public function getForumTopicIconStickers() + { + return ArrayOfSticker::fromResponse($this->call('getForumTopicIconStickers')); + } + + /** + * @param string $webAppQueryId + * @param AbstractInlineQueryResult $result + * @return SentWebAppMessage + * @throws Exception + * @throws HttpException + * @throws InvalidArgumentException + * @throws InvalidJsonException + */ + public function answerWebAppQuery($webAppQueryId, $result) + { + return SentWebAppMessage::fromResponse($this->call('answerWebAppQuery', [ + 'web_app_query_id' => $webAppQueryId, + 'result' => $result->toJson(), + ])); + } + + /** + * Enable proxy for curl requests. Empty string will disable proxy. + * + * @param string $proxyString + * @param bool $socks5 + * + * @return BotApi + */ + public function setProxy($proxyString = '', $socks5 = false) + { + @trigger_error(sprintf('Method "%s:%s" is deprecated. Manage options on HttpClient instance', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if (method_exists($this->httpClient, 'setProxy')) { + $this->httpClient->setProxy($proxyString, $socks5); + } + + return $this; + } + + /** + * Use this method to change the chosen reactions on a message. + * Service messages can't be reacted to. + * Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $messageId Identifier of the target message. + * @param ArrayOfReactionType $reaction A list of reaction types to set on the message. + * @param bool $isBig Pass `true` to set the reaction with a big animation + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function setMessageReaction($chatId, $messageId, $reaction, $isBig = false) + { + return $this->call('setMessageReaction', [ + 'chat_id' => $chatId, + 'message_id' => $messageId, + 'reaction' => $reaction, + 'is_big' => $isBig + ]); + } + + /** + * Use this method to delete multiple messages simultaneously. + * If some of the specified messages can't be found, they are skipped. + * Returns True on success. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int[] $messageIds A JSON-serialized list of 1-100 identifiers of messages to delete. See deleteMessage for limitations on which messages can be deleted + * + * @return bool + * @throws Exception + * + * @author bernard-ng + */ + public function deleteMessages($chatId, $messageIds) + { + return $this->call('deleteMessages', [ + 'chat_id' => $chatId, + 'message_ids' => $messageIds + ]); + } + + /** + * Use this method to forward multiple messages of any kind. + * If some of the specified messages can't be found or forwarded, they are skipped. + * Service messages and messages with protected content can't be forwarded. + * Album grouping is kept for forwarded messages. + * On success, an array of MessageId of the sent messages is returned. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param string|int $fromChatId Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) + * @param int[] $messageIds A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order. + * @param bool $disableNotification Sends the messages silently. Users will receive a notification with no sound. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool $protectContent Protects the contents of the forwarded messages from forwarding and saving + * + * @return int[] + * @throws Exception + * + * @author bernard-ng + */ + public function forwardMessages( + $chatId, + $fromChatId, + $messageIds, + $messageThreadId = null, + $disableNotification = false, + $protectContent = false + ) { + return $this->call('forwardMessages', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_ids' => $messageIds, + 'message_thread_id' => $messageThreadId, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent + ]); + } + + /** + * Use this method to copy messages of any kind. + * If some of the specified messages can't be found or copied, they are skipped. + * Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied + * + * A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. + * The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. + * + * On success, an array of MessageId of the sent messages is returned. + * + * @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param string|int $fromChatId Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) + * @param int[] $messageIds A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order. + * @param int|null $messageThreadId Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param bool $disableNotification Sends the messages silently. Users will receive a notification with no sound. + * @param bool $protectContent Protects the contents of the copied messages from forwarding and saving + * @param bool $removeCaption Pass True to copy the messages without their captions + * + * @return int[] + * @throws Exception + * + * @author bernard-ng + */ + public function copyMessages( + $chatId, + $fromChatId, + $messageIds, + $messageThreadId, + $disableNotification = false, + $protectContent = false, + $removeCaption = false + ) { + return $this->call('copyMessages', [ + 'chat_id' => $chatId, + 'from_chat_id' => $fromChatId, + 'message_ids' => $messageIds, + 'message_thread_id' => $messageThreadId, + 'disable_notification' => (bool) $disableNotification, + 'protect_content' => (bool) $protectContent, + 'remove_caption' => (bool) $removeCaption + ]); + } + + /** + * Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. + * Returns a UserChatBoosts object. + * + * @param string|int $chatId Unique identifier for the chat or username of the channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * + * @return UserChatBoosts + * @throws Exception + * + * @author bernard-ng + */ + public function getUserChatBoosts($chatId, $userId) + { + return UserChatBoosts::fromResponse($this->call('getUserChatBoosts', [ + 'chat_id' => $chatId, + 'user_id' => $userId + ])); + } + + /** + * Set an option for a cURL transfer + * + * @param int $option The CURLOPT_XXX option to set + * @param mixed $value The value to be set on option + * + * @return void + */ + public function setCurlOption($option, $value) + { + @trigger_error(sprintf('Method "%s:%s" is deprecated. Manage options on http client instance', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if (method_exists($this->httpClient, 'setOption')) { + $this->httpClient->setOption($option, $value); + } + } + + /** + * Unset an option for a cURL transfer + * + * @param int $option The CURLOPT_XXX option to unset + * + * @return void + */ + public function unsetCurlOption($option) + { + @trigger_error(sprintf('Method "%s:%s" is deprecated. Manage options on http client instance', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if (method_exists($this->httpClient, 'unsetOption')) { + $this->httpClient->unsetOption($option); + } + } + + /** + * Clean custom options + * + * @return void + */ + public function resetCurlOptions() + { + @trigger_error(sprintf('Method "%s:%s" is deprecated. Manage options on http client instance', __CLASS__, __METHOD__), \E_USER_DEPRECATED); + + if (method_exists($this->httpClient, 'resetOptions')) { + $this->httpClient->resetOptions(); + } + } } diff --git a/src/Botan.php b/src/Botan.php deleted file mode 100644 index 1abb17fa..00000000 --- a/src/Botan.php +++ /dev/null @@ -1,91 +0,0 @@ -token = $token; - $this->curl = curl_init(); - } - - /** - * Event tracking - * - * @param \TelegramBot\Api\Types\Message $message - * @param string $eventName - * - * @throws \TelegramBot\Api\Exception - * @throws \TelegramBot\Api\HttpException - */ - public function track(Message $message, $eventName = 'Message') - { - $uid = $message->getFrom()->getId(); - - $options = [ - CURLOPT_URL => self::BASE_URL . "?token={$this->token}&uid={$uid}&name={$eventName}", - CURLOPT_RETURNTRANSFER => true, - CURLOPT_POST => true, - CURLOPT_HTTPHEADER => [ - 'Content-Type: application/json' - ], - CURLOPT_POSTFIELDS => $message->toJson() - ]; - - curl_setopt_array($this->curl, $options); - $result = BotApi::jsonValidate(curl_exec($this->curl), true); - - BotApi::curlValidate($this->curl); - - if ($result['status'] !== 'accepted') { - throw new Exception('Error Processing Request'); - } - } - - /** - * Destructor. Close curl - */ - public function __destruct() - { - $this->curl && curl_close($this->curl); - } -} diff --git a/src/Client.php b/src/Client.php index 57fe0b14..5109cfba 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,12 +5,19 @@ use Closure; use ReflectionFunction; use TelegramBot\Api\Events\EventCollection; +use TelegramBot\Api\Http\HttpClientInterface; use TelegramBot\Api\Types\Update; +use TelegramBot\Api\Types\Message; +use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; +use TelegramBot\Api\Types\ReplyKeyboardRemove; +use TelegramBot\Api\Types\ForceReply; +use TelegramBot\Api\Types\ReplyKeyboardMarkup; /** * Class Client * * @package TelegramBot\Api + * @method Message editMessageText(string $chatId, int $messageId, string $text, string $parseMode = null, bool $disablePreview = false, ReplyKeyboardMarkup|ForceReply|ReplyKeyboardRemove|InlineKeyboardMarkup|null $replyMarkup = null, string $inlineMessageId = null) */ class Client { @@ -33,12 +40,13 @@ class Client * Client constructor * * @param string $token Telegram Bot API token - * @param string|null $trackerToken Yandex AppMetrica application api_key + * @param HttpClientInterface|null $httpClient + * @param string|null $endpoint */ - public function __construct($token, $trackerToken = null) + public function __construct($token, ?HttpClientInterface $httpClient = null, $endpoint = null) { - $this->api = new BotApi($token); - $this->events = new EventCollection($trackerToken); + $this->api = new BotApi($token, $httpClient, $endpoint); + $this->events = new EventCollection(); } /** @@ -54,41 +62,65 @@ public function command($name, Closure $action) return $this->on(self::getEvent($action), self::getChecker($name)); } + /** + * @return self + */ public function editedMessage(Closure $action) { return $this->on(self::getEditedMessageEvent($action), self::getEditedMessageChecker()); } + /** + * @return self + */ public function callbackQuery(Closure $action) { return $this->on(self::getCallbackQueryEvent($action), self::getCallbackQueryChecker()); } + /** + * @return self + */ public function channelPost(Closure $action) { return $this->on(self::getChannelPostEvent($action), self::getChannelPostChecker()); } + /** + * @return self + */ public function editedChannelPost(Closure $action) { return $this->on(self::getEditedChannelPostEvent($action), self::getEditedChannelPostChecker()); } + /** + * @return self + */ public function inlineQuery(Closure $action) { return $this->on(self::getInlineQueryEvent($action), self::getInlineQueryChecker()); } + /** + * @return self + */ public function chosenInlineResult(Closure $action) { return $this->on(self::getChosenInlineResultEvent($action), self::getChosenInlineResultChecker()); } + /** + * @return self + */ public function shippingQuery(Closure $action) { return $this->on(self::getShippingQueryEvent($action), self::getShippingQueryChecker()); } + /** + * @return self + */ public function preCheckoutQuery(Closure $action) { return $this->on(self::getPreCheckoutQueryEvent($action), self::getPreCheckoutQueryChecker()); @@ -103,7 +135,7 @@ public function preCheckoutQuery(Closure $action) * * @return \TelegramBot\Api\Client */ - public function on(Closure $event, Closure $checker = null) + public function on(Closure $event, ?Closure $checker = null) { $this->events->add($event, $checker); @@ -114,6 +146,8 @@ public function on(Closure $event, Closure $checker = null) * Handle updates * * @param Update[] $updates + * + * @return void */ public function handle(array $updates) { @@ -126,16 +160,20 @@ public function handle(array $updates) /** * Webhook handler * - * @return array + * @return void * @throws \TelegramBot\Api\InvalidJsonException */ public function run() { - if ($data = BotApi::jsonValidate($this->getRawBody(), true)) { + if ($data = BotApi::jsonValidate((string) $this->getRawBody(), true)) { + /** @var array $data */ $this->handle([Update::fromResponse($data)]); } } + /** + * @return false|string + */ public function getRawBody() { return file_get_contents('php://input'); @@ -156,7 +194,7 @@ protected static function getEvent(Closure $action) return true; } - preg_match(self::REGEXP, $message->getText(), $matches); + preg_match(self::REGEXP, (string) $message->getText(), $matches); if (isset($matches[3]) && !empty($matches[3])) { $parameters = str_getcsv($matches[3], chr(32)); @@ -176,6 +214,9 @@ protected static function getEvent(Closure $action) }; } + /** + * @return Closure + */ protected static function getEditedMessageEvent(Closure $action) { return function (Update $update) use ($action) { @@ -189,6 +230,11 @@ protected static function getEditedMessageEvent(Closure $action) }; } + /** + * @return Closure + * + * @psalm-return Closure(Update):bool + */ protected static function getChannelPostEvent(Closure $action) { return function (Update $update) use ($action) { @@ -202,6 +248,9 @@ protected static function getChannelPostEvent(Closure $action) }; } + /** + * @return Closure + */ protected static function getCallbackQueryEvent(Closure $action) { return function (Update $update) use ($action) { @@ -215,6 +264,11 @@ protected static function getCallbackQueryEvent(Closure $action) }; } + /** + * @return Closure + * + * @psalm-return Closure(Update):bool + */ protected static function getEditedChannelPostEvent(Closure $action) { return function (Update $update) use ($action) { @@ -228,6 +282,9 @@ protected static function getEditedChannelPostEvent(Closure $action) }; } + /** + * @return Closure + */ protected static function getInlineQueryEvent(Closure $action) { return function (Update $update) use ($action) { @@ -241,6 +298,11 @@ protected static function getInlineQueryEvent(Closure $action) }; } + /** + * @return Closure + * + * @psalm-return Closure(Update):bool + */ protected static function getChosenInlineResultEvent(Closure $action) { return function (Update $update) use ($action) { @@ -254,6 +316,9 @@ protected static function getChosenInlineResultEvent(Closure $action) }; } + /** + * @return Closure + */ protected static function getShippingQueryEvent(Closure $action) { return function (Update $update) use ($action) { @@ -267,6 +332,11 @@ protected static function getShippingQueryEvent(Closure $action) }; } + /** + * @return Closure + * + * @psalm-return Closure(Update):bool + */ protected static function getPreCheckoutQueryEvent(Closure $action) { return function (Update $update) use ($action) { @@ -291,11 +361,15 @@ protected static function getChecker($name) { return function (Update $update) use ($name) { $message = $update->getMessage(); - if (is_null($message) || !strlen($message->getText())) { + if (!$message) { + return false; + } + $text = $message->getText(); + if (empty($text)) { return false; } - preg_match(self::REGEXP, $message->getText(), $matches); + preg_match(self::REGEXP, $text, $matches); return !empty($matches) && $matches[1] == $name; }; @@ -397,6 +471,12 @@ protected static function getPreCheckoutQueryChecker() }; } + /** + * @param string $name + * @param array $arguments + * @return mixed + * @throws BadMethodCallException + */ public function __call($name, array $arguments) { if (method_exists($this, $name)) { diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php new file mode 100644 index 00000000..6a1b451d --- /dev/null +++ b/src/Collection/Collection.php @@ -0,0 +1,106 @@ + + */ +class Collection extends \ArrayObject +{ + /** + * @var int Max items count, if set 0 - unlimited + */ + protected $maxCount = 0; + + /** + * @param CollectionItemInterface[] $items + */ + public function __construct(array $items = []) + { + parent::__construct($items); + } + + /** + * @param CollectionItemInterface $item + * @param mixed $key + * @return void + * @throws ReachedMaxSizeException + * @throws KeyHasUseException + */ + public function addItem(CollectionItemInterface $item, $key = null) + { + if ($this->maxCount > 0 && $this->count() + 1 > $this->maxCount) { + throw new ReachedMaxSizeException("Maximum collection items count reached. Max size: {$this->maxCount}"); + } + + if ($key == null) { + $this->append($item); + } else { + if ($this->offsetExists($key)) { + throw new KeyHasUseException("Key $key already in use."); + } + $this->offsetSet($key, $item); + } + } + + /** + * @param int|string $key + * @throws KeyInvalidException + * @return void + */ + public function deleteItem($key) + { + $this->checkItemKey($key); + + $this->offsetUnset($key); + } + + /** + * @param int|string $key + * @return CollectionItemInterface + * @throws KeyInvalidException + */ + public function getItem($key) + { + $this->checkItemKey($key); + + return $this->offsetGet($key); + } + + /** + * @param bool $inner + * @return array|string + */ + public function toJson($inner = false) + { + $output = []; + foreach ($this as $item) { + $output[] = $item->toJson(true); + } + + return $inner === false ? json_encode($output) : $output; + } + + /** + * @param int $maxCount + * @return void + */ + public function setMaxCount($maxCount) + { + $this->maxCount = $maxCount; + } + + /** + * @param int|string $key + * + * @throws KeyInvalidException + * + * @return void + */ + private function checkItemKey($key) + { + if (!$this->offsetExists($key)) { + throw new KeyInvalidException("Invalid key $key."); + } + } +} diff --git a/src/Collection/CollectionItemInterface.php b/src/Collection/CollectionItemInterface.php new file mode 100644 index 00000000..bdeb9f1d --- /dev/null +++ b/src/Collection/CollectionItemInterface.php @@ -0,0 +1,12 @@ +action = $action; $this->checker = $checker; @@ -46,8 +45,6 @@ public function getChecker() } /** - * @param \TelegramBot\Api\Types\Update - * * @return mixed */ public function executeChecker(Update $message) @@ -60,16 +57,10 @@ public function executeChecker(Update $message) } /** - * @param \TelegramBot\Api\Types\Update - * * @return mixed */ public function executeAction(Update $message) { - if (is_callable($this->action)) { - return call_user_func($this->action, $message); - } - - return false; + return call_user_func($this->action, $message); } } diff --git a/src/Events/EventCollection.php b/src/Events/EventCollection.php index b11e40ca..84d98abd 100644 --- a/src/Events/EventCollection.php +++ b/src/Events/EventCollection.php @@ -3,8 +3,6 @@ namespace TelegramBot\Api\Events; use Closure; -use ReflectionFunction; -use TelegramBot\Api\Botan; use TelegramBot\Api\Types\Update; class EventCollection @@ -14,27 +12,7 @@ class EventCollection * * @var array */ - protected $events; - - /** - * Botan tracker - * - * @var \TelegramBot\Api\Botan - */ - protected $tracker; - - /** - * EventCollection constructor. - * - * @param string $trackerToken - */ - public function __construct($trackerToken = null) - { - if ($trackerToken) { - $this->tracker = new Botan($trackerToken); - } - } - + protected $events = []; /** * Add new event to collection @@ -47,25 +25,20 @@ public function __construct($trackerToken = null) public function add(Closure $event, $checker = null) { $this->events[] = !is_null($checker) ? new Event($event, $checker) - : new Event($event, function () { - }); + : new Event($event, function () {}); return $this; } /** - * @param \TelegramBot\Api\Types\Update + * @return void */ public function handle(Update $update) { foreach ($this->events as $event) { /* @var \TelegramBot\Api\Events\Event $event */ if ($event->executeChecker($update) === true) { - if (false === $event->executeAction($update)) { - if (!is_null($this->tracker)) { - $checker = new ReflectionFunction($event->getChecker()); - $this->tracker->track($update->getMessage(), $checker->getStaticVariables()['name']); - } + if ($event->executeAction($update) === false) { break; } } diff --git a/src/Exception.php b/src/Exception.php index a47a58f6..e43cf16d 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -10,5 +10,4 @@ */ class Exception extends \Exception { - } diff --git a/src/Http/AbstractHttpClient.php b/src/Http/AbstractHttpClient.php new file mode 100644 index 00000000..c98bce74 --- /dev/null +++ b/src/Http/AbstractHttpClient.php @@ -0,0 +1,37 @@ +doRequest($url, $data); + + if (!isset($response['ok']) || !$response['ok']) { + throw new Exception($response['description'], $response['error_code']); + } + + return $response['result']; + } + + public function download($url) + { + return $this->doDownload($url); + } + + /** + * @param string $url + * @param array|null $data + * @return array + */ + abstract protected function doRequest($url, ?array $data = null); + + /** + * @param string $url + * @return string + */ + abstract protected function doDownload($url); +} diff --git a/src/Http/CurlHttpClient.php b/src/Http/CurlHttpClient.php new file mode 100644 index 00000000..352e1b97 --- /dev/null +++ b/src/Http/CurlHttpClient.php @@ -0,0 +1,249 @@ + 'Continue', + 101 => 'Switching Protocols', + 102 => 'Processing', // RFC2518 + // Success 2xx + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 207 => 'Multi-Status', // RFC4918 + 208 => 'Already Reported', // RFC5842 + 226 => 'IM Used', // RFC3229 + // Redirection 3xx + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', // 1.1 + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + // 306 is deprecated but reserved + 307 => 'Temporary Redirect', + 308 => 'Permanent Redirect', // RFC7238 + // Client Error 4xx + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Payload Too Large', + 414 => 'URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Range Not Satisfiable', + 417 => 'Expectation Failed', + 422 => 'Unprocessable Entity', // RFC4918 + 423 => 'Locked', // RFC4918 + 424 => 'Failed Dependency', // RFC4918 + 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 + 426 => 'Upgrade Required', // RFC2817 + 428 => 'Precondition Required', // RFC6585 + 429 => 'Too Many Requests', // RFC6585 + 431 => 'Request Header Fields Too Large', // RFC6585 + // Server Error 5xx + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 + 507 => 'Insufficient Storage', // RFC4918 + 508 => 'Loop Detected', // RFC5842 + 510 => 'Not Extended', // RFC2774 + 511 => 'Network Authentication Required', // RFC6585 + ]; + + /** + * Default http status code + */ + const DEFAULT_STATUS_CODE = 200; + + /** + * Not Modified http status code + */ + const NOT_MODIFIED_STATUS_CODE = 304; + + /** + * CURL object + * + * @var \CurlHandle + */ + private $curl; + + /** + * @var array + */ + private $options; + + public function __construct(array $options = []) + { + $this->curl = curl_init(); + $this->options = $options; + } + + /** + * @inheritDoc + */ + protected function doRequest($url, ?array $data = null) + { + $options = $this->options + [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + ]; + + if ($data) { + $options[CURLOPT_POST] = true; + $options[CURLOPT_POSTFIELDS] = $data; + } + + return self::jsonValidate($this->execute($options)); + } + + /** + * @inheritDoc + */ + protected function doDownload($url) + { + $options = [ + CURLOPT_HEADER => false, + CURLOPT_HTTPGET => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_URL => $url, + ]; + + return $this->execute($options); + } + + /** + * @param array $options + * @return string + * @throws HttpException + */ + private function execute(array $options) + { + curl_setopt_array($this->curl, $options); + + /** @var string|false $result */ + $result = curl_exec($this->curl); + if ($result === false) { + throw new HttpException(curl_error($this->curl), curl_errno($this->curl)); + } + + self::curlValidate($this->curl, $result); + + return $result; + } + + /** + * @param string $jsonString + * @return array + * @throws InvalidJsonException + */ + private static function jsonValidate($jsonString) + { + /** @var array $json */ + $json = json_decode($jsonString, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new InvalidJsonException(json_last_error_msg(), json_last_error()); + } + + return $json; + } + + /** + * @param \CurlHandle $curl + * @param string|null $response + * @return void + * @throws HttpException + */ + private static function curlValidate($curl, $response = null) + { + $json = json_decode((string) $response, true) ?: []; + + if (($httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE)) + && !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE]) + ) { + $errorDescription = array_key_exists('description', $json) ? $json['description'] : self::$codes[$httpCode]; + $errorParameters = array_key_exists('parameters', $json) ? $json['parameters'] : []; + + throw new HttpException($errorDescription, $httpCode, null, $errorParameters); + } + } + + /** + * Enable proxy for curl requests. Empty string will disable proxy. + * + * @param string $proxyString + * @param bool $socks5 + * @return void + */ + public function setProxy($proxyString = '', $socks5 = false) + { + if (empty($proxyString)) { + unset($this->options[CURLOPT_PROXY], $this->options[CURLOPT_HTTPPROXYTUNNEL], $this->options[CURLOPT_PROXYTYPE]); + + return; + } + + $this->options[CURLOPT_PROXY] = $proxyString; + $this->options[CURLOPT_HTTPPROXYTUNNEL] = true; + + if ($socks5) { + $this->options[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5; + } + } + + /** + * @param string $option + * @param string|int|bool $value + * @return void + */ + public function setOption($option, $value) + { + $this->options[$option] = $value; + } + + /** + * @param string $option + * @return void + */ + public function unsetOption($option) + { + unset($this->options[$option]); + } + + /** + * @return void + */ + public function resetOptions() + { + $this->options = []; + } +} diff --git a/src/Http/HttpClientInterface.php b/src/Http/HttpClientInterface.php new file mode 100644 index 00000000..ed374daa --- /dev/null +++ b/src/Http/HttpClientInterface.php @@ -0,0 +1,31 @@ +http = $http; + $this->requestFactory = $requestFactory; + $this->streamFactory = $streamFactory; + } + + /** + * @inheritDoc + */ + protected function doRequest($url, ?array $data = null) + { + if ($data) { + $method = 'POST'; + $data = array_filter($data); + } else { + $method = 'GET'; + } + + $request = $this->requestFactory->createRequest($method, $url); + if ($method === 'POST') { + $multipart = false; + + /** @var array $data */ + foreach ($data as &$value) { + if ($value instanceof \CURLFile) { + $value = fopen($value->getFilename(), 'r'); + $multipart = true; + } + } + unset($value); + + if ($multipart) { + $builder = new MultipartStreamBuilder($this->streamFactory); + foreach ($data as $name => $value) { + $builder->addResource($name, $value); + } + $stream = $builder->build(); + $request = $request->withHeader('Content-Type', "multipart/form-data; boundary={$builder->getBoundary()}"); + } else { + $stream = $this->streamFactory->createStream(http_build_query($data)); + $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded'); + } + + $request = $request->withBody($stream); + } + + try { + $response = $this->http->sendRequest($request); + } catch (ClientExceptionInterface $exception) { + throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); + } + + $content = $response->getBody()->getContents(); + + $json = self::jsonValidate($content); + + if (!\in_array($response->getStatusCode(), [200, 304])) { + $errorDescription = array_key_exists('description', $json) ? $json['description'] : $response->getReasonPhrase(); + $errorParameters = array_key_exists('parameters', $json) ? $json['parameters'] : []; + + throw new HttpException($errorDescription, $response->getStatusCode(), null, $errorParameters); + } + + return $json; + } + + /** + * @inheritDoc + */ + protected function doDownload($url) + { + $request = $this->requestFactory->createRequest('GET', $url); + + try { + return $this->http->sendRequest($request)->getBody()->getContents(); + } catch (ClientExceptionInterface $exception) { + throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); + } + } + + /** + * @param string $jsonString + * @return array + * @throws InvalidJsonException + */ + private static function jsonValidate($jsonString) + { + /** @var array $json */ + $json = json_decode($jsonString, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new InvalidJsonException(json_last_error_msg(), json_last_error()); + } + + return $json; + } +} diff --git a/src/Http/SymfonyHttpClient.php b/src/Http/SymfonyHttpClient.php new file mode 100644 index 00000000..007e287f --- /dev/null +++ b/src/Http/SymfonyHttpClient.php @@ -0,0 +1,78 @@ +http = $http; + } + + /** + * @inheritDoc + */ + protected function doRequest($url, ?array $data = null) + { + $options = []; + if ($data) { + $method = 'POST'; + + $data = array_filter($data); + foreach ($data as &$value) { + if ($value instanceof \CURLFile) { + $value = DataPart::fromPath($value->getFilename()); + } elseif (!\is_string($value) && !\is_array($value)) { + $value = (string) $value; + } + } + $formData = new FormDataPart($data); + + $options['headers'] = $formData->getPreparedHeaders()->toArray(); + $options['body'] = $formData->toIterable(); + } else { + $method = 'GET'; + } + + $response = $this->http->request($method, $url, $options); + + try { + return $response->toArray(); + } catch (ExceptionInterface $exception) { + if ($exception instanceof HttpExceptionInterface) { + $response = $exception->getResponse()->toArray(false); + $message = array_key_exists('description', $response) ? $response['description'] : $exception->getMessage(); + $parameters = array_key_exists('parameters', $response) ? $response['parameters'] : []; + } else { + $message = $exception->getMessage(); + $parameters = []; + } + + throw new HttpException($message, $exception->getCode(), $exception, $parameters); + } + } + + /** + * @inheritDoc + */ + protected function doDownload($url) + { + try { + return $this->http->request('GET', $url)->getContent(); + } catch (ExceptionInterface $exception) { + throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); + } + } +} diff --git a/src/HttpException.php b/src/HttpException.php index 0b80890d..e6859920 100644 --- a/src/HttpException.php +++ b/src/HttpException.php @@ -10,5 +10,31 @@ */ class HttpException extends Exception { + /** + * @var array + */ + protected $parameters = []; + /** + * HttpException constructor. + * + * @param string $message [optional] The Exception message to throw. + * @param int $code [optional] The Exception code. + * @param \Throwable|\Exception $previous [optional] The previous throwable used for the exception chaining. + * @param array $parameters [optional] Array of parameters returned from API. + */ + public function __construct($message = '', $code = 0, $previous = null, $parameters = []) + { + $this->parameters = $parameters; + + parent::__construct($message, $code, $previous); + } + + /** + * @return array + */ + public function getParameters() + { + return $this->parameters; + } } diff --git a/src/InvalidArgumentException.php b/src/InvalidArgumentException.php index 9c650905..ae9b949e 100644 --- a/src/InvalidArgumentException.php +++ b/src/InvalidArgumentException.php @@ -10,5 +10,4 @@ */ class InvalidArgumentException extends Exception { - } diff --git a/src/InvalidJsonException.php b/src/InvalidJsonException.php index 6eea8bc5..71011e96 100644 --- a/src/InvalidJsonException.php +++ b/src/InvalidJsonException.php @@ -10,5 +10,4 @@ */ class InvalidJsonException extends Exception { - } diff --git a/src/TypeInterface.php b/src/TypeInterface.php index c3637843..7418fe9b 100644 --- a/src/TypeInterface.php +++ b/src/TypeInterface.php @@ -4,5 +4,9 @@ interface TypeInterface { + /** + * @param array $data + * @return static + */ public static function fromResponse($data); } diff --git a/src/Types/AcceptedGiftTypes.php b/src/Types/AcceptedGiftTypes.php new file mode 100644 index 00000000..ff77e02c --- /dev/null +++ b/src/Types/AcceptedGiftTypes.php @@ -0,0 +1,63 @@ + true, + 'limited_gifts' => true, + 'unique_gifts' => true, + 'premium_subscription' => true, + ]; + + protected $unlimitedGifts; + protected $limitedGifts; + protected $uniqueGifts; + protected $premiumSubscription; + + public function getUnlimitedGifts() + { + return $this->unlimitedGifts; + } + + public function setUnlimitedGifts($unlimitedGifts) + { + $this->unlimitedGifts = $unlimitedGifts; + } + + public function getLimitedGifts() + { + return $this->limitedGifts; + } + + public function setLimitedGifts($limitedGifts) + { + $this->limitedGifts = $limitedGifts; + } + + public function getUniqueGifts() + { + return $this->uniqueGifts; + } + + public function setUniqueGifts($uniqueGifts) + { + $this->uniqueGifts = $uniqueGifts; + } + + public function getPremiumSubscription() + { + return $this->premiumSubscription; + } + + public function setPremiumSubscription($premiumSubscription) + { + $this->premiumSubscription = $premiumSubscription; + } +} diff --git a/src/Types/Animation.php b/src/Types/Animation.php new file mode 100644 index 00000000..141cc7aa --- /dev/null +++ b/src/Types/Animation.php @@ -0,0 +1,276 @@ + true, + 'file_unique_id' => true, + 'width' => true, + 'height' => true, + 'duration' => true, + 'thumbnail' => PhotoSize::class, + 'file_name' => true, + 'mime_type' => true, + 'file_size' => true + ]; + + /** + * Unique file identifier + * + * @var string + */ + protected $fileId; + + /** + * 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. + * + * @var string + */ + protected $fileUniqueId; + + /** + * Video width as defined by sender + * + * @var int + */ + protected $width; + + /** + * Video height as defined by sender + * + * @var int + */ + protected $height; + + /** + * Duration of the video in seconds as defined by sender + * + * @var int + */ + protected $duration; + + /** + * Optional. Animation thumbnail as defined by sender + * + * @var PhotoSize + */ + protected $thumbnail; + + /** + * Optional. Original animation filename as defined by sender + * + * @var string|null + */ + protected $fileName; + + /** + * Optional. MIME type of the file as defined by sender + * + * @var string|null + */ + protected $mimeType; + + /** + * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. + * + * @var int|null + */ + protected $fileSize; + + /** + * @return string + */ + public function getFileId() + { + return $this->fileId; + } + + /** + * @param string $fileId + * @return void + */ + public function setFileId($fileId) + { + $this->fileId = $fileId; + } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + + /** + * @return int + */ + public function getWidth() + { + return $this->width; + } + + /** + * @param int $width + * @return void + * @throws InvalidArgumentException + */ + public function setWidth($width) + { + if (is_integer($width)) { + $this->width = $width; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return int + */ + public function getHeight() + { + return $this->height; + } + + /** + * @param int $height + * @return void + * @throws InvalidArgumentException + */ + public function setHeight($height) + { + if (is_integer($height)) { + $this->height = $height; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return int + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param int $duration + * @return void + * @throws InvalidArgumentException + */ + public function setDuration($duration) + { + if (is_integer($duration)) { + $this->duration = $duration; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return PhotoSize + */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * @return void + */ + public function setThumbnail(PhotoSize $thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getFileName() + { + return $this->fileName; + } + + /** + * @param string $fileName + * @return void + */ + public function setFileName($fileName) + { + $this->fileName = $fileName; + } + + /** + * @return string|null + */ + public function getMimeType() + { + return $this->mimeType; + } + + /** + * @param string $mimeType + * @return void + */ + public function setMimeType($mimeType) + { + $this->mimeType = $mimeType; + } + + /** + * @return int|null + */ + public function getFileSize() + { + return $this->fileSize; + } + + /** + * @param int|null $fileSize + * @return void + * @throws InvalidArgumentException + */ + public function setFileSize($fileSize) + { + if (is_integer($fileSize) || is_null($fileSize)) { + $this->fileSize = $fileSize; + } else { + throw new InvalidArgumentException(); + } + } +} diff --git a/src/Types/ArrayOfArrayOfPhotoSize.php b/src/Types/ArrayOfArrayOfPhotoSize.php index 14491da4..3d2a1799 100644 --- a/src/Types/ArrayOfArrayOfPhotoSize.php +++ b/src/Types/ArrayOfArrayOfPhotoSize.php @@ -4,6 +4,10 @@ abstract class ArrayOfArrayOfPhotoSize { + /** + * @param array $data + * @return PhotoSize[][] + */ public static function fromResponse($data) { return array_map(function ($arrayOfPhotoSize) { diff --git a/src/Types/ArrayOfBotCommand.php b/src/Types/ArrayOfBotCommand.php new file mode 100644 index 00000000..59602c28 --- /dev/null +++ b/src/Types/ArrayOfBotCommand.php @@ -0,0 +1,19 @@ +addItem(BotCommand::fromResponse($botCommand)); + } + + return $arrayOfBotCommand; + } +} diff --git a/src/Types/ArrayOfBusinessOpeningHoursInterval.php b/src/Types/ArrayOfBusinessOpeningHoursInterval.php new file mode 100644 index 00000000..d2b497d6 --- /dev/null +++ b/src/Types/ArrayOfBusinessOpeningHoursInterval.php @@ -0,0 +1,20 @@ + true, + 'file_unique_id' => true, 'duration' => true, 'performer' => true, 'title' => true, + 'file_name' => true, 'mime_type' => true, - 'file_size' => true + 'file_size' => true, + 'thumbnail' => PhotoSize::class ]; /** @@ -43,7 +46,14 @@ class Audio extends BaseType implements TypeInterface protected $fileId; /** - * Photo width + * 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. + * + * @var string + */ + protected $fileUniqueId; + + /** + * Duration of the audio in seconds as defined by sender * * @var int */ @@ -52,31 +62,79 @@ class Audio extends BaseType implements TypeInterface /** * Optional. Performer of the audio as defined by sender or by audio tags * - * @var string + * @var string|null */ protected $performer; /** * Optional. Title of the audio as defined by sender or by audio tags * - * @var string + * @var string|null */ protected $title; + /** + * Optional. Original filename as defined by sender + * + * @var string|null + */ + protected $fileName; + /** * Optional. MIME type of the file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** - * Optional. File size + * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. * - * @var int + * @var int|null */ protected $fileSize; + /** + * Optional. Thumbnail of the album cover to which the music file belongs + * + * @var PhotoSize|null + */ + protected $thumbnail; + + /** + * @return string + */ + public function getFileId() + { + return $this->fileId; + } + + /** + * @param string $fileId + * @return void + */ + public function setFileId($fileId) + { + $this->fileId = $fileId; + } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + /** * @return int */ @@ -87,7 +145,7 @@ public function getDuration() /** * @param int $duration - * + * @return void * @throws InvalidArgumentException */ public function setDuration($duration) @@ -100,7 +158,7 @@ public function setDuration($duration) } /** - * @return string + * @return string|null */ public function getPerformer() { @@ -108,7 +166,8 @@ public function getPerformer() } /** - * @param string $performer + * @param string|null $performer + * @return void */ public function setPerformer($performer) { @@ -116,7 +175,7 @@ public function setPerformer($performer) } /** - * @return string + * @return string|null */ public function getTitle() { @@ -124,7 +183,8 @@ public function getTitle() } /** - * @param string $title + * @param string|null $title + * @return void */ public function setTitle($title) { @@ -132,23 +192,41 @@ public function setTitle($title) } /** - * @return string + * @return string|null */ - public function getFileId() + public function getFileName() { - return $this->fileId; + return $this->fileName; } /** - * @param string $fileId + * @param string|null $fileName + * @return void */ - public function setFileId($fileId) + public function setFileName($fileName) { - $this->fileId = $fileId; + $this->fileName = $fileName; } /** - * @return int + * @return string|null + */ + public function getMimeType() + { + return $this->mimeType; + } + + /** + * @param string|null $mimeType + * @return void + */ + public function setMimeType($mimeType) + { + $this->mimeType = $mimeType; + } + + /** + * @return int|null */ public function getFileSize() { @@ -156,13 +234,13 @@ public function getFileSize() } /** - * @param int $fileSize - * + * @param int|null $fileSize + * @return void * @throws InvalidArgumentException */ public function setFileSize($fileSize) { - if (is_integer($fileSize)) { + if (is_integer($fileSize) || is_null($fileSize)) { $this->fileSize = $fileSize; } else { throw new InvalidArgumentException(); @@ -170,18 +248,19 @@ public function setFileSize($fileSize) } /** - * @return string + * @return PhotoSize|null */ - public function getMimeType() + public function getThumbnail() { - return $this->mimeType; + return $this->thumbnail; } /** - * @param string $mimeType + * @param PhotoSize|null $thumbnail + * @return void */ - public function setMimeType($mimeType) + public function setThumbnail($thumbnail) { - $this->mimeType = $mimeType; + $this->thumbnail = $thumbnail; } } diff --git a/src/Types/BackgroundFill.php b/src/Types/BackgroundFill.php new file mode 100644 index 00000000..8da9d869 --- /dev/null +++ b/src/Types/BackgroundFill.php @@ -0,0 +1,39 @@ +type; + } + + /** + * @param string $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } +} diff --git a/src/Types/BackgroundFillFreeformGradient.php b/src/Types/BackgroundFillFreeformGradient.php new file mode 100644 index 00000000..3d028e04 --- /dev/null +++ b/src/Types/BackgroundFillFreeformGradient.php @@ -0,0 +1,53 @@ + true, + 'colors' => true, + ]; + + /** + * A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format + * + * @var array + */ + protected $colors; + + /** + * @return array + */ + public function getColors() + { + return $this->colors; + } + + /** + * @param array $colors + * @return void + */ + public function setColors($colors) + { + $this->colors = $colors; + } +} diff --git a/src/Types/BackgroundFillGradient.php b/src/Types/BackgroundFillGradient.php new file mode 100644 index 00000000..740a9249 --- /dev/null +++ b/src/Types/BackgroundFillGradient.php @@ -0,0 +1,97 @@ + true, + 'top_color' => true, + 'bottom_color' => true, + 'rotation_angle' => true, + ]; + + /** + * Top color of the gradient in the RGB24 format + * + * @var int + */ + protected $topColor; + + /** + * Bottom color of the gradient in the RGB24 format + * + * @var int + */ + protected $bottomColor; + + /** + * Clockwise rotation angle of the background fill in degrees; 0-359 + * + * @var int + */ + protected $rotationAngle; + + /** + * @return int + */ + public function getTopColor() + { + return $this->topColor; + } + + /** + * @param int $topColor + * @return void + */ + public function setTopColor($topColor) + { + $this->topColor = $topColor; + } + + /** + * @return int + */ + public function getBottomColor() + { + return $this->bottomColor; + } + + /** + * @param int $bottomColor + * @return void + */ + public function setBottomColor($bottomColor) + { + $this->bottomColor = $bottomColor; + } + + /** + * @return int + */ + public function getRotationAngle() + { + return $this->rotationAngle; + } + + /** + * @param int $rotationAngle + * @return void + */ + public function setRotationAngle($rotationAngle) + { + $this->rotationAngle = $rotationAngle; + } +} diff --git a/src/Types/BackgroundFillSolid.php b/src/Types/BackgroundFillSolid.php new file mode 100644 index 00000000..f9fe2bf8 --- /dev/null +++ b/src/Types/BackgroundFillSolid.php @@ -0,0 +1,53 @@ + true, + 'color' => true, + ]; + + /** + * The color of the background fill in the RGB24 format + * + * @var int + */ + protected $color; + + /** + * @return int + */ + public function getColor() + { + return $this->color; + } + + /** + * @param int $color + * @return void + */ + public function setColor($color) + { + $this->color = $color; + } +} diff --git a/src/Types/BackgroundType.php b/src/Types/BackgroundType.php new file mode 100644 index 00000000..dc2d8c30 --- /dev/null +++ b/src/Types/BackgroundType.php @@ -0,0 +1,39 @@ +type; + } + + /** + * @param string $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } +} diff --git a/src/Types/BackgroundTypeChatTheme.php b/src/Types/BackgroundTypeChatTheme.php new file mode 100644 index 00000000..6fb4d567 --- /dev/null +++ b/src/Types/BackgroundTypeChatTheme.php @@ -0,0 +1,53 @@ + true, + 'theme_name' => true, + ]; + + /** + * Name of the chat theme, which is usually an emoji + * + * @var string + */ + protected $themeName; + + /** + * @return string + */ + public function getThemeName() + { + return $this->themeName; + } + + /** + * @param string $themeName + * @return void + */ + public function setThemeName($themeName) + { + $this->themeName = $themeName; + } +} diff --git a/src/Types/BackgroundTypeFill.php b/src/Types/BackgroundTypeFill.php new file mode 100644 index 00000000..dab90920 --- /dev/null +++ b/src/Types/BackgroundTypeFill.php @@ -0,0 +1,78 @@ + true, + 'fill' => BackgroundFill::class, + 'dark_theme_dimming' => true, + ]; + + /** + * The background fill + * + * @var BackgroundFill + */ + protected $fill; + + /** + * Dimming of the background in dark themes, as a percentage; 0-100 + * + * @var int + */ + protected $darkThemeDimming; + + /** + * @return BackgroundFill + */ + public function getFill() + { + return $this->fill; + } + + /** + * @param BackgroundFill $fill + * @return void + */ + public function setFill(BackgroundFill $fill) + { + $this->fill = $fill; + } + + /** + * @return int + */ + public function getDarkThemeDimming() + { + return $this->darkThemeDimming; + } + + /** + * @param int $darkThemeDimming + * @return void + */ + public function setDarkThemeDimming($darkThemeDimming) + { + $this->darkThemeDimming = $darkThemeDimming; + } +} diff --git a/src/Types/BackgroundTypePattern.php b/src/Types/BackgroundTypePattern.php new file mode 100644 index 00000000..c9c37b66 --- /dev/null +++ b/src/Types/BackgroundTypePattern.php @@ -0,0 +1,153 @@ + true, + 'document' => Document::class, + 'fill' => BackgroundFill::class, + 'intensity' => true, + 'is_inverted' => true, + 'is_moving' => true, + ]; + + /** + * Document with the pattern + * + * @var Document + */ + protected $document; + + /** + * The background fill that is combined with the pattern + * + * @var BackgroundFill + */ + protected $fill; + + /** + * Intensity of the pattern when it is shown above the filled background; 0-100 + * + * @var int + */ + protected $intensity; + + /** + * Optional. True, if the background fill must be applied only to the pattern itself. All other pixels are black in this case. For dark themes only + * + * @var bool|null + */ + protected $isInverted; + + /** + * Optional. True, if the background moves slightly when the device is tilted + * + * @var bool|null + */ + protected $isMoving; + + /** + * @return Document + */ + public function getDocument() + { + return $this->document; + } + + /** + * @param Document $document + * @return void + */ + public function setDocument(Document $document) + { + $this->document = $document; + } + + /** + * @return BackgroundFill + */ + public function getFill() + { + return $this->fill; + } + + /** + * @param BackgroundFill $fill + * @return void + */ + public function setFill(BackgroundFill $fill) + { + $this->fill = $fill; + } + + /** + * @return int + */ + public function getIntensity() + { + return $this->intensity; + } + + /** + * @param int $intensity + * @return void + */ + public function setIntensity($intensity) + { + $this->intensity = $intensity; + } + + /** + * @return bool|null + */ + public function getIsInverted() + { + return $this->isInverted; + } + + /** + * @param bool $isInverted + * @return void + */ + public function setIsInverted($isInverted) + { + $this->isInverted = $isInverted; + } + + /** + * @return bool|null + */ + public function getIsMoving() + { + return $this->isMoving; + } + + /** + * @param bool $isMoving + * @return void + */ + public function setIsMoving($isMoving) + { + $this->isMoving = $isMoving; + } +} diff --git a/src/Types/BackgroundTypeWallpaper.php b/src/Types/BackgroundTypeWallpaper.php new file mode 100644 index 00000000..dba3baa7 --- /dev/null +++ b/src/Types/BackgroundTypeWallpaper.php @@ -0,0 +1,128 @@ + true, + 'document' => Document::class, + 'dark_theme_dimming' => true, + 'is_blurred' => true, + 'is_moving' => true, + ]; + + /** + * Document with the wallpaper + * + * @var Document + */ + protected $document; + + /** + * Dimming of the background in dark themes, as a percentage; 0-100 + * + * @var int + */ + protected $darkThemeDimming; + + /** + * Optional. True, if the wallpaper is downscaled to fit in a 450x450 square and then box-blurred with radius 12 + * + * @var bool|null + */ + protected $isBlurred; + + /** + * Optional. True, if the background moves slightly when the device is tilted + * + * @var bool|null + */ + protected $isMoving; + + /** + * @return Document + */ + public function getDocument() + { + return $this->document; + } + + /** + * @param Document $document + * @return void + */ + public function setDocument(Document $document) + { + $this->document = $document; + } + + /** + * @return int + */ + public function getDarkThemeDimming() + { + return $this->darkThemeDimming; + } + + /** + * @param int $darkThemeDimming + * @return void + */ + public function setDarkThemeDimming($darkThemeDimming) + { + $this->darkThemeDimming = $darkThemeDimming; + } + + /** + * @return bool|null + */ + public function getIsBlurred() + { + return $this->isBlurred; + } + + /** + * @param bool $isBlurred + * @return void + */ + public function setIsBlurred($isBlurred) + { + $this->isBlurred = $isBlurred; + } + + /** + * @return bool|null + */ + public function getIsMoving() + { + return $this->isMoving; + } + + /** + * @param bool $isMoving + * @return void + */ + public function setIsMoving($isMoving) + { + $this->isMoving = $isMoving; + } +} diff --git a/src/Types/Birthdate.php b/src/Types/Birthdate.php new file mode 100644 index 00000000..2e2d1b7e --- /dev/null +++ b/src/Types/Birthdate.php @@ -0,0 +1,99 @@ + true, + 'month' => true, + 'year' => true, + ]; + + /** + * Day of the user's birth; 1-31 + * + * @var int + */ + protected $day; + + /** + * Month of the user's birth; 1-12 + * + * @var int + */ + protected $month; + + /** + * Optional. Year of the user's birth + * + * @var int|null + */ + protected $year; + + /** + * @return int + */ + public function getDay() + { + return $this->day; + } + + /** + * @param int $day + * @return void + */ + public function setDay($day) + { + $this->day = $day; + } + + /** + * @return int + */ + public function getMonth() + { + return $this->month; + } + + /** + * @param int $month + * @return void + */ + public function setMonth($month) + { + $this->month = $month; + } + + /** + * @return int|null + */ + public function getYear() + { + return $this->year; + } + + /** + * @param int|null $year + * @return void + */ + public function setYear($year) + { + $this->year = $year; + } +} diff --git a/src/Types/BotCommand.php b/src/Types/BotCommand.php new file mode 100644 index 00000000..b1c78bd0 --- /dev/null +++ b/src/Types/BotCommand.php @@ -0,0 +1,75 @@ + true, + 'description' => true, + ]; + + /** + * Text of the command, 1-32 characters. Can contain only lowercase English letters, digits and underscores. + * + * @var string + */ + protected $command; + + /** + * Description of the command, 3-256 characters. + * + * @var string + */ + protected $description; + + /** + * @return string + */ + public function getCommand() + { + return $this->command; + } + + /** + * @param string $command + * @return void + */ + public function setCommand($command) + { + $this->command = $command; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + * @return void + */ + public function setDescription($description) + { + $this->description = $description; + } +} diff --git a/src/Types/BotDescription.php b/src/Types/BotDescription.php new file mode 100644 index 00000000..28188681 --- /dev/null +++ b/src/Types/BotDescription.php @@ -0,0 +1,54 @@ + true + ]; + + /** + * The bot's description + * + * @var string + */ + protected $description; + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + */ + public function setDescription($description) + { + $this->description = $description; + } +} diff --git a/src/Types/BotShortDescription.php b/src/Types/BotShortDescription.php new file mode 100644 index 00000000..29bb381d --- /dev/null +++ b/src/Types/BotShortDescription.php @@ -0,0 +1,54 @@ + true + ]; + + /** + * The bot's short description + * + * @var string + */ + protected $shortDescription; + + /** + * @return string + */ + public function getShortDescription() + { + return $this->shortDescription; + } + + /** + * @param string $shortDescription + */ + public function setShortDescription($shortDescription) + { + $this->shortDescription = $shortDescription; + } +} diff --git a/src/Types/BusinessConnection.php b/src/Types/BusinessConnection.php new file mode 100644 index 00000000..247f051f --- /dev/null +++ b/src/Types/BusinessConnection.php @@ -0,0 +1,174 @@ + true, + 'user' => User::class, + 'user_chat_id' => true, + 'date' => true, + 'can_reply' => true, + 'is_enabled' => true + ]; + + /** + * Unique identifier of the business connection + * + * @var string + */ + protected $id; + + /** + * Business account user that created the business connection + * + * @var User + */ + protected $user; + + /** + * Identifier of a private chat with the user who created the business connection + * + * @var int + */ + protected $userChatId; + + /** + * Date the connection was established in Unix time + * + * @var int + */ + protected $date; + + /** + * True, if the bot can act on behalf of the business account in chats that were active in the last 24 hours + * + * @var bool + */ + protected $canReply; + + /** + * True, if the connection is active + * + * @var bool + */ + protected $isEnabled; + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $user + */ + public function setUser($user) + { + $this->user = $user; + } + + /** + * @return int + */ + public function getUserChatId() + { + return $this->userChatId; + } + + /** + * @param int $userChatId + */ + public function setUserChatId($userChatId) + { + $this->userChatId = $userChatId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return bool + */ + public function getCanReply() + { + return $this->canReply; + } + + /** + * @param bool $canReply + */ + public function setCanReply($canReply) + { + $this->canReply = $canReply; + } + + /** + * @return bool + */ + public function getIsEnabled() + { + return $this->isEnabled; + } + + /** + * @param bool $isEnabled + */ + public function setIsEnabled($isEnabled) + { + $this->isEnabled = $isEnabled; + } +} diff --git a/src/Types/BusinessIntro.php b/src/Types/BusinessIntro.php new file mode 100644 index 00000000..7b6030df --- /dev/null +++ b/src/Types/BusinessIntro.php @@ -0,0 +1,92 @@ + true, + 'message' => true, + 'sticker' => Sticker::class, + ]; + + /** + * Optional. Title text of the business intro + * + * @var string|null + */ + protected $title; + + /** + * Optional. Message text of the business intro + * + * @var string|null + */ + protected $message; + + /** + * Optional. Sticker of the business intro + * + * @var Sticker|null + */ + protected $sticker; + + /** + * @return string|null + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string|null $title + * @return void + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string|null + */ + public function getMessage() + { + return $this->message; + } + + /** + * @param string|null $message + * @return void + */ + public function setMessage($message) + { + $this->message = $message; + } + + /** + * @return Sticker|null + */ + public function getSticker() + { + return $this->sticker; + } + + /** + * @param Sticker|null $sticker + * @return void + */ + public function setSticker($sticker) + { + $this->sticker = $sticker; + } +} diff --git a/src/Types/BusinessLocation.php b/src/Types/BusinessLocation.php new file mode 100644 index 00000000..9d8e2b0d --- /dev/null +++ b/src/Types/BusinessLocation.php @@ -0,0 +1,74 @@ + true, + 'location' => Location::class, + ]; + + /** + * Address of the business + * + * @var string + */ + protected $address; + + /** + * Optional. Location of the business + * + * @var Location|null + */ + protected $location; + + /** + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * @param string $address + * @return void + */ + public function setAddress($address) + { + $this->address = $address; + } + + /** + * @return Location|null + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param Location|null $location + * @return void + */ + public function setLocation($location) + { + $this->location = $location; + } +} diff --git a/src/Types/BusinessMessagesDeleted.php b/src/Types/BusinessMessagesDeleted.php new file mode 100644 index 00000000..68438f1b --- /dev/null +++ b/src/Types/BusinessMessagesDeleted.php @@ -0,0 +1,102 @@ + true, + 'chat' => Chat::class, + 'message_ids' => true + ]; + + /** + * Unique identifier of the business connection + * + * @var string + */ + protected $businessConnectionId; + + /** + * Information about a chat in the business account. The bot may not have access to the chat or the corresponding user. + * + * @var Chat + */ + protected $chat; + + /** + * The list of identifiers of deleted messages in the chat of the business account + * + * @var int[] + */ + protected $messageIds; + + /** + * @return string + */ + public function getBusinessConnectionId() + { + return $this->businessConnectionId; + } + + /** + * @param string $businessConnectionId + */ + public function setBusinessConnectionId($businessConnectionId) + { + $this->businessConnectionId = $businessConnectionId; + } + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int[] + */ + public function getMessageIds() + { + return $this->messageIds; + } + + /** + * @param int[] $messageIds + */ + public function setMessageIds(array $messageIds) + { + $this->messageIds = $messageIds; + } +} diff --git a/src/Types/BusinessOpeningHours.php b/src/Types/BusinessOpeningHours.php new file mode 100644 index 00000000..67ea67a3 --- /dev/null +++ b/src/Types/BusinessOpeningHours.php @@ -0,0 +1,74 @@ + true, + 'opening_hours' => ArrayOfBusinessOpeningHoursInterval::class, + ]; + + /** + * Unique name of the time zone for which the opening hours are defined + * + * @var string + */ + protected $timeZoneName; + + /** + * List of time intervals describing business opening hours + * + * @var array + */ + protected $openingHours; + + /** + * @return string + */ + public function getTimeZoneName() + { + return $this->timeZoneName; + } + + /** + * @param string $timeZoneName + * @return void + */ + public function setTimeZoneName($timeZoneName) + { + $this->timeZoneName = $timeZoneName; + } + + /** + * @return array + */ + public function getOpeningHours() + { + return $this->openingHours; + } + + /** + * @param array $openingHours + * @return void + */ + public function setOpeningHours($openingHours) + { + $this->openingHours = $openingHours; + } +} diff --git a/src/Types/BusinessOpeningHoursInterval.php b/src/Types/BusinessOpeningHoursInterval.php new file mode 100644 index 00000000..6f7b8065 --- /dev/null +++ b/src/Types/BusinessOpeningHoursInterval.php @@ -0,0 +1,74 @@ + true, + 'closing_minute' => true, + ]; + + /** + * The minute's sequence number in a week, starting on Monday, marking the start of the time interval during which the business is open; 0 - 7 * 24 * 60 + * + * @var int + */ + protected $openingMinute; + + /** + * The minute's sequence number in a week, starting on Monday, marking the end of the time interval during which the business is open; 0 - 8 * 24 * 60 + * + * @var int + */ + protected $closingMinute; + + /** + * @return int + */ + public function getOpeningMinute() + { + return $this->openingMinute; + } + + /** + * @param int $openingMinute + * @return void + */ + public function setOpeningMinute($openingMinute) + { + $this->openingMinute = $openingMinute; + } + + /** + * @return int + */ + public function getClosingMinute() + { + return $this->closingMinute; + } + + /** + * @param int $closingMinute + * @return void + */ + public function setClosingMinute($closingMinute) + { + $this->closingMinute = $closingMinute; + } +} diff --git a/src/Types/CallbackGame.php b/src/Types/CallbackGame.php new file mode 100644 index 00000000..193daad7 --- /dev/null +++ b/src/Types/CallbackGame.php @@ -0,0 +1,10 @@ + true, 'from' => User::class, - 'message' => Message::class, + 'message' => MaybeInaccessibleMessage::class, 'inline_message_id' => true, 'chat_instance' => true, 'data' => true, @@ -59,7 +58,7 @@ class CallbackQuery extends BaseType * Note that message content and message date will not be available * if the message is too old * - * @var \TelegramBot\Api\Types\Message + * @var Message|InaccessibleMessage|null */ protected $message; @@ -67,7 +66,7 @@ class CallbackQuery extends BaseType * Optional. Identifier of the message sent via the bot in inline mode, * that originated the query. * - * @var string + * @var string|null */ protected $inlineMessageId; @@ -83,7 +82,7 @@ class CallbackQuery extends BaseType * Optional. Data associated with the callback button. * Be aware that a bad client can send arbitrary data in this field. * - * @var string + * @var string|null */ protected $data; @@ -91,11 +90,10 @@ class CallbackQuery extends BaseType * Optional. Short name of a Game to be returned, * serves as the unique identifier for the game * - * @var string + * @var string|null */ protected $gameShortName; - /** * @return string */ @@ -106,6 +104,7 @@ public function getId() /** * @param string $id + * @return void */ public function setId($id) { @@ -122,6 +121,7 @@ public function getFrom() /** * @param User $from + * @return void */ public function setFrom(User $from) { @@ -129,7 +129,7 @@ public function setFrom(User $from) } /** - * @return Message + * @return Message|InaccessibleMessage|null */ public function getMessage() { @@ -137,7 +137,8 @@ public function getMessage() } /** - * @param Message $message + * @param Message|InaccessibleMessage|null $message + * @return void */ public function setMessage($message) { @@ -145,7 +146,7 @@ public function setMessage($message) } /** - * @return string + * @return null|string */ public function getInlineMessageId() { @@ -154,6 +155,7 @@ public function getInlineMessageId() /** * @param string $inlineMessageId + * @return void */ public function setInlineMessageId($inlineMessageId) { @@ -170,6 +172,7 @@ public function getChatInstance() /** * @param string $chatInstance + * @return void */ public function setChatInstance($chatInstance) { @@ -177,7 +180,7 @@ public function setChatInstance($chatInstance) } /** - * @return string + * @return null|string */ public function getData() { @@ -186,6 +189,7 @@ public function getData() /** * @param string $data + * @return void */ public function setData($data) { @@ -193,7 +197,7 @@ public function setData($data) } /** - * @return string + * @return null|string */ public function getGameShortName() { @@ -202,6 +206,7 @@ public function getGameShortName() /** * @param string $gameShortName + * @return void */ public function setGameShortName($gameShortName) { diff --git a/src/Types/Chat.php b/src/Types/Chat.php index f0f337bd..9ff38e9a 100644 --- a/src/Types/Chat.php +++ b/src/Types/Chat.php @@ -6,6 +6,12 @@ use TelegramBot\Api\InvalidArgumentException; use TelegramBot\Api\TypeInterface; +/** + * Class Chat + * This object represents a chat. + * + * @package TelegramBot\Api\Types + */ class Chat extends BaseType implements TypeInterface { /** @@ -13,101 +19,74 @@ class Chat extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['id', 'type']; + protected static $requiredParams = ['id', 'type']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'type' => true, 'title' => true, 'username' => true, 'first_name' => true, 'last_name' => true, - 'all_members_are_administrators' => true, - 'photo' => ChatPhoto::class, - 'description' => true, - 'invite_link' => true, - 'pinned_message' => Message::class + 'is_forum' => true, ]; /** - * Unique identifier for this chat, not exceeding 1e13 by absolute value + * Unique identifier for this chat. * - * @var int|string + * @var int|float */ protected $id; /** - * Type of chat, can be either “private”, “group”, “supergroup” or “channel” + * Type of chat, can be either “private”, “group”, “supergroup” or “channel”. * * @var string */ protected $type; /** - * Optional. Title, for channels and group chats + * Optional. Title, for supergroups, channels and group chats. * - * @var string + * @var string|null */ protected $title; /** - * Optional. Username, for private chats and channels if available + * Optional. Username, for private chats, supergroups and channels if available. * - * @var string + * @var string|null */ protected $username; /** - * Optional. First name of the other party in a private chat + * Optional. First name of the other party in a private chat. * - * @var string + * @var string|null */ protected $firstName; /** - * Optional. Last name of the other party in a private chat + * Optional. Last name of the other party in a private chat. * - * @var string + * @var string|null */ protected $lastName; - protected $allMembersAreAdministrators; - /** - * Optional. Chat photo. Returned only in getChat. + * Optional. True, if the supergroup chat is a forum (has topics enabled). * - * @var ChatPhoto + * @var bool|null */ - protected $photo; + protected $isForum; /** - * Optional. Description, for supergroups and channel chats. Returned only in getChat. - * - * @var string - */ - protected $description; - - /** - * Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat. - * - * @var string - */ - protected $inviteLink; - - /** - * Optional. Pinned message, for supergroups. Returned only in getChat. - * - * @var Message - */ - protected $pinnedMessage; - - /** - * @return int|string + * @return int|float */ public function getId() { @@ -115,13 +94,13 @@ public function getId() } /** - * @param int|string $id - * + * @param mixed $id + * @return void * @throws InvalidArgumentException */ - public function setId($id) + public function setId($id): void { - if (is_integer($id) || is_float($id) || is_string($id)) { + if (is_integer($id) || is_float($id)) { $this->id = $id; } else { throw new InvalidArgumentException(); @@ -139,13 +118,13 @@ public function getType() /** * @param string $type */ - public function setType($type) + public function setType($type): void { $this->type = $type; } /** - * @return string + * @return string|null */ public function getTitle() { @@ -153,15 +132,15 @@ public function getTitle() } /** - * @param string $title + * @param string|null $title */ - public function setTitle($title) + public function setTitle($title): void { $this->title = $title; } /** - * @return string + * @return string|null */ public function getUsername() { @@ -169,15 +148,15 @@ public function getUsername() } /** - * @param string $username + * @param string|null $username */ - public function setUsername($username) + public function setUsername($username): void { $this->username = $username; } /** - * @return string + * @return string|null */ public function getFirstName() { @@ -185,15 +164,15 @@ public function getFirstName() } /** - * @param string $firstName + * @param string|null $firstName */ - public function setFirstName($firstName) + public function setFirstName($firstName): void { $this->firstName = $firstName; } /** - * @return string + * @return string|null */ public function getLastName() { @@ -201,90 +180,26 @@ public function getLastName() } /** - * @param string $lastName + * @param string|null $lastName */ - public function setLastName($lastName) + public function setLastName($lastName): void { $this->lastName = $lastName; } /** - * @return mixed - */ - public function getAllMembersAreAdministrators() - { - return $this->allMembersAreAdministrators; - } - - /** - * @param mixed $allMembersAreAdministrators - */ - public function setAllMembersAreAdministrators($allMembersAreAdministrators) - { - $this->allMembersAreAdministrators = $allMembersAreAdministrators; - } - - /** - * @return ChatPhoto - */ - public function getPhoto() - { - return $this->photo; - } - - /** - * @param ChatPhoto $photo - */ - public function setPhoto($photo) - { - $this->photo = $photo; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * @return string - */ - public function getInviteLink() - { - return $this->inviteLink; - } - - /** - * @param string $inviteLink - */ - public function setInviteLink($inviteLink) - { - $this->inviteLink = $inviteLink; - } - - /** - * @return Message + * @return bool|null */ - public function getPinnedMessage() + public function getIsForum() { - return $this->pinnedMessage; + return $this->isForum; } /** - * @param Message $pinnedMessage + * @param bool|null $isForum */ - public function setPinnedMessage($pinnedMessage) + public function setIsForum($isForum): void { - $this->pinnedMessage = $pinnedMessage; + $this->isForum = $isForum; } } diff --git a/src/Types/ChatAdministratorRights.php b/src/Types/ChatAdministratorRights.php new file mode 100644 index 00000000..a2b54a9c --- /dev/null +++ b/src/Types/ChatAdministratorRights.php @@ -0,0 +1,411 @@ + true, + 'can_manage_chat' => true, + 'can_delete_messages' => true, + 'can_manage_video_chats' => true, + 'can_restrict_members' => true, + 'can_promote_members' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_post_stories' => true, + 'can_edit_stories' => true, + 'can_delete_stories' => true, + 'can_post_messages' => true, + 'can_edit_messages' => true, + 'can_pin_messages' => true, + 'can_manage_topics' => true, + ]; + + /** + * True, if the user's presence in the chat is hidden + * + * @var bool + */ + protected $isAnonymous; + + /** + * True, if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode. Implied by any other administrator privilege. + * + * @var bool + */ + protected $canManageChat; + + /** + * True, if the administrator can delete messages of other users + * + * @var bool + */ + protected $canDeleteMessages; + + /** + * True, if the administrator can manage video chats + * + * @var bool + */ + protected $canManageVideoChats; + + /** + * True, if the administrator can restrict, ban or unban chat members, or access supergroup statistics + * + * @var bool + */ + protected $canRestrictMembers; + + /** + * True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user) + * + * @var bool + */ + protected $canPromoteMembers; + + /** + * True, if the user is allowed to change the chat title, photo and other settings + * + * @var bool + */ + protected $canChangeInfo; + + /** + * True, if the user is allowed to invite new users to the chat + * + * @var bool + */ + protected $canInviteUsers; + + /** + * True, if the administrator can post stories to the chat + * + * @var bool + */ + protected $canPostStories; + + /** + * True, if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat's story archive + * + * @var bool + */ + protected $canEditStories; + + /** + * True, if the administrator can delete stories posted by other users + * + * @var bool + */ + protected $canDeleteStories; + + /** + * Optional. True, if the administrator can post messages in the channel, or access channel statistics; for channels only + * + * @var bool|null + */ + protected $canPostMessages; + + /** + * Optional. True, if the administrator can edit messages of other users and can pin messages; for channels only + * + * @var bool|null + */ + protected $canEditMessages; + + /** + * Optional. True, if the user is allowed to pin messages; for groups and supergroups only + * + * @var bool|null + */ + protected $canPinMessages; + + /** + * Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only + * + * @var bool|null + */ + protected $canManageTopics; + + /** + * @return bool + */ + public function isAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + * @return void + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return bool + */ + public function canManageChat() + { + return $this->canManageChat; + } + + /** + * @param bool $canManageChat + * @return void + */ + public function setCanManageChat($canManageChat) + { + $this->canManageChat = $canManageChat; + } + + /** + * @return bool + */ + public function canDeleteMessages() + { + return $this->canDeleteMessages; + } + + /** + * @param bool $canDeleteMessages + * @return void + */ + public function setCanDeleteMessages($canDeleteMessages) + { + $this->canDeleteMessages = $canDeleteMessages; + } + + /** + * @return bool + */ + public function canManageVideoChats() + { + return $this->canManageVideoChats; + } + + /** + * @param bool $canManageVideoChats + * @return void + */ + public function setCanManageVideoChats($canManageVideoChats) + { + $this->canManageVideoChats = $canManageVideoChats; + } + + /** + * @return bool + */ + public function canRestrictMembers() + { + return $this->canRestrictMembers; + } + + /** + * @param bool $canRestrictMembers + * @return void + */ + public function setCanRestrictMembers($canRestrictMembers) + { + $this->canRestrictMembers = $canRestrictMembers; + } + + /** + * @return bool + */ + public function canPromoteMembers() + { + return $this->canPromoteMembers; + } + + /** + * @param bool $canPromoteMembers + * @return void + */ + public function setCanPromoteMembers($canPromoteMembers) + { + $this->canPromoteMembers = $canPromoteMembers; + } + + /** + * @return bool + */ + public function canChangeInfo() + { + return $this->canChangeInfo; + } + + /** + * @param bool $canChangeInfo + * @return void + */ + public function setCanChangeInfo($canChangeInfo) + { + $this->canChangeInfo = $canChangeInfo; + } + + /** + * @return bool + */ + public function canInviteUsers() + { + return $this->canInviteUsers; + } + + /** + * @param bool $canInviteUsers + * @return void + */ + public function setCanInviteUsers($canInviteUsers) + { + $this->canInviteUsers = $canInviteUsers; + } + + /** + * @return bool + */ + public function canPostStories() + { + return $this->canPostStories; + } + + /** + * @param bool $canPostStories + * @return void + */ + public function setCanPostStories($canPostStories) + { + $this->canPostStories = $canPostStories; + } + + /** + * @return bool + */ + public function canEditStories() + { + return $this->canEditStories; + } + + /** + * @param bool $canEditStories + * @return void + */ + public function setCanEditStories($canEditStories) + { + $this->canEditStories = $canEditStories; + } + + /** + * @return bool + */ + public function canDeleteStories() + { + return $this->canDeleteStories; + } + + /** + * @param bool $canDeleteStories + * @return void + */ + public function setCanDeleteStories($canDeleteStories) + { + $this->canDeleteStories = $canDeleteStories; + } + + /** + * @return bool|null + */ + public function canPostMessages() + { + return $this->canPostMessages; + } + + /** + * @param bool|null $canPostMessages + * @return void + */ + public function setCanPostMessages($canPostMessages) + { + $this->canPostMessages = $canPostMessages; + } + + /** + * @return bool|null + */ + public function canEditMessages() + { + return $this->canEditMessages; + } + + /** + * @param bool|null $canEditMessages + * @return void + */ + public function setCanEditMessages($canEditMessages) + { + $this->canEditMessages = $canEditMessages; + } + + /** + * @return bool|null + */ + public function canPinMessages() + { + return $this->canPinMessages; + } + + /** + * @param bool|null $canPinMessages + * @return void + */ + public function setCanPinMessages($canPinMessages) + { + $this->canPinMessages = $canPinMessages; + } + + /** + * @return bool|null + */ + public function canManageTopics() + { + return $this->canManageTopics; + } + + /** + * @param bool|null $canManageTopics + * @return void + */ + public function setCanManageTopics($canManageTopics) + { + $this->canManageTopics = $canManageTopics; + } +} diff --git a/src/Types/ChatBackground.php b/src/Types/ChatBackground.php new file mode 100644 index 00000000..614c9469 --- /dev/null +++ b/src/Types/ChatBackground.php @@ -0,0 +1,55 @@ + BackgroundType::class, + ]; + + /** + * Type of the background + * + * @var BackgroundType + */ + protected $type; + + /** + * @return BackgroundType + */ + public function getType() + { + return $this->type; + } + + /** + * @param BackgroundType $type + * @return void + */ + public function setType(BackgroundType $type) + { + $this->type = $type; + } +} diff --git a/src/Types/ChatBoost.php b/src/Types/ChatBoost.php new file mode 100644 index 00000000..a913c839 --- /dev/null +++ b/src/Types/ChatBoost.php @@ -0,0 +1,126 @@ + true, + 'add_date' => true, + 'expiration_date' => true, + 'source' => ChatBoostSource::class + ]; + + /** + * Unique identifier of the boost + * + * @var string + */ + protected $boostId; + + /** + * Point in time (Unix timestamp) when the chat was boosted + * + * @var int + */ + protected $addDate; + + /** + * Point in time (Unix timestamp) when the boost will automatically expire, unless the booster's Telegram Premium subscription is prolonged + * + * @var int + */ + protected $expirationDate; + + /** + * Source of the added boost + * + * @var ChatBoostSource + */ + protected $source; + + /** + * @return string + */ + public function getBoostId() + { + return $this->boostId; + } + + /** + * @param string $boostId + */ + public function setBoostId($boostId) + { + $this->boostId = $boostId; + } + + /** + * @return int + */ + public function getAddDate() + { + return $this->addDate; + } + + /** + * @param int $addDate + */ + public function setAddDate($addDate) + { + $this->addDate = $addDate; + } + + /** + * @return int + */ + public function getExpirationDate() + { + return $this->expirationDate; + } + + /** + * @param int $expirationDate + */ + public function setExpirationDate($expirationDate) + { + $this->expirationDate = $expirationDate; + } + + /** + * @return ChatBoostSource + */ + public function getSource() + { + return $this->source; + } + + /** + * @param ChatBoostSource $source + */ + public function setSource($source) + { + $this->source = $source; + } +} diff --git a/src/Types/ChatBoostAdded.php b/src/Types/ChatBoostAdded.php new file mode 100644 index 00000000..5e040e80 --- /dev/null +++ b/src/Types/ChatBoostAdded.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * Number of boosts added by the user + * + * @var int + */ + protected $boostCount; + + /** + * @return int + */ + public function getBoostCount() + { + return $this->boostCount; + } + + /** + * @param int $boostCount + * @return void + */ + public function setBoostCount($boostCount) + { + $this->boostCount = $boostCount; + } +} diff --git a/src/Types/ChatBoostRemoved.php b/src/Types/ChatBoostRemoved.php new file mode 100644 index 00000000..8ec1e8f9 --- /dev/null +++ b/src/Types/ChatBoostRemoved.php @@ -0,0 +1,126 @@ + Chat::class, + 'boost_id' => true, + 'remove_date' => true, + 'source' => ChatBoostSource::class + ]; + + /** + * Chat which was boosted + * + * @var Chat + */ + protected $chat; + + /** + * Unique identifier of the boost + * + * @var string + */ + protected $boostId; + + /** + * Point in time (Unix timestamp) when the boost was removed + * + * @var int + */ + protected $removeDate; + + /** + * Source of the removed boost + * + * @var ChatBoostSource + */ + protected $source; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return string + */ + public function getBoostId() + { + return $this->boostId; + } + + /** + * @param string $boostId + */ + public function setBoostId($boostId) + { + $this->boostId = $boostId; + } + + /** + * @return int + */ + public function getRemoveDate() + { + return $this->removeDate; + } + + /** + * @param int $removeDate + */ + public function setRemoveDate($removeDate) + { + $this->removeDate = $removeDate; + } + + /** + * @return ChatBoostSource + */ + public function getSource() + { + return $this->source; + } + + /** + * @param ChatBoostSource $source + */ + public function setSource($source) + { + $this->source = $source; + } +} diff --git a/src/Types/ChatBoostSource.php b/src/Types/ChatBoostSource.php new file mode 100644 index 00000000..d07c4221 --- /dev/null +++ b/src/Types/ChatBoostSource.php @@ -0,0 +1,99 @@ + true, + 'user' => User::class, + ]; + + /** + * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType + */ + public static function fromResponse($data) + { + self::validate($data); + $source = $data['source']; + + switch ($source) { + case 'premium': + return ChatBoostSourcePremium::fromResponse($data); + case 'gift_code': + return ChatBoostSourceGiftCode::fromResponse($data); + case 'giveaway': + return ChatBoostSourceGiveaway::fromResponse($data); + default: + throw new InvalidArgumentException("Unknown chat boost source: $source"); + } + } + + /** + * Source of the boost, always “premium”, “gift_code”, or “giveaway” + * + * @var string + */ + protected $source; + + /** + * User that boosted the chat or for which the gift code was created + * + * @var User + */ + protected $user; + + /** + * @return string + */ + public function getSource() + { + return $this->source; + } + + /** + * @param string $source + */ + public function setSource($source) + { + $this->source = $source; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $user + */ + public function setUser($user) + { + $this->user = $user; + } +} diff --git a/src/Types/ChatBoostSourceGiftCode.php b/src/Types/ChatBoostSourceGiftCode.php new file mode 100644 index 00000000..f54f6cc7 --- /dev/null +++ b/src/Types/ChatBoostSourceGiftCode.php @@ -0,0 +1,53 @@ + true, + 'user' => User::class + ]; + + /** + * Source of the boost, always “gift_code” + * + * @var string + */ + protected $source = 'gift_code'; + + /** + * User for which the gift code was created + * + * @var User + */ + protected $user; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } +} diff --git a/src/Types/ChatBoostSourceGiveaway.php b/src/Types/ChatBoostSourceGiveaway.php new file mode 100644 index 00000000..39f00ad6 --- /dev/null +++ b/src/Types/ChatBoostSourceGiveaway.php @@ -0,0 +1,105 @@ + true, + 'giveaway_message_id' => true, + 'user' => User::class, + 'is_unclaimed' => true + ]; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * Source of the boost, always “giveaway” + * + * @var string + */ + protected $source = 'giveaway'; + + /** + * Identifier of a message in the chat with the giveaway + * + * @var int|null + */ + protected $giveawayMessageId; + + /** + * @psalm-suppress NonInvariantDocblockPropertyType + * + * Optional. User that won the prize in the giveaway if any + * + * @var User|null + */ + protected $user; + + /** + * Optional. True, if the giveaway was completed, but there was no user to win the prize + * + * @var bool|null + */ + protected $isUnclaimed; + + /** + * @return int|null + */ + public function getGiveawayMessageId(): ?int + { + return $this->giveawayMessageId; + } + + /** + * @param int|null $giveawayMessageId + * @return void + */ + public function setGiveawayMessageId(?int $giveawayMessageId): void + { + $this->giveawayMessageId = $giveawayMessageId; + } + + /** + * @return bool|null + */ + public function getIsUnclaimed(): ?bool + { + return $this->isUnclaimed; + } + + /** + * @param bool|null $isUnclaimed + * @return void + */ + public function setIsUnclaimed(?bool $isUnclaimed): void + { + $this->isUnclaimed = $isUnclaimed; + } +} diff --git a/src/Types/ChatBoostSourcePremium.php b/src/Types/ChatBoostSourcePremium.php new file mode 100644 index 00000000..9e05b62f --- /dev/null +++ b/src/Types/ChatBoostSourcePremium.php @@ -0,0 +1,85 @@ + true, + 'user' => User::class + ]; + + /** + * Source of the boost, always “premium” + * + * @var string + */ + protected $source = 'premium'; + + /** + * User that boosted the chat + * + * @var User + */ + protected $user; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getSource(): string + { + return $this->source; + } + + /** + * @param string $source + */ + public function setSource($source): void + { + $this->source = $source; + } + + /** + * @return User + */ + public function getUser(): User + { + return $this->user; + } + + /** + * @param User $user + */ + public function setUser($user): void + { + $this->user = $user; + } +} diff --git a/src/Types/ChatBoostUpdated.php b/src/Types/ChatBoostUpdated.php new file mode 100644 index 00000000..1298db0c --- /dev/null +++ b/src/Types/ChatBoostUpdated.php @@ -0,0 +1,78 @@ + Chat::class, + 'boost' => ChatBoost::class + ]; + + /** + * Chat which was boosted + * + * @var Chat + */ + protected $chat; + + /** + * Information about the chat boost + * + * @var ChatBoost + */ + protected $boost; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return ChatBoost + */ + public function getBoost() + { + return $this->boost; + } + + /** + * @param ChatBoost $boost + */ + public function setBoost($boost) + { + $this->boost = $boost; + } +} diff --git a/src/Types/ChatFullInfo.php b/src/Types/ChatFullInfo.php new file mode 100644 index 00000000..b3a93cfa --- /dev/null +++ b/src/Types/ChatFullInfo.php @@ -0,0 +1,1069 @@ + true, + 'type' => true, + 'title' => true, + 'username' => true, + 'first_name' => true, + 'last_name' => true, + 'is_forum' => true, + 'accent_color_id' => true, + 'max_reaction_count' => true, + 'photo' => ChatPhoto::class, + 'active_usernames' => true, + 'birthdate' => true, + 'business_intro' => true, + 'business_location' => true, + 'business_opening_hours' => true, + 'personal_chat' => Chat::class, + 'available_reactions' => ArrayOfReactionType::class, + 'background_custom_emoji_id' => true, + 'profile_accent_color_id' => true, + 'profile_background_custom_emoji_id' => true, + 'emoji_status_custom_emoji_id' => true, + 'emoji_status_expiration_date' => true, + 'bio' => true, + 'has_private_forwards' => true, + 'has_restricted_voice_and_video_messages' => true, + 'join_to_send_messages' => true, + 'join_by_request' => true, + 'description' => true, + 'invite_link' => true, + 'pinned_message' => Message::class, + 'permissions' => ChatPermissions::class, + 'slow_mode_delay' => true, + 'unrestrict_boost_count' => true, + 'message_auto_delete_time' => true, + 'has_aggressive_anti_spam_enabled' => true, + 'has_hidden_members' => true, + 'has_protected_content' => true, + 'has_visible_history' => true, + 'sticker_set_name' => true, + 'can_set_sticker_set' => true, + 'custom_emoji_sticker_set_name' => true, + 'linked_chat_id' => true, + 'location' => ChatLocation::class, + ]; + + /** + * Unique identifier for this chat. + * + * @var int|float|string + */ + protected $id; + + /** + * Type of chat, can be either “private”, “group”, “supergroup” or “channel”. + * + * @var string + */ + protected $type; + + /** + * Optional. Title, for supergroups, channels and group chats. + * + * @var string|null + */ + protected $title; + + /** + * Optional. Username, for private chats, supergroups and channels if available. + * + * @var string|null + */ + protected $username; + + /** + * Optional. First name of the other party in a private chat. + * + * @var string|null + */ + protected $firstName; + + /** + * Optional. Last name of the other party in a private chat. + * + * @var string|null + */ + protected $lastName; + + /** + * Optional. True, if the supergroup chat is a forum (has topics enabled). + * + * @var bool|null + */ + protected $isForum; + + /** + * Optional. Identifier of the accent color for the chat name and backgrounds of the chat photo, reply header, and link preview. + * + * @var int|null + */ + protected $accentColorId; + + /** + * Optional. The maximum number of reactions that can be set on a message in the chat. + * + * @var int|null + */ + protected $maxReactionCount; + + /** + * Optional. Chat photo. Returned only in getChat. + * + * @var ChatPhoto|null + */ + protected $photo; + + /** + * Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels. Returned only in getChat. + * + * @var array|null + */ + protected $activeUsernames; + + /** + * Optional. For private chats, the date of birth of the user. + * + * @var string|null + */ + protected $birthdate; + + /** + * Optional. For private chats with business accounts, the intro of the business. + * + * @var string|null + */ + protected $businessIntro; + + /** + * Optional. For private chats with business accounts, the location of the business. + * + * @var string|null + */ + protected $businessLocation; + + /** + * Optional. For private chats with business accounts, the opening hours of the business. + * + * @var string|null + */ + protected $businessOpeningHours; + + /** + * Optional. For private chats, the personal channel of the user. + * + * @var Chat|null + */ + protected $personalChat; + + /** + * Optional. List of available reactions allowed in the chat. If omitted, then all emoji reactions are allowed. Returned only in getChat. + * + * @var array|null + */ + protected $availableReactions; + + /** + * Optional. Custom emoji identifier of emoji chosen by the chat for the reply header and link preview background. + * + * @var string|null + */ + protected $backgroundCustomEmojiId; + + /** + * Optional. Identifier of the accent color for the chat's profile background. + * + * @var int|null + */ + protected $profileAccentColorId; + + /** + * Optional. Custom emoji identifier of the emoji chosen by the chat for its profile background. + * + * @var string|null + */ + protected $profileBackgroundCustomEmojiId; + + /** + * Optional. Custom emoji identifier of the emoji status of the chat or the other party in a private chat. Returned only in getChat. + * + * @var string|null + */ + protected $emojiStatusCustomEmojiId; + + /** + * Optional. Expiration date of the emoji status of the chat or the other party in a private chat, in Unix time, if any. + * + * @var int|null + */ + protected $emojiStatusExpirationDate; + + /** + * Optional. Bio of the other party in a private chat. Returned only in getChat. + * + * @var string|null + */ + protected $bio; + + /** + * Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id= links only in chats with the user. + * + * @var bool|null + */ + protected $hasPrivateForwards; + + /** + * Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. Returned only in getChat. + * + * @var bool|null + */ + protected $hasRestrictedVoiceAndVideoMessages; + + /** + * Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. + * + * @var bool|null + */ + protected $joinToSendMessages; + + /** + * Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat. + * + * @var bool|null + */ + protected $joinByRequest; + + /** + * Optional. Description, for groups, supergroups and channel chats. Returned only in getChat. + * + * @var string|null + */ + protected $description; + + /** + * Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat. + * + * @var string|null + */ + protected $inviteLink; + + /** + * Optional. The most recent pinned message (by sending date). Returned only in getChat. + * + * @var Message|null + */ + protected $pinnedMessage; + + /** + * Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. + * + * @var ChatPermissions|null + */ + protected $permissions; + + /** + * Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unprivileged user; in seconds. Returned only in getChat. + * + * @var int|null + */ + protected $slowModeDelay; + + /** + * Optional. For supergroups, the minimum number of boosts that a non-administrator user needs to add in order to ignore slow mode and chat permissions. + * + * @var int|null + */ + protected $unrestrictBoostCount; + + /** + * Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat. + * + * @var int|null + */ + protected $messageAutoDeleteTime; + + /** + * Optional. True, if aggressive anti-spam checks are enabled in the supergroup. The field is only available to chat administrators. Returned only in getChat. + * + * @var bool|null + */ + protected $hasAggressiveAntiSpamEnabled; + + /** + * Optional. True, if non-administrators can only get the list of bots and administrators in the chat. Returned only in getChat. + * + * @var bool|null + */ + protected $hasHiddenMembers; + + /** + * Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. + * + * @var bool|null + */ + protected $hasProtectedContent; + + /** + * Optional. True, if new chat members will have access to old messages; available only to chat administrators. Returned only in getChat. + * + * @var bool|null + */ + protected $hasVisibleHistory; + + /** + * Optional. For supergroups, name of the group sticker set. Returned only in getChat. + * + * @var string|null + */ + protected $stickerSetName; + + /** + * Optional. True, if the bot can change the group sticker set. Returned only in getChat. + * + * @var bool|null + */ + protected $canSetStickerSet; + + /** + * Optional. For supergroups, the name of the group's custom emoji sticker set. Custom emoji from this set can be used by all users and bots in the group. + * + * @var string|null + */ + protected $customEmojiStickerSetName; + + /** + * Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice versa; for supergroups and channel chats. This identifier may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + * + * @var int|null + */ + protected $linkedChatId; + + /** + * Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. + * + * @var ChatLocation|null + */ + protected $location; + + /** + * @return int|float|string + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $id + * @return void + * @throws InvalidArgumentException + */ + public function setId($id) + { + if (is_integer($id) || is_float($id) || is_string($id)) { + $this->id = $id; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string|null + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string|null $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string|null + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param string|null $username + */ + public function setUsername($username) + { + $this->username = $username; + } + + /** + * @return string|null + */ + public function getFirstName() + { + return $this->firstName; + } + + /** + * @param string|null $firstName + */ + public function setFirstName($firstName) + { + $this->firstName = $firstName; + } + + /** + * @return string|null + */ + public function getLastName() + { + return $this->lastName; + } + + /** + * @param string|null $lastName + */ + public function setLastName($lastName) + { + $this->lastName = $lastName; + } + + /** + * @return bool|null + */ + public function getIsForum() + { + return $this->isForum; + } + + /** + * @param bool|null $isForum + */ + public function setIsForum($isForum) + { + $this->isForum = $isForum; + } + + /** + * @return int|null + */ + public function getAccentColorId() + { + return $this->accentColorId; + } + + /** + * @param int|null $accentColorId + */ + public function setAccentColorId($accentColorId) + { + $this->accentColorId = $accentColorId; + } + + /** + * @return int|null + */ + public function getMaxReactionCount() + { + return $this->maxReactionCount; + } + + /** + * @param int|null $maxReactionCount + */ + public function setMaxReactionCount($maxReactionCount) + { + $this->maxReactionCount = $maxReactionCount; + } + + /** + * @return ChatPhoto|null + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param ChatPhoto|null $photo + */ + public function setPhoto($photo) + { + $this->photo = $photo; + } + + /** + * @return array|null + */ + public function getActiveUsernames() + { + return $this->activeUsernames; + } + + /** + * @param array|null $activeUsernames + */ + public function setActiveUsernames($activeUsernames) + { + $this->activeUsernames = $activeUsernames; + } + + /** + * @return string|null + */ + public function getBirthdate() + { + return $this->birthdate; + } + + /** + * @param string|null $birthdate + */ + public function setBirthdate($birthdate) + { + $this->birthdate = $birthdate; + } + + /** + * @return string|null + */ + public function getBusinessIntro() + { + return $this->businessIntro; + } + + /** + * @param string|null $businessIntro + */ + public function setBusinessIntro($businessIntro) + { + $this->businessIntro = $businessIntro; + } + + /** + * @return string|null + */ + public function getBusinessLocation() + { + return $this->businessLocation; + } + + /** + * @param string|null $businessLocation + */ + public function setBusinessLocation($businessLocation) + { + $this->businessLocation = $businessLocation; + } + + /** + * @return string|null + */ + public function getBusinessOpeningHours() + { + return $this->businessOpeningHours; + } + + /** + * @param string|null $businessOpeningHours + */ + public function setBusinessOpeningHours($businessOpeningHours) + { + $this->businessOpeningHours = $businessOpeningHours; + } + + /** + * @return Chat|null + */ + public function getPersonalChat() + { + return $this->personalChat; + } + + /** + * @param Chat|null $personalChat + */ + public function setPersonalChat($personalChat) + { + $this->personalChat = $personalChat; + } + + /** + * @return array|null + */ + public function getAvailableReactions() + { + return $this->availableReactions; + } + + /** + * @param array|null $availableReactions + */ + public function setAvailableReactions($availableReactions) + { + $this->availableReactions = $availableReactions; + } + + /** + * @return string|null + */ + public function getBackgroundCustomEmojiId() + { + return $this->backgroundCustomEmojiId; + } + + /** + * @param string|null $backgroundCustomEmojiId + */ + public function setBackgroundCustomEmojiId($backgroundCustomEmojiId) + { + $this->backgroundCustomEmojiId = $backgroundCustomEmojiId; + } + + /** + * @return int|null + */ + public function getProfileAccentColorId() + { + return $this->profileAccentColorId; + } + + /** + * @param int|null $profileAccentColorId + */ + public function setProfileAccentColorId($profileAccentColorId) + { + $this->profileAccentColorId = $profileAccentColorId; + } + + /** + * @return string|null + */ + public function getProfileBackgroundCustomEmojiId() + { + return $this->profileBackgroundCustomEmojiId; + } + + /** + * @param string|null $profileBackgroundCustomEmojiId + */ + public function setProfileBackgroundCustomEmojiId($profileBackgroundCustomEmojiId) + { + $this->profileBackgroundCustomEmojiId = $profileBackgroundCustomEmojiId; + } + + /** + * @return string|null + */ + public function getEmojiStatusCustomEmojiId() + { + return $this->emojiStatusCustomEmojiId; + } + + /** + * @param string|null $emojiStatusCustomEmojiId + */ + public function setEmojiStatusCustomEmojiId($emojiStatusCustomEmojiId) + { + $this->emojiStatusCustomEmojiId = $emojiStatusCustomEmojiId; + } + + /** + * @return int|null + */ + public function getEmojiStatusExpirationDate() + { + return $this->emojiStatusExpirationDate; + } + + /** + * @param int|null $emojiStatusExpirationDate + */ + public function setEmojiStatusExpirationDate($emojiStatusExpirationDate) + { + $this->emojiStatusExpirationDate = $emojiStatusExpirationDate; + } + + /** + * @return string|null + */ + public function getBio() + { + return $this->bio; + } + + /** + * @param string|null $bio + */ + public function setBio($bio) + { + $this->bio = $bio; + } + + /** + * @return bool|null + */ + public function getHasPrivateForwards() + { + return $this->hasPrivateForwards; + } + + /** + * @param bool|null $hasPrivateForwards + */ + public function setHasPrivateForwards($hasPrivateForwards) + { + $this->hasPrivateForwards = $hasPrivateForwards; + } + + /** + * @return bool|null + */ + public function getHasRestrictedVoiceAndVideoMessages() + { + return $this->hasRestrictedVoiceAndVideoMessages; + } + + /** + * @param bool|null $hasRestrictedVoiceAndVideoMessages + */ + public function setHasRestrictedVoiceAndVideoMessages($hasRestrictedVoiceAndVideoMessages) + { + $this->hasRestrictedVoiceAndVideoMessages = $hasRestrictedVoiceAndVideoMessages; + } + + /** + * @return bool|null + */ + public function getJoinToSendMessages() + { + return $this->joinToSendMessages; + } + + /** + * @param bool|null $joinToSendMessages + */ + public function setJoinToSendMessages($joinToSendMessages) + { + $this->joinToSendMessages = $joinToSendMessages; + } + + /** + * @return bool|null + */ + public function getJoinByRequest() + { + return $this->joinByRequest; + } + + /** + * @param bool|null $joinByRequest + */ + public function setJoinByRequest($joinByRequest) + { + $this->joinByRequest = $joinByRequest; + } + + /** + * @return string|null + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string|null $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * @return string|null + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param string|null $inviteLink + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } + + /** + * @return Message|null + */ + public function getPinnedMessage() + { + return $this->pinnedMessage; + } + + /** + * @param Message|null $pinnedMessage + */ + public function setPinnedMessage($pinnedMessage) + { + $this->pinnedMessage = $pinnedMessage; + } + + /** + * @return ChatPermissions|null + */ + public function getPermissions() + { + return $this->permissions; + } + + /** + * @param ChatPermissions|null $permissions + */ + public function setPermissions($permissions) + { + $this->permissions = $permissions; + } + + /** + * @return int|null + */ + public function getSlowModeDelay() + { + return $this->slowModeDelay; + } + + /** + * @param int|null $slowModeDelay + */ + public function setSlowModeDelay($slowModeDelay) + { + $this->slowModeDelay = $slowModeDelay; + } + + /** + * @return int|null + */ + public function getUnrestrictBoostCount() + { + return $this->unrestrictBoostCount; + } + + /** + * @param int|null $unrestrictBoostCount + */ + public function setUnrestrictBoostCount($unrestrictBoostCount) + { + $this->unrestrictBoostCount = $unrestrictBoostCount; + } + + /** + * @return int|null + */ + public function getMessageAutoDeleteTime() + { + return $this->messageAutoDeleteTime; + } + + /** + * @param int|null $messageAutoDeleteTime + */ + public function setMessageAutoDeleteTime($messageAutoDeleteTime) + { + $this->messageAutoDeleteTime = $messageAutoDeleteTime; + } + + /** + * @return bool|null + */ + public function getHasAggressiveAntiSpamEnabled() + { + return $this->hasAggressiveAntiSpamEnabled; + } + + /** + * @param bool|null $hasAggressiveAntiSpamEnabled + */ + public function setHasAggressiveAntiSpamEnabled($hasAggressiveAntiSpamEnabled) + { + $this->hasAggressiveAntiSpamEnabled = $hasAggressiveAntiSpamEnabled; + } + + /** + * @return bool|null + */ + public function getHasHiddenMembers() + { + return $this->hasHiddenMembers; + } + + /** + * @param bool|null $hasHiddenMembers + */ + public function setHasHiddenMembers($hasHiddenMembers) + { + $this->hasHiddenMembers = $hasHiddenMembers; + } + + /** + * @return bool|null + */ + public function getHasProtectedContent() + { + return $this->hasProtectedContent; + } + + /** + * @param bool|null $hasProtectedContent + */ + public function setHasProtectedContent($hasProtectedContent) + { + $this->hasProtectedContent = $hasProtectedContent; + } + + /** + * @return bool|null + */ + public function getHasVisibleHistory() + { + return $this->hasVisibleHistory; + } + + /** + * @param bool|null $hasVisibleHistory + */ + public function setHasVisibleHistory($hasVisibleHistory) + { + $this->hasVisibleHistory = $hasVisibleHistory; + } + + /** + * @return string|null + */ + public function getStickerSetName() + { + return $this->stickerSetName; + } + + /** + * @param string|null $stickerSetName + */ + public function setStickerSetName($stickerSetName) + { + $this->stickerSetName = $stickerSetName; + } + + /** + * @return bool|null + */ + public function getCanSetStickerSet() + { + return $this->canSetStickerSet; + } + + /** + * @param bool|null $canSetStickerSet + */ + public function setCanSetStickerSet($canSetStickerSet) + { + $this->canSetStickerSet = $canSetStickerSet; + } + + /** + * @return string|null + */ + public function getCustomEmojiStickerSetName() + { + return $this->customEmojiStickerSetName; + } + + /** + * @param string|null $customEmojiStickerSetName + */ + public function setCustomEmojiStickerSetName($customEmojiStickerSetName) + { + $this->customEmojiStickerSetName = $customEmojiStickerSetName; + } + + /** + * @return int|null + */ + public function getLinkedChatId() + { + return $this->linkedChatId; + } + + /** + * @param int|null $linkedChatId + */ + public function setLinkedChatId($linkedChatId) + { + $this->linkedChatId = $linkedChatId; + } + + /** + * @return ChatLocation|null + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param ChatLocation|null $location + */ + public function setLocation($location) + { + $this->location = $location; + } +} diff --git a/src/Types/ChatInviteLink.php b/src/Types/ChatInviteLink.php new file mode 100644 index 00000000..4cbfbbe5 --- /dev/null +++ b/src/Types/ChatInviteLink.php @@ -0,0 +1,249 @@ + true, + 'creator' => User::class, + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + 'name' => true, + 'expire_date' => true, + 'member_limit' => true, + 'pending_join_request_count' => true, + ]; + + /** + * The invite link. If the link was created by another chat administrator, then the second part of the link will be replaced with “…”. + * + * @var string + */ + protected $inviteLink; + + /** + * Creator of the link + * + * @var User + */ + protected $creator; + + /** + * True, if users joining the chat via the link need to be approved by chat administrators + * + * @var bool + */ + protected $createsJoinRequest; + + /** + * True, if the link is primary + * + * @var bool + */ + protected $isPrimary; + + /** + * True, if the link is revoked + * + * @var bool + */ + protected $isRevoked; + + /** + * Optional. Invite link name + * + * @var string|null + */ + protected $name; + + /** + * Optional. Point in time (Unix timestamp) when the link will expire or has been expired + * + * @var int|null + */ + protected $expireDate; + + /** + * Optional. The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 + * + * @var int|null + */ + protected $memberLimit; + + /** + * Optional. Number of pending join requests created using this link + * + * @var int|null + */ + protected $pendingJoinRequestCount; + + /** + * @return string + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param string $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } + + /** + * @return User + */ + public function getCreator() + { + return $this->creator; + } + + /** + * @param User $creator + * @return void + */ + public function setCreator($creator) + { + $this->creator = $creator; + } + + /** + * @return bool + */ + public function getCreatesJoinRequest() + { + return $this->createsJoinRequest; + } + + /** + * @param bool $createsJoinRequest + * @return void + */ + public function setCreatesJoinRequest($createsJoinRequest) + { + $this->createsJoinRequest = $createsJoinRequest; + } + + /** + * @return bool + */ + public function isPrimary() + { + return $this->isPrimary; + } + + /** + * @param bool $isPrimary + * @return void + */ + public function setIsPrimary($isPrimary) + { + $this->isPrimary = $isPrimary; + } + + /** + * @return bool + */ + public function isRevoked() + { + return $this->isRevoked; + } + + /** + * @param bool $isRevoked + * @return void + */ + public function setIsRevoked($isRevoked) + { + $this->isRevoked = $isRevoked; + } + + /** + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * @param string|null $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int|null + */ + public function getExpireDate() + { + return $this->expireDate; + } + + /** + * @param int|null $expireDate + * @return void + */ + public function setExpireDate($expireDate) + { + $this->expireDate = $expireDate; + } + + /** + * @return int|null + */ + public function getMemberLimit() + { + return $this->memberLimit; + } + + /** + * @param int|null $memberLimit + * @return void + */ + public function setMemberLimit($memberLimit) + { + $this->memberLimit = $memberLimit; + } + + /** + * @return int|null + */ + public function getPendingJoinRequestCount() + { + return $this->pendingJoinRequestCount; + } + + /** + * @param int|null $pendingJoinRequestCount + * @return void + */ + public function setPendingJoinRequestCount($pendingJoinRequestCount) + { + $this->pendingJoinRequestCount = $pendingJoinRequestCount; + } +} diff --git a/src/Types/ChatJoinRequest.php b/src/Types/ChatJoinRequest.php new file mode 100644 index 00000000..76b33718 --- /dev/null +++ b/src/Types/ChatJoinRequest.php @@ -0,0 +1,174 @@ + Chat::class, + 'from' => User::class, + 'user_chat_id' => true, + 'date' => true, + 'bio' => true, + 'invite_link' => ChatInviteLink::class, + ]; + + /** + * Chat to which the request was sent + * + * @var Chat + */ + protected $chat; + + /** + * User that sent the join request + * + * @var User + */ + protected $from; + + /** + * Identifier of a private chat with the user who sent the join request. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot can use this identifier for 24 hours to send messages until the join request is processed, assuming no other administrator contacted the user. + * + * @var int + */ + protected $userChatId; + + /** + * Date the request was sent in Unix time + * + * @var int + */ + protected $date; + + /** + * Optional. Bio of the user. + * + * @var string|null + */ + protected $bio; + + /** + * Optional. Chat invite link that was used by the user to send the join request + * + * @var ChatInviteLink|null + */ + protected $inviteLink; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + * @return void + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * @return int + */ + public function getUserChatId() + { + return $this->userChatId; + } + + /** + * @param int $userChatId + * @return void + */ + public function setUserChatId($userChatId) + { + $this->userChatId = $userChatId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return string|null + */ + public function getBio() + { + return $this->bio; + } + + /** + * @param string|null $bio + * @return void + */ + public function setBio($bio) + { + $this->bio = $bio; + } + + /** + * @return ChatInviteLink|null + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param ChatInviteLink|null $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } +} diff --git a/src/Types/ChatLocation.php b/src/Types/ChatLocation.php new file mode 100644 index 00000000..492b35be --- /dev/null +++ b/src/Types/ChatLocation.php @@ -0,0 +1,74 @@ + Location::class, + 'address' => true, + ]; + + /** + * The location to which the supergroup is connected. Can't be a live location. + * + * @var Location + */ + protected $location; + + /** + * Location address; 1-64 characters, as defined by the chat owner + * + * @var string + */ + protected $address; + + /** + * @return Location + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param Location $location + * @return void + */ + public function setLocation($location) + { + $this->location = $location; + } + + /** + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * @param string $address + * @return void + */ + public function setAddress($address) + { + $this->address = $address; + } +} diff --git a/src/Types/ChatMember.php b/src/Types/ChatMember.php index c107eea5..5c1f69d2 100644 --- a/src/Types/ChatMember.php +++ b/src/Types/ChatMember.php @@ -3,172 +3,67 @@ namespace TelegramBot\Api\Types; use TelegramBot\Api\BaseType; +use TelegramBot\Api\InvalidArgumentException; +use TelegramBot\Api\TypeInterface; -class ChatMember extends BaseType +abstract class ChatMember extends BaseType implements TypeInterface { /** * {@inheritdoc} * * @var array */ - static protected $requiredParams = ['user', 'status']; + protected static $requiredParams = ['status', 'user']; + + /** + * @psalm-suppress MoreSpecificReturnType,LessSpecificImplementedReturnType,LessSpecificReturnStatement + */ + public static function fromResponse($data) + { + self::validate($data); + $status = $data['status']; + + switch ($status) { + case 'creator': + return ChatMemberOwner::fromResponse($data); + case 'administrator': + return ChatMemberAdministrator::fromResponse($data); + case 'member': + return ChatMemberMember::fromResponse($data); + case 'restricted': + return ChatMemberRestricted::fromResponse($data); + case 'left': + return ChatMemberLeft::fromResponse($data); + case 'kicked': + return ChatMemberBanned::fromResponse($data); + default: + throw new InvalidArgumentException("Unknown chat member status: $status"); + } + } /** * {@inheritdoc} * * @var array */ - static protected $map = [ - 'user' => User::class, + protected static $map = [ 'status' => true, - 'until_date' => true, - 'can_be_edited' => true, - 'can_change_info' => true, - 'can_post_messages' => true, - 'can_edit_messages' => true, - 'can_delete_messages' => true, - 'can_invite_users' => true, - 'can_restrict_members' => true, - 'can_pin_messages' => true, - 'can_promote_members' => true, - 'can_send_messages' => true, - 'can_send_media_messages' => true, - 'can_send_other_messages' => true, - 'can_add_web_page_previews' => true + 'user' => User::class, ]; /** - * Information about the user - * - * @var User - */ - protected $user; - - /** - * The member's status in the chat. Can be “creator”, “administrator”, “member”, “restricted”, “left” or “kicked” + * The member's status in the chat * * @var string */ protected $status; /** - * Optional. Restictred and kicked only. Date when restrictions will be lifted for this user, unix time - * - * @var integer - */ - protected $untilDate; - - /** - * Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user - * - * @var bool - */ - protected $canBeEdited; - - /** - * Optional. Administrators only. True, if the administrator can change the chat title, photo and other settings - * - * @var bool - */ - protected $canChangeInfo; - - /** - * Optional. Administrators only. True, if the administrator can post in the channel, channels only - * - * @var bool - */ - protected $canPostMessages; - - /** - * Optional. Administrators only. True, if the administrator can edit messages of other users, channels only - * - * @var bool - */ - protected $canEditMessages; - - /** - * Optional. Administrators only. True, if the administrator can delete messages of other users - * - * @var bool - */ - protected $canDeleteMessages; - - /** - * Optional. Administrators only. True, if the administrator can invite new users to the chat - * - * @var bool - */ - protected $canInviteUsers; - - /** - * Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members - * - * @var bool - */ - protected $canRestrictMembers; - - /** - * Optional. Administrators only. True, if the administrator can pin messages, supergroups only - * - * @var bool - */ - protected $canPinMessages; - - /** - * Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own - * privileges or demote administrators that he has promoted, directly or indirectly - * (promoted by administrators that were appointed by the user) - * - * @var bool - */ - protected $canPromoteMembers; - - /** - * Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues - * - * @var bool - */ - protected $canSendMessages; - - /** - * Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes - * and voice notes, implies can_send_messages - * - * @var bool - */ - protected $canSendMediaMessages; - - /** - * Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, - * implies can_send_media_messages - * - * @var bool - */ - protected $canSendOtherMessages; - - /** - * Optional. Restricted only. True, if user may add web page previews to his messages, - * implies can_send_media_messages + * Information about the user * - * @var bool - */ - protected $canAddWebPagePreviews; - - /** - * @return User - */ - public function getUser() - { - return $this->user; - } - - /** - * @param User $user + * @var User */ - public function setUser($user) - { - $this->user = $user; - } + protected $user; /** * @return string @@ -180,6 +75,7 @@ public function getStatus() /** * @param string $status + * @return void */ public function setStatus($status) { @@ -187,226 +83,19 @@ public function setStatus($status) } /** - * @return int - */ - public function getUntilDate() - { - return $this->untilDate; - } - - /** - * @param int $untilDate - */ - public function setUntilDate($untilDate) - { - $this->untilDate = $untilDate; - } - - /** - * @return bool - */ - public function getCanBeEdited() - { - return $this->canBeEdited; - } - - /** - * @param bool $canBeEdited - */ - public function setCanBeEdited($canBeEdited) - { - $this->canBeEdited = $canBeEdited; - } - - /** - * @return bool - */ - public function getCanChangeInfo() - { - return $this->canChangeInfo; - } - - /** - * @param bool $canChangeInfo - */ - public function setCanChangeInfo($canChangeInfo) - { - $this->canChangeInfo = $canChangeInfo; - } - - /** - * @return bool - */ - public function getCanPostMessages() - { - return $this->canPostMessages; - } - - /** - * @param bool $canPostMessages - */ - public function setCanPostMessages($canPostMessages) - { - $this->canPostMessages = $canPostMessages; - } - - /** - * @return bool - */ - public function getCanEditMessages() - { - return $this->canEditMessages; - } - - /** - * @param bool $canEditMessages - */ - public function setCanEditMessages($canEditMessages) - { - $this->canEditMessages = $canEditMessages; - } - - /** - * @return bool - */ - public function getCanDeleteMessages() - { - return $this->canDeleteMessages; - } - - /** - * @param bool $canDeleteMessages - */ - public function setCanDeleteMessages($canDeleteMessages) - { - $this->canDeleteMessages = $canDeleteMessages; - } - - /** - * @return bool - */ - public function getCanInviteUsers() - { - return $this->canInviteUsers; - } - - /** - * @param bool $canInviteUsers - */ - public function setCanInviteUsers($canInviteUsers) - { - $this->canInviteUsers = $canInviteUsers; - } - - /** - * @return bool - */ - public function getCanRestrictMembers() - { - return $this->canRestrictMembers; - } - - /** - * @param bool $canRestrictMembers - */ - public function setCanRestrictMembers($canRestrictMembers) - { - $this->canRestrictMembers = $canRestrictMembers; - } - - /** - * @return bool - */ - public function getCanPinMessages() - { - return $this->canPinMessages; - } - - /** - * @param bool $canPinMessages - */ - public function setCanPinMessages($canPinMessages) - { - $this->canPinMessages = $canPinMessages; - } - - /** - * @return bool - */ - public function getCanPromoteMembers() - { - return $this->canPromoteMembers; - } - - /** - * @param bool $canPromoteMembers - */ - public function setCanPromoteMembers($canPromoteMembers) - { - $this->canPromoteMembers = $canPromoteMembers; - } - - /** - * @return bool - */ - public function getCanSendMessages() - { - return $this->canSendMessages; - } - - /** - * @param bool $canSendMessages - */ - public function setCanSendMessages($canSendMessages) - { - $this->canSendMessages = $canSendMessages; - } - - /** - * @return bool - */ - public function getCanSendMediaMessages() - { - return $this->canSendMediaMessages; - } - - /** - * @param bool $canSendMediaMessages - */ - public function setCanSendMediaMessages($canSendMediaMessages) - { - $this->canSendMediaMessages = $canSendMediaMessages; - } - - /** - * @return bool - */ - public function getCanSendOtherMessages() - { - return $this->canSendOtherMessages; - } - - /** - * @param bool $canSendOtherMessages - */ - public function setCanSendOtherMessages($canSendOtherMessages) - { - $this->canSendOtherMessages = $canSendOtherMessages; - } - - /** - * @return bool + * @return User */ - public function getCanAddWebPagePreviews() + public function getUser() { - return $this->canAddWebPagePreviews; + return $this->user; } /** - * @param bool $canAddWebPagePreviews + * @param User $user + * @return void */ - public function setCanAddWebPagePreviews($canAddWebPagePreviews) + public function setUser($user) { - $this->canAddWebPagePreviews = $canAddWebPagePreviews; + $this->user = $user; } } diff --git a/src/Types/ChatMemberAdministrator.php b/src/Types/ChatMemberAdministrator.php new file mode 100644 index 00000000..0ee56bf7 --- /dev/null +++ b/src/Types/ChatMemberAdministrator.php @@ -0,0 +1,458 @@ + true, + 'user' => User::class, + 'can_be_edited' => true, + 'is_anonymous' => true, + 'can_manage_chat' => true, + 'can_delete_messages' => true, + 'can_manage_video_chats' => true, + 'can_restrict_members' => true, + 'can_promote_members' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_post_stories' => true, + 'can_edit_stories' => true, + 'can_delete_stories' => true, + 'can_post_messages' => true, + 'can_edit_messages' => true, + 'can_pin_messages' => true, + 'can_manage_topics' => true, + 'custom_title' => true, + ]; + + /** + * True, if the bot is allowed to edit administrator privileges of that user + * + * @var bool + */ + protected $canBeEdited; + + /** + * True, if the user's presence in the chat is hidden + * + * @var bool + */ + protected $isAnonymous; + + /** + * True, if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode + * + * @var bool + */ + protected $canManageChat; + + /** + * True, if the administrator can delete messages of other users + * + * @var bool + */ + protected $canDeleteMessages; + + /** + * True, if the administrator can manage video chats + * + * @var bool + */ + protected $canManageVideoChats; + + /** + * True, if the administrator can restrict, ban or unban chat members, or access supergroup statistics + * + * @var bool + */ + protected $canRestrictMembers; + + /** + * True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly + * + * @var bool + */ + protected $canPromoteMembers; + + /** + * True, if the user is allowed to change the chat title, photo and other settings + * + * @var bool + */ + protected $canChangeInfo; + + /** + * True, if the user is allowed to invite new users to the chat + * + * @var bool + */ + protected $canInviteUsers; + + /** + * True, if the administrator can post stories to the chat + * + * @var bool|null + */ + protected $canPostStories; + + /** + * True, if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat's story archive + * + * @var bool|null + */ + protected $canEditStories; + + /** + * True, if the administrator can delete stories posted by other users + * + * @var bool|null + */ + protected $canDeleteStories; + + /** + * Optional. True, if the administrator can post messages in the channel, or access channel statistics; for channels only + * + * @var bool|null + */ + protected $canPostMessages; + + /** + * Optional. True, if the administrator can edit messages of other users and can pin messages; for channels only + * + * @var bool|null + */ + protected $canEditMessages; + + /** + * Optional. True, if the user is allowed to pin messages; for groups and supergroups only + * + * @var bool|null + */ + protected $canPinMessages; + + /** + * Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only + * + * @var bool|null + */ + protected $canManageTopics; + + /** + * Optional. Custom title for this user + * + * @var string|null + */ + protected $customTitle; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return bool + */ + public function canBeEdited() + { + return $this->canBeEdited; + } + + /** + * @param bool $canBeEdited + * @return void + */ + public function setCanBeEdited($canBeEdited) + { + $this->canBeEdited = $canBeEdited; + } + + /** + * @return bool + */ + public function isAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + * @return void + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return bool + */ + public function canManageChat() + { + return $this->canManageChat; + } + + /** + * @param bool $canManageChat + * @return void + */ + public function setCanManageChat($canManageChat) + { + $this->canManageChat = $canManageChat; + } + + /** + * @return bool + */ + public function canDeleteMessages() + { + return $this->canDeleteMessages; + } + + /** + * @param bool $canDeleteMessages + * @return void + */ + public function setCanDeleteMessages($canDeleteMessages) + { + $this->canDeleteMessages = $canDeleteMessages; + } + + /** + * @return bool + */ + public function canManageVideoChats() + { + return $this->canManageVideoChats; + } + + /** + * @param bool $canManageVideoChats + * @return void + */ + public function setCanManageVideoChats($canManageVideoChats) + { + $this->canManageVideoChats = $canManageVideoChats; + } + + /** + * @return bool + */ + public function canRestrictMembers() + { + return $this->canRestrictMembers; + } + + /** + * @param bool $canRestrictMembers + * @return void + */ + public function setCanRestrictMembers($canRestrictMembers) + { + $this->canRestrictMembers = $canRestrictMembers; + } + + /** + * @return bool + */ + public function canPromoteMembers() + { + return $this->canPromoteMembers; + } + + /** + * @param bool $canPromoteMembers + * @return void + */ + public function setCanPromoteMembers($canPromoteMembers) + { + $this->canPromoteMembers = $canPromoteMembers; + } + + /** + * @return bool + */ + public function canChangeInfo() + { + return $this->canChangeInfo; + } + + /** + * @param bool $canChangeInfo + * @return void + */ + public function setCanChangeInfo($canChangeInfo) + { + $this->canChangeInfo = $canChangeInfo; + } + + /** + * @return bool + */ + public function canInviteUsers() + { + return $this->canInviteUsers; + } + + /** + * @param bool $canInviteUsers + * @return void + */ + public function setCanInviteUsers($canInviteUsers) + { + $this->canInviteUsers = $canInviteUsers; + } + + /** + * @return bool|null + */ + public function canPostStories() + { + return $this->canPostStories; + } + + /** + * @param bool|null $canPostStories + * @return void + */ + public function setCanPostStories($canPostStories) + { + $this->canPostStories = $canPostStories; + } + + /** + * @return bool|null + */ + public function canEditStories() + { + return $this->canEditStories; + } + + /** + * @param bool|null $canEditStories + * @return void + */ + public function setCanEditStories($canEditStories) + { + $this->canEditStories = $canEditStories; + } + + /** + * @return bool|null + */ + public function canDeleteStories() + { + return $this->canDeleteStories; + } + + /** + * @param bool|null $canDeleteStories + * @return void + */ + public function setCanDeleteStories($canDeleteStories) + { + $this->canDeleteStories = $canDeleteStories; + } + + /** + * @return bool|null + */ + public function canPostMessages() + { + return $this->canPostMessages; + } + + /** + * @param bool|null $canPostMessages + * @return void + */ + public function setCanPostMessages($canPostMessages) + { + $this->canPostMessages = $canPostMessages; + } + + /** + * @return bool|null + */ + public function canEditMessages() + { + return $this->canEditMessages; + } + + /** + * @param bool|null $canEditMessages + * @return void + */ + public function setCanEditMessages($canEditMessages) + { + $this->canEditMessages = $canEditMessages; + } + + /** + * @return bool|null + */ + public function canPinMessages() + { + return $this->canPinMessages; + } + + /** + * @param bool|null $canPinMessages + * @return void + */ + public function setCanPinMessages($canPinMessages) + { + $this->canPinMessages = $canPinMessages; + } + + /** + * @return bool|null + */ + public function canManageTopics() + { + return $this->canManageTopics; + } + + /** + * @param bool|null $canManageTopics + * @return void + */ + public function setCanManageTopics($canManageTopics) + { + $this->canManageTopics = $canManageTopics; + } + + /** + * @return string|null + */ + public function getCustomTitle() + { + return $this->customTitle; + } + + /** + * @param string|null $customTitle + * @return void + */ + public function setCustomTitle($customTitle) + { + $this->customTitle = $customTitle; + } +} diff --git a/src/Types/ChatMemberBanned.php b/src/Types/ChatMemberBanned.php new file mode 100644 index 00000000..17647318 --- /dev/null +++ b/src/Types/ChatMemberBanned.php @@ -0,0 +1,58 @@ + true, + 'user' => User::class, + 'until_date' => true, + ]; + + /** + * Date when restrictions will be lifted for this user; Unix time. If 0, then the user is banned forever + * + * @var int + */ + protected $untilDate; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return int + */ + public function getUntilDate() + { + return $this->untilDate; + } + + /** + * @param int $untilDate + * @return void + */ + public function setUntilDate($untilDate) + { + $this->untilDate = $untilDate; + } +} diff --git a/src/Types/ChatMemberLeft.php b/src/Types/ChatMemberLeft.php new file mode 100644 index 00000000..85c96feb --- /dev/null +++ b/src/Types/ChatMemberLeft.php @@ -0,0 +1,23 @@ +map($data); + + return $instance; + } +} diff --git a/src/Types/ChatMemberMember.php b/src/Types/ChatMemberMember.php new file mode 100644 index 00000000..ae1a8678 --- /dev/null +++ b/src/Types/ChatMemberMember.php @@ -0,0 +1,23 @@ +map($data); + + return $instance; + } +} diff --git a/src/Types/ChatMemberOwner.php b/src/Types/ChatMemberOwner.php new file mode 100644 index 00000000..e6c6520c --- /dev/null +++ b/src/Types/ChatMemberOwner.php @@ -0,0 +1,83 @@ + true, + 'user' => User::class, + 'is_anonymous' => true, + 'custom_title' => true, + ]; + + /** + * True, if the user's presence in the chat is hidden + * + * @var bool + */ + protected $isAnonymous; + + /** + * Optional. Custom title for this user + * + * @var string|null + */ + protected $customTitle; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return bool + */ + public function isAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + * @return void + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return string|null + */ + public function getCustomTitle() + { + return $this->customTitle; + } + + /** + * @param string|null $customTitle + * @return void + */ + public function setCustomTitle($customTitle) + { + $this->customTitle = $customTitle; + } +} diff --git a/src/Types/ChatMemberRestricted.php b/src/Types/ChatMemberRestricted.php new file mode 100644 index 00000000..386305b4 --- /dev/null +++ b/src/Types/ChatMemberRestricted.php @@ -0,0 +1,433 @@ + true, + 'user' => User::class, + 'is_member' => true, + 'can_send_messages' => true, + 'can_send_audios' => true, + 'can_send_documents' => true, + 'can_send_photos' => true, + 'can_send_videos' => true, + 'can_send_video_notes' => true, + 'can_send_voice_notes' => true, + 'can_send_polls' => true, + 'can_send_other_messages' => true, + 'can_add_web_page_previews' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_pin_messages' => true, + 'can_manage_topics' => true, + 'until_date' => true, + ]; + + /** + * True, if the user is a member of the chat at the moment of the request + * + * @var bool + */ + protected $isMember; + + /** + * True, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues + * + * @var bool + */ + protected $canSendMessages; + + /** + * True, if the user is allowed to send audios + * + * @var bool + */ + protected $canSendAudios; + + /** + * True, if the user is allowed to send documents + * + * @var bool + */ + protected $canSendDocuments; + + /** + * True, if the user is allowed to send photos + * + * @var bool + */ + protected $canSendPhotos; + + /** + * True, if the user is allowed to send videos + * + * @var bool + */ + protected $canSendVideos; + + /** + * True, if the user is allowed to send video notes + * + * @var bool + */ + protected $canSendVideoNotes; + + /** + * True, if the user is allowed to send voice notes + * + * @var bool + */ + protected $canSendVoiceNotes; + + /** + * True, if the user is allowed to send polls + * + * @var bool + */ + protected $canSendPolls; + + /** + * True, if the user is allowed to send animations, games, stickers and use inline bots + * + * @var bool + */ + protected $canSendOtherMessages; + + /** + * True, if the user is allowed to add web page previews to their messages + * + * @var bool + */ + protected $canAddWebPagePreviews; + + /** + * True, if the user is allowed to change the chat title, photo and other settings + * + * @var bool + */ + protected $canChangeInfo; + + /** + * True, if the user is allowed to invite new users to the chat + * + * @var bool + */ + protected $canInviteUsers; + + /** + * True, if the user is allowed to pin messages + * + * @var bool + */ + protected $canPinMessages; + + /** + * True, if the user is allowed to create forum topics + * + * @var bool + */ + protected $canManageTopics; + + /** + * Date when restrictions will be lifted for this user; Unix time. If 0, then the user is restricted forever + * + * @var int + */ + protected $untilDate; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return bool + */ + public function isMember() + { + return $this->isMember; + } + + /** + * @param bool $isMember + * @return void + */ + public function setIsMember($isMember) + { + $this->isMember = $isMember; + } + + /** + * @return bool + */ + public function canSendMessages() + { + return $this->canSendMessages; + } + + /** + * @param bool $canSendMessages + * @return void + */ + public function setCanSendMessages($canSendMessages) + { + $this->canSendMessages = $canSendMessages; + } + + /** + * @return bool + */ + public function canSendAudios() + { + return $this->canSendAudios; + } + + /** + * @param bool $canSendAudios + * @return void + */ + public function setCanSendAudios($canSendAudios) + { + $this->canSendAudios = $canSendAudios; + } + + /** + * @return bool + */ + public function canSendDocuments() + { + return $this->canSendDocuments; + } + + /** + * @param bool $canSendDocuments + * @return void + */ + public function setCanSendDocuments($canSendDocuments) + { + $this->canSendDocuments = $canSendDocuments; + } + + /** + * @return bool + */ + public function canSendPhotos() + { + return $this->canSendPhotos; + } + + /** + * @param bool $canSendPhotos + * @return void + */ + public function setCanSendPhotos($canSendPhotos) + { + $this->canSendPhotos = $canSendPhotos; + } + + /** + * @return bool + */ + public function canSendVideos() + { + return $this->canSendVideos; + } + + /** + * @param bool $canSendVideos + * @return void + */ + public function setCanSendVideos($canSendVideos) + { + $this->canSendVideos = $canSendVideos; + } + + /** + * @return bool + */ + public function canSendVideoNotes() + { + return $this->canSendVideoNotes; + } + + /** + * @param bool $canSendVideoNotes + * @return void + */ + public function setCanSendVideoNotes($canSendVideoNotes) + { + $this->canSendVideoNotes = $canSendVideoNotes; + } + + /** + * @return bool + */ + public function canSendVoiceNotes() + { + return $this->canSendVoiceNotes; + } + + /** + * @param bool $canSendVoiceNotes + * @return void + */ + public function setCanSendVoiceNotes($canSendVoiceNotes) + { + $this->canSendVoiceNotes = $canSendVoiceNotes; + } + + /** + * @return bool + */ + public function canSendPolls() + { + return $this->canSendPolls; + } + + /** + * @param bool $canSendPolls + * @return void + */ + public function setCanSendPolls($canSendPolls) + { + $this->canSendPolls = $canSendPolls; + } + + /** + * @return bool + */ + public function canSendOtherMessages() + { + return $this->canSendOtherMessages; + } + + /** + * @param bool $canSendOtherMessages + * @return void + */ + public function setCanSendOtherMessages($canSendOtherMessages) + { + $this->canSendOtherMessages = $canSendOtherMessages; + } + + /** + * @return bool + */ + public function canAddWebPagePreviews() + { + return $this->canAddWebPagePreviews; + } + + /** + * @param bool $canAddWebPagePreviews + * @return void + */ + public function setCanAddWebPagePreviews($canAddWebPagePreviews) + { + $this->canAddWebPagePreviews = $canAddWebPagePreviews; + } + + /** + * @return bool + */ + public function canChangeInfo() + { + return $this->canChangeInfo; + } + + /** + * @param bool $canChangeInfo + * @return void + */ + public function setCanChangeInfo($canChangeInfo) + { + $this->canChangeInfo = $canChangeInfo; + } + + /** + * @return bool + */ + public function canInviteUsers() + { + return $this->canInviteUsers; + } + + /** + * @param bool $canInviteUsers + * @return void + */ + public function setCanInviteUsers($canInviteUsers) + { + $this->canInviteUsers = $canInviteUsers; + } + + /** + * @return bool + */ + public function canPinMessages() + { + return $this->canPinMessages; + } + + /** + * @param bool $canPinMessages + * @return void + */ + public function setCanPinMessages($canPinMessages) + { + $this->canPinMessages = $canPinMessages; + } + + /** + * @return bool + */ + public function canManageTopics() + { + return $this->canManageTopics; + } + + /** + * @param bool $canManageTopics + * @return void + */ + public function setCanManageTopics($canManageTopics) + { + $this->canManageTopics = $canManageTopics; + } + + /** + * @return int + */ + public function getUntilDate() + { + return $this->untilDate; + } + + /** + * @param int $untilDate + * @return void + */ + public function setUntilDate($untilDate) + { + $this->untilDate = $untilDate; + } +} diff --git a/src/Types/ChatMemberUpdated.php b/src/Types/ChatMemberUpdated.php new file mode 100644 index 00000000..298f8169 --- /dev/null +++ b/src/Types/ChatMemberUpdated.php @@ -0,0 +1,234 @@ + Chat::class, + 'from' => User::class, + 'date' => true, + 'old_chat_member' => ChatMember::class, + 'new_chat_member' => ChatMember::class, + 'invite_link' => ChatInviteLink::class, + 'via_join_request' => true, + 'via_chat_folder_invite_link' => true, + ]; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * Chat the user belongs to + * + * @var Chat + */ + protected $chat; + + /** + * Performer of the action, which resulted in the change + * + * @var User + */ + protected $from; + + /** + * Date the change was done in Unix time + * + * @var int + */ + protected $date; + + /** + * Previous information about the chat member + * + * @var ChatMember + */ + protected $oldChatMember; + + /** + * New information about the chat member + * + * @var ChatMember + */ + protected $newChatMember; + + /** + * Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events only. + * + * @var ChatInviteLink|null + */ + protected $inviteLink; + + /** + * Optional. True, if the user joined the chat via a chat folder invite link + * + * @var bool|null + */ + protected $viaChatFolderInviteLink; + + /** + * Optional. True, if the user joined the chat after sending a direct join request without using an invite link and being approved by an administrator + * + * @var bool|null + */ + protected $viaJoinRequest; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + * @return void + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return ChatMember + */ + public function getOldChatMember() + { + return $this->oldChatMember; + } + + /** + * @param ChatMember $oldChatMember + * @return void + */ + public function setOldChatMember($oldChatMember) + { + $this->oldChatMember = $oldChatMember; + } + + /** + * @return ChatMember + */ + public function getNewChatMember() + { + return $this->newChatMember; + } + + /** + * @param ChatMember $newChatMember + * @return void + */ + public function setNewChatMember($newChatMember) + { + $this->newChatMember = $newChatMember; + } + + /** + * @return ChatInviteLink|null + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param ChatInviteLink|null $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } + + /** + * @return bool|null + */ + public function getViaChatFolderInviteLink() + { + return $this->viaChatFolderInviteLink; + } + + /** + * @param bool|null $viaChatFolderInviteLink + * @return void + */ + public function setViaChatFolderInviteLink($viaChatFolderInviteLink) + { + $this->viaChatFolderInviteLink = $viaChatFolderInviteLink; + } + + /** + * @return bool|null + */ + public function getViaJoinRequest() + { + return $this->viaJoinRequest; + } + + /** + * @param bool|null $viaJoinRequest + * @return void + */ + public function setViaJoinRequest($viaJoinRequest) + { + $this->viaJoinRequest = $viaJoinRequest; + } +} diff --git a/src/Types/ChatPermissions.php b/src/Types/ChatPermissions.php new file mode 100644 index 00000000..3e93d3d7 --- /dev/null +++ b/src/Types/ChatPermissions.php @@ -0,0 +1,228 @@ + true, + 'can_send_media_messages' => true, + 'can_send_polls' => true, + 'can_send_other_messages' => true, + 'can_add_web_page_previews' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_pin_messages' => true, + ]; + + /** + * Optional. True, if the user is allowed to send text messages, contacts, locations and venues + * + * @var bool|null + */ + protected $canSendMessages; + + /** + * Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, + * implies can_send_messages + * + * @var bool|null + */ + protected $canSendMediaMessages; + + /** + * Optional. True, if the user is allowed to send polls, implies can_send_messages + * + * @var bool|null + */ + protected $canSendPolls; + + /** + * Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, implies + * can_send_media_messages + * + * @var bool|null + */ + protected $canSendOtherMessages; + + /** + * Optional. True, if the user is allowed to add web page previews to their messages, implies + * can_send_media_messages + * + * @var bool|null + */ + protected $canAddWebPagePreviews; + + /** + * Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public + * supergroups + * + * @var bool|null + */ + protected $canChangeInfo; + + /** + * Optional. True, if the user is allowed to invite new users to the chat + * + * @var bool|null + */ + protected $canInviteUsers; + + /** + * Optional. True, if the user is allowed to pin messages. Ignored in public supergroups + * + * @var bool|null + */ + protected $canPinMessages; + + /** + * @return bool|null + */ + public function isCanSendMessages() + { + return $this->canSendMessages; + } + + /** + * @param bool $canSendMessages + * @return void + */ + public function setCanSendMessages($canSendMessages) + { + $this->canSendMessages = $canSendMessages; + } + + /** + * @return bool|null + */ + public function isCanSendMediaMessages() + { + return $this->canSendMediaMessages; + } + + /** + * @param bool $canSendMediaMessages + * @return void + */ + public function setCanSendMediaMessages($canSendMediaMessages) + { + $this->canSendMediaMessages = $canSendMediaMessages; + } + + /** + * @return bool|null + */ + public function isCanSendPolls() + { + return $this->canSendPolls; + } + + /** + * @param bool $canSendPolls + * @return void + */ + public function setCanSendPolls($canSendPolls) + { + $this->canSendPolls = $canSendPolls; + } + + /** + * @return bool|null + */ + public function isCanSendOtherMessages() + { + return $this->canSendOtherMessages; + } + + /** + * @param bool $canSendOtherMessages + * @return void + */ + public function setCanSendOtherMessages($canSendOtherMessages) + { + $this->canSendOtherMessages = $canSendOtherMessages; + } + + /** + * @return bool|null + */ + public function isCanAddWebPagePreviews() + { + return $this->canAddWebPagePreviews; + } + + /** + * @param bool $canAddWebPagePreviews + * @return void + */ + public function setCanAddWebPagePreviews($canAddWebPagePreviews) + { + $this->canAddWebPagePreviews = $canAddWebPagePreviews; + } + + /** + * @return bool|null + */ + public function isCanChangeInfo() + { + return $this->canChangeInfo; + } + + /** + * @param bool $canChangeInfo + * @return void + */ + public function setCanChangeInfo($canChangeInfo) + { + $this->canChangeInfo = $canChangeInfo; + } + + /** + * @return bool|null + */ + public function isCanInviteUsers() + { + return $this->canInviteUsers; + } + + /** + * @param bool $canInviteUsers + * @return void + */ + public function setCanInviteUsers($canInviteUsers) + { + $this->canInviteUsers = $canInviteUsers; + } + + /** + * @return bool|null + */ + public function isCanPinMessages() + { + return $this->canPinMessages; + } + + /** + * @param bool $canPinMessages + * @return void + */ + public function setCanPinMessages($canPinMessages) + { + $this->canPinMessages = $canPinMessages; + } +} diff --git a/src/Types/ChatPhoto.php b/src/Types/ChatPhoto.php index 29a8d8f1..7fbabceb 100644 --- a/src/Types/ChatPhoto.php +++ b/src/Types/ChatPhoto.php @@ -11,16 +11,18 @@ class ChatPhoto extends BaseType * * @var array */ - static protected $requiredParams = ['small_file_id', 'big_file_id']; + protected static $requiredParams = ['small_file_id', 'big_file_id']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'small_file_id' => true, + 'small_file_unique_id' => true, 'big_file_id' => true, + 'big_file_unique_id' => true, ]; /** @@ -30,6 +32,13 @@ class ChatPhoto extends BaseType */ protected $smallFileId; + /** + * 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. + * + * @var string + */ + protected $smallFileUniqueId; + /** * Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download. * @@ -37,6 +46,13 @@ class ChatPhoto extends BaseType */ protected $bigFileId; + /** + * 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. + * + * @var string + */ + protected $bigFileUniqueId; + /** * @return string */ @@ -47,12 +63,30 @@ public function getSmallFileId() /** * @param string $smallFileId + * @return void */ public function setSmallFileId($smallFileId) { $this->smallFileId = $smallFileId; } + /** + * @return string + */ + public function getSmallFileUniqueId() + { + return $this->smallFileUniqueId; + } + + /** + * @param string $smallFileUniqueId + * @return void + */ + public function setSmallFileUniqueId($smallFileUniqueId) + { + $this->smallFileUniqueId = $smallFileUniqueId; + } + /** * @return string */ @@ -63,9 +97,27 @@ public function getBigFileId() /** * @param string $bigFileId + * @return void */ public function setBigFileId($bigFileId) { $this->bigFileId = $bigFileId; } + + /** + * @return string + */ + public function getBigFileUniqueId() + { + return $this->bigFileUniqueId; + } + + /** + * @param string $bigFileUniqueId + * @return void + */ + public function setBigFileUniqueId($bigFileUniqueId) + { + $this->bigFileUniqueId = $bigFileUniqueId; + } } diff --git a/src/Types/ChatShared.php b/src/Types/ChatShared.php new file mode 100644 index 00000000..fc28a422 --- /dev/null +++ b/src/Types/ChatShared.php @@ -0,0 +1,156 @@ + true, + 'chat_id' => true, + 'title' => true, + 'username' => true, + 'photo' => ArrayOfPhotoSize::class, + ]; + + /** + * Identifier of the request + * + * @var int + */ + protected $requestId; + + /** + * Identifier of the shared chat + * + * @var int + */ + protected $chatId; + + /** + * Optional. Title of the chat + * + * @var string|null + */ + protected $title; + + /** + * Optional. Username of the chat + * + * @var string|null + */ + protected $username; + + /** + * Optional. Available sizes of the chat photo + * Array of \TelegramBot\Api\Types\PhotoSize + * + * @var array|null + */ + protected $photo; + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @param int $requestId + * @return void + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + } + + /** + * @return int + */ + public function getChatId() + { + return $this->chatId; + } + + /** + * @param int $chatId + * @return void + */ + public function setChatId($chatId) + { + $this->chatId = $chatId; + } + + /** + * @return string|null + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string|null $title + * @return void + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string|null + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param string|null $username + * @return void + */ + public function setUsername($username) + { + $this->username = $username; + } + + /** + * @return array|null + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param array|null $photo + * @return void + */ + public function setPhoto($photo) + { + $this->photo = $photo; + } +} diff --git a/src/Types/Contact.php b/src/Types/Contact.php index e9c5564a..eb4d671f 100644 --- a/src/Types/Contact.php +++ b/src/Types/Contact.php @@ -7,7 +7,7 @@ /** * Class Contact - * This object represents a sticker. + * This object represents a phone contact. * * @package TelegramBot\Api\Types */ @@ -18,18 +18,19 @@ class Contact extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['phone_number', 'first_name']; + protected static $requiredParams = ['phone_number', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'phone_number' => true, 'first_name' => true, 'last_name' => true, - 'user_id' => true + 'user_id' => true, + 'vcard' => true, ]; /** @@ -49,17 +50,24 @@ class Contact extends BaseType implements TypeInterface /** * Optional. Contact's last name * - * @var string + * @var string|null */ protected $lastName; /** * Optional. Contact's user identifier in Telegram * - * @var int + * @var int|null */ protected $userId; + /** + * Optional. Additional data about the contact in the form of a vCard + * + * @var string|null + */ + protected $vcard; + /** * @return string */ @@ -70,6 +78,7 @@ public function getFirstName() /** * @param string $firstName + * @return void */ public function setFirstName($firstName) { @@ -77,7 +86,7 @@ public function setFirstName($firstName) } /** - * @return string + * @return null|string */ public function getLastName() { @@ -86,6 +95,7 @@ public function getLastName() /** * @param string $lastName + * @return void */ public function setLastName($lastName) { @@ -102,6 +112,7 @@ public function getPhoneNumber() /** * @param string $phoneNumber + * @return void */ public function setPhoneNumber($phoneNumber) { @@ -109,7 +120,7 @@ public function setPhoneNumber($phoneNumber) } /** - * @return int + * @return int|null */ public function getUserId() { @@ -118,9 +129,27 @@ public function getUserId() /** * @param int $userId + * @return void */ public function setUserId($userId) { $this->userId = $userId; } + + /** + * @return null|string + */ + public function getVCard() + { + return $this->vcard; + } + + /** + * @param string $vcard + * @return void + */ + public function setVCard($vcard) + { + $this->vcard = $vcard; + } } diff --git a/src/Types/Dice.php b/src/Types/Dice.php new file mode 100644 index 00000000..7ebde544 --- /dev/null +++ b/src/Types/Dice.php @@ -0,0 +1,80 @@ + true, + 'value' => true + ]; + + /** + * Emoji on which the dice throw animation is based + * + * @var string + */ + protected $emoji; + + /** + * Value of the dice, 1-6 for “🎲” and “🎯” base emoji, 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji + * + * @var int + */ + protected $value; + + /** + * @return string + */ + public function getEmoji() + { + return $this->emoji; + } + + /** + * @param string $emoji + * @return void + */ + public function setEmoji($emoji) + { + $this->emoji = $emoji; + } + + /** + * @return int + */ + public function getValue() + { + return $this->value; + } + + /** + * @param int $value + * @return void + */ + public function setValue($value) + { + $this->value = $value; + } +} diff --git a/src/Types/Document.php b/src/Types/Document.php index d84d2c49..8b067f68 100644 --- a/src/Types/Document.php +++ b/src/Types/Document.php @@ -8,7 +8,7 @@ /** * Class Document - * This object represents a general file (as opposed to photos and audio files). + * This object represents a general file (as opposed to photos, voice messages and audio files). * Telegram users can send files of any type of up to 1.5 GB in size. * * @package TelegramBot\Api\Types @@ -20,9 +20,10 @@ class Document extends BaseType implements TypeInterface * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, - 'thumb' => PhotoSize::class, + 'file_unique_id' => true, + 'thumbnail' => PhotoSize::class, 'file_name' => true, 'mime_type' => true, 'file_size' => true @@ -33,7 +34,7 @@ class Document extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id']; + protected static $requiredParams = ['file_id', 'file_unique_id']; /** * Unique identifier for this file @@ -43,30 +44,37 @@ class Document extends BaseType implements TypeInterface protected $fileId; /** - * Document thumbnail as defined by sender + * 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. * - * @var PhotoSize + * @var string + */ + protected $fileUniqueId; + + /** + * Optional. Document thumbnail as defined by sender + * + * @var PhotoSize|null */ - protected $thumb; + protected $thumbnail; /** * Optional. Original filename as defined by sender * - * @var string + * @var string|null */ protected $fileName; /** * Optional. MIME type of the file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** - * Optional. File size + * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. * - * @var int + * @var int|null */ protected $fileSize; @@ -80,6 +88,7 @@ public function getFileId() /** * @param string $fileId + * @return void */ public function setFileId($fileId) { @@ -89,43 +98,78 @@ public function setFileId($fileId) /** * @return string */ - public function getFileName() + public function getFileUniqueId() { - return $this->fileName; + return $this->fileUniqueId; } /** - * @param string $fileName + * @param string $fileUniqueId + * @return void */ - public function setFileName($fileName) + public function setFileUniqueId($fileUniqueId) { - $this->fileName = $fileName; + $this->fileUniqueId = $fileUniqueId; } /** - * @return int + * @return PhotoSize|null */ - public function getFileSize() + public function getThumbnail() { - return $this->fileSize; + return $this->thumbnail; } /** - * @param int $fileSize + * @param PhotoSize|null $thumbnail + * @return void + */ + public function setThumbnail($thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method * - * @throws InvalidArgumentException + * @return PhotoSize|null */ - public function setFileSize($fileSize) + public function getThumb() { - if (is_integer($fileSize)) { - $this->fileSize = $fileSize; - } else { - throw new InvalidArgumentException(); - } + return $this->getThumbnail(); } /** - * @return string + * @deprecated use setThumbnail method + * + * @param PhotoSize $thumb + * + * @return void + */ + public function setThumb($thumb) + { + $this->setThumbnail($thumb); + } + + /** + * @return string|null + */ + public function getFileName() + { + return $this->fileName; + } + + /** + * @param string|null $fileName + * @return void + */ + public function setFileName($fileName) + { + $this->fileName = $fileName; + } + + /** + * @return string|null */ public function getMimeType() { @@ -133,7 +177,8 @@ public function getMimeType() } /** - * @param string $mimeType + * @param string|null $mimeType + * @return void */ public function setMimeType($mimeType) { @@ -141,18 +186,24 @@ public function setMimeType($mimeType) } /** - * @return PhotoSize + * @return int|null */ - public function getThumb() + public function getFileSize() { - return $this->thumb; + return $this->fileSize; } /** - * @param PhotoSize $thumb + * @param int|null $fileSize + * @return void + * @throws InvalidArgumentException */ - public function setThumb(PhotoSize $thumb) + public function setFileSize($fileSize) { - $this->thumb = $thumb; + if (is_integer($fileSize) || is_null($fileSize)) { + $this->fileSize = $fileSize; + } else { + throw new InvalidArgumentException(); + } } } diff --git a/src/Types/ExternalReplyInfo.php b/src/Types/ExternalReplyInfo.php new file mode 100644 index 00000000..3afe124b --- /dev/null +++ b/src/Types/ExternalReplyInfo.php @@ -0,0 +1,606 @@ + MessageOrigin::class, + 'chat' => Chat::class, + 'message_id' => true, + 'link_preview_options' => LinkPreviewOptions::class, + 'animation' => Animation::class, + 'audio' => Audio::class, + 'document' => Document::class, + 'photo' => ArrayOfPhotoSize::class, + 'sticker' => Sticker::class, + 'story' => Story::class, + 'video' => Video::class, + 'video_note' => VideoNote::class, + 'voice' => Voice::class, + 'has_media_spoiler' => true, + 'contact' => Contact::class, + 'dice' => Dice::class, + 'game' => Game::class, + 'giveaway' => Giveaway::class, + 'giveaway_winners' => GiveawayWinners::class, + 'invoice' => Invoice::class, + 'location' => Location::class, + 'poll' => Poll::class, + 'venue' => Venue::class, + ]; + + /** + * Origin of the message replied to by the given message + * + * @var MessageOrigin + */ + protected $origin; + + /** + * Optional. Chat the original message belongs to. Available only if the chat is a supergroup or a channel. + * + * @var Chat|null + */ + protected $chat; + + /** + * Optional. Unique message identifier inside the original chat. Available only if the original chat is a supergroup or a channel. + * + * @var int|null + */ + protected $messageId; + + /** + * Optional. Options used for link preview generation for the original message, if it is a text message + * + * @var LinkPreviewOptions|null + */ + protected $linkPreviewOptions; + + /** + * Optional. Message is an animation, information about the animation + * + * @var Animation|null + */ + protected $animation; + + /** + * Optional. Message is an audio file, information about the file + * + * @var Audio|null + */ + protected $audio; + + /** + * Optional. Message is a general file, information about the file + * + * @var Document|null + */ + protected $document; + + /** + * Optional. Message is a photo, available sizes of the photo + * + * @var array|null + */ + protected $photo; + + /** + * Optional. Message is a sticker, information about the sticker + * + * @var Sticker|null + */ + protected $sticker; + + /** + * Optional. Message is a forwarded story + * + * @var Story|null + */ + protected $story; + + /** + * Optional. Message is a video, information about the video + * + * @var Video|null + */ + protected $video; + + /** + * Optional. Message is a video note, information about the video message + * + * @var VideoNote|null + */ + protected $videoNote; + + /** + * Optional. Message is a voice message, information about the file + * + * @var Voice|null + */ + protected $voice; + + /** + * Optional. True, if the message media is covered by a spoiler animation + * + * @var bool|null + */ + protected $hasMediaSpoiler; + + /** + * Optional. Message is a shared contact, information about the contact + * + * @var Contact|null + */ + protected $contact; + + /** + * Optional. Message is a dice with random value + * + * @var Dice|null + */ + protected $dice; + + /** + * Optional. Message is a game, information about the game + * + * @var Game|null + */ + protected $game; + + /** + * Optional. Message is a scheduled giveaway, information about the giveaway + * + * @var Giveaway|null + */ + protected $giveaway; + + /** + * Optional. A giveaway with public winners was completed + * + * @var GiveawayWinners|null + */ + protected $giveawayWinners; + + /** + * Optional. Message is an invoice for a payment, information about the invoice + * + * @var Invoice|null + */ + protected $invoice; + + /** + * Optional. Message is a shared location, information about the location + * + * @var Location|null + */ + protected $location; + + /** + * Optional. Message is a native poll, information about the poll + * + * @var Poll|null + */ + protected $poll; + + /** + * Optional. Message is a venue, information about the venue + * + * @var Venue|null + */ + protected $venue; + + /** + * @return MessageOrigin + */ + public function getOrigin() + { + return $this->origin; + } + + /** + * @param MessageOrigin $origin + * @return void + */ + public function setOrigin(MessageOrigin $origin) + { + $this->origin = $origin; + } + + /** + * @return Chat|null + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat|null $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int|null + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int|null $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } + + /** + * @return LinkPreviewOptions|null + */ + public function getLinkPreviewOptions() + { + return $this->linkPreviewOptions; + } + + /** + * @param LinkPreviewOptions|null $linkPreviewOptions + * @return void + */ + public function setLinkPreviewOptions($linkPreviewOptions) + { + $this->linkPreviewOptions = $linkPreviewOptions; + } + + /** + * @return Animation|null + */ + public function getAnimation() + { + return $this->animation; + } + + /** + * @param Animation|null $animation + * @return void + */ + public function setAnimation($animation) + { + $this->animation = $animation; + } + + /** + * @return Audio|null + */ + public function getAudio() + { + return $this->audio; + } + + /** + * @param Audio|null $audio + * @return void + */ + public function setAudio($audio) + { + $this->audio = $audio; + } + + /** + * @return Document|null + */ + public function getDocument() + { + return $this->document; + } + + /** + * @param Document|null $document + * @return void + */ + public function setDocument($document) + { + $this->document = $document; + } + + /** + * @return array|null + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param array|null $photo + * @return void + */ + public function setPhoto($photo) + { + $this->photo = $photo; + } + + /** + * @return Sticker|null + */ + public function getSticker() + { + return $this->sticker; + } + + /** + * @param Sticker|null $sticker + * @return void + */ + public function setSticker($sticker) + { + $this->sticker = $sticker; + } + + /** + * @return Story|null + */ + public function getStory() + { + return $this->story; + } + + /** + * @param Story|null $story + * @return void + */ + public function setStory($story) + { + $this->story = $story; + } + + /** + * @return Video|null + */ + public function getVideo() + { + return $this->video; + } + + /** + * @param Video|null $video + * @return void + */ + public function setVideo($video) + { + $this->video = $video; + } + + /** + * @return VideoNote|null + */ + public function getVideoNote() + { + return $this->videoNote; + } + + /** + * @param VideoNote|null $videoNote + * @return void + */ + public function setVideoNote($videoNote) + { + $this->videoNote = $videoNote; + } + + /** + * @return Voice|null + */ + public function getVoice() + { + return $this->voice; + } + + /** + * @param Voice|null $voice + * @return void + */ + public function setVoice($voice) + { + $this->voice = $voice; + } + + /** + * @return bool|null + */ + public function getHasMediaSpoiler() + { + return $this->hasMediaSpoiler; + } + + /** + * @param bool|null $hasMediaSpoiler + * @return void + */ + public function setHasMediaSpoiler($hasMediaSpoiler) + { + $this->hasMediaSpoiler = $hasMediaSpoiler; + } + + /** + * @return Contact|null + */ + public function getContact() + { + return $this->contact; + } + + /** + * @param Contact|null $contact + * @return void + */ + public function setContact($contact) + { + $this->contact = $contact; + } + + /** + * @return Dice|null + */ + public function getDice() + { + return $this->dice; + } + + /** + * @param Dice|null $dice + * @return void + */ + public function setDice($dice) + { + $this->dice = $dice; + } + + /** + * @return Game|null + */ + public function getGame() + { + return $this->game; + } + + /** + * @param Game|null $game + * @return void + */ + public function setGame($game) + { + $this->game = $game; + } + + /** + * @return Giveaway|null + */ + public function getGiveaway() + { + return $this->giveaway; + } + + /** + * @param Giveaway|null $giveaway + * @return void + */ + public function setGiveaway($giveaway) + { + $this->giveaway = $giveaway; + } + + /** + * @return GiveawayWinners|null + */ + public function getGiveawayWinners() + { + return $this->giveawayWinners; + } + + /** + * @param GiveawayWinners|null $giveawayWinners + * @return void + */ + public function setGiveawayWinners($giveawayWinners) + { + $this->giveawayWinners = $giveawayWinners; + } + + /** + * @return Invoice|null + */ + public function getInvoice() + { + return $this->invoice; + } + + /** + * @param Invoice|null $invoice + * @return void + */ + public function setInvoice($invoice) + { + $this->invoice = $invoice; + } + + /** + * @return Location|null + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param Location|null $location + * @return void + */ + public function setLocation($location) + { + $this->location = $location; + } + + /** + * @return Poll|null + */ + public function getPoll() + { + return $this->poll; + } + + /** + * @param Poll|null $poll + * @return void + */ + public function setPoll($poll) + { + $this->poll = $poll; + } + + /** + * @return Venue|null + */ + public function getVenue() + { + return $this->venue; + } + + /** + * @param Venue|null $venue + * @return void + */ + public function setVenue($venue) + { + $this->venue = $venue; + } +} diff --git a/src/Types/File.php b/src/Types/File.php index c1bccfa6..eb2c5232 100644 --- a/src/Types/File.php +++ b/src/Types/File.php @@ -22,15 +22,16 @@ class File extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id']; + protected static $requiredParams = ['file_id']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, + 'file_unique_id' => true, 'file_size' => true, 'file_path' => true ]; @@ -45,17 +46,24 @@ class File extends BaseType implements TypeInterface /** * Optional. File size, if known * - * @var int + * @var int|null */ protected $fileSize; /** * Optional. File path. Use https://api.telegram.org/file/bot/ to get the file. * - * @var string + * @var string|null */ protected $filePath; + /** + * 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. + * + * @var string + */ + protected $fileUniqueId; + /** * @return string */ @@ -66,6 +74,7 @@ public function getFileId() /** * @param string $fileId + * @return void */ public function setFileId($fileId) { @@ -73,7 +82,7 @@ public function setFileId($fileId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -81,8 +90,8 @@ public function getFileSize() } /** - * @param int $fileSize - * + * @param mixed $fileSize + * @return void * @throws InvalidArgumentException */ public function setFileSize($fileSize) @@ -95,7 +104,7 @@ public function setFileSize($fileSize) } /** - * @return string + * @return null|string */ public function getFilePath() { @@ -104,9 +113,27 @@ public function getFilePath() /** * @param string $filePath + * @return void */ public function setFilePath($filePath) { $this->filePath = $filePath; } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } } diff --git a/src/Types/ForceReply.php b/src/Types/ForceReply.php index 6dbd2d79..1cc04256 100644 --- a/src/Types/ForceReply.php +++ b/src/Types/ForceReply.php @@ -19,15 +19,16 @@ class ForceReply extends BaseType * * @var array */ - static protected $requiredParams = ['force_reply']; + protected static $requiredParams = ['force_reply']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'force_reply' => true, + 'input_field_placeholder' => true, 'selective' => true ]; @@ -38,24 +39,37 @@ class ForceReply extends BaseType */ protected $forceReply; + /** + * The placeholder to be shown in the input field when the reply is active; 1-64 characters + * + * @var string|null + */ + protected $inputFieldPlaceholder; + /** * Optional. Use this parameter if you want to show the keyboard to specific users only. * Targets: * 1) users that are @mentioned in the text of the Message object; * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. * - * @var bool + * @var bool|null */ protected $selective; - public function __construct($forceReply = true, $selective = null) + /** + * @param bool $forceReply + * @param bool|null $selective + * @param string|null $inputFieldPlaceholder + */ + public function __construct($forceReply = true, $selective = null, $inputFieldPlaceholder = null) { $this->forceReply = $forceReply; $this->selective = $selective; + $this->inputFieldPlaceholder = $inputFieldPlaceholder; } /** - * @return boolean + * @return bool */ public function isForceReply() { @@ -63,7 +77,8 @@ public function isForceReply() } /** - * @param boolean $forceReply + * @param bool $forceReply + * @return void */ public function setForceReply($forceReply) { @@ -71,7 +86,7 @@ public function setForceReply($forceReply) } /** - * @return boolean + * @return bool|null */ public function isSelective() { @@ -79,10 +94,28 @@ public function isSelective() } /** - * @param boolean $selective + * @param bool|null $selective + * @return void */ public function setSelective($selective) { $this->selective = $selective; } + + /** + * @param string|null $inputFieldPlaceholder + * @return void + */ + public function setInputFieldPlaceholder($inputFieldPlaceholder) + { + $this->inputFieldPlaceholder = $inputFieldPlaceholder; + } + + /** + * @return string|null + */ + public function getInputFieldPlaceholder() + { + return $this->inputFieldPlaceholder; + } } diff --git a/src/Types/ForumTopic.php b/src/Types/ForumTopic.php new file mode 100644 index 00000000..320e1aff --- /dev/null +++ b/src/Types/ForumTopic.php @@ -0,0 +1,131 @@ + + */ +class ForumTopic extends BaseType implements TypeInterface +{ + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['message_thread_id', 'name', 'icon_color']; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'message_thread_id' => true, + 'name' => true, + 'icon_color' => true, + 'icon_custom_emoji_id' => true, + ]; + + /** + * Unique identifier of the forum topic + * + * @var int + */ + protected $messageThreadId; + + /** + * Name of the topic + * + * @var string + */ + protected $name; + + /** + * Color of the topic icon in RGB format + * + * @var int + */ + protected $iconColor; + + /** + * Optional. Unique identifier of the custom emoji shown as the topic icon + * + * @var string|null + */ + protected $iconCustomEmojiId; + + /** + * @return int + */ + public function getMessageThreadId() + { + return $this->messageThreadId; + } + + /** + * @param int $messageThreadId + * @return void + */ + public function setMessageThreadId($messageThreadId) + { + $this->messageThreadId = $messageThreadId; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int + */ + public function getIconColor() + { + return $this->iconColor; + } + + /** + * @param int $iconColor + * @return void + */ + public function setIconColor($iconColor) + { + $this->iconColor = $iconColor; + } + + /** + * @return null|string + */ + public function getIconCustomEmojiId() + { + return $this->iconCustomEmojiId; + } + + /** + * @param string $iconCustomEmojiId + * @return void + */ + public function setIconCustomEmojiId($iconCustomEmojiId) + { + $this->iconCustomEmojiId = $iconCustomEmojiId; + } +} diff --git a/src/Types/ForumTopicClosed.php b/src/Types/ForumTopicClosed.php new file mode 100644 index 00000000..6dfcc1d5 --- /dev/null +++ b/src/Types/ForumTopicClosed.php @@ -0,0 +1,17 @@ + + */ +class ForumTopicClosed extends BaseType implements TypeInterface +{ +} diff --git a/src/Types/ForumTopicCreated.php b/src/Types/ForumTopicCreated.php new file mode 100644 index 00000000..f1da401c --- /dev/null +++ b/src/Types/ForumTopicCreated.php @@ -0,0 +1,106 @@ + + */ +class ForumTopicCreated extends BaseType implements TypeInterface +{ + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['name', 'icon_color']; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'name' => true, + 'icon_color' => true, + 'icon_custom_emoji_id' => true, + ]; + + /** + * Name of the forum topic + * + * @var string + */ + protected $name; + + /** + * Color of the forum topic + * + * @var int + */ + protected $iconColor; + + /** + * Optional. Unique identifier of the custom emoji shown as the topic icon + * + * @var string|null + */ + protected $iconCustomEmojiId; + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int + */ + public function getIconColor() + { + return $this->iconColor; + } + + /** + * @param int $iconColor + * @return void + */ + public function setIconColor($iconColor) + { + $this->iconColor = $iconColor; + } + + /** + * @return string|null + */ + public function getIconCustomEmojiId() + { + return $this->iconCustomEmojiId; + } + + /** + * @param string|null $iconCustomEmojiId + * @return void + */ + public function setIconCustomEmojiId($iconCustomEmojiId) + { + $this->iconCustomEmojiId = $iconCustomEmojiId; + } +} diff --git a/src/Types/ForumTopicEdited.php b/src/Types/ForumTopicEdited.php new file mode 100644 index 00000000..c51a9c25 --- /dev/null +++ b/src/Types/ForumTopicEdited.php @@ -0,0 +1,73 @@ + true, + 'icon_custom_emoji_id' => true, + ]; + + /** + * Optional. New name of the topic, if it was edited + * + * @var string|null + */ + protected $name; + + /** + * Optional. New identifier of the custom emoji shown as the topic icon, if it was edited; an empty string if the icon was removed + * + * @var string|null + */ + protected $iconCustomEmojiId; + + /** + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * @param string|null $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return string|null + */ + public function getIconCustomEmojiId() + { + return $this->iconCustomEmojiId; + } + + /** + * @param string|null $iconCustomEmojiId + * @return void + */ + public function setIconCustomEmojiId($iconCustomEmojiId) + { + $this->iconCustomEmojiId = $iconCustomEmojiId; + } +} diff --git a/src/Types/ForumTopicReopened.php b/src/Types/ForumTopicReopened.php new file mode 100644 index 00000000..2db4c65d --- /dev/null +++ b/src/Types/ForumTopicReopened.php @@ -0,0 +1,17 @@ + + */ +class ForumTopicReopened extends BaseType implements TypeInterface +{ +} diff --git a/src/Types/Game.php b/src/Types/Game.php new file mode 100644 index 00000000..ae5c417f --- /dev/null +++ b/src/Types/Game.php @@ -0,0 +1,174 @@ + true, + 'description' => true, + 'photo' => ArrayOfPhotoSize::class, + 'text' => true, + 'text_entities' => ArrayOfMessageEntity::class, + 'animation' => Animation::class + ]; + + /** + * Title of the game + * + * @var string + */ + protected $title; + + /** + * Description of the game + * + * @var string + */ + protected $description; + + /** + * Photo that will be displayed in the game message in chats + * + * @var PhotoSize[] + */ + protected $photo; + + /** + * Optional. Brief description of the game or high scores included in the game message + * + * @var string|null + */ + protected $text; + + /** + * Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. + * + * @var MessageEntity[]|null + */ + protected $textEntities; + + /** + * Optional. Animation that will be displayed in the game message in chats + * + * @var Animation|null + */ + protected $animation; + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * @return PhotoSize[] + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param PhotoSize[] $photo + */ + public function setPhoto(array $photo) + { + $this->photo = $photo; + } + + /** + * @return string|null + */ + public function getText() + { + return $this->text; + } + + /** + * @param string|null $text + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return MessageEntity[]|null + */ + public function getTextEntities() + { + return $this->textEntities; + } + + /** + * @param MessageEntity[]|null $textEntities + */ + public function setTextEntities($textEntities) + { + $this->textEntities = $textEntities; + } + + /** + * @return Animation|null + */ + public function getAnimation() + { + return $this->animation; + } + + /** + * @param Animation|null $animation + */ + public function setAnimation($animation) + { + $this->animation = $animation; + } +} diff --git a/src/Types/GeneralForumTopicHidden.php b/src/Types/GeneralForumTopicHidden.php new file mode 100644 index 00000000..3bbd25c2 --- /dev/null +++ b/src/Types/GeneralForumTopicHidden.php @@ -0,0 +1,10 @@ + true, + 'sticker' => Sticker::class, + 'star_count' => true, + 'upgrade_star_count' => true, + 'total_count' => true, + 'remaining_count' => true, + ]; + + protected $id; + protected $sticker; + protected $starCount; + protected $upgradeStarCount; + protected $totalCount; + protected $remainingCount; + + public function getId() + { + return $this->id; + } + + public function setId($id) + { + $this->id = $id; + } + + public function getSticker() + { + return $this->sticker; + } + + public function setSticker($sticker) + { + $this->sticker = $sticker; + } + + public function getStarCount() + { + return $this->starCount; + } + + public function setStarCount($starCount) + { + $this->starCount = $starCount; + } + + public function getUpgradeStarCount() + { + return $this->upgradeStarCount; + } + + public function setUpgradeStarCount($upgradeStarCount) + { + $this->upgradeStarCount = $upgradeStarCount; + } + + public function getTotalCount() + { + return $this->totalCount; + } + + public function setTotalCount($totalCount) + { + $this->totalCount = $totalCount; + } + + public function getRemainingCount() + { + return $this->remainingCount; + } + + public function setRemainingCount($remainingCount) + { + $this->remainingCount = $remainingCount; + } +} diff --git a/src/Types/GiftInfo.php b/src/Types/GiftInfo.php new file mode 100644 index 00000000..e91b1b2e --- /dev/null +++ b/src/Types/GiftInfo.php @@ -0,0 +1,111 @@ + Gift::class, + 'owned_gift_id' => true, + 'convert_star_count' => true, + 'prepaid_upgrade_star_count' => true, + 'can_be_upgraded' => true, + 'text' => true, + 'entities' => ArrayOfMessageEntity::class, + 'is_private' => true, + ]; + + protected $gift; + protected $ownedGiftId; + protected $convertStarCount; + protected $prepaidUpgradeStarCount; + protected $canBeUpgraded; + protected $text; + protected $entities; + protected $isPrivate; + + public function getGift() + { + return $this->gift; + } + + public function setGift($gift) + { + $this->gift = $gift; + } + + public function getOwnedGiftId() + { + return $this->ownedGiftId; + } + + public function setOwnedGiftId($ownedGiftId) + { + $this->ownedGiftId = $ownedGiftId; + } + + public function getConvertStarCount() + { + return $this->convertStarCount; + } + + public function setConvertStarCount($convertStarCount) + { + $this->convertStarCount = $convertStarCount; + } + + public function getPrepaidUpgradeStarCount() + { + return $this->prepaidUpgradeStarCount; + } + + public function setPrepaidUpgradeStarCount($prepaidUpgradeStarCount) + { + $this->prepaidUpgradeStarCount = $prepaidUpgradeStarCount; + } + + public function getCanBeUpgraded() + { + return $this->canBeUpgraded; + } + + public function setCanBeUpgraded($canBeUpgraded) + { + $this->canBeUpgraded = $canBeUpgraded; + } + + public function getText() + { + return $this->text; + } + + public function setText($text) + { + $this->text = $text; + } + + public function getEntities() + { + return $this->entities; + } + + public function setEntities($entities) + { + $this->entities = $entities; + } + + public function getIsPrivate() + { + return $this->isPrivate; + } + + public function setIsPrivate($isPrivate) + { + $this->isPrivate = $isPrivate; + } +} diff --git a/src/Types/Gifts.php b/src/Types/Gifts.php new file mode 100644 index 00000000..dc28bac0 --- /dev/null +++ b/src/Types/Gifts.php @@ -0,0 +1,27 @@ + ArrayOfGift::class, + ]; + + protected $gifts; + + public function getGifts() + { + return $this->gifts; + } + + public function setGifts($gifts) + { + $this->gifts = $gifts; + } +} diff --git a/src/Types/Giveaway.php b/src/Types/Giveaway.php new file mode 100644 index 00000000..55c385fc --- /dev/null +++ b/src/Types/Giveaway.php @@ -0,0 +1,230 @@ + ArrayOfChat::class, + 'winners_selection_date' => true, + 'winner_count' => true, + 'only_new_members' => true, + 'has_public_winners' => true, + 'prize_description' => true, + 'country_codes' => true, + 'premium_subscription_month_count' => true, + ]; + + /** + * The list of chats which the user must join to participate in the giveaway + * + * @var array + */ + protected $chats; + + /** + * Point in time (Unix timestamp) when winners of the giveaway will be selected + * + * @var int + */ + protected $winnersSelectionDate; + + /** + * The number of users which are supposed to be selected as winners of the giveaway + * + * @var int + */ + protected $winnerCount; + + /** + * Optional. True, if only users who join the chats after the giveaway started should be eligible to win + * + * @var bool|null + */ + protected $onlyNewMembers; + + /** + * Optional. True, if the list of giveaway winners will be visible to everyone + * + * @var bool|null + */ + protected $hasPublicWinners; + + /** + * Optional. Description of additional giveaway prize + * + * @var string|null + */ + protected $prizeDescription; + + /** + * 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. + * + * @var array|null + */ + protected $countryCodes; + + /** + * Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for + * + * @var int|null + */ + protected $premiumSubscriptionMonthCount; + + /** + * @return array + */ + public function getChats() + { + return $this->chats; + } + + /** + * @param array $chats + * @return void + */ + public function setChats($chats) + { + $this->chats = $chats; + } + + /** + * @return int + */ + public function getWinnersSelectionDate() + { + return $this->winnersSelectionDate; + } + + /** + * @param int $winnersSelectionDate + * @return void + */ + public function setWinnersSelectionDate($winnersSelectionDate) + { + $this->winnersSelectionDate = $winnersSelectionDate; + } + + /** + * @return int + */ + public function getWinnerCount() + { + return $this->winnerCount; + } + + /** + * @param int $winnerCount + * @return void + */ + public function setWinnerCount($winnerCount) + { + $this->winnerCount = $winnerCount; + } + + /** + * @return bool|null + */ + public function getOnlyNewMembers() + { + return $this->onlyNewMembers; + } + + /** + * @param bool|null $onlyNewMembers + * @return void + */ + public function setOnlyNewMembers($onlyNewMembers) + { + $this->onlyNewMembers = $onlyNewMembers; + } + + /** + * @return bool|null + */ + public function getHasPublicWinners() + { + return $this->hasPublicWinners; + } + + /** + * @param bool|null $hasPublicWinners + * @return void + */ + public function setHasPublicWinners($hasPublicWinners) + { + $this->hasPublicWinners = $hasPublicWinners; + } + + /** + * @return string|null + */ + public function getPrizeDescription() + { + return $this->prizeDescription; + } + + /** + * @param string|null $prizeDescription + * @return void + */ + public function setPrizeDescription($prizeDescription) + { + $this->prizeDescription = $prizeDescription; + } + + /** + * @return array|null + */ + public function getCountryCodes() + { + return $this->countryCodes; + } + + /** + * @param array|null $countryCodes + * @return void + */ + public function setCountryCodes($countryCodes) + { + $this->countryCodes = $countryCodes; + } + + /** + * @return int|null + */ + public function getPremiumSubscriptionMonthCount() + { + return $this->premiumSubscriptionMonthCount; + } + + /** + * @param int|null $premiumSubscriptionMonthCount + * @return void + */ + public function setPremiumSubscriptionMonthCount($premiumSubscriptionMonthCount) + { + $this->premiumSubscriptionMonthCount = $premiumSubscriptionMonthCount; + } +} diff --git a/src/Types/GiveawayCompleted.php b/src/Types/GiveawayCompleted.php new file mode 100644 index 00000000..28ac6b92 --- /dev/null +++ b/src/Types/GiveawayCompleted.php @@ -0,0 +1,105 @@ + true, + 'unclaimed_prize_count' => true, + 'giveaway_message' => MaybeInaccessibleMessage::class, + ]; + + /** + * Number of winners in the giveaway + * + * @var int + */ + protected $winnerCount; + + /** + * Optional. Number of undistributed prizes + * + * @var int|null + */ + protected $unclaimedPrizeCount; + + /** + * Optional. Message with the giveaway that was completed, if it wasn't deleted + * + * @var MaybeInaccessibleMessage|null + */ + protected $giveawayMessage; + + /** + * @return int + */ + public function getWinnerCount() + { + return $this->winnerCount; + } + + /** + * @param int $winnerCount + * @return void + */ + public function setWinnerCount($winnerCount) + { + $this->winnerCount = $winnerCount; + } + + /** + * @return int|null + */ + public function getUnclaimedPrizeCount() + { + return $this->unclaimedPrizeCount; + } + + /** + * @param int|null $unclaimedPrizeCount + * @return void + */ + public function setUnclaimedPrizeCount($unclaimedPrizeCount) + { + $this->unclaimedPrizeCount = $unclaimedPrizeCount; + } + + /** + * @return MaybeInaccessibleMessage|null + */ + public function getGiveawayMessage() + { + return $this->giveawayMessage; + } + + /** + * @param MaybeInaccessibleMessage|null $giveawayMessage + * @return void + */ + public function setGiveawayMessage($giveawayMessage) + { + $this->giveawayMessage = $giveawayMessage; + } +} diff --git a/src/Types/GiveawayCreated.php b/src/Types/GiveawayCreated.php new file mode 100644 index 00000000..cd50ea4d --- /dev/null +++ b/src/Types/GiveawayCreated.php @@ -0,0 +1,15 @@ + Chat::class, + 'giveaway_message_id' => true, + 'winners_selection_date' => true, + 'winner_count' => true, + 'winners' => ArrayOfUser::class, + 'additional_chat_count' => true, + 'premium_subscription_month_count' => true, + 'unclaimed_prize_count' => true, + 'only_new_members' => true, + 'was_refunded' => true, + 'prize_description' => true, + ]; + + /** + * The chat that created the giveaway + * + * @var Chat + */ + protected $chat; + + /** + * Identifier of the message with the giveaway in the chat + * + * @var int + */ + protected $giveawayMessageId; + + /** + * Point in time (Unix timestamp) when winners of the giveaway were selected + * + * @var int + */ + protected $winnersSelectionDate; + + /** + * Total number of winners in the giveaway + * + * @var int + */ + protected $winnerCount; + + /** + * List of up to 100 winners of the giveaway + * + * @var array + */ + protected $winners; + + /** + * Optional. The number of other chats the user had to join in order to be eligible for the giveaway + * + * @var int|null + */ + protected $additionalChatCount; + + /** + * Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for + * + * @var int|null + */ + protected $premiumSubscriptionMonthCount; + + /** + * Optional. Number of undistributed prizes + * + * @var int|null + */ + protected $unclaimedPrizeCount; + + /** + * Optional. True, if only users who had joined the chats after the giveaway started were eligible to win + * + * @var bool|null + */ + protected $onlyNewMembers; + + /** + * Optional. True, if the giveaway was canceled because the payment for it was refunded + * + * @var bool|null + */ + protected $wasRefunded; + + /** + * Optional. Description of additional giveaway prize + * + * @var string|null + */ + protected $prizeDescription; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getGiveawayMessageId() + { + return $this->giveawayMessageId; + } + + /** + * @param int $giveawayMessageId + * @return void + */ + public function setGiveawayMessageId($giveawayMessageId) + { + $this->giveawayMessageId = $giveawayMessageId; + } + + /** + * @return int + */ + public function getWinnersSelectionDate() + { + return $this->winnersSelectionDate; + } + + /** + * @param int $winnersSelectionDate + * @return void + */ + public function setWinnersSelectionDate($winnersSelectionDate) + { + $this->winnersSelectionDate = $winnersSelectionDate; + } + + /** + * @return int + */ + public function getWinnerCount() + { + return $this->winnerCount; + } + + /** + * @param int $winnerCount + * @return void + */ + public function setWinnerCount($winnerCount) + { + $this->winnerCount = $winnerCount; + } + + /** + * @return array + */ + public function getWinners() + { + return $this->winners; + } + + /** + * @param array $winners + * @return void + */ + public function setWinners($winners) + { + $this->winners = $winners; + } + + /** + * @return int|null + */ + public function getAdditionalChatCount() + { + return $this->additionalChatCount; + } + + /** + * @param int|null $additionalChatCount + * @return void + */ + public function setAdditionalChatCount($additionalChatCount) + { + $this->additionalChatCount = $additionalChatCount; + } + + /** + * @return int|null + */ + public function getPremiumSubscriptionMonthCount() + { + return $this->premiumSubscriptionMonthCount; + } + + /** + * @param int|null $premiumSubscriptionMonthCount + * @return void + */ + public function setPremiumSubscriptionMonthCount($premiumSubscriptionMonthCount) + { + $this->premiumSubscriptionMonthCount = $premiumSubscriptionMonthCount; + } + + /** + * @return int|null + */ + public function getUnclaimedPrizeCount() + { + return $this->unclaimedPrizeCount; + } + + /** + * @param int|null $unclaimedPrizeCount + * @return void + */ + public function setUnclaimedPrizeCount($unclaimedPrizeCount) + { + $this->unclaimedPrizeCount = $unclaimedPrizeCount; + } + + /** + * @return bool|null + */ + public function getOnlyNewMembers() + { + return $this->onlyNewMembers; + } + + /** + * @param bool|null $onlyNewMembers + * @return void + */ + public function setOnlyNewMembers($onlyNewMembers) + { + $this->onlyNewMembers = $onlyNewMembers; + } + + /** + * @return bool|null + */ + public function getWasRefunded() + { + return $this->wasRefunded; + } + + /** + * @param bool|null $wasRefunded + * @return void + */ + public function setWasRefunded($wasRefunded) + { + $this->wasRefunded = $wasRefunded; + } + + /** + * @return string|null + */ + public function getPrizeDescription() + { + return $this->prizeDescription; + } + + /** + * @param string|null $prizeDescription + * @return void + */ + public function setPrizeDescription($prizeDescription) + { + $this->prizeDescription = $prizeDescription; + } +} diff --git a/src/Types/InaccessibleMessage.php b/src/Types/InaccessibleMessage.php new file mode 100644 index 00000000..1f41e04e --- /dev/null +++ b/src/Types/InaccessibleMessage.php @@ -0,0 +1,131 @@ + Chat::class, + 'message_id' => true, + 'date' => true, + ]; + + /** + * Chat the message belonged to + * + * @var Chat + */ + protected $chat; + + /** + * Unique message identifier inside the chat + * + * @var int + */ + protected $messageId; + + /** + * Always 0. The field can be used to differentiate regular and inaccessible messages. + * + * @var int + */ + protected $date; + + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat(Chat $chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + * @throws InvalidArgumentException + */ + public function setMessageId($messageId) + { + if (!is_int($messageId)) { + throw new InvalidArgumentException('MessageId must be an integer'); + } + $this->messageId = $messageId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + * @throws InvalidArgumentException + */ + public function setDate($date) + { + if (!is_int($date)) { + throw new InvalidArgumentException('Date must be an integer'); + } + $this->date = $date; + } +} diff --git a/src/Types/Inline/ChosenInlineResult.php b/src/Types/Inline/ChosenInlineResult.php index ff86a004..7255a72b 100644 --- a/src/Types/Inline/ChosenInlineResult.php +++ b/src/Types/Inline/ChosenInlineResult.php @@ -19,14 +19,14 @@ class ChosenInlineResult extends BaseType * * @var array */ - static protected $requiredParams = ['result_id', 'from', 'query']; + protected static $requiredParams = ['result_id', 'from', 'query']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'result_id' => true, 'from' => User::class, 'location' => Location::class, @@ -51,7 +51,7 @@ class ChosenInlineResult extends BaseType /** * Optional. Sender location, only for bots that require user location * - * @var Location + * @var Location|null */ protected $location; @@ -60,7 +60,7 @@ class ChosenInlineResult extends BaseType * 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. * - * @var string + * @var string|null */ protected $inlineMessageId; @@ -81,6 +81,8 @@ public function getResultId() /** * @param string $resultId + * + * @return void */ public function setResultId($resultId) { @@ -97,6 +99,8 @@ public function getFrom() /** * @param User $from + * + * @return void */ public function setFrom(User $from) { @@ -104,7 +108,7 @@ public function setFrom(User $from) } /** - * @return Location + * @return Location|null */ public function getLocation() { @@ -113,6 +117,8 @@ public function getLocation() /** * @param Location $location + * + * @return void */ public function setLocation($location) { @@ -120,7 +126,7 @@ public function setLocation($location) } /** - * @return string + * @return null|string */ public function getInlineMessageId() { @@ -129,6 +135,8 @@ public function getInlineMessageId() /** * @param string $inlineMessageId + * + * @return void */ public function setInlineMessageId($inlineMessageId) { @@ -145,6 +153,8 @@ public function getQuery() /** * @param string $query + * + * @return void */ public function setQuery($query) { diff --git a/src/Types/Inline/InlineKeyboardButton.php b/src/Types/Inline/InlineKeyboardButton.php new file mode 100644 index 00000000..afdf17ed --- /dev/null +++ b/src/Types/Inline/InlineKeyboardButton.php @@ -0,0 +1,283 @@ + true, + 'url' => true, + 'callback_data' => true, + 'web_app' => WebAppInfo::class, + 'login_url' => LoginUrl::class, + 'switch_inline_query' => true, + 'switch_inline_query_current_chat' => true, + 'switch_inline_query_chosen_chat' => SwitchInlineQueryChosenChat::class, + 'callback_game' => CallbackGame::class, + 'pay' => true, + ]; + + /** + * Label text on the button + * + * @var string + */ + protected $text; + + /** + * Optional. HTTP or tg:// URL to be opened when the button is pressed + * + * @var string|null + */ + protected $url; + + /** + * Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes + * + * @var string|null + */ + protected $callbackData; + + /** + * Optional. Description of the Web App that will be launched when the user presses the button + * + * @var WebAppInfo|null + */ + protected $webApp; + + /** + * Optional. An HTTPS URL used to automatically authorize the user + * + * @var LoginUrl|null + */ + protected $loginUrl; + + /** + * Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field + * + * @var string|null + */ + protected $switchInlineQuery; + + /** + * Optional. If set, pressing the button will insert the bot's username and the specified inline query in the current chat's input field + * + * @var string|null + */ + protected $switchInlineQueryCurrentChat; + + /** + * Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field + * + * @var SwitchInlineQueryChosenChat|null + */ + protected $switchInlineQueryChosenChat; + + /** + * Optional. Description of the game that will be launched when the user presses the button + * + * @var CallbackGame|null + */ + protected $callbackGame; + + /** + * Optional. Specify True to send a Pay button + * + * @var bool|null + */ + protected $pay; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return string|null + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string|null $url + * @return void + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * @return string|null + */ + public function getCallbackData() + { + return $this->callbackData; + } + + /** + * @param string|null $callbackData + * @return void + */ + public function setCallbackData($callbackData) + { + $this->callbackData = $callbackData; + } + + /** + * @return WebAppInfo|null + */ + public function getWebApp() + { + return $this->webApp; + } + + /** + * @param WebAppInfo|null $webApp + * @return void + */ + public function setWebApp($webApp) + { + $this->webApp = $webApp; + } + + /** + * @return LoginUrl|null + */ + public function getLoginUrl() + { + return $this->loginUrl; + } + + /** + * @param LoginUrl|null $loginUrl + * @return void + */ + public function setLoginUrl($loginUrl) + { + $this->loginUrl = $loginUrl; + } + + /** + * @return string|null + */ + public function getSwitchInlineQuery() + { + return $this->switchInlineQuery; + } + + /** + * @param string|null $switchInlineQuery + * @return void + */ + public function setSwitchInlineQuery($switchInlineQuery) + { + $this->switchInlineQuery = $switchInlineQuery; + } + + /** + * @return string|null + */ + public function getSwitchInlineQueryCurrentChat() + { + return $this->switchInlineQueryCurrentChat; + } + + /** + * @param string|null $switchInlineQueryCurrentChat + * @return void + */ + public function setSwitchInlineQueryCurrentChat($switchInlineQueryCurrentChat) + { + $this->switchInlineQueryCurrentChat = $switchInlineQueryCurrentChat; + } + + /** + * @return SwitchInlineQueryChosenChat|null + */ + public function getSwitchInlineQueryChosenChat() + { + return $this->switchInlineQueryChosenChat; + } + + /** + * @param SwitchInlineQueryChosenChat|null $switchInlineQueryChosenChat + * @return void + */ + public function setSwitchInlineQueryChosenChat($switchInlineQueryChosenChat) + { + $this->switchInlineQueryChosenChat = $switchInlineQueryChosenChat; + } + + /** + * @return CallbackGame|null + */ + public function getCallbackGame() + { + return $this->callbackGame; + } + + /** + * @param CallbackGame|null $callbackGame + * @return void + */ + public function setCallbackGame($callbackGame) + { + $this->callbackGame = $callbackGame; + } + + /** + * @return bool|null + */ + public function isPay() + { + return $this->pay; + } + + /** + * @param bool|null $pay + * @return void + */ + public function setPay($pay) + { + $this->pay = $pay; + } +} diff --git a/src/Types/Inline/InlineKeyboardMarkup.php b/src/Types/Inline/InlineKeyboardMarkup.php index 92a5b270..5868e725 100644 --- a/src/Types/Inline/InlineKeyboardMarkup.php +++ b/src/Types/Inline/InlineKeyboardMarkup.php @@ -1,10 +1,4 @@ true, ]; @@ -39,7 +33,7 @@ class InlineKeyboardMarkup extends BaseType /** * @param array $inlineKeyboard */ - public function __construct($inlineKeyboard) + public function __construct($inlineKeyboard = []) { $this->inlineKeyboard = $inlineKeyboard; } @@ -54,6 +48,8 @@ public function getInlineKeyboard() /** * @param array $inlineKeyboard + * + * @return void */ public function setInlineKeyboard($inlineKeyboard) { diff --git a/src/Types/Inline/InlineQuery.php b/src/Types/Inline/InlineQuery.php index b6623a89..dc0b9806 100644 --- a/src/Types/Inline/InlineQuery.php +++ b/src/Types/Inline/InlineQuery.php @@ -20,14 +20,14 @@ class InlineQuery extends BaseType * * @var array */ - static protected $requiredParams = ['id', 'from', 'query', 'offset']; + protected static $requiredParams = ['id', 'from', 'query', 'offset']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'from' => User::class, 'location' => Location::class, @@ -49,11 +49,10 @@ class InlineQuery extends BaseType */ protected $from; - /** * Optional. Sender location, only for bots that request user location * - * @var Location + * @var Location|null */ protected $location; @@ -81,6 +80,8 @@ public function getId() /** * @param string $id + * + * @return void */ public function setId($id) { @@ -97,6 +98,8 @@ public function getFrom() /** * @param User $from + * + * @return void */ public function setFrom(User $from) { @@ -104,7 +107,7 @@ public function setFrom(User $from) } /** - * @return Location + * @return Location|null */ public function getLocation() { @@ -113,6 +116,8 @@ public function getLocation() /** * @param Location $location + * + * @return void */ public function setLocation($location) { @@ -129,6 +134,8 @@ public function getQuery() /** * @param string $query + * + * @return void */ public function setQuery($query) { @@ -145,6 +152,8 @@ public function getOffset() /** * @param string $offset + * + * @return void */ public function setOffset($offset) { diff --git a/src/Types/Inline/InputMessageContent.php b/src/Types/Inline/InputMessageContent.php index ba4a314b..f3218b56 100644 --- a/src/Types/Inline/InputMessageContent.php +++ b/src/Types/Inline/InputMessageContent.php @@ -12,5 +12,4 @@ class InputMessageContent extends BaseType { - } diff --git a/src/Types/Inline/InputMessageContent/Contact.php b/src/Types/Inline/InputMessageContent/Contact.php index 508eaef2..ae92a82d 100644 --- a/src/Types/Inline/InputMessageContent/Contact.php +++ b/src/Types/Inline/InputMessageContent/Contact.php @@ -8,7 +8,6 @@ namespace TelegramBot\Api\Types\Inline\InputMessageContent; -use TelegramBot\Api\BaseType; use TelegramBot\Api\TypeInterface; use TelegramBot\Api\Types\Inline\InputMessageContent; @@ -27,14 +26,14 @@ class Contact extends InputMessageContent implements TypeInterface * * @var array */ - static protected $requiredParams = ['phone_number', 'first_name']; + protected static $requiredParams = ['phone_number', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'phone_number' => true, 'first_name' => true, 'last_name' => true, @@ -57,7 +56,7 @@ class Contact extends InputMessageContent implements TypeInterface /** * Optional. Contact's last name * - * @var string + * @var string|null */ protected $lastName; @@ -75,7 +74,6 @@ public function __construct($phoneNumber, $firstName, $lastName = null) $this->lastName = $lastName; } - /** * @return string */ @@ -86,6 +84,8 @@ public function getPhoneNumber() /** * @param string $phoneNumber + * + * @return void */ public function setPhoneNumber($phoneNumber) { @@ -102,6 +102,8 @@ public function getFirstName() /** * @param mixed $firstName + * + * @return void */ public function setFirstName($firstName) { @@ -109,7 +111,7 @@ public function setFirstName($firstName) } /** - * @return string + * @return string|null */ public function getLastName() { @@ -117,7 +119,9 @@ public function getLastName() } /** - * @param string $lastName + * @param string|null $lastName + * + * @return void */ public function setLastName($lastName) { diff --git a/src/Types/Inline/InputMessageContent/Location.php b/src/Types/Inline/InputMessageContent/Location.php index d20d90b7..e605b867 100644 --- a/src/Types/Inline/InputMessageContent/Location.php +++ b/src/Types/Inline/InputMessageContent/Location.php @@ -25,14 +25,14 @@ class Location extends InputMessageContent implements TypeInterface * * @var array */ - static protected $requiredParams = ['latitude', 'longitude']; + protected static $requiredParams = ['latitude', 'longitude']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'latitude' => true, 'longitude' => true ]; @@ -62,7 +62,6 @@ public function __construct($latitude, $longitude) $this->longitude = $longitude; } - /** * @return float */ @@ -73,6 +72,8 @@ public function getLatitude() /** * @param float $latitude + * + * @return void */ public function setLatitude($latitude) { @@ -89,6 +90,8 @@ public function getLongitude() /** * @param float $longitude + * + * @return void */ public function setLongitude($longitude) { diff --git a/src/Types/Inline/InputMessageContent/Text.php b/src/Types/Inline/InputMessageContent/Text.php index fdcfce17..fafc89fe 100644 --- a/src/Types/Inline/InputMessageContent/Text.php +++ b/src/Types/Inline/InputMessageContent/Text.php @@ -8,8 +8,9 @@ namespace TelegramBot\Api\Types\Inline\InputMessageContent; -use TelegramBot\Api\BaseType; use TelegramBot\Api\TypeInterface; +use TelegramBot\Api\Types\LinkPreviewOptions; +use TelegramBot\Api\Types\ArrayOfMessageEntity; use TelegramBot\Api\Types\Inline\InputMessageContent; /** @@ -26,17 +27,19 @@ class Text extends InputMessageContent implements TypeInterface * * @var array */ - static protected $requiredParams = ['message_text']; + protected static $requiredParams = ['message_text']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'message_text' => true, 'parse_mode' => true, - 'disable_web_page_preview' => true, + 'entities' => ArrayOfMessageEntity::class, + 'disable_web_page_preview' => true, // @todo: remove as deprecated with bot api 7.0 + 'link_preview_options' => LinkPreviewOptions::class ]; /** @@ -50,28 +53,47 @@ class Text extends InputMessageContent implements TypeInterface * 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. * - * @var string + * @var string|null */ protected $parseMode; /** + * @deprecated use $linkPreviewOptions instead * Optional. Disables link previews for links in the sent message * - * @var bool + * @var bool|null */ protected $disableWebPagePreview; + /** + * Link preview generation options for the message + * + * @var LinkPreviewOptions|null + */ + protected $linkPreviewOptions; + /** * Text constructor. + * * @param string $messageText - * @param string $parseMode + * @param string|null $parseMode * @param bool $disableWebPagePreview + * @param LinkPreviewOptions|null $linkPreviewOptions Link preview generation options for the message. */ - public function __construct($messageText, $parseMode = null, $disableWebPagePreview = false) + public function __construct($messageText, $parseMode = null, $disableWebPagePreview = false, $linkPreviewOptions = null) { $this->messageText = $messageText; $this->parseMode = $parseMode; $this->disableWebPagePreview = $disableWebPagePreview; + + if (null === $linkPreviewOptions && false !== $disableWebPagePreview) { + @trigger_error('setting $disableWebPagePreview is now deprecated use $linkPreviewOptions instead', E_USER_DEPRECATED); + + $this->linkPreviewOptions = new LinkPreviewOptions(); + $this->linkPreviewOptions->map([ + 'is_disabled' => $disableWebPagePreview + ]); + } } /** @@ -84,6 +106,8 @@ public function getMessageText() /** * @param string $messageText + * + * @return void */ public function setMessageText($messageText) { @@ -91,7 +115,7 @@ public function setMessageText($messageText) } /** - * @return string + * @return string|null */ public function getParseMode() { @@ -99,7 +123,9 @@ public function getParseMode() } /** - * @param string $parseMode + * @param string|null $parseMode + * + * @return void */ public function setParseMode($parseMode) { @@ -107,7 +133,7 @@ public function setParseMode($parseMode) } /** - * @return boolean + * @return bool|null */ public function isDisableWebPagePreview() { @@ -115,10 +141,29 @@ public function isDisableWebPagePreview() } /** - * @param boolean $disableWebPagePreview + * @param bool|null $disableWebPagePreview + * + * @return void */ public function setDisableWebPagePreview($disableWebPagePreview) { $this->disableWebPagePreview = $disableWebPagePreview; } + + /** + * @return LinkPreviewOptions|null + */ + public function getLinkPreviewOptions() + { + return $this->linkPreviewOptions; + } + + /** + * @param LinkPreviewOptions|null $linkPreviewOptions + * @return void + */ + public function setLinkPreviewOptions($linkPreviewOptions) + { + $this->linkPreviewOptions = $linkPreviewOptions; + } } diff --git a/src/Types/Inline/InputMessageContent/Venue.php b/src/Types/Inline/InputMessageContent/Venue.php index 7b57438c..a6b46b80 100644 --- a/src/Types/Inline/InputMessageContent/Venue.php +++ b/src/Types/Inline/InputMessageContent/Venue.php @@ -25,14 +25,14 @@ class Venue extends InputMessageContent implements TypeInterface * * @var array */ - static protected $requiredParams = ['latitude', 'longitude', 'title', 'address']; + protected static $requiredParams = ['latitude', 'longitude', 'title', 'address']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'latitude' => true, 'longitude' => true, 'title' => true, @@ -71,7 +71,7 @@ class Venue extends InputMessageContent implements TypeInterface /** * Optional. Foursquare identifier of the venue, if known * - * @var string + * @var string|null */ protected $foursquareId; @@ -81,7 +81,7 @@ class Venue extends InputMessageContent implements TypeInterface * @param float $longitude * @param string $title * @param string $address - * @param string $foursquareId + * @param string|null $foursquareId */ public function __construct($latitude, $longitude, $title, $address, $foursquareId = null) { @@ -92,7 +92,6 @@ public function __construct($latitude, $longitude, $title, $address, $foursquare $this->foursquareId = $foursquareId; } - /** * @return float */ @@ -103,6 +102,8 @@ public function getLatitude() /** * @param float $latitude + * + * @return void */ public function setLatitude($latitude) { @@ -119,6 +120,8 @@ public function getLongitude() /** * @param float $longitude + * + * @return void */ public function setLongitude($longitude) { @@ -135,6 +138,8 @@ public function getTitle() /** * @param string $title + * + * @return void */ public function setTitle($title) { @@ -151,6 +156,8 @@ public function getAddress() /** * @param string $address + * + * @return void */ public function setAddress($address) { @@ -158,7 +165,7 @@ public function setAddress($address) } /** - * @return string + * @return string|null */ public function getFoursquareId() { @@ -166,7 +173,9 @@ public function getFoursquareId() } /** - * @param string $foursquareId + * @param string|null $foursquareId + * + * @return void */ public function setFoursquareId($foursquareId) { diff --git a/src/Types/Inline/QueryResult/AbstractInlineQueryResult.php b/src/Types/Inline/QueryResult/AbstractInlineQueryResult.php index 6d50c1f1..30c41f8e 100644 --- a/src/Types/Inline/QueryResult/AbstractInlineQueryResult.php +++ b/src/Types/Inline/QueryResult/AbstractInlineQueryResult.php @@ -31,21 +31,21 @@ class AbstractInlineQueryResult extends BaseType /** * Title for the result * - * @var string + * @var string|null */ protected $title; /** * Content of the message to be sent instead of the file * - * @var InputMessageContent + * @var InputMessageContent|null */ protected $inputMessageContent; /** * Optional. Inline keyboard attached to the message * - * @var InlineKeyboardMarkup + * @var InlineKeyboardMarkup|null */ protected $replyMarkup; @@ -53,11 +53,11 @@ class AbstractInlineQueryResult extends BaseType * AbstractInlineQueryResult constructor. * * @param string $id - * @param string $title + * @param string|null $title * @param InputMessageContent|null $inputMessageContent * @param InlineKeyboardMarkup|null $replyMarkup */ - public function __construct($id, $title, $inputMessageContent = null, $replyMarkup = null) + public function __construct($id, $title = null, $inputMessageContent = null, $replyMarkup = null) { $this->id = $id; $this->title = $title; @@ -75,6 +75,8 @@ public function getType() /** * @param string $type + * + * @return void */ public function setType($type) { @@ -91,6 +93,8 @@ public function getId() /** * @param string $id + * + * @return void */ public function setId($id) { @@ -98,7 +102,7 @@ public function setId($id) } /** - * @return string + * @return string|null */ public function getTitle() { @@ -106,7 +110,9 @@ public function getTitle() } /** - * @param string $title + * @param string|null $title + * + * @return void */ public function setTitle($title) { @@ -114,7 +120,7 @@ public function setTitle($title) } /** - * @return InputMessageContent + * @return InputMessageContent|null */ public function getInputMessageContent() { @@ -122,7 +128,9 @@ public function getInputMessageContent() } /** - * @param InputMessageContent $inputMessageContent + * @param InputMessageContent|null $inputMessageContent + * + * @return void */ public function setInputMessageContent($inputMessageContent) { @@ -130,7 +138,7 @@ public function setInputMessageContent($inputMessageContent) } /** - * @return InlineKeyboardMarkup + * @return InlineKeyboardMarkup|null */ public function getReplyMarkup() { @@ -138,7 +146,9 @@ public function getReplyMarkup() } /** - * @param InlineKeyboardMarkup $replyMarkup + * @param InlineKeyboardMarkup|null $replyMarkup + * + * @return void */ public function setReplyMarkup($replyMarkup) { diff --git a/src/Types/Inline/QueryResult/Article.php b/src/Types/Inline/QueryResult/Article.php index a0b12178..8d48c0df 100644 --- a/src/Types/Inline/QueryResult/Article.php +++ b/src/Types/Inline/QueryResult/Article.php @@ -18,14 +18,14 @@ class Article extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'title', 'input_message_content']; + protected static $requiredParams = ['type', 'id', 'title', 'input_message_content']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'title' => true, @@ -34,9 +34,9 @@ class Article extends AbstractInlineQueryResult 'url' => true, 'hide_url' => true, 'description' => true, - 'thumb_url' => true, - 'thumb_width' => true, - 'thumb_height' => true, + 'thumbnail_url' => true, + 'thumbnail_width' => true, + 'thumbnail_height' => true, ]; /** @@ -49,44 +49,44 @@ class Article extends AbstractInlineQueryResult /** * Optional. URL of the result * - * @var string + * @var string|null */ protected $url; /** * Optional. Pass True, if you don't want the URL to be shown in the message * - * @var bool + * @var bool|null */ protected $hideUrl; /** * Optional. Short description of the result * - * @var string + * @var string|null */ protected $description; /** * Optional. Url of the thumbnail for the result * - * @var string + * @var string|null */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Thumbnail width * - * @var int + * @var int|null */ - protected $thumbWidth; + protected $thumbnailWidth; /** * Optional. Thumbnail height * - * @var int + * @var int|null */ - protected $thumbHeight; + protected $thumbnailHeight; /** * InlineQueryResultArticle constructor. @@ -94,9 +94,9 @@ class Article extends AbstractInlineQueryResult * @param string $id * @param string $title * @param string|null $description - * @param string|null $thumbUrl - * @param int|null $thumbWidth - * @param int|null $thumbHeight + * @param string|null $thumbnailUrl + * @param int|null $thumbnailWidth + * @param int|null $thumbnailHeight * @param InputMessageContent $inputMessageContent * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup */ @@ -104,23 +104,22 @@ public function __construct( $id, $title, $description = null, - $thumbUrl = null, - $thumbWidth = null, - $thumbHeight = null, + $thumbnailUrl = null, + $thumbnailWidth = null, + $thumbnailHeight = null, $inputMessageContent = null, $inlineKeyboardMarkup = null ) { parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->description = $description; - $this->thumbUrl = $thumbUrl; - $this->thumbWidth = $thumbWidth; - $this->thumbHeight = $thumbHeight; + $this->thumbnailUrl = $thumbnailUrl; + $this->thumbnailWidth = $thumbnailWidth; + $this->thumbnailHeight = $thumbnailHeight; } - /** - * @return string + * @return string|null */ public function getUrl() { @@ -128,7 +127,9 @@ public function getUrl() } /** - * @param string $url + * @param string|null $url + * + * @return void */ public function setUrl($url) { @@ -136,7 +137,7 @@ public function setUrl($url) } /** - * @return boolean + * @return bool|null */ public function isHideUrl() { @@ -144,7 +145,9 @@ public function isHideUrl() } /** - * @param boolean $hideUrl + * @param bool|null $hideUrl + * + * @return void */ public function setHideUrl($hideUrl) { @@ -152,7 +155,7 @@ public function setHideUrl($hideUrl) } /** - * @return string + * @return string|null */ public function getDescription() { @@ -160,7 +163,9 @@ public function getDescription() } /** - * @param string $description + * @param string|null $description + * + * @return void */ public function setDescription($description) { @@ -168,50 +173,122 @@ public function setDescription($description) } /** - * @return string + * @return string|null + */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string|null $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string|null */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** - * @param string $thumbUrl + * @deprecated Use setThumbnailUrl + * + * @param string|null $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); + } + + /** + * @return int|null + */ + public function getThumbnailWidth() + { + return $this->thumbnailWidth; + } + + /** + * @param int|null $thumbnailWidth + * + * @return void + */ + public function setThumbnailWidth($thumbnailWidth) + { + $this->thumbnailWidth = $thumbnailWidth; } /** - * @return int + * @deprecated Use getThumbnailWidth + * + * @return int|null */ public function getThumbWidth() { - return $this->thumbWidth; + return $this->getThumbnailWidth(); } /** - * @param int $thumbWidth + * @deprecated Use setThumbnailWidth + * + * @param int|null $thumbWidth + * + * @return void */ public function setThumbWidth($thumbWidth) { - $this->thumbWidth = $thumbWidth; + $this->setThumbnailWidth($thumbWidth); + } + + /** + * @return int|null + */ + public function getThumbnailHeight() + { + return $this->thumbnailHeight; + } + + /** + * @param int|null $thumbnailHeight + * + * @return void + */ + public function setThumbnailHeight($thumbnailHeight) + { + $this->thumbnailHeight = $thumbnailHeight; } /** - * @return int + * @deprecated Use getThumbnailHeight + * + * @return int|null */ public function getThumbHeight() { - return $this->thumbHeight; + return $this->getThumbnailHeight(); } /** - * @param int $thumbHeight + * @deprecated Use setThumbnailWidth + * + * @param int|null $thumbHeight + * + * @return void */ public function setThumbHeight($thumbHeight) { - $this->thumbHeight = $thumbHeight; + $this->setThumbnailHeight($thumbHeight); } } diff --git a/src/Types/Inline/QueryResult/Audio.php b/src/Types/Inline/QueryResult/Audio.php index d4a3e9f0..d4c1f2e1 100644 --- a/src/Types/Inline/QueryResult/Audio.php +++ b/src/Types/Inline/QueryResult/Audio.php @@ -29,14 +29,14 @@ class Audio extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'audio_url', 'title']; + protected static $requiredParams = ['type', 'id', 'audio_url', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'audio_url' => true, @@ -64,14 +64,14 @@ class Audio extends AbstractInlineQueryResult /** * Optional. Performer * - * @var string + * @var string|null */ protected $performer; /** * Optional. Audio duration in seconds * - * @var int + * @var int|null */ protected $audioDuration; @@ -112,6 +112,8 @@ public function getAudioUrl() /** * @param string $audioUrl + * + * @return void */ public function setAudioUrl($audioUrl) { @@ -119,7 +121,7 @@ public function setAudioUrl($audioUrl) } /** - * @return string + * @return string|null */ public function getPerformer() { @@ -127,7 +129,9 @@ public function getPerformer() } /** - * @param string $performer + * @param string|null $performer + * + * @return void */ public function setPerformer($performer) { @@ -135,7 +139,7 @@ public function setPerformer($performer) } /** - * @return int + * @return int|null */ public function getAudioDuration() { @@ -143,7 +147,9 @@ public function getAudioDuration() } /** - * @param int $audioDuration + * @param int|null $audioDuration + * + * @return void */ public function setAudioDuration($audioDuration) { diff --git a/src/Types/Inline/QueryResult/Contact.php b/src/Types/Inline/QueryResult/Contact.php index 9fee3535..8e0f4347 100644 --- a/src/Types/Inline/QueryResult/Contact.php +++ b/src/Types/Inline/QueryResult/Contact.php @@ -18,14 +18,14 @@ class Contact extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'phone_number', 'first_name']; + protected static $requiredParams = ['type', 'id', 'phone_number', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'phone_number' => true, @@ -33,9 +33,9 @@ class Contact extends AbstractInlineQueryResult 'last_name' => true, 'reply_markup' => InlineKeyboardMarkup::class, 'input_message_content' => InputMessageContent::class, - 'thumb_url' => true, - 'thumb_width' => true, - 'thumb_height' => true, + 'thumbnail_url' => true, + 'thumbnail_width' => true, + 'thumbnail_height' => true, ]; /** @@ -62,30 +62,30 @@ class Contact extends AbstractInlineQueryResult /** * Optional. Contact's last name * - * @var string + * @var string|null */ protected $lastName; /** * Optional. Url of the thumbnail for the result * - * @var string + * @var string|null */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Thumbnail width * - * @var int + * @var int|null */ - protected $thumbWidth; + protected $thumbnailWidth; /** * Optional. Thumbnail height * - * @var int + * @var int|null */ - protected $thumbHeight; + protected $thumbnailHeight; /** * Contact constructor. @@ -94,9 +94,9 @@ class Contact extends AbstractInlineQueryResult * @param string $phoneNumber * @param string $firstName * @param string $lastName - * @param string $thumbUrl - * @param int $thumbWidth - * @param int $thumbHeight + * @param string $thumbnailUrl + * @param int $thumbnailWidth + * @param int $thumbnailHeight * @param InputMessageContent|null $inputMessageContent * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup */ @@ -105,9 +105,9 @@ public function __construct( $phoneNumber, $firstName, $lastName = null, - $thumbUrl = null, - $thumbWidth = null, - $thumbHeight = null, + $thumbnailUrl = null, + $thumbnailWidth = null, + $thumbnailHeight = null, $inputMessageContent = null, $inlineKeyboardMarkup = null ) { @@ -116,12 +116,11 @@ public function __construct( $this->phoneNumber = $phoneNumber; $this->firstName = $firstName; $this->lastName = $lastName; - $this->thumbUrl = $thumbUrl; - $this->thumbWidth = $thumbWidth; - $this->thumbHeight = $thumbHeight; + $this->thumbnailUrl = $thumbnailUrl; + $this->thumbnailWidth = $thumbnailWidth; + $this->thumbnailHeight = $thumbnailHeight; } - /** * @return string */ @@ -132,6 +131,8 @@ public function getPhoneNumber() /** * @param string $phoneNumber + * + * @return void */ public function setPhoneNumber($phoneNumber) { @@ -148,6 +149,8 @@ public function getFirstName() /** * @param string $firstName + * + * @return void */ public function setFirstName($firstName) { @@ -155,7 +158,7 @@ public function setFirstName($firstName) } /** - * @return string + * @return string|null */ public function getLastName() { @@ -163,7 +166,9 @@ public function getLastName() } /** - * @param string $lastName + * @param string|null $lastName + * + * @return void */ public function setLastName($lastName) { @@ -171,50 +176,122 @@ public function setLastName($lastName) } /** - * @return string + * @return string|null + */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string|null $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string|null */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** - * @param string $thumbUrl + * @deprecated Use setThumbnailUrl + * + * @param string|null $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** - * @return int + * @return int|null + */ + public function getThumbnailWidth() + { + return $this->thumbnailWidth; + } + + /** + * @param int|null $thumbnailWidth + * + * @return void + */ + public function setThumbnailWidth($thumbnailWidth) + { + $this->thumbnailWidth = $thumbnailWidth; + } + + /** + * @deprecated Use getThumbnailWidth + * + * @return int|null */ public function getThumbWidth() { - return $this->thumbWidth; + return $this->getThumbnailWidth(); } /** - * @param int $thumbWidth + * @deprecated Use setThumbnailWidth + * + * @param int|null $thumbWidth + * + * @return void */ public function setThumbWidth($thumbWidth) { - $this->thumbWidth = $thumbWidth; + $this->setThumbnailWidth($thumbWidth); } /** - * @return int + * @return int|null + */ + public function getThumbnailHeight() + { + return $this->thumbnailHeight; + } + + /** + * @param int|null $thumbnailHeight + * + * @return void + */ + public function setThumbnailHeight($thumbnailHeight) + { + $this->thumbnailHeight = $thumbnailHeight; + } + + /** + * @deprecated Use getThumbnailHeight + * + * @return int|null */ public function getThumbHeight() { - return $this->thumbHeight; + return $this->getThumbnailHeight(); } /** - * @param int $thumbHeight + * @deprecated Use setThumbnailWidth + * + * @param int|null $thumbHeight + * + * @return void */ public function setThumbHeight($thumbHeight) { - $this->thumbHeight = $thumbHeight; + $this->setThumbnailHeight($thumbHeight); } } diff --git a/src/Types/Inline/QueryResult/Gif.php b/src/Types/Inline/QueryResult/Gif.php index de3f10de..1bf388ed 100644 --- a/src/Types/Inline/QueryResult/Gif.php +++ b/src/Types/Inline/QueryResult/Gif.php @@ -20,20 +20,20 @@ class Gif extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'gif_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'gif_url', 'thumbnail_url']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'gif_url' => true, 'gif_width' => true, 'gif_height' => true, - 'thumb_url' => true, + 'thumbnail_url' => true, 'title' => true, 'caption' => true, 'reply_markup' => InlineKeyboardMarkup::class, @@ -57,14 +57,14 @@ class Gif extends AbstractInlineQueryResult /** * Optional. Width of the GIF * - * @var int + * @var int|null */ protected $gifWidth; /** * Optional. Height of the GIF * - * @var int + * @var int|null */ protected $gifHeight; @@ -73,12 +73,12 @@ class Gif extends AbstractInlineQueryResult * * @var string */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Caption of the GIF file to be sent, 0-200 characters * - * @var string + * @var string|null */ protected $caption; @@ -87,7 +87,7 @@ class Gif extends AbstractInlineQueryResult * * @param string $id * @param string $gifUrl - * @param string $thumbUrl + * @param string|null $thumbnailUrl * @param int|null $gifWidth * @param int|null $gifHeight * @param string|null $title @@ -98,7 +98,7 @@ class Gif extends AbstractInlineQueryResult public function __construct( $id, $gifUrl, - $thumbUrl = null, + $thumbnailUrl = null, $title = null, $caption = null, $gifWidth = null, @@ -109,7 +109,7 @@ public function __construct( parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->gifUrl = $gifUrl; - $this->thumbUrl = is_null($thumbUrl) ? $gifUrl : $thumbUrl; + $this->thumbnailUrl = is_null($thumbnailUrl) ? $gifUrl : $thumbnailUrl; $this->gifWidth = $gifWidth; $this->gifHeight = $gifHeight; $this->caption = $caption; @@ -125,6 +125,8 @@ public function getGifUrl() /** * @param string $gifUrl + * + * @return void */ public function setGifUrl($gifUrl) { @@ -132,7 +134,7 @@ public function setGifUrl($gifUrl) } /** - * @return int + * @return int|null */ public function getGifWidth() { @@ -140,7 +142,9 @@ public function getGifWidth() } /** - * @param int $gifWidth + * @param int|null $gifWidth + * + * @return void */ public function setGifWidth($gifWidth) { @@ -148,7 +152,7 @@ public function setGifWidth($gifWidth) } /** - * @return int + * @return int|null */ public function getGifHeight() { @@ -156,7 +160,9 @@ public function getGifHeight() } /** - * @param int $gifHeight + * @param int|null $gifHeight + * + * @return void */ public function setGifHeight($gifHeight) { @@ -166,21 +172,45 @@ public function setGifHeight($gifHeight) /** * @return string */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** - * @return string + * @return string|null */ public function getCaption() { @@ -188,7 +218,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { diff --git a/src/Types/Inline/QueryResult/Location.php b/src/Types/Inline/QueryResult/Location.php index 799f6be6..9c64339e 100644 --- a/src/Types/Inline/QueryResult/Location.php +++ b/src/Types/Inline/QueryResult/Location.php @@ -29,22 +29,22 @@ class Location extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'latitude', 'longitude', 'title']; + protected static $requiredParams = ['type', 'id', 'latitude', 'longitude', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'latitude' => true, 'longitude' => true, 'title' => true, - 'thumb_url' => true, - 'thumb_width' => true, - 'thumb_height' => true, + 'thumbnail_url' => true, + 'thumbnail_width' => true, + 'thumbnail_height' => true, 'reply_markup' => InlineKeyboardMarkup::class, 'input_message_content' => InputMessageContent::class, ]; @@ -73,23 +73,23 @@ class Location extends AbstractInlineQueryResult /** * Optional. Url of the thumbnail for the result * - * @var string + * @var string|null */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Thumbnail width * - * @var int + * @var int|null */ - protected $thumbWidth; + protected $thumbnailWidth; /** * Optional. Thumbnail height * - * @var int + * @var int|null */ - protected $thumbHeight; + protected $thumbnailHeight; /** * Voice constructor @@ -98,9 +98,9 @@ class Location extends AbstractInlineQueryResult * @param float $latitude * @param float $longitude * @param string $title - * @param string $thumbUrl - * @param int $thumbWidth - * @param int $thumbHeight + * @param string|null $thumbnailUrl + * @param int|null $thumbnailWidth + * @param int|null $thumbnailHeight * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup * @param InputMessageContent|null $inputMessageContent */ @@ -109,9 +109,9 @@ public function __construct( $latitude, $longitude, $title, - $thumbUrl = null, - $thumbWidth = null, - $thumbHeight = null, + $thumbnailUrl = null, + $thumbnailWidth = null, + $thumbnailHeight = null, $inlineKeyboardMarkup = null, $inputMessageContent = null ) { @@ -119,9 +119,9 @@ public function __construct( $this->latitude = $latitude; $this->longitude = $longitude; - $this->thumbUrl = $thumbUrl; - $this->thumbWidth = $thumbWidth; - $this->thumbHeight = $thumbHeight; + $this->thumbnailUrl = $thumbnailUrl; + $this->thumbnailWidth = $thumbnailWidth; + $this->thumbnailHeight = $thumbnailHeight; } /** @@ -134,6 +134,8 @@ public function getLatitude() /** * @param float $latitude + * + * @return void */ public function setLatitude($latitude) { @@ -150,6 +152,8 @@ public function getLongitude() /** * @param float $longitude + * + * @return void */ public function setLongitude($longitude) { @@ -157,50 +161,122 @@ public function setLongitude($longitude) } /** - * @return string + * @return string|null + */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string|null $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string|null */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** - * @param string $thumbUrl + * @deprecated Use setThumbnailUrl + * + * @param string|null $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** - * @return int + * @return int|null + */ + public function getThumbnailWidth() + { + return $this->thumbnailWidth; + } + + /** + * @param int|null $thumbnailWidth + * + * @return void + */ + public function setThumbnailWidth($thumbnailWidth) + { + $this->thumbnailWidth = $thumbnailWidth; + } + + /** + * @deprecated Use getThumbnailWidth + * + * @return int|null */ public function getThumbWidth() { - return $this->thumbWidth; + return $this->getThumbnailWidth(); } /** - * @param int $thumbWidth + * @deprecated Use setThumbnailWidth + * + * @param int|null $thumbWidth + * + * @return void */ public function setThumbWidth($thumbWidth) { - $this->thumbWidth = $thumbWidth; + $this->setThumbnailWidth($thumbWidth); + } + + /** + * @return int|null + */ + public function getThumbnailHeight() + { + return $this->thumbnailHeight; } /** - * @return int + * @param int|null $thumbnailHeight + * + * @return void + */ + public function setThumbnailHeight($thumbnailHeight) + { + $this->thumbnailHeight = $thumbnailHeight; + } + + /** + * @deprecated Use getThumbnailHeight + * + * @return int|null */ public function getThumbHeight() { - return $this->thumbHeight; + return $this->getThumbnailHeight(); } /** - * @param int $thumbHeight + * @deprecated Use setThumbnailWidth + * + * @param int|null $thumbHeight + * + * @return void */ public function setThumbHeight($thumbHeight) { - $this->thumbHeight = $thumbHeight; + $this->setThumbnailHeight($thumbHeight); } } diff --git a/src/Types/Inline/QueryResult/Mpeg4Gif.php b/src/Types/Inline/QueryResult/Mpeg4Gif.php index 8578e69f..f5e5cce1 100644 --- a/src/Types/Inline/QueryResult/Mpeg4Gif.php +++ b/src/Types/Inline/QueryResult/Mpeg4Gif.php @@ -20,20 +20,20 @@ class Mpeg4Gif extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'mpeg4_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'mpeg4_url', 'thumbnail_url']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'mpeg4_url' => true, 'mpeg4_width' => true, 'mpeg4_height' => true, - 'thumb_url' => true, + 'thumbnail_url' => true, 'title' => true, 'caption' => true, 'reply_markup' => InlineKeyboardMarkup::class, @@ -57,14 +57,14 @@ class Mpeg4Gif extends AbstractInlineQueryResult /** * Optional. Video width * - * @var int + * @var int|null */ protected $mpeg4Width; /** * Optional. Video height * - * @var int + * @var int|null */ protected $mpeg4Height; @@ -73,12 +73,12 @@ class Mpeg4Gif extends AbstractInlineQueryResult * * @var string */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Caption of the MPEG-4 file to be sent, 0-200 characters * - * @var string + * @var string|null */ protected $caption; @@ -87,7 +87,7 @@ class Mpeg4Gif extends AbstractInlineQueryResult * * @param string $id * @param string $mpeg4Url - * @param string $thumbUrl + * @param string $thumbnailUrl * @param int|null $mpeg4Width * @param int|null $mpeg4Height * @param string|null $caption @@ -98,7 +98,7 @@ class Mpeg4Gif extends AbstractInlineQueryResult public function __construct( $id, $mpeg4Url, - $thumbUrl, + $thumbnailUrl, $title = null, $caption = null, $mpeg4Width = null, @@ -109,13 +109,12 @@ public function __construct( parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->mpeg4Url = $mpeg4Url; - $this->thumbUrl = $thumbUrl; + $this->thumbnailUrl = $thumbnailUrl; $this->mpeg4Width = $mpeg4Width; $this->mpeg4Height = $mpeg4Height; $this->caption = $caption; } - /** * @return string */ @@ -126,6 +125,8 @@ public function getMpeg4Url() /** * @param string $mpeg4Url + * + * @return void */ public function setMpeg4Url($mpeg4Url) { @@ -133,7 +134,7 @@ public function setMpeg4Url($mpeg4Url) } /** - * @return int + * @return int|null */ public function getMpeg4Width() { @@ -141,7 +142,9 @@ public function getMpeg4Width() } /** - * @param int $mpeg4Width + * @param int|null $mpeg4Width + * + * @return void */ public function setMpeg4Width($mpeg4Width) { @@ -149,7 +152,7 @@ public function setMpeg4Width($mpeg4Width) } /** - * @return int + * @return int|null */ public function getMpeg4Height() { @@ -157,7 +160,9 @@ public function getMpeg4Height() } /** - * @param int $mpeg4Height + * @param int|null $mpeg4Height + * + * @return void */ public function setMpeg4Height($mpeg4Height) { @@ -167,21 +172,45 @@ public function setMpeg4Height($mpeg4Height) /** * @return string */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string + */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** + * @deprecated Use setThumbnailUrl + * * @param string $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** - * @return string + * @return string|null */ public function getCaption() { @@ -189,7 +218,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { diff --git a/src/Types/Inline/QueryResult/Photo.php b/src/Types/Inline/QueryResult/Photo.php index 106ec04f..e53d9408 100644 --- a/src/Types/Inline/QueryResult/Photo.php +++ b/src/Types/Inline/QueryResult/Photo.php @@ -19,18 +19,18 @@ class Photo extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'photo_url', 'thumb_url']; + protected static $requiredParams = ['type', 'id', 'photo_url', 'thumbnail_url']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'photo_url' => true, - 'thumb_url' => true, + 'thumbnail_url' => true, 'photo_width' => true, 'photo_height' => true, 'title' => true, @@ -57,35 +57,35 @@ class Photo extends AbstractInlineQueryResult /** * Optional. Width of the photo * - * @var int + * @var int|null */ protected $photoWidth; /** * Optional. Height of the photo * - * @var int + * @var int|null */ protected $photoHeight; /** * URL of the thumbnail for the photo * - * @var + * @var string */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Short description of the result * - * @var string + * @var string|null */ protected $description; /** * Optional. Caption of the photo to be sent, 0-200 characters * - * @var string + * @var string|null */ protected $caption; @@ -94,7 +94,7 @@ class Photo extends AbstractInlineQueryResult * * @param string $id * @param string $photoUrl - * @param string $thumbUrl + * @param string $thumbnailUrl * @param int|null $photoWidth * @param int|null $photoHeight * @param string|null $title @@ -106,7 +106,7 @@ class Photo extends AbstractInlineQueryResult public function __construct( $id, $photoUrl, - $thumbUrl, + $thumbnailUrl, $photoWidth = null, $photoHeight = null, $title = null, @@ -118,14 +118,13 @@ public function __construct( parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); $this->photoUrl = $photoUrl; - $this->thumbUrl = $thumbUrl; + $this->thumbnailUrl = $thumbnailUrl; $this->photoWidth = $photoWidth; $this->photoHeight = $photoHeight; $this->description = $description; $this->caption = $caption; } - /** * @return string */ @@ -136,6 +135,8 @@ public function getPhotoUrl() /** * @param string $photoUrl + * + * @return void */ public function setPhotoUrl($photoUrl) { @@ -143,7 +144,7 @@ public function setPhotoUrl($photoUrl) } /** - * @return int + * @return int|null */ public function getPhotoWidth() { @@ -151,7 +152,9 @@ public function getPhotoWidth() } /** - * @param int $photoWidth + * @param int|null $photoWidth + * + * @return void */ public function setPhotoWidth($photoWidth) { @@ -159,7 +162,7 @@ public function setPhotoWidth($photoWidth) } /** - * @return int + * @return int|null */ public function getPhotoHeight() { @@ -167,7 +170,9 @@ public function getPhotoHeight() } /** - * @param int $photoHeight + * @param int|null $photoHeight + * + * @return void */ public function setPhotoHeight($photoHeight) { @@ -175,23 +180,47 @@ public function setPhotoHeight($photoHeight) } /** - * @return mixed + * @return string + */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** - * @param mixed $thumbUrl + * @deprecated Use setThumbnailUrl + * + * @param string $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** - * @return string + * @return string|null */ public function getDescription() { @@ -199,7 +228,9 @@ public function getDescription() } /** - * @param string $description + * @param string|null $description + * + * @return void */ public function setDescription($description) { @@ -207,7 +238,7 @@ public function setDescription($description) } /** - * @return string + * @return string|null */ public function getCaption() { @@ -215,7 +246,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { diff --git a/src/Types/Inline/QueryResult/Venue.php b/src/Types/Inline/QueryResult/Venue.php index b3c6940c..34631044 100644 --- a/src/Types/Inline/QueryResult/Venue.php +++ b/src/Types/Inline/QueryResult/Venue.php @@ -29,14 +29,14 @@ class Venue extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'latitude', 'longitude', 'title', 'address']; + protected static $requiredParams = ['type', 'id', 'latitude', 'longitude', 'title', 'address']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'latitude' => true, @@ -44,9 +44,9 @@ class Venue extends AbstractInlineQueryResult 'title' => true, 'address' => true, 'foursquare_id' => true, - 'thumb_url' => true, - 'thumb_width' => true, - 'thumb_height' => true, + 'thumbnail_url' => true, + 'thumbnail_width' => true, + 'thumbnail_height' => true, 'reply_markup' => InlineKeyboardMarkup::class, 'input_message_content' => InputMessageContent::class, ]; @@ -75,35 +75,35 @@ class Venue extends AbstractInlineQueryResult /** * Optional. Thumbnail width * - * @var string + * @var string|null */ protected $address; /** * Optional. Url of the thumbnail for the result * - * @var string + * @var string|null */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Thumbnail width * - * @var int + * @var int|null */ - protected $thumbWidth; + protected $thumbnailWidth; /** * Optional. Thumbnail height * - * @var int + * @var int|null */ - protected $thumbHeight; + protected $thumbnailHeight; /** * Optional. Foursquare identifier of the venue if known * - * @var int + * @var string|null */ protected $foursquareId; @@ -115,10 +115,10 @@ class Venue extends AbstractInlineQueryResult * @param float $longitude * @param string $title * @param string $address - * @param string $thumbUrl - * @param int $thumbWidth - * @param int $thumbHeight - * @param string $foursquareId + * @param string|null $thumbnailUrl + * @param int|null $thumbnailWidth + * @param int|null $thumbnailHeight + * @param string|null $foursquareId * @param InlineKeyboardMarkup|null $inlineKeyboardMarkup * @param InputMessageContent|null $inputMessageContent */ @@ -128,9 +128,9 @@ public function __construct( $longitude, $title, $address, - $thumbUrl = null, - $thumbWidth = null, - $thumbHeight = null, + $thumbnailUrl = null, + $thumbnailWidth = null, + $thumbnailHeight = null, $foursquareId = null, $inputMessageContent = null, $inlineKeyboardMarkup = null @@ -140,9 +140,9 @@ public function __construct( $this->latitude = $latitude; $this->longitude = $longitude; $this->address = $address; - $this->thumbUrl = $thumbUrl; - $this->thumbWidth = $thumbWidth; - $this->thumbHeight = $thumbHeight; + $this->thumbnailUrl = $thumbnailUrl; + $this->thumbnailWidth = $thumbnailWidth; + $this->thumbnailHeight = $thumbnailHeight; $this->foursquareId = $foursquareId; } @@ -156,6 +156,8 @@ public function getLatitude() /** * @param float $latitude + * + * @return void */ public function setLatitude($latitude) { @@ -172,6 +174,8 @@ public function getLongitude() /** * @param float $longitude + * + * @return void */ public function setLongitude($longitude) { @@ -179,7 +183,7 @@ public function setLongitude($longitude) } /** - * @return string + * @return string|null */ public function getAddress() { @@ -187,7 +191,9 @@ public function getAddress() } /** - * @param string $address + * @param string|null $address + * + * @return void */ public function setAddress($address) { @@ -195,7 +201,7 @@ public function setAddress($address) } /** - * @return int + * @return string|null */ public function getFoursquareId() { @@ -203,7 +209,9 @@ public function getFoursquareId() } /** - * @param int $foursquareId + * @param string|null $foursquareId + * + * @return void */ public function setFoursquareId($foursquareId) { @@ -211,50 +219,122 @@ public function setFoursquareId($foursquareId) } /** - * @return string + * @return string|null + */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string|null $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string|null */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** - * @param string $thumbUrl + * @deprecated Use setThumbnailUrl + * + * @param string|null $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** - * @return int + * @return int|null + */ + public function getThumbnailWidth() + { + return $this->thumbnailWidth; + } + + /** + * @param int|null $thumbnailWidth + * + * @return void + */ + public function setThumbnailWidth($thumbnailWidth) + { + $this->thumbnailWidth = $thumbnailWidth; + } + + /** + * @deprecated Use getThumbnailWidth + * + * @return int|null */ public function getThumbWidth() { - return $this->thumbWidth; + return $this->getThumbnailWidth(); } /** - * @param int $thumbWidth + * @deprecated Use setThumbnailWidth + * + * @param int|null $thumbWidth + * + * @return void */ public function setThumbWidth($thumbWidth) { - $this->thumbWidth = $thumbWidth; + $this->setThumbnailWidth($thumbWidth); + } + + /** + * @return int|null + */ + public function getThumbnailHeight() + { + return $this->thumbnailHeight; + } + + /** + * @param int|null $thumbnailHeight + * + * @return void + */ + public function setThumbnailHeight($thumbnailHeight) + { + $this->thumbnailHeight = $thumbnailHeight; } /** - * @return int + * @deprecated Use getThumbnailHeight + * + * @return int|null */ public function getThumbHeight() { - return $this->thumbHeight; + return $this->getThumbnailHeight(); } /** - * @param int $thumbHeight + * @deprecated Use setThumbnailWidth + * + * @param int|null $thumbHeight + * + * @return void */ public function setThumbHeight($thumbHeight) { - $this->thumbHeight = $thumbHeight; + $this->setThumbnailHeight($thumbHeight); } } diff --git a/src/Types/Inline/QueryResult/Video.php b/src/Types/Inline/QueryResult/Video.php index 7a999cc9..9eec6962 100644 --- a/src/Types/Inline/QueryResult/Video.php +++ b/src/Types/Inline/QueryResult/Video.php @@ -18,19 +18,19 @@ class Video extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'video_url', 'mime_type', 'thumb_url', 'title']; + protected static $requiredParams = ['type', 'id', 'video_url', 'mime_type', 'thumbnail_url', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'video_url' => true, 'mime_type' => true, - 'thumb_url' => true, + 'thumbnail_url' => true, 'title' => true, 'caption' => true, 'description' => true, @@ -65,21 +65,21 @@ class Video extends AbstractInlineQueryResult /** * Optional. Video width * - * @var int + * @var int|null */ protected $videoWidth; /** * Optional. Video height * - * @var int + * @var int|null */ protected $videoHeight; /** * Optional. Video duration in seconds * - * @var int + * @var int|null */ protected $videoDuration; @@ -88,29 +88,28 @@ class Video extends AbstractInlineQueryResult * * @var string */ - protected $thumbUrl; + protected $thumbnailUrl; /** * Optional. Short description of the result * - * @var string + * @var string|null */ protected $caption; /** * Optional. Short description of the result * - * @var string + * @var string|null */ protected $description; - /** * Video constructor * * @param string $id * @param string $videoUrl - * @param string $thumbUrl + * @param string $thumbnailUrl * @param string $mimeType * @param string $title * @param string|null $caption @@ -124,7 +123,7 @@ class Video extends AbstractInlineQueryResult public function __construct( $id, $videoUrl, - $thumbUrl, + $thumbnailUrl, $mimeType, $title, $caption = null, @@ -136,9 +135,9 @@ public function __construct( $inlineKeyboardMarkup = null ) { parent::__construct($id, $title, $inputMessageContent, $inlineKeyboardMarkup); - + $this->videoUrl = $videoUrl; - $this->thumbUrl = $thumbUrl; + $this->thumbnailUrl = $thumbnailUrl; $this->caption = $caption; $this->description = $description; $this->mimeType = $mimeType; @@ -147,7 +146,6 @@ public function __construct( $this->videoDuration = $videoDuration; } - /** * @return string */ @@ -158,6 +156,8 @@ public function getVideoUrl() /** * @param string $videoUrl + * + * @return void */ public function setVideoUrl($videoUrl) { @@ -174,6 +174,8 @@ public function getMimeType() /** * @param string $mimeType + * + * @return void */ public function setMimeType($mimeType) { @@ -181,7 +183,7 @@ public function setMimeType($mimeType) } /** - * @return int + * @return int|null */ public function getVideoWidth() { @@ -189,7 +191,9 @@ public function getVideoWidth() } /** - * @param int $videoWidth + * @param int|null $videoWidth + * + * @return void */ public function setVideoWidth($videoWidth) { @@ -197,7 +201,7 @@ public function setVideoWidth($videoWidth) } /** - * @return int + * @return int|null */ public function getVideoHeight() { @@ -205,7 +209,9 @@ public function getVideoHeight() } /** - * @param int $videoHeight + * @param int|null $videoHeight + * + * @return void */ public function setVideoHeight($videoHeight) { @@ -213,7 +219,7 @@ public function setVideoHeight($videoHeight) } /** - * @return int + * @return int|null */ public function getVideoDuration() { @@ -221,7 +227,9 @@ public function getVideoDuration() } /** - * @param int $videoDuration + * @param int|null $videoDuration + * + * @return void */ public function setVideoDuration($videoDuration) { @@ -229,23 +237,47 @@ public function setVideoDuration($videoDuration) } /** - * @return mixed + * @return string + */ + public function getThumbnailUrl() + { + return $this->thumbnailUrl; + } + + /** + * @param string $thumbnailUrl + * + * @return void + */ + public function setThumbnailUrl($thumbnailUrl) + { + $this->thumbnailUrl = $thumbnailUrl; + } + + /** + * @deprecated Use getThumbnailUrl + * + * @return string */ public function getThumbUrl() { - return $this->thumbUrl; + return $this->getThumbnailUrl(); } /** - * @param mixed $thumbUrl + * @deprecated Use setThumbnailUrl + * + * @param string $thumbUrl + * + * @return void */ public function setThumbUrl($thumbUrl) { - $this->thumbUrl = $thumbUrl; + $this->setThumbnailUrl($thumbUrl); } /** - * @return string + * @return string|null */ public function getCaption() { @@ -253,7 +285,9 @@ public function getCaption() } /** - * @param string $caption + * @param string|null $caption + * + * @return void */ public function setCaption($caption) { @@ -261,7 +295,7 @@ public function setCaption($caption) } /** - * @return string + * @return string|null */ public function getDescription() { @@ -269,7 +303,9 @@ public function getDescription() } /** - * @param string $description + * @param string|null $description + * + * @return void */ public function setDescription($description) { diff --git a/src/Types/Inline/QueryResult/Voice.php b/src/Types/Inline/QueryResult/Voice.php index f86d19bb..e8158827 100644 --- a/src/Types/Inline/QueryResult/Voice.php +++ b/src/Types/Inline/QueryResult/Voice.php @@ -29,14 +29,14 @@ class Voice extends AbstractInlineQueryResult * * @var array */ - static protected $requiredParams = ['type', 'id', 'voice_url', 'title']; + protected static $requiredParams = ['type', 'id', 'voice_url', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'type' => true, 'id' => true, 'voice_url' => true, @@ -60,11 +60,10 @@ class Voice extends AbstractInlineQueryResult */ protected $voiceUrl; - /** * Optional. Audio duration in seconds * - * @var int + * @var int|null */ protected $voiceDuration; @@ -104,6 +103,8 @@ public function getVoiceUrl() /** * @param string $voiceUrl + * + * @return void */ public function setVoiceUrl($voiceUrl) { @@ -111,7 +112,7 @@ public function setVoiceUrl($voiceUrl) } /** - * @return int + * @return int|null */ public function getVoiceDuration() { @@ -119,7 +120,9 @@ public function getVoiceDuration() } /** - * @param int $voiceDuration + * @param int|null $voiceDuration + * + * @return void */ public function setVoiceDuration($voiceDuration) { diff --git a/src/Types/Inline/SwitchInlineQueryChosenChat.php b/src/Types/Inline/SwitchInlineQueryChosenChat.php new file mode 100644 index 00000000..da88f394 --- /dev/null +++ b/src/Types/Inline/SwitchInlineQueryChosenChat.php @@ -0,0 +1,148 @@ + true, + 'allow_user_chats' => true, + 'allow_bot_chats' => true, + 'allow_group_chats' => true, + 'allow_channel_chats' => true + ]; + + /** + * Optional. The default inline query to be inserted in the input field. If left empty, only the bot's username will be inserted. + * + * @var string|null + */ + protected $query; + + /** + * Optional. True, if private chats with users can be chosen. + * + * @var bool|null + */ + protected $allowUserChats; + + /** + * Optional. True, if private chats with bots can be chosen. + * + * @var bool|null + */ + protected $allowBotChats; + + /** + * Optional. True, if group and supergroup chats can be chosen. + * + * @var bool|null + */ + protected $allowGroupChats; + + /** + * Optional. True, if channel chats can be chosen. + * + * @var bool|null + */ + protected $allowChannelChats; + + /** + * @return string|null + */ + public function getQuery() + { + return $this->query; + } + + /** + * @param string|null $query + * @return void + */ + public function setQuery($query) + { + $this->query = $query; + } + + /** + * @return bool|null + */ + public function getAllowUserChats() + { + return $this->allowUserChats; + } + + /** + * @param bool|null $allowUserChats + * @return void + */ + public function setAllowUserChats($allowUserChats) + { + $this->allowUserChats = $allowUserChats; + } + + /** + * @return bool|null + */ + public function getAllowBotChats() + { + return $this->allowBotChats; + } + + /** + * @param bool|null $allowBotChats + * @return void + */ + public function setAllowBotChats($allowBotChats) + { + $this->allowBotChats = $allowBotChats; + } + + /** + * @return bool|null + */ + public function getAllowGroupChats() + { + return $this->allowGroupChats; + } + + /** + * @param bool|null $allowGroupChats + * @return void + */ + public function setAllowGroupChats($allowGroupChats) + { + $this->allowGroupChats = $allowGroupChats; + } + + /** + * @return bool|null + */ + public function getAllowChannelChats() + { + return $this->allowChannelChats; + } + + /** + * @param bool|null $allowChannelChats + * @return void + */ + public function setAllowChannelChats($allowChannelChats) + { + $this->allowChannelChats = $allowChannelChats; + } +} diff --git a/src/Types/InputMedia/ArrayOfInputMedia.php b/src/Types/InputMedia/ArrayOfInputMedia.php new file mode 100644 index 00000000..9c5bf12f --- /dev/null +++ b/src/Types/InputMedia/ArrayOfInputMedia.php @@ -0,0 +1,15 @@ + true, + 'media' => true, + 'thumbnail' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'show_caption_above_media' => true, + 'width' => true, + 'height' => true, + 'duration' => true, + 'has_spoiler' => true + ]; + + /** + * Type of the result, must be animation + * + * @var string + */ + protected $type = 'animation'; + + /** + * File to send + * + * @var string + */ + protected $media; + + /** + * Optional. Thumbnail of the file sent + * + * @var string|null + */ + protected $thumbnail; + + /** + * Optional. Caption of the animation to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the animation caption + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Pass True, if the caption must be shown above the message media + * + * @var bool|null + */ + protected $showCaptionAboveMedia; + + /** + * Optional. Animation width + * + * @var int|null + */ + protected $width; + + /** + * Optional. Animation height + * + * @var int|null + */ + protected $height; + + /** + * Optional. Animation duration in seconds + * + * @var int|null + */ + protected $duration; + + /** + * Optional. Pass True if the animation needs to be covered with a spoiler animation + * + * @var bool|null + */ + protected $hasSpoiler; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia(string $media): void + { + $this->media = $media; + } + + /** + * @return string|null + */ + public function getThumbnail(): ?string + { + return $this->thumbnail; + } + + /** + * @param string|null $thumbnail + */ + public function setThumbnail(?string $thumbnail): void + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption(?string $caption): void + { + $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode(?string $parseMode): void + { + $this->parseMode = $parseMode; + } + + /** + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities(?array $captionEntities): void + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getShowCaptionAboveMedia(): ?bool + { + return $this->showCaptionAboveMedia; + } + + /** + * @param bool|null $showCaptionAboveMedia + */ + public function setShowCaptionAboveMedia(?bool $showCaptionAboveMedia): void + { + $this->showCaptionAboveMedia = $showCaptionAboveMedia; + } + + /** + * @return int|null + */ + public function getWidth(): ?int + { + return $this->width; + } + + /** + * @param int|null $width + */ + public function setWidth(?int $width): void + { + $this->width = $width; + } + + /** + * @return int|null + */ + public function getHeight(): ?int + { + return $this->height; + } + + /** + * @param int|null $height + */ + public function setHeight(?int $height): void + { + $this->height = $height; + } + + /** + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * @param int|null $duration + */ + public function setDuration(?int $duration): void + { + $this->duration = $duration; + } + + /** + * @return bool|null + */ + public function getHasSpoiler(): ?bool + { + return $this->hasSpoiler; + } + + /** + * @param bool|null $hasSpoiler + */ + public function setHasSpoiler(?bool $hasSpoiler): void + { + $this->hasSpoiler = $hasSpoiler; + } +} diff --git a/src/Types/InputMedia/InputMediaAudio.php b/src/Types/InputMedia/InputMediaAudio.php new file mode 100644 index 00000000..8bd555d3 --- /dev/null +++ b/src/Types/InputMedia/InputMediaAudio.php @@ -0,0 +1,260 @@ + true, + 'media' => true, + 'thumbnail' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'duration' => true, + 'performer' => true, + 'title' => true + ]; + + /** + * Type of the result, must be audio + * + * @var string + */ + protected $type = 'audio'; + + /** + * File to send + * + * @var string + */ + protected $media; + + /** + * Optional. Thumbnail of the file sent + * + * @var string|null + */ + protected $thumbnail; + + /** + * Optional. Caption of the audio to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the audio caption + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Duration of the audio in seconds + * + * @var int|null + */ + protected $duration; + + /** + * Optional. Performer of the audio + * + * @var string|null + */ + protected $performer; + + /** + * Optional. Title of the audio + * + * @var string|null + */ + protected $title; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia(string $media): void + { + $this->media = $media; + } + + /** + * @return string|null + */ + public function getThumbnail(): ?string + { + return $this->thumbnail; + } + + /** + * @param string|null $thumbnail + */ + public function setThumbnail(?string $thumbnail): void + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption(?string $caption): void + { + $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode(?string $parseMode): void + { + $this->parseMode = $parseMode; + } + + /** + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities(?array $captionEntities): void + { + $this->captionEntities = $captionEntities; + } + + /** + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * @param int|null $duration + */ + public function setDuration(?int $duration): void + { + $this->duration = $duration; + } + + /** + * @return string|null + */ + public function getPerformer(): ?string + { + return $this->performer; + } + + /** + * @param string|null $performer + */ + public function setPerformer(?string $performer): void + { + $this->performer = $performer; + } + + /** + * @return string|null + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param string|null $title + */ + public function setTitle(?string $title): void + { + $this->title = $title; + } +} diff --git a/src/Types/InputMedia/InputMediaDocument.php b/src/Types/InputMedia/InputMediaDocument.php new file mode 100644 index 00000000..3012e232 --- /dev/null +++ b/src/Types/InputMedia/InputMediaDocument.php @@ -0,0 +1,212 @@ + true, + 'media' => true, + 'thumbnail' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'disable_content_type_detection' => true + ]; + + /** + * Type of the result, must be document + * + * @var string + */ + protected $type = 'document'; + + /** + * File to send + * + * @var string + */ + protected $media; + + /** + * Optional. Thumbnail of the file sent + * + * @var string|null + */ + protected $thumbnail; + + /** + * Optional. Caption of the document to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the document caption + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data. Always True, if the document is sent as part of an album. + * + * @var bool|null + */ + protected $disableContentTypeDetection; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia(string $media): void + { + $this->media = $media; + } + + /** + * @return string|null + */ + public function getThumbnail(): ?string + { + return $this->thumbnail; + } + + /** + * @param string|null $thumbnail + */ + public function setThumbnail(?string $thumbnail): void + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption(?string $caption): void + { + $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode(?string $parseMode): void + { + $this->parseMode = $parseMode; + } + + /** + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities(?array $captionEntities): void + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getDisableContentTypeDetection(): ?bool + { + return $this->disableContentTypeDetection; + } + + /** + * @param bool|null $disableContentTypeDetection + */ + public function setDisableContentTypeDetection(?bool $disableContentTypeDetection): void + { + $this->disableContentTypeDetection = $disableContentTypeDetection; + } +} diff --git a/src/Types/InputMedia/InputMediaPhoto.php b/src/Types/InputMedia/InputMediaPhoto.php new file mode 100644 index 00000000..891e2327 --- /dev/null +++ b/src/Types/InputMedia/InputMediaPhoto.php @@ -0,0 +1,212 @@ + true, + 'media' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'show_caption_above_media' => true, + 'has_spoiler' => true + ]; + + /** + * Type of the result, must be photo + * + * @var string + */ + protected $type; + + /** + * File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. + * + * @var string + */ + protected $media; + + /** + * Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the photo caption. See formatting options for more details. + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Pass True, if the caption must be shown above the message media + * + * @var bool|null + */ + protected $showCaptionAboveMedia; + + /** + * Optional. Pass True if the photo needs to be covered with a spoiler animation + * + * @var bool|null + */ + protected $hasSpoiler; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia() + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia($media) + { + $this->media = $media; + } + + /** + * @return string|null + */ + public function getCaption() + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption($caption) + { + $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode() + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode($parseMode) + { + $this->parseMode = $parseMode; + } + + /** + * @return array|null + */ + public function getCaptionEntities() + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities($captionEntities) + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getShowCaptionAboveMedia() + { + return $this->showCaptionAboveMedia; + } + + /** + * @param bool|null $showCaptionAboveMedia + */ + public function setShowCaptionAboveMedia($showCaptionAboveMedia) + { + $this->showCaptionAboveMedia = $showCaptionAboveMedia; + } + + /** + * @return bool|null + */ + public function getHasSpoiler() + { + return $this->hasSpoiler; + } + + /** + * @param bool|null $hasSpoiler + */ + public function setHasSpoiler($hasSpoiler) + { + $this->hasSpoiler = $hasSpoiler; + } +} diff --git a/src/Types/InputMedia/InputMediaVideo.php b/src/Types/InputMedia/InputMediaVideo.php new file mode 100644 index 00000000..b51b32bb --- /dev/null +++ b/src/Types/InputMedia/InputMediaVideo.php @@ -0,0 +1,333 @@ + true, + 'media' => true, + 'thumbnail' => true, + 'caption' => true, + 'parse_mode' => true, + 'caption_entities' => true, + 'show_caption_above_media' => true, + 'width' => true, + 'height' => true, + 'duration' => true, + 'supports_streaming' => true, + 'has_spoiler' => true + ]; + + /** + * Type of the result, must be video + * + * @var string + */ + protected $type = 'video'; + + /** + * File to send + * + * @var string + */ + protected $media; + + /** + * Optional. Thumbnail of the file sent + * + * @var string|null + */ + protected $thumbnail; + + /** + * Optional. Caption of the video to be sent, 0-1024 characters after entities parsing + * + * @var string|null + */ + protected $caption; + + /** + * Optional. Mode for parsing entities in the video caption + * + * @var string|null + */ + protected $parseMode; + + /** + * Optional. List of special entities that appear in the caption + * + * @var array|null + */ + protected $captionEntities; + + /** + * Optional. Pass True, if the caption must be shown above the message media + * + * @var bool|null + */ + protected $showCaptionAboveMedia; + + /** + * Optional. Video width + * + * @var int|null + */ + protected $width; + + /** + * Optional. Video height + * + * @var int|null + */ + protected $height; + + /** + * Optional. Video duration in seconds + * + * @var int|null + */ + protected $duration; + + /** + * Optional. Pass True if the uploaded video is suitable for streaming + * + * @var bool|null + */ + protected $supportsStreaming; + + /** + * Optional. Pass True if the video needs to be covered with a spoiler animation + * + * @var bool|null + */ + protected $hasSpoiler; + + /** + * @param array $data + * @return static + * @throws InvalidArgumentException + */ + public static function fromResponse($data) + { + self::validate($data); + /** @psalm-suppress UnsafeInstantiation */ + $instance = new static(); + $instance->map($data); + + return $instance; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @return string + */ + public function getMedia(): string + { + return $this->media; + } + + /** + * @param string $media + */ + public function setMedia(string $media): void + { + $this->media = $media; + } + + /** + * @return string|null + */ + public function getThumbnail(): ?string + { + return $this->thumbnail; + } + + /** + * @param string|null $thumbnail + */ + public function setThumbnail(?string $thumbnail): void + { + $this->thumbnail = $thumbnail; + } + + /** + * @return string|null + */ + public function getCaption(): ?string + { + return $this->caption; + } + + /** + * @param string|null $caption + */ + public function setCaption(?string $caption): void + { + $this->caption = $caption; + } + + /** + * @return string|null + */ + public function getParseMode(): ?string + { + return $this->parseMode; + } + + /** + * @param string|null $parseMode + */ + public function setParseMode(?string $parseMode): void + { + $this->parseMode = $parseMode; + } + + /** + * @return array|null + */ + public function getCaptionEntities(): ?array + { + return $this->captionEntities; + } + + /** + * @param array|null $captionEntities + */ + public function setCaptionEntities(?array $captionEntities): void + { + $this->captionEntities = $captionEntities; + } + + /** + * @return bool|null + */ + public function getShowCaptionAboveMedia(): ?bool + { + return $this->showCaptionAboveMedia; + } + + /** + * @param bool|null $showCaptionAboveMedia + */ + public function setShowCaptionAboveMedia(?bool $showCaptionAboveMedia): void + { + $this->showCaptionAboveMedia = $showCaptionAboveMedia; + } + + /** + * @return int|null + */ + public function getWidth(): ?int + { + return $this->width; + } + + /** + * @param int|null $width + */ + public function setWidth(?int $width): void + { + $this->width = $width; + } + + /** + * @return int|null + */ + public function getHeight(): ?int + { + return $this->height; + } + + /** + * @param int|null $height + */ + public function setHeight(?int $height): void + { + $this->height = $height; + } + + /** + * @return int|null + */ + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * @param int|null $duration + */ + public function setDuration(?int $duration): void + { + $this->duration = $duration; + } + + /** + * @return bool|null + */ + public function getSupportsStreaming(): ?bool + { + return $this->supportsStreaming; + } + + /** + * @param bool|null $supportsStreaming + */ + public function setSupportsStreaming(?bool $supportsStreaming): void + { + $this->supportsStreaming = $supportsStreaming; + } + + /** + * @return bool|null + */ + public function getHasSpoiler(): ?bool + { + return $this->hasSpoiler; + } + + /** + * @param bool|null $hasSpoiler + */ + public function setHasSpoiler(?bool $hasSpoiler): void + { + $this->hasSpoiler = $hasSpoiler; + } + +} diff --git a/src/Types/InputPollOption.php b/src/Types/InputPollOption.php new file mode 100644 index 00000000..f6791a23 --- /dev/null +++ b/src/Types/InputPollOption.php @@ -0,0 +1,105 @@ + true, + 'text_parse_mode' => true, + 'text_entities' => ArrayOfMessageEntity::class + ]; + + /** + * Option text, 1-100 characters + * + * @var string + */ + protected $text; + + /** + * Optional. Mode for parsing entities in the text. Currently, only custom emoji entities are allowed + * + * @var string|null + */ + protected $textParseMode; + + /** + * Optional. A JSON-serialized list of special entities that appear in the poll option text + * + * @var array|null + */ + protected $textEntities; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return string|null + */ + public function getTextParseMode() + { + return $this->textParseMode; + } + + /** + * @param string|null $textParseMode + * @return void + */ + public function setTextParseMode($textParseMode) + { + $this->textParseMode = $textParseMode; + } + + /** + * @return array|null + */ + public function getTextEntities() + { + return $this->textEntities; + } + + /** + * @param array|null $textEntities + * @return void + */ + public function setTextEntities($textEntities) + { + $this->textEntities = $textEntities; + } +} diff --git a/src/Types/KeyboardButton.php b/src/Types/KeyboardButton.php new file mode 100644 index 00000000..9db786a9 --- /dev/null +++ b/src/Types/KeyboardButton.php @@ -0,0 +1,213 @@ + true, + 'request_users' => KeyboardButtonRequestUsers::class, + 'request_chat' => KeyboardButtonRequestChat::class, + 'request_contact' => true, + 'request_location' => true, + 'request_poll' => KeyboardButtonPollType::class, + 'web_app' => WebAppInfo::class, + ]; + + /** + * Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed + * + * @var string + */ + protected $text; + + /** + * Optional. If specified, pressing the button will open a list of suitable users. + * Identifiers of selected users will be sent to the bot in a “users_shared” service message. + * Available in private chats only. + * + * @var KeyboardButtonRequestUsers|null + */ + protected $requestUsers; + + /** + * Optional. If specified, pressing the button will open a list of suitable chats. + * Tapping on a chat will send its identifier to the bot in a “chat_shared” service message. + * Available in private chats only. + * + * @var KeyboardButtonRequestChat|null + */ + protected $requestChat; + + /** + * Optional. If True, the user's phone number will be sent as a contact when the button is pressed. + * Available in private chats only. + * + * @var bool|null + */ + protected $requestContact; + + /** + * Optional. If True, the user's current location will be sent when the button is pressed. + * Available in private chats only. + * + * @var bool|null + */ + protected $requestLocation; + + /** + * Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. + * Available in private chats only. + * + * @var KeyboardButtonPollType|null + */ + protected $requestPoll; + + /** + * Optional. If specified, the described Web App will be launched when the button is pressed. + * The Web App will be able to send a “web_app_data” service message. Available in private chats only. + * + * @var WebAppInfo|null + */ + protected $webApp; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return KeyboardButtonRequestUsers|null + */ + public function getRequestUsers() + { + return $this->requestUsers; + } + + /** + * @param KeyboardButtonRequestUsers|null $requestUsers + * @return void + */ + public function setRequestUsers($requestUsers) + { + $this->requestUsers = $requestUsers; + } + + /** + * @return KeyboardButtonRequestChat|null + */ + public function getRequestChat() + { + return $this->requestChat; + } + + /** + * @param KeyboardButtonRequestChat|null $requestChat + * @return void + */ + public function setRequestChat($requestChat) + { + $this->requestChat = $requestChat; + } + + /** + * @return bool|null + */ + public function getRequestContact() + { + return $this->requestContact; + } + + /** + * @param bool|null $requestContact + * @return void + */ + public function setRequestContact($requestContact) + { + $this->requestContact = $requestContact; + } + + /** + * @return bool|null + */ + public function getRequestLocation() + { + return $this->requestLocation; + } + + /** + * @param bool|null $requestLocation + * @return void + */ + public function setRequestLocation($requestLocation) + { + $this->requestLocation = $requestLocation; + } + + /** + * @return KeyboardButtonPollType|null + */ + public function getRequestPoll() + { + return $this->requestPoll; + } + + /** + * @param KeyboardButtonPollType|null $requestPoll + * @return void + */ + public function setRequestPoll($requestPoll) + { + $this->requestPoll = $requestPoll; + } + + /** + * @return WebAppInfo|null + */ + public function getWebApp() + { + return $this->webApp; + } + + /** + * @param WebAppInfo|null $webApp + * @return void + */ + public function setWebApp($webApp) + { + $this->webApp = $webApp; + } +} diff --git a/src/Types/KeyboardButtonPollType.php b/src/Types/KeyboardButtonPollType.php new file mode 100644 index 00000000..2fa8c507 --- /dev/null +++ b/src/Types/KeyboardButtonPollType.php @@ -0,0 +1,50 @@ + true, + ]; + + /** + * 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. + * + * @var string|null + */ + protected $type; + + /** + * @return string|null + */ + public function getType() + { + return $this->type; + } + + /** + * @param string|null $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } +} diff --git a/src/Types/KeyboardButtonRequestChat.php b/src/Types/KeyboardButtonRequestChat.php new file mode 100644 index 00000000..6e77522f --- /dev/null +++ b/src/Types/KeyboardButtonRequestChat.php @@ -0,0 +1,307 @@ + true, + 'chat_is_channel' => true, + 'chat_is_forum' => true, + 'chat_has_username' => true, + 'chat_is_created' => true, + 'user_administrator_rights' => ChatAdministratorRights::class, + 'bot_administrator_rights' => ChatAdministratorRights::class, + 'bot_is_member' => true, + 'request_title' => true, + 'request_username' => true, + 'request_photo' => true, + ]; + + /** + * Signed 32-bit identifier of the request, which will be received back in the ChatShared object. Must be unique within the message + * + * @var int + */ + protected $requestId; + + /** + * Pass True to request a channel chat, pass False to request a group or a supergroup chat. + * + * @var bool + */ + protected $chatIsChannel; + + /** + * Optional. Pass True to request a forum supergroup, pass False to request a non-forum chat. If not specified, no additional restrictions are applied. + * + * @var bool|null + */ + protected $chatIsForum; + + /** + * Optional. Pass True to request a supergroup or a channel with a username, pass False to request a chat without a username. If not specified, no additional restrictions are applied. + * + * @var bool|null + */ + protected $chatHasUsername; + + /** + * Optional. Pass True to request a chat owned by the user. Otherwise, no additional restrictions are applied. + * + * @var bool|null + */ + protected $chatIsCreated; + + /** + * Optional. A JSON-serialized object listing the required administrator rights of the user in the chat. The rights must be a superset of bot_administrator_rights. If not specified, no additional restrictions are applied. + * + * @var ChatAdministratorRights|null + */ + protected $userAdministratorRights; + + /** + * Optional. A JSON-serialized object listing the required administrator rights of the bot in the chat. The rights must be a subset of user_administrator_rights. If not specified, no additional restrictions are applied. + * + * @var ChatAdministratorRights|null + */ + protected $botAdministratorRights; + + /** + * Optional. Pass True to request a chat with the bot as a member. Otherwise, no additional restrictions are applied. + * + * @var bool|null + */ + protected $botIsMember; + + /** + * Optional. Pass True to request the chat's title. + * + * @var bool|null + */ + protected $requestTitle; + + /** + * Optional. Pass True to request the chat's username. + * + * @var bool|null + */ + protected $requestUsername; + + /** + * Optional. Pass True to request the chat's photo. + * + * @var bool|null + */ + protected $requestPhoto; + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @param int $requestId + * @return void + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + } + + /** + * @return bool + */ + public function getChatIsChannel() + { + return $this->chatIsChannel; + } + + /** + * @param bool $chatIsChannel + * @return void + */ + public function setChatIsChannel($chatIsChannel) + { + $this->chatIsChannel = $chatIsChannel; + } + + /** + * @return bool|null + */ + public function getChatIsForum() + { + return $this->chatIsForum; + } + + /** + * @param bool|null $chatIsForum + * @return void + */ + public function setChatIsForum($chatIsForum) + { + $this->chatIsForum = $chatIsForum; + } + + /** + * @return bool|null + */ + public function getChatHasUsername() + { + return $this->chatHasUsername; + } + + /** + * @param bool|null $chatHasUsername + * @return void + */ + public function setChatHasUsername($chatHasUsername) + { + $this->chatHasUsername = $chatHasUsername; + } + + /** + * @return bool|null + */ + public function getChatIsCreated() + { + return $this->chatIsCreated; + } + + /** + * @param bool|null $chatIsCreated + * @return void + */ + public function setChatIsCreated($chatIsCreated) + { + $this->chatIsCreated = $chatIsCreated; + } + + /** + * @return ChatAdministratorRights|null + */ + public function getUserAdministratorRights() + { + return $this->userAdministratorRights; + } + + /** + * @param ChatAdministratorRights|null $userAdministratorRights + * @return void + */ + public function setUserAdministratorRights($userAdministratorRights) + { + $this->userAdministratorRights = $userAdministratorRights; + } + + /** + * @return ChatAdministratorRights|null + */ + public function getBotAdministratorRights() + { + return $this->botAdministratorRights; + } + + /** + * @param ChatAdministratorRights|null $botAdministratorRights + * @return void + */ + public function setBotAdministratorRights($botAdministratorRights) + { + $this->botAdministratorRights = $botAdministratorRights; + } + + /** + * @return bool|null + */ + public function getBotIsMember() + { + return $this->botIsMember; + } + + /** + * @param bool|null $botIsMember + * @return void + */ + public function setBotIsMember($botIsMember) + { + $this->botIsMember = $botIsMember; + } + + /** + * @return bool|null + */ + public function getRequestTitle() + { + return $this->requestTitle; + } + + /** + * @param bool|null $requestTitle + * @return void + */ + public function setRequestTitle($requestTitle) + { + $this->requestTitle = $requestTitle; + } + + /** + * @return bool|null + */ + public function getRequestUsername() + { + return $this->requestUsername; + } + + /** + * @param bool|null $requestUsername + * @return void + */ + public function setRequestUsername($requestUsername) + { + $this->requestUsername = $requestUsername; + } + + /** + * @return bool|null + */ + public function getRequestPhoto() + { + return $this->requestPhoto; + } + + /** + * @param bool|null $requestPhoto + * @return void + */ + public function setRequestPhoto($requestPhoto) + { + $this->requestPhoto = $requestPhoto; + } +} diff --git a/src/Types/KeyboardButtonRequestUsers.php b/src/Types/KeyboardButtonRequestUsers.php new file mode 100644 index 00000000..4cf02c76 --- /dev/null +++ b/src/Types/KeyboardButtonRequestUsers.php @@ -0,0 +1,206 @@ + true, + 'user_is_bot' => true, + 'user_is_premium' => true, + 'max_quantity' => true, + 'request_name' => true, + 'request_username' => true, + 'request_photo' => true, + ]; + + /** + * Signed 32-bit identifier of the request that will be received back in the UsersShared object. Must be unique within the message + * + * @var int + */ + protected $requestId; + + /** + * Optional. Pass True to request bots, pass False to request regular users. If not specified, no additional restrictions are applied. + * + * @var bool|null + */ + protected $userIsBot; + + /** + * Optional. Pass True to request premium users, pass False to request non-premium users. If not specified, no additional restrictions are applied. + * + * @var bool|null + */ + protected $userIsPremium; + + /** + * Optional. The maximum number of users to be selected; 1-10. Defaults to 1. + * + * @var int|null + */ + protected $maxQuantity; + + /** + * Optional. Pass True to request the users' first and last names. + * + * @var bool|null + */ + protected $requestName; + + /** + * Optional. Pass True to request the users' usernames. + * + * @var bool|null + */ + protected $requestUsername; + + /** + * Optional. Pass True to request the users' photos. + * + * @var bool|null + */ + protected $requestPhoto; + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @param int $requestId + * @return void + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + } + + /** + * @return bool|null + */ + public function getUserIsBot() + { + return $this->userIsBot; + } + + /** + * @param bool|null $userIsBot + * @return void + */ + public function setUserIsBot($userIsBot) + { + $this->userIsBot = $userIsBot; + } + + /** + * @return bool|null + */ + public function getUserIsPremium() + { + return $this->userIsPremium; + } + + /** + * @param bool|null $userIsPremium + * @return void + */ + public function setUserIsPremium($userIsPremium) + { + $this->userIsPremium = $userIsPremium; + } + + /** + * @return int|null + */ + public function getMaxQuantity() + { + return $this->maxQuantity; + } + + /** + * @param int|null $maxQuantity + * @return void + */ + public function setMaxQuantity($maxQuantity) + { + $this->maxQuantity = $maxQuantity; + } + + /** + * @return bool|null + */ + public function getRequestName() + { + return $this->requestName; + } + + /** + * @param bool|null $requestName + * @return void + */ + public function setRequestName($requestName) + { + $this->requestName = $requestName; + } + + /** + * @return bool|null + */ + public function getRequestUsername() + { + return $this->requestUsername; + } + + /** + * @param bool|null $requestUsername + * @return void + */ + public function setRequestUsername($requestUsername) + { + $this->requestUsername = $requestUsername; + } + + /** + * @return bool|null + */ + public function getRequestPhoto() + { + return $this->requestPhoto; + } + + /** + * @param bool|null $requestPhoto + * @return void + */ + public function setRequestPhoto($requestPhoto) + { + $this->requestPhoto = $requestPhoto; + } +} diff --git a/src/Types/LinkPreviewOptions.php b/src/Types/LinkPreviewOptions.php new file mode 100644 index 00000000..e12175c6 --- /dev/null +++ b/src/Types/LinkPreviewOptions.php @@ -0,0 +1,148 @@ + true, + 'url' => true, + 'prefer_small_media' => true, + 'prefer_large_media' => true, + 'show_above_text' => true, + ]; + + /** + * Optional. True, if the link preview is disabled + * + * @var bool|null + */ + protected $isDisabled; + + /** + * Optional. URL to use for the link preview. If empty, then the first URL found in the message text will be used + * + * @var string|null + */ + protected $url; + + /** + * 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 + * + * @var bool|null + */ + protected $preferSmallMedia; + + /** + * 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 + * + * @var bool|null + */ + protected $preferLargeMedia; + + /** + * Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text + * + * @var bool|null + */ + protected $showAboveText; + + /** + * @return bool|null + */ + public function getIsDisabled() + { + return $this->isDisabled; + } + + /** + * @param bool|null $isDisabled + * @return void + */ + public function setIsDisabled($isDisabled) + { + $this->isDisabled = $isDisabled; + } + + /** + * @return string|null + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string|null $url + * @return void + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * @return bool|null + */ + public function getPreferSmallMedia() + { + return $this->preferSmallMedia; + } + + /** + * @param bool|null $preferSmallMedia + * @return void + */ + public function setPreferSmallMedia($preferSmallMedia) + { + $this->preferSmallMedia = $preferSmallMedia; + } + + /** + * @return bool|null + */ + public function getPreferLargeMedia() + { + return $this->preferLargeMedia; + } + + /** + * @param bool|null $preferLargeMedia + * @return void + */ + public function setPreferLargeMedia($preferLargeMedia) + { + $this->preferLargeMedia = $preferLargeMedia; + } + + /** + * @return bool|null + */ + public function getShowAboveText() + { + return $this->showAboveText; + } + + /** + * @param bool|null $showAboveText + * @return void + */ + public function setShowAboveText($showAboveText) + { + $this->showAboveText = $showAboveText; + } +} diff --git a/src/Types/Location.php b/src/Types/Location.php index 5c449c96..9237858a 100644 --- a/src/Types/Location.php +++ b/src/Types/Location.php @@ -19,16 +19,20 @@ class Location extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['latitude', 'longitude']; + protected static $requiredParams = ['latitude', 'longitude']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'latitude' => true, - 'longitude' => true + 'longitude' => true, + 'horizontal_accuracy' => true, + 'live_period' => true, + 'heading' => true, + 'proximity_alert_radius' => true, ]; /** @@ -45,6 +49,34 @@ class Location extends BaseType implements TypeInterface */ protected $latitude; + /** + * Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + * + * @var float|null + */ + protected $horizontalAccuracy; + + /** + * Optional. Time relative to the message sending date, during which the location can be updated, in seconds. For active live locations only. + * + * @var int|null + */ + protected $livePeriod; + + /** + * Optional. The direction in which user is moving, in degrees; 1-360. For active live locations only. + * + * @var int|null + */ + protected $heading; + + /** + * Optional. Maximum distance for proximity alerts about approaching another chat member, in meters. For sent live locations only. + * + * @var int|null + */ + protected $proximityAlertRadius; + /** * @return float */ @@ -55,7 +87,7 @@ public function getLatitude() /** * @param float $latitude - * + * @return void * @throws InvalidArgumentException */ public function setLatitude($latitude) @@ -77,7 +109,7 @@ public function getLongitude() /** * @param float $longitude - * + * @return void * @throws InvalidArgumentException */ public function setLongitude($longitude) @@ -88,4 +120,77 @@ public function setLongitude($longitude) throw new InvalidArgumentException(); } } + + /** + * @return float|null + */ + public function getHorizontalAccuracy() + { + return $this->horizontalAccuracy; + } + + /** + * @param float|null $horizontalAccuracy + * @return void + * @throws InvalidArgumentException + */ + public function setHorizontalAccuracy($horizontalAccuracy) + { + if (is_float($horizontalAccuracy)) { + $this->horizontalAccuracy = $horizontalAccuracy; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return int|null + */ + public function getLivePeriod() + { + return $this->livePeriod; + } + + /** + * @param int|null $livePeriod + * @return void + */ + public function setLivePeriod($livePeriod) + { + $this->livePeriod = $livePeriod; + } + + /** + * @return int|null + */ + public function getHeading() + { + return $this->heading; + } + + /** + * @param int|null $heading + * @return void + */ + public function setHeading($heading) + { + $this->heading = $heading; + } + + /** + * @return int|null + */ + public function getProximityAlertRadius() + { + return $this->proximityAlertRadius; + } + + /** + * @param int|null $proximityAlertRadius + * @return void + */ + public function setProximityAlertRadius($proximityAlertRadius) + { + $this->proximityAlertRadius = $proximityAlertRadius; + } } diff --git a/src/Types/LoginUrl.php b/src/Types/LoginUrl.php new file mode 100644 index 00000000..c441f4e2 --- /dev/null +++ b/src/Types/LoginUrl.php @@ -0,0 +1,126 @@ + true, + 'forward_text' => true, + 'bot_username' => true, + 'request_write_access' => true + ]; + + /** + * An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. + * + * @var string + */ + protected $url; + + /** + * Optional. New text of the button in forwarded messages. + * + * @var string|null + */ + protected $forwardText; + + /** + * Optional. Username of a bot, which will be used for user authorization + * + * @var string|null + */ + protected $botUsername; + + /** + * Optional. Pass True to request the permission for your bot to send messages to the user. + * + * @var bool|null + */ + protected $requestWriteAccess; + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + * @return void + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * @return null|string + */ + public function getForwardText() + { + return $this->forwardText; + } + + /** + * @param string $forwardText + * @return void + */ + public function setForwardText($forwardText) + { + $this->forwardText = $forwardText; + } + + /** + * @return null|string + */ + public function getBotUsername() + { + return $this->botUsername; + } + + /** + * @param string $botUsername + * @return void + */ + public function setBotUsername($botUsername) + { + $this->botUsername = $botUsername; + } + + /** + * @return bool|null + */ + public function isRequestWriteAccess() + { + return $this->requestWriteAccess; + } + + /** + * @param bool $requestWriteAccess + * @return void + */ + public function setRequestWriteAccess($requestWriteAccess) + { + $this->requestWriteAccess = $requestWriteAccess; + } +} diff --git a/src/Types/MaskPosition.php b/src/Types/MaskPosition.php new file mode 100644 index 00000000..466ec5e6 --- /dev/null +++ b/src/Types/MaskPosition.php @@ -0,0 +1,123 @@ + + */ +class MaskPosition extends BaseType implements TypeInterface +{ + protected static $requiredParams = ['point', 'x_shift', 'y_shift', 'scale']; + + protected static $map = [ + 'point' => true, + 'x_shift' => true, + 'y_shift' => true, + 'scale' => true, + ]; + + /** + * The part of the face relative to which the mask should be placed. One of “forehead”, “eyes”, “mouth”, or “chin”. + * + * @var string + */ + protected $point; + + /** + * 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. + * + * @var float + */ + protected $xShift; + + /** + * 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. + * + * @var float + */ + protected $yShift; + + /** + * Mask scaling coefficient. For example, 2.0 means double size. + * + * @var float + */ + protected $scale; + + /** + * @return string + */ + public function getPoint() + { + return $this->point; + } + + /** + * @param string $point + * @return void + */ + public function setPoint($point) + { + $this->point = $point; + } + + /** + * @return float + */ + public function getXShift() + { + return $this->xShift; + } + + /** + * @param float $xShift + * @return void + */ + public function setXShift($xShift) + { + $this->xShift = $xShift; + } + + /** + * @return float + */ + public function getYShift() + { + return $this->yShift; + } + + /** + * @param float $yShift + * @return void + */ + public function setYShift($yShift) + { + $this->yShift = $yShift; + } + + /** + * @return float + */ + public function getScale() + { + return $this->scale; + } + + /** + * @param float $scale + * @return void + */ + public function setScale($scale) + { + $this->scale = $scale; + } +} diff --git a/src/Types/MaybeInaccessibleMessage.php b/src/Types/MaybeInaccessibleMessage.php new file mode 100644 index 00000000..e53b5b91 --- /dev/null +++ b/src/Types/MaybeInaccessibleMessage.php @@ -0,0 +1,29 @@ + true, + 'message_thread_id' => true, 'from' => User::class, + 'sender_chat' => Chat::class, + 'sender_boost_count' => true, + 'sender_business_bot' => User::class, 'date' => true, + 'business_connection_id' => true, 'chat' => Chat::class, - 'forward_from' => User::class, - 'forward_date' => true, - 'reply_to_message' => Message::class, + 'forward_origin' => MessageOrigin::class, + 'is_topic_message' => true, + 'is_automatic_forward' => true, + 'reply_to_message' => self::class, + 'external_reply' => ExternalReplyInfo::class, + 'quote' => TextQuote::class, + 'reply_to_story' => Story::class, + 'via_bot' => User::class, + 'edit_date' => true, + 'has_protected_content' => true, + 'is_from_offline' => true, + 'media_group_id' => true, + 'author_signature' => true, 'text' => true, 'entities' => ArrayOfMessageEntity::class, + 'link_preview_options' => LinkPreviewOptions::class, + 'effect_id' => true, + 'animation' => Animation::class, 'audio' => Audio::class, 'document' => Document::class, 'photo' => ArrayOfPhotoSize::class, 'sticker' => Sticker::class, + 'story' => Story::class, 'video' => Video::class, + 'video_note' => VideoNote::class, 'voice' => Voice::class, 'caption' => true, + 'caption_entities' => ArrayOfMessageEntity::class, + 'show_caption_above_media' => true, + 'has_media_spoiler' => true, 'contact' => Contact::class, - 'location' => Location::class, + 'dice' => Dice::class, + 'game' => Game::class, + 'poll' => Poll::class, 'venue' => Venue::class, - 'new_chat_member' => User::class, + 'location' => Location::class, + 'new_chat_members' => ArrayOfUser::class, 'left_chat_member' => User::class, 'new_chat_title' => true, 'new_chat_photo' => ArrayOfPhotoSize::class, @@ -49,278 +83,1094 @@ class Message extends BaseType implements TypeInterface 'group_chat_created' => true, 'supergroup_chat_created' => true, 'channel_chat_created' => true, + 'message_auto_delete_timer_changed' => MessageAutoDeleteTimerChanged::class, 'migrate_to_chat_id' => true, 'migrate_from_chat_id' => true, - 'pinned_message' => Message::class, + 'pinned_message' => MaybeInaccessibleMessage::class, 'invoice' => Invoice::class, 'successful_payment' => SuccessfulPayment::class, - 'forward_signature' => true, - 'author_signature' => true + 'users_shared' => UsersShared::class, + 'chat_shared' => ChatShared::class, + 'connected_website' => true, + 'write_access_allowed' => WriteAccessAllowed::class, + // 'passport_data' => PassportData::class, + 'proximity_alert_triggered' => ProximityAlertTriggered::class, + 'boost_added' => ChatBoostAdded::class, + 'chat_background_set' => ChatBackground::class, + 'forum_topic_created' => ForumTopicCreated::class, + 'forum_topic_edited' => ForumTopicEdited::class, + 'forum_topic_closed' => ForumTopicClosed::class, + 'forum_topic_reopened' => ForumTopicReopened::class, + 'general_forum_topic_hidden' => GeneralForumTopicHidden::class, + 'general_forum_topic_unhidden' => GeneralForumTopicUnhidden::class, + 'giveaway_created' => GiveawayCreated::class, + 'giveaway' => Giveaway::class, + 'giveaway_winners' => GiveawayWinners::class, + 'giveaway_completed' => GiveawayCompleted::class, + 'video_chat_scheduled' => VideoChatScheduled::class, + 'video_chat_started' => VideoChatStarted::class, + 'video_chat_ended' => VideoChatEnded::class, + 'video_chat_participants_invited' => VideoChatParticipantsInvited::class, + 'web_app_data' => WebAppData::class, + 'reply_markup' => InlineKeyboardMarkup::class, ]; /** - * Unique message identifier + * Unique message identifier inside this chat * - * @var int + * @var int|float */ protected $messageId; /** - * Optional. Sender name. Can be empty for messages sent to channels + * Optional. Unique identifier of a message thread to which the message belongs; for supergroups only + * + * @var int|null + */ + protected $messageThreadId; + + /** + * Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, + * the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. * - * @var \TelegramBot\Api\Types\User + * @var \TelegramBot\Api\Types\User|null */ protected $from; /** - * Date the message was sent in Unix time + * Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts, + * the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. + * For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. + * + * @var \TelegramBot\Api\Types\Chat|null + */ + protected $senderChat; + + /** + * Optional. If the sender of the message boosted the chat, the number of boosts added by the user + * + * @var int|null + */ + protected $senderBoostCount; + + /** + * Optional. The bot that actually sent the message on behalf of the business account. + * Available only for outgoing messages sent on behalf of the connected business account. + * + * @var \TelegramBot\Api\Types\User|null + */ + protected $senderBusinessBot; + + /** + * Date the message was sent in Unix time. It is always a positive number, representing a valid date. * * @var int */ protected $date; /** - * Conversation the message belongs to — user in case of a private message, GroupChat in case of a group + * Optional. Unique identifier of the business connection from which the message was received. + * If non-empty, the message belongs to a chat of the corresponding business account that is independent + * from any potential bot chat which might share the same identifier. + * + * @var string|null + */ + protected $businessConnectionId; + + /** + * Chat the message belongs to * * @var \TelegramBot\Api\Types\Chat */ protected $chat; /** - * Optional. For forwarded messages, sender of the original message + * Optional. Information about the original message for forwarded messages * - * @var \TelegramBot\Api\Types\User + * @var \TelegramBot\Api\Types\MessageOrigin|null */ - protected $forwardFrom; + protected $forwardOrigin; /** - * Optional. For forwarded messages, date the original message was sent in Unix time + * Optional. True, if the message is sent to a forum topic * - * @var int + * @var bool|null + */ + protected $isTopicMessage; + + /** + * Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group + * + * @var bool|null */ - protected $forwardDate; + protected $isAutomaticForward; /** - * Optional. For replies, the original message. Note that the Message object in this field will not contain further - * reply_to_message fields even if it itself is a reply. + * Optional. For replies in the same chat and message thread, the original message. + * Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. * - * @var \TelegramBot\Api\Types\Message + * @var \TelegramBot\Api\Types\Message|null */ protected $replyToMessage; + /** + * Optional. Information about the message that is being replied to, which may come from another chat or forum topic + * + * @var \TelegramBot\Api\Types\ExternalReplyInfo|null + */ + protected $externalReply; + + /** + * Optional. For replies that quote part of the original message, the quoted part of the message + * + * @var \TelegramBot\Api\Types\TextQuote|null + */ + protected $quote; + + /** + * Optional. For replies to a story, the original story + * + * @var \TelegramBot\Api\Types\Story|null + */ + protected $replyToStory; + + /** + * Optional. Bot through which the message was sent + * + * @var \TelegramBot\Api\Types\User|null + */ + protected $viaBot; + + /** + * Optional. Date the message was last edited in Unix time + * + * @var int|null + */ + protected $editDate; + + /** + * Optional. True, if the message can't be forwarded + * + * @var bool|null + */ + protected $hasProtectedContent; + + /** + * Optional. True, if the message was sent by an implicit action, for example, as an away or a greeting business message, + * or as a scheduled message + * + * @var bool|null + */ + protected $isFromOffline; + + /** + * Optional. The unique identifier of a media message group this message belongs to + * + * @var string|null + */ + protected $mediaGroupId; + + /** + * Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator + * + * @var string|null + */ + protected $authorSignature; + /** * Optional. For text messages, the actual UTF-8 text of the message * - * @var string + * @var string|null */ protected $text; /** - * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. - * array of \TelegramBot\Api\Types\MessageEntity + * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text * - * @var array + * @var MessageEntity[]|null */ protected $entities; + /** + * Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed + * + * @var \TelegramBot\Api\Types\LinkPreviewOptions|null + */ + protected $linkPreviewOptions; + + /** + * Optional. Unique identifier of the message effect added to the message + * + * @var string|null + */ + protected $effectId; + + /** + * Optional. Message is an animation, information about the animation. + * For backward compatibility, when this field is set, the document field will also be set + * + * @var \TelegramBot\Api\Types\Animation|null + */ + protected $animation; + /** * Optional. Message is an audio file, information about the file * - * @var \TelegramBot\Api\Types\Audio + * @var \TelegramBot\Api\Types\Audio|null */ protected $audio; /** * Optional. Message is a general file, information about the file * - * @var \TelegramBot\Api\Types\Document + * @var \TelegramBot\Api\Types\Document|null */ protected $document; /** * Optional. Message is a photo, available sizes of the photo - * array of \TelegramBot\Api\Types\Photo * - * @var array + * @var PhotoSize[]|null */ protected $photo; /** * Optional. Message is a sticker, information about the sticker * - * @var \TelegramBot\Api\Types\Sticker + * @var \TelegramBot\Api\Types\Sticker|null */ protected $sticker; + /** + * Optional. Message is a forwarded story + * + * @var \TelegramBot\Api\Types\Story|null + */ + protected $story; + /** * Optional. Message is a video, information about the video * - * @var \TelegramBot\Api\Types\Video + * @var \TelegramBot\Api\Types\Video|null */ protected $video; + /** + * Optional. Message is a video note, information about the video message + * + * @var \TelegramBot\Api\Types\VideoNote|null + */ + protected $videoNote; + /** * Optional. Message is a voice message, information about the file * - * @var \TelegramBot\Api\Types\Voice + * @var \TelegramBot\Api\Types\Voice|null */ protected $voice; + /** + * Optional. Caption for the animation, audio, document, photo, video or voice + * + * @var string|null + */ + protected $caption; + + /** + * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption + * + * @var MessageEntity[]|null + */ + protected $captionEntities; + + /** + * Optional. True, if the caption must be shown above the message media + * + * @var bool|null + */ + protected $showCaptionAboveMedia; + + /** + * Optional. True, if the message media is covered by a spoiler animation + * + * @var bool|null + */ + protected $hasMediaSpoiler; + /** * Optional. Message is a shared contact, information about the contact * - * @var \TelegramBot\Api\Types\Contact + * @var \TelegramBot\Api\Types\Contact|null */ protected $contact; /** - * Optional. Message is a shared location, information about the location + * Optional. Message is a dice with random value * - * @var \TelegramBot\Api\Types\Location + * @var \TelegramBot\Api\Types\Dice|null */ - protected $location; + protected $dice; + + /** + * Optional. Message is a game, information about the game + * + * @var \TelegramBot\Api\Types\Game|null + */ + protected $game; + + /** + * Optional. Message is a native poll, information about the poll + * + * @var \TelegramBot\Api\Types\Poll|null + */ + protected $poll; /** - * Optional. Message is a venue, information about the venue + * Optional. Message is a venue, information about the venue. + * For backward compatibility, when this field is set, the location field will also be set * - * @var \TelegramBot\Api\Types\Venue + * @var \TelegramBot\Api\Types\Venue|null */ protected $venue; /** - * Optional. A new member was added to the group, information about them (this member may be bot itself) + * Optional. Message is a shared location, information about the location + * + * @var \TelegramBot\Api\Types\Location|null + */ + protected $location; + + /** + * Optional. New members that were added to the group or supergroup and information about them + * (the bot itself may be one of these members) * - * @var \TelegramBot\Api\Types\User + * @var User[]|null */ - protected $newChatMember; + protected $newChatMembers; /** - * Optional. A member was removed from the group, information about them (this member may be bot itself) + * Optional. A member was removed from the group, information about them (this member may be the bot itself) * - * @var \TelegramBot\Api\Types\User + * @var \TelegramBot\Api\Types\User|null */ protected $leftChatMember; /** - * Optional. A group title was changed to this value + * Optional. A chat title was changed to this value * - * @var string + * @var string|null */ protected $newChatTitle; /** - * Optional. A group photo was change to this value + * Optional. A chat photo was change to this value * - * @var mixed + * @var PhotoSize[]|null */ protected $newChatPhoto; /** - * Optional. Informs that the group photo was deleted + * Optional. Service message: the chat photo was deleted * - * @var bool + * @var bool|null */ protected $deleteChatPhoto; /** - * Optional. Informs that the group has been created + * Optional. Service message: the group has been created * - * @var bool + * @var bool|null */ protected $groupChatCreated; /** - * Optional. Text description of the video (usually empty) + * Optional. Service message: the supergroup has been created. + * This field can't be received in a message coming through updates, + * because bot can't be a member of a supergroup when it is created. + * It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup. * - * @var string + * @var bool|null */ - protected $caption; - + protected $supergroupChatCreated; /** - * Optional. Service message: the supergroup has been created + * Optional. Service message: the channel has been created. + * This field can't be received in a message coming through updates, + * because bot can't be a member of a channel when it is created. + * It can only be found in reply_to_message if someone replies to a very first message in a channel. * - * @var bool + * @var bool|null */ - protected $supergroupChatCreated; + protected $channelChatCreated; /** - * Optional. Service message: the channel has been created + * Optional. Service message: auto-delete timer settings changed in the chat * - * @var bool + * @var \TelegramBot\Api\Types\MessageAutoDeleteTimerChanged|null */ - protected $channelChatCreated; + protected $messageAutoDeleteTimerChanged; /** - * Optional. The group has been migrated to a supergroup with the specified identifier, - * not exceeding 1e13 by absolute value + * Optional. The group has been migrated to a supergroup with the specified identifier. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. * - * @var int + * @var int|null */ protected $migrateToChatId; /** - * Optional. The supergroup has been migrated from a group with the specified identifier, - * not exceeding 1e13 by absolute value + * Optional. The supergroup has been migrated from a group with the specified identifier. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. * - * @var int + * @var int|null */ protected $migrateFromChatId; /** - * Optional. Specified message was pinned.Note that the Message object in this field - * will not contain further reply_to_message fields even if it is itself a reply. - * - * @var Message + * Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. + * + * @var Message|InaccessibleMessage|null + */ + protected $pinnedMessage; + + /** + * Optional. Message is an invoice for a payment, information about the invoice + * + * @var Invoice + */ + protected $invoice; + + /** + * Optional. Message is a service message about a successful payment, information about the payment + * + * @var SuccessfulPayment + */ + protected $successfulPayment; + + /** + * Optional. Service message: users were shared with the bot + * + * @var \TelegramBot\Api\Types\UsersShared|null + */ + protected $usersShared; + + /** + * Optional. Service message: a chat was shared with the bot + * + * @var \TelegramBot\Api\Types\ChatShared|null + */ + protected $chatShared; + + /** + * Optional. The domain name of the website on which the user has logged in + * + * @var string|null + */ + protected $connectedWebsite; + + /** + * Optional. Service message: the user allowed the bot to write messages after adding it to the attachment or side menu, + * launching a Web App from a link, or accepting an explicit request from a Web App sent by the method requestWriteAccess + * + * @var \TelegramBot\Api\Types\WriteAccessAllowed|null + */ + protected $writeAccessAllowed; + + // /** + // * Optional. Telegram Passport data + // * + // * @var \TelegramBot\Api\Types\PassportData|null + // */ + // protected $passportData; + + /** + * Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live Location + * + * @var \TelegramBot\Api\Types\ProximityAlertTriggered|null + */ + protected $proximityAlertTriggered; + + /** + * Optional. Service message: user boosted the chat + * + * @var \TelegramBot\Api\Types\ChatBoostAdded|null + */ + protected $boostAdded; + + /** + * Optional. Service message: chat background set + * + * @var \TelegramBot\Api\Types\ChatBackground|null + */ + protected $chatBackgroundSet; + + /** + * Optional. Service message: forum topic created + * + * @var \TelegramBot\Api\Types\ForumTopicCreated|null + */ + protected $forumTopicCreated; + + /** + * Optional. Service message: forum topic edited + * + * @var \TelegramBot\Api\Types\ForumTopicEdited|null + */ + protected $forumTopicEdited; + + /** + * Optional. Service message: forum topic closed + * + * @var \TelegramBot\Api\Types\ForumTopicClosed|null + */ + protected $forumTopicClosed; + + /** + * Optional. Service message: forum topic reopened + * + * @var \TelegramBot\Api\Types\ForumTopicReopened|null + */ + protected $forumTopicReopened; + + /** + * Optional. Service message: the 'General' forum topic hidden + * + * @var \TelegramBot\Api\Types\GeneralForumTopicHidden|null + */ + protected $generalForumTopicHidden; + + /** + * Optional. Service message: the 'General' forum topic unhidden + * + * @var \TelegramBot\Api\Types\GeneralForumTopicUnhidden|null + */ + protected $generalForumTopicUnhidden; + + /** + * Optional. Service message: a scheduled giveaway was created + * + * @var \TelegramBot\Api\Types\GiveawayCreated|null + */ + protected $giveawayCreated; + + /** + * Optional. The message is a scheduled giveaway message + * + * @var \TelegramBot\Api\Types\Giveaway|null + */ + protected $giveaway; + + /** + * Optional. A giveaway with public winners was completed + * + * @var \TelegramBot\Api\Types\GiveawayWinners|null + */ + protected $giveawayWinners; + + /** + * Optional. Service message: a giveaway without public winners was completed + * + * @var \TelegramBot\Api\Types\GiveawayCompleted|null + */ + protected $giveawayCompleted; + + /** + * Optional. Service message: video chat scheduled + * + * @var \TelegramBot\Api\Types\VideoChatScheduled|null + */ + protected $videoChatScheduled; + + /** + * Optional. Service message: video chat started + * + * @var \TelegramBot\Api\Types\VideoChatStarted|null + */ + protected $videoChatStarted; + + /** + * Optional. Service message: video chat ended + * + * @var \TelegramBot\Api\Types\VideoChatEnded|null + */ + protected $videoChatEnded; + + /** + * Optional. Service message: new participants invited to a video chat + * + * @var \TelegramBot\Api\Types\VideoChatParticipantsInvited|null + */ + protected $videoChatParticipantsInvited; + + /** + * Optional. Service message: data sent by a Web App + * + * @var \TelegramBot\Api\Types\WebAppData|null + */ + protected $webAppData; + + /** + * Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons + * + * @var \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup|null + */ + protected $replyMarkup; + + /** + * @return int|float + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param mixed $messageId + * @return void + * @throws InvalidArgumentException + */ + public function setMessageId($messageId) + { + if (is_integer($messageId) || is_float($messageId)) { + $this->messageId = $messageId; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return int|null + */ + public function getMessageThreadId() + { + return $this->messageThreadId; + } + + /** + * @param int|null $messageThreadId + * @return void + */ + public function setMessageThreadId($messageThreadId) + { + $this->messageThreadId = $messageThreadId; + } + + /** + * @return User|null + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + * @return void + */ + public function setFrom(User $from) + { + $this->from = $from; + } + + /** + * @return Chat|null + */ + public function getSenderChat() + { + return $this->senderChat; + } + + /** + * @param Chat $senderChat + * @return void + */ + public function setSenderChat(Chat $senderChat) + { + $this->senderChat = $senderChat; + } + + /** + * @return int|null + */ + public function getSenderBoostCount() + { + return $this->senderBoostCount; + } + + /** + * @param int|null $senderBoostCount + */ + public function setSenderBoostCount($senderBoostCount) + { + $this->senderBoostCount = $senderBoostCount; + } + + /** + * @return User|null + */ + public function getSenderBusinessBot() + { + return $this->senderBusinessBot; + } + + /** + * @param User|null $senderBusinessBot + */ + public function setSenderBusinessBot($senderBusinessBot) + { + $this->senderBusinessBot = $senderBusinessBot; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param mixed $date + * @return void + * @throws InvalidArgumentException + */ + public function setDate($date) + { + if (is_int($date)) { + $this->date = $date; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return string|null + */ + public function getBusinessConnectionId() + { + return $this->businessConnectionId; + } + + /** + * @param string|null $businessConnectionId + */ + public function setBusinessConnectionId($businessConnectionId) + { + $this->businessConnectionId = $businessConnectionId; + } + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat(Chat $chat) + { + $this->chat = $chat; + } + + /** + * @return MessageOrigin|null + */ + public function getForwardOrigin() + { + return $this->forwardOrigin; + } + + /** + * @param MessageOrigin|null $forwardOrigin + */ + public function setForwardOrigin($forwardOrigin) + { + $this->forwardOrigin = $forwardOrigin; + } + + /** + * @return bool|null + */ + public function getIsTopicMessage() + { + return $this->isTopicMessage; + } + + /** + * @param bool|null $isTopicMessage + */ + public function setIsTopicMessage($isTopicMessage) + { + $this->isTopicMessage = $isTopicMessage; + } + + /** + * @return bool|null + */ + public function getIsAutomaticForward() + { + return $this->isAutomaticForward; + } + + /** + * @param bool|null $isAutomaticForward + */ + public function setIsAutomaticForward($isAutomaticForward) + { + $this->isAutomaticForward = $isAutomaticForward; + } + + /** + * @return Message|null + */ + public function getReplyToMessage() + { + return $this->replyToMessage; + } + + /** + * @param Message|null $replyToMessage + */ + public function setReplyToMessage($replyToMessage) + { + $this->replyToMessage = $replyToMessage; + } + + /** + * @return ExternalReplyInfo|null + */ + public function getExternalReply() + { + return $this->externalReply; + } + + /** + * @param ExternalReplyInfo|null $externalReply + */ + public function setExternalReply($externalReply) + { + $this->externalReply = $externalReply; + } + + /** + * @return TextQuote|null + */ + public function getQuote() + { + return $this->quote; + } + + /** + * @param TextQuote|null $quote + */ + public function setQuote($quote) + { + $this->quote = $quote; + } + + /** + * @return Story|null + */ + public function getReplyToStory() + { + return $this->replyToStory; + } + + /** + * @param Story|null $replyToStory + */ + public function setReplyToStory($replyToStory) + { + $this->replyToStory = $replyToStory; + } + + /** + * @return User|null + */ + public function getViaBot() + { + return $this->viaBot; + } + + /** + * @param User|null $viaBot + */ + public function setViaBot($viaBot) + { + $this->viaBot = $viaBot; + } + + /** + * @return int|null + */ + public function getEditDate() + { + return $this->editDate; + } + + /** + * @param mixed $editDate + * @return void + * @throws InvalidArgumentException + */ + public function setEditDate($editDate) + { + if (is_int($editDate)) { + $this->editDate = $editDate; + } else { + throw new InvalidArgumentException(); + } + } + + /** + * @return bool|null + */ + public function getHasProtectedContent() + { + return $this->hasProtectedContent; + } + + /** + * @param bool|null $hasProtectedContent + */ + public function setHasProtectedContent($hasProtectedContent) + { + $this->hasProtectedContent = $hasProtectedContent; + } + + /** + * @return bool|null + */ + public function getIsFromOffline() + { + return $this->isFromOffline; + } + + /** + * @param bool|null $isFromOffline + */ + public function setIsFromOffline($isFromOffline) + { + $this->isFromOffline = $isFromOffline; + } + + /** + * @return string|null + */ + public function getMediaGroupId() + { + return $this->mediaGroupId; + } + + /** + * @param string|null $mediaGroupId + */ + public function setMediaGroupId($mediaGroupId) + { + $this->mediaGroupId = $mediaGroupId; + } + + /** + * @return string|null + */ + public function getAuthorSignature() + { + return $this->authorSignature; + } + + /** + * @param string|null $authorSignature + */ + public function setAuthorSignature($authorSignature) + { + $this->authorSignature = $authorSignature; + } + + /** + * @return string|null + */ + public function getText() + { + return $this->text; + } + + /** + * @param string|null $text + */ + public function setText($text) + { + $this->text = $text; + } + + public function getEntities() + { + return $this->entities; + } + + /** + * @param array|null $entities */ - protected $pinnedMessage; + public function setEntities($entities) + { + $this->entities = $entities; + } /** - * Optional. Message is an invoice for a payment, information about the invoice. - * - * @var Invoice + * @return LinkPreviewOptions|null */ - protected $invoice; + public function getLinkPreviewOptions() + { + return $this->linkPreviewOptions; + } /** - * Optional. Message is a service message about a successful payment, information about the payment. - * - * @var SuccessfulPayment + * @param LinkPreviewOptions|null $linkPreviewOptions */ - protected $successfulPayment; + public function setLinkPreviewOptions($linkPreviewOptions) + { + $this->linkPreviewOptions = $linkPreviewOptions; + } /** - * Optional. For messages forwarded from channels, signature of the post author if present - * - * @var string + * @return string|null */ - protected $forwardSignature; + public function getEffectId() + { + return $this->effectId; + } /** - * Optional. Signature of the post author for messages in channels - * - * @var string + * @param string|null $effectId */ - protected $authorSignature; + public function setEffectId($effectId) + { + $this->effectId = $effectId; + } /** - * @return string + * @return Animation|null */ - public function getCaption() + public function getAnimation() { - return $this->caption; + return $this->animation; } /** - * @param string $caption + * @param Animation|null $animation */ - public function setCaption($caption) + public function setAnimation($animation) { - $this->caption = $caption; + $this->animation = $animation; } /** - * @return Audio + * @return Audio|null */ public function getAudio() { @@ -328,401 +1178,389 @@ public function getAudio() } /** - * @param Audio $audio + * @param Audio|null $audio */ - public function setAudio(Audio $audio) + public function setAudio($audio) { $this->audio = $audio; } /** - * @return Chat + * @return Document|null */ - public function getChat() + public function getDocument() { - return $this->chat; + return $this->document; } /** - * @param Chat $chat + * @param Document|null $document */ - public function setChat(Chat $chat) + public function setDocument($document) { - $this->chat = $chat; + $this->document = $document; } - /** - * @return Contact - */ - public function getContact() + public function getPhoto() { - return $this->contact; + return $this->photo; } /** - * @param Contact $contact + * @param array|null $photo */ - public function setContact(Contact $contact) + public function setPhoto($photo) { - $this->contact = $contact; + $this->photo = $photo; } /** - * @return int + * @return Sticker|null */ - public function getDate() + public function getSticker() { - return $this->date; + return $this->sticker; } /** - * @param int $date - * - * @throws InvalidArgumentException + * @param Sticker|null $sticker */ - public function setDate($date) + public function setSticker($sticker) { - if (is_integer($date)) { - $this->date = $date; - } else { - throw new InvalidArgumentException(); - } + $this->sticker = $sticker; } /** - * @return boolean + * @return Story|null */ - public function isDeleteChatPhoto() + public function getStory() { - return $this->deleteChatPhoto; + return $this->story; } /** - * @param boolean $deleteChatPhoto + * @param Story|null $story */ - public function setDeleteChatPhoto($deleteChatPhoto) + public function setStory($story) { - $this->deleteChatPhoto = (bool)$deleteChatPhoto; + $this->story = $story; } /** - * @return Document + * @return Video|null */ - public function getDocument() + public function getVideo() { - return $this->document; + return $this->video; } /** - * @param Document $document + * @param Video|null $video */ - public function setDocument($document) + public function setVideo($video) { - $this->document = $document; + $this->video = $video; } /** - * @return int + * @return VideoNote|null */ - public function getForwardDate() + public function getVideoNote() { - return $this->forwardDate; + return $this->videoNote; } /** - * @param int $forwardDate - * - * @throws InvalidArgumentException + * @param VideoNote|null $videoNote */ - public function setForwardDate($forwardDate) + public function setVideoNote($videoNote) { - if (is_integer($forwardDate)) { - $this->forwardDate = $forwardDate; - } else { - throw new InvalidArgumentException(); - } + $this->videoNote = $videoNote; } /** - * @return User + * @return Voice|null */ - public function getForwardFrom() + public function getVoice() { - return $this->forwardFrom; + return $this->voice; } /** - * @param User $forwardFrom + * @param Voice|null $voice */ - public function setForwardFrom(User $forwardFrom) + public function setVoice($voice) { - $this->forwardFrom = $forwardFrom; + $this->voice = $voice; } /** - * @return boolean + * @return null|string */ - public function isGroupChatCreated() + public function getCaption() { - return $this->groupChatCreated; + return $this->caption; } /** - * @param boolean $groupChatCreated + * @param string|null $caption */ - public function setGroupChatCreated($groupChatCreated) + public function setCaption($caption) { - $this->groupChatCreated = (bool)$groupChatCreated; + $this->caption = $caption; } /** - * @return User + * @return MessageEntity[]|null */ - public function getLeftChatMember() + public function getCaptionEntities() { - return $this->leftChatMember; + return $this->captionEntities; } /** - * @param User $leftChatMember + * @param MessageEntity[]|null $captionEntities */ - public function setLeftChatMember($leftChatMember) + public function setCaptionEntities($captionEntities) { - $this->leftChatMember = $leftChatMember; + $this->captionEntities = $captionEntities; } /** - * @return Location + * @return bool|null */ - public function getLocation() + public function getShowCaptionAboveMedia() { - return $this->location; + return $this->showCaptionAboveMedia; } /** - * @param Location $location + * @param bool|null $showCaptionAboveMedia */ - public function setLocation(Location $location) + public function setShowCaptionAboveMedia($showCaptionAboveMedia) { - $this->location = $location; + $this->showCaptionAboveMedia = $showCaptionAboveMedia; } /** - * @return Venue + * @return bool|null */ - public function getVenue() + public function getHasMediaSpoiler() { - return $this->venue; + return $this->hasMediaSpoiler; } /** - * @param Venue $venue + * @param bool|null $hasMediaSpoiler */ - public function setVenue($venue) + public function setHasMediaSpoiler($hasMediaSpoiler) { - $this->venue = $venue; + $this->hasMediaSpoiler = $hasMediaSpoiler; } /** - * @return int + * @return Contact|null */ - public function getMessageId() + public function getContact() { - return $this->messageId; + return $this->contact; } /** - * @param int $messageId - * - * @throws InvalidArgumentException + * @param Contact|null $contact */ - public function setMessageId($messageId) + public function setContact($contact) { - if (is_integer($messageId) || is_float($messageId)) { - $this->messageId = $messageId; - } else { - throw new InvalidArgumentException(); - } + $this->contact = $contact; } /** - * @return User + * @return Dice|null */ - public function getNewChatMember() + public function getDice() { - return $this->newChatMember; + return $this->dice; } /** - * @param User $newChatMember + * @param Dice|null $dice */ - public function setNewChatMember($newChatMember) + public function setDice($dice) { - $this->newChatMember = $newChatMember; + $this->dice = $dice; } /** - * @return array + * @return Game|null */ - public function getNewChatPhoto() + public function getGame() { - return $this->newChatPhoto; + return $this->game; } /** - * @param array $newChatPhoto + * @param Game|null $game */ - public function setNewChatPhoto($newChatPhoto) + public function setGame($game) { - $this->newChatPhoto = $newChatPhoto; + $this->game = $game; } /** - * @return string + * @return Poll|null */ - public function getNewChatTitle() + public function getPoll() { - return $this->newChatTitle; + return $this->poll; } /** - * @param string $newChatTitle + * @param Poll|null $poll */ - public function setNewChatTitle($newChatTitle) + public function setPoll($poll) { - $this->newChatTitle = $newChatTitle; + $this->poll = $poll; } /** - * @return array + * @return Venue|null */ - public function getPhoto() + public function getVenue() { - return $this->photo; + return $this->venue; } /** - * @param array $photo + * @param Venue|null $venue */ - public function setPhoto(array $photo) + public function setVenue($venue) { - $this->photo = $photo; + $this->venue = $venue; } /** - * @return Message + * @return Location|null */ - public function getReplyToMessage() + public function getLocation() { - return $this->replyToMessage; + return $this->location; } /** - * @param Message $replyToMessage + * @param Location|null $location */ - public function setReplyToMessage(Message $replyToMessage) + public function setLocation($location) { - $this->replyToMessage = $replyToMessage; + $this->location = $location; } - /** - * @return Sticker - */ - public function getSticker() + public function getNewChatMembers() { - return $this->sticker; + return $this->newChatMembers; } /** - * @param Sticker $sticker + * @param \TelegramBot\Api\Types\User[]|null $newChatMembers + * @return void */ - public function setSticker(Sticker $sticker) + public function setNewChatMembers($newChatMembers) { - $this->sticker = $sticker; + $this->newChatMembers = $newChatMembers; } /** - * @return string + * @return User|null */ - public function getText() + public function getLeftChatMember() { - return $this->text; + return $this->leftChatMember; } /** - * @param string $text + * @param User $leftChatMember + * @return void */ - public function setText($text) + public function setLeftChatMember($leftChatMember) { - $this->text = $text; + $this->leftChatMember = $leftChatMember; } /** - * @return array + * @return null|string */ - public function getEntities() + public function getNewChatTitle() { - return $this->entities; + return $this->newChatTitle; } /** - * @param array $entities + * @param string $newChatTitle + * @return void */ - public function setEntities($entities) + public function setNewChatTitle($newChatTitle) { - $this->entities = $entities; + $this->newChatTitle = $newChatTitle; + } + + public function getNewChatPhoto() + { + return $this->newChatPhoto; } /** - * @return User + * @param PhotoSize[]|null $newChatPhoto + * @return void */ - public function getFrom() + public function setNewChatPhoto($newChatPhoto) { - return $this->from; + $this->newChatPhoto = $newChatPhoto; } /** - * @param User $from + * @return bool|null */ - public function setFrom(User $from) + public function isDeleteChatPhoto() { - $this->from = $from; + return $this->deleteChatPhoto; } /** - * @return Video + * @param mixed $deleteChatPhoto + * @return void */ - public function getVideo() + public function setDeleteChatPhoto($deleteChatPhoto) { - return $this->video; + $this->deleteChatPhoto = (bool) $deleteChatPhoto; } /** - * @param Video $video + * @return bool|null */ - public function setVideo(Video $video) + public function isGroupChatCreated() { - $this->video = $video; + return $this->groupChatCreated; } /** - * @return Voice + * @param mixed $groupChatCreated + * @return void */ - public function getVoice() + public function setGroupChatCreated($groupChatCreated) { - return $this->voice; + $this->groupChatCreated = (bool) $groupChatCreated; } /** - * @param Voice $voice + * @return bool|null */ - public function setVoice($voice) + public function isSupergroupChatCreated() { - $this->voice = $voice; + return $this->supergroupChatCreated; } /** - * @param boolean $supergroupChatCreated + * @param bool $supergroupChatCreated + * @return void */ public function setSupergroupChatCreated($supergroupChatCreated) { @@ -730,15 +1568,16 @@ public function setSupergroupChatCreated($supergroupChatCreated) } /** - * @return boolean + * @return bool|null */ - public function isSupergroupChatCreated() + public function isChannelChatCreated() { - return $this->supergroupChatCreated; + return $this->channelChatCreated; } /** - * @param boolean $channelChatCreated + * @param bool $channelChatCreated + * @return void */ public function setChannelChatCreated($channelChatCreated) { @@ -746,15 +1585,16 @@ public function setChannelChatCreated($channelChatCreated) } /** - * @return boolean + * @return int|null */ - public function isChannelChatCreated() + public function getMigrateToChatId() { - return $this->channelChatCreated; + return $this->migrateToChatId; } /** * @param int $migrateToChatId + * @return void */ public function setMigrateToChatId($migrateToChatId) { @@ -762,32 +1602,22 @@ public function setMigrateToChatId($migrateToChatId) } /** - * @return int + * @return int|null */ - public function getMigrateToChatId() + public function getMigrateFromChatId() { - return $this->migrateToChatId; + return $this->migrateFromChatId; } /** * @param int $migrateFromChatId + * @return void */ public function setMigrateFromChatId($migrateFromChatId) { $this->migrateFromChatId = $migrateFromChatId; } - /** - * @return int - */ - public function getMigrateFromChatId() - { - return $this->migrateFromChatId; - } - - /** - * @return Message - */ public function getPinnedMessage() { return $this->pinnedMessage; @@ -795,6 +1625,7 @@ public function getPinnedMessage() /** * @param Message $pinnedMessage + * @return void */ public function setPinnedMessage($pinnedMessage) { @@ -802,8 +1633,7 @@ public function setPinnedMessage($pinnedMessage) } /** - * @author MY - * @return Invoice + * @return Invoice|null */ public function getInvoice() { @@ -811,8 +1641,8 @@ public function getInvoice() } /** - * @author MY * @param Invoice $invoice + * @return void */ public function setInvoice($invoice) { @@ -820,8 +1650,7 @@ public function setInvoice($invoice) } /** - * @author MY - * @return SuccessfulPayment + * @return SuccessfulPayment|null */ public function getSuccessfulPayment() { @@ -829,8 +1658,8 @@ public function getSuccessfulPayment() } /** - * @author MY * @param SuccessfulPayment $successfulPayment + * @return void */ public function setSuccessfulPayment($successfulPayment) { @@ -838,34 +1667,104 @@ public function setSuccessfulPayment($successfulPayment) } /** - * @return string + * @return null|string */ - public function getForwardSignature() + public function getConnectedWebsite() { - return $this->forwardSignature; + return $this->connectedWebsite; } /** - * @param string $forwardSignature + * @param string $connectedWebsite + * @return void */ - public function setForwardSignature($forwardSignature) + public function setConnectedWebsite($connectedWebsite) { - $this->forwardSignature = $forwardSignature; + $this->connectedWebsite = $connectedWebsite; } /** - * @return string + * @return WebAppData|null */ - public function getAuthorSignature() + public function getWebAppData() { - return $this->authorSignature; + return $this->webAppData; } /** - * @param string $authorSignature + * @param WebAppData|null $webAppData + * @return void */ - public function setAuthorSignature($authorSignature) + public function setWebAppData($webAppData) { - $this->authorSignature = $authorSignature; + $this->webAppData = $webAppData; + } + + /** + * @return InlineKeyboardMarkup|null + */ + public function getReplyMarkup() + { + return $this->replyMarkup; + } + + /** + * @param InlineKeyboardMarkup $replyMarkup + * @return void + */ + public function setReplyMarkup($replyMarkup) + { + $this->replyMarkup = $replyMarkup; + } + + /** + * @return ForumTopicCreated|null + */ + public function getForumTopicCreated() + { + return $this->forumTopicCreated; + } + + /** + * @param ForumTopicCreated $forumTopicCreated + * @return void + */ + public function setForumTopicCreated($forumTopicCreated) + { + $this->forumTopicCreated = $forumTopicCreated; + } + + /** + * @return ForumTopicClosed|null + */ + public function getForumTopicClosed() + { + return $this->forumTopicClosed; + } + + /** + * @param ForumTopicClosed $forumTopicClosed + * @return void + */ + public function setForumTopicClosed($forumTopicClosed) + { + $this->forumTopicClosed = $forumTopicClosed; + } + + /** + * @return ForumTopicReopened|null + */ + public function getForumTopicReopened() + { + return $this->forumTopicReopened; + } + + /** + * @param ForumTopicReopened $forumTopicReopened + * @return void + */ + public function setForumTopicReopened($forumTopicReopened) + { + $this->forumTopicReopened = $forumTopicReopened; } } diff --git a/src/Types/MessageAutoDeleteTimerChanged.php b/src/Types/MessageAutoDeleteTimerChanged.php new file mode 100644 index 00000000..9e662d94 --- /dev/null +++ b/src/Types/MessageAutoDeleteTimerChanged.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * New auto-delete time for messages in the chat; in seconds + * + * @var int + */ + protected $messageAutoDeleteTime; + + /** + * @return int + */ + public function getMessageAutoDeleteTime() + { + return $this->messageAutoDeleteTime; + } + + /** + * @param int $messageAutoDeleteTime + * @return void + */ + public function setMessageAutoDeleteTime($messageAutoDeleteTime) + { + $this->messageAutoDeleteTime = $messageAutoDeleteTime; + } +} diff --git a/src/Types/MessageEntity.php b/src/Types/MessageEntity.php index bd8934b4..a1499da1 100644 --- a/src/Types/MessageEntity.php +++ b/src/Types/MessageEntity.php @@ -1,53 +1,63 @@ true, 'offset' => true, 'length' => true, 'url' => true, + 'user' => User::class, + 'language' => true, + 'custom_emoji_id' => true, ]; /** * Type of the entity. - * One of mention (@username), hashtag, bot_command, url, email, bold (bold text), - * italic (italic text), code (monowidth string),pre (monowidth block), text_link (for clickable text URLs) + * One of mention (@username), hashtag (#hashtag), cashtag ($USD), bot_command, url, email, phone_number, + * bold (bold text), italic (italic text), underline (underlined text), strikethrough (strikethrough text), + * 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) * * @var string */ @@ -68,12 +78,34 @@ class MessageEntity extends BaseType implements TypeInterface protected $length; /** - * Optional. For “text_link” only, url that will be opened after user taps on the text + * Optional. For “text_link” only, URL that will be opened after user taps on the text * - * @var string + * @var string|null */ protected $url; + /** + * Optional. For “text_mention” only, the mentioned user + * + * @var User|null + */ + protected $user; + + /** + * Optional. For “pre” only, the programming language of the entity text + * + * @var string|null + */ + protected $language; + + /** + * Optional. For “custom_emoji” only, unique identifier of the custom emoji. + * Use getCustomEmojiStickers to get full information about the sticker + * + * @var string|null + */ + protected $customEmojiId; + /** * @return string */ @@ -84,6 +116,7 @@ public function getType() /** * @param string $type + * @return void */ public function setType($type) { @@ -100,6 +133,7 @@ public function getOffset() /** * @param int $offset + * @return void */ public function setOffset($offset) { @@ -116,6 +150,7 @@ public function getLength() /** * @param int $length + * @return void */ public function setLength($length) { @@ -123,7 +158,7 @@ public function setLength($length) } /** - * @return string + * @return null|string */ public function getUrl() { @@ -132,9 +167,61 @@ public function getUrl() /** * @param string $url + * @return void */ public function setUrl($url) { $this->url = $url; } + + /** + * @return User|null + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $user + * @return void + */ + public function setUser($user) + { + $this->user = $user; + } + + /** + * @return null|string + */ + public function getLanguage() + { + return $this->language; + } + + /** + * @param string $language + * @return void + */ + public function setLanguage($language) + { + $this->language = $language; + } + + /** + * @return null|string + */ + public function getCustomEmojiId() + { + return $this->customEmojiId; + } + + /** + * @param string $customEmojiId + * @return void + */ + public function setCustomEmojiId($customEmojiId) + { + $this->customEmojiId = $customEmojiId; + } } diff --git a/src/Types/MessageId.php b/src/Types/MessageId.php new file mode 100644 index 00000000..3fd88ff5 --- /dev/null +++ b/src/Types/MessageId.php @@ -0,0 +1,58 @@ + true, + ]; + + /** + * Unique message identifier + * + * @var int + */ + protected $messageId; + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + * @throws InvalidArgumentException + */ + public function setMessageId($messageId) + { + if (!is_int($messageId)) { + throw new InvalidArgumentException('MessageId must be an integer'); + } + $this->messageId = $messageId; + } +} diff --git a/src/Types/MessageOrigin.php b/src/Types/MessageOrigin.php new file mode 100644 index 00000000..c7daa670 --- /dev/null +++ b/src/Types/MessageOrigin.php @@ -0,0 +1,65 @@ + true, + 'date' => true, + ]; + + protected $type; + protected $date; + + /** + * @psalm-suppress MoreSpecificReturnType,LessSpecificReturnStatement + */ + public static function fromResponse($data) + { + self::validate($data); + $class = match ($data['type']) { + 'user' => MessageOriginUser::class, + 'hidden_user' => MessageOriginHiddenUser::class, + 'chat' => MessageOriginChat::class, + 'channel' => MessageOriginChannel::class, + default => MessageOrigin::class + }; + + $instance = new $class(); + $instance->map($data); + + return $instance; + } + + public function getType() + { + return $this->type; + } + + public function setType($type) + { + $this->type = $type; + } + + public function getDate() + { + return $this->date; + } + + public function setDate($date) + { + $this->date = $date; + } +} diff --git a/src/Types/MessageOriginChannel.php b/src/Types/MessageOriginChannel.php new file mode 100644 index 00000000..2e78834f --- /dev/null +++ b/src/Types/MessageOriginChannel.php @@ -0,0 +1,56 @@ + true, + 'date' => true, + 'chat' => Chat::class, + 'message_id' => true, + 'author_signature' => true, + ]; + + protected $chat; + protected $messageId; + protected $authorSignature; + + public function getChat(): ?Chat + { + return $this->chat; + } + + public function setChat($chat): void + { + $this->chat = $chat; + } + + public function getMessageId(): ?int + { + return $this->messageId; + } + + public function setMessageId($messageId): void + { + $this->messageId = $messageId; + } + + public function getAuthorSignature(): ?string + { + return $this->authorSignature; + } + + public function setAuthorSignature($authorSignature): void + { + $this->authorSignature = $authorSignature; + } +} diff --git a/src/Types/MessageOriginChat.php b/src/Types/MessageOriginChat.php new file mode 100644 index 00000000..3027b6f6 --- /dev/null +++ b/src/Types/MessageOriginChat.php @@ -0,0 +1,44 @@ + true, + 'date' => true, + 'sender_chat' => Chat::class, + 'author_signature' => true, + ]; + + protected $senderChat; + protected $authorSignature; + + public function getSenderChat() + { + return $this->senderChat; + } + + public function setSenderChat(Chat $senderChat) + { + $this->senderChat = $senderChat; + } + + public function getAuthorSignature() + { + return $this->authorSignature; + } + + public function setAuthorSignature($authorSignature) + { + $this->authorSignature = $authorSignature; + } +} diff --git a/src/Types/MessageOriginHiddenUser.php b/src/Types/MessageOriginHiddenUser.php new file mode 100644 index 00000000..5adee031 --- /dev/null +++ b/src/Types/MessageOriginHiddenUser.php @@ -0,0 +1,32 @@ + true, + 'date' => true, + 'sender_user_name' => true, + ]; + + protected $senderUserName; + + public function getSenderUserName() + { + return $this->senderUserName; + } + + public function setSenderUserName(string $senderUserName) + { + $this->senderUserName = $senderUserName; + } +} diff --git a/src/Types/MessageOriginUser.php b/src/Types/MessageOriginUser.php new file mode 100644 index 00000000..d68aaa7d --- /dev/null +++ b/src/Types/MessageOriginUser.php @@ -0,0 +1,32 @@ + true, + 'date' => true, + 'sender_user' => User::class, + ]; + + protected $senderUser; + + public function getSenderUser() + { + return $this->senderUser; + } + + public function setSenderUser(User $senderUser) + { + $this->senderUser = $senderUser; + } +} diff --git a/src/Types/MessageReactionCountUpdated.php b/src/Types/MessageReactionCountUpdated.php new file mode 100644 index 00000000..b768a919 --- /dev/null +++ b/src/Types/MessageReactionCountUpdated.php @@ -0,0 +1,124 @@ + Chat::class, + 'message_id' => true, + 'date' => true, + 'reactions' => ArrayOfReactionType::class, + ]; + + /** + * The chat containing the message + * + * @var Chat + */ + protected $chat; + + /** + * Unique message identifier inside the chat + * + * @var int + */ + protected $messageId; + + /** + * Date of the change in Unix time + * + * @var int + */ + protected $date; + + /** + * List of reactions that are present on the message + * + * @var array + */ + protected $reactions; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return array + */ + public function getReactions() + { + return $this->reactions; + } + + /** + * @param array $reactions + * @return void + */ + public function setReactions($reactions) + { + $this->reactions = $reactions; + } +} diff --git a/src/Types/MessageReactionUpdated.php b/src/Types/MessageReactionUpdated.php new file mode 100644 index 00000000..350ae560 --- /dev/null +++ b/src/Types/MessageReactionUpdated.php @@ -0,0 +1,199 @@ + Chat::class, + 'message_id' => true, + 'user' => User::class, + 'actor_chat' => Chat::class, + 'date' => true, + 'old_reaction' => ArrayOfReactionType::class, + 'new_reaction' => ArrayOfReactionType::class, + ]; + + /** + * The chat containing the message the user reacted to + * + * @var Chat + */ + protected $chat; + + /** + * Unique identifier of the message inside the chat + * + * @var int + */ + protected $messageId; + + /** + * Optional. The user that changed the reaction, if the user isn't anonymous + * + * @var User|null + */ + protected $user; + + /** + * Optional. The chat on behalf of which the reaction was changed, if the user is anonymous + * + * @var Chat|null + */ + protected $actorChat; + + /** + * Date of the change in Unix time + * + * @var int + */ + protected $date; + + /** + * Previous list of reaction types that were set by the user + * + * @var array + */ + protected $oldReaction; + + /** + * New list of reaction types that have been set by the user + * + * @var array + */ + protected $newReaction; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } + + /** + * @return User|null + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User|null $user + * @return void + */ + public function setUser($user) + { + $this->user = $user; + } + + /** + * @return Chat|null + */ + public function getActorChat() + { + return $this->actorChat; + } + + /** + * @param Chat|null $actorChat + * @return void + */ + public function setActorChat($actorChat) + { + $this->actorChat = $actorChat; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return array + */ + public function getOldReaction() + { + return $this->oldReaction; + } + + /** + * @param array $oldReaction + * @return void + */ + public function setOldReaction($oldReaction) + { + $this->oldReaction = $oldReaction; + } + + /** + * @return array + */ + public function getNewReaction() + { + return $this->newReaction; + } + + /** + * @param array $newReaction + * @return void + */ + public function setNewReaction($newReaction) + { + $this->newReaction = $newReaction; + } +} diff --git a/src/Types/OwnedGift.php b/src/Types/OwnedGift.php new file mode 100644 index 00000000..7f524927 --- /dev/null +++ b/src/Types/OwnedGift.php @@ -0,0 +1,96 @@ + true, + 'gift' => true, + 'owned_gift_id' => true, + 'sender_user' => User::class, + 'send_date' => true, + ]; + + protected $type; + protected $gift; + protected $ownedGiftId; + protected $senderUser; + protected $sendDate; + + final public function __construct() + { + } + + /** + * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType + */ + public static function fromResponse($data) + { + self::validate($data); + switch ($data['type']) { + case 'regular': + return OwnedGiftRegular::fromResponse($data); + case 'unique': + return OwnedGiftUnique::fromResponse($data); + default: + throw new InvalidArgumentException('Unknown owned gift type: ' . $data['type']); + } + } + + public function getType() + { + return $this->type; + } + + public function setType($type) + { + $this->type = $type; + } + + public function getGift() + { + return $this->gift; + } + + public function setGift($gift) + { + $this->gift = $gift; + } + + public function getOwnedGiftId() + { + return $this->ownedGiftId; + } + + public function setOwnedGiftId($ownedGiftId) + { + $this->ownedGiftId = $ownedGiftId; + } + + public function getSenderUser() + { + return $this->senderUser; + } + + public function setSenderUser($senderUser) + { + $this->senderUser = $senderUser; + } + + public function getSendDate() + { + return $this->sendDate; + } + + public function setSendDate($sendDate) + { + $this->sendDate = $sendDate; + } +} diff --git a/src/Types/OwnedGiftRegular.php b/src/Types/OwnedGiftRegular.php new file mode 100644 index 00000000..5a4ebc78 --- /dev/null +++ b/src/Types/OwnedGiftRegular.php @@ -0,0 +1,122 @@ + true, + 'gift' => Gift::class, + 'owned_gift_id' => true, + 'sender_user' => User::class, + 'send_date' => true, + 'text' => true, + 'entities' => ArrayOfMessageEntity::class, + 'is_private' => true, + 'is_saved' => true, + 'can_be_upgraded' => true, + 'was_refunded' => true, + 'convert_star_count' => true, + 'prepaid_upgrade_star_count' => true, + ]; + + protected $text; + protected $entities; + protected $isPrivate; + protected $isSaved; + protected $canBeUpgraded; + protected $wasRefunded; + protected $convertStarCount; + protected $prepaidUpgradeStarCount; + protected $type = 'regular'; + + public static function fromResponse($data) + { + self::validate($data); + $instance = new static(); + $instance->map($data); + return $instance; + } + + public function getText() + { + return $this->text; + } + + public function setText($text) + { + $this->text = $text; + } + + public function getEntities() + { + return $this->entities; + } + + public function setEntities($entities) + { + $this->entities = $entities; + } + + public function getIsPrivate() + { + return $this->isPrivate; + } + + public function setIsPrivate($isPrivate) + { + $this->isPrivate = $isPrivate; + } + + public function getIsSaved() + { + return $this->isSaved; + } + + public function setIsSaved($isSaved) + { + $this->isSaved = $isSaved; + } + + public function getCanBeUpgraded() + { + return $this->canBeUpgraded; + } + + public function setCanBeUpgraded($canBeUpgraded) + { + $this->canBeUpgraded = $canBeUpgraded; + } + + public function getWasRefunded() + { + return $this->wasRefunded; + } + + public function setWasRefunded($wasRefunded) + { + $this->wasRefunded = $wasRefunded; + } + + public function getConvertStarCount() + { + return $this->convertStarCount; + } + + public function setConvertStarCount($convertStarCount) + { + $this->convertStarCount = $convertStarCount; + } + + public function getPrepaidUpgradeStarCount() + { + return $this->prepaidUpgradeStarCount; + } + + public function setPrepaidUpgradeStarCount($prepaidUpgradeStarCount) + { + $this->prepaidUpgradeStarCount = $prepaidUpgradeStarCount; + } +} diff --git a/src/Types/OwnedGiftUnique.php b/src/Types/OwnedGiftUnique.php new file mode 100644 index 00000000..62445b5c --- /dev/null +++ b/src/Types/OwnedGiftUnique.php @@ -0,0 +1,62 @@ + true, + 'gift' => UniqueGift::class, + 'owned_gift_id' => true, + 'sender_user' => User::class, + 'send_date' => true, + 'is_saved' => true, + 'can_be_transferred' => true, + 'transfer_star_count' => true, + ]; + + protected $isSaved; + protected $canBeTransferred; + protected $transferStarCount; + protected $type = 'unique'; + + public static function fromResponse($data) + { + self::validate($data); + $instance = new static(); + $instance->map($data); + return $instance; + } + + public function getIsSaved() + { + return $this->isSaved; + } + + public function setIsSaved($isSaved) + { + $this->isSaved = $isSaved; + } + + public function getCanBeTransferred() + { + return $this->canBeTransferred; + } + + public function setCanBeTransferred($canBeTransferred) + { + $this->canBeTransferred = $canBeTransferred; + } + + public function getTransferStarCount() + { + return $this->transferStarCount; + } + + public function setTransferStarCount($transferStarCount) + { + $this->transferStarCount = $transferStarCount; + } +} diff --git a/src/Types/OwnedGifts.php b/src/Types/OwnedGifts.php new file mode 100644 index 00000000..c466f33a --- /dev/null +++ b/src/Types/OwnedGifts.php @@ -0,0 +1,51 @@ + true, + 'gifts' => ArrayOfOwnedGift::class, + 'next_offset' => true, + ]; + + protected $totalCount; + protected $gifts; + protected $nextOffset; + + public function getTotalCount() + { + return $this->totalCount; + } + + public function setTotalCount($totalCount) + { + $this->totalCount = $totalCount; + } + + public function getGifts() + { + return $this->gifts; + } + + public function setGifts($gifts) + { + $this->gifts = $gifts; + } + + public function getNextOffset() + { + return $this->nextOffset; + } + + public function setNextOffset($nextOffset) + { + $this->nextOffset = $nextOffset; + } +} diff --git a/src/Types/Payments/ArrayOfLabeledPrice.php b/src/Types/Payments/ArrayOfLabeledPrice.php index 85c60974..ab2f111c 100644 --- a/src/Types/Payments/ArrayOfLabeledPrice.php +++ b/src/Types/Payments/ArrayOfLabeledPrice.php @@ -4,6 +4,10 @@ abstract class ArrayOfLabeledPrice { + /** + * @param array $data + * @return LabeledPrice[] + */ public static function fromResponse($data) { $arrayOfLabeledPrice = []; diff --git a/src/Types/Payments/Invoice.php b/src/Types/Payments/Invoice.php index 61669a8b..9df2c29b 100644 --- a/src/Types/Payments/Invoice.php +++ b/src/Types/Payments/Invoice.php @@ -15,12 +15,12 @@ class Invoice extends BaseType /** * @var array */ - static protected $requiredParams = ['title', 'description', 'start_parameter', 'currency', 'total_amount']; + protected static $requiredParams = ['title', 'description', 'start_parameter', 'currency', 'total_amount']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'title' => true, 'description' => true, 'start_parameter' => true, @@ -74,7 +74,10 @@ public function getTitle() /** * @author MY + * * @param string $title + * + * @return void */ public function setTitle($title) { @@ -92,7 +95,10 @@ public function getDescription() /** * @author MY + * * @param string $description + * + * @return void */ public function setDescription($description) { @@ -110,7 +116,10 @@ public function getStartParameter() /** * @author MY + * * @param string $startParameter + * + * @return void */ public function setStartParameter($startParameter) { @@ -128,7 +137,10 @@ public function getCurrency() /** * @author MY + * * @param string $currency + * + * @return void */ public function setCurrency($currency) { @@ -146,7 +158,10 @@ public function getTotalAmount() /** * @author MY + * * @param int $totalAmount + * + * @return void */ public function setTotalAmount($totalAmount) { diff --git a/src/Types/Payments/LabeledPrice.php b/src/Types/Payments/LabeledPrice.php index c04b983b..be6c7a53 100644 --- a/src/Types/Payments/LabeledPrice.php +++ b/src/Types/Payments/LabeledPrice.php @@ -15,12 +15,12 @@ class LabeledPrice extends BaseType /** * @var array */ - static protected $requiredParams = ['label', 'amount']; + protected static $requiredParams = ['label', 'amount']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'label' => true, 'amount' => true ]; @@ -49,6 +49,8 @@ public function getLabel() /** * @param string $label + * + * @return void */ public function setLabel($label) { @@ -65,6 +67,8 @@ public function getAmount() /** * @param int $amount + * + * @return void */ public function setAmount($amount) { diff --git a/src/Types/Payments/OrderInfo.php b/src/Types/Payments/OrderInfo.php index 3d45d8db..d730595c 100644 --- a/src/Types/Payments/OrderInfo.php +++ b/src/Types/Payments/OrderInfo.php @@ -15,12 +15,12 @@ class OrderInfo extends BaseType /** * @var array */ - static protected $requiredParams = []; + protected static $requiredParams = []; /** * @var array */ - static protected $map = [ + protected static $map = [ 'name' => true, 'phone_number' => true, 'email' => true, @@ -30,34 +30,35 @@ class OrderInfo extends BaseType /** * Optional. User name * - * @var string + * @var string|null */ protected $name; /** * Optional. User's phone number * - * @var string + * @var string|null */ protected $phoneNumber; /** * Optional. User email * - * @var string + * @var string|null */ protected $email; /** * Optional. User shipping address * - * @var ShippingAddress + * @var ShippingAddress|null */ protected $shippingAddress; /** * @author MY - * @return string + * + * @return null|string */ public function getName() { @@ -66,7 +67,10 @@ public function getName() /** * @author MY + * * @param string $name + * + * @return void */ public function setName($name) { @@ -75,7 +79,8 @@ public function setName($name) /** * @author MY - * @return string + * + * @return null|string */ public function getPhoneNumber() { @@ -84,7 +89,10 @@ public function getPhoneNumber() /** * @author MY + * * @param string $phoneNumber + * + * @return void */ public function setPhoneNumber($phoneNumber) { @@ -93,7 +101,8 @@ public function setPhoneNumber($phoneNumber) /** * @author MY - * @return string + * + * @return null|string */ public function getEmail() { @@ -102,7 +111,10 @@ public function getEmail() /** * @author MY + * * @param string $email + * + * @return void */ public function setEmail($email) { @@ -111,7 +123,8 @@ public function setEmail($email) /** * @author MY - * @return ShippingAddress + * + * @return ShippingAddress|null */ public function getShippingAddress() { @@ -120,7 +133,10 @@ public function getShippingAddress() /** * @author MY + * * @param ShippingAddress $shippingAddress + * + * @return void */ public function setShippingAddress($shippingAddress) { diff --git a/src/Types/Payments/Query/AnswerPreCheckoutQuery.php b/src/Types/Payments/Query/AnswerPreCheckoutQuery.php index dd427d7d..f28741b7 100644 --- a/src/Types/Payments/Query/AnswerPreCheckoutQuery.php +++ b/src/Types/Payments/Query/AnswerPreCheckoutQuery.php @@ -3,7 +3,6 @@ namespace TelegramBot\Api\Types\Payments\Query; use TelegramBot\Api\BaseType; -use TelegramBot\Api\Types\Payments\ArrayOfLabeledPrice; /** * Class AnswerPreCheckoutQuery @@ -16,12 +15,12 @@ class AnswerPreCheckoutQuery extends BaseType /** * @var array */ - static protected $requiredParams = ['pre_checkout_query_id', 'ok']; + protected static $requiredParams = ['pre_checkout_query_id', 'ok']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'pre_checkout_query_id' => true, 'ok' => true, 'error_message' => true, @@ -50,7 +49,7 @@ class AnswerPreCheckoutQuery extends BaseType /** * @author MY - * @return true + * @return bool */ public function getOk() { @@ -59,7 +58,10 @@ public function getOk() /** * @author MY - * @param true $ok + * + * @param bool $ok + * + * @return void */ public function setOk($ok) { @@ -77,7 +79,10 @@ public function getErrorMessage() /** * @author MY + * * @param string $errorMessage + * + * @return void */ public function setErrorMessage($errorMessage) { @@ -95,7 +100,10 @@ public function getPreCheckoutQueryId() /** * @author MY + * * @param string $preCheckoutQueryId + * + * @return void */ public function setPreCheckoutQueryId($preCheckoutQueryId) { diff --git a/src/Types/Payments/Query/AnswerShippingQuery.php b/src/Types/Payments/Query/AnswerShippingQuery.php index f7ea2871..c663e72e 100644 --- a/src/Types/Payments/Query/AnswerShippingQuery.php +++ b/src/Types/Payments/Query/AnswerShippingQuery.php @@ -17,12 +17,12 @@ class AnswerShippingQuery extends BaseType /** * @var array */ - static protected $requiredParams = ['shipping_query_id', 'ok']; + protected static $requiredParams = ['shipping_query_id', 'ok']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'shipping_query_id' => true, 'ok' => true, 'shipping_options' => ArrayOfLabeledPrice::class, @@ -69,7 +69,10 @@ public function getShippingQueryId() /** * @author MY + * * @param string $shippingQueryId + * + * @return void */ public function setShippingQueryId($shippingQueryId) { @@ -87,7 +90,10 @@ public function getOk() /** * @author MY + * * @param true $ok + * + * @return void */ public function setOk($ok) { @@ -105,7 +111,10 @@ public function getShippingOptions() /** * @author MY + * * @param array $shippingOptions + * + * @return void */ public function setShippingOptions($shippingOptions) { @@ -123,7 +132,10 @@ public function getErrorMessage() /** * @author MY + * * @param string $errorMessage + * + * @return void */ public function setErrorMessage($errorMessage) { diff --git a/src/Types/Payments/Query/PreCheckoutQuery.php b/src/Types/Payments/Query/PreCheckoutQuery.php index 7422f286..51b2e49a 100644 --- a/src/Types/Payments/Query/PreCheckoutQuery.php +++ b/src/Types/Payments/Query/PreCheckoutQuery.php @@ -3,9 +3,7 @@ namespace TelegramBot\Api\Types\Payments\Query; use TelegramBot\Api\BaseType; -use TelegramBot\Api\Types\Payments\ArrayOfLabeledPrice; use TelegramBot\Api\Types\Payments\OrderInfo; -use TelegramBot\Api\Types\Payments\ShippingAddress; use TelegramBot\Api\Types\User; /** @@ -19,12 +17,12 @@ class PreCheckoutQuery extends BaseType /** * @var array */ - static protected $requiredParams = ['id', 'from', 'currency', 'total_amount', 'invoice_payload']; + protected static $requiredParams = ['id', 'from', 'currency', 'total_amount', 'invoice_payload']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'from' => User::class, 'currency' => true, @@ -72,14 +70,14 @@ class PreCheckoutQuery extends BaseType /** * Optional. Identifier of the shipping option chosen by the user * - * @var string + * @var string|null */ protected $shippingOptionId; /** * Optional. Order info provided by the user * - * @var OrderInfo + * @var OrderInfo|null */ protected $orderInfo; @@ -94,7 +92,10 @@ public function getId() /** * @author MY + * * @param string $id + * + * @return void */ public function setId($id) { @@ -112,7 +113,10 @@ public function getFrom() /** * @author MY + * * @param User $from + * + * @return void */ public function setFrom($from) { @@ -130,7 +134,10 @@ public function getCurrency() /** * @author MY + * * @param string $currency + * + * @return void */ public function setCurrency($currency) { @@ -148,7 +155,10 @@ public function getTotalAmount() /** * @author MY + * * @param int $totalAmount + * + * @return void */ public function setTotalAmount($totalAmount) { @@ -166,7 +176,10 @@ public function getInvoicePayload() /** * @author MY + * * @param mixed $invoicePayload + * + * @return void */ public function setInvoicePayload($invoicePayload) { @@ -175,7 +188,8 @@ public function setInvoicePayload($invoicePayload) /** * @author MY - * @return string + * + * @return null|string */ public function getShippingOptionId() { @@ -184,7 +198,10 @@ public function getShippingOptionId() /** * @author MY + * * @param string $shippingOptionId + * + * @return void */ public function setShippingOptionId($shippingOptionId) { @@ -193,7 +210,8 @@ public function setShippingOptionId($shippingOptionId) /** * @author MY - * @return OrderInfo + * + * @return OrderInfo|null */ public function getOrderInfo() { @@ -202,7 +220,10 @@ public function getOrderInfo() /** * @author MY + * * @param OrderInfo $orderInfo + * + * @return void */ public function setOrderInfo($orderInfo) { diff --git a/src/Types/Payments/Query/ShippingQuery.php b/src/Types/Payments/Query/ShippingQuery.php index f50d1f9e..df4c54bf 100644 --- a/src/Types/Payments/Query/ShippingQuery.php +++ b/src/Types/Payments/Query/ShippingQuery.php @@ -3,7 +3,6 @@ namespace TelegramBot\Api\Types\Payments\Query; use TelegramBot\Api\BaseType; -use TelegramBot\Api\Types\Payments\ArrayOfLabeledPrice; use TelegramBot\Api\Types\Payments\ShippingAddress; use TelegramBot\Api\Types\User; @@ -18,14 +17,14 @@ class ShippingQuery extends BaseType /** * @var array */ - static protected $requiredParams = ['id', 'from', 'invoice_payload', 'shipping_address']; + protected static $requiredParams = ['id', 'from', 'invoice_payload', 'shipping_address']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'from' => User::class, 'invoice_payload' => true, @@ -71,7 +70,10 @@ public function getId() /** * @author MY + * * @param string $id + * + * @return void */ public function setId($id) { @@ -89,7 +91,10 @@ public function getFrom() /** * @author MY + * * @param User $from + * + * @return void */ public function setFrom($from) { @@ -107,7 +112,10 @@ public function getInvoicePayload() /** * @author MY + * * @param string $invoicePayload + * + * @return void */ public function setInvoicePayload($invoicePayload) { @@ -125,7 +133,10 @@ public function getShippingAddress() /** * @author MY + * * @param ShippingAddress $shippingAddress + * + * @return void */ public function setShippingAddress($shippingAddress) { diff --git a/src/Types/Payments/ShippingAddress.php b/src/Types/Payments/ShippingAddress.php index d5e34728..3f1f626e 100644 --- a/src/Types/Payments/ShippingAddress.php +++ b/src/Types/Payments/ShippingAddress.php @@ -15,12 +15,12 @@ class ShippingAddress extends BaseType /** * @var array */ - static protected $requiredParams = ['country_code', 'state', 'city', 'street_line1', 'street_line2', 'post_code']; + protected static $requiredParams = ['country_code', 'state', 'city', 'street_line1', 'street_line2', 'post_code']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'country_code' => true, 'state' => true, 'city' => true, @@ -60,14 +60,14 @@ class ShippingAddress extends BaseType /** * Second line for the address * - * @var integer + * @var string */ protected $streetLine2; /** * Address post code * - * @var integer + * @var string */ protected $postCode; @@ -82,7 +82,10 @@ public function getCountryCode() /** * @author MY + * * @param string $countryCode + * + * @return void */ public function setCountryCode($countryCode) { @@ -100,7 +103,10 @@ public function getState() /** * @author MY + * * @param string $state + * + * @return void */ public function setState($state) { @@ -118,7 +124,10 @@ public function getCity() /** * @author MY + * * @param string $city + * + * @return void */ public function setCity($city) { @@ -136,7 +145,10 @@ public function getStreetLine1() /** * @author MY + * * @param string $streetLine1 + * + * @return void */ public function setStreetLine1($streetLine1) { @@ -145,7 +157,7 @@ public function setStreetLine1($streetLine1) /** * @author MY - * @return int + * @return string */ public function getStreetLine2() { @@ -154,7 +166,10 @@ public function getStreetLine2() /** * @author MY - * @param int $streetLine2 + * + * @param string $streetLine2 + * + * @return void */ public function setStreetLine2($streetLine2) { @@ -163,7 +178,7 @@ public function setStreetLine2($streetLine2) /** * @author MY - * @return int + * @return string */ public function getPostCode() { @@ -172,7 +187,10 @@ public function getPostCode() /** * @author MY - * @param int $postCode + * + * @param string $postCode + * + * @return void */ public function setPostCode($postCode) { diff --git a/src/Types/Payments/ShippingOption.php b/src/Types/Payments/ShippingOption.php index 15359592..34bf3447 100644 --- a/src/Types/Payments/ShippingOption.php +++ b/src/Types/Payments/ShippingOption.php @@ -15,12 +15,12 @@ class ShippingOption extends BaseType /** * @var array */ - static protected $requiredParams = ['id', 'title', 'prices']; + protected static $requiredParams = ['id', 'title', 'prices']; /** * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'title' => true, 'prices' => ArrayOfLabeledPrice::class @@ -58,7 +58,10 @@ public function getId() /** * @author MY + * * @param string $id + * + * @return void */ public function setId($id) { @@ -76,7 +79,10 @@ public function getTitle() /** * @author MY + * * @param string $title + * + * @return void */ public function setTitle($title) { @@ -94,7 +100,10 @@ public function getPrices() /** * @author MY + * * @param array $prices + * + * @return void */ public function setPrices($prices) { diff --git a/src/Types/Payments/SuccessfulPayment.php b/src/Types/Payments/SuccessfulPayment.php index 51707930..b9186e0d 100644 --- a/src/Types/Payments/SuccessfulPayment.php +++ b/src/Types/Payments/SuccessfulPayment.php @@ -15,7 +15,7 @@ class SuccessfulPayment extends BaseType /** * @var array */ - static protected $requiredParams = [ + protected static $requiredParams = [ 'currency', 'total_amount', 'invoice_payload', @@ -26,7 +26,7 @@ class SuccessfulPayment extends BaseType /** * @var array */ - static protected $map = [ + protected static $map = [ 'currency' => true, 'total_amount' => true, 'invoice_payload' => true, @@ -60,14 +60,14 @@ class SuccessfulPayment extends BaseType /** * Optional. Identifier of the shipping option chosen by the user * - * @var string + * @var string|null */ protected $shippingOptionId; /** * Optional. Order info provided by the user * - * @var OrderInfo + * @var OrderInfo|null */ protected $orderInfo; @@ -96,7 +96,10 @@ public function getCurrency() /** * @author MY + * * @param string $currency + * + * @return void */ public function setCurrency($currency) { @@ -114,7 +117,10 @@ public function getTotalAmount() /** * @author MY + * * @param int $totalAmount + * + * @return void */ public function setTotalAmount($totalAmount) { @@ -132,7 +138,10 @@ public function getInvoicePayload() /** * @author MY + * * @param array $invoicePayload + * + * @return void */ public function setInvoicePayload($invoicePayload) { @@ -141,7 +150,8 @@ public function setInvoicePayload($invoicePayload) /** * @author MY - * @return string + * + * @return null|string */ public function getShippingOptionId() { @@ -150,7 +160,10 @@ public function getShippingOptionId() /** * @author MY + * * @param string $shippingOptionId + * + * @return void */ public function setShippingOptionId($shippingOptionId) { @@ -168,7 +181,10 @@ public function getTelegramPaymentChargeId() /** * @author MY + * * @param string $telegramPaymentChargeId + * + * @return void */ public function setTelegramPaymentChargeId($telegramPaymentChargeId) { @@ -186,7 +202,10 @@ public function getProviderPaymentChargeId() /** * @author MY + * * @param mixed $providerPaymentChargeId + * + * @return void */ public function setProviderPaymentChargeId($providerPaymentChargeId) { @@ -195,7 +214,8 @@ public function setProviderPaymentChargeId($providerPaymentChargeId) /** * @author MY - * @return OrderInfo + * + * @return OrderInfo|null */ public function getOrderInfo() { @@ -204,7 +224,10 @@ public function getOrderInfo() /** * @author MY + * * @param OrderInfo $orderInfo + * + * @return void */ public function setOrderInfo($orderInfo) { diff --git a/src/Types/PhotoSize.php b/src/Types/PhotoSize.php index 61a1c744..07144621 100644 --- a/src/Types/PhotoSize.php +++ b/src/Types/PhotoSize.php @@ -19,27 +19,35 @@ class PhotoSize extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'width', 'height']; + protected static $requiredParams = ['file_id', 'file_unique_id', 'width', 'height']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, + 'file_unique_id' => true, 'width' => true, 'height' => true, 'file_size' => true, ]; /** - * Unique identifier for this file + * Identifier for this file, which can be used to download or reuse the file * * @var string */ protected $fileId; + /** + * 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. + * + * @var string + */ + protected $fileUniqueId; + /** * Photo width * @@ -55,9 +63,9 @@ class PhotoSize extends BaseType implements TypeInterface protected $height; /** - * Optional. File size + * Optional. File size in bytes * - * @var int + * @var int|null */ protected $fileSize; @@ -71,29 +79,47 @@ public function getFileId() /** * @param string $fileId + * @return void */ public function setFileId($fileId) { $this->fileId = $fileId; } + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + /** * @return int */ - public function getFileSize() + public function getWidth() { - return $this->fileSize; + return $this->width; } /** - * @param int $fileSize - * + * @param int $width + * @return void * @throws InvalidArgumentException */ - public function setFileSize($fileSize) + public function setWidth($width) { - if (is_integer($fileSize)) { - $this->fileSize = $fileSize; + if (is_integer($width)) { + $this->width = $width; } else { throw new InvalidArgumentException(); } @@ -109,7 +135,7 @@ public function getHeight() /** * @param int $height - * + * @return void * @throws InvalidArgumentException */ public function setHeight($height) @@ -122,22 +148,22 @@ public function setHeight($height) } /** - * @return int + * @return int|null */ - public function getWidth() + public function getFileSize() { - return $this->width; + return $this->fileSize; } /** - * @param int $width - * + * @param int|null $fileSize + * @return void * @throws InvalidArgumentException */ - public function setWidth($width) + public function setFileSize($fileSize) { - if (is_integer($width)) { - $this->width = $width; + if (is_integer($fileSize) || is_null($fileSize)) { + $this->fileSize = $fileSize; } else { throw new InvalidArgumentException(); } diff --git a/src/Types/Poll.php b/src/Types/Poll.php new file mode 100644 index 00000000..b8bbb90b --- /dev/null +++ b/src/Types/Poll.php @@ -0,0 +1,392 @@ + true, + 'question' => true, + 'question_entities' => ArrayOfMessageEntity::class, + 'options' => ArrayOfPollOption::class, + 'total_voter_count' => true, + 'is_closed' => true, + 'is_anonymous' => true, + 'type' => true, + 'allows_multiple_answers' => true, + 'correct_option_id' => true, + 'explanation' => true, + 'explanation_entities' => ArrayOfMessageEntity::class, + 'open_period' => true, + 'close_date' => true, + ]; + + /** + * Unique poll identifier + * + * @var string + */ + protected $id; + + /** + * Poll question, 1-300 characters + * + * @var string + */ + protected $question; + + /** + * Optional. Special entities that appear in the question. Currently, only custom emoji entities are allowed in poll questions. + * + * @var array|null + */ + protected $questionEntities; + + /** + * List of poll options + * Array of \TelegramBot\Api\Types\PollOption + * + * @var array + */ + protected $options; + + /** + * Total number of users that voted in the poll + * + * @var int + */ + protected $totalVoterCount; + + /** + * True, if the poll is closed + * + * @var bool + */ + protected $isClosed; + + /** + * True, if the poll is anonymous + * + * @var bool + */ + protected $isAnonymous; + + /** + * Poll type, currently can be “regular” or “quiz” + * + * @var string + */ + protected $type; + + /** + * True, if the poll allows multiple answers + * + * @var bool + */ + protected $allowsMultipleAnswers; + + /** + * 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. + * + * @var int|null + */ + protected $correctOptionId; + + /** + * 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 + * + * @var string|null + */ + protected $explanation; + + /** + * Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation + * + * @var array|null + */ + protected $explanationEntities; + + /** + * Optional. Amount of time in seconds the poll will be active after creation + * + * @var int|null + */ + protected $openPeriod; + + /** + * Optional. Point in time (Unix timestamp) when the poll will be automatically closed + * + * @var int|null + */ + protected $closeDate; + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return void + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return string + */ + public function getQuestion() + { + return $this->question; + } + + /** + * @param string $question + * @return void + */ + public function setQuestion($question) + { + $this->question = $question; + } + + /** + * @return array|null + */ + public function getQuestionEntities() + { + return $this->questionEntities; + } + + /** + * @param array|null $questionEntities + * @return void + */ + public function setQuestionEntities($questionEntities) + { + $this->questionEntities = $questionEntities; + } + + /** + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * @param array $options + * @return void + */ + public function setOptions($options) + { + $this->options = $options; + } + + /** + * @return int + */ + public function getTotalVoterCount() + { + return $this->totalVoterCount; + } + + /** + * @param int $totalVoterCount + * @return void + */ + public function setTotalVoterCount($totalVoterCount) + { + $this->totalVoterCount = $totalVoterCount; + } + + /** + * @return bool + */ + public function isClosed() + { + return $this->isClosed; + } + + /** + * @param bool $isClosed + * @return void + */ + public function setIsClosed($isClosed) + { + $this->isClosed = $isClosed; + } + + /** + * @return bool + */ + public function isAnonymous() + { + return $this->isAnonymous; + } + + /** + * @param bool $isAnonymous + * @return void + */ + public function setIsAnonymous($isAnonymous) + { + $this->isAnonymous = $isAnonymous; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return bool + */ + public function isAllowsMultipleAnswers() + { + return $this->allowsMultipleAnswers; + } + + /** + * @param bool $allowsMultipleAnswers + * @return void + */ + public function setAllowsMultipleAnswers($allowsMultipleAnswers) + { + $this->allowsMultipleAnswers = $allowsMultipleAnswers; + } + + /** + * @return int|null + */ + public function getCorrectOptionId() + { + return $this->correctOptionId; + } + + /** + * @param int $correctOptionId + * @return void + */ + public function setCorrectOptionId($correctOptionId) + { + $this->correctOptionId = $correctOptionId; + } + + /** + * @return string|null + */ + public function getExplanation() + { + return $this->explanation; + } + + /** + * @param string|null $explanation + * @return void + */ + public function setExplanation($explanation) + { + $this->explanation = $explanation; + } + + /** + * @return array|null + */ + public function getExplanationEntities() + { + return $this->explanationEntities; + } + + /** + * @param array|null $explanationEntities + * @return void + */ + public function setExplanationEntities($explanationEntities) + { + $this->explanationEntities = $explanationEntities; + } + + /** + * @return int|null + */ + public function getOpenPeriod() + { + return $this->openPeriod; + } + + /** + * @param int|null $openPeriod + * @return void + */ + public function setOpenPeriod($openPeriod) + { + $this->openPeriod = $openPeriod; + } + + /** + * @return int|null + */ + public function getCloseDate() + { + return $this->closeDate; + } + + /** + * @param int|null $closeDate + * @return void + */ + public function setCloseDate($closeDate) + { + $this->closeDate = $closeDate; + } +} diff --git a/src/Types/PollAnswer.php b/src/Types/PollAnswer.php new file mode 100644 index 00000000..69f19c52 --- /dev/null +++ b/src/Types/PollAnswer.php @@ -0,0 +1,132 @@ + true, + 'voter_chat' => Chat::class, + 'user' => User::class, + 'option_ids' => true, + ]; + + /** + * Unique poll identifier + * + * @var string + */ + protected $pollId; + + /** + * Optional. The chat that changed the answer to the poll, if the voter is anonymous + * + * @var Chat|null + */ + protected $voterChat; + + /** + * Optional. The user that changed the answer to the poll, if the voter isn't anonymous + * + * @var User|null + */ + protected $user; + + /** + * 0-based identifiers of chosen answer options. May be empty if the vote was retracted + * + * @var int[] + */ + protected $optionIds; + + /** + * @return string + */ + public function getPollId() + { + return $this->pollId; + } + + /** + * @param string $pollId + * @return void + */ + public function setPollId($pollId) + { + $this->pollId = $pollId; + } + + /** + * @return Chat|null + */ + public function getVoterChat() + { + return $this->voterChat; + } + + /** + * @param Chat|null $voterChat + * @return void + */ + public function setVoterChat($voterChat) + { + $this->voterChat = $voterChat; + } + + /** + * @return User|null + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User|null $user + * @return void + */ + public function setUser($user) + { + $this->user = $user; + } + + /** + * @return int[] + */ + public function getOptionIds() + { + return $this->optionIds; + } + + /** + * @param int[] $optionIds + * @return void + */ + public function setOptionIds(array $optionIds) + { + $this->optionIds = $optionIds; + } +} diff --git a/src/Types/PollOption.php b/src/Types/PollOption.php new file mode 100644 index 00000000..f9b70304 --- /dev/null +++ b/src/Types/PollOption.php @@ -0,0 +1,105 @@ + true, + 'voter_count' => true, + 'text_entities' => ArrayOfMessageEntity::class + ]; + + /** + * Option text, 1-100 characters + * + * @var string + */ + protected $text; + + /** + * Number of users that voted for this option + * + * @var integer + */ + protected $voterCount; + + /** + * Optional. Special entities that appear in the option text. Currently, only custom emoji entities are allowed in poll option texts + * + * @var array|null + */ + protected $textEntities; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return int + */ + public function getVoterCount() + { + return $this->voterCount; + } + + /** + * @param int $voterCount + * @return void + */ + public function setVoterCount($voterCount) + { + $this->voterCount = $voterCount; + } + + /** + * @return array|null + */ + public function getTextEntities() + { + return $this->textEntities; + } + + /** + * @param array|null $textEntities + * @return void + */ + public function setTextEntities($textEntities) + { + $this->textEntities = $textEntities; + } +} diff --git a/src/Types/ProximityAlertTriggered.php b/src/Types/ProximityAlertTriggered.php new file mode 100644 index 00000000..837c4d50 --- /dev/null +++ b/src/Types/ProximityAlertTriggered.php @@ -0,0 +1,105 @@ + User::class, + 'watcher' => User::class, + 'distance' => true, + ]; + + /** + * User that triggered the alert + * + * @var User + */ + protected $traveler; + + /** + * User that set the alert + * + * @var User + */ + protected $watcher; + + /** + * The distance between the users + * + * @var int + */ + protected $distance; + + /** + * @return User + */ + public function getTraveler() + { + return $this->traveler; + } + + /** + * @param User $traveler + * @return void + */ + public function setTraveler(User $traveler) + { + $this->traveler = $traveler; + } + + /** + * @return User + */ + public function getWatcher() + { + return $this->watcher; + } + + /** + * @param User $watcher + * @return void + */ + public function setWatcher(User $watcher) + { + $this->watcher = $watcher; + } + + /** + * @return int + */ + public function getDistance() + { + return $this->distance; + } + + /** + * @param int $distance + * @return void + */ + public function setDistance($distance) + { + $this->distance = $distance; + } +} diff --git a/src/Types/ReactionCount.php b/src/Types/ReactionCount.php new file mode 100644 index 00000000..be6f62b9 --- /dev/null +++ b/src/Types/ReactionCount.php @@ -0,0 +1,74 @@ + ReactionType::class, + 'total_count' => true, + ]; + + /** + * Type of the reaction + * + * @var ReactionType + */ + protected $type; + + /** + * Number of times the reaction was added + * + * @var int + */ + protected $totalCount; + + /** + * @return ReactionType + */ + public function getType() + { + return $this->type; + } + + /** + * @param ReactionType $type + * @return void + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return int + */ + public function getTotalCount() + { + return $this->totalCount; + } + + /** + * @param int $totalCount + * @return void + */ + public function setTotalCount($totalCount) + { + $this->totalCount = $totalCount; + } +} diff --git a/src/Types/ReactionType.php b/src/Types/ReactionType.php new file mode 100644 index 00000000..983473e7 --- /dev/null +++ b/src/Types/ReactionType.php @@ -0,0 +1,36 @@ +type; + } + + /** + * Set the type of the reaction. + * + * @param string $type + */ + protected function setType($type) + { + $this->type = $type; + } +} diff --git a/src/Types/ReactionTypeCustomEmoji.php b/src/Types/ReactionTypeCustomEmoji.php new file mode 100644 index 00000000..6e7c7b74 --- /dev/null +++ b/src/Types/ReactionTypeCustomEmoji.php @@ -0,0 +1,56 @@ + true, + 'custom_emoji_id' => true, + ]; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['type', 'custom_emoji_id']; + + /** + * Custom emoji identifier + * + * @var string + */ + protected $customEmojiId; + + /** + * Get the custom emoji identifier. + * + * @return string + */ + public function getCustomEmojiId() + { + return $this->customEmojiId; + } + + /** + * Set the custom emoji identifier. + * + * @param string $customEmojiId + */ + protected function setCustomEmojiId($customEmojiId) + { + $this->customEmojiId = $customEmojiId; + } +} diff --git a/src/Types/ReactionTypeEmoji.php b/src/Types/ReactionTypeEmoji.php new file mode 100644 index 00000000..9fec8892 --- /dev/null +++ b/src/Types/ReactionTypeEmoji.php @@ -0,0 +1,55 @@ + true, + 'emoji' => true, + ]; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['type', 'emoji']; + /** + * Reaction emoji + * + * @var string + */ + protected $emoji; + + /** + * Get the reaction emoji. + * + * @return string + */ + public function getEmoji() + { + return $this->emoji; + } + + /** + * Set the reaction emoji. + * + * @param string $emoji + */ + protected function setEmoji($emoji) + { + $this->emoji = $emoji; + } +} diff --git a/src/Types/ReplyKeyboardHide.php b/src/Types/ReplyKeyboardHide.php index d7c27e51..6dad3664 100644 --- a/src/Types/ReplyKeyboardHide.php +++ b/src/Types/ReplyKeyboardHide.php @@ -5,6 +5,8 @@ use TelegramBot\Api\BaseType; /** + * @deprecated Use ReplyKeyboardRemove + * * Class ReplyKeyboardHide * Upon receiving a message with this object, Telegram clients will hide the current custom keyboard * and display the default letter-keyboard. By default, custom keyboards are displayed @@ -20,14 +22,14 @@ class ReplyKeyboardHide extends BaseType * * @var array */ - static protected $requiredParams = ['hide_keyboard']; + protected static $requiredParams = ['hide_keyboard']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'hide_keyboard' => true, 'selective' => true ]; @@ -45,10 +47,14 @@ class ReplyKeyboardHide extends BaseType * 1) users that are @mentioned in the text of the Message object; * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. * - * @var bool + * @var bool|null */ protected $selective; + /** + * @param bool $hideKeyboard + * @param bool|null $selective + */ public function __construct($hideKeyboard = true, $selective = null) { $this->hideKeyboard = $hideKeyboard; @@ -56,7 +62,7 @@ public function __construct($hideKeyboard = true, $selective = null) } /** - * @return boolean + * @return bool */ public function isHideKeyboard() { @@ -64,7 +70,8 @@ public function isHideKeyboard() } /** - * @param boolean $hideKeyboard + * @param bool $hideKeyboard + * @return void */ public function setHideKeyboard($hideKeyboard) { @@ -72,7 +79,7 @@ public function setHideKeyboard($hideKeyboard) } /** - * @return boolean + * @return bool|null */ public function isSelective() { @@ -80,7 +87,8 @@ public function isSelective() } /** - * @param boolean $selective + * @param bool $selective + * @return void */ public function setSelective($selective) { diff --git a/src/Types/ReplyKeyboardMarkup.php b/src/Types/ReplyKeyboardMarkup.php index 5c9cce9e..f490ec4f 100644 --- a/src/Types/ReplyKeyboardMarkup.php +++ b/src/Types/ReplyKeyboardMarkup.php @@ -17,18 +17,20 @@ class ReplyKeyboardMarkup extends BaseType * * @var array */ - static protected $requiredParams = ['keyboard']; + protected static $requiredParams = ['keyboard']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'keyboard' => true, 'one_time_keyboard' => true, 'resize_keyboard' => true, - 'selective' => true + 'selective' => true, + 'is_persistent' => true, + 'input_field_placeholder' => true, ]; /** @@ -44,14 +46,14 @@ class ReplyKeyboardMarkup extends BaseType * (e.g., make the keyboard smaller if there are just two rows of buttons). * Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. * - * @var bool + * @var bool|null */ protected $resizeKeyboard; /** * Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. * - * @var bool + * @var bool|null */ protected $oneTimeKeyboard; @@ -61,16 +63,41 @@ class ReplyKeyboardMarkup extends BaseType * 1) users that are @mentioned in the text of the Message object; * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. * - * @var bool + * @var bool|null */ protected $selective; - public function __construct($keyboard, $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null) + /** + * Optional. Requests clients to always show the keyboard when the regular keyboard is hidden. + * Defaults to false, in which case the custom keyboard can be hidden and opened with a keyboard icon. + * + * @var bool|null + */ + protected $isPersistent; + + /** + * Optional. The placeholder to be shown in the input field when the keyboard is active; 1-64 characters + * + * @var string|null + */ + protected $inputFieldPlaceholder; + + /** + * @param array $keyboard + * @param bool|null $oneTimeKeyboard + * @param bool|null $resizeKeyboard + * @param bool|null $selective + * @param bool|null $isPersistent + * @param string|null $inputFieldPlaceholder + */ + public function __construct($keyboard = [], $oneTimeKeyboard = null, $resizeKeyboard = null, $selective = null, $isPersistent = null, $inputFieldPlaceholder = null) { $this->keyboard = $keyboard; $this->oneTimeKeyboard = $oneTimeKeyboard; $this->resizeKeyboard = $resizeKeyboard; $this->selective = $selective; + $this->isPersistent = $isPersistent; + $this->inputFieldPlaceholder = $inputFieldPlaceholder; } /** @@ -83,6 +110,7 @@ public function getKeyboard() /** * @param array $keyboard + * @return void */ public function setKeyboard($keyboard) { @@ -90,7 +118,7 @@ public function setKeyboard($keyboard) } /** - * @return boolean + * @return bool|null */ public function isOneTimeKeyboard() { @@ -98,7 +126,8 @@ public function isOneTimeKeyboard() } /** - * @param boolean $oneTimeKeyboard + * @param bool $oneTimeKeyboard + * @return void */ public function setOneTimeKeyboard($oneTimeKeyboard) { @@ -106,7 +135,7 @@ public function setOneTimeKeyboard($oneTimeKeyboard) } /** - * @return boolean + * @return bool|null */ public function isResizeKeyboard() { @@ -114,7 +143,8 @@ public function isResizeKeyboard() } /** - * @param boolean $resizeKeyboard + * @param bool $resizeKeyboard + * @return void */ public function setResizeKeyboard($resizeKeyboard) { @@ -122,7 +152,7 @@ public function setResizeKeyboard($resizeKeyboard) } /** - * @return boolean + * @return bool|null */ public function isSelective() { @@ -130,10 +160,45 @@ public function isSelective() } /** - * @param boolean $selective + * @param bool $selective + * @return void */ public function setSelective($selective) { $this->selective = $selective; } + + /** + * @return bool|null + */ + public function getIsPersistent() + { + return $this->isPersistent; + } + + /** + * @param bool $isPersistent + * @return void + */ + public function setIsPersistent($isPersistent) + { + $this->isPersistent = $isPersistent; + } + + /** + * @return string|null + */ + public function getInputFieldPlaceholder() + { + return $this->inputFieldPlaceholder; + } + + /** + * @param string|null $inputFieldPlaceholder + * @return void + */ + public function setInputFieldPlaceholder($inputFieldPlaceholder) + { + $this->inputFieldPlaceholder = $inputFieldPlaceholder; + } } diff --git a/src/Types/ReplyKeyboardRemove.php b/src/Types/ReplyKeyboardRemove.php new file mode 100644 index 00000000..7f55a036 --- /dev/null +++ b/src/Types/ReplyKeyboardRemove.php @@ -0,0 +1,94 @@ + true, + 'selective' => true + ]; + + /** + * Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; + * if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup) + * + * @var bool + */ + protected $removeKeyboard; + + /** + * Optional. Use this parameter if you want to remove the keyboard for specific users only. + * Targets: + * 1) users that are @mentioned in the text of the Message object; + * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + * + * @var bool|null + */ + protected $selective; + + /** + * @param bool $removeKeyboard + * @param bool $selective + */ + public function __construct($removeKeyboard = true, $selective = false) + { + $this->removeKeyboard = $removeKeyboard; + $this->selective = $selective; + } + + /** + * @return bool + */ + public function getRemoveKeyboard() + { + return $this->removeKeyboard; + } + + /** + * @param bool $removeKeyboard + * @return void + */ + public function setRemoveKeyboard($removeKeyboard) + { + $this->removeKeyboard = $removeKeyboard; + } + + /** + * @return bool|null + */ + public function getSelective() + { + return $this->selective; + } + + /** + * @param bool|null $selective + * @return void + */ + public function setSelective($selective) + { + $this->selective = $selective; + } +} diff --git a/src/Types/ReplyParameters.php b/src/Types/ReplyParameters.php new file mode 100644 index 00000000..5275bb33 --- /dev/null +++ b/src/Types/ReplyParameters.php @@ -0,0 +1,205 @@ + true, + 'chat_id' => true, + 'allow_sending_without_reply' => true, + 'quote' => true, + 'quote_parse_mode' => true, + 'quote_entities' => ArrayOfMessageEntity::class, + 'quote_position' => true, + ]; + + /** + * Identifier of the message that will be replied to in the current chat, or in the chat chat_id if it is specified + * + * @var int + */ + protected $messageId; + + /** + * 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). Not supported for messages sent on behalf of a business account. + * + * @var int|string|null + */ + protected $chatId; + + /** + * Optional. Pass True if the message should be sent even if the specified message to be replied to is not found. Always False for replies in another chat or forum topic. Always True for messages sent on behalf of a business account. + * + * @var bool|null + */ + protected $allowSendingWithoutReply; + + /** + * 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. + * + * @var string|null + */ + protected $quote; + + /** + * Optional. Mode for parsing entities in the quote. See formatting options for more details. + * + * @var string|null + */ + protected $quoteParseMode; + + /** + * Optional. A JSON-serialized list of special entities that appear in the quote. It can be specified instead of quote_parse_mode. + * + * @var ArrayOfMessageEntity|null + */ + protected $quoteEntities; + + /** + * Optional. Position of the quote in the original message in UTF-16 code units + * + * @var int|null + */ + protected $quotePosition; + + /** + * @return int + */ + public function getMessageId() + { + return $this->messageId; + } + + /** + * @param int $messageId + * @return void + */ + public function setMessageId($messageId) + { + $this->messageId = $messageId; + } + + /** + * @return int|string|null + */ + public function getChatId() + { + return $this->chatId; + } + + /** + * @param int|string|null $chatId + * @return void + */ + public function setChatId($chatId) + { + $this->chatId = $chatId; + } + + /** + * @return bool|null + */ + public function getAllowSendingWithoutReply() + { + return $this->allowSendingWithoutReply; + } + + /** + * @param bool|null $allowSendingWithoutReply + * @return void + */ + public function setAllowSendingWithoutReply($allowSendingWithoutReply) + { + $this->allowSendingWithoutReply = $allowSendingWithoutReply; + } + + /** + * @return string|null + */ + public function getQuote() + { + return $this->quote; + } + + /** + * @param string|null $quote + * @return void + */ + public function setQuote($quote) + { + $this->quote = $quote; + } + + /** + * @return string|null + */ + public function getQuoteParseMode() + { + return $this->quoteParseMode; + } + + /** + * @param string|null $quoteParseMode + * @return void + */ + public function setQuoteParseMode($quoteParseMode) + { + $this->quoteParseMode = $quoteParseMode; + } + + /** + * @return ArrayOfMessageEntity|null + */ + public function getQuoteEntities() + { + return $this->quoteEntities; + } + + /** + * @param ArrayOfMessageEntity|null $quoteEntities + * @return void + */ + public function setQuoteEntities($quoteEntities) + { + $this->quoteEntities = $quoteEntities; + } + + /** + * @return int|null + */ + public function getQuotePosition() + { + return $this->quotePosition; + } + + /** + * @param int|null $quotePosition + * @return void + */ + public function setQuotePosition($quotePosition) + { + $this->quotePosition = $quotePosition; + } +} diff --git a/src/Types/ResponseParameters.php b/src/Types/ResponseParameters.php new file mode 100644 index 00000000..7cc3bf24 --- /dev/null +++ b/src/Types/ResponseParameters.php @@ -0,0 +1,78 @@ + true, + 'retry_after' => true + ]; + + /** + * The group has been migrated to a supergroup with the specified identifier + * + * @var int|null + */ + protected $migrateToChatId; + + /** + * In case of exceeding flood control, the number of seconds left to wait before the request can be repeated + * + * @var int|null + */ + protected $retryAfter; + + /** + * @return int|null + */ + public function getMigrateToChatId() + { + return $this->migrateToChatId; + } + + /** + * @param int|null $migrateToChatId + */ + public function setMigrateToChatId($migrateToChatId) + { + $this->migrateToChatId = $migrateToChatId; + } + + /** + * @return int|null + */ + public function getRetryAfter() + { + return $this->retryAfter; + } + + /** + * @param int|null $retryAfter + */ + public function setRetryAfter($retryAfter) + { + $this->retryAfter = $retryAfter; + } +} diff --git a/src/Types/SentWebAppMessage.php b/src/Types/SentWebAppMessage.php new file mode 100644 index 00000000..27e32e25 --- /dev/null +++ b/src/Types/SentWebAppMessage.php @@ -0,0 +1,49 @@ + true, + ]; + + /** + * Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. + * + * @var string|null + */ + protected $inlineMessageId; + + /** + * @return string|null + */ + public function getInlineMessageId() + { + return $this->inlineMessageId; + } + + /** + * @param string|null $inlineMessageId + * @return void + */ + public function setInlineMessageId($inlineMessageId) + { + $this->inlineMessageId = $inlineMessageId; + } +} diff --git a/src/Types/SharedUser.php b/src/Types/SharedUser.php new file mode 100644 index 00000000..21f9a1fd --- /dev/null +++ b/src/Types/SharedUser.php @@ -0,0 +1,155 @@ + true, + 'first_name' => true, + 'last_name' => true, + 'username' => true, + 'photo' => ArrayOfPhotoSize::class + ]; + + /** + * Identifier of the shared user + * + * @var int + */ + protected $userId; + + /** + * Optional. First name of the user, if the name was requested by the bot + * + * @var string|null + */ + protected $firstName; + + /** + * Optional. Last name of the user, if the name was requested by the bot + * + * @var string|null + */ + protected $lastName; + + /** + * Optional. Username of the user, if the username was requested by the bot + * + * @var string|null + */ + protected $username; + + /** + * Optional. Available sizes of the chat photo, if the photo was requested by the bot + * + * @var array|null + */ + protected $photo; + + /** + * @return int + */ + public function getUserId() + { + return $this->userId; + } + + /** + * @param int $userId + * @return void + */ + public function setUserId($userId) + { + $this->userId = $userId; + } + + /** + * @return string|null + */ + public function getFirstName() + { + return $this->firstName; + } + + /** + * @param string|null $firstName + * @return void + */ + public function setFirstName($firstName) + { + $this->firstName = $firstName; + } + + /** + * @return string|null + */ + public function getLastName() + { + return $this->lastName; + } + + /** + * @param string|null $lastName + * @return void + */ + public function setLastName($lastName) + { + $this->lastName = $lastName; + } + + /** + * @return string|null + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param string|null $username + * @return void + */ + public function setUsername($username) + { + $this->username = $username; + } + + /** + * @return array|null + */ + public function getPhoto() + { + return $this->photo; + } + + /** + * @param array|null $photo + * @return void + */ + public function setPhoto($photo) + { + $this->photo = $photo; + } +} diff --git a/src/Types/StarAmount.php b/src/Types/StarAmount.php new file mode 100644 index 00000000..9977f336 --- /dev/null +++ b/src/Types/StarAmount.php @@ -0,0 +1,39 @@ + true, + 'nanostar_amount' => true, + ]; + + protected $amount; + protected $nanostarAmount; + + public function getAmount() + { + return $this->amount; + } + + public function setAmount($amount) + { + $this->amount = $amount; + } + + public function getNanostarAmount() + { + return $this->nanostarAmount; + } + + public function setNanostarAmount($nanostarAmount) + { + $this->nanostarAmount = $nanostarAmount; + } +} diff --git a/src/Types/Sticker.php b/src/Types/Sticker.php index 4de6d803..3a948caf 100644 --- a/src/Types/Sticker.php +++ b/src/Types/Sticker.php @@ -19,19 +19,36 @@ class Sticker extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'width', 'height']; + protected static $requiredParams = [ + 'file_id', + 'file_unique_id', + 'type', + 'width', + 'height', + 'is_animated', + 'is_video' + ]; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, + 'file_unique_id' => true, + 'type' => true, 'width' => true, 'height' => true, - 'thumb' => PhotoSize::class, + 'is_animated' => true, + 'is_video' => true, + 'thumbnail' => PhotoSize::class, 'file_size' => true, + 'premium_animation' => File::class, + 'emoji' => true, + 'set_name' => true, + 'mask_position' => MaskPosition::class, + 'custom_emoji_id' => true, ]; /** @@ -56,19 +73,85 @@ class Sticker extends BaseType implements TypeInterface protected $height; /** - * Document thumbnail as defined by sender + * Optional. Sticker thumbnail in the .WEBP or .JPG format * - * @var PhotoSize + * @var PhotoSize|null */ - protected $thumb; + protected $thumbnail; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; + /** + * 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. + * + * @var string + */ + protected $type; + + /** + * 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. + * + * @var string + */ + protected $fileUniqueId; + + /** + * Optional. For premium regular stickers, premium animation for the sticker + * + * @var File|null + */ + protected $premiumAnimation; + + /** + * True, if the sticker is animated + * + * @var bool + */ + protected $isAnimated; + + /** + * True, if the sticker is a video sticker + * + * @var bool + */ + protected $isVideo; + + /** + * Optional. Emoji associated with the sticker + * + * @var string|null + */ + protected $emoji; + + /** + * Optional. Name of the sticker set to which the sticker belongs + * + * @var string|null + */ + protected $setName; + + /** + * Optional. For mask stickers, the position where the mask should be placed + * + * @var MaskPosition|null + */ + protected $maskPosition; + + /** + * Optional. For custom emoji stickers, unique identifier of the custom emoji + * + * @var string|null + */ + protected $customEmojiId; + /** * @return string */ @@ -79,6 +162,8 @@ public function getFileId() /** * @param string $fileId + * + * @return void */ public function setFileId($fileId) { @@ -86,7 +171,7 @@ public function setFileId($fileId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -94,9 +179,11 @@ public function getFileSize() } /** - * @param int $fileSize + * @param mixed $fileSize * * @throws InvalidArgumentException + * + * @return void */ public function setFileSize($fileSize) { @@ -116,9 +203,11 @@ public function getHeight() } /** - * @param int $height + * @param mixed $height * * @throws InvalidArgumentException + * + * @return void */ public function setHeight($height) { @@ -130,19 +219,43 @@ public function setHeight($height) } /** - * @return PhotoSize + * @return PhotoSize|null + */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * + * @return void + */ + public function setThumbnail(PhotoSize $thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null */ public function getThumb() { - return $this->thumb; + return $this->getThumbnail(); } /** + * @deprecated use setThumbnail method + * * @param PhotoSize $thumb + * + * @return void */ - public function setThumb(PhotoSize $thumb) + public function setThumb($thumb) { - $this->thumb = $thumb; + $this->setThumbnail($thumb); } /** @@ -154,9 +267,11 @@ public function getWidth() } /** - * @param int $width + * @param mixed $width * * @throws InvalidArgumentException + * + * @return void */ public function setWidth($width) { @@ -166,4 +281,166 @@ public function setWidth($width) throw new InvalidArgumentException(); } } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * + * @return void + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + + /** + * @return File|null + */ + public function getPremiumAnimation() + { + return $this->premiumAnimation; + } + + /** + * @param File $premiumAnimation + * + * @return void + */ + public function setPremiumAnimation(File $premiumAnimation) + { + $this->premiumAnimation = $premiumAnimation; + } + + /** + * @return bool + */ + public function getIsAnimated() + { + return $this->isAnimated; + } + + /** + * @param bool $isAnimated + * + * @return void + */ + public function setIsAnimated($isAnimated) + { + $this->isAnimated = $isAnimated; + } + + /** + * @return bool + */ + public function getIsVideo() + { + return $this->isVideo; + } + + /** + * @param bool $isVideo + * + * @return void + */ + public function setIsVideo($isVideo) + { + $this->isVideo = $isVideo; + } + + /** + * @return null|string + */ + public function getEmoji() + { + return $this->emoji; + } + + /** + * @param string $emoji + * + * @return void + */ + public function setEmoji($emoji) + { + $this->emoji = $emoji; + } + + /** + * @return null|string + */ + public function getSetName() + { + return $this->setName; + } + + /** + * @param string $setName + * + * @return void + */ + public function setSetName($setName) + { + $this->setName = $setName; + } + + /** + * @return MaskPosition|null + */ + public function getMaskPosition() + { + return $this->maskPosition; + } + + /** + * @param MaskPosition $maskPosition + * + * @return void + */ + public function setMaskPosition(MaskPosition $maskPosition) + { + $this->maskPosition = $maskPosition; + } + + /** + * @return null|string + */ + public function getCustomEmojiId() + { + return $this->customEmojiId; + } + + /** + * @param string $customEmojiId + * + * @return void + */ + public function setCustomEmojiId($customEmojiId) + { + $this->customEmojiId = $customEmojiId; + } } diff --git a/src/Types/StickerSet.php b/src/Types/StickerSet.php new file mode 100644 index 00000000..6f038bea --- /dev/null +++ b/src/Types/StickerSet.php @@ -0,0 +1,235 @@ + + */ +class StickerSet extends BaseType implements TypeInterface +{ + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['name', 'title', 'sticker_type', 'is_animated', 'is_video', 'stickers']; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'name' => true, + 'title' => true, + 'sticker_type' => true, + 'is_animated' => true, + 'is_video' => true, + 'stickers' => ArrayOfSticker::class, + 'thumbnail' => PhotoSize::class, + ]; + + /** + * Sticker set name + * + * @var string + */ + protected $name; + + /** + * Sticker set title + * + * @var string + */ + protected $title; + + /** + * Type of stickers in the set, currently one of “regular”, “mask”, “custom_emoji” + * + * @var string + */ + protected $stickerType; + + /** + * True, if the sticker set contains animated stickers + * + * @var bool + */ + protected $isAnimated; + + /** + * True, if the sticker set contains video stickers + * + * @var bool + */ + protected $isVideo; + + /** + * List of all set stickers + * + * @var ArrayOfSticker + */ + protected $stickers; + + /** + * Optional. Sticker set thumbnail in the .WEBP or .TGS format + * + * @var PhotoSize|null + */ + protected $thumbnail; + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * + * @return void + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string + */ + public function getStickerType() + { + return $this->stickerType; + } + + /** + * @param string $stickerType + * + * @return void + */ + public function setStickerType($stickerType) + { + $this->stickerType = $stickerType; + } + + /** + * @return bool + */ + public function getIsAnimated() + { + return $this->isAnimated; + } + + /** + * @param bool $isAnimated + * + * @return void + */ + public function setIsAnimated($isAnimated) + { + $this->isAnimated = $isAnimated; + } + + /** + * @return bool + */ + public function getIsVideo() + { + return $this->isVideo; + } + + /** + * @param bool $isVideo + * + * @return void + */ + public function setIsVideo($isVideo) + { + $this->isVideo = $isVideo; + } + + /** + * @return ArrayOfSticker + */ + public function getStickers() + { + return $this->stickers; + } + + /** + * @param ArrayOfSticker $stickers + * + * @return void + */ + public function setStickers($stickers) + { + $this->stickers = $stickers; + } + + /** + * @return PhotoSize|null + */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * + * @return void + */ + public function setThumbnail($thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null + */ + public function getThumb() + { + return $this->getThumbnail(); + } + + /** + * @deprecated use setThumbnail method + * + * @param PhotoSize $thumb + * + * @return void + */ + public function setThumb($thumb) + { + $this->setThumbnail($thumb); + } +} diff --git a/src/Types/Story.php b/src/Types/Story.php new file mode 100644 index 00000000..42683884 --- /dev/null +++ b/src/Types/Story.php @@ -0,0 +1,85 @@ + Chat::class, + 'id' => true, + ]; + + /** + * Chat that posted the story + * + * @var Chat + */ + protected $chat; + + /** + * Unique identifier for the story in the chat + * + * @var int + */ + protected $id; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat(Chat $chat) + { + $this->chat = $chat; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * @return void + */ + public function setId($id) + { + if (is_integer($id)) { + $this->id = $id; + } else { + throw new InvalidArgumentException(); + } + } +} diff --git a/src/Types/TextQuote.php b/src/Types/TextQuote.php new file mode 100644 index 00000000..d7202bfa --- /dev/null +++ b/src/Types/TextQuote.php @@ -0,0 +1,131 @@ + true, + 'entities' => ArrayOfMessageEntity::class, + 'position' => true, + 'is_manual' => true, + ]; + + /** + * Text of the quoted part of a message that is replied to by the given message + * + * @var string + */ + protected $text; + + /** + * Optional. Special entities that appear in the quote. Currently, only bold, italic, underline, strikethrough, + * spoiler, and custom_emoji entities are kept in quotes. + * + * @var array|null + */ + protected $entities; + + /** + * Approximate quote position in the original message in UTF-16 code units as specified by the sender + * + * @var int + */ + protected $position; + + /** + * Optional. True, if the quote was chosen manually by the message sender. Otherwise, the quote was added automatically by the server. + * + * @var bool|null + */ + protected $isManual; + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return void + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return array|null + */ + public function getEntities() + { + return $this->entities; + } + + /** + * @param array|null $entities + * @return void + */ + public function setEntities($entities) + { + $this->entities = $entities; + } + + /** + * @return int + */ + public function getPosition() + { + return $this->position; + } + + /** + * @param int $position + * @return void + */ + public function setPosition($position) + { + $this->position = $position; + } + + /** + * @return bool|null + */ + public function getIsManual() + { + return $this->isManual; + } + + /** + * @param bool|null $isManual + * @return void + */ + public function setIsManual($isManual) + { + $this->isManual = $isManual; + } +} diff --git a/src/Types/UniqueGift.php b/src/Types/UniqueGift.php new file mode 100644 index 00000000..c2823672 --- /dev/null +++ b/src/Types/UniqueGift.php @@ -0,0 +1,87 @@ + true, + 'name' => true, + 'number' => true, + 'model' => UniqueGiftModel::class, + 'symbol' => UniqueGiftSymbol::class, + 'backdrop' => UniqueGiftBackdrop::class, + ]; + + protected $baseName; + protected $name; + protected $number; + protected $model; + protected $symbol; + protected $backdrop; + + public function getBaseName() + { + return $this->baseName; + } + + public function setBaseName($baseName) + { + $this->baseName = $baseName; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getNumber() + { + return $this->number; + } + + public function setNumber($number) + { + $this->number = $number; + } + + public function getModel() + { + return $this->model; + } + + public function setModel($model) + { + $this->model = $model; + } + + public function getSymbol() + { + return $this->symbol; + } + + public function setSymbol($symbol) + { + $this->symbol = $symbol; + } + + public function getBackdrop() + { + return $this->backdrop; + } + + public function setBackdrop($backdrop) + { + $this->backdrop = $backdrop; + } +} diff --git a/src/Types/UniqueGiftBackdrop.php b/src/Types/UniqueGiftBackdrop.php new file mode 100644 index 00000000..9b70ac7a --- /dev/null +++ b/src/Types/UniqueGiftBackdrop.php @@ -0,0 +1,51 @@ + true, + 'colors' => UniqueGiftBackdropColors::class, + 'rarity_per_mille' => true, + ]; + + protected $name; + protected $colors; + protected $rarityPerMille; + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getColors() + { + return $this->colors; + } + + public function setColors($colors) + { + $this->colors = $colors; + } + + public function getRarityPerMille() + { + return $this->rarityPerMille; + } + + public function setRarityPerMille($rarityPerMille) + { + $this->rarityPerMille = $rarityPerMille; + } +} diff --git a/src/Types/UniqueGiftBackdropColors.php b/src/Types/UniqueGiftBackdropColors.php new file mode 100644 index 00000000..7fa5732f --- /dev/null +++ b/src/Types/UniqueGiftBackdropColors.php @@ -0,0 +1,63 @@ + true, + 'edge_color' => true, + 'symbol_color' => true, + 'text_color' => true, + ]; + + protected $centerColor; + protected $edgeColor; + protected $symbolColor; + protected $textColor; + + public function getCenterColor() + { + return $this->centerColor; + } + + public function setCenterColor($centerColor) + { + $this->centerColor = $centerColor; + } + + public function getEdgeColor() + { + return $this->edgeColor; + } + + public function setEdgeColor($edgeColor) + { + $this->edgeColor = $edgeColor; + } + + public function getSymbolColor() + { + return $this->symbolColor; + } + + public function setSymbolColor($symbolColor) + { + $this->symbolColor = $symbolColor; + } + + public function getTextColor() + { + return $this->textColor; + } + + public function setTextColor($textColor) + { + $this->textColor = $textColor; + } +} diff --git a/src/Types/UniqueGiftInfo.php b/src/Types/UniqueGiftInfo.php new file mode 100644 index 00000000..4fe9ed86 --- /dev/null +++ b/src/Types/UniqueGiftInfo.php @@ -0,0 +1,63 @@ + UniqueGift::class, + 'origin' => true, + 'owned_gift_id' => true, + 'transfer_star_count' => true, + ]; + + protected $gift; + protected $origin; + protected $ownedGiftId; + protected $transferStarCount; + + public function getGift() + { + return $this->gift; + } + + public function setGift($gift) + { + $this->gift = $gift; + } + + public function getOrigin() + { + return $this->origin; + } + + public function setOrigin($origin) + { + $this->origin = $origin; + } + + public function getOwnedGiftId() + { + return $this->ownedGiftId; + } + + public function setOwnedGiftId($ownedGiftId) + { + $this->ownedGiftId = $ownedGiftId; + } + + public function getTransferStarCount() + { + return $this->transferStarCount; + } + + public function setTransferStarCount($transferStarCount) + { + $this->transferStarCount = $transferStarCount; + } +} diff --git a/src/Types/UniqueGiftModel.php b/src/Types/UniqueGiftModel.php new file mode 100644 index 00000000..bcc30afb --- /dev/null +++ b/src/Types/UniqueGiftModel.php @@ -0,0 +1,51 @@ + true, + 'sticker' => Sticker::class, + 'rarity_per_mille' => true, + ]; + + protected $name; + protected $sticker; + protected $rarityPerMille; + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getSticker() + { + return $this->sticker; + } + + public function setSticker($sticker) + { + $this->sticker = $sticker; + } + + public function getRarityPerMille() + { + return $this->rarityPerMille; + } + + public function setRarityPerMille($rarityPerMille) + { + $this->rarityPerMille = $rarityPerMille; + } +} diff --git a/src/Types/UniqueGiftSymbol.php b/src/Types/UniqueGiftSymbol.php new file mode 100644 index 00000000..bea9ead9 --- /dev/null +++ b/src/Types/UniqueGiftSymbol.php @@ -0,0 +1,51 @@ + true, + 'sticker' => Sticker::class, + 'rarity_per_mille' => true, + ]; + + protected $name; + protected $sticker; + protected $rarityPerMille; + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getSticker() + { + return $this->sticker; + } + + public function setSticker($sticker) + { + $this->sticker = $sticker; + } + + public function getRarityPerMille() + { + return $this->rarityPerMille; + } + + public function setRarityPerMille($rarityPerMille) + { + $this->rarityPerMille = $rarityPerMille; + } +} diff --git a/src/Types/Update.php b/src/Types/Update.php index 118a908b..0294b71e 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -23,14 +23,14 @@ class Update extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['update_id']; + protected static $requiredParams = ['update_id']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'update_id' => true, 'message' => Message::class, 'edited_message' => Message::class, @@ -41,6 +41,15 @@ class Update extends BaseType implements TypeInterface 'callback_query' => CallbackQuery::class, 'shipping_query' => ShippingQuery::class, 'pre_checkout_query' => PreCheckoutQuery::class, + 'poll_answer' => PollAnswer::class, + 'poll' => Poll::class, + 'my_chat_member' => ChatMemberUpdated::class, + 'chat_member' => ChatMemberUpdated::class, + 'chat_join_request' => ChatJoinRequest::class, + 'message_reaction' => MessageReactionUpdated::class, + 'message_reaction_count' => MessageReactionCountUpdated::class, + 'chat_boost' => ChatBoostUpdated::class, + 'chat_boost_removed' => ChatBoostRemoved::class, ]; /** @@ -56,66 +65,139 @@ class Update extends BaseType implements TypeInterface /** * Optional. New incoming message of any kind — text, photo, sticker, etc. * - * @var Message + * @var Message|null */ protected $message; + /** + * Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself. + * + * @var PollAnswer|null + */ + protected $pollAnswer; + + /** + * Optional. New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot + * + * @var Poll|null + */ + protected $poll; + /** * Optional. New version of a message that is known to the bot and was edited * - * @var Message + * @var Message|null */ protected $editedMessage; /** * Optional. New incoming channel post of any kind — text, photo, sticker, etc. * - * @var Message + * @var Message|null */ protected $channelPost; /** * Optional. New version of a channel post that is known to the bot and was edited * - * @var Message + * @var Message|null */ protected $editedChannelPost; /** * Optional. New incoming inline query * - * @var \TelegramBot\Api\Types\Inline\InlineQuery + * @var \TelegramBot\Api\Types\Inline\InlineQuery|null */ protected $inlineQuery; /** * Optional. The result of a inline query that was chosen by a user and sent to their chat partner * - * @var \TelegramBot\Api\Types\Inline\ChosenInlineResult + * @var \TelegramBot\Api\Types\Inline\ChosenInlineResult|null */ protected $chosenInlineResult; /** * Optional. New incoming callback query * - * @var \TelegramBot\Api\Types\CallbackQuery + * @var \TelegramBot\Api\Types\CallbackQuery|null */ protected $callbackQuery; /** * Optional. New incoming shipping query. Only for invoices with flexible price * - * @var ShippingQuery + * @var ShippingQuery|null */ protected $shippingQuery; /** * Optional. New incoming pre-checkout query. Contains full information about checkout * - * @var PreCheckoutQuery + * @var PreCheckoutQuery|null */ protected $preCheckoutQuery; + /** + * Optional. 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. + * + * @var ChatMemberUpdated|null + */ + protected $myChatMember; + + /** + * Optional. 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. + * + * @var ChatMemberUpdated|null + */ + protected $chatMember; + + /** + * Optional. A request to join the chat has been sent. The bot must have the can_invite_users administrator + * right in the chat to receive these updates. + * + * @var ChatJoinRequest|null + */ + protected $chatJoinRequest; + + /** + * Optional. A reaction to a message was changed by a user. + * The bot must be an administrator in the chat and must explicitly specify 'message_reaction' + * in the list of allowed_updates to receive these updates. The update isn't received for reactions set by bots. + * + * @var MessageReactionUpdated|null + */ + protected $messageReaction; + + /** + * Optional. Reactions to a message with anonymous reactions were changed. + * The bot must be an administrator in the chat and must explicitly specify 'message_reaction_count' + * in the list of allowed_updates to receive these updates. + * The updates are grouped and can be sent with delay up to a few minutes. + * + * @var MessageReactionCountUpdated|null + */ + protected $messageReactionCount; + + /** + * Optional. A chat boost was added or changed. + * The bot must be an administrator in the chat to receive these updates. + * + * @var ChatBoostUpdated|null + */ + protected $chatBoost; + + /** + * Optional. A boost was removed from a chat. + * The bot must be an administrator in the chat to receive these updates. + * + * @var ChatBoostRemoved|null + */ + protected $chatBoostRemoved; + /** * @return int */ @@ -126,6 +208,8 @@ public function getUpdateId() /** * @param int $updateId + * + * @return void */ public function setUpdateId($updateId) { @@ -133,7 +217,7 @@ public function setUpdateId($updateId) } /** - * @return Message + * @return Message|null */ public function getMessage() { @@ -142,6 +226,8 @@ public function getMessage() /** * @param Message $message + * + * @return void */ public function setMessage(Message $message) { @@ -149,7 +235,7 @@ public function setMessage(Message $message) } /** - * @return Message + * @return Message|null */ public function getEditedMessage() { @@ -158,6 +244,8 @@ public function getEditedMessage() /** * @param Message $editedMessage + * + * @return void */ public function setEditedMessage($editedMessage) { @@ -165,7 +253,7 @@ public function setEditedMessage($editedMessage) } /** - * @return Message + * @return Message|null */ public function getChannelPost() { @@ -174,6 +262,8 @@ public function getChannelPost() /** * @param Message $channelPost + * + * @return void */ public function setChannelPost($channelPost) { @@ -181,7 +271,43 @@ public function setChannelPost($channelPost) } /** - * @return Message + * @return PollAnswer|null + */ + public function getPollAnswer() + { + return $this->pollAnswer; + } + + /** + * @return Poll|null + */ + public function getPoll() + { + return $this->poll; + } + + /** + * @param Poll $poll + * + * @return void + */ + public function setPoll($poll) + { + $this->poll = $poll; + } + + /** + * @param PollAnswer $pollAnswer + * + * @return void + */ + public function setPollAnswer($pollAnswer) + { + $this->pollAnswer = $pollAnswer; + } + + /** + * @return Message|null */ public function getEditedChannelPost() { @@ -190,6 +316,8 @@ public function getEditedChannelPost() /** * @param Message $editedChannelPost + * + * @return void */ public function setEditedChannelPost($editedChannelPost) { @@ -197,7 +325,7 @@ public function setEditedChannelPost($editedChannelPost) } /** - * @return InlineQuery + * @return InlineQuery|null */ public function getInlineQuery() { @@ -206,6 +334,8 @@ public function getInlineQuery() /** * @param InlineQuery $inlineQuery + * + * @return void */ public function setInlineQuery($inlineQuery) { @@ -213,7 +343,7 @@ public function setInlineQuery($inlineQuery) } /** - * @return ChosenInlineResult + * @return ChosenInlineResult|null */ public function getChosenInlineResult() { @@ -222,6 +352,8 @@ public function getChosenInlineResult() /** * @param ChosenInlineResult $chosenInlineResult + * + * @return void */ public function setChosenInlineResult($chosenInlineResult) { @@ -229,7 +361,7 @@ public function setChosenInlineResult($chosenInlineResult) } /** - * @return CallbackQuery + * @return CallbackQuery|null */ public function getCallbackQuery() { @@ -238,6 +370,8 @@ public function getCallbackQuery() /** * @param CallbackQuery $callbackQuery + * + * @return void */ public function setCallbackQuery($callbackQuery) { @@ -246,7 +380,8 @@ public function setCallbackQuery($callbackQuery) /** * @author MY - * @return ShippingQuery + * + * @return ShippingQuery|null */ public function getShippingQuery() { @@ -255,7 +390,10 @@ public function getShippingQuery() /** * @author MY + * * @param ShippingQuery $shippingQuery + * + * @return void */ public function setShippingQuery($shippingQuery) { @@ -264,7 +402,8 @@ public function setShippingQuery($shippingQuery) /** * @author MY - * @return PreCheckoutQuery + * + * @return PreCheckoutQuery|null */ public function getPreCheckoutQuery() { @@ -273,10 +412,132 @@ public function getPreCheckoutQuery() /** * @author MY + * * @param PreCheckoutQuery $preCheckoutQuery + * + * @return void */ public function setPreCheckoutQuery($preCheckoutQuery) { $this->preCheckoutQuery = $preCheckoutQuery; } + + /** + * @return ChatMemberUpdated|null + */ + public function getMyChatMember() + { + return $this->myChatMember; + } + + /** + * @param ChatMemberUpdated|null $myChatMember + * @return void + */ + public function setMyChatMember($myChatMember) + { + $this->myChatMember = $myChatMember; + } + + /** + * @return ChatMemberUpdated|null + */ + public function getChatMember() + { + return $this->chatMember; + } + + /** + * @param ChatMemberUpdated|null $chatMember + * @return void + */ + public function setChatMember($chatMember) + { + $this->chatMember = $chatMember; + } + + /** + * @return ChatJoinRequest|null + */ + public function getChatJoinRequest() + { + return $this->chatJoinRequest; + } + + /** + * @param ChatJoinRequest|null $chatJoinRequest + * @return void + */ + public function setChatJoinRequest($chatJoinRequest) + { + $this->chatJoinRequest = $chatJoinRequest; + } + + /** + * @return MessageReactionUpdated|null + */ + public function getMessageReaction() + { + return $this->messageReaction; + } + + /** + * @param MessageReactionUpdated|null $messageReaction + * @return void + */ + public function setMessageReaction(?MessageReactionUpdated $messageReaction) + { + $this->messageReaction = $messageReaction; + } + + /** + * @return MessageReactionCountUpdated|null + */ + public function getMessageReactionCount() + { + return $this->messageReactionCount; + } + + /** + * @param MessageReactionCountUpdated|null $messageReactionCount + * @return void + */ + public function setMessageReactionCount(?MessageReactionCountUpdated $messageReactionCount) + { + $this->messageReactionCount = $messageReactionCount; + } + + /** + * @return ChatBoostUpdated|null + */ + public function getChatBoost() + { + return $this->chatBoost; + } + + /** + * @param ChatBoostUpdated|null $chatBoost + * @return void + */ + public function setChatBoost($chatBoost) + { + $this->chatBoost = $chatBoost; + } + + /** + * @return ChatBoostRemoved|null + */ + public function getChatBoostRemoved() + { + return $this->chatBoostRemoved; + } + + /** + * @param ChatBoostRemoved|null $chatBoostRemoved + * @return void + */ + public function setChatBoostRemoved($chatBoostRemoved) + { + $this->chatBoostRemoved = $chatBoostRemoved; + } } diff --git a/src/Types/User.php b/src/Types/User.php index aa84bb34..0ea3ea55 100644 --- a/src/Types/User.php +++ b/src/Types/User.php @@ -19,26 +19,32 @@ class User extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['id', 'first_name']; + protected static $requiredParams = ['id', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'id' => true, 'first_name' => true, 'last_name' => true, 'username' => true, 'language_code' => true, - 'is_bot' => true + 'is_bot' => true, + 'is_premium' => true, + 'added_to_attachment_menu' => true, + 'can_join_groups' => true, + 'can_read_all_group_messages' => true, + 'supports_inline_queries' => true, + 'can_connect_to_business' => true ]; /** * Unique identifier for this user or bot * - * @var int + * @var int|float */ protected $id; @@ -52,21 +58,21 @@ class User extends BaseType implements TypeInterface /** * Optional. User‘s or bot’s last name * - * @var string + * @var string|null */ protected $lastName; /** * Optional. User‘s or bot’s username * - * @var string + * @var string|null */ protected $username; /** * Optional. IETF language tag of the user's language * - * @var string + * @var string|null */ protected $languageCode; @@ -78,104 +84,167 @@ class User extends BaseType implements TypeInterface protected $isBot; /** - * @return string + * Optional. True, if this user is a Telegram Premium user + * + * @var bool|null */ - public function getFirstName() - { - return $this->firstName; - } + protected $isPremium; /** - * @param string $firstName + * Optional. True, if this user added the bot to the attachment menu + * + * @var bool|null */ - public function setFirstName($firstName) - { - $this->firstName = $firstName; - } + protected $addedToAttachmentMenu; /** - * @return int + * Optional. True, if the bot can be invited to groups. Returned only in getMe. + * + * @var bool|null */ - public function getId() - { - return $this->id; - } + protected $canJoinGroups; + + /** + * Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. + * + * @var bool|null + */ + protected $canReadAllGroupMessages; + + /** + * Optional. True, if the bot supports inline queries. Returned only in getMe. + * + * @var bool|null + */ + protected $supportsInlineQueries; /** - * @param int $id + * Optional. True, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in getMe. * - * @throws InvalidArgumentException + * @var bool|null */ - public function setId($id) + protected $canConnectToBusiness; + + public function getId(): int|float + { + return $this->id; + } + + public function setId($id): void { - if (is_integer($id) || is_float($id)) { - $this->id = $id; - } else { - throw new InvalidArgumentException(); + if (!is_int($id) && !is_float($id)) { + throw new InvalidArgumentException('ID must be an integer or float'); } + $this->id = $id; } - /** - * @return string - */ - public function getLastName() + public function getFirstName(): string + { + return $this->firstName; + } + + public function setFirstName($firstName): void + { + $this->firstName = $firstName; + } + + public function getLastName(): ?string { return $this->lastName; } - /** - * @param string $lastName - */ - public function setLastName($lastName) + public function setLastName($lastName): void { $this->lastName = $lastName; } - /** - * @return string - */ - public function getUsername() + public function getUsername(): ?string { return $this->username; } - /** - * @param string $username - */ - public function setUsername($username) + public function setUsername($username): void { $this->username = $username; } - /** - * @return string - */ public function getLanguageCode() { return $this->languageCode; } - /** - * @param string $languageCode - */ - public function setLanguageCode($languageCode) + public function setLanguageCode($languageCode): void { $this->languageCode = $languageCode; } - /** - * @return bool - */ - public function isBot() + public function isBot(): bool { - return $this->isBot; + return (bool) $this->isBot; } - /** - * @param bool $isBot - */ - public function setIsBot($isBot) + public function setIsBot($isBot): void { $this->isBot = $isBot; } + + public function getIsPremium(): ?bool + { + return $this->isPremium; + } + + public function setIsPremium($isPremium): void + { + $this->isPremium = $isPremium; + } + + public function getAddedToAttachmentMenu(): ?bool + { + return $this->addedToAttachmentMenu; + } + + public function setAddedToAttachmentMenu($addedToAttachmentMenu): void + { + $this->addedToAttachmentMenu = $addedToAttachmentMenu; + } + + public function getCanJoinGroups(): ?bool + { + return $this->canJoinGroups; + } + + public function setCanJoinGroups($canJoinGroups): void + { + $this->canJoinGroups = $canJoinGroups; + } + + public function getCanReadAllGroupMessages(): ?bool + { + return $this->canReadAllGroupMessages; + } + + public function setCanReadAllGroupMessages($canReadAllGroupMessages): void + { + $this->canReadAllGroupMessages = $canReadAllGroupMessages; + } + + public function getSupportsInlineQueries(): ?bool + { + return $this->supportsInlineQueries; + } + + public function setSupportsInlineQueries($supportsInlineQueries): void + { + $this->supportsInlineQueries = $supportsInlineQueries; + } + + public function getCanConnectToBusiness(): ?bool + { + return $this->canConnectToBusiness; + } + + public function setCanConnectToBusiness($canConnectToBusiness): void + { + $this->canConnectToBusiness = $canConnectToBusiness; + } } diff --git a/src/Types/UserChatBoosts.php b/src/Types/UserChatBoosts.php new file mode 100644 index 00000000..5543b587 --- /dev/null +++ b/src/Types/UserChatBoosts.php @@ -0,0 +1,54 @@ + ArrayOfChatBoost::class + ]; + + /** + * The list of boosts added to the chat by the user + * + * @var ArrayOfChatBoost + */ + protected $boosts; + + /** + * @return ArrayOfChatBoost + */ + public function getBoosts() + { + return $this->boosts; + } + + /** + * @param ArrayOfChatBoost $boosts + */ + public function setBoosts($boosts): void + { + $this->boosts = $boosts; + } +} diff --git a/src/Types/UserProfilePhotos.php b/src/Types/UserProfilePhotos.php index cdfa842f..5c22c33d 100644 --- a/src/Types/UserProfilePhotos.php +++ b/src/Types/UserProfilePhotos.php @@ -19,14 +19,14 @@ class UserProfilePhotos extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['total_count', 'photos']; + protected static $requiredParams = ['total_count', 'photos']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'total_count' => true, 'photos' => ArrayOfArrayOfPhotoSize::class, ]; @@ -34,7 +34,7 @@ class UserProfilePhotos extends BaseType implements TypeInterface /** * Total number of profile pictures the target user has * - * @var Integer + * @var int */ protected $totalCount; @@ -56,6 +56,8 @@ public function getPhotos() /** * @param array $photos + * + * @return void */ public function setPhotos($photos) { @@ -71,9 +73,11 @@ public function getTotalCount() } /** - * @param int $totalCount + * @param mixed $totalCount * * @throws InvalidArgumentException + * + * @return void */ public function setTotalCount($totalCount) { diff --git a/src/Types/UsersShared.php b/src/Types/UsersShared.php new file mode 100644 index 00000000..818b5950 --- /dev/null +++ b/src/Types/UsersShared.php @@ -0,0 +1,81 @@ + true, + 'users' => ArrayOfSharedUser::class + ]; + + /** + * Identifier of the request + * + * @var int + */ + protected $requestId; + + /** + * Information about users shared with the bot + * Array of \TelegramBot\Api\Types\SharedUser + * + * @var array + */ + protected $users; + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @param int $requestId + * @return void + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + } + + /** + * @return array + */ + public function getUsers() + { + return $this->users; + } + + /** + * @param array $users + * @return void + */ + public function setUsers($users) + { + $this->users = $users; + } +} diff --git a/src/Types/Venue.php b/src/Types/Venue.php index 173be67c..2ffd125c 100644 --- a/src/Types/Venue.php +++ b/src/Types/Venue.php @@ -1,10 +1,4 @@ Location::class, 'title' => true, 'address' => true, 'foursquare_id' => true, + 'foursquare_type' => true, + 'google_place_id' => true, + 'google_place_type' => true, ]; /** @@ -62,10 +59,31 @@ class Venue extends BaseType implements TypeInterface /** * Optional. Foursquare identifier of the venue * - * @var string + * @var string|null */ protected $foursquareId; + /** + * Optional. Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) + * + * @var string|null + */ + protected $foursquareType; + + /** + * Optional. Google Places identifier of the venue + * + * @var string|null + */ + protected $googlePlaceId; + + /** + * Optional. Google Places type of the venue. + * + * @var string|null + */ + protected $googlePlaceType; + /** * @return Location */ @@ -76,6 +94,8 @@ public function getLocation() /** * @param Location $location + * + * @return void */ public function setLocation($location) { @@ -92,6 +112,8 @@ public function getTitle() /** * @param string $title + * + * @return void */ public function setTitle($title) { @@ -108,6 +130,8 @@ public function getAddress() /** * @param string $address + * + * @return void */ public function setAddress($address) { @@ -115,7 +139,7 @@ public function setAddress($address) } /** - * @return string + * @return null|string */ public function getFoursquareId() { @@ -123,10 +147,66 @@ public function getFoursquareId() } /** - * @param string $foursquareId + * @param string|null $foursquareId + * + * @return void */ public function setFoursquareId($foursquareId) { $this->foursquareId = $foursquareId; } + + /** + * @return null|string + */ + public function getFoursquareType() + { + return $this->foursquareType; + } + + /** + * @param string|null $foursquareType + * + * @return void + */ + public function setFoursquareType($foursquareType) + { + $this->foursquareType = $foursquareType; + } + + /** + * @return null|string + */ + public function getGooglePlaceId() + { + return $this->googlePlaceId; + } + + /** + * @param string|null $googlePlaceId + * + * @return void + */ + public function setGooglePlaceId($googlePlaceId) + { + $this->googlePlaceId = $googlePlaceId; + } + + /** + * @return null|string + */ + public function getGooglePlaceType() + { + return $this->googlePlaceType; + } + + /** + * @param string|null $googlePlaceType + * + * @return void + */ + public function setGooglePlaceType($googlePlaceType) + { + $this->googlePlaceType = $googlePlaceType; + } } diff --git a/src/Types/Video.php b/src/Types/Video.php index d82d7fd0..abf79e8a 100644 --- a/src/Types/Video.php +++ b/src/Types/Video.php @@ -19,19 +19,20 @@ class Video extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'width', 'height', 'duration']; + protected static $requiredParams = ['file_id', 'file_unique_id', 'width', 'height', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, + 'file_unique_id' => true, 'width' => true, 'height' => true, 'duration' => true, - 'thumb' => PhotoSize::class, + 'thumbnail' => PhotoSize::class, 'mime_type' => true, 'file_size' => true ]; @@ -67,25 +68,31 @@ class Video extends BaseType implements TypeInterface /** * Video thumbnail * - * @var PhotoSize + * @var PhotoSize|null */ - protected $thumb; - + protected $thumbnail; /** * Optional. Mime type of a file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; + /** + * 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. + * + * @var string + */ + protected $fileUniqueId; + /** * @return int */ @@ -95,9 +102,11 @@ public function getDuration() } /** - * @param int $duration + * @param mixed $duration * * @throws InvalidArgumentException + * + * @return void */ public function setDuration($duration) { @@ -118,6 +127,8 @@ public function getFileId() /** * @param string $fileId + * + * @return void */ public function setFileId($fileId) { @@ -125,7 +136,7 @@ public function setFileId($fileId) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -133,9 +144,11 @@ public function getFileSize() } /** - * @param int $fileSize + * @param mixed $fileSize * * @throws InvalidArgumentException + * + * @return void */ public function setFileSize($fileSize) { @@ -155,9 +168,11 @@ public function getHeight() } /** - * @param int $height + * @param mixed $height * * @throws InvalidArgumentException + * + * @return void */ public function setHeight($height) { @@ -169,7 +184,7 @@ public function setHeight($height) } /** - * @return string + * @return null|string */ public function getMimeType() { @@ -178,6 +193,8 @@ public function getMimeType() /** * @param string $mimeType + * + * @return void */ public function setMimeType($mimeType) { @@ -185,19 +202,43 @@ public function setMimeType($mimeType) } /** - * @return PhotoSize + * @return PhotoSize|null + */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize|null $thumbnail + * + * @return void + */ + public function setThumbnail($thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null */ public function getThumb() { - return $this->thumb; + return $this->getThumbnail(); } /** - * @param PhotoSize $thumb + * @deprecated use setThumbnail method + * + * @param PhotoSize|null $thumb + * + * @return void */ - public function setThumb(PhotoSize $thumb) + public function setThumb($thumb) { - $this->thumb = $thumb; + $this->setThumbnail($thumb); } /** @@ -209,9 +250,11 @@ public function getWidth() } /** - * @param int $width + * @param mixed $width * * @throws InvalidArgumentException + * + * @return void */ public function setWidth($width) { @@ -221,4 +264,22 @@ public function setWidth($width) throw new InvalidArgumentException(); } } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } } diff --git a/src/Types/VideoChatEnded.php b/src/Types/VideoChatEnded.php new file mode 100644 index 00000000..509bde39 --- /dev/null +++ b/src/Types/VideoChatEnded.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * Video chat duration in seconds + * + * @var int + */ + protected $duration; + + /** + * @return int + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param int $duration + * @return void + */ + public function setDuration($duration) + { + $this->duration = $duration; + } +} diff --git a/src/Types/VideoChatParticipantsInvited.php b/src/Types/VideoChatParticipantsInvited.php new file mode 100644 index 00000000..934b3ad5 --- /dev/null +++ b/src/Types/VideoChatParticipantsInvited.php @@ -0,0 +1,55 @@ + ArrayOfUser::class, + ]; + + /** + * New members that were invited to the video chat + * + * @var array + */ + protected $users; + + /** + * @return array + */ + public function getUsers() + { + return $this->users; + } + + /** + * @param array $users + * @return void + */ + public function setUsers($users) + { + $this->users = $users; + } +} diff --git a/src/Types/VideoChatScheduled.php b/src/Types/VideoChatScheduled.php new file mode 100644 index 00000000..d329f52f --- /dev/null +++ b/src/Types/VideoChatScheduled.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * Point in time (Unix timestamp) when the video chat is supposed to be started by a chat administrator + * + * @var int + */ + protected $startDate; + + /** + * @return int + */ + public function getStartDate() + { + return $this->startDate; + } + + /** + * @param int $startDate + * @return void + */ + public function setStartDate($startDate) + { + $this->startDate = $startDate; + } +} diff --git a/src/Types/VideoChatStarted.php b/src/Types/VideoChatStarted.php new file mode 100644 index 00000000..f67914c7 --- /dev/null +++ b/src/Types/VideoChatStarted.php @@ -0,0 +1,10 @@ + true, + 'file_unique_id' => true, + 'length' => true, + 'duration' => true, + 'thumbnail' => PhotoSize::class, + 'file_size' => true, + ]; + + /** + * Unique identifier for this file + * + * @var string + */ + protected $fileId; + + /** + * 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. + * + * @var string + */ + protected $fileUniqueId; + + /** + * Video width and height (diameter of the video message) as defined by sender + * + * @var int + */ + protected $length; + + /** + * Duration of the video in seconds as defined by sender + * + * @var int + */ + protected $duration; + + /** + * Optional. Video thumbnail + * + * @var PhotoSize|null + */ + protected $thumbnail; + + /** + * Optional. File size in bytes + * + * @var int|null + */ + protected $fileSize; + + /** + * @return string + */ + public function getFileId() + { + return $this->fileId; + } + + /** + * @param string $fileId + * + * @return void + */ + public function setFileId($fileId) + { + $this->fileId = $fileId; + } + + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + + /** + * @return int + */ + public function getLength() + { + return $this->length; + } + + /** + * @param int $length + * + * @return void + */ + public function setLength($length) + { + $this->length = $length; + } + + /** + * @return int + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param int $duration + * + * @return void + */ + public function setDuration($duration) + { + $this->duration = $duration; + } + + /** + * @return PhotoSize|null + */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @param PhotoSize $thumbnail + * + * @return void + */ + public function setThumbnail($thumbnail) + { + $this->thumbnail = $thumbnail; + } + + /** + * @deprecated use getThumbnail method + * + * @return PhotoSize|null + */ + public function getThumb() + { + return $this->getThumbnail(); + } + + /** + * @deprecated use setThumbnail method + * + * @param PhotoSize $thumb + * + * @return void + */ + public function setThumb($thumb) + { + $this->setThumbnail($thumb); + } + + /** + * @return int|null + */ + public function getFileSize() + { + return $this->fileSize; + } + + /** + * @param int $fileSize + * + * @return void + */ + public function setFileSize($fileSize) + { + $this->fileSize = $fileSize; + } +} diff --git a/src/Types/Voice.php b/src/Types/Voice.php index f4227b2b..8d4e4cba 100644 --- a/src/Types/Voice.php +++ b/src/Types/Voice.php @@ -19,27 +19,36 @@ class Voice extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = ['file_id', 'duration']; + protected static $requiredParams = ['file_id', 'file_unique_id', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = [ + protected static $map = [ 'file_id' => true, + 'file_unique_id' => true, 'duration' => true, 'mime_type' => true, - 'file_size' => true + 'file_size' => true, ]; /** - * Unique identifier for this file + * Identifier for this file, which can be used to download or reuse the file * * @var string */ protected $fileId; + /** + * 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. + * + * @var string + */ + protected $fileUniqueId; + /** * Duration of the audio in seconds as defined by sender * @@ -50,14 +59,14 @@ class Voice extends BaseType implements TypeInterface /** * Optional. MIME type of the file as defined by sender * - * @var string + * @var string|null */ protected $mimeType; /** * Optional. File size * - * @var int + * @var int|null */ protected $fileSize; @@ -71,12 +80,32 @@ public function getFileId() /** * @param string $fileId + * + * @return void */ public function setFileId($fileId) { $this->fileId = $fileId; } + /** + * @return string + */ + public function getFileUniqueId() + { + return $this->fileUniqueId; + } + + /** + * @param string $fileUniqueId + * + * @return void + */ + public function setFileUniqueId($fileUniqueId) + { + $this->fileUniqueId = $fileUniqueId; + } + /** * @return int */ @@ -86,9 +115,11 @@ public function getDuration() } /** - * @param int $duration + * @param mixed $duration * * @throws InvalidArgumentException + * + * @return void */ public function setDuration($duration) { @@ -100,7 +131,7 @@ public function setDuration($duration) } /** - * @return string + * @return null|string */ public function getMimeType() { @@ -109,6 +140,8 @@ public function getMimeType() /** * @param string $mimeType + * + * @return void */ public function setMimeType($mimeType) { @@ -116,7 +149,7 @@ public function setMimeType($mimeType) } /** - * @return int + * @return int|null */ public function getFileSize() { @@ -124,9 +157,11 @@ public function getFileSize() } /** - * @param int $fileSize + * @param mixed $fileSize * * @throws InvalidArgumentException + * + * @return void */ public function setFileSize($fileSize) { diff --git a/src/Types/WebAppData.php b/src/Types/WebAppData.php new file mode 100644 index 00000000..ee88dbc0 --- /dev/null +++ b/src/Types/WebAppData.php @@ -0,0 +1,74 @@ + true, + 'button_text' => true, + ]; + + /** + * The data. Be aware that a bad client can send arbitrary data in this field. + * + * @var string + */ + protected $data; + + /** + * Text of the web_app keyboard button from which the Web App was opened. Be aware that a bad client can send arbitrary data in this field. + * + * @var string + */ + protected $buttonText; + + /** + * @return string + */ + public function getData() + { + return $this->data; + } + + /** + * @param string $data + * @return void + */ + public function setData($data) + { + $this->data = $data; + } + + /** + * @return string + */ + public function getButtonText() + { + return $this->buttonText; + } + + /** + * @param string $buttonText + * @return void + */ + public function setButtonText($buttonText) + { + $this->buttonText = $buttonText; + } +} diff --git a/src/Types/WebAppInfo.php b/src/Types/WebAppInfo.php new file mode 100644 index 00000000..d33ea0a5 --- /dev/null +++ b/src/Types/WebAppInfo.php @@ -0,0 +1,55 @@ + true, + ]; + + /** + * An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps + * + * @var string + */ + protected $url; + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + * @return void + */ + public function setUrl($url) + { + $this->url = $url; + } +} diff --git a/src/Types/WebhookInfo.php b/src/Types/WebhookInfo.php new file mode 100644 index 00000000..68a64327 --- /dev/null +++ b/src/Types/WebhookInfo.php @@ -0,0 +1,270 @@ + true, + 'has_custom_certificate' => true, + 'pending_update_count' => true, + 'ip_address' => true, + 'last_error_date' => true, + 'last_error_message' => true, + 'last_synchronization_error_date' => true, + 'max_connections' => true, + 'allowed_updates' => true + ]; + + /** + * Webhook URL, may be empty if webhook is not set up + * + * @var string + */ + protected $url; + + /** + * True, if a custom certificate was provided for webhook certificate checks + * + * @var bool + */ + protected $hasCustomCertificate; + + /** + * Number of updates awaiting delivery + * + * @var int + */ + protected $pendingUpdateCount; + + /** + * Optional. Currently used webhook IP address + * + * @var string|null + */ + protected $ipAddress; + + /** + * Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook + * + * @var int|null + */ + protected $lastErrorDate; + + /** + * Optional. Error message in human-readable format for the most recent error that happened when trying to deliver + * an update via webhook + * + * @var string|null + */ + protected $lastErrorMessage; + + /** + * Optional. Unix time of the most recent error that happened when trying to synchronize available updates + * with Telegram datacenters + * + * @var int|null + */ + protected $lastSynchronizationErrorDate; + + /** + * Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery + * + * @var int|null + */ + protected $maxConnections; + + /** + * Optional. A list of update types the bot is subscribed to. Defaults to all update types + * + * @var array|null + */ + protected $allowedUpdates; + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + * + * @return void + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * @return bool + */ + public function hasCustomCertificate() + { + return $this->hasCustomCertificate; + } + + /** + * @param bool $hasCustomCertificate + * + * @return void + */ + public function setHasCustomCertificate($hasCustomCertificate) + { + $this->hasCustomCertificate = $hasCustomCertificate; + } + + /** + * @param string $ipAddress + * + * @return void + */ + public function setIpAddress($ipAddress) + { + $this->ipAddress = $ipAddress; + } + + /** + * @return null|string + */ + public function getIpAddress() + { + return $this->ipAddress; + } + + /** + * @return int + */ + public function getPendingUpdateCount() + { + return $this->pendingUpdateCount; + } + + /** + * @param int $pendingUpdateCount + * + * @return void + */ + public function setPendingUpdateCount($pendingUpdateCount) + { + $this->pendingUpdateCount = $pendingUpdateCount; + } + + /** + * @return int|null + */ + public function getLastErrorDate() + { + return $this->lastErrorDate; + } + + /** + * @param int $lastErrorDate + * + * @return void + */ + public function setLastErrorDate($lastErrorDate) + { + $this->lastErrorDate = $lastErrorDate; + } + + /** + * @return null|string + */ + public function getLastErrorMessage() + { + return $this->lastErrorMessage; + } + + /** + * @param string $lastErrorMessage + * + * @return void + */ + public function setLastErrorMessage($lastErrorMessage) + { + $this->lastErrorMessage = $lastErrorMessage; + } + + /** + * @param int $lastSynchronizationErrorDate + * + * @return void + */ + public function setLastSynchronizationErrorDate($lastSynchronizationErrorDate) + { + $this->lastSynchronizationErrorDate = $lastSynchronizationErrorDate; + } + + /** + * @return int|null + */ + public function getLastSynchronizationErrorDate() + { + return $this->lastSynchronizationErrorDate; + } + + /** + * @return int|null + */ + public function getMaxConnections() + { + return $this->maxConnections; + } + + /** + * @param int $maxConnections + * + * @return void + */ + public function setMaxConnections($maxConnections) + { + $this->maxConnections = $maxConnections; + } + + /** + * @return array|null + */ + public function getAllowedUpdates() + { + return $this->allowedUpdates; + } + + /** + * @param array $allowedUpdates + * + * @return void + */ + public function setAllowedUpdates($allowedUpdates) + { + $this->allowedUpdates = $allowedUpdates; + } +} diff --git a/src/Types/WriteAccessAllowed.php b/src/Types/WriteAccessAllowed.php new file mode 100644 index 00000000..243de7b1 --- /dev/null +++ b/src/Types/WriteAccessAllowed.php @@ -0,0 +1,98 @@ + true, + 'web_app_name' => true, + 'from_attachment_menu' => true, + ]; + + /** + * Optional. True, if the access was granted after the user accepted an explicit request from a Web App sent by the method requestWriteAccess + * + * @var bool|null + */ + protected $fromRequest; + + /** + * Optional. Name of the Web App, if the access was granted when the Web App was launched from a link + * + * @var string|null + */ + protected $webAppName; + + /** + * Optional. True, if the access was granted when the bot was added to the attachment or side menu + * + * @var bool|null + */ + protected $fromAttachmentMenu; + + /** + * @return bool|null + */ + public function isFromRequest() + { + return $this->fromRequest; + } + + /** + * @param bool|null $fromRequest + * @return void + */ + public function setFromRequest($fromRequest) + { + $this->fromRequest = $fromRequest; + } + + /** + * @return string|null + */ + public function getWebAppName() + { + return $this->webAppName; + } + + /** + * @param string|null $webAppName + * @return void + */ + public function setWebAppName($webAppName) + { + $this->webAppName = $webAppName; + } + + /** + * @return bool|null + */ + public function isFromAttachmentMenu() + { + return $this->fromAttachmentMenu; + } + + /** + * @param bool|null $fromAttachmentMenu + * @return void + */ + public function setFromAttachmentMenu($fromAttachmentMenu) + { + $this->fromAttachmentMenu = $fromAttachmentMenu; + } +} diff --git a/tests/AbstractTypeTest.php b/tests/AbstractTypeTest.php new file mode 100644 index 00000000..ce9b0253 --- /dev/null +++ b/tests/AbstractTypeTest.php @@ -0,0 +1,78 @@ +assertInstanceOf(static::getType(), $item); + $this->assertMinItem($item); + } + + public function testFromResponseFull() + { + $item = static::createFullInstance(); + + $this->assertInstanceOf(static::getType(), $item); + $this->assertFullItem($item); + + $innerJson = $item->toJson(); + + $this->assertIsString($innerJson); + } + + /** + * @param object $item + * @return void + */ + abstract protected function assertMinItem($item); + + /** + * @param object $item + * @return void + */ + abstract protected function assertFullItem($item); +} diff --git a/tests/AudioTest.php b/tests/AudioTest.php deleted file mode 100644 index b03bb3f1..00000000 --- a/tests/AudioTest.php +++ /dev/null @@ -1,152 +0,0 @@ -setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() - { - $item = new Audio(); - $item->setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetDuration() - { - $item = new Audio(); - $item->setDuration(1); - $this->assertAttributeEquals(1, 'duration', $item); - } - - public function testGetDuration() - { - $item = new Audio(); - $item->setDuration(1); - $this->assertEquals(1, $item->getDuration()); - } - - public function testSetPerformer() - { - $item = new Audio(); - $item->setPerformer('test'); - $this->assertAttributeEquals('test', 'performer', $item); - } - - public function testGetPerformer() - { - $item = new Audio(); - $item->setPerformer('test'); - $this->assertEquals('test', $item->getPerformer()); - } - - public function testSetTitle() - { - $item = new Audio(); - $item->setTitle('test'); - $this->assertAttributeEquals('test', 'title', $item); - } - - public function testGetTitle() - { - $item = new Audio(); - $item->setTitle('test'); - $this->assertEquals('test', $item->getTitle()); - } - - public function testSetFileSize() - { - $item = new Audio(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() - { - $item = new Audio(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetMimeType() - { - $item = new Audio(); - $item->setMimeType('audio/mp3'); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - } - - public function testGetMimeType() - { - $item = new Audio(); - $item->setMimeType('audio/mp3'); - $this->assertEquals('audio/mp3', $item->getMimeType()); - } - - public function testFromResponse() - { - $item = Audio::fromResponse(array( - 'file_id' => 'testFileId1', - 'duration' => 1, - 'performer' => 'testperformer', - 'title' => 'testtitle', - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Audio', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals(1, 'duration', $item); - $this->assertAttributeEquals('testperformer', 'performer', $item); - $this->assertAttributeEquals('testtitle', 'title', $item); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - $this->assertAttributeEquals(3, 'fileSize', $item); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException() - { - $item = Audio::fromResponse(array( - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() - { - $item = Audio::fromResponse(array( - 'file_id' => 'testFileId1', - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetDurationException() - { - $item = new Audio(); - $item->setDuration('s'); - } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetFileSizeException() - { - $item = new Audio(); - $item->setFileSize('s'); - } - -} diff --git a/tests/BaseTypeTest.php b/tests/BaseTypeTest.php index 4b3ec98e..e0bcff77 100644 --- a/tests/BaseTypeTest.php +++ b/tests/BaseTypeTest.php @@ -2,29 +2,26 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\BaseType; +use TelegramBot\Api\InvalidArgumentException; -class BaseTypeTest extends \PHPUnit_Framework_TestCase +class BaseTypeTest extends TestCase { - public function setUp() + public function testValidate() { - include_once('tests/_fixtures/TestBaseType.php'); + $this->assertTrue(TestBaseType::validate(['test1' => 1, 'test2' => 2, 'test3' => 3])); } - public function testRequiredParams() + public function testValidateFail() { - $testItem = new \TestBaseType(); + $this->expectException(InvalidArgumentException::class); - $this->assertAttributeEquals(array('test1', 'test2'), 'requiredParams', $testItem); - } - - public function testValidate() { - $this->assertTrue(\TestBaseType::validate(array('test1' => 1, 'test2' => 2, 'test3' => 3))); + $this->assertTrue(TestBaseType::validate(['test1' => 1])); } +} - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testValidateFail() { - $this->assertTrue(\TestBaseType::validate(array('test1' => 1))); - } +class TestBaseType extends BaseType +{ + protected static $requiredParams = ['test1', 'test2']; } diff --git a/tests/BotApiTest.php b/tests/BotApiTest.php index 341bab3b..43e351bf 100644 --- a/tests/BotApiTest.php +++ b/tests/BotApiTest.php @@ -2,11 +2,13 @@ namespace TelegramBot\Api\Test; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\BotApi; +use TelegramBot\Api\Http\HttpClientInterface; use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\Update; -class BotApiTest extends \PHPUnit_Framework_TestCase +class BotApiTest extends TestCase { public function data() { @@ -107,24 +109,40 @@ public function data() */ public function testGetUpdates($updates) { - $mock = $this->getMockBuilder('\TelegramBot\Api\BotApi') - ->setMethods(['call']) - ->enableOriginalConstructor() - ->setConstructorArgs(['testToken']) - ->getMock(); + $httpClient = $this->createHttpClient(); + $botApi = $this->createBotApi($httpClient); - $mock->expects($this->once())->method('call')->willReturn($updates); + $httpClient + ->expects($this->once()) + ->method('request') + ->willReturn($updates) + ; + $result = $botApi->getUpdates(); $expectedResult = ArrayOfUpdates::fromResponse($updates); - $result = $mock->getUpdates(); - $this->assertInternalType('array', $result); $this->assertEquals($expectedResult, $result); foreach($result as $key => $item) { - $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $item); + $this->assertInstanceOf(Update::class, $item); $this->assertEquals($expectedResult[$key], $item); } } + + /** + * @return HttpClientInterface&\PHPUnit\Framework\MockObject\MockObject + */ + private function createHttpClient() + { + /** @var HttpClientInterface $httpClient */ + $httpClient = $this->createMock(HttpClientInterface::class); + + return $httpClient; + } + + private function createBotApi(HttpClientInterface $httpClient) + { + return new BotApi('token', $httpClient); + } } diff --git a/tests/ChatTest.php b/tests/ChatTest.php deleted file mode 100644 index 0dd1ae90..00000000 --- a/tests/ChatTest.php +++ /dev/null @@ -1,218 +0,0 @@ - 1, - 'type' => 'group', - 'title' => 'test chat' - )); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item); - $this->assertEquals(1, $item->getId()); - $this->assertEquals('test chat', $item->getTitle()); - - } - - public function testSetId() - { - $chat = new Chat(); - $chat->setId(1); - $this->assertAttributeEquals(1, 'id', $chat); - } - - public function testSet64bitId() - { - $chat = new Chat(); - $chat->setId(2147483648); - $this->assertAttributeEquals(2147483648, 'id', $chat); - } - - public function testGetId() - { - $chat = new Chat(); - $chat->setId(1); - $this->assertEquals(1, $chat->getId()); - } - - public function testSetType() - { - $chat = new Chat(); - $chat->setType('private'); - $this->assertAttributeEquals('private', 'type', $chat); - } - - public function testGetType() - { - $chat = new Chat(); - $chat->setType('private'); - $this->assertEquals('private', $chat->getType()); - } - - public function testSetTitle() - { - $chat = new Chat(); - $chat->setTitle('test chat'); - $this->assertAttributeEquals('test chat', 'title', $chat); - } - - public function testGetTitle() - { - $chat = new Chat(); - $chat->setTitle('test chat'); - $this->assertEquals('test chat', $chat->getTitle()); - } - - public function testSetUsername() - { - $chat = new Chat(); - $chat->setUsername('iGusev'); - $this->assertAttributeEquals('iGusev', 'username', $chat); - } - - public function testGetUsername() - { - $chat = new Chat(); - $chat->setUsername('iGusev'); - $this->assertEquals('iGusev', $chat->getUsername()); - } - - public function testSetFirstName() - { - $chat = new Chat(); - $chat->setFirstName('Ilya'); - $this->assertAttributeEquals('Ilya', 'firstName', $chat); - } - - public function testGetFirstName() - { - $chat = new Chat(); - $chat->setFirstName('Ilya'); - $this->assertEquals('Ilya', $chat->getFirstName()); - } - - public function testSetLastName() - { - $chat = new Chat(); - $chat->setLastName('Gusev'); - $this->assertAttributeEquals('Gusev', 'lastName', $chat); - } - - public function testGetLastName() - { - $chat = new Chat(); - $chat->setLastName('Gusev'); - $this->assertEquals('Gusev', $chat->getLastName()); - } - - public function testSetAllMembersAreAdministrators() - { - $chat = new Chat(); - $chat->setAllMembersAreAdministrators(true); - $this->assertAttributeEquals(true, 'allMembersAreAdministrators', $chat); - } - - public function testGetAllMembersAreAdministrators() - { - $chat = new Chat(); - $chat->setAllMembersAreAdministrators(true); - $this->assertEquals(true, $chat->getAllMembersAreAdministrators()); - } - - public function testSetPhoto() - { - $chat = new Chat(); - $photo = ChatPhoto::fromResponse([ - 'small_file_id' => 'small_file_id', - 'big_file_id' => 'big_file_id' - ]); - $chat->setPhoto($photo); - $this->assertAttributeEquals($photo, 'photo', $chat); - } - - public function testGetPhoto() - { - $chat = new Chat(); - $photo = ChatPhoto::fromResponse([ - 'small_file_id' => 'small_file_id', - 'big_file_id' => 'big_file_id' - ]); - $chat->setPhoto($photo); - $this->assertEquals($photo, $chat->getPhoto()); - } - - public function testSetDescriptions() - { - $chat = new Chat(); - $chat->setDescription('description'); - $this->assertAttributeEquals('description', 'description', $chat); - } - - public function testGetDescription() - { - $chat = new Chat(); - $chat->setDescription('description'); - $this->assertEquals('description', $chat->getDescription()); - } - - public function testFromResponseUser() - { - $item = Chat::fromResponse(array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - 'type' => 'private' - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item); - $this->assertEquals(123456, $item->getId()); - $this->assertEquals('Ilya', $item->getFirstName()); - $this->assertEquals('Gusev', $item->getLastName()); - $this->assertEquals('iGusev', $item->getUsername()); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetIdException1() - { - $chat = new Chat(); - $chat->setId([]); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetIdException2() - { - $chat = new Chat(); - $chat->setId(null); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() - { - $chat = Chat::fromResponse(array( - 'id' => 1 - )); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException3() - { - $chat = Chat::fromResponse(array( - 'type' => 'private' - )); - } -} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index d5f82d8b..14a70371 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -2,15 +2,15 @@ namespace TelegramBot\Api\Test; - -use Symfony\Component\Yaml\Inline; -use TelegramBot\Api\BotApi; +use PHPUnit\Framework\TestCase; +use TelegramBot\Api\BadMethodCallException; use TelegramBot\Api\Client; +use TelegramBot\Api\Events\EventCollection; use TelegramBot\Api\Types\Inline\InlineQuery; use TelegramBot\Api\Types\Message; use TelegramBot\Api\Types\Update; -class ClientTest extends \PHPUnit_Framework_TestCase +class ClientTest extends TestCase { public function data() { @@ -123,41 +123,30 @@ public function data() */ public function testGetInlineQueryChecker($update) { - $reflectionMethod = new \ReflectionMethod('TelegramBot\Api\Client', 'getInlineQueryChecker'); + $reflectionMethod = new \ReflectionMethod(Client::class, 'getInlineQueryChecker'); $reflectionMethod->setAccessible(true); $result = $reflectionMethod->invoke(null); - $this->assertInstanceOf('\Closure', $result); + $this->assertInstanceOf(\Closure::class, $result); $this->assertEquals(!is_null($update->getInlineQuery()), call_user_func($result, $update)); } - /** - * @expectedException \TelegramBot\Api\BadMethodCallException - * @expectedExceptionMessage Method testMethod not exists - */ public function testBadMethodCallException() { - $item = new Client('testToken'); - - $item->testMethod(); - } + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage('Method testMethod not exists'); - public function testConstructor() - { $item = new Client('testToken'); - - $this->assertInstanceOf('\TelegramBot\Api\Client', $item); - $this->assertAttributeInstanceOf('\TelegramBot\Api\BotApi', 'api', $item); - $this->assertAttributeInstanceOf('\TelegramBot\Api\Events\EventCollection', 'events', $item); + $item->testMethod(); } public function testOn() { $item = new Client('testToken'); - $mockedEventCollection = $this->getMockBuilder('\TelegramBot\Api\Events\EventCollection') + $mockedEventCollection = $this->getMockBuilder(EventCollection::class) ->disableOriginalConstructor() ->getMock(); @@ -182,12 +171,12 @@ public function testOn() */ public function testGetChecker($update, $command) { - $reflectionMethod = new \ReflectionMethod('TelegramBot\Api\Client', 'getChecker'); + $reflectionMethod = new \ReflectionMethod(Client::class, 'getChecker'); $reflectionMethod->setAccessible(true); $result = $reflectionMethod->invoke(null, $command); - $this->assertInstanceOf('\Closure', $result); + $this->assertInstanceOf(\Closure::class, $result); preg_match(Client::REGEXP, $update->getMessage() ? $update->getMessage()->getText() : '', $matches); @@ -206,7 +195,7 @@ public function testHandle($update) { $item = new Client('testToken'); - $mockedEventCollection = $this->getMockBuilder('\TelegramBot\Api\Events\EventCollection') + $mockedEventCollection = $this->getMockBuilder(EventCollection::class) ->disableOriginalConstructor() ->getMock(); @@ -229,7 +218,7 @@ public function testHandle($update) */ public function testGetEvent($update, $command, $attr1, $attr2) { - $reflectionMethod = new \ReflectionMethod('TelegramBot\Api\Client', 'getEvent'); + $reflectionMethod = new \ReflectionMethod(Client::class, 'getEvent'); $reflectionMethod->setAccessible(true); global $test; @@ -254,7 +243,7 @@ public function testGetEvent($update, $command, $attr1, $attr2) $result = $reflectionMethod->invoke(null, $action); - $this->assertInstanceOf('\Closure', $result); + $this->assertInstanceOf(\Closure::class, $result); $mustBeCalled = !is_null($update->getMessage()); @@ -274,7 +263,7 @@ public function testGetEvent($update, $command, $attr1, $attr2) */ public function testGetInlineQueryEvent($update) { - $reflectionMethod = new \ReflectionMethod('TelegramBot\Api\Client', 'getInlineQueryEvent'); + $reflectionMethod = new \ReflectionMethod(Client::class, 'getInlineQueryEvent'); $reflectionMethod->setAccessible(true); global $test; @@ -291,7 +280,7 @@ public function testGetInlineQueryEvent($update) $result = $reflectionMethod->invoke(null, $action); - $this->assertInstanceOf('\Closure', $result); + $this->assertInstanceOf(\Closure::class, $result); $mustBeCalled = !is_null($update->getInlineQuery()); @@ -303,4 +292,4 @@ public function testGetInlineQueryEvent($update) $this->assertEquals(1, $test); } } -} \ No newline at end of file +} diff --git a/tests/Collection/CollectionTest.php b/tests/Collection/CollectionTest.php new file mode 100644 index 00000000..48994aab --- /dev/null +++ b/tests/Collection/CollectionTest.php @@ -0,0 +1,91 @@ + 'photo', + 'media' => 'link' + ] + ]; + + public function testAddItem() + { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link')); + + $this->assertSame(1, $media->count()); + } + + public function testAddItemWithKey() + { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link'), 'key'); + + $this->assertSame(1, $media->count()); + } + + public function testAddItemWithDuplicateKey() + { + $this->expectException(KeyHasUseException::class); + + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link'), 'key'); + $media->addItem(new InputMediaPhoto('link'), 'key'); + } + + public function testGetItem() + { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link'), 'key'); + + $this->assertInstanceOf(CollectionItemInterface::class, $media->getItem('key')); + } + + public function testGetInvalidItem() + { + $this->expectException(KeyInvalidException::class); + + $media = new ArrayOfInputMedia(); + $media->getItem('key'); + } + + public function testDeleteItem() + { + $media = new ArrayOfInputMedia(); + $media->addItem(new InputMediaPhoto('link'), 'key'); + $media->deleteItem('key'); + + $this->assertSame(0, $media->count()); + } + + public function testCount() + { + $media = new ArrayOfInputMedia(); + $media->setMaxCount(5); + for ($i = 0; $i < 5; $i++) { + $media->addItem(new InputMediaPhoto('link')); + } + $this->assertSame(5, $media->count()); + } + + public function testCantAddMoreThenMaxLimit() + { + $this->expectException(ReachedMaxSizeException::class); + $media = new ArrayOfInputMedia(); + $media->setMaxCount(2); + $media->addItem(new InputMediaPhoto('link')); + $media->addItem(new InputMediaPhoto('link')); + $media->addItem(new InputMediaPhoto('link')); + } +} diff --git a/tests/ContactTest.php b/tests/ContactTest.php deleted file mode 100644 index 7aea3aec..00000000 --- a/tests/ContactTest.php +++ /dev/null @@ -1,79 +0,0 @@ -setPhoneNumber('123456'); - $this->assertAttributeEquals('123456', 'phoneNumber', $contact); - } - - public function testGetPhoneNumber() - { - $contact = new Contact(); - $contact->setPhoneNumber('123456'); - $this->assertEquals('123456', $contact->getPhoneNumber()); - } - - public function testSetFirstName() - { - $contact = new Contact(); - $contact->setFirstName('Ilya'); - $this->assertAttributeEquals('Ilya', 'firstName', $contact); - } - - public function testGetFirstName() - { - $contact = new Contact(); - $contact->setFirstName('Ilya'); - $this->assertEquals('Ilya', $contact->getFirstName()); - } - - public function testSetLastName() - { - $contact = new Contact(); - $contact->setLastName('Gusev'); - $this->assertAttributeEquals('Gusev', 'lastName', $contact); - } - - public function testGetLastName() - { - $contact = new Contact(); - $contact->setLastName('Gusev'); - $this->assertEquals('Gusev', $contact->getLastName()); - } - - public function testSetUserId() - { - $contact = new Contact(); - $contact->setUserId('iGusev'); - $this->assertAttributeEquals('iGusev', 'userId', $contact); - } - - public function testGetUserId() - { - $contact = new Contact(); - $contact->setUserId('iGusev'); - $this->assertEquals('iGusev', $contact->getUserId()); - } - - public function testFromResponse() - { - $contact = Contact::fromResponse(array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'phone_number' => '123456', - 'user_id' => 'iGusev' - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Contact', $contact); - $this->assertEquals('123456', $contact->getPhoneNumber()); - $this->assertEquals('Ilya', $contact->getFirstName()); - $this->assertEquals('Gusev', $contact->getLastName()); - $this->assertEquals('iGusev', $contact->getUserId()); - } -} diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php deleted file mode 100644 index 9aee4cd4..00000000 --- a/tests/DocumentTest.php +++ /dev/null @@ -1,149 +0,0 @@ -setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() - { - $item = new Document(); - $item->setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetThumb() - { - $item = new Document(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $item->setThumb($thumb); - $this->assertAttributeEquals($thumb, 'thumb', $item); - } - - public function testGetThumb() - { - $item = new Document(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $item->setThumb($thumb); - $this->assertEquals($thumb, $item->getThumb()); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); - } - - public function testSetFileName() - { - $item = new Document(); - $item->setFileName('testfileName'); - $this->assertAttributeEquals('testfileName', 'fileName', $item); - } - - public function testGetFileName() - { - $item = new Document(); - $item->setFileName('testfileName'); - $this->assertEquals('testfileName', $item->getFileName()); - } - - public function testSetFileSize() - { - $item = new Document(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() - { - $item = new Document(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetMimeType() - { - $item = new Document(); - $item->setMimeType('audio/mp3'); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - } - - public function testGetMimeType() - { - $item = new Document(); - $item->setMimeType('audio/mp3'); - $this->assertEquals('audio/mp3', $item->getMimeType()); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetFileSizeException() - { - $item = new Document(); - $item->setFileSize('s'); - } - - public function testFromResponse() - { - $item = Document::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_name' => 'testFileName', - 'mime_type' => 'audio/mp3', - 'file_size' => 3, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - $thumb = PhotoSize::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Document', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals('testFileName', 'fileName', $item); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - $this->assertAttributeEquals(3, 'fileSize', $item); - $this->assertAttributeEquals($thumb, 'thumb', $item); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException1() - { - $item = Document::fromResponse(array( - 'file_name' => 'testFileName', - 'mime_type' => 'audio/mp3', - 'file_size' => 3, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - } -} diff --git a/tests/Types/Events/EventCollectionTest.php b/tests/Events/EventCollectionTest.php similarity index 60% rename from tests/Types/Events/EventCollectionTest.php rename to tests/Events/EventCollectionTest.php index 0c8640be..a5e18d8b 100644 --- a/tests/Types/Events/EventCollectionTest.php +++ b/tests/Events/EventCollectionTest.php @@ -1,12 +1,13 @@ assertAttributeEmpty('tracker', $item); - $this->assertAttributeEmpty('events', $item); - } - - public function testConstructor2() - { - $item = new EventCollection('testToken'); - - $this->assertAttributeInstanceOf('\TelegramBot\Api\Botan', 'tracker', $item); - $this->assertAttributeEmpty('events', $item); - } - /** * @param \Closure $action * @param \Closure $checker @@ -76,10 +61,10 @@ public function testAdd1($action, $checker) $innerItem = $reflectionProperty->getValue($item); $reflectionProperty->setAccessible(false); - $this->assertAttributeInternalType('array', 'events', $item); + $this->assertIsArray($innerItem); /* @var \TelegramBot\Api\Events\Event $event */ foreach($innerItem as $event) { - $this->assertInstanceOf('\TelegramBot\Api\Events\Event', $event); + $this->assertInstanceOf(Event::class, $event); } } @@ -99,10 +84,10 @@ public function testAdd2($action) $innerItem = $reflectionProperty->getValue($item); $reflectionProperty->setAccessible(false); - $this->assertAttributeInternalType('array', 'events', $item); + $this->assertIsArray($innerItem); /* @var \TelegramBot\Api\Events\Event $event */ foreach($innerItem as $event) { - $this->assertInstanceOf('\TelegramBot\Api\Events\Event', $event); + $this->assertInstanceOf(Event::class, $event); } } @@ -113,54 +98,19 @@ public function testAdd2($action) * * @dataProvider data */ - public function testHandle1($action, $checker, $update) { - $item = new EventCollection('testToken'); - $name = 'test'; - $item->add($action, function ($update) use ($name) { - return true; - }); - - $mockedTracker = $this->getMockBuilder('\TelegramBot\Api\Botan') - ->disableOriginalConstructor() - ->getMock(); - - // Configure the stub. - - $mockedTracker->expects($this->once())->method('track')->willReturn(null); - - $reflection = new \ReflectionClass($item); - $reflectionProperty = $reflection->getProperty('tracker'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($item, $mockedTracker); - $reflectionProperty->setAccessible(false); - - $item->handle($update); - } - - /** - * @param \Closure $action - * @param \Closure $checker - * @param Update $update - * - * @dataProvider data - */ - public function testHandle2($action, $checker, $update) { + public function testHandle2($action, $checker, $update) + { $item = new EventCollection(); $name = 'test'; $item->add($action, function ($update) use ($name) { return true; }); - $mockedTracker = $this->getMockBuilder('\TelegramBot\Api\Botan') - ->disableOriginalConstructor() - ->getMock(); - - $mockedEvent = $this->getMockBuilder('\TelegramBot\Api\Events\Event') + $mockedEvent = $this->getMockBuilder(Event::class) ->disableOriginalConstructor() ->getMock(); // Configure the stub. - $mockedTracker->expects($this->exactly(0))->method('track')->willReturn(null); $mockedEvent->expects($this->once())->method('executeChecker')->willReturn(true); $mockedEvent->expects($this->once())->method('executeAction')->willReturn(true); diff --git a/tests/Types/Events/EventTest.php b/tests/Events/EventTest.php similarity index 76% rename from tests/Types/Events/EventTest.php rename to tests/Events/EventTest.php index eb45ed40..3247a4e5 100644 --- a/tests/Types/Events/EventTest.php +++ b/tests/Events/EventTest.php @@ -1,11 +1,12 @@ assertInstanceOf('TelegramBot\Api\Events\Event', $item); + $this->assertInstanceOf(Event::class, $item); } /** @@ -67,7 +68,6 @@ public function testGetAction($action, $checker, $update) { $item = new Event($action, $checker); - $this->assertAttributeInstanceOf('\Closure', 'action', $item); $this->assertEquals($action, $item->getAction()); } @@ -82,7 +82,6 @@ public function testGetChecker($action, $checker, $update) { $item = new Event($action, $checker); - $this->assertAttributeInstanceOf('\Closure', 'checker', $item); $this->assertEquals($checker, $item->getChecker()); } @@ -99,29 +98,10 @@ public function testExecuteAction($action, $checker, $update) $result = $item->executeAction($update); - $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $result); + $this->assertInstanceOf(Update::class, $result); $this->assertEquals($update, $result); } - /** - * @param \Closure $action - * @param \Closure $checker - * @param Update $update - * - * @dataProvider data - */ - public function testExecuteActionFalse($action, $checker, $update) { - $item = new Event($action, $checker); - - $reflection = new \ReflectionClass($item); - $reflectionProperty = $reflection->getProperty('action'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($item, 1); - $reflectionProperty->setAccessible(false); - - $this->assertFalse($item->executeAction($update)); - } - /** * @param \Closure $action * @param \Closure $checker @@ -135,7 +115,7 @@ public function testExecuteCheker($action, $checker, $update) $result = $item->executeChecker($update); - $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $result); + $this->assertInstanceOf(Update::class, $result); $this->assertEquals($update, $result); } @@ -146,7 +126,8 @@ public function testExecuteCheker($action, $checker, $update) * * @dataProvider data */ - public function testExecuteCheckerFalse($action, $checker, $update) { + public function testExecuteCheckerFalse($action, $checker, $update) + { $item = new Event($action, $checker); $reflection = new \ReflectionClass($item); diff --git a/tests/FileTest.php b/tests/FileTest.php deleted file mode 100644 index 459874d9..00000000 --- a/tests/FileTest.php +++ /dev/null @@ -1,83 +0,0 @@ -setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() - { - $item = new File(); - $item->setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetFileSize() - { - $item = new File(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() - { - $item = new File(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetFilePath() - { - $item = new File(); - $item->setFilePath('testfilepath'); - $this->assertAttributeEquals('testfilepath', 'filePath', $item); - } - - public function testGetFilePath() - { - $item = new File(); - $item->setFilePath('testfilepath'); - $this->assertEquals('testfilepath', $item->getFilePath()); - } - - public function testFromResponse() - { - $item = File::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_size' => 3, - 'file_path' => 'testfilepath' - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\File', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals(3, 'fileSize', $item); - $this->assertAttributeEquals('testfilepath', 'filePath', $item); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException() - { - $item = File::fromResponse(array( - 'file_size' => 3, - 'file_path' => 'testfilepath' - )); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetFileSizeException() - { - $item = new File(); - $item->setFileSize('s'); - } - -} diff --git a/tests/ForceReplyTest.php b/tests/ForceReplyTest.php deleted file mode 100644 index 56f916a1..00000000 --- a/tests/ForceReplyTest.php +++ /dev/null @@ -1,105 +0,0 @@ -assertAttributeEquals(true, 'forceReply', $item); - $this->assertAttributeEquals(null, 'selective', $item); - } - - public function testConstructor2() - { - $item = new ForceReply(true, true); - - $this->assertAttributeEquals(true, 'forceReply', $item); - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testConstructor3() - { - $item = new ForceReply(false, true); - - $this->assertAttributeEquals(false, 'forceReply', $item); - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testConstructor4() - { - $item = new ForceReply(true); - - $this->assertAttributeEquals(true, 'forceReply', $item); - $this->assertAttributeEquals(null, 'selective', $item); - } - - public function testSetforceReply() - { - $item = new ForceReply(true); - - $item->setforceReply(false); - - $this->assertAttributeEquals(false, 'forceReply', $item); - } - - public function testIsforceReply() - { - $item = new ForceReply(true); - - $item->setforceReply(false); - - $this->assertEquals(false, $item->isforceReply()); - } - - public function testSetSelective() - { - $item = new ForceReply(); - - $item->setSelective(true); - - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testIsSelective() - { - $item = new ForceReply(); - - $item->setSelective(true); - - $this->assertEquals(true, $item->isSelective()); - } - - public function testToJson() - { - $item = new ForceReply(); - - $this->assertEquals(json_encode(array('force_reply' => true)), $item->toJson()); - } - - public function testToJson2() - { - $item = new ForceReply(); - - $this->assertEquals(array('force_reply' => true), $item->toJson(true)); - } - - public function testToJson3() - { - $item = new ForceReply(true, true); - - $this->assertEquals(json_encode(array('force_reply' => true, 'selective' => true)), $item->toJson()); - } - - public function testToJson4() - { - $item = new ForceReply(true, true); - - $this->assertEquals(array('force_reply' => true, 'selective' => true), $item->toJson(true)); - } -} diff --git a/tests/LocationTest.php b/tests/LocationTest.php deleted file mode 100644 index 136e40e4..00000000 --- a/tests/LocationTest.php +++ /dev/null @@ -1,63 +0,0 @@ -setLatitude(55.585827); - $this->assertAttributeEquals(55.585827, 'latitude', $location); - } - - public function testGetLatitude() - { - $location = new Location(); - $location->setLatitude(55.585827); - $this->assertEquals(55.585827, $location->getLatitude()); - } - - public function testSetLongtitude() - { - $location = new Location(); - $location->setLongitude(37.675309); - $this->assertAttributeEquals(37.675309, 'longitude', $location); - } - - public function testGetLongtitude() - { - $location = new Location(); - $location->setLongitude(37.675309); - $this->assertEquals(37.675309, $location->getLongitude()); - } - - public function testFromResponse() - { - $location = Location::fromResponse(array("latitude" => 55.585827, 'longitude' => 37.675309)); - $this->assertInstanceOf('\TelegramBot\Api\Types\Location', $location); - $this->assertAttributeEquals(55.585827, 'latitude', $location); - $this->assertAttributeEquals(37.675309, 'longitude', $location); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetLatitudeException() - { - $item = new Location(); - $item->setLatitude('s'); - } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetLongitudeException() - { - $item = new Location(); - $item->setLongitude('s'); - } - -} diff --git a/tests/MessageTest.php b/tests/MessageTest.php deleted file mode 100644 index a148f85b..00000000 --- a/tests/MessageTest.php +++ /dev/null @@ -1,853 +0,0 @@ -setMessageId(1); - $this->assertAttributeEquals(1, 'messageId', $item); - } - - public function testSet64bitMessageId() - { - $item = new Message(); - $item->setMessageId(2147483648); - $this->assertAttributeEquals(2147483648, 'messageId', $item); - } - - public function testGetMessageId() - { - $item = new Message(); - $item->setMessageId(1); - $this->assertEquals(1, $item->getMessageId()); - } - - public function testSetCaption() - { - $item = new Message(); - $item->setCaption('test'); - $this->assertAttributeEquals('test', 'caption', $item); - } - - public function testGetCaption() - { - $item = new Message(); - $item->setCaption('test'); - $this->assertEquals('test', $item->getCaption()); - } - - public function testSetDate() - { - $item = new Message(); - $item->setDate(1234567); - $this->assertAttributeEquals(1234567, 'date', $item); - } - - public function testGetDate() - { - $item = new Message(); - $item->setDate(1234567); - $this->assertEquals(1234567, $item->getDate()); - } - - public function testSetForwardDate() - { - $item = new Message(); - $item->setForwardDate(1234567); - $this->assertAttributeEquals(1234567, 'forwardDate', $item); - } - - public function testGetForwardDate() - { - $item = new Message(); - $item->setForwardDate(1234567); - $this->assertEquals(1234567, $item->getForwardDate()); - } - - public function testSetFrom() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setFrom($user); - $this->assertAttributeEquals($user, 'from', $item); - } - - public function testGetFrom() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setFrom($user); - $this->assertEquals($user, $item->getFrom()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getFrom()); - } - - public function testSetForwardFrom() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setForwardFrom($user); - $this->assertAttributeEquals($user, 'forwardFrom', $item); - } - - public function testGetForwardFrom() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setForwardFrom($user); - $this->assertEquals($user, $item->getForwardFrom()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getForwardFrom()); - } - - public function testSetChatGroup() - { - $item = new Message(); - $chat = Chat::fromResponse(array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - )); - $item->setChat($chat); - $this->assertAttributeEquals($chat, 'chat', $item); - } - - public function testGetChatGroup() - { - $item = new Message(); - $chat = Chat::fromResponse(array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - )); - $item->setChat($chat); - $this->assertEquals($chat, $item->getChat()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item->getChat()); - } - - public function testSetChatUser() - { - $item = new Message(); - $user = Chat::fromResponse(array( - 'id' => 1, - 'type' => 'private', - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setChat($user); - $this->assertAttributeEquals($user, 'chat', $item); - } - - public function testGetChatUser() - { - $item = new Message(); - $user = Chat::fromResponse(array( - 'id' => 1, - 'type' => 'private', - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setChat($user); - $this->assertEquals($user, $item->getChat()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Chat', $item->getChat()); - } - - public function testSetContact() - { - $item = new Message(); - $contact = Contact::fromResponse(array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'phone_number' => '123456', - 'user_id' => 'iGusev' - )); - $item->setContact($contact); - $this->assertAttributeEquals($contact, 'contact', $item); - } - - public function testGetContact() - { - $item = new Message(); - $contact = Contact::fromResponse(array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'phone_number' => '123456', - 'user_id' => 'iGusev' - )); - $item->setContact($contact); - $this->assertEquals($contact, $item->getContact()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Contact', $item->getContact()); - } - - public function testSetDocument() - { - $item = new Message(); - $document = Document::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_name' => 'testFileName', - 'mime_type' => 'audio/mp3', - 'file_size' => 3, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - $item->setDocument($document); - $this->assertAttributeEquals($document, 'document', $item); - } - - public function testGetDocument() - { - $item = new Message(); - $document = Document::fromResponse(array( - 'file_id' => 'testFileId1', - 'file_name' => 'testFileName', - 'mime_type' => 'audio/mp3', - 'file_size' => 3, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - $item->setDocument($document); - $this->assertEquals($document, $item->getDocument()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Document', $item->getDocument()); - } - - public function testSetLocation() - { - $item = new Message(); - $location = Location::fromResponse(array('latitude' => 55.585827, 'longitude' => 37.675309)); - $item->setLocation($location); - $this->assertAttributeEquals($location, 'location', $item); - } - - public function testGetLocation() - { - $item = new Message(); - $location = Location::fromResponse(array('latitude' => 55.585827, 'longitude' => 37.675309)); - $item->setLocation($location); - $this->assertEquals($location, $item->getLocation()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Location', $item->getLocation()); - } - - public function testSetAudio() - { - $item = new Message(); - $audio = Audio::fromResponse(array( - 'file_id' => 'testFileId1', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - $item->setAudio($audio); - $this->assertAttributeEquals($audio, 'audio', $item); - } - - public function testGetAudio() - { - $item = new Message(); - $audio = Audio::fromResponse(array( - 'file_id' => 'testFileId1', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - $item->setAudio($audio); - $this->assertEquals($audio, $item->getAudio()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Audio', $item->getAudio()); - } - - public function testSetVoice() - { - $item = new Message(); - $voice = Voice::fromResponse(array( - 'file_id' => 'testFileId1', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - $item->setVoice($voice); - $this->assertAttributeEquals($voice, 'voice', $item); - } - - public function testGetVoice() - { - $item = new Message(); - $voice = Voice::fromResponse(array( - 'file_id' => 'testFileId1', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - $item->setVoice($voice); - $this->assertEquals($voice, $item->getVoice()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Voice', $item->getVoice()); - } - - public function testSetVideo() - { - $item = new Message(); - $video = Video::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'duration' => 3, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - $item->setVideo($video); - $this->assertAttributeEquals($video, 'video', $item); - } - - public function testGetVideo() - { - $item = new Message(); - $video = Video::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'duration' => 3, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - $item->setVideo($video); - $this->assertEquals($video, $item->getVideo()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Video', $item->getVideo()); - } - - public function testSetSticker() - { - $item = new Message(); - $sticker = Sticker::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3, - 'thumb' => array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ) - )); - $item->setSticker($sticker); - $this->assertAttributeEquals($sticker, 'sticker', $item); - } - - public function testGetSticker() - { - $item = new Message(); - $sticker = Sticker::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3, - 'thumb' => array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ) - )); - $item->setSticker($sticker); - $this->assertEquals($sticker, $item->getSticker()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Sticker', $item->getSticker()); - } - - public function testSetGroupChatCreated() - { - $item = new Message(); - $item->setGroupChatCreated(true); - - $this->assertAttributeEquals(true, 'groupChatCreated', $item); - } - - public function testIsGroupChatCreated() - { - $item = new Message(); - $item->setGroupChatCreated(true); - - $this->assertTrue($item->isGroupChatCreated()); - } - - public function testSetDeleteChatPhoto() - { - $item = new Message(); - $item->setDeleteChatPhoto(true); - - $this->assertAttributeEquals(true, 'deleteChatPhoto', $item); - } - - public function testIsDeleteChatPhoto() - { - $item = new Message(); - $item->setDeleteChatPhoto(true); - - $this->assertTrue($item->isDeleteChatPhoto()); - } - - public function testSetLeftChatParticipant() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setLeftChatMember($user); - - - $this->assertAttributeEquals($user, 'leftChatMember', $item); - } - - public function testGetLeftChatParticipant() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setLeftChatMember($user); - - $this->assertEquals($user, $item->getLeftChatMember()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getLeftChatMember()); - } - - public function testSetNewChatParticipant() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setNewChatMember($user); - - - $this->assertAttributeEquals($user, 'newChatMember', $item); - } - - public function testGetNewChatParticipant() - { - $item = new Message(); - $user = User::fromResponse(array( - 'id' => 1, - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - $item->setNewChatMember($user); - - $this->assertEquals($user, $item->getNewChatMember()); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $item->getNewChatMember()); - } - - public function testSetNewChatTitle() - { - $item = new Message(); - $item->setNewChatTitle('testtitle'); - - $this->assertAttributeEquals('testtitle', 'newChatTitle', $item); - } - - public function testGetNewChatTitle() - { - $item = new Message(); - $item->setNewChatTitle('testtitle'); - - $this->assertEquals('testtitle', $item->getNewChatTitle()); - } - - public function testSetText() - { - $item = new Message(); - $item->setText('testtitle'); - - $this->assertAttributeEquals('testtitle', 'text', $item); - } - - public function testGetText() - { - $item = new Message(); - $item->setText('testtitle'); - - $this->assertEquals('testtitle', $item->getText()); - } - - public function testSetReplyToMessage() - { - $item = new Message(); - $replyMessage = Message::fromResponse(array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ) - )); - $item->setReplyToMessage($replyMessage); - - $this->assertAttributeEquals($replyMessage, 'replyToMessage', $item); - } - - public function testGetReplyToMessage() - { - $item = new Message(); - $replyMessage = Message::fromResponse(array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ) - )); - $item->setReplyToMessage($replyMessage); - - $this->assertEquals($replyMessage, $item->getReplyToMessage()); - $this->assertInstanceOf('\TelegramBot\Api\Types\Message', $item->getReplyToMessage()); - } - - public function testSetPhoto() - { - $item = new Message(); - $photo = array( - PhotoSize::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - )) - ); - - $item->setPhoto($photo); - - $this->assertAttributeEquals($photo, 'photo', $item); - } - - public function testGetPhoto() - { - $item = new Message(); - $photo = array( - PhotoSize::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - )) - ); - - $item->setPhoto($photo); - - $this->assertEquals($photo, $item->getPhoto()); - - foreach ($item->getPhoto() as $photoItem) { - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photoItem); - } - } - - public function testGetNewChatPhoto() - { - $item = new Message(); - $photo = array( - PhotoSize::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - )) - ); - - $item->setNewChatPhoto($photo); - $this->assertAttributeEquals($photo, 'newChatPhoto', $item); - } - - public function testSetNewChatPhoto() - { - $item = new Message(); - $photo = array( - PhotoSize::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - )) - ); - - $item->setNewChatPhoto($photo); - $this->assertEquals($photo, $item->getNewChatPhoto()); - - foreach ($item->getNewChatPhoto() as $photoItem) { - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photoItem); - } - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetMessageIdException() - { - $item = new Message(); - $item->setMessageId('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetDateException() - { - $item = new Message(); - $item->setDate('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetForwardDateException() - { - $item = new Message(); - $item->setForwardDate('s'); - } - - public function testSetSupergroupChatCreated() - { - $item = new Message(); - $item->setSupergroupChatCreated(true); - - $this->assertAttributeEquals(true, 'supergroupChatCreated', $item); - } - - public function testIsSupergroupChatCreated() - { - $item = Message::fromResponse(array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ), - 'supergroup_chat_created' => true - )); - - $this->assertTrue($item->isSupergroupChatCreated()); - } - - public function testSetChannelChatCreated() - { - $item = new Message(); - $item->setChannelChatCreated(true); - - $this->assertAttributeEquals(true, 'channelChatCreated', $item); - } - - public function testIsChannelChatCreated() - { - $item = Message::fromResponse(array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ), - 'channel_chat_created' => true - )); - - $this->assertTrue($item->isChannelChatCreated()); - } - - public function testSetMigrateToChatId() - { - $item = new Message(); - $item->setMigrateToChatId(2); - $this->assertAttributeEquals(2, 'migrateToChatId', $item); - } - - public function testGetMigrateToChatId() - { - $item = Message::fromResponse(array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ), - 'migrate_to_chat_id' => 2 - )); - - $this->assertEquals(2, $item->getMigrateToChatId()); - } - - public function testSetMigrateFromChatId() - { - $item = new Message(); - $item->setMigrateFromChatId(2); - $this->assertAttributeEquals(2, 'migrateFromChatId', $item); - } - - public function testGetMigrateFromChatId() - { - $item = Message::fromResponse(array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ), - 'migrate_from_chat_id' => 3 - )); - - $this->assertEquals(3, $item->getMigrateFromChatId()); - } - - public function testToJson1() - { - $data = array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ), - 'migrate_from_chat_id' => 3 - ); - - $item = Message::fromResponse($data); - $this->assertJson(json_encode($data), $item->toJson()); - } - - public function testToJson2() - { - $data = array( - 'message_id' => 1, - 'from' => array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - ), - 'date' => 2, - 'chat' => array( - 'id' => 1, - 'type' => 'group', - 'title' => 'test chat' - ), - 'entities' => array( - array( - "type" => "bot_command", - "offset" => 0, - "length" => 7, - ) - ), - 'migrate_from_chat_id' => 3 - ); - - $item = Message::fromResponse($data); - $this->assertJson(json_encode($data), $item->toJson()); - } -} diff --git a/tests/PhotoSizeTest.php b/tests/PhotoSizeTest.php deleted file mode 100644 index 215df137..00000000 --- a/tests/PhotoSizeTest.php +++ /dev/null @@ -1,106 +0,0 @@ -setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $photoSize); - } - - public function testGetFileId() - { - $photoSize = new PhotoSize(); - $photoSize->setFileId('testfileId'); - $this->assertEquals('testfileId', $photoSize->getFileId()); - } - - public function testSetWidth() - { - $photoSize = new PhotoSize(); - $photoSize->setWidth(1); - $this->assertAttributeEquals(1, 'width', $photoSize); - } - - public function testGetWidth() - { - $photoSize = new PhotoSize(); - $photoSize->setWidth(2); - $this->assertEquals(2, $photoSize->getWidth()); - } - - public function testSetHeight() - { - $photoSize = new PhotoSize(); - $photoSize->setHeight(3); - $this->assertAttributeEquals(3, 'height', $photoSize); - } - - public function testGetHeight() - { - $photoSize = new PhotoSize(); - $photoSize->setHeight(4); - $this->assertEquals(4, $photoSize->getHeight()); - } - - public function testSetFileSize() - { - $photoSize = new PhotoSize(); - $photoSize->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $photoSize); - } - - public function testGetFileSize() - { - $photoSize = new PhotoSize(); - $photoSize->setFileSize(6); - $this->assertEquals(6, $photoSize->getFileSize()); - } - - public function testFromResponse() - { - $photoSize = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photoSize); - $this->assertAttributeEquals('testFileId1', 'fileId', $photoSize); - $this->assertAttributeEquals(1, 'width', $photoSize); - $this->assertAttributeEquals(2, 'height', $photoSize); - $this->assertAttributeEquals(3, 'fileSize', $photoSize); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetFileSizeException() - { - $item = new PhotoSize(); - $item->setFileSize('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetHeightException() - { - $item = new PhotoSize(); - $item->setHeight('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetWidthException() - { - $item = new PhotoSize(); - $item->setWidth('s'); - } -} diff --git a/tests/ReplyKeyboardHideTest.php b/tests/ReplyKeyboardHideTest.php deleted file mode 100644 index 17bbdfa4..00000000 --- a/tests/ReplyKeyboardHideTest.php +++ /dev/null @@ -1,104 +0,0 @@ -assertAttributeEquals(true, 'hideKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); - } - - public function testConstructor2() - { - $item = new ReplyKeyboardHide(true, true); - - $this->assertAttributeEquals(true, 'hideKeyboard', $item); - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testConstructor3() - { - $item = new ReplyKeyboardHide(false, true); - - $this->assertAttributeEquals(false, 'hideKeyboard', $item); - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testConstructor4() - { - $item = new ReplyKeyboardHide(true); - - $this->assertAttributeEquals(true, 'hideKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); - } - - public function testSetHideKeyboard() - { - $item = new ReplyKeyboardHide(true); - - $item->setHideKeyboard(false); - - $this->assertAttributeEquals(false, 'hideKeyboard', $item); - } - - public function testIsHideKeyboard() - { - $item = new ReplyKeyboardHide(true); - - $item->setHideKeyboard(false); - - $this->assertEquals(false, $item->isHideKeyboard()); - } - - public function testSetSelective() - { - $item = new ReplyKeyboardHide(); - - $item->setSelective(true); - - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testIsSelective() - { - $item = new ReplyKeyboardHide(); - - $item->setSelective(true); - - $this->assertEquals(true, $item->isSelective()); - } - - public function testToJson() - { - $item = new ReplyKeyboardHide(); - - $this->assertEquals(json_encode(array('hide_keyboard' => true)), $item->toJson()); - } - - public function testToJson2() - { - $item = new ReplyKeyboardHide(); - - $this->assertEquals(array('hide_keyboard' => true), $item->toJson(true)); - } - - public function testToJson3() - { - $item = new ReplyKeyboardHide(true, true); - - $this->assertEquals(json_encode(array('hide_keyboard' => true, 'selective' => true)), $item->toJson()); - } - - public function testToJson4() - { - $item = new ReplyKeyboardHide(true, true); - - $this->assertEquals(array('hide_keyboard' => true, 'selective' => true), $item->toJson(true)); - } -} diff --git a/tests/ReplyKeyboardMarkupTest.php b/tests/ReplyKeyboardMarkupTest.php deleted file mode 100644 index e4361d6d..00000000 --- a/tests/ReplyKeyboardMarkupTest.php +++ /dev/null @@ -1,153 +0,0 @@ -assertAttributeEquals(array(array('one', 'two')), 'keyboard', $item); - $this->assertAttributeEquals(null, 'oneTimeKeyboard', $item); - $this->assertAttributeEquals(null, 'resizeKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); - } - - public function testConstructor2() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true); - - $this->assertAttributeEquals(array(array('one', 'two')), 'keyboard', $item); - $this->assertAttributeEquals(true, 'oneTimeKeyboard', $item); - $this->assertAttributeEquals(null, 'resizeKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); - } - - public function testConstructor3() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true); - - $this->assertAttributeEquals(array(array('one', 'two')), 'keyboard', $item); - $this->assertAttributeEquals(true, 'oneTimeKeyboard', $item); - $this->assertAttributeEquals(true, 'resizeKeyboard', $item); - $this->assertAttributeEquals(null, 'selective', $item); - } - - public function testConstructor4() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true, true); - - $this->assertAttributeEquals(array(array('one', 'two')), 'keyboard', $item); - $this->assertAttributeEquals(true, 'oneTimeKeyboard', $item); - $this->assertAttributeEquals(true, 'resizeKeyboard', $item); - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testSetKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setKeyboard(array(array('one', 'two', 'three'))); - - $this->assertAttributeEquals(array(array('one', 'two', 'three')), 'keyboard', $item); - } - - public function testGetKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setKeyboard(array(array('one', 'two', 'three'))); - - $this->assertEquals(array(array('one', 'two', 'three')), $item->getKeyboard()); - } - - public function testSetSelective() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setSelective(true); - - $this->assertAttributeEquals(true, 'selective', $item); - } - - public function testIsSelective() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setSelective(true); - - $this->assertEquals(true, $item->isSelective()); - } - - public function testSetOneTimeKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setOneTimeKeyboard(false); - - $this->assertAttributeEquals(false, 'oneTimeKeyboard', $item); - } - - public function testIsOneTimeKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setOneTimeKeyboard(false); - - $this->assertEquals(false, $item->isOneTimeKeyboard()); - } - - public function testSetResizeKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setResizeKeyboard(true); - - $this->assertAttributeEquals(true, 'resizeKeyboard', $item); - } - - public function testIsResizeKeyboard() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - $item->setResizeKeyboard(true); - - $this->assertEquals(true, $item->isResizeKeyboard()); - } - - public function testToJson() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - - $this->assertEquals(json_encode(array('keyboard' => array(array('one', 'two')))), $item->toJson()); - } - - public function testToJson2() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true, true); - - $this->assertEquals(json_encode(array( - 'keyboard' => array(array('one', 'two')), - 'one_time_keyboard' => true, - 'resize_keyboard' => true, - 'selective' => true, - )), - $item->toJson()); - } - - public function testToJson3() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two'))); - - $this->assertEquals(array('keyboard' => array(array('one', 'two'))), $item->toJson(true)); - } - - public function testToJson4() - { - $item = new ReplyKeyboardMarkup(array(array('one', 'two')), true, true, true); - - $this->assertEquals(array( - 'keyboard' => array(array('one', 'two')), - 'one_time_keyboard' => true, - 'resize_keyboard' => true, - 'selective' => true, - ), - $item->toJson(true)); - } - -} diff --git a/tests/StickerTest.php b/tests/StickerTest.php deleted file mode 100644 index 3d37f849..00000000 --- a/tests/StickerTest.php +++ /dev/null @@ -1,146 +0,0 @@ -setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $sticker); - } - - public function testGetFileId() - { - $sticker = new Sticker(); - $sticker->setFileId('testfileId'); - $this->assertEquals('testfileId', $sticker->getFileId()); - } - - public function testSetWidth() - { - $sticker = new Sticker(); - $sticker->setWidth(1); - $this->assertAttributeEquals(1, 'width', $sticker); - } - - public function testGetWidth() - { - $sticker = new Sticker(); - $sticker->setWidth(2); - $this->assertEquals(2, $sticker->getWidth()); - } - - public function testSetHeight() - { - $sticker = new Sticker(); - $sticker->setHeight(3); - $this->assertAttributeEquals(3, 'height', $sticker); - } - - public function testGetHeight() - { - $sticker = new Sticker(); - $sticker->setHeight(4); - $this->assertEquals(4, $sticker->getHeight()); - } - - public function testSetFileSize() - { - $sticker = new Sticker(); - $sticker->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $sticker); - } - - public function testGetFileSize() - { - $sticker = new Sticker(); - $sticker->setFileSize(6); - $this->assertEquals(6, $sticker->getFileSize()); - } - - public function testSetThumb() - { - $sticker = new Sticker(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $sticker->setThumb($thumb); - $this->assertAttributeEquals($thumb, 'thumb', $sticker); - } - - public function testGetThumb() - { - $sticker = new Sticker(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $sticker->setThumb($thumb); - $this->assertEquals($thumb, $sticker->getThumb()); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $sticker->getThumb()); - } - - public function testFromResponse() - { - $sticker = Sticker::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3, - 'thumb' => array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ) - )); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Sticker', $sticker); - $this->assertAttributeEquals('testFileId1', 'fileId', $sticker); - $this->assertAttributeEquals(1, 'width', $sticker); - $this->assertAttributeEquals(2, 'height', $sticker); - $this->assertAttributeEquals(3, 'fileSize', $sticker); - $this->assertAttributeEquals($thumb, 'thumb', $sticker); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetFileSizeException() - { - $item = new Sticker(); - $item->setFileSize('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetHeightException() - { - $item = new Sticker(); - $item->setHeight('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetWidthException() - { - $item = new Sticker(); - $item->setWidth('s'); - } -} diff --git a/tests/Types/AcceptedGiftTypesTest.php b/tests/Types/AcceptedGiftTypesTest.php new file mode 100644 index 00000000..ddd84e52 --- /dev/null +++ b/tests/Types/AcceptedGiftTypesTest.php @@ -0,0 +1,42 @@ + true, + 'limited_gifts' => true, + 'unique_gifts' => true, + 'premium_subscription' => true, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertTrue($item->getUnlimitedGifts()); + $this->assertTrue($item->getLimitedGifts()); + $this->assertTrue($item->getUniqueGifts()); + $this->assertTrue($item->getPremiumSubscription()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/AnimationTest.php b/tests/Types/AnimationTest.php new file mode 100644 index 00000000..9aba5b58 --- /dev/null +++ b/tests/Types/AnimationTest.php @@ -0,0 +1,107 @@ + 'file_id', + 'file_unique_id' => 'file_unique_id', + 'width' => 10, + 'height' => 20, + 'duration' => 30, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'file_id', + 'file_unique_id' => 'file_unique_id', + 'width' => 10, + 'height' => 20, + 'duration' => 30, + 'thumbnail' => PhotoSizeTest::getMinResponse(), + 'file_name' => 'file_name', + 'mime_type' => 'mime_type', + 'file_size' => 100 + ]; + } + + /** + * @param Animation $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('file_id', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(10, $item->getWidth()); + $this->assertEquals(20, $item->getHeight()); + $this->assertEquals(30, $item->getDuration()); + $this->assertNull($item->getThumbnail()); + $this->assertNull($item->getFileName()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + } + + /** + * @param Animation $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('file_id', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(10, $item->getWidth()); + $this->assertEquals(20, $item->getHeight()); + $this->assertEquals(30, $item->getDuration()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); + $this->assertEquals('file_name', $item->getFileName()); + $this->assertEquals('mime_type', $item->getMimeType()); + $this->assertEquals(100, $item->getFileSize()); + } + + public function testSetDuration() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Animation(); + $item->setDuration('s'); + } + + public function testSetFileSize() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Animation(); + $item->setFileSize('s'); + } + + public function testSetHeight() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Animation(); + $item->setHeight('s'); + } + + public function testSetWidth() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Animation(); + $item->setWidth('s'); + } +} diff --git a/tests/Types/ArrayOfBotCommandTest.php b/tests/Types/ArrayOfBotCommandTest.php new file mode 100644 index 00000000..dddb66fd --- /dev/null +++ b/tests/Types/ArrayOfBotCommandTest.php @@ -0,0 +1,31 @@ + 'start', + 'description' => 'This is a start command!', + ], + ]); + + $expected = [ + BotCommand::fromResponse([ + 'command' => 'start', + 'description' => 'This is a start command!', + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfChatMemberEntityTest.php b/tests/Types/ArrayOfChatMemberEntityTest.php new file mode 100644 index 00000000..46ca2a93 --- /dev/null +++ b/tests/Types/ArrayOfChatMemberEntityTest.php @@ -0,0 +1,37 @@ + [ + 'id' => 1, + 'first_name' => 'first_name', + ], + 'status' => 'member', + ], + ]); + + $expected = [ + ChatMember::fromResponse([ + 'user' => [ + 'id' => 1, + 'first_name' => 'first_name', + ], + 'status' => 'member', + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfChatTest.php b/tests/Types/ArrayOfChatTest.php new file mode 100644 index 00000000..94776250 --- /dev/null +++ b/tests/Types/ArrayOfChatTest.php @@ -0,0 +1,39 @@ + 123456789, + 'type' => 'group', + ], + [ + 'id' => 123456788, + 'type' => 'private', + ] + ]); + + $expected = [ + Chat::fromResponse([ + 'id' => 123456789, + 'type' => 'group', + ]), + Chat::fromResponse([ + 'id' => 123456788, + 'type' => 'private', + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfMessageEntityTest.php b/tests/Types/ArrayOfMessageEntityTest.php new file mode 100644 index 00000000..ce6ca65d --- /dev/null +++ b/tests/Types/ArrayOfMessageEntityTest.php @@ -0,0 +1,33 @@ + 'mention', + 'offset' => 0, + 'length' => 10, + ], + ]); + + $expected = [ + MessageEntity::fromResponse([ + 'type' => 'mention', + 'offset' => 0, + 'length' => 10, + ]), + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfMessagesTest.php b/tests/Types/ArrayOfMessagesTest.php new file mode 100644 index 00000000..b96939af --- /dev/null +++ b/tests/Types/ArrayOfMessagesTest.php @@ -0,0 +1,39 @@ + 1, + 'date' => 1682343644, + 'chat' => [ + 'id' => 2, + 'type' => 'private', + ], + ] + ]); + + $expected = [ + Message::fromResponse([ + 'message_id' => 1, + 'date' => 1682343644, + 'chat' => [ + 'id' => 2, + 'type' => 'private', + ], + ]), + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/ArrayOfPhotoSizeTest.php b/tests/Types/ArrayOfPhotoSizeTest.php similarity index 61% rename from tests/ArrayOfPhotoSizeTest.php rename to tests/Types/ArrayOfPhotoSizeTest.php index 816f124d..280da570 100644 --- a/tests/ArrayOfPhotoSizeTest.php +++ b/tests/Types/ArrayOfPhotoSizeTest.php @@ -1,35 +1,36 @@ 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - ) - ) + ] + ] ); - $expected = array( - PhotoSize::fromResponse(array( + $expected = [ + PhotoSize::fromResponse([ 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', 'width' => 5, 'height' => 6, 'file_size' => 7 - )) - ); + ]) + ]; foreach($actual as $key => $item) { $this->assertEquals($expected[$key], $item); diff --git a/tests/Types/ArrayOfPollOptionTest.php b/tests/Types/ArrayOfPollOptionTest.php new file mode 100644 index 00000000..a22a0992 --- /dev/null +++ b/tests/Types/ArrayOfPollOptionTest.php @@ -0,0 +1,31 @@ + 'text', + 'voter_count' => 3 + ] + ]); + + $expected = [ + PollOption::fromResponse([ + 'text' => 'text', + 'voter_count' => 3 + ]), + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfReactionTypeTest.php b/tests/Types/ArrayOfReactionTypeTest.php new file mode 100644 index 00000000..47fff3e8 --- /dev/null +++ b/tests/Types/ArrayOfReactionTypeTest.php @@ -0,0 +1,40 @@ + '👍', + 'type' => 'emoji' + ], + [ + 'custom_emoji_id' => 'custom_emoji_123', + 'type' => 'custom_emoji' + ] + ]); + + $expected = [ + ReactionTypeEmoji::fromResponse([ + 'emoji' => '👍', + 'type' => 'emoji' + ]), + ReactionTypeCustomEmoji::fromResponse([ + 'custom_emoji_id' => 'custom_emoji_123', + 'type' => 'custom_emoji' + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfStickerTest.php b/tests/Types/ArrayOfStickerTest.php new file mode 100644 index 00000000..3b6ea1da --- /dev/null +++ b/tests/Types/ArrayOfStickerTest.php @@ -0,0 +1,41 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'type' => 'regular', + 'width' => 1, + 'height' => 2, + 'is_animated' => false, + 'is_video' => false, + ], + ]); + + $expected = [ + Sticker::fromResponse([ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'type' => 'regular', + 'width' => 1, + 'height' => 2, + 'is_animated' => false, + 'is_video' => false, + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/ArrayOfUpdatesTest.php b/tests/Types/ArrayOfUpdatesTest.php index 1f3d1485..53ba31fc 100644 --- a/tests/Types/ArrayOfUpdatesTest.php +++ b/tests/Types/ArrayOfUpdatesTest.php @@ -2,11 +2,12 @@ namespace TelegramBot\Api\Test\Types; +use PHPUnit\Framework\TestCase; use TelegramBot\Api\Types\ArrayOfUpdates; +use TelegramBot\Api\Types\Update; -class ArrayOfUpdatesTest extends \PHPUnit_Framework_TestCase +class ArrayOfUpdatesTest extends TestCase { - public function data() { return [ @@ -47,10 +48,10 @@ public function testFromResponse($data) { $items = ArrayOfUpdates::fromResponse($data); - $this->assertInternalType('array', $items); + $this->assertIsArray($items); foreach($items as $item) { - $this->assertInstanceOf('\TelegramBot\Api\Types\Update', $item); + $this->assertInstanceOf(Update::class, $item); } } } diff --git a/tests/Types/ArrayOfUserTest.php b/tests/Types/ArrayOfUserTest.php new file mode 100644 index 00000000..5d99708f --- /dev/null +++ b/tests/Types/ArrayOfUserTest.php @@ -0,0 +1,31 @@ + 1, + 'first_name' => 'first_name', + ], + ]); + + $expected = [ + User::fromResponse([ + 'id' => 1, + 'first_name' => 'first_name', + ]) + ]; + + foreach ($items as $key => $item) { + $this->assertEquals($expected[$key], $item); + } + } +} diff --git a/tests/Types/AudioTest.php b/tests/Types/AudioTest.php new file mode 100644 index 00000000..b254a08c --- /dev/null +++ b/tests/Types/AudioTest.php @@ -0,0 +1,129 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'duration' => 1, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'duration' => 1, + 'performer' => 'testperformer', + 'title' => 'testtitle', + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + ]; + } + + /** + * @param Audio $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getDuration()); + $this->assertNull($item->getPerformer()); + $this->assertNull($item->getTitle()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + } + + /** + * @param Audio $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getDuration()); + $this->assertEquals('testperformer', $item->getPerformer()); + $this->assertEquals('testtitle', $item->getTitle()); + $this->assertEquals('audio/mp3', $item->getMimeType()); + $this->assertEquals(3, $item->getFileSize()); + } + + /** + * file_id is missing + */ + public function testFromResponseException() + { + $this->expectException(InvalidArgumentException::class); + + Audio::fromResponse([ + 'file_unique_id' => 'testFileUniqueId1', + 'duration' => 1, + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + ]); + } + + /** + * duration is missing + */ + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + + Audio::fromResponse([ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + ]); + } + + /** + * file_unique_id is missing + */ + public function testFromResponseException3() + { + $this->expectException(InvalidArgumentException::class); + + Audio::fromResponse([ + 'file_id' => 'testFileId1', + 'duration' => 1, + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + ]); + } + + public function testSetDurationException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Audio(); + $item->setDuration('s'); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Audio(); + $item->setFileSize('s'); + } + +} diff --git a/tests/Types/BotCommandTest.php b/tests/Types/BotCommandTest.php new file mode 100644 index 00000000..c2849b06 --- /dev/null +++ b/tests/Types/BotCommandTest.php @@ -0,0 +1,46 @@ + 'start', + 'description' => 'This is a start command!', + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param BotCommand $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('start', $item->getCommand()); + $this->assertEquals('This is a start command!', $item->getDescription()); + } + + /** + * @param BotCommand $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/CallbackQueryTest.php b/tests/Types/CallbackQueryTest.php index 2e82b5b2..250af482 100644 --- a/tests/Types/CallbackQueryTest.php +++ b/tests/Types/CallbackQueryTest.php @@ -2,136 +2,64 @@ namespace TelegramBot\Api\Test\Types; +use TelegramBot\Api\Test\AbstractTypeTest; use TelegramBot\Api\Types\CallbackQuery; -use TelegramBot\Api\Types\Message; -use TelegramBot\Api\Types\User; -class CallbackQueryTest extends \PHPUnit_Framework_TestCase +class CallbackQueryTest extends AbstractTypeTest { - protected $callbackQueryFixture = [ - 'id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - ], - 'inline_message_id' => 1234, - 'chat_instance' => 123, - 'data' => 'callback_data', - 'game_short_name' => 'game_name' - ]; - - public function testFromResponse() - { - $item = CallbackQuery::fromResponse($this->callbackQueryFixture); - - $user = User::fromResponse($this->callbackQueryFixture['from']); - - $this->assertInstanceOf('\TelegramBot\Api\Types\CallbackQuery', $item); - $this->assertEquals($this->callbackQueryFixture['id'], $item->getId()); - $this->assertEquals($user, $item->getFrom()); - $this->assertEquals($this->callbackQueryFixture['inline_message_id'], $item->getInlineMessageId()); - $this->assertEquals($this->callbackQueryFixture['chat_instance'], $item->getChatInstance()); - $this->assertEquals($this->callbackQueryFixture['data'], $item->getData()); - $this->assertEquals($this->callbackQueryFixture['game_short_name'], $item->getGameShortName()); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseExceptionEmptyId() { - unset($this->callbackQueryFixture['id']); - CallbackQuery::fromResponse($this->callbackQueryFixture); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseExceptionEmptyFrom() { - unset($this->callbackQueryFixture['from']); - CallbackQuery::fromResponse($this->callbackQueryFixture); - } - - public function testSetId() + protected static function getType() { - $item = new CallbackQuery(); - $item->setId($this->callbackQueryFixture['id']); - $this->assertAttributeEquals($this->callbackQueryFixture['id'], 'id', $item); + return CallbackQuery::class; } - public function testGetId() + public static function getMinResponse() { - $item = new CallbackQuery(); - $item->setId($this->callbackQueryFixture['id']); - $this->assertEquals($this->callbackQueryFixture['id'], $item->getId()); + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + ]; } - public function testSetFrom() + public static function getFullResponse() { - $item = new CallbackQuery(); - $user = User::fromResponse($this->callbackQueryFixture['from']); - $item->setFrom($user); - $this->assertAttributeEquals($user, 'from', $item); + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + 'message' => MessageTest::getMinResponse(), + 'inline_message_id' => 'inline_message_id', + 'chat_instance' => 'chat_instance', + 'data' => 'data', + 'game_short_name' => 'game_short_name' + ]; } - public function testGetFrom() { - $item = new CallbackQuery(); - $user = User::fromResponse($this->callbackQueryFixture['from']); - $item->setFrom($user); - $this->assertEquals($user, $item->getFrom()); - } - - public function testSetInlineMessageId() - { - $item = new CallbackQuery(); - $item->setInlineMessageId($this->callbackQueryFixture['inline_message_id']); - $this->assertAttributeEquals($this->callbackQueryFixture['inline_message_id'], 'inlineMessageId', $item); - } - - public function testGetInlineMessageId() { - $item = new CallbackQuery(); - $item->setInlineMessageId('testInlineMessageId'); - $this->assertEquals('testInlineMessageId', $item->getInlineMessageId()); - } - - public function testSetChatInstance() - { - $item = new CallbackQuery(); - $item->setChatInstance($this->callbackQueryFixture['chat_instance']); - $this->assertAttributeEquals($this->callbackQueryFixture['chat_instance'], 'chatInstance', $item); - } - - public function testGetChatInstance() { - $item = new CallbackQuery(); - $item->setChatInstance('testChatInstance'); - $this->assertEquals('testChatInstance', $item->getChatInstance()); - } - - public function testSetData() + /** + * @param CallbackQuery $item + * @return void + */ + protected function assertMinItem($item) { - $item = new CallbackQuery(); - $item->setData($this->callbackQueryFixture['data']); - $this->assertAttributeEquals($this->callbackQueryFixture['data'], 'data', $item); - } - - public function testGetData() { - $item = new CallbackQuery(); - $item->setData('testData'); - $this->assertEquals('testData', $item->getData()); + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertNull($item->getMessage()); + $this->assertNull($item->getInlineMessageId()); + $this->assertNull($item->getChatInstance()); + $this->assertNull($item->getData()); + $this->assertNull($item->getGameShortName()); } - public function testSetGameShortName() + /** + * @param CallbackQuery $item + * @return void + */ + protected function assertFullItem($item) { - $item = new CallbackQuery(); - $item->setGameShortName($this->callbackQueryFixture['game_short_name']); - $this->assertAttributeEquals($this->callbackQueryFixture['game_short_name'], 'gameShortName', $item); - } - - public function testGetGameShortName() { - $item = new CallbackQuery(); - $item->setGameShortName('testGameShortName'); - $this->assertEquals('testGameShortName', $item->getGameShortName()); + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getMessage()); + $this->assertEquals('inline_message_id', $item->getInlineMessageId()); + $this->assertEquals('chat_instance', $item->getChatInstance()); + $this->assertEquals('data', $item->getData()); + $this->assertEquals('game_short_name', $item->getGameShortName()); } - } diff --git a/tests/Types/ChatBoostRemovedTest.php b/tests/Types/ChatBoostRemovedTest.php new file mode 100644 index 00000000..1fb18e80 --- /dev/null +++ b/tests/Types/ChatBoostRemovedTest.php @@ -0,0 +1,50 @@ + ChatTest::getMinResponse(), + 'boost_id' => 1, + 'remove_date' => 1682343643, + 'source' => ChatBoostSourceTest::getMinResponse() + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'boost_id' => 1, + 'remove_date' => 1682343643, + 'source' => ChatBoostSourceTest::getMinResponse() + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getBoostId()); + $this->assertEquals(1682343643, $item->getRemoveDate()); + $this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getBoostId()); + $this->assertEquals(1682343643, $item->getRemoveDate()); + $this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource()); + } +} diff --git a/tests/Types/ChatBoostSourceTest.php b/tests/Types/ChatBoostSourceTest.php new file mode 100644 index 00000000..35e21646 --- /dev/null +++ b/tests/Types/ChatBoostSourceTest.php @@ -0,0 +1,42 @@ + 'premium', + 'user' => UserTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'source' => 'premium', + 'user' => UserTest::getMinResponse(), + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('premium', $item->getSource()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('premium', $item->getSource()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + } +} diff --git a/tests/Types/ChatBoostTest.php b/tests/Types/ChatBoostTest.php new file mode 100644 index 00000000..2a8fa88f --- /dev/null +++ b/tests/Types/ChatBoostTest.php @@ -0,0 +1,50 @@ + 1, + 'add_date' => 1682343643, + 'expiration_date' => 1725042370, + 'source' => ChatBoostSourceTest::getMinResponse() + ]; + } + + public static function getFullResponse() + { + return [ + 'boost_id' => 1, + 'add_date' => 1682343643, + 'expiration_date' => 1725042370, + 'source' => ChatBoostSourceTest::getMinResponse() + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getBoostId()); + $this->assertEquals(1682343643, $item->getAddDate()); + $this->assertEquals(1725042370, $item->getExpirationDate()); + $this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getBoostId()); + $this->assertEquals(1682343643, $item->getAddDate()); + $this->assertEquals(1725042370, $item->getExpirationDate()); + $this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource()); + } +} diff --git a/tests/Types/ChatBoostUpdatedTest.php b/tests/Types/ChatBoostUpdatedTest.php new file mode 100644 index 00000000..1dc8bb74 --- /dev/null +++ b/tests/Types/ChatBoostUpdatedTest.php @@ -0,0 +1,42 @@ + ChatTest::getMinResponse(), + 'boost' => ChatBoostTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'boost' => ChatBoostTest::getMinResponse(), + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(ChatBoostTest::createMinInstance(), $item->getBoost()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(ChatBoostTest::createMinInstance(), $item->getBoost()); + } +} diff --git a/tests/Types/ChatInviteLinkTest.php b/tests/Types/ChatInviteLinkTest.php new file mode 100644 index 00000000..459d62bd --- /dev/null +++ b/tests/Types/ChatInviteLinkTest.php @@ -0,0 +1,74 @@ + 'invite_link', + 'creator' => UserTest::getMinResponse(), + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + ]; + } + + public static function getFullResponse() + { + return [ + 'invite_link' => 'invite_link', + 'creator' => UserTest::getMinResponse(), + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + 'name' => 'name', + 'expire_date' => 100500, + 'member_limit' => 10, + 'pending_join_request_count' => 10, + ]; + } + + /** + * @param ChatInviteLink $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('invite_link', $item->getInviteLink()); + $this->assertEquals(UserTest::createMinInstance(), $item->getCreator()); + $this->assertTrue($item->getCreatesJoinRequest()); + $this->assertTrue($item->isPrimary()); + $this->assertTrue($item->isRevoked()); + $this->assertNull($item->getName()); + $this->assertNull($item->getExpireDate()); + $this->assertNull($item->getMemberLimit()); + $this->assertNull($item->getPendingJoinRequestCount()); + } + + /** + * @param ChatInviteLink $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('invite_link', $item->getInviteLink()); + $this->assertEquals(UserTest::createMinInstance(), $item->getCreator()); + $this->assertTrue($item->getCreatesJoinRequest()); + $this->assertTrue($item->isPrimary()); + $this->assertTrue($item->isRevoked()); + $this->assertEquals('name', $item->getName()); + $this->assertEquals(100500, $item->getExpireDate()); + $this->assertEquals(10, $item->getMemberLimit()); + $this->assertEquals(10, $item->getPendingJoinRequestCount()); + } +} diff --git a/tests/Types/ChatJoinRequestTest.php b/tests/Types/ChatJoinRequestTest.php new file mode 100644 index 00000000..faaa52fe --- /dev/null +++ b/tests/Types/ChatJoinRequestTest.php @@ -0,0 +1,64 @@ + ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'user_chat_id' => 10, + 'date' => 100500, + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'user_chat_id' => 10, + 'date' => 100500, + 'bio' => 'bio', + 'invite_link' => ChatInviteLinkTest::getMinResponse(), + ]; + } + + /** + * @param ChatJoinRequest $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(10, $item->getUserChatId()); + $this->assertEquals(100500, $item->getDate()); + $this->assertNull($item->getBio()); + $this->assertNull($item->getInviteLink()); + } + + /** + * @param ChatJoinRequest $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(10, $item->getUserChatId()); + $this->assertEquals(100500, $item->getDate()); + $this->assertEquals('bio', $item->getBio()); + $this->assertEquals(ChatInviteLinkTest::createMinInstance(), $item->getInviteLink()); + } +} diff --git a/tests/Types/ChatLocationTest.php b/tests/Types/ChatLocationTest.php new file mode 100644 index 00000000..e5d626a4 --- /dev/null +++ b/tests/Types/ChatLocationTest.php @@ -0,0 +1,46 @@ + LocationTest::getMinResponse(), + 'address' => 'Wall St. 123' + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ChatLocation $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertEquals('Wall St. 123', $item->getAddress()); + } + + /** + * @param ChatLocation $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/ChatPermissionsTest.php b/tests/Types/ChatPermissionsTest.php new file mode 100644 index 00000000..9e99ca5f --- /dev/null +++ b/tests/Types/ChatPermissionsTest.php @@ -0,0 +1,65 @@ + true, + 'can_send_media_messages' => true, + 'can_send_polls' => true, + 'can_send_other_messages' => true, + 'can_add_web_page_previews' => true, + 'can_change_info' => true, + 'can_invite_users' => true, + 'can_pin_messages' => true, + ]; + } + + /** + * @param ChatPermissions $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertNull($item->isCanSendMessages()); + $this->assertNull($item->isCanSendMediaMessages()); + $this->assertNull($item->isCanSendPolls()); + $this->assertNull($item->isCanSendOtherMessages()); + $this->assertNull($item->isCanAddWebPagePreviews()); + $this->assertNull($item->isCanChangeInfo()); + $this->assertNull($item->isCanInviteUsers()); + $this->assertNull($item->isCanPinMessages()); + } + + /** + * @param ChatPermissions $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertTrue($item->isCanSendMessages()); + $this->assertTrue($item->isCanSendMediaMessages()); + $this->assertTrue($item->isCanSendPolls()); + $this->assertTrue($item->isCanSendOtherMessages()); + $this->assertTrue($item->isCanAddWebPagePreviews()); + $this->assertTrue($item->isCanChangeInfo()); + $this->assertTrue($item->isCanInviteUsers()); + $this->assertTrue($item->isCanPinMessages()); + } +} diff --git a/tests/Types/ChatPhotoTest.php b/tests/Types/ChatPhotoTest.php new file mode 100644 index 00000000..3557ee90 --- /dev/null +++ b/tests/Types/ChatPhotoTest.php @@ -0,0 +1,46 @@ + 'small_file_id', + 'big_file_id' => 'big_file_id', + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ChatPhoto $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('small_file_id', $item->getSmallFileId()); + $this->assertEquals('big_file_id', $item->getBigFileId()); + } + + /** + * @param ChatPhoto $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/ChatTest.php b/tests/Types/ChatTest.php new file mode 100644 index 00000000..54ab521c --- /dev/null +++ b/tests/Types/ChatTest.php @@ -0,0 +1,128 @@ + 123456, + 'type' => 'private', + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 123456, + 'type' => 'private', + 'title' => 'title', + 'username' => 'iGusev', + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'photo' => ChatPhotoTest::getMinResponse(), + 'bio' => 'PHP Telegram Bot API', + 'description' => 'description', + 'invite_link' => 'invite_link', + 'pinned_message' => MessageTest::getMinResponse(), + 'permissions' => ChatPermissionsTest::getFullResponse(), + 'slow_mode_delay' => 10, + 'sticker_set_name' => 'sticker_set_name', + 'can_set_sticker_set' => true, + 'linked_chat_id' => 2, + 'location' => ChatLocationTest::getMinResponse(), + 'join_to_send_messages' => true, + 'join_by_request' => true, + 'message_auto_delete_time' => 10000, + 'has_protected_content' => true, + 'is_forum' => true, + 'active_usernames' => [ + 'username', + ], + 'emoji_status_custom_emoji_id' => 'emoji_status_custom_emoji_id', + 'has_private_forwards' => true, + 'has_restricted_voice_and_video_messages' => true, + ]; + } + + /** + * @param Chat $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(123456, $item->getId()); + $this->assertEquals('private', $item->getType()); + + $this->assertNull($item->getTitle()); + $this->assertNull($item->getFirstName()); + $this->assertNull($item->getLastName()); + $this->assertNull($item->getUsername()); + $this->assertNull($item->getIsForum()); + } + + /** + * @param Chat $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(123456, $item->getId()); + $this->assertEquals('private', $item->getType()); + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('Ilya', $item->getFirstName()); + $this->assertEquals('Gusev', $item->getLastName()); + $this->assertEquals('iGusev', $item->getUsername()); + } + + public function testSet64bitId() + { + $chat = new Chat(); + $chat->setId(2147483648); + $this->assertEquals(2147483648, $chat->getId()); + } + + public function testSetIdException1() + { + $this->expectException(InvalidArgumentException::class); + + $chat = new Chat(); + $chat->setId([]); + } + + public function testSetIdException2() + { + $this->expectException(InvalidArgumentException::class); + + $chat = new Chat(); + $chat->setId(null); + } + + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + + Chat::fromResponse([ + 'id' => 1 + ]); + } + + public function testFromResponseException3() + { + $this->expectException(InvalidArgumentException::class); + + Chat::fromResponse([ + 'type' => 'private' + ]); + } +} diff --git a/tests/Types/ContactTest.php b/tests/Types/ContactTest.php new file mode 100644 index 00000000..a8a19516 --- /dev/null +++ b/tests/Types/ContactTest.php @@ -0,0 +1,59 @@ + 'Ilya', + 'phone_number' => '123456', + ]; + } + + public static function getFullResponse() + { + return [ + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'phone_number' => '123456', + 'user_id' => 'iGusev', + 'vcard' => 'vcard', + ]; + } + + /** + * @param Contact $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('123456', $item->getPhoneNumber()); + $this->assertEquals('Ilya', $item->getFirstName()); + $this->assertNull($item->getLastName()); + $this->assertNull($item->getUserId()); + $this->assertNull($item->getVCard()); + } + + /** + * @param Contact $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('123456', $item->getPhoneNumber()); + $this->assertEquals('Ilya', $item->getFirstName()); + $this->assertEquals('Gusev', $item->getLastName()); + $this->assertEquals('iGusev', $item->getUserId()); + $this->assertEquals('vcard', $item->getVCard()); + } +} diff --git a/tests/Types/DiceTest.php b/tests/Types/DiceTest.php new file mode 100644 index 00000000..05cd250a --- /dev/null +++ b/tests/Types/DiceTest.php @@ -0,0 +1,46 @@ + '🎉', + 'value' => 5 + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param Dice $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('🎉', $item->getEmoji()); + $this->assertEquals(5, $item->getValue()); + } + + /** + * @param Dice $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/DocumentTest.php b/tests/Types/DocumentTest.php new file mode 100644 index 00000000..a0734669 --- /dev/null +++ b/tests/Types/DocumentTest.php @@ -0,0 +1,92 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'file_name' => 'testFileName', + 'mime_type' => 'audio/mp3', + 'file_size' => 3, + 'thumbnail' => PhotoSizeTest::getMinResponse(), + ]; + } + + /** + * @param Document $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertNull($item->getFileName()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + $this->assertNull($item->getThumbnail()); + } + + /** + * @param Document $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals('testFileName', $item->getFileName()); + $this->assertEquals('audio/mp3', $item->getMimeType()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Document(); + $item->setFileSize('s'); + } + + /** + * file_id and file_unique_id are required + */ + public function testFromResponseException1() + { + $this->expectException(InvalidArgumentException::class); + + Document::fromResponse([ + 'file_name' => 'testFileName', + 'mime_type' => 'audio/mp3', + 'file_size' => 3, + 'thumbnail' => [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 5, + 'height' => 6, + 'file_size' => 7 + ] + ]); + } +} diff --git a/tests/Types/FileTest.php b/tests/Types/FileTest.php new file mode 100644 index 00000000..55c4f7c6 --- /dev/null +++ b/tests/Types/FileTest.php @@ -0,0 +1,75 @@ + 'testFileId1', + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'file_unique_id', + 'file_size' => 3, + 'file_path' => 'testfilepath' + ]; + } + + /** + * @param File $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertNull($item->getFileUniqueId()); + $this->assertNull($item->getFileSize()); + $this->assertNull($item->getFilePath()); + } + + /** + * @param File $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals('testfilepath', $item->getFilePath()); + } + + public function testFromResponseException() + { + $this->expectException(InvalidArgumentException::class); + + File::fromResponse([ + 'file_size' => 3, + 'file_path' => 'testfilepath' + ]); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new File(); + $item->setFileSize('s'); + } + +} diff --git a/tests/Types/ForceReplyTest.php b/tests/Types/ForceReplyTest.php new file mode 100644 index 00000000..0215c3d8 --- /dev/null +++ b/tests/Types/ForceReplyTest.php @@ -0,0 +1,134 @@ + true, + ]; + } + + public static function getFullResponse() + { + return [ + 'force_reply' => true, + 'input_field_placeholder' => 'input_field_placeholder', + 'selective' => true + ]; + } + + /** + * @param ForceReply $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); + } + + /** + * @param ForceReply $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(true, $item->isSelective()); + $this->assertEquals('input_field_placeholder', $item->getInputFieldPlaceholder()); + } + + public function testConstructor() + { + $item = new ForceReply(); + + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); + } + + public function testConstructor2() + { + $item = new ForceReply(true, true); + + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); + } + + public function testConstructor3() + { + $item = new ForceReply(false, true); + + $this->assertEquals(false, $item->isForceReply()); + $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); + } + + public function testConstructor4() + { + $item = new ForceReply(true); + + $this->assertEquals(true, $item->isForceReply()); + $this->assertEquals(null, $item->isSelective()); + $this->assertEquals(null, $item->getInputFieldPlaceholder()); + } + + public function testSetforceReply() + { + $item = new ForceReply(true); + + $item->setForceReply(false); + + $this->assertEquals(false, $item->isforceReply()); + } + + public function testSetSelective() + { + $item = new ForceReply(); + + $item->setSelective(true); + + $this->assertEquals(true, $item->isSelective()); + } + + public function testToJson() + { + $item = new ForceReply(); + + $this->assertEquals(json_encode(['force_reply' => true]), $item->toJson()); + } + + public function testToJson2() + { + $item = new ForceReply(); + + $this->assertEquals(['force_reply' => true], $item->toJson(true)); + } + + public function testToJson3() + { + $item = new ForceReply(true, true); + + $this->assertEquals(json_encode(['force_reply' => true, 'selective' => true]), $item->toJson()); + } + + public function testToJson4() + { + $item = new ForceReply(true, true); + + $this->assertEquals(['force_reply' => true, 'selective' => true], $item->toJson(true)); + } +} diff --git a/tests/Types/ForumTopicClosedTest.php b/tests/Types/ForumTopicClosedTest.php new file mode 100644 index 00000000..629e356c --- /dev/null +++ b/tests/Types/ForumTopicClosedTest.php @@ -0,0 +1,40 @@ + 'name', + 'icon_color' => 2, + ]; + } + + public static function getFullResponse() + { + return [ + 'name' => 'name', + 'icon_color' => 2, + 'icon_custom_emoji_id' => 'icon_custom_emoji_id', + ]; + } + + /** + * @param ForumTopicCreated $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals(2, $item->getIconColor()); + $this->assertNull($item->getIconCustomEmojiId()); + } + + /** + * @param ForumTopicCreated $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals(2, $item->getIconColor()); + $this->assertEquals('icon_custom_emoji_id', $item->getIconCustomEmojiId()); + } +} diff --git a/tests/Types/ForumTopicReopenedTest.php b/tests/Types/ForumTopicReopenedTest.php new file mode 100644 index 00000000..be9625cf --- /dev/null +++ b/tests/Types/ForumTopicReopenedTest.php @@ -0,0 +1,40 @@ + 1, + 'name' => 'name', + 'icon_color' => 2, + ]; + } + + public static function getFullResponse() + { + return [ + 'message_thread_id' => 1, + 'name' => 'name', + 'icon_color' => 2, + 'icon_custom_emoji_id' => 'icon_custom_emoji_id', + ]; + } + + /** + * @param ForumTopic $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getMessageThreadId()); + $this->assertEquals('name', $item->getName()); + $this->assertEquals(2, $item->getIconColor()); + $this->assertNull($item->getIconCustomEmojiId()); + } + + /** + * @param ForumTopic $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getMessageThreadId()); + $this->assertEquals('name', $item->getName()); + $this->assertEquals(2, $item->getIconColor()); + $this->assertEquals('icon_custom_emoji_id', $item->getIconCustomEmojiId()); + } +} diff --git a/tests/Types/GiftInfoTest.php b/tests/Types/GiftInfoTest.php new file mode 100644 index 00000000..e69d936e --- /dev/null +++ b/tests/Types/GiftInfoTest.php @@ -0,0 +1,59 @@ + GiftTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'gift' => GiftTest::getMinResponse(), + 'owned_gift_id' => 'id', + 'convert_star_count' => 1, + 'prepaid_upgrade_star_count' => 2, + 'can_be_upgraded' => true, + 'text' => 'hi', + 'entities' => [MessageEntityTest::getMinResponse()], + 'is_private' => true, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(GiftTest::createMinInstance(), $item->getGift()); + $this->assertNull($item->getOwnedGiftId()); + $this->assertNull($item->getConvertStarCount()); + $this->assertNull($item->getPrepaidUpgradeStarCount()); + $this->assertNull($item->getCanBeUpgraded()); + $this->assertNull($item->getText()); + $this->assertNull($item->getEntities()); + $this->assertNull($item->getIsPrivate()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(GiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('id', $item->getOwnedGiftId()); + $this->assertEquals(1, $item->getConvertStarCount()); + $this->assertEquals(2, $item->getPrepaidUpgradeStarCount()); + $this->assertTrue($item->getCanBeUpgraded()); + $this->assertEquals('hi', $item->getText()); + $this->assertEquals([MessageEntityTest::createMinInstance()], $item->getEntities()); + $this->assertTrue($item->getIsPrivate()); + } +} diff --git a/tests/Types/GiftTest.php b/tests/Types/GiftTest.php new file mode 100644 index 00000000..416f0078 --- /dev/null +++ b/tests/Types/GiftTest.php @@ -0,0 +1,55 @@ + 'gift1', + 'sticker' => StickerTest::getMinResponse(), + 'star_count' => 10, + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 'gift1', + 'sticker' => StickerTest::getMinResponse(), + 'star_count' => 10, + 'upgrade_star_count' => 5, + 'total_count' => 100, + 'remaining_count' => 50, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('gift1', $item->getId()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(10, $item->getStarCount()); + $this->assertNull($item->getUpgradeStarCount()); + $this->assertNull($item->getTotalCount()); + $this->assertNull($item->getRemainingCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('gift1', $item->getId()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(10, $item->getStarCount()); + $this->assertEquals(5, $item->getUpgradeStarCount()); + $this->assertEquals(100, $item->getTotalCount()); + $this->assertEquals(50, $item->getRemainingCount()); + } +} diff --git a/tests/Types/GiftsTest.php b/tests/Types/GiftsTest.php new file mode 100644 index 00000000..5944bb60 --- /dev/null +++ b/tests/Types/GiftsTest.php @@ -0,0 +1,44 @@ + [ + GiftTest::getMinResponse(), + ], + ]; + } + + public static function getFullResponse() + { + return [ + 'gifts' => [ + GiftTest::getFullResponse(), + ], + ]; + } + + protected function assertMinItem($item) + { + $this->assertIsArray($item->getGifts()); + $this->assertEquals([GiftTest::createMinInstance()], $item->getGifts()); + } + + protected function assertFullItem($item) + { + $this->assertIsArray($item->getGifts()); + $this->assertEquals([GiftTest::createFullInstance()], $item->getGifts()); + } +} diff --git a/tests/Types/GiveawayCompletedTest.php b/tests/Types/GiveawayCompletedTest.php new file mode 100644 index 00000000..633b6127 --- /dev/null +++ b/tests/Types/GiveawayCompletedTest.php @@ -0,0 +1,42 @@ + 1 + ]; + } + + public static function getFullResponse() + { + return [ + 'winner_count' => 1, + 'unclaimed_prize_count' => 1, + 'giveaway_message' => MessageTest::getMinResponse() + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getWinnerCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals(1, $item->getUnclaimedPrizeCount()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getGiveawayMessage()); + } +} diff --git a/tests/Types/GiveawayCreatedTest.php b/tests/Types/GiveawayCreatedTest.php new file mode 100644 index 00000000..90e948ff --- /dev/null +++ b/tests/Types/GiveawayCreatedTest.php @@ -0,0 +1,32 @@ + [ + ChatTest::getMinResponse() + ], + 'winners_selection_date' => 1682343643, + 'winner_count' => 1, + ]; + } + + public static function getFullResponse() + { + return [ + 'chats' => [ + ChatTest::getMinResponse() + ], + 'winners_selection_date' => 1682343643, + 'winner_count' => 1, + 'only_new_members' => true, + 'has_public_winners' => true, + 'prize_description' => 'prize', + 'country_codes' => ['RU'], + 'premium_subscription_month_count' => 1, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals(1682343643, $item->getWinnersSelectionDate()); + $this->assertIsArray($item->getChats()); + + $this->assertNull($item->getOnlyNewMembers()); + $this->assertNull($item->getHasPublicWinners()); + $this->assertNull($item->getPrizeDescription()); + $this->assertNull($item->getCountryCodes()); + $this->assertNull($item->getPremiumSubscriptionMonthCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals(1682343643, $item->getWinnersSelectionDate()); + $this->assertIsArray($item->getChats()); + $this->assertTrue($item->getOnlyNewMembers()); + $this->assertTrue($item->getHasPublicWinners()); + $this->assertEquals('prize', $item->getPrizeDescription()); + $this->assertIsArray($item->getCountryCodes()); + $this->assertEquals(1, $item->getPremiumSubscriptionMonthCount()); + } +} diff --git a/tests/Types/GiveawayWinnersTest.php b/tests/Types/GiveawayWinnersTest.php new file mode 100644 index 00000000..aac8e408 --- /dev/null +++ b/tests/Types/GiveawayWinnersTest.php @@ -0,0 +1,74 @@ + ChatTest::getMinResponse(), + 'giveaway_message_id' => 1, + 'winners_selection_date' => 1682343643, + 'winner_count' => 1, + 'winners' => [ + UserTest::getMinResponse() + ], + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'giveaway_message_id' => 1, + 'winners_selection_date' => 1682343643, + 'winner_count' => 1, + 'winners' => [ + UserTest::getMinResponse() + ], + 'additional_chat_count' => 1, + 'premium_subscription_month_count' => 1, + 'unclaimed_prize_count' => 0, + 'only_new_members' => true, + 'was_refunded' => true, + 'prize_description' => 'prize', + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getGiveawayMessageId()); + $this->assertEquals(1682343643, $item->getWinnersSelectionDate()); + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals([UserTest::createMinInstance()], $item->getWinners()); + $this->assertNull($item->getAdditionalChatCount()); + $this->assertNull($item->getPremiumSubscriptionMonthCount()); + $this->assertNull($item->getUnclaimedPrizeCount()); + $this->assertNull($item->getOnlyNewMembers()); + $this->assertNull($item->getWasRefunded()); + $this->assertNull($item->getPrizeDescription()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getGiveawayMessageId()); + $this->assertEquals(1682343643, $item->getWinnersSelectionDate()); + $this->assertEquals(1, $item->getWinnerCount()); + $this->assertEquals([UserTest::createMinInstance()], $item->getWinners()); + $this->assertEquals(1, $item->getAdditionalChatCount()); + $this->assertEquals(1, $item->getPremiumSubscriptionMonthCount()); + $this->assertEquals(0, $item->getUnclaimedPrizeCount()); + $this->assertTrue($item->getOnlyNewMembers()); + $this->assertTrue($item->getWasRefunded()); + $this->assertEquals('prize', $item->getPrizeDescription()); + } +} diff --git a/tests/Types/Inline/ChosenInlineResultTest.php b/tests/Types/Inline/ChosenInlineResultTest.php index 180e71cb..915e93cd 100644 --- a/tests/Types/Inline/ChosenInlineResultTest.php +++ b/tests/Types/Inline/ChosenInlineResultTest.php @@ -2,95 +2,61 @@ namespace TelegramBot\Api\Test\Types\Inline; +use TelegramBot\Api\Test\AbstractTypeTest; +use TelegramBot\Api\Test\Types\LocationTest; +use TelegramBot\Api\Test\Types\UserTest; use TelegramBot\Api\Types\Inline\ChosenInlineResult; -use TelegramBot\Api\Types\User; -class ChosenInlineResultTest extends \PHPUnit_Framework_TestCase +class ChosenInlineResultTest extends AbstractTypeTest { - protected $chosenInlineResultFixture = [ - 'result_id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - ], - 'query' => 'test_query' - ]; - - public function testFromResponse() + protected static function getType() { - $item = ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); - - $user = User::fromResponse($this->chosenInlineResultFixture['from']); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Inline\ChosenInlineResult', $item); - $this->assertEquals($this->chosenInlineResultFixture['result_id'], $item->getResultId()); - $this->assertEquals($user, $item->getFrom()); - $this->assertEquals($this->chosenInlineResultFixture['query'], $item->getQuery()); + return ChosenInlineResult::class; } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException1() { - unset($this->chosenInlineResultFixture['result_id']); - ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); + public static function getMinResponse() + { + return [ + 'result_id' => 1, + 'from' => UserTest::getMinResponse(), + 'query' => 'test_query', + ]; } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() { - unset($this->chosenInlineResultFixture['from']); - ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); + public static function getFullResponse() + { + return [ + 'result_id' => 1, + 'from' => UserTest::getMinResponse(), + 'query' => 'test_query', + 'location' => LocationTest::getMinResponse(), + 'inline_message_id' => 'inline_message_id', + ]; } /** - * @expectedException \TelegramBot\Api\InvalidArgumentException + * @param ChosenInlineResult $item + * @return void */ - public function testFromResponseException3() { - unset($this->chosenInlineResultFixture['query']); - ChosenInlineResult::fromResponse($this->chosenInlineResultFixture); - } - - public function testSetResultId() + protected function assertMinItem($item) { - $item = new ChosenInlineResult(); - $item->setResultId($this->chosenInlineResultFixture['result_id']); - $this->assertAttributeEquals($this->chosenInlineResultFixture['result_id'], 'resultId', $item); + $this->assertEquals(1, $item->getResultId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('test_query', $item->getQuery()); + $this->assertNull($item->getLocation()); + $this->assertNull($item->getInlineMessageId()); } - public function testGetResultId() + /** + * @param ChosenInlineResult $item + * @return void + */ + protected function assertFullItem($item) { - $item = new ChosenInlineResult(); - $item->setResultId($this->chosenInlineResultFixture['result_id']); - $this->assertEquals($this->chosenInlineResultFixture['result_id'], $item->getResultId()); - } - - public function testSetFrom() { - $item = new ChosenInlineResult(); - $user = User::fromResponse($this->chosenInlineResultFixture['from']); - $item->setFrom($user); - $this->assertAttributeEquals($user, 'from', $item); - } - - public function testGetFrom() { - $item = new ChosenInlineResult(); - $user = User::fromResponse($this->chosenInlineResultFixture['from']); - $item->setFrom($user); - $this->assertEquals($user, $item->getFrom()); - } - - public function testSetQuery() { - $item = new ChosenInlineResult(); - $item->setQuery('testQuery'); - $this->assertAttributeEquals('testQuery', 'query', $item); - } - - public function testGetQuery() { - $item = new ChosenInlineResult(); - $item->setQuery('testQuery'); - $this->assertEquals('testQuery', $item->getQuery()); + $this->assertEquals(1, $item->getResultId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('test_query', $item->getQuery()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertEquals('inline_message_id', $item->getInlineMessageId()); } } diff --git a/tests/Types/Inline/InlineKeyboardMarkupTest.php b/tests/Types/Inline/InlineKeyboardMarkupTest.php index 0eb05a09..bfe32d1e 100644 --- a/tests/Types/Inline/InlineKeyboardMarkupTest.php +++ b/tests/Types/Inline/InlineKeyboardMarkupTest.php @@ -2,27 +2,59 @@ namespace TelegramBot\Api\Test\Types\Inline; +use TelegramBot\Api\Test\AbstractTypeTest; use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup; -class InlineKeyboardMarkupTest extends \PHPUnit_Framework_TestCase +class InlineKeyboardMarkupTest extends AbstractTypeTest { + protected static function getType() + { + return InlineKeyboardMarkup::class; + } - public function testConstructor() + public static function getMinResponse() { - $item = new InlineKeyboardMarkup([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]]); + return [ + 'inline_keyboard' => [ + [ + ['url' => 'http://test.com', 'text' => 'Link'], + ['url' => 'http://test.com', 'text' => 'Link'], + ], + ], + ]; + } - $this->assertAttributeEquals([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]], 'inlineKeyboard', $item); + public static function getFullResponse() + { + return static::getMinResponse(); } - public function testSetInlineKeyboard() + /** + * @param InlineKeyboardMarkup $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]], $item->getInlineKeyboard()); + } + + /** + * @param InlineKeyboardMarkup $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } + + public function testConstructor() { $item = new InlineKeyboardMarkup([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]]); - $item->setInlineKeyboard([[['url' => 'http://test.com', 'text' => 'Link']]]); - $this->assertAttributeEquals([[['url' => 'http://test.com', 'text' => 'Link']]], 'inlineKeyboard', $item); + $this->assertEquals([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]], $item->getInlineKeyboard()); } - public function testGetInlineKeyboard() + public function testSetInlineKeyboard() { $item = new InlineKeyboardMarkup([[['url' => 'http://test.com', 'text' => 'Link'], ['url' => 'http://test.com', 'text' => 'Link']]]); $item->setInlineKeyboard([[['url' => 'http://test.com', 'text' => 'Link']]]); diff --git a/tests/Types/Inline/InlineQueryTest.php b/tests/Types/Inline/InlineQueryTest.php index fa1d5f7e..4256fe8e 100644 --- a/tests/Types/Inline/InlineQueryTest.php +++ b/tests/Types/Inline/InlineQueryTest.php @@ -2,129 +2,62 @@ namespace TelegramBot\Api\Test\Types\Inline; +use TelegramBot\Api\Test\AbstractTypeTest; +use TelegramBot\Api\Test\Types\LocationTest; +use TelegramBot\Api\Test\Types\UserTest; use TelegramBot\Api\Types\Inline\InlineQuery; -use TelegramBot\Api\Types\User; -class InlineQueryTest extends \PHPUnit_Framework_TestCase +class InlineQueryTest extends AbstractTypeTest { - protected $inlineQueryFixture = [ - 'id' => 1, - 'from' => [ - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev', - ], - 'query' => 'test_query', - 'offset' => '20' - ]; - - public function testFromResponse1() + protected static function getType() { - $item = InlineQuery::fromResponse($this->inlineQueryFixture); - - $user = User::fromResponse($this->inlineQueryFixture['from']); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Inline\InlineQuery', $item); - $this->assertEquals(1, $item->getId()); - $this->assertEquals($user, $item->getFrom()); - $this->assertEquals('20', $item->getOffset()); + return InlineQuery::class; } - - public function testFromResponse2() { - $this->inlineQueryFixture['offset'] = ''; - $item = InlineQuery::fromResponse($this->inlineQueryFixture); - - $user = User::fromResponse($this->inlineQueryFixture['from']); - - $this->assertInstanceOf('\TelegramBot\Api\Types\Inline\InlineQuery', $item); - $this->assertEquals(1, $item->getId()); - $this->assertEquals($user, $item->getFrom()); - $this->assertEquals('', $item->getOffset()); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException1() { - unset($this->inlineQueryFixture['id']); - InlineQuery::fromResponse($this->inlineQueryFixture); + public static function getMinResponse() + { + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + 'query' => 'test_query', + 'offset' => '20' + ]; } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() { - unset($this->inlineQueryFixture['from']); - InlineQuery::fromResponse($this->inlineQueryFixture); + public static function getFullResponse() + { + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + 'location' => LocationTest::getMinResponse(), + 'query' => 'test_query', + 'offset' => '20' + ]; } /** - * @expectedException \TelegramBot\Api\InvalidArgumentException + * @param InlineQuery $item + * @return void */ - public function testFromResponseException3() { - unset($this->inlineQueryFixture['query']); - InlineQuery::fromResponse($this->inlineQueryFixture); + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('test_query', $item->getQuery()); + $this->assertEquals('20', $item->getOffset()); + $this->assertNull($item->getLocation()); } /** - * @expectedException \TelegramBot\Api\InvalidArgumentException + * @param InlineQuery $item + * @return void */ - public function testFromResponseException4() { - unset($this->inlineQueryFixture['offset']); - InlineQuery::fromResponse($this->inlineQueryFixture); - } - - public function testSetId() - { - $item = new InlineQuery(); - $item->setId('testId'); - $this->assertAttributeEquals('testId', 'id', $item); - } - - public function testGetId() + protected function assertFullItem($item) { - $item = new InlineQuery(); - $item->setId('testId'); - $this->assertEquals('testId', $item->getId()); - } - - public function testSetFrom() { - $item = new InlineQuery(); - $user = User::fromResponse($this->inlineQueryFixture['from']); - $item->setFrom($user); - $this->assertAttributeEquals($user, 'from', $item); - } - - public function testGetFrom() { - $item = new InlineQuery(); - $user = User::fromResponse($this->inlineQueryFixture['from']); - $item->setFrom($user); - $this->assertEquals($user, $item->getFrom()); - } - - public function testSetQuery() { - $item = new InlineQuery(); - $item->setQuery('testQuery'); - $this->assertAttributeEquals('testQuery', 'query', $item); - } - - public function testGetQuery() { - $item = new InlineQuery(); - $item->setQuery('testQuery'); - $this->assertEquals('testQuery', $item->getQuery()); - } - - public function testSetOffset() { - $item = new InlineQuery(); - $item->setOffset('20'); - $this->assertAttributeEquals('20', 'offset', $item); - } - - public function testGetOffset() { - $item = new InlineQuery(); - $item->setOffset('20'); + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('test_query', $item->getQuery()); $this->assertEquals('20', $item->getOffset()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); } } diff --git a/tests/Types/LocationTest.php b/tests/Types/LocationTest.php new file mode 100644 index 00000000..28f6799a --- /dev/null +++ b/tests/Types/LocationTest.php @@ -0,0 +1,88 @@ + 55.585827, + 'longitude' => 37.675309, + ]; + } + + public static function getFullResponse() + { + return [ + 'latitude' => 55.585827, + 'longitude' => 37.675309, + 'horizontal_accuracy' => 20.5, + 'live_period' => 300, + 'heading' => 100, + 'proximity_alert_radius' => 15 + ]; + } + + /** + * @param Location $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(55.585827, $item->getLatitude()); + $this->assertEquals(37.675309, $item->getLongitude()); + $this->assertNull($item->getHorizontalAccuracy()); + $this->assertNull($item->getLivePeriod()); + $this->assertNull($item->getHeading()); + $this->assertNull($item->getProximityAlertRadius()); + } + + /** + * @param Location $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(55.585827, $item->getLatitude()); + $this->assertEquals(37.675309, $item->getLongitude()); + $this->assertEquals(20.5, $item->getHorizontalAccuracy()); + $this->assertEquals(300, $item->getLivePeriod()); + $this->assertEquals(100, $item->getHeading()); + $this->assertEquals(15, $item->getProximityAlertRadius()); + } + + public function testSetHorizontalAccuracyException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Location(); + $item->setHorizontalAccuracy('s'); + } + + public function testSetLatitudeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Location(); + $item->setLatitude('s'); + } + + public function testSetLongitudeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Location(); + $item->setLongitude('s'); + } + +} diff --git a/tests/Types/LoginUrlTest.php b/tests/Types/LoginUrlTest.php new file mode 100644 index 00000000..7cc00bf0 --- /dev/null +++ b/tests/Types/LoginUrlTest.php @@ -0,0 +1,55 @@ + 'https://telegram.org', + ]; + } + + public static function getFullResponse() + { + return [ + 'url' => 'https://telegram.org', + 'forward_text' => 'Log in!', + 'bot_username' => 'TestBot', + 'request_write_access' => true + ]; + } + + /** + * @param LoginUrl $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('https://telegram.org', $item->getUrl()); + $this->assertNull($item->getForwardText()); + $this->assertNull($item->getBotUsername()); + $this->assertNull($item->isRequestWriteAccess()); + } + + /** + * @param LoginUrl $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('https://telegram.org', $item->getUrl()); + $this->assertEquals('Log in!', $item->getForwardText()); + $this->assertEquals('TestBot', $item->getBotUsername()); + $this->assertEquals(true, $item->isRequestWriteAccess()); + } +} diff --git a/tests/Types/MaskPositionTest.php b/tests/Types/MaskPositionTest.php new file mode 100644 index 00000000..3641c417 --- /dev/null +++ b/tests/Types/MaskPositionTest.php @@ -0,0 +1,50 @@ + 'mouth', + 'x_shift' => 1.0, + 'y_shift' => 1.0, + 'scale' => 2.0, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param MaskPosition $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('mouth', $item->getPoint()); + $this->assertEquals('1.0', $item->getXShift()); + $this->assertEquals('1.0', $item->getYShift()); + $this->assertEquals('2.0', $item->getScale()); + } + + /** + * @param MaskPosition $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/MessageEntityTest.php b/tests/Types/MessageEntityTest.php new file mode 100644 index 00000000..d3f4ed8e --- /dev/null +++ b/tests/Types/MessageEntityTest.php @@ -0,0 +1,84 @@ + 'text_mention', + 'offset' => 108, + 'length' => 10, + ]; + } + + public static function getFullResponse() + { + return [ + 'type' => 'text_mention', + 'offset' => 108, + 'length' => 10, + 'url' => 'url', + 'user' => UserTest::getMinResponse(), + 'language' => 'language', + 'custom_emoji_id' => 'custom_emoji_id', + ]; + } + + /** + * @param MessageEntity $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(MessageEntity::TYPE_TEXT_MENTION, $item->getType()); + $this->assertEquals(108, $item->getOffset()); + $this->assertEquals(10, $item->getLength()); + $this->assertNull($item->getUrl()); + $this->assertNull($item->getUser()); + $this->assertNull($item->getLanguage()); + $this->assertNull($item->getCustomEmojiId()); + } + + /** + * @param MessageEntity $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(MessageEntity::TYPE_TEXT_MENTION, $item->getType()); + $this->assertEquals(108, $item->getOffset()); + $this->assertEquals(10, $item->getLength()); + $this->assertEquals('url', $item->getUrl()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + $this->assertEquals('language', $item->getLanguage()); + $this->assertEquals('custom_emoji_id', $item->getCustomEmojiId()); + } + + public function testPreFromResponse() + { + $messageEntity = MessageEntity::fromResponse([ + 'type' => 'pre', + 'offset' => 16, + 'length' => 128, + 'language' => 'php', + ]); + + $this->assertInstanceOf(MessageEntity::class, $messageEntity); + $this->assertEquals(MessageEntity::TYPE_PRE, $messageEntity->getType()); + $this->assertEquals(16, $messageEntity->getOffset()); + $this->assertEquals(128, $messageEntity->getLength()); + $this->assertNull($messageEntity->getUrl()); + $this->assertNull($messageEntity->getUser()); + $this->assertEquals('php', $messageEntity->getLanguage()); + } +} diff --git a/tests/Types/MessageOriginChannelTest.php b/tests/Types/MessageOriginChannelTest.php new file mode 100644 index 00000000..c6c0db3b --- /dev/null +++ b/tests/Types/MessageOriginChannelTest.php @@ -0,0 +1,74 @@ + 'channel', + 'date' => 1640908800, + 'chat' => [ + 'id' => 123456, + 'type' => 'private', + ], + 'message_id' => 12345, + ]; + } + + public static function getFullResponse() + { + return [ + 'type' => 'channel', + 'date' => 1640908800, + 'chat' => [ + 'id' => 123456, + 'type' => 'private', + ], + 'message_id' => 12345, + 'author_signature' => 'John Doe', + ]; + } + + /** + * @param MessageOriginChannel $item + */ + protected function assertMinItem($item) + { + $this->assertEquals('channel', $item->getType()); + $this->assertEquals(1640908800, $item->getDate()); + $this->assertEquals(12345, $item->getMessageId()); + $this->assertNull($item->getAuthorSignature()); + + $chat = $item->getChat(); + $this->assertInstanceOf(Chat::class, $chat); + $this->assertEquals(123456, $chat->getId()); + $this->assertEquals('private', $chat->getType()); + } + + /** + * @param MessageOriginChannel $item + */ + protected function assertFullItem($item) + { + $this->assertEquals('channel', $item->getType()); + $this->assertEquals(1640908800, $item->getDate()); + $this->assertEquals(12345, $item->getMessageId()); + $this->assertEquals('John Doe', $item->getAuthorSignature()); + + $chat = $item->getChat(); + $this->assertInstanceOf(Chat::class, $chat); + $this->assertEquals(123456, $chat->getId()); + $this->assertEquals('private', $chat->getType()); + } +} diff --git a/tests/Types/MessageReactionCountUpdatedTest.php b/tests/Types/MessageReactionCountUpdatedTest.php new file mode 100644 index 00000000..5216c7ed --- /dev/null +++ b/tests/Types/MessageReactionCountUpdatedTest.php @@ -0,0 +1,54 @@ + ChatTest::getMinResponse(), + 'message_id' => 1, + 'date' => 1682343644, + 'reactions' => [ + ReactionTypeEmojiTest::getMinResponse() + ] + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getFullResponse(), + 'message_id' => 1, + 'date' => 1682343644, + 'reactions' => [ + ReactionTypeEmojiTest::getFullResponse() + ] + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getReactions()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createFullInstance(), $item->getChat()); + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals([ReactionTypeEmojiTest::createFullInstance()], $item->getReactions()); + } +} diff --git a/tests/Types/MessageReactionUpdatedTest.php b/tests/Types/MessageReactionUpdatedTest.php new file mode 100644 index 00000000..5f5da651 --- /dev/null +++ b/tests/Types/MessageReactionUpdatedTest.php @@ -0,0 +1,68 @@ + ChatTest::getMinResponse(), + 'message_id' => 1, + 'date' => 1682343644, + 'old_reaction' => [ + ReactionTypeEmojiTest::getMinResponse() + ], + 'new_reaction' => [ + ReactionTypeCustomEmojiTest::getMinResponse() + ] + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'message_id' => 1, + 'user' => UserTest::getMinResponse(), + 'actor_chat' => ChatTest::getMinResponse(), + 'date' => 1682343644, + 'old_reaction' => [ + ReactionTypeEmojiTest::getMinResponse() + ], + 'new_reaction' => [ + ReactionTypeCustomEmojiTest::getMinResponse() + ] + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getOldReaction()); + $this->assertEquals([ReactionTypeCustomEmojiTest::createMinInstance()], $item->getNewReaction()); + + $this->assertNull($item->getUser()); + $this->assertNull($item->getActorChat()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + $this->assertEquals(ChatTest::createMinInstance(), $item->getActorChat()); + $this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getOldReaction()); + $this->assertEquals([ReactionTypeCustomEmojiTest::createMinInstance()], $item->getNewReaction()); + } +} diff --git a/tests/Types/MessageTest.php b/tests/Types/MessageTest.php new file mode 100644 index 00000000..ae4f470c --- /dev/null +++ b/tests/Types/MessageTest.php @@ -0,0 +1,293 @@ + 1, + 'date' => 1682343644, + 'chat' => ChatTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'message_id' => 1, + 'date' => 1682343644, + 'chat' => ChatTest::getMinResponse(), + + 'from' => UserTest::getMinResponse(), + 'forward_from' => UserTest::getMinResponse(), + 'forward_from_chat' => ChatTest::getMinResponse(), + 'forward_from_message_id' => 2, + 'forward_date' => 1682343645, + 'forward_signature' => 'forward_signature', + 'forward_sender_name' => 'forward_sender_name', + 'reply_to_message' => MessageTest::getMinResponse(), + 'via_bot' => UserTest::getMinResponse(), + 'edit_date' => 1682343643, + 'media_group_id' => 3, + 'author_signature' => 'author_signature', + 'text' => 'text', + 'entities' => [ + MessageEntityTest::getMinResponse() + ], + 'caption_entities' => [ + MessageEntityTest::getMinResponse() + ], + 'audio' => AudioTest::getMinResponse(), + 'document' => DocumentTest::getMinResponse(), + 'animation' => AnimationTest::getMinResponse(), + 'photo' => [ + PhotoSizeTest::getMinResponse(), + ], + 'sticker' => StickerTest::getMinResponse(), + 'video' => VideoTest::getMinResponse(), + 'video_note' => VideoNoteTest::getMinResponse(), + 'voice' => VoiceTest::getMinResponse(), + 'caption' => 'caption', + 'contact' => ContactTest::getMinResponse(), + 'location' => LocationTest::getMinResponse(), + 'venue' => VenueTest::getMinResponse(), + 'poll' => PollTest::getMinResponse(), + 'dice' => DiceTest::getMinResponse(), + 'new_chat_members' => [ + UserTest::getMinResponse(), + ], + 'left_chat_member' => UserTest::getMinResponse(), + 'new_chat_title' => 'new_chat_title', + 'new_chat_photo' => [ + PhotoSizeTest::getMinResponse(), + ], + 'delete_chat_photo' => true, + 'group_chat_created' => true, + 'supergroup_chat_created' => true, + 'channel_chat_created' => true, + 'migrate_to_chat_id' => 4, + 'migrate_from_chat_id' => 5, + 'pinned_message' => MessageTest::getMinResponse(), + 'invoice' => InvoiceTest::getMinResponse(), + 'successful_payment' => SuccessfulPaymentTest::getMinResponse(), + 'connected_website' => 'connected_website', + 'forum_topic_created' => ForumTopicCreatedTest::getMinResponse(), + 'forum_topic_closed' => ForumTopicClosedTest::getMinResponse(), + 'forum_topic_reopened' => ForumTopicReopenedTest::getMinResponse(), + 'is_topic_message' => true, + 'message_thread_id' => 6, + 'web_app_data' => WebAppDataTest::getMinResponse(), + 'reply_markup' => InlineKeyboardMarkupTest::getMinResponse() + ]; + } + + /** + * @param Message $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + + $this->assertNull($item->getFrom()); + $this->assertNull($item->getReplyToMessage()); + $this->assertNull($item->getViaBot()); + $this->assertNull($item->getEditDate()); + $this->assertNull($item->getMediaGroupId()); + $this->assertNull($item->getAuthorSignature()); + $this->assertNull($item->getText()); + $this->assertNull($item->getEntities()); + $this->assertNull($item->getCaptionEntities()); + $this->assertNull($item->getAudio()); + $this->assertNull($item->getDocument()); + $this->assertNull($item->getAnimation()); + $this->assertNull($item->getPhoto()); + $this->assertNull($item->getSticker()); + $this->assertNull($item->getVideo()); + $this->assertNull($item->getVideoNote()); + $this->assertNull($item->getVoice()); + $this->assertNull($item->getCaption()); + $this->assertNull($item->getContact()); + $this->assertNull($item->getLocation()); + $this->assertNull($item->getVenue()); + $this->assertNull($item->getPoll()); + $this->assertNull($item->getDice()); + $this->assertNull($item->getNewChatMembers()); + $this->assertNull($item->getLeftChatMember()); + $this->assertNull($item->getNewChatTitle()); + $this->assertNull($item->getNewChatPhoto()); + $this->assertNull($item->isDeleteChatPhoto()); + $this->assertNull($item->isGroupChatCreated()); + $this->assertNull($item->isSupergroupChatCreated()); + $this->assertNull($item->isChannelChatCreated()); + $this->assertNull($item->getMigrateToChatId()); + $this->assertNull($item->getMigrateFromChatId()); + $this->assertNull($item->getPinnedMessage()); + $this->assertNull($item->getInvoice()); + $this->assertNull($item->getSuccessfulPayment()); + $this->assertNull($item->getConnectedWebsite()); + $this->assertNull($item->getForumTopicCreated()); + $this->assertNull($item->getForumTopicClosed()); + $this->assertNull($item->getForumTopicReopened()); + $this->assertNull($item->getIsTopicMessage()); + $this->assertNull($item->getMessageThreadId()); + $this->assertNull($item->getWebAppData()); + $this->assertNull($item->getReplyMarkup()); + } + + /** + * @param Message $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getMessageId()); + $this->assertEquals(1682343644, $item->getDate()); + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getReplyToMessage()); + $this->assertEquals(UserTest::createMinInstance(), $item->getViaBot()); + $this->assertEquals(1682343643, $item->getEditDate()); + $this->assertEquals(3, $item->getMediaGroupId()); + $this->assertEquals('author_signature', $item->getAuthorSignature()); + $this->assertEquals('text', $item->getText()); + $this->assertEquals([MessageEntityTest::createMinInstance()], $item->getEntities()); + $this->assertEquals([MessageEntityTest::createMinInstance()], $item->getCaptionEntities()); + $this->assertEquals(AudioTest::createMinInstance(), $item->getAudio()); + $this->assertEquals(DocumentTest::createMinInstance(), $item->getDocument()); + $this->assertEquals(AnimationTest::createMinInstance(), $item->getAnimation()); + $this->assertEquals([PhotoSizeTest::createMinInstance()], $item->getPhoto()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(VideoTest::createMinInstance(), $item->getVideo()); + $this->assertEquals(VideoNoteTest::createMinInstance(), $item->getVideoNote()); + $this->assertEquals(VoiceTest::createMinInstance(), $item->getVoice()); + $this->assertEquals('caption', $item->getCaption()); + $this->assertEquals(ContactTest::createMinInstance(), $item->getContact()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertEquals(VenueTest::createMinInstance(), $item->getVenue()); + $this->assertEquals(PollTest::createMinInstance(), $item->getPoll()); + $this->assertEquals(DiceTest::createMinInstance(), $item->getDice()); + $this->assertEquals([UserTest::createMinInstance()], $item->getNewChatMembers()); + $this->assertEquals(UserTest::createMinInstance(), $item->getLeftChatMember()); + $this->assertEquals('new_chat_title', $item->getNewChatTitle()); + $this->assertEquals([PhotoSizeTest::createMinInstance()], $item->getNewChatPhoto()); + $this->assertTrue($item->isDeleteChatPhoto()); + $this->assertTrue($item->isGroupChatCreated()); + $this->assertTrue($item->isSupergroupChatCreated()); + $this->assertTrue($item->isChannelChatCreated()); + $this->assertEquals(4, $item->getMigrateToChatId()); + $this->assertEquals(5, $item->getMigrateFromChatId()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getPinnedMessage()); + $this->assertEquals(InvoiceTest::createMinInstance(), $item->getInvoice()); + $this->assertEquals(SuccessfulPaymentTest::createMinInstance(), $item->getSuccessfulPayment()); + $this->assertEquals('connected_website', $item->getConnectedWebsite()); + $this->assertEquals(ForumTopicCreatedTest::createMinInstance(), $item->getForumTopicCreated()); + // $this->assertEquals(ForumTopicClosedTest::createMinInstance(), $item->getForumTopicClosed()); + // $this->assertEquals(ForumTopicReopenedTest::createMinInstance(), $item->getForumTopicReopened()); + $this->assertTrue($item->getIsTopicMessage()); + $this->assertEquals(6, $item->getMessageThreadId()); + $this->assertEquals(WebAppDataTest::createMinInstance(), $item->getWebAppData()); + $this->assertEquals(InlineKeyboardMarkupTest::createMinInstance(), $item->getReplyMarkup()); + } + + public function testSet64bitMessageId() + { + $item = new Message(); + $item->setMessageId(2147483648); + $this->assertEquals(2147483648, $item->getMessageId()); + } + + public function testSetMessageIdException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Message(); + $item->setMessageId('s'); + } + + public function testSetDateException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Message(); + $item->setDate('s'); + } + + public function testSetEditDateException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Message(); + $item->setEditDate('s'); + } + + public function testToJson1() + { + $data = [ + 'message_id' => 1, + 'from' => [ + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'id' => 123456, + 'username' => 'iGusev' + ], + 'date' => 2, + 'chat' => [ + 'id' => 1, + 'type' => 'group', + 'title' => 'test chat' + ], + 'migrate_from_chat_id' => 3 + ]; + + $item = Message::fromResponse($data); + $this->assertJson(json_encode($data), $item->toJson()); + } + + public function testToJson2() + { + $data = [ + 'message_id' => 1, + 'from' => [ + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'id' => 123456, + 'username' => 'iGusev' + ], + 'date' => 2, + 'chat' => [ + 'id' => 1, + 'type' => 'group', + 'title' => 'test chat' + ], + 'entities' => [ + [ + 'type' => 'bot_command', + 'offset' => 0, + 'length' => 7, + ] + ], + 'migrate_from_chat_id' => 3 + ]; + + $item = Message::fromResponse($data); + $this->assertJson(json_encode($data), $item->toJson()); + } +} diff --git a/tests/Types/OwnedGiftRegularTest.php b/tests/Types/OwnedGiftRegularTest.php new file mode 100644 index 00000000..1b6a7bf8 --- /dev/null +++ b/tests/Types/OwnedGiftRegularTest.php @@ -0,0 +1,67 @@ + 'regular', + 'gift' => GiftTest::getMinResponse(), + 'send_date' => 1682343643, + ]; + } + + public static function getFullResponse() + { + return [ + 'type' => 'regular', + 'gift' => GiftTest::getMinResponse(), + 'owned_gift_id' => 'id', + 'sender_user' => UserTest::getMinResponse(), + 'send_date' => 1682343643, + 'text' => 'hi', + 'entities' => [MessageEntityTest::getMinResponse()], + 'is_private' => true, + 'is_saved' => true, + 'can_be_upgraded' => true, + 'was_refunded' => true, + 'convert_star_count' => 1, + 'prepaid_upgrade_star_count' => 2, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('regular', $item->getType()); + $this->assertEquals(GiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals(1682343643, $item->getSendDate()); + $this->assertNull($item->getOwnedGiftId()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('regular', $item->getType()); + $this->assertEquals(GiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('id', $item->getOwnedGiftId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getSenderUser()); + $this->assertEquals(1682343643, $item->getSendDate()); + $this->assertEquals('hi', $item->getText()); + $this->assertEquals([MessageEntityTest::createMinInstance()], $item->getEntities()); + $this->assertTrue($item->getIsPrivate()); + $this->assertTrue($item->getIsSaved()); + $this->assertTrue($item->getCanBeUpgraded()); + $this->assertTrue($item->getWasRefunded()); + $this->assertEquals(1, $item->getConvertStarCount()); + $this->assertEquals(2, $item->getPrepaidUpgradeStarCount()); + } +} diff --git a/tests/Types/OwnedGiftUniqueTest.php b/tests/Types/OwnedGiftUniqueTest.php new file mode 100644 index 00000000..ebee3c67 --- /dev/null +++ b/tests/Types/OwnedGiftUniqueTest.php @@ -0,0 +1,57 @@ + 'unique', + 'gift' => UniqueGiftTest::getMinResponse(), + 'send_date' => 1682343643, + ]; + } + + public static function getFullResponse() + { + return [ + 'type' => 'unique', + 'gift' => UniqueGiftTest::getMinResponse(), + 'owned_gift_id' => 'id', + 'sender_user' => UserTest::getMinResponse(), + 'send_date' => 1682343643, + 'is_saved' => true, + 'can_be_transferred' => true, + 'transfer_star_count' => 3, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('unique', $item->getType()); + $this->assertEquals(UniqueGiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals(1682343643, $item->getSendDate()); + $this->assertNull($item->getOwnedGiftId()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('unique', $item->getType()); + $this->assertEquals(UniqueGiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('id', $item->getOwnedGiftId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getSenderUser()); + $this->assertEquals(1682343643, $item->getSendDate()); + $this->assertTrue($item->getIsSaved()); + $this->assertTrue($item->getCanBeTransferred()); + $this->assertEquals(3, $item->getTransferStarCount()); + } +} diff --git a/tests/Types/OwnedGiftsTest.php b/tests/Types/OwnedGiftsTest.php new file mode 100644 index 00000000..81fc4858 --- /dev/null +++ b/tests/Types/OwnedGiftsTest.php @@ -0,0 +1,45 @@ + 1, + 'gifts' => [OwnedGiftRegularTest::getMinResponse()], + ]; + } + + public static function getFullResponse() + { + return [ + 'total_count' => 2, + 'gifts' => [OwnedGiftRegularTest::getMinResponse()], + 'next_offset' => '1', + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getTotalCount()); + $this->assertEquals([OwnedGiftRegularTest::createMinInstance()], $item->getGifts()); + $this->assertNull($item->getNextOffset()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(2, $item->getTotalCount()); + $this->assertEquals([OwnedGiftRegularTest::createMinInstance()], $item->getGifts()); + $this->assertEquals('1', $item->getNextOffset()); + } +} diff --git a/tests/Types/Payments/InvoiceTest.php b/tests/Types/Payments/InvoiceTest.php new file mode 100644 index 00000000..302aea91 --- /dev/null +++ b/tests/Types/Payments/InvoiceTest.php @@ -0,0 +1,52 @@ + 'title', + 'description' => 'description', + 'start_parameter' => 'start_parameter', + 'currency' => 'currency', + 'total_amount' => 1000, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param Invoice $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('description', $item->getDescription()); + $this->assertEquals('start_parameter', $item->getStartParameter()); + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + } + + /** + * @param Invoice $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/Payments/OrderInfoTest.php b/tests/Types/Payments/OrderInfoTest.php new file mode 100644 index 00000000..106d6f32 --- /dev/null +++ b/tests/Types/Payments/OrderInfoTest.php @@ -0,0 +1,53 @@ + 'name', + 'phone_number' => 'phone_number', + 'email' => 'email', + 'shipping_address' => ShippingAddressTest::getMinResponse() + ]; + } + + /** + * @param OrderInfo $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertNull($item->getName()); + $this->assertNull($item->getPhoneNumber()); + $this->assertNull($item->getEmail()); + $this->assertNull($item->getShippingAddress()); + } + + /** + * @param OrderInfo $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals('phone_number', $item->getPhoneNumber()); + $this->assertEquals('email', $item->getEmail()); + $this->assertEquals(ShippingAddressTest::createMinInstance(), $item->getShippingAddress()); + } +} diff --git a/tests/Types/Payments/Query/PreCheckoutQueryTest.php b/tests/Types/Payments/Query/PreCheckoutQueryTest.php new file mode 100644 index 00000000..cecf7dee --- /dev/null +++ b/tests/Types/Payments/Query/PreCheckoutQueryTest.php @@ -0,0 +1,70 @@ + 1, + 'from' => UserTest::getMinResponse(), + 'currency' => 'currency', + 'total_amount' => 1000, + 'invoice_payload' => 'invoice_payload', + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 1, + 'from' => UserTest::getMinResponse(), + 'currency' => 'currency', + 'total_amount' => 1000, + 'invoice_payload' => 'invoice_payload', + 'shipping_option_id' => 'shipping_option_id', + 'order_info' => OrderInfoTest::getFullResponse() + ]; + } + + /** + * @param PreCheckoutQuery $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertNull($item->getShippingOptionId()); + $this->assertNull($item->getOrderInfo()); + } + + /** + * @param PreCheckoutQuery $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertEquals('shipping_option_id', $item->getShippingOptionId()); + $this->assertEquals(OrderInfoTest::createFullInstance(), $item->getOrderInfo()); + } +} diff --git a/tests/Types/Payments/Query/ShippingQueryTest.php b/tests/Types/Payments/Query/ShippingQueryTest.php new file mode 100644 index 00000000..413544af --- /dev/null +++ b/tests/Types/Payments/Query/ShippingQueryTest.php @@ -0,0 +1,52 @@ + 1, + 'from' => UserTest::getMinResponse(), + 'invoice_payload' => 'invoice_payload', + 'shipping_address' => ShippingAddressTest::getMinResponse() + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ShippingQuery $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertEquals(ShippingAddressTest::createMinInstance(), $item->getShippingAddress()); + } + + /** + * @param ShippingQuery $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/Payments/ShippingAddressTest.php b/tests/Types/Payments/ShippingAddressTest.php new file mode 100644 index 00000000..d2016075 --- /dev/null +++ b/tests/Types/Payments/ShippingAddressTest.php @@ -0,0 +1,54 @@ + 'country_code', + 'state' => 'state', + 'city' => 'city', + 'street_line1' => 'street_line1', + 'street_line2' => 'street_line2', + 'post_code' => 'post_code', + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ShippingAddress $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('country_code', $item->getCountryCode()); + $this->assertEquals('state', $item->getState()); + $this->assertEquals('city', $item->getCity()); + $this->assertEquals('street_line1', $item->getStreetLine1()); + $this->assertEquals('street_line2', $item->getStreetLine2()); + $this->assertEquals('post_code', $item->getPostCode()); + } + + /** + * @param ShippingAddress $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/Payments/SuccessfulPaymentTest.php b/tests/Types/Payments/SuccessfulPaymentTest.php new file mode 100644 index 00000000..2c55c294 --- /dev/null +++ b/tests/Types/Payments/SuccessfulPaymentTest.php @@ -0,0 +1,68 @@ + 'currency', + 'total_amount' => 1000, + 'invoice_payload' => 'invoice_payload', + 'telegram_payment_charge_id' => 'telegram_payment_charge_id', + 'provider_payment_charge_id' => 'provider_payment_charge_id', + ]; + } + + public static function getFullResponse() + { + return [ + 'currency' => 'currency', + 'total_amount' => 1000, + 'invoice_payload' => 'invoice_payload', + 'telegram_payment_charge_id' => 'telegram_payment_charge_id', + 'provider_payment_charge_id' => 'provider_payment_charge_id', + 'shipping_option_id' => 'shipping_option_id', + 'order_info' => OrderInfoTest::getFullResponse(), + ]; + } + + /** + * @param SuccessfulPayment $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertEquals('telegram_payment_charge_id', $item->getTelegramPaymentChargeId()); + $this->assertEquals('provider_payment_charge_id', $item->getProviderPaymentChargeId()); + $this->assertNull($item->getShippingOptionId()); + $this->assertNull($item->getOrderInfo()); + } + + /** + * @param SuccessfulPayment $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('currency', $item->getCurrency()); + $this->assertEquals(1000, $item->getTotalAmount()); + $this->assertEquals('invoice_payload', $item->getInvoicePayload()); + $this->assertEquals('telegram_payment_charge_id', $item->getTelegramPaymentChargeId()); + $this->assertEquals('provider_payment_charge_id', $item->getProviderPaymentChargeId()); + $this->assertEquals('shipping_option_id', $item->getShippingOptionId()); + $this->assertEquals(OrderInfoTest::createFullInstance(), $item->getOrderInfo()); + } +} diff --git a/tests/Types/PhotoSizeTest.php b/tests/Types/PhotoSizeTest.php new file mode 100644 index 00000000..6b3e9dda --- /dev/null +++ b/tests/Types/PhotoSizeTest.php @@ -0,0 +1,86 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'height' => 2, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'height' => 2, + 'file_size' => 3 + ]; + } + + /** + * @param PhotoSize $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertNull($item->getFileSize()); + } + + /** + * @param PhotoSize $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(3, $item->getFileSize()); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new PhotoSize(); + $item->setFileSize('s'); + } + + public function testSetHeightException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new PhotoSize(); + $item->setHeight('s'); + } + + public function testSetWidthException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new PhotoSize(); + $item->setWidth('s'); + } +} diff --git a/tests/Types/PollAnswerTest.php b/tests/Types/PollAnswerTest.php new file mode 100644 index 00000000..ed08dbd4 --- /dev/null +++ b/tests/Types/PollAnswerTest.php @@ -0,0 +1,48 @@ + [1,2,3,4,5,6], + 'user' => UserTest::getMinResponse(), + 'poll_id' => 123456789, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param PollAnswer $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(123456789, $item->getPollId()); + $this->assertEquals(UserTest::createMinInstance(), $item->getUser()); + $this->assertEquals([1,2,3,4,5,6], $item->getOptionIds()); + } + + /** + * @param PollAnswer $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/PollOptionTest.php b/tests/Types/PollOptionTest.php new file mode 100644 index 00000000..f1095066 --- /dev/null +++ b/tests/Types/PollOptionTest.php @@ -0,0 +1,46 @@ + 'text', + 'voter_count' => 3 + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param PollOption $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('text', $item->getText()); + $this->assertEquals(3, $item->getVoterCount()); + } + + /** + * @param PollOption $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/PollTest.php b/tests/Types/PollTest.php new file mode 100644 index 00000000..463b95ce --- /dev/null +++ b/tests/Types/PollTest.php @@ -0,0 +1,81 @@ + 123456789, + 'question' => 'What is the name of Heisenberg from "Breaking bad"?', + 'options' => [ + PollOptionTest::getMinResponse(), + ], + 'total_voter_count' => 17, + 'is_closed' => true, + 'is_anonymous' => true, + 'type' => 'regular', + 'allows_multiple_answers' => true, + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 123456789, + 'question' => 'What is the name of Heisenberg from "Breaking bad"?', + 'options' => [ + PollOptionTest::getMinResponse(), + ], + 'total_voter_count' => 17, + 'is_closed' => true, + 'is_anonymous' => true, + 'type' => 'regular', + 'allows_multiple_answers' => true, + 'correct_option_id' => 2, + ]; + } + + /** + * @param Poll $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(123456789, $item->getId()); + $this->assertEquals('What is the name of Heisenberg from "Breaking bad"?', $item->getQuestion()); + $this->assertEquals([PollOptionTest::createMinInstance()], $item->getOptions()); + $this->assertEquals(17, $item->getTotalVoterCount()); + $this->assertTrue($item->isClosed()); + $this->assertTrue($item->isAnonymous()); + $this->assertEquals('regular', $item->getType()); + $this->assertTrue($item->isAllowsMultipleAnswers()); + $this->assertNull($item->getCorrectOptionId()); + } + + /** + * @param Poll $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(123456789, $item->getId()); + $this->assertEquals('What is the name of Heisenberg from "Breaking bad"?', $item->getQuestion()); + $this->assertEquals([PollOptionTest::createMinInstance()], $item->getOptions()); + $this->assertEquals(17, $item->getTotalVoterCount()); + $this->assertTrue($item->isClosed()); + $this->assertTrue($item->isAnonymous()); + $this->assertEquals('regular', $item->getType()); + $this->assertTrue($item->isAllowsMultipleAnswers()); + $this->assertEquals(2, $item->getCorrectOptionId()); + } +} diff --git a/tests/Types/ReactionTypeCustomEmojiTest.php b/tests/Types/ReactionTypeCustomEmojiTest.php new file mode 100644 index 00000000..bab97bd5 --- /dev/null +++ b/tests/Types/ReactionTypeCustomEmojiTest.php @@ -0,0 +1,46 @@ + 'custom_emoji', + 'custom_emoji_id' => 'custom_emoji_123' + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ReactionTypeCustomEmoji $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('custom_emoji', $item->getType()); + $this->assertEquals('custom_emoji_123', $item->getCustomEmojiId()); + } + + /** + * @param ReactionTypeCustomEmoji $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/ReactionTypeEmojiTest.php b/tests/Types/ReactionTypeEmojiTest.php new file mode 100644 index 00000000..6c192f8e --- /dev/null +++ b/tests/Types/ReactionTypeEmojiTest.php @@ -0,0 +1,46 @@ + 'emoji', + 'emoji' => '👍' + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param ReactionTypeEmoji $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('emoji', $item->getType()); + $this->assertEquals('👍', $item->getEmoji()); + } + + /** + * @param ReactionTypeEmoji $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/ReplyKeyboardHideTest.php b/tests/Types/ReplyKeyboardHideTest.php new file mode 100644 index 00000000..8aef3f4b --- /dev/null +++ b/tests/Types/ReplyKeyboardHideTest.php @@ -0,0 +1,81 @@ + true, + ]; + } + + public static function getFullResponse() + { + return [ + 'hide_keyboard' => true, + 'selective' => true + ]; + } + + /** + * @param ReplyKeyboardHide $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(null, $item->isSelective()); + } + + /** + * @param ReplyKeyboardHide $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(true, $item->isSelective()); + } + + public function testConstructor() + { + $item = new ReplyKeyboardHide(); + + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(null, $item->isSelective()); + } + + public function testConstructor2() + { + $item = new ReplyKeyboardHide(true, true); + + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(true, $item->isSelective()); + } + + public function testConstructor3() + { + $item = new ReplyKeyboardHide(false, true); + + $this->assertEquals(false, $item->isHideKeyboard()); + $this->assertEquals(true, $item->isSelective()); + } + + public function testConstructor4() + { + $item = new ReplyKeyboardHide(true); + + $this->assertEquals(true, $item->isHideKeyboard()); + $this->assertEquals(null, $item->isSelective()); + } +} diff --git a/tests/Types/ReplyKeyboardMarkupTest.php b/tests/Types/ReplyKeyboardMarkupTest.php new file mode 100644 index 00000000..f3154e13 --- /dev/null +++ b/tests/Types/ReplyKeyboardMarkupTest.php @@ -0,0 +1,133 @@ + [['one', 'two']], + ]; + } + + public static function getFullResponse() + { + return [ + 'keyboard' => [['one', 'two']], + 'one_time_keyboard' => true, + 'resize_keyboard' => true, + 'selective' => true, + 'is_persistent' => true, + 'input_field_placeholder' => 'input_field_placeholder', + ]; + } + + /** + * @param ReplyKeyboardMarkup $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertNull($item->isOneTimeKeyboard()); + $this->assertNull($item->isResizeKeyboard()); + $this->assertNull($item->isSelective()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); + } + + /** + * @param ReplyKeyboardMarkup $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(true, $item->getIsPersistent()); + $this->assertEquals('input_field_placeholder', $item->getInputFieldPlaceholder()); + } + + public function testConstructor() + { + $item = new ReplyKeyboardMarkup([['one', 'two']]); + + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertNull($item->isOneTimeKeyboard()); + $this->assertNull($item->isResizeKeyboard()); + $this->assertNull($item->isSelective()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); + } + + public function testConstructor2() + { + $item = new ReplyKeyboardMarkup([['one', 'two']], true); + + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertNull($item->isResizeKeyboard()); + $this->assertNull($item->isSelective()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); + } + + public function testConstructor3() + { + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true); + + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertNull($item->isSelective()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); + } + + public function testConstructor4() + { + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true); + + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(true, $item->isSelective()); + $this->assertNull($item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); + } + + public function testConstructor5() + { + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true, true); + + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(true, $item->getIsPersistent()); + $this->assertNull($item->getInputFieldPlaceholder()); + } + + public function testConstructor6() + { + $item = new ReplyKeyboardMarkup([['one', 'two']], true, true, true, true, 'input_field_placeholder'); + + $this->assertEquals([['one', 'two']], $item->getKeyboard()); + $this->assertEquals(true, $item->isOneTimeKeyboard()); + $this->assertEquals(true, $item->isResizeKeyboard()); + $this->assertEquals(true, $item->isSelective()); + $this->assertEquals(true, $item->getIsPersistent()); + $this->assertEquals('input_field_placeholder', $item->getInputFieldPlaceholder()); + } +} diff --git a/tests/Types/ReplyKeyboardRemoveTest.php b/tests/Types/ReplyKeyboardRemoveTest.php new file mode 100644 index 00000000..d5fde809 --- /dev/null +++ b/tests/Types/ReplyKeyboardRemoveTest.php @@ -0,0 +1,65 @@ + true, + ]; + } + + public static function getFullResponse() + { + return [ + 'remove_keyboard' => true, + 'selective' => true + ]; + } + + /** + * @param ReplyKeyboardRemove $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(true, $item->getRemoveKeyboard()); + $this->assertEquals(false, $item->getSelective()); + } + + /** + * @param ReplyKeyboardRemove $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(true, $item->getRemoveKeyboard()); + $this->assertEquals(true, $item->getSelective()); + } + + public function testDefaultConstructor() + { + $keyboard = new ReplyKeyboardRemove(); + + $this->assertEquals(true, $keyboard->getRemoveKeyboard()); + $this->assertEquals(false, $keyboard->getSelective()); + } + + public function testConstructor() + { + $keyboard = new ReplyKeyboardRemove(false, true); + + $this->assertEquals(false, $keyboard->getRemoveKeyboard()); + $this->assertEquals(true, $keyboard->getSelective()); + } +} diff --git a/tests/Types/SentWebAppMessageTest.php b/tests/Types/SentWebAppMessageTest.php new file mode 100644 index 00000000..37820df2 --- /dev/null +++ b/tests/Types/SentWebAppMessageTest.php @@ -0,0 +1,44 @@ + 'inline_message_id', + ]; + } + + /** + * @param SentWebAppMessage $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertNull($item->getInlineMessageId()); + } + + /** + * @param SentWebAppMessage $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('inline_message_id', $item->getInlineMessageId()); + } +} diff --git a/tests/Types/StarAmountTest.php b/tests/Types/StarAmountTest.php new file mode 100644 index 00000000..327bf350 --- /dev/null +++ b/tests/Types/StarAmountTest.php @@ -0,0 +1,41 @@ + 1, + ]; + } + + public static function getFullResponse() + { + return [ + 'amount' => 2, + 'nanostar_amount' => 100, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getAmount()); + $this->assertNull($item->getNanostarAmount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(2, $item->getAmount()); + $this->assertEquals(100, $item->getNanostarAmount()); + } +} diff --git a/tests/Types/StickerSetTest.php b/tests/Types/StickerSetTest.php new file mode 100644 index 00000000..b15ab212 --- /dev/null +++ b/tests/Types/StickerSetTest.php @@ -0,0 +1,73 @@ + 'name', + 'title' => 'title', + 'sticker_type' => 'regular', + 'is_animated' => true, + 'is_video' => true, + 'stickers' => [ + StickerTest::getMinResponse(), + ], + ]; + } + + public static function getFullResponse() + { + return [ + 'name' => 'name', + 'title' => 'title', + 'sticker_type' => 'regular', + 'is_animated' => true, + 'is_video' => true, + 'stickers' => [ + StickerTest::getMinResponse(), + ], + 'thumbnail' => PhotoSizeTest::getMinResponse(), + ]; + } + + /** + * @param StickerSet $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('regular', $item->getStickerType()); + $this->assertEquals(true, $item->getIsAnimated()); + $this->assertEquals(true, $item->getIsVideo()); + $this->assertEquals([StickerTest::createMinInstance()], $item->getStickers()); + $this->assertNull($item->getThumbnail()); + } + + /** + * @param StickerSet $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('name', $item->getName()); + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('regular', $item->getStickerType()); + $this->assertEquals(true, $item->getIsAnimated()); + $this->assertEquals(true, $item->getIsVideo()); + $this->assertEquals([StickerTest::createMinInstance()], $item->getStickers()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); + } +} diff --git a/tests/Types/StickerTest.php b/tests/Types/StickerTest.php new file mode 100644 index 00000000..cd880d50 --- /dev/null +++ b/tests/Types/StickerTest.php @@ -0,0 +1,109 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'type' => 'regular', + 'width' => 1, + 'height' => 2, + 'is_animated' => false, + 'is_video' => false, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'type' => 'regular', + 'width' => 1, + 'height' => 2, + 'is_animated' => false, + 'is_video' => false, + 'file_size' => 3, + 'premium_animation' => FileTest::getMinResponse(), + 'emoji' => '🎉', + 'thumbnail' => PhotoSizeTest::getMinResponse(), + 'set_name' => 'set', + 'custom_emoji_id' => 'custom_emoji_id', + 'mask_position' => MaskPositionTest::getMinResponse(), + ]; + } + + /** + * @param Sticker $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals('regular', $item->getType()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(false, $item->getIsAnimated()); + $this->assertEquals(false, $item->getIsVideo()); + } + + /** + * @param Sticker $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals('regular', $item->getType()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals(false, $item->getIsAnimated()); + $this->assertEquals(FileTest::createMinInstance(), $item->getPremiumAnimation()); + $this->assertEquals(false, $item->getIsVideo()); + $this->assertEquals('🎉', $item->getEmoji()); + $this->assertEquals('set', $item->getSetName()); + $this->assertEquals('custom_emoji_id', $item->getCustomEmojiId()); + $this->assertEquals(MaskPositionTest::createMinInstance(), $item->getMaskPosition()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Sticker(); + $item->setFileSize('s'); + } + + public function testSetHeightException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Sticker(); + $item->setHeight('s'); + } + + public function testSetWidthException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Sticker(); + $item->setWidth('s'); + } +} diff --git a/tests/Types/UniqueGiftBackdropColorsTest.php b/tests/Types/UniqueGiftBackdropColorsTest.php new file mode 100644 index 00000000..f78b1410 --- /dev/null +++ b/tests/Types/UniqueGiftBackdropColorsTest.php @@ -0,0 +1,42 @@ + 1, + 'edge_color' => 2, + 'symbol_color' => 3, + 'text_color' => 4, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getCenterColor()); + $this->assertEquals(2, $item->getEdgeColor()); + $this->assertEquals(3, $item->getSymbolColor()); + $this->assertEquals(4, $item->getTextColor()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UniqueGiftBackdropTest.php b/tests/Types/UniqueGiftBackdropTest.php new file mode 100644 index 00000000..c5955493 --- /dev/null +++ b/tests/Types/UniqueGiftBackdropTest.php @@ -0,0 +1,40 @@ + 'backdrop', + 'colors' => UniqueGiftBackdropColorsTest::getMinResponse(), + 'rarity_per_mille' => 1, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals('backdrop', $item->getName()); + $this->assertEquals(UniqueGiftBackdropColorsTest::createMinInstance(), $item->getColors()); + $this->assertEquals(1, $item->getRarityPerMille()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UniqueGiftInfoTest.php b/tests/Types/UniqueGiftInfoTest.php new file mode 100644 index 00000000..a56e0de8 --- /dev/null +++ b/tests/Types/UniqueGiftInfoTest.php @@ -0,0 +1,48 @@ + UniqueGiftTest::getMinResponse(), + 'origin' => 'upgrade', + ]; + } + + public static function getFullResponse() + { + return [ + 'gift' => UniqueGiftTest::getMinResponse(), + 'origin' => 'upgrade', + 'owned_gift_id' => 'id', + 'transfer_star_count' => 3, + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals(UniqueGiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('upgrade', $item->getOrigin()); + $this->assertNull($item->getOwnedGiftId()); + $this->assertNull($item->getTransferStarCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals(UniqueGiftTest::createMinInstance(), $item->getGift()); + $this->assertEquals('upgrade', $item->getOrigin()); + $this->assertEquals('id', $item->getOwnedGiftId()); + $this->assertEquals(3, $item->getTransferStarCount()); + } +} diff --git a/tests/Types/UniqueGiftModelTest.php b/tests/Types/UniqueGiftModelTest.php new file mode 100644 index 00000000..11863a8e --- /dev/null +++ b/tests/Types/UniqueGiftModelTest.php @@ -0,0 +1,40 @@ + 'model', + 'sticker' => StickerTest::getMinResponse(), + 'rarity_per_mille' => 1, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals('model', $item->getName()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(1, $item->getRarityPerMille()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UniqueGiftSymbolTest.php b/tests/Types/UniqueGiftSymbolTest.php new file mode 100644 index 00000000..fb58e7d9 --- /dev/null +++ b/tests/Types/UniqueGiftSymbolTest.php @@ -0,0 +1,40 @@ + 'symbol', + 'sticker' => StickerTest::getMinResponse(), + 'rarity_per_mille' => 1, + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals('symbol', $item->getName()); + $this->assertEquals(StickerTest::createMinInstance(), $item->getSticker()); + $this->assertEquals(1, $item->getRarityPerMille()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UniqueGiftTest.php b/tests/Types/UniqueGiftTest.php new file mode 100644 index 00000000..e7004fe6 --- /dev/null +++ b/tests/Types/UniqueGiftTest.php @@ -0,0 +1,46 @@ + 'gift', + 'name' => 'unique1', + 'number' => 1, + 'model' => UniqueGiftModelTest::getMinResponse(), + 'symbol' => UniqueGiftSymbolTest::getMinResponse(), + 'backdrop' => UniqueGiftBackdropTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + protected function assertMinItem($item) + { + $this->assertEquals('gift', $item->getBaseName()); + $this->assertEquals('unique1', $item->getName()); + $this->assertEquals(1, $item->getNumber()); + $this->assertEquals(UniqueGiftModelTest::createMinInstance(), $item->getModel()); + $this->assertEquals(UniqueGiftSymbolTest::createMinInstance(), $item->getSymbol()); + $this->assertEquals(UniqueGiftBackdropTest::createMinInstance(), $item->getBackdrop()); + } + + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/UpdateTest.php b/tests/Types/UpdateTest.php new file mode 100644 index 00000000..fb730af2 --- /dev/null +++ b/tests/Types/UpdateTest.php @@ -0,0 +1,100 @@ + 10, + ]; + } + + public static function getFullResponse() + { + return [ + 'update_id' => 10, + 'message' => MessageTest::getMinResponse(), + 'edited_message' => MessageTest::getMinResponse(), + 'channel_post' => MessageTest::getMinResponse(), + 'edited_channel_post' => MessageTest::getMinResponse(), + 'inline_query' => InlineQueryTest::getMinResponse(), + 'chosen_inline_result' => ChosenInlineResultTest::getMinResponse(), + 'callback_query' => CallbackQueryTest::getMinResponse(), + 'shipping_query' => ShippingQueryTest::getMinResponse(), + 'pre_checkout_query' => PreCheckoutQueryTest::getMinResponse(), + 'poll_answer' => PollAnswerTest::getMinResponse(), + 'poll' => PollTest::getMinResponse(), + 'chat_join_request' => ChatJoinRequestTest::getMinResponse(), + 'message_reaction' => MessageReactionUpdatedTest::getMinResponse(), + 'message_reaction_count' => MessageReactionCountUpdatedTest::getMinResponse(), + 'chat_boost' => ChatBoostUpdatedTest::getMinResponse(), + 'chat_boost_removed' => ChatBoostRemovedTest::getMinResponse(), + ]; + } + + /** + * @param Update $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(10, $item->getUpdateId()); + $this->assertNull($item->getMessage()); + $this->assertNull($item->getEditedMessage()); + $this->assertNull($item->getChannelPost()); + $this->assertNull($item->getEditedChannelPost()); + $this->assertNull($item->getInlineQuery()); + $this->assertNull($item->getChosenInlineResult()); + $this->assertNull($item->getCallbackQuery()); + $this->assertNull($item->getShippingQuery()); + $this->assertNull($item->getPreCheckoutQuery()); + $this->assertNull($item->getPollAnswer()); + $this->assertNull($item->getPoll()); + $this->assertNull($item->getMyChatMember()); + $this->assertNull($item->getChatMember()); + $this->assertNull($item->getChatJoinRequest()); + $this->assertNull($item->getMessageReaction()); + $this->assertNull($item->getMessageReactionCount()); + $this->assertNull($item->getChatBoost()); + $this->assertNull($item->getChatBoostRemoved()); + } + + /** + * @param Update $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(10, $item->getUpdateId()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getMessage()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getEditedMessage()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getChannelPost()); + $this->assertEquals(MessageTest::createMinInstance(), $item->getEditedChannelPost()); + $this->assertEquals(InlineQueryTest::createMinInstance(), $item->getInlineQuery()); + $this->assertEquals(ChosenInlineResultTest::createMinInstance(), $item->getChosenInlineResult()); + $this->assertEquals(CallbackQueryTest::createMinInstance(), $item->getCallbackQuery()); + $this->assertEquals(ShippingQueryTest::createMinInstance(), $item->getShippingQuery()); + $this->assertEquals(PreCheckoutQueryTest::createMinInstance(), $item->getPreCheckoutQuery()); + $this->assertEquals(PollAnswerTest::createMinInstance(), $item->getPollAnswer()); + $this->assertEquals(PollTest::createMinInstance(), $item->getPoll()); + $this->assertEquals(ChatJoinRequestTest::createMinInstance(), $item->getChatJoinRequest()); + $this->assertEquals(MessageReactionUpdatedTest::createMinInstance(), $item->getMessageReaction()); + $this->assertEquals(MessageReactionCountUpdatedTest::createMinInstance(), $item->getMessageReactionCount()); + $this->assertEquals(ChatBoostUpdatedTest::createMinInstance(), $item->getChatBoost()); + $this->assertEquals(ChatBoostRemovedTest::createMinInstance(), $item->getChatBoostRemoved()); + } +} diff --git a/tests/Types/UserProfilePhotosTest.php b/tests/Types/UserProfilePhotosTest.php new file mode 100644 index 00000000..a9a3f468 --- /dev/null +++ b/tests/Types/UserProfilePhotosTest.php @@ -0,0 +1,59 @@ + 1, + 'photos' => [ + [ + PhotoSizeTest::getMinResponse(), + ] + ] + ]; + } + + public static function getFullResponse() + { + return static::getMinResponse(); + } + + /** + * @param UserProfilePhotos $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(1, $item->getTotalCount()); + $this->assertEquals([[PhotoSizeTest::createMinInstance()]], $item->getPhotos()); + } + + /** + * @param UserProfilePhotos $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } + + public function testSetTotalCountException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new UserProfilePhotos(); + $item->setTotalCount('s'); + } +} diff --git a/tests/Types/UserTest.php b/tests/Types/UserTest.php new file mode 100644 index 00000000..d024c374 --- /dev/null +++ b/tests/Types/UserTest.php @@ -0,0 +1,187 @@ + 123456, + 'first_name' => 'Ilya', + ]; + } + + public static function getFullResponse() + { + return [ + 'id' => 123456, + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'username' => 'iGusev', + 'language_code' => 'en', + 'is_premium' => false, + 'added_to_attachment_menu' => false, + 'can_join_groups' => true, + 'can_read_all_group_messages' => true, + 'supports_inline_queries' => false, + 'is_bot' => false, + ]; + } + + /** + * @param User $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(123456, $item->getId()); + $this->assertEquals('Ilya', $item->getFirstName()); + + $this->assertNull($item->getLastName()); + $this->assertNull($item->getUsername()); + $this->assertNull($item->getLanguageCode()); + $this->assertNull($item->getIsPremium()); + $this->assertNull($item->getAddedToAttachmentMenu()); + $this->assertNull($item->getCanJoinGroups()); + $this->assertNull($item->getCanReadAllGroupMessages()); + $this->assertNull($item->getSupportsInlineQueries()); + $this->assertFalse($item->isBot()); + } + + /** + * @param User $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(123456, $item->getId()); + $this->assertEquals('Ilya', $item->getFirstName()); + $this->assertEquals('Gusev', $item->getLastName()); + $this->assertEquals('iGusev', $item->getUsername()); + $this->assertEquals('en', $item->getLanguageCode()); + $this->assertEquals(false, $item->getIsPremium()); + $this->assertEquals(false, $item->getAddedToAttachmentMenu()); + $this->assertEquals(true, $item->getCanJoinGroups()); + $this->assertEquals(true, $item->getCanReadAllGroupMessages()); + $this->assertEquals(false, $item->getSupportsInlineQueries()); + $this->assertEquals(false, $item->isBot()); + } + + public function testSet64bitId() + { + $item = new User(); + $item->setId(2147483648); + $this->assertEquals(2147483648, $item->getId()); + } + + public function testSetIdException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new User(); + $item->setId('s'); + } + + public function testFromResponseException1() + { + $this->expectException(InvalidArgumentException::class); + + User::fromResponse([ + 'last_name' => 'Gusev', + 'id' => 123456, + 'username' => 'iGusev' + ]); + } + + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + + User::fromResponse([ + 'first_name' => 'Ilya', + 'last_name' => 'Gusev', + 'username' => 'iGusev' + ]); + } + + public function testSetAndGetFirstName() + { + $item = new User(); + $item->setFirstName('John'); + $this->assertEquals('John', $item->getFirstName()); + } + + public function testSetAndGetLastName() + { + $item = new User(); + $item->setLastName('Doe'); + $this->assertEquals('Doe', $item->getLastName()); + } + + public function testSetAndGetUsername() + { + $item = new User(); + $item->setUsername('johndoe'); + $this->assertEquals('johndoe', $item->getUsername()); + } + + public function testSetAndGetLanguageCode() + { + $item = new User(); + $item->setLanguageCode('en'); + $this->assertEquals('en', $item->getLanguageCode()); + } + + public function testSetAndGetIsBot() + { + $item = new User(); + $item->setIsBot(true); + $this->assertTrue($item->isBot()); + } + + public function testSetAndGetIsPremium() + { + $item = new User(); + $item->setIsPremium(true); + $this->assertTrue($item->getIsPremium()); + } + + public function testSetAndGetAddedToAttachmentMenu() + { + $item = new User(); + $item->setAddedToAttachmentMenu(true); + $this->assertTrue($item->getAddedToAttachmentMenu()); + } + + public function testSetAndGetCanJoinGroups() + { + $item = new User(); + $item->setCanJoinGroups(true); + $this->assertTrue($item->getCanJoinGroups()); + } + + public function testSetAndGetCanReadAllGroupMessages() + { + $item = new User(); + $item->setCanReadAllGroupMessages(true); + $this->assertTrue($item->getCanReadAllGroupMessages()); + } + + public function testSetAndGetSupportsInlineQueries() + { + $item = new User(); + $item->setSupportsInlineQueries(true); + $this->assertTrue($item->getSupportsInlineQueries()); + } + +} diff --git a/tests/Types/VenueTest.php b/tests/Types/VenueTest.php new file mode 100644 index 00000000..2cd40191 --- /dev/null +++ b/tests/Types/VenueTest.php @@ -0,0 +1,66 @@ + LocationTest::getMinResponse(), + 'title' => 'title', + 'address' => 'address', + ]; + } + + public static function getFullResponse() + { + return [ + 'location' => LocationTest::getMinResponse(), + 'title' => 'title', + 'address' => 'address', + 'foursquare_id' => 'foursquare_id', + 'foursquare_type' => 'foursquare_type', + 'google_place_id' => 'google_place_id', + 'google_place_type' => 'google_place_type', + ]; + } + + /** + * @param Venue $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('address', $item->getAddress()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertNull($item->getFoursquareId()); + $this->assertNull($item->getFoursquareType()); + $this->assertNull($item->getGooglePlaceId()); + $this->assertNull($item->getGooglePlaceType()); + } + + /** + * @param Venue $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('title', $item->getTitle()); + $this->assertEquals('address', $item->getAddress()); + $this->assertEquals(LocationTest::createMinInstance(), $item->getLocation()); + $this->assertEquals('foursquare_id', $item->getFoursquareId()); + $this->assertEquals('foursquare_type', $item->getFoursquareType()); + $this->assertEquals('google_place_id', $item->getGooglePlaceId()); + $this->assertEquals('google_place_type', $item->getGooglePlaceType()); + } +} diff --git a/tests/Types/VideoNoteTest.php b/tests/Types/VideoNoteTest.php new file mode 100644 index 00000000..b0197075 --- /dev/null +++ b/tests/Types/VideoNoteTest.php @@ -0,0 +1,64 @@ + 'file_id', + 'file_unique_id' => 'file_unique_id', + 'length' => 1, + 'duration' => 2, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'file_id', + 'file_unique_id' => 'file_unique_id', + 'length' => 1, + 'duration' => 2, + 'thumbnail' => PhotoSizeTest::getMinResponse(), + 'file_size' => 3, + ]; + } + + /** + * @param VideoNote $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('file_id', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getLength()); + $this->assertEquals(2, $item->getDuration()); + $this->assertNull($item->getFileSize()); + $this->assertNull($item->getThumbnail()); + } + + /** + * @param VideoNote $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('file_id', $item->getFileId()); + $this->assertEquals('file_unique_id', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getLength()); + $this->assertEquals(2, $item->getDuration()); + $this->assertEquals(3, $item->getFileSize()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); + } +} diff --git a/tests/Types/VideoTest.php b/tests/Types/VideoTest.php new file mode 100644 index 00000000..d74a5489 --- /dev/null +++ b/tests/Types/VideoTest.php @@ -0,0 +1,222 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'height' => 2, + 'duration' => 3, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'height' => 2, + 'duration' => 3, + 'mime_type' => 'video/mp4', + 'file_size' => 4, + 'thumbnail' => PhotoSizeTest::getMinResponse() + ]; + } + + /** + * @param Video $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(3, $item->getDuration()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + $this->assertNull($item->getThumbnail()); + } + + /** + * @param Video $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getWidth()); + $this->assertEquals(2, $item->getHeight()); + $this->assertEquals(3, $item->getDuration()); + $this->assertEquals('video/mp4', $item->getMimeType()); + $this->assertEquals(4, $item->getFileSize()); + $this->assertEquals(PhotoSizeTest::createMinInstance(), $item->getThumbnail()); + } + + public function testSetHeightException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Video(); + $item->setHeight('s'); + } + + public function testSetWidthException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Video(); + $item->setWidth('s'); + } + + public function testSetDurationException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Video(); + $item->setDuration('s'); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Video(); + $item->setFileSize('s'); + } + + /** + * file_id is required + */ + public function testFromResponseException1() + { + $this->expectException(InvalidArgumentException::class); + + Video::fromResponse([ + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'height' => 2, + 'duration' => 3, + 'mime_type' => 'video/mp4', + 'file_size' => 4, + 'thumbnail' => [ + 'file_id' => 'testFileId1', + 'width' => 5, + 'height' => 6, + 'file_size' => 7 + ] + ]); + } + /** + * width is required + */ + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + + Video::fromResponse([ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'height' => 2, + 'duration' => 3, + 'mime_type' => 'video/mp4', + 'file_size' => 4, + 'thumbnail' => [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 5, + 'height' => 6, + 'file_size' => 7 + ] + ]); + } + + /** + * height is required + */ + public function testFromResponseException3() + { + $this->expectException(InvalidArgumentException::class); + + Video::fromResponse([ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'duration' => 3, + 'mime_type' => 'video/mp4', + 'file_size' => 4, + 'thumbnail' => [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 5, + 'height' => 6, + 'file_size' => 7 + ] + ]); + } + + /** + * duration is required + */ + public function testFromResponseException4() + { + $this->expectException(InvalidArgumentException::class); + + Video::fromResponse([ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 1, + 'height' => 2, + 'mime_type' => 'video/mp4', + 'file_size' => 4, + 'thumbnail' => [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 5, + 'height' => 6, + 'file_size' => 7 + ] + ]); + } + + /** + * file_unique_id is required + */ + public function testFromResponseException5() + { + $this->expectException(InvalidArgumentException::class); + + Video::fromResponse([ + 'file_id' => 'testFileId1', + 'width' => 1, + 'height' => 2, + 'duration' => 1, + 'mime_type' => 'video/mp4', + 'file_size' => 4, + 'thumbnail' => [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'width' => 5, + 'height' => 6, + 'file_size' => 7 + ] + ]); + } +} diff --git a/tests/Types/VoiceTest.php b/tests/Types/VoiceTest.php new file mode 100644 index 00000000..47b3d9a7 --- /dev/null +++ b/tests/Types/VoiceTest.php @@ -0,0 +1,100 @@ + 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'duration' => 1, + ]; + } + + public static function getFullResponse() + { + return [ + 'file_id' => 'testFileId1', + 'file_unique_id' => 'testFileUniqueId1', + 'duration' => 1, + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + ]; + } + + /** + * @param Voice $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getDuration()); + $this->assertNull($item->getMimeType()); + $this->assertNull($item->getFileSize()); + } + + /** + * @param Voice $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('testFileId1', $item->getFileId()); + $this->assertEquals('testFileUniqueId1', $item->getFileUniqueId()); + $this->assertEquals(1, $item->getDuration()); + $this->assertEquals('audio/mp3', $item->getMimeType()); + $this->assertEquals(3, $item->getFileSize()); + } + + public function testFromResponseException() + { + $this->expectException(InvalidArgumentException::class); + + Voice::fromResponse([ + 'duration' => 1, + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + ]); + } + + public function testFromResponseException2() + { + $this->expectException(InvalidArgumentException::class); + + Voice::fromResponse([ + 'file_id' => 'testFileId1', + 'mime_type' => 'audio/mp3', + 'file_size' => 3 + ]); + } + + public function testSetDurationException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Voice(); + $item->setDuration('s'); + } + + public function testSetFileSizeException() + { + $this->expectException(InvalidArgumentException::class); + + $item = new Voice(); + $item->setFileSize('s'); + } + +} diff --git a/tests/Types/WebAppDataTest.php b/tests/Types/WebAppDataTest.php new file mode 100644 index 00000000..a5879146 --- /dev/null +++ b/tests/Types/WebAppDataTest.php @@ -0,0 +1,46 @@ + 'data', + 'button_text' => 'button_text', + ]; + } + + public static function getFullResponse() + { + return self::getMinResponse(); + } + + /** + * @param WebAppData $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('data', $item->getData()); + $this->assertEquals('button_text', $item->getButtonText()); + } + + /** + * @param WebAppData $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertMinItem($item); + } +} diff --git a/tests/Types/WebhookInfoTest.php b/tests/Types/WebhookInfoTest.php new file mode 100644 index 00000000..4bc8f948 --- /dev/null +++ b/tests/Types/WebhookInfoTest.php @@ -0,0 +1,63 @@ + 'https://google.com', + 'has_custom_certificate' => false, + 'pending_update_count' => 0, + ]; + } + + public static function getFullResponse() + { + return [ + 'url' => 'https://google.com', + 'has_custom_certificate' => false, + 'pending_update_count' => 0, + 'ip_address' => '127.0.0.1', + 'last_error_date' => 1682335353, + 'last_error_message' => 'Last error message', + 'last_synchronization_error_date' => 1682335353, + 'max_connections' => 40, + 'allowed_updates' => ['test'] + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('https://google.com', $item->getUrl()); + $this->assertEquals(false, $item->hasCustomCertificate()); + $this->assertEquals(0, $item->getPendingUpdateCount()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('https://google.com', $item->getUrl()); + $this->assertEquals(false, $item->hasCustomCertificate()); + $this->assertEquals(0, $item->getPendingUpdateCount()); + $this->assertEquals('127.0.0.1', $item->getipAddress()); + $this->assertEquals(1682335353, $item->getLastErrorDate()); + $this->assertEquals('Last error message', $item->getLastErrorMessage()); + $this->assertEquals(1682335353, $item->getLastSynchronizationErrorDate()); + $this->assertEquals(40, $item->getMaxConnections()); + $this->assertEquals(['test'], $item->getAllowedUpdates()); + } +} diff --git a/tests/UserProfilePhotosTest.php b/tests/UserProfilePhotosTest.php deleted file mode 100644 index 2a489119..00000000 --- a/tests/UserProfilePhotosTest.php +++ /dev/null @@ -1,104 +0,0 @@ -setTotalCount(1); - $this->assertAttributeEquals(1, 'totalCount', $userProfilePhotos); - } - - public function testGetTotalCount() - { - $userProfilePhotos = new UserProfilePhotos(); - $userProfilePhotos->setTotalCount(1); - $this->assertEquals(1, $userProfilePhotos->getTotalCount()); - } - - public function testSetPhotos() - { - $userProfilePhotos = new UserProfilePhotos(); - $photos = array(); - for ($i = 0; $i < 10; $i++) { - $photos[] = array( - PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => $i, - 'height' => $i * 2, - 'file_size' => $i * 3 - )) - ); - } - - $userProfilePhotos->setPhotos($photos); - $this->assertAttributeEquals($photos, 'photos', $userProfilePhotos); - } - - public function testGetPhotos() - { - $userProfilePhotos = new UserProfilePhotos(); - $photos = array(); - for ($i = 0; $i < 10; $i++) { - $photos[] = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => $i, - 'height' => $i * 2, - 'file_size' => $i * 3 - )); - } - - $userProfilePhotos->setPhotos($photos); - $this->assertEquals($photos, $userProfilePhotos->getPhotos()); - } - - public function testFromResponse() - { - $userProfilePhotos = UserProfilePhotos::fromResponse(array( - "total_count" => 1, - 'photos' => array( - array( - array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - ) - ) - ) - )); - $photos = array( - array( - PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )) - ) - ); - $this->assertInstanceOf('\TelegramBot\Api\Types\UserProfilePhotos', $userProfilePhotos); - $this->assertAttributeEquals(1, 'totalCount', $userProfilePhotos); - $this->assertAttributeEquals($photos, 'photos', $userProfilePhotos); - foreach ($userProfilePhotos->getPhotos() as $photoArray) { - foreach($photoArray as $photo) { - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $photo); - } - } - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetTotalCountException() - { - $item = new UserProfilePhotos(); - $item->setTotalCount('s'); - } -} diff --git a/tests/UserTest.php b/tests/UserTest.php deleted file mode 100644 index 1c9c115d..00000000 --- a/tests/UserTest.php +++ /dev/null @@ -1,119 +0,0 @@ -setId(1); - $this->assertAttributeEquals(1, 'id', $item); - } - - public function testSet64bitId() - { - $item = new User(); - $item->setId(2147483648); - $this->assertAttributeEquals(2147483648, 'id', $item); - } - - public function testGetDuration() - { - $item = new User(); - $item->setId(1); - $this->assertEquals(1, $item->getId()); - } - - public function testSetFirstName() - { - $item = new User(); - $item->setFirstName('Ilya'); - $this->assertAttributeEquals('Ilya', 'firstName', $item); - } - - public function testGetFirstName() - { - $item = new User(); - $item->setFirstName('Ilya'); - $this->assertEquals('Ilya', $item->getFirstName()); - } - - public function testSetLastName() - { - $item = new User(); - $item->setLastName('Gusev'); - $this->assertAttributeEquals('Gusev', 'lastName', $item); - } - - public function testGetLastName() - { - $item = new User(); - $item->setLastName('Gusev'); - $this->assertEquals('Gusev', $item->getLastName()); - } - - public function testSetUsername() - { - $item = new User(); - $item->setUsername('iGusev'); - $this->assertAttributeEquals('iGusev', 'username', $item); - } - - public function testGetUsername() - { - $item = new User(); - $item->setUsername('iGusev'); - $this->assertEquals('iGusev', $item->getUsername()); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetIdException() - { - $item = new User(); - $item->setId('s'); - } - - public function testFromResponse() - { - $user = User::fromResponse(array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\User', $user); - $this->assertEquals(123456, $user->getId()); - $this->assertEquals('Ilya', $user->getFirstName()); - $this->assertEquals('Gusev', $user->getLastName()); - $this->assertEquals('iGusev', $user->getUsername()); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException1() - { - $user = User::fromResponse(array( - 'last_name' => 'Gusev', - 'id' => 123456, - 'username' => 'iGusev' - )); - } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() - { - $user = User::fromResponse(array( - 'first_name' => 'Ilya', - 'last_name' => 'Gusev', - 'username' => 'iGusev' - )); - } - -} diff --git a/tests/VideoTest.php b/tests/VideoTest.php deleted file mode 100644 index 4cea8536..00000000 --- a/tests/VideoTest.php +++ /dev/null @@ -1,267 +0,0 @@ -setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() - { - $item = new Video(); - $item->setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetDuration() - { - $item = new Video(); - $item->setDuration(1); - $this->assertAttributeEquals(1, 'duration', $item); - } - - public function testGetDuration() - { - $item = new Video(); - $item->setDuration(1); - $this->assertEquals(1, $item->getDuration()); - } - - public function testSetFileSize() - { - $item = new Video(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() - { - $item = new Video(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetMimeType() - { - $item = new Video(); - $item->setMimeType('video/mp4'); - $this->assertAttributeEquals('video/mp4', 'mimeType', $item); - } - - public function testGetMimeType() - { - $item = new Video(); - $item->setMimeType('video/mp4'); - $this->assertEquals('video/mp4', $item->getMimeType()); - } - - public function testSetThumb() - { - $item = new Video(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $item->setThumb($thumb); - $this->assertAttributeEquals($thumb, 'thumb', $item); - } - - public function testGetThumb() - { - $item = new Video(); - $thumb = PhotoSize::fromResponse(array( - "file_id" => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'file_size' => 3 - )); - $item->setThumb($thumb); - $this->assertEquals($thumb, $item->getThumb()); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); - } - - public function testSetWidth() - { - $item = new Video(); - $item->setWidth(1); - $this->assertAttributeEquals(1, 'width', $item); - } - - public function testGetWidth() - { - $item = new Video(); - $item->setWidth(2); - $this->assertEquals(2, $item->getWidth()); - } - - public function testSetHeight() - { - $item = new Video(); - $item->setHeight(3); - $this->assertAttributeEquals(3, 'height', $item); - } - - public function testGetHeight() - { - $item = new Video(); - $item->setHeight(4); - $this->assertEquals(4, $item->getHeight()); - } - - public function testFromResponse() - { - $item = Video::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'duration' => 3, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - $thumb = PhotoSize::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Video', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals(1, 'width', $item); - $this->assertAttributeEquals(2, 'height', $item); - $this->assertAttributeEquals(3, 'duration', $item); - $this->assertAttributeEquals('video/mp4', 'mimeType', $item); - $this->assertAttributeEquals(4, 'fileSize', $item); - $this->assertAttributeEquals($thumb, 'thumb', $item); - $this->assertInstanceOf('\TelegramBot\Api\Types\PhotoSize', $item->getThumb()); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetHeightException() - { - $item = new Video(); - $item->setHeight('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetWidthException() - { - $item = new Video(); - $item->setWidth('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetDurationException() - { - $item = new Video(); - $item->setDuration('s'); - } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetFileSizeException() - { - $item = new Video(); - $item->setFileSize('s'); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException1() - { - $item = Video::fromResponse(array( - 'width' => 1, - 'height' => 2, - 'duration' => 3, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() - { - $item = Video::fromResponse(array( - 'file_id' => 'testFileId1', - 'height' => 2, - 'duration' => 3, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException3() - { - $item = Video::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 1, - 'duration' => 3, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException4() - { - $item = Video::fromResponse(array( - 'file_id' => 'testFileId1', - 'width' => 1, - 'height' => 2, - 'mime_type' => 'video/mp4', - 'file_size' => 4, - 'thumb' => array( - 'file_id' => 'testFileId1', - 'width' => 5, - 'height' => 6, - 'file_size' => 7 - ) - )); - } -} diff --git a/tests/VoiceTest.php b/tests/VoiceTest.php deleted file mode 100644 index 35ac39f6..00000000 --- a/tests/VoiceTest.php +++ /dev/null @@ -1,119 +0,0 @@ -setFileId('testfileId'); - $this->assertAttributeEquals('testfileId', 'fileId', $item); - } - - public function testGetFileId() - { - $item = new Voice(); - $item->setFileId('testfileId'); - $this->assertEquals('testfileId', $item->getFileId()); - } - - public function testSetDuration() - { - $item = new Voice(); - $item->setDuration(1); - $this->assertAttributeEquals(1, 'duration', $item); - } - - public function testGetDuration() - { - $item = new Voice(); - $item->setDuration(1); - $this->assertEquals(1, $item->getDuration()); - } - - public function testSetFileSize() - { - $item = new Voice(); - $item->setFileSize(5); - $this->assertAttributeEquals(5, 'fileSize', $item); - } - - public function testGetFileSize() - { - $item = new Voice(); - $item->setFileSize(6); - $this->assertEquals(6, $item->getFileSize()); - } - - public function testSetMimeType() - { - $item = new Voice(); - $item->setMimeType('audio/mp3'); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - } - - public function testGetMimeType() - { - $item = new Voice(); - $item->setMimeType('audio/mp3'); - $this->assertEquals('audio/mp3', $item->getMimeType()); - } - - public function testFromResponse() - { - $item = Voice::fromResponse(array( - 'file_id' => 'testFileId1', - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - $this->assertInstanceOf('\TelegramBot\Api\Types\Voice', $item); - $this->assertAttributeEquals('testFileId1', 'fileId', $item); - $this->assertAttributeEquals(1, 'duration', $item); - $this->assertAttributeEquals('audio/mp3', 'mimeType', $item); - $this->assertAttributeEquals(3, 'fileSize', $item); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException() - { - $item = Voice::fromResponse(array( - 'duration' => 1, - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testFromResponseException2() - { - $item = Voice::fromResponse(array( - 'file_id' => 'testFileId1', - 'mime_type' => 'audio/mp3', - 'file_size' => 3 - )); - } - - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetDurationException() - { - $item = new Voice(); - $item->setDuration('s'); - } - /** - * @expectedException \TelegramBot\Api\InvalidArgumentException - */ - public function testSetFileSizeException() - { - $item = new Voice(); - $item->setFileSize('s'); - } - -} diff --git a/tests/_fixtures/TestBaseType.php b/tests/_fixtures/TestBaseType.php deleted file mode 100644 index 4ad2b6af..00000000 --- a/tests/_fixtures/TestBaseType.php +++ /dev/null @@ -1,9 +0,0 @@ -