From 4cd67cebd9664cbc275d8b3e116d9632ca54773a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Mon, 4 Jul 2016 00:26:19 +0200 Subject: [PATCH 1/2] Return an empty response when an empty inline query is passed. --- src/Commands/SystemCommands/InlinequeryCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Commands/SystemCommands/InlinequeryCommand.php b/src/Commands/SystemCommands/InlinequeryCommand.php index 535c0cb36..481f62082 100644 --- a/src/Commands/SystemCommands/InlinequeryCommand.php +++ b/src/Commands/SystemCommands/InlinequeryCommand.php @@ -25,7 +25,7 @@ class InlinequeryCommand extends SystemCommand */ protected $name = 'inlinequery'; protected $description = 'Reply to inline query'; - protected $version = '1.0.1'; + protected $version = '1.0.2'; /**#@-*/ /** @@ -37,6 +37,10 @@ public function execute() $inline_query = $update->getInlineQuery(); $query = $inline_query->getQuery(); + if ($query === '') { + return Request::emptyResponse(); + } + $data['inline_query_id'] = $inline_query->getId(); $articles = [ From 2e6f8688fb85d8cd5ab3e836aa95903b0eea6e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Tue, 5 Jul 2016 16:28:17 +0200 Subject: [PATCH 2/2] If no query is entered, just return an empty result. --- .../SystemCommands/InlinequeryCommand.php | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Commands/SystemCommands/InlinequeryCommand.php b/src/Commands/SystemCommands/InlinequeryCommand.php index 481f62082..eb7b2e5bb 100644 --- a/src/Commands/SystemCommands/InlinequeryCommand.php +++ b/src/Commands/SystemCommands/InlinequeryCommand.php @@ -37,23 +37,22 @@ public function execute() $inline_query = $update->getInlineQuery(); $query = $inline_query->getQuery(); - if ($query === '') { - return Request::emptyResponse(); + $data = ['inline_query_id' => $inline_query->getId()]; + $results = []; + + if ($query !== '') { + $articles = [ + ['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query, 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])], + ['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query, 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])], + ['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query, 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])], + ]; + + foreach ($articles as $article) { + $results[] = new InlineQueryResultArticle($article); + } } - $data['inline_query_id'] = $inline_query->getId(); - - $articles = [ - ['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])], - ['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])], - ['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])], - ]; - - $array_article = []; - foreach ($articles as $article) { - $array_article[] = new InlineQueryResultArticle($article); - } - $data['results'] = '[' . implode(',', $array_article) . ']'; + $data['results'] = '[' . implode(',', $results) . ']'; return Request::answerInlineQuery($data); }