diff --git a/README.md b/README.md index ddcc3f5..3438be3 100644 --- a/README.md +++ b/README.md @@ -159,8 +159,12 @@ Parameter | Description --------- |------------ webhook | URL to the manager PHP file used for setting up the Webhook. | *e.g.* `'https://example.com/manager.php'` -selfcrt | Path to a self-signed certificate (if necessary). +certificate | Path to a self-signed certificate (if necessary). | *e.g.* `__DIR__ . '/server.crt'` +max_connections | Maximum allowed simultaneous HTTPS connections to the webhook + | *e.g.* `20` +allowed_updates | List the types of updates you want your bot to receive + | *e.g.* `['message', 'edited_channel_post', 'callback_query']` logging | Path(s) where to the log files should be put. This is an array that can contain all 3 log file paths (`error`, `debug` and `update`). | *e.g.* `['error' => __DIR__ . '/php-telegram-bot-error.log']` admins | An array of user ids that have admin access to your bot. diff --git a/composer.json b/composer.json index 7ed3b7f..a60df52 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ ], "require": { "php": "^7.0", - "longman/telegram-bot": "^0.36" + "longman/telegram-bot": "^0.38" }, "require-dev": { "phpunit/phpunit": "^5.5", diff --git a/composer.lock b/composer.lock index 904f02d..93e2e5a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "dc6368aa2fac9744c0c0906a8a7a0975", - "content-hash": "fd9704b884229884a38698c825b5f97e", + "hash": "fe9431593ab21960654da362ddfca855", + "content-hash": "8adcb74622db40ab8f2eab7b21b1e759", "packages": [ { "name": "guzzlehttp/guzzle", @@ -71,28 +71,28 @@ }, { "name": "guzzlehttp/promises", - "version": "1.3.0", + "version": "v1.3.1", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "2693c101803ca78b27972d84081d027fca790a1e" + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/2693c101803ca78b27972d84081d027fca790a1e", - "reference": "2693c101803ca78b27972d84081d027fca790a1e", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", "shasum": "" }, "require": { "php": ">=5.5.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -118,7 +118,7 @@ "keywords": [ "promise" ], - "time": "2016-11-18 17:47:58" + "time": "2016-12-20 10:07:11" }, { "name": "guzzlehttp/psr7", @@ -180,16 +180,16 @@ }, { "name": "longman/telegram-bot", - "version": "0.36", + "version": "0.38.0", "source": { "type": "git", "url": "https://github.com/akalongman/php-telegram-bot.git", - "reference": "ef9e39444ca917e952591f4042417749233ebe98" + "reference": "112a61b41224a96b5202a350f904239845ddc741" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/akalongman/php-telegram-bot/zipball/ef9e39444ca917e952591f4042417749233ebe98", - "reference": "ef9e39444ca917e952591f4042417749233ebe98", + "url": "https://api.github.com/repos/akalongman/php-telegram-bot/zipball/112a61b41224a96b5202a350f904239845ddc741", + "reference": "112a61b41224a96b5202a350f904239845ddc741", "shasum": "" }, "require": { @@ -229,7 +229,7 @@ "bot", "telegram" ], - "time": "2016-11-25 20:40:52" + "time": "2016-12-25 04:05:50" }, { "name": "monolog/monolog", @@ -762,16 +762,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "4.0.3", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "903fd6318d0a90b4770a009ff73e4a4e9c437929" + "reference": "c14196e64a78570034afd0b7a9f3757ba71c2a0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/903fd6318d0a90b4770a009ff73e4a4e9c437929", - "reference": "903fd6318d0a90b4770a009ff73e4a4e9c437929", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c14196e64a78570034afd0b7a9f3757ba71c2a0a", + "reference": "c14196e64a78570034afd0b7a9f3757ba71c2a0a", "shasum": "" }, "require": { @@ -821,7 +821,7 @@ "testing", "xunit" ], - "time": "2016-11-28 16:00:31" + "time": "2016-12-20 15:22:42" }, { "name": "phpunit/php-file-iterator", @@ -1006,16 +1006,16 @@ }, { "name": "phpunit/phpunit", - "version": "5.6.7", + "version": "5.7.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "38810e97481723ef918f6e35c03cb1014a645bd5" + "reference": "af91da3f2671006ff5d0628023de3b7ac4d1ef09" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/38810e97481723ef918f6e35c03cb1014a645bd5", - "reference": "38810e97481723ef918f6e35c03cb1014a645bd5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/af91da3f2671006ff5d0628023de3b7ac4d1ef09", + "reference": "af91da3f2671006ff5d0628023de3b7ac4d1ef09", "shasum": "" }, "require": { @@ -1026,7 +1026,7 @@ "ext-xml": "*", "myclabs/deep-copy": "~1.3", "php": "^5.6 || ^7.0", - "phpspec/prophecy": "^1.3.1", + "phpspec/prophecy": "^1.6.2", "phpunit/php-code-coverage": "^4.0.3", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", @@ -1034,9 +1034,9 @@ "phpunit/phpunit-mock-objects": "^3.2", "sebastian/comparator": "~1.2.2", "sebastian/diff": "~1.2", - "sebastian/environment": "^1.3 || ^2.0", + "sebastian/environment": "^1.3.4 || ^2.0", "sebastian/exporter": "~2.0", - "sebastian/global-state": "~1.0", + "sebastian/global-state": "^1.0 || ^2.0", "sebastian/object-enumerator": "~2.0", "sebastian/resource-operations": "~1.0", "sebastian/version": "~1.0|~2.0", @@ -1058,7 +1058,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.6.x-dev" + "dev-master": "5.7.x-dev" } }, "autoload": { @@ -1084,20 +1084,20 @@ "testing", "xunit" ], - "time": "2016-11-28 16:04:24" + "time": "2016-12-13 16:19:44" }, { "name": "phpunit/phpunit-mock-objects", - "version": "3.4.2", + "version": "3.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "90a08f5deed5f7ac35463c161f2e8fa0e5652faf" + "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/90a08f5deed5f7ac35463c161f2e8fa0e5652faf", - "reference": "90a08f5deed5f7ac35463c161f2e8fa0e5652faf", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", + "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", "shasum": "" }, "require": { @@ -1143,7 +1143,7 @@ "mock", "xunit" ], - "time": "2016-11-27 07:52:03" + "time": "2016-12-08 20:27:08" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1660,16 +1660,16 @@ }, { "name": "symfony/yaml", - "version": "v3.2.0", + "version": "v3.2.1", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "f2300ba8fbb002c028710b92e1906e7457410693" + "reference": "a7095af4b97a0955f85c8989106c249fa649011f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/f2300ba8fbb002c028710b92e1906e7457410693", - "reference": "f2300ba8fbb002c028710b92e1906e7457410693", + "url": "https://api.github.com/repos/symfony/yaml/zipball/a7095af4b97a0955f85c8989106c249fa649011f", + "reference": "a7095af4b97a0955f85c8989106c249fa649011f", "shasum": "" }, "require": { @@ -1711,7 +1711,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-11-18 21:17:59" + "time": "2016-12-10 10:07:06" }, { "name": "webmozart/assert", diff --git a/src/BotManager.php b/src/BotManager.php index 90392c9..4c10888 100644 --- a/src/BotManager.php +++ b/src/BotManager.php @@ -172,21 +172,27 @@ public function validateSecret(bool $force = false): self public function validateAndSetWebhook(): self { $webhook = $this->params->getBotParam('webhook'); - $selfcrt = $this->params->getBotParam('selfcrt'); if (empty($webhook) && $this->action->isAction(['set', 'reset'])) { throw new \InvalidArgumentException('Invalid webhook'); } if ($this->action->isAction(['unset', 'reset'])) { - $this->handleOutput($this->telegram->unsetWebHook()->getDescription() . PHP_EOL); + $this->handleOutput($this->telegram->deleteWebhook()->getDescription() . PHP_EOL); // When resetting the webhook, sleep for a bit to prevent too many requests. $this->action->isAction('reset') && sleep(1); } + if ($this->action->isAction(['set', 'reset'])) { + $webhook_params = array_filter([ + 'certificate' => $this->params->getBotParam('certificate'), + 'max_connections' => $this->params->getBotParam('max_connections'), + 'allowed_updates' => $this->params->getBotParam('allowed_updates'), + ]); + $this->handleOutput( - $this->telegram->setWebHook( + $this->telegram->setWebhook( $webhook . '?a=handle&s=' . $this->params->getBotParam('secret'), - $selfcrt + $webhook_params )->getDescription() . PHP_EOL ); } diff --git a/src/Params.php b/src/Params.php index 54bec09..c638af5 100644 --- a/src/Params.php +++ b/src/Params.php @@ -36,7 +36,9 @@ class Params */ private static $valid_extra_bot_params = [ 'webhook', - 'selfcrt', + 'certificate', + 'max_connections', + 'allowed_updates', 'logging', 'admins', 'mysql', @@ -65,7 +67,9 @@ class Params * botname (string) Telegram Bot name * secret (string) Secret string to validate calls * webhook (string) URI of the webhook - * selfcrt (string) Path to the self-signed certificate + * certificate (string) Path to the self-signed certificate + * max_connections (int) Maximum allowed simultaneous HTTPS connections to the webhook + * allowed_updates (array) List the types of updates you want your bot to receive * logging (array) Array of logger files to set. * admins (array) List of admins to enable. * mysql (array) MySQL credentials to use. diff --git a/tests/TelegramBotManager/Tests/BotManagerTest.php b/tests/TelegramBotManager/Tests/BotManagerTest.php index d1758f3..5448cf2 100644 --- a/tests/TelegramBotManager/Tests/BotManagerTest.php +++ b/tests/TelegramBotManager/Tests/BotManagerTest.php @@ -141,7 +141,7 @@ public function testValidateAndSetWebhookSuccess() 'telegram', $this->getMockBuilder(Telegram::class) ->disableOriginalConstructor() - ->setMethods(['setWebHook', 'unsetWebHook', 'getDescription']) + ->setMethods(['setWebhook', 'deleteWebhook', 'getDescription']) ->getMock() ); @@ -149,11 +149,11 @@ public function testValidateAndSetWebhookSuccess() /** @var \PHPUnit_Framework_MockObject_MockObject $telegram */ $telegram->expects(static::any()) - ->method('setWebHook') + ->method('setWebhook') ->with('https://web/hook.php?a=handle&s=secret_12345') ->will(static::returnSelf()); $telegram->expects(static::any()) - ->method('unsetWebHook') + ->method('deleteWebhook') ->will(static::returnSelf()); $telegram->expects(static::any()) ->method('getDescription') @@ -229,7 +229,7 @@ public function testValidateAndSetWebhookSuccessLiveBot() /** * @group live */ - public function testUnsetWebhookViaRunLiveBot() + public function testDeleteWebhookViaRunLiveBot() { $_GET = ['a' => 'unset']; $botManager = new BotManager(array_merge(self::$live_params, [ @@ -386,7 +386,7 @@ public function testGetUpdatesLiveBot() public function testGetUpdatesLoopLiveBot() { // Webhook must NOT be set for this to work! - $this->testUnsetWebhookViaRunLiveBot(); + $this->testDeleteWebhookViaRunLiveBot(); // Looping for 5 seconds should be enough to get a result. $_GET = ['l' => 5]; diff --git a/tests/TelegramBotManager/Tests/ParamsTest.php b/tests/TelegramBotManager/Tests/ParamsTest.php index df21a63..c668644 100644 --- a/tests/TelegramBotManager/Tests/ParamsTest.php +++ b/tests/TelegramBotManager/Tests/ParamsTest.php @@ -28,7 +28,9 @@ class ParamsTest extends \PHPUnit_Framework_TestCase */ public static $demo_extra_params = [ 'webhook' => 'https://php.telegram.bot/manager.php', - 'selfcrt' => __DIR__ . '/server.crt', + 'certificate' => __DIR__ . '/server.crt', + 'max_connections' => 20, + 'allowed_updates' => ['message', 'edited_channel_post', 'callback_query'], 'admins' => [1], 'mysql' => [ 'host' => '127.0.0.1',