1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tgallice\Wit; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\ResponseInterface; |
6
|
|
|
use Tgallice\Wit\Model\Context; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @deprecated This class is deprecated as of 0.1 and will be removed in 1.0. |
10
|
|
|
*/ |
11
|
|
|
class Api |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Client client |
15
|
|
|
*/ |
16
|
|
|
private $client; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var MessageApi |
20
|
|
|
*/ |
21
|
|
|
private $messageApi; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var SpeechApi |
25
|
|
|
*/ |
26
|
|
|
private $speechApi; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ConverseApi |
30
|
|
|
*/ |
31
|
|
|
private $converseApi; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param Client $client |
35
|
|
|
*/ |
36
|
|
|
public function __construct(Client $client) |
37
|
|
|
{ |
38
|
|
|
$this->client = $client; |
39
|
|
|
$this->messageApi = new MessageApi($client); |
40
|
|
|
$this->speechApi = new SpeechApi($client); |
41
|
|
|
$this->converseApi = new ConverseApi($client); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @deprecated This method is deprecated as of 0.1 and will be removed in 1.0. |
46
|
|
|
* You should use the ConverseApi::converse() instead |
47
|
|
|
* |
48
|
|
|
* @param string $sessionId |
49
|
|
|
* @param string $text |
50
|
|
|
* @param Context|null $context |
51
|
|
|
* |
52
|
|
|
* @return array|null |
53
|
|
|
*/ |
54
|
|
|
public function getConverseNextStep($sessionId, $text, Context $context = null) |
55
|
|
|
{ |
56
|
|
|
return $this->converseApi->converse($sessionId, $text, $context); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @deprecated This method is deprecated as of 0.1 and will be removed in 1.0. |
61
|
|
|
* You should use the MessageApi::extractMeaning() instead |
62
|
|
|
* |
63
|
|
|
* @param string $text |
64
|
|
|
* @param Context|null $context |
65
|
|
|
* @param array $extraParams |
66
|
|
|
* |
67
|
|
|
* @return array|null |
68
|
|
|
*/ |
69
|
|
|
public function getIntentByText($text, Context $context = null, array $extraParams = []) |
70
|
|
|
{ |
71
|
|
|
return $this->messageApi->extractMeaning($text, $context, $extraParams); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @deprecated This method is deprecated as of 0.1 and will be removed in 1.0. |
76
|
|
|
* You should use the SpeechApi::extractMeaning() instead |
77
|
|
|
* |
78
|
|
|
* @param string|resource $file |
79
|
|
|
* @param array|null $context |
80
|
|
|
* @param array $queryParams |
81
|
|
|
* |
82
|
|
|
* @return array|null |
83
|
|
|
*/ |
84
|
|
|
public function getIntentBySpeech($file, Context $context = null, array $queryParams = []) |
85
|
|
|
{ |
86
|
|
|
return $this->speechApi->extractMeaning($file, $context, $queryParams); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @deprecated This method is deprecated as of 0.1 and will be removed in 1.0. |
91
|
|
|
* |
92
|
|
|
* @param string $messageId |
93
|
|
|
* |
94
|
|
|
* @return array|null |
95
|
|
|
*/ |
96
|
|
|
public function getMessage($messageId) |
97
|
|
|
{ |
98
|
|
|
$response = $this->client->get(sprintf('/messages/%s', $messageId)); |
99
|
|
|
|
100
|
|
|
return $this->decodeResponse($response); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return Client |
105
|
|
|
*/ |
106
|
|
|
public function getClient() |
107
|
|
|
{ |
108
|
|
|
return $this->client; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @deprecated This method is deprecated as of 0.1 and will be removed in 1.0. |
113
|
|
|
* You should use the ResponseHandler::decodeResponse() instead |
114
|
|
|
* |
115
|
|
|
* @param ResponseInterface $response |
116
|
|
|
* |
117
|
|
|
* @return array|null |
118
|
|
|
*/ |
119
|
|
|
protected function decodeResponse(ResponseInterface $response) |
120
|
|
|
{ |
121
|
|
|
return json_decode((string) $response->getBody(), true); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.