From 8d9d11aff30ddfbd3c44355b0219003eb89bd3ec Mon Sep 17 00:00:00 2001 From: Nikita Tarasov Date: Fri, 5 Jan 2018 23:23:11 +0300 Subject: [PATCH 1/3] resolve #678 --- src/Middleware/ApiAi.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Middleware/ApiAi.php b/src/Middleware/ApiAi.php index 183e53f8..26142d10 100644 --- a/src/Middleware/ApiAi.php +++ b/src/Middleware/ApiAi.php @@ -30,21 +30,24 @@ class ApiAi implements MiddlewareInterface /** * Wit constructor. - * @param string $token wit.ai access token + * @param string $token api.ai access token + * @param string $lang language * @param HttpInterface $http */ - public function __construct($token, HttpInterface $http) + public function __construct($token, $lang = 'en', HttpInterface $http) { $this->token = $token; - $this->http = $http; + $this->lang = $lang; + $this->http = $http; } /** * Create a new Wit middleware instance. - * @param string $token wit.ai access token + * @param string $token api.ai access token + * @param string $lang language * @return ApiAi */ - public static function create($token) + public static function create($token, $lang = 'en') { return new static($token, new Curl()); } @@ -71,7 +74,7 @@ protected function getResponse(IncomingMessage $message) $response = $this->http->post($this->apiUrl, [], [ 'query' => [$message->getText()], 'sessionId' => md5($message->getConversationIdentifier()), - 'lang' => 'en', + 'lang' => $this->lang, ], [ 'Authorization: Bearer '.$this->token, 'Content-Type: application/json; charset=utf-8', From 56bd164f95ebdfd7c7dd104fd8856c99c641fe14 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 9 Jan 2018 20:04:55 +0300 Subject: [PATCH 2/3] fix constuct parameter --- src/Middleware/ApiAi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Middleware/ApiAi.php b/src/Middleware/ApiAi.php index 26142d10..94ac7fd7 100644 --- a/src/Middleware/ApiAi.php +++ b/src/Middleware/ApiAi.php @@ -49,7 +49,7 @@ public function __construct($token, $lang = 'en', HttpInterface $http) */ public static function create($token, $lang = 'en') { - return new static($token, new Curl()); + return new static($token, $lang, new Curl()); } /** From 7b022cd84ed5036979df7840802061a2a13942e3 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 9 Jan 2018 21:41:19 +0300 Subject: [PATCH 3/3] tests --- src/Middleware/ApiAi.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Middleware/ApiAi.php b/src/Middleware/ApiAi.php index 94ac7fd7..f200cf6b 100644 --- a/src/Middleware/ApiAi.php +++ b/src/Middleware/ApiAi.php @@ -34,11 +34,11 @@ class ApiAi implements MiddlewareInterface * @param string $lang language * @param HttpInterface $http */ - public function __construct($token, $lang = 'en', HttpInterface $http) + public function __construct($token, HttpInterface $http, $lang = 'en') { $this->token = $token; - $this->lang = $lang; - $this->http = $http; + $this->lang = $lang; + $this->http = $http; } /** @@ -49,7 +49,7 @@ public function __construct($token, $lang = 'en', HttpInterface $http) */ public static function create($token, $lang = 'en') { - return new static($token, $lang, new Curl()); + return new static($token, new Curl(), $lang); } /**