diff --git a/CHANGELOG.md b/CHANGELOG.md index 65bd1ea9b..d18ef4f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,12 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c - [:ledger: View file changes][Unreleased] ### Added ### Changed +- Small readme and code fixes / simplifications. ### Deprecated ### Removed ### Fixed - Boolean value for Polls gets saved correctly in MySQL DB. +- Correctly use `Request::answerInlineQuery` in `InlineQuery::answer`. ### Security ## [0.60.0] - 2019-08-16 diff --git a/README.md b/README.md index 0ae67a853..e75389738 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Telegram announced official support for a [Bot API](https://telegram.org/blog/bo This Bot aims to provide a platform where one can simply write a bot and have interactions in a matter of minutes. The Bot can: -- Retrieve updates with [webhook][#webhook-installation] and [getUpdates][#getupdates-installation] methods. +- Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods. - Supports all types and methods according to Telegram API 4.4 (July 2019). - Supports supergroups. - Handle commands in chat with other bots. diff --git a/composer.json b/composer.json index 0ac24ecea..e89d84d6a 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "ext-json": "*", "ext-mbstring": "*", "psr/log": "^1.1", - "monolog/monolog": "^1.24", + "monolog/monolog": "^1.25", "guzzlehttp/guzzle": "^6.3" }, "require-dev": { diff --git a/composer.lock b/composer.lock index cb7f6d9b4..6730372cc 100644 --- a/composer.lock +++ b/composer.lock @@ -124,33 +124,37 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.5.2", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "9f83dded91781a01c63574e387eaa769be769115" + "reference": "239400de7a173fe9901b9ac7c06497751f00727a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", - "reference": "9f83dded91781a01c63574e387eaa769be769115", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", + "reference": "239400de7a173fe9901b9ac7c06497751f00727a", "shasum": "" }, "require": { "php": ">=5.4.0", "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5" + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { + "ext-zlib": "*", "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" }, + "suggest": { + "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5-dev" + "dev-master": "1.6-dev" } }, "autoload": { @@ -187,20 +191,20 @@ "uri", "url" ], - "time": "2018-12-04T20:46:45+00:00" + "time": "2019-07-01T23:21:34+00:00" }, { "name": "monolog/monolog", - "version": "1.24.0", + "version": "1.25.1", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266" + "reference": "70e65a5470a42cfec1a7da00d30edb6e617e8dcf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", - "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/70e65a5470a42cfec1a7da00d30edb6e617e8dcf", + "reference": "70e65a5470a42cfec1a7da00d30edb6e617e8dcf", "shasum": "" }, "require": { @@ -265,7 +269,7 @@ "logging", "psr-3" ], - "time": "2018-11-05T09:00:11+00:00" + "time": "2019-09-06T13:49:17+00:00" }, { "name": "psr/http-message", @@ -608,16 +612,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", "shasum": "" }, "require": { @@ -638,8 +642,8 @@ } }, "autoload": { - "psr-0": { - "Prophecy\\": "src/" + "psr-4": { + "Prophecy\\": "src/Prophecy" } }, "notification-url": "https://packagist.org/downloads/", @@ -667,7 +671,7 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "time": "2019-06-13T12:50:23+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1471,16 +1475,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", "shasum": "" }, "require": { @@ -1492,7 +1496,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -1509,12 +1513,12 @@ ], "authors": [ { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" }, { - "name": "Gert de Pagter", - "email": "backendtea@gmail.com" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -1525,20 +1529,20 @@ "polyfill", "portable" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.28", + "version": "v3.4.31", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "212a27b731e5bfb735679d1ffaac82bd6a1dc996" + "reference": "3dc414b7db30695bae671a1d86013d03f4ae9834" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/212a27b731e5bfb735679d1ffaac82bd6a1dc996", - "reference": "212a27b731e5bfb735679d1ffaac82bd6a1dc996", + "url": "https://api.github.com/repos/symfony/yaml/zipball/3dc414b7db30695bae671a1d86013d03f4ae9834", + "reference": "3dc414b7db30695bae671a1d86013d03f4ae9834", "shasum": "" }, "require": { @@ -1584,20 +1588,20 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2019-03-25T07:48:46+00:00" + "time": "2019-08-20T13:31:17+00:00" }, { "name": "webmozart/assert", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", "shasum": "" }, "require": { @@ -1605,8 +1609,7 @@ "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", "extra": { @@ -1635,7 +1638,7 @@ "check", "validate" ], - "time": "2018-12-25T11:19:39+00:00" + "time": "2019-08-24T08:43:50+00:00" } ], "aliases": [], diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 20643cd32..f2a5994f7 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -197,16 +197,7 @@ abstract public function execute(); */ public function executeNoDb() { - //Preparing message - $message = $this->getMessage(); - $chat_id = $message->getChat()->getId(); - - $data = [ - 'chat_id' => $chat_id, - 'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.', - ]; - - return Request::sendMessage($data); + return $this->replyToChat('Sorry no database connection, unable to execute "' . $this->name . '" command.'); } /** diff --git a/src/Commands/SystemCommands/CallbackqueryCommand.php b/src/Commands/SystemCommands/CallbackqueryCommand.php index cedc1f659..da83de99f 100644 --- a/src/Commands/SystemCommands/CallbackqueryCommand.php +++ b/src/Commands/SystemCommands/CallbackqueryCommand.php @@ -11,7 +11,7 @@ namespace Longman\TelegramBot\Commands\SystemCommands; use Longman\TelegramBot\Commands\SystemCommand; -use Longman\TelegramBot\Request; +use Longman\TelegramBot\Entities\ServerResponse; /** * Callback query command @@ -41,21 +41,24 @@ class CallbackqueryCommand extends SystemCommand /** * Command execute method * - * @return mixed + * @return ServerResponse */ public function execute() { - //$callback_query = $this->getUpdate()->getCallbackQuery(); + //$callback_query = $this->getCallbackQuery(); //$user_id = $callback_query->getFrom()->getId(); //$query_id = $callback_query->getId(); //$query_data = $callback_query->getData(); + $answer = null; + $callback_query = $this->getCallbackQuery(); + // Call all registered callbacks. foreach (self::$callbacks as $callback) { - $callback($this->getUpdate()->getCallbackQuery()); + $answer = $callback($callback_query); } - return Request::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]); + return ($answer instanceof ServerResponse) ? $answer : $callback_query->answer(); } /** diff --git a/src/Commands/SystemCommands/InlinequeryCommand.php b/src/Commands/SystemCommands/InlinequeryCommand.php index d73278988..3eb6227cf 100644 --- a/src/Commands/SystemCommands/InlinequeryCommand.php +++ b/src/Commands/SystemCommands/InlinequeryCommand.php @@ -11,7 +11,6 @@ namespace Longman\TelegramBot\Commands\SystemCommands; use Longman\TelegramBot\Commands\SystemCommand; -use Longman\TelegramBot\Request; /** * Inline query command @@ -31,7 +30,7 @@ class InlinequeryCommand extends SystemCommand /** * @var string */ - protected $version = '1.0.0'; + protected $version = '1.0.1'; /** * Command execute method @@ -40,10 +39,10 @@ class InlinequeryCommand extends SystemCommand */ public function execute() { - //$inline_query = $this->getUpdate()->getInlineQuery(); + //$inline_query = $this->getInlineQuery(); //$user_id = $inline_query->getFrom()->getId(); //$query = $inline_query->getQuery(); - return Request::answerInlineQuery(['inline_query_id' => $this->getUpdate()->getInlineQuery()->getId()]); + return $this->getInlineQuery()->answer([]); } } diff --git a/src/Entities/InlineQuery.php b/src/Entities/InlineQuery.php index b90c0bfd8..a6657beff 100644 --- a/src/Entities/InlineQuery.php +++ b/src/Entities/InlineQuery.php @@ -47,7 +47,7 @@ protected function subEntities() */ public function answer(array $results, array $data = []) { - return Request::answerCallbackQuery(array_merge([ + return Request::answerInlineQuery(array_merge([ 'callback_query_id' => $this->getId(), 'results' => $results, ], $data)); diff --git a/src/Entities/Update.php b/src/Entities/Update.php index e2c520cd1..5e35a1117 100644 --- a/src/Entities/Update.php +++ b/src/Entities/Update.php @@ -58,18 +58,7 @@ protected function subEntities() */ public function getUpdateType() { - $types = [ - 'message', - 'edited_message', - 'channel_post', - 'edited_channel_post', - 'inline_query', - 'chosen_inline_result', - 'callback_query', - 'shipping_query', - 'pre_checkout_query', - 'poll', - ]; + $types = array_keys($this->subEntities()); foreach ($types as $type) { if ($this->getProperty($type)) { return $type; diff --git a/src/Telegram.php b/src/Telegram.php index 820a5cfcd..78b8724b8 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -91,7 +91,7 @@ class Telegram /** * MySQL integration * - * @var boolean + * @var bool */ protected $mysql_enabled = false; @@ -126,7 +126,7 @@ class Telegram /** * Check if runCommands() is running in this session * - * @var boolean + * @var bool */ protected $run_commands = false; @@ -494,7 +494,7 @@ public function processUpdate(Update $update) * * @param string $command * - * @return mixed + * @return ServerResponse * @throws TelegramException */ public function executeCommand($command)