Skip to content

Commit

Permalink
Merge branch 'luckyraul-dialogflow_lang' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Apr 3, 2018
2 parents a4d0377 + b27cd07 commit b0d561d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Middleware/ApiAi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class ApiAi implements MiddlewareInterface
/** @var string */
protected $token;

/** @var string */
protected $lang = 'en';

/** @var HttpInterface */
protected $http;

Expand All @@ -29,24 +32,27 @@ class ApiAi implements MiddlewareInterface
protected $listenForAction = false;

/**
* API.ai constructor.
* Wit constructor.
* @param string $token api.ai access token
* @param string $lang language
* @param HttpInterface $http
*/
public function __construct($token, HttpInterface $http)
public function __construct($token, HttpInterface $http, $lang = 'en')
{
$this->token = $token;
$this->lang = $lang;
$this->http = $http;
}

/**
* Create a new API.ai middleware instance.
* @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());
return new static($token, new Curl(), $lang);
}

/**
Expand All @@ -71,7 +77,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',
Expand Down

0 comments on commit b0d561d

Please sign in to comment.