|
1 | 1 | # Recast.AI - SDK PHP |
2 | 2 |
|
3 | | -[logo]: https://github.com/RecastAI/SDK-NodeJs/blob/master/misc/logo-inline.png "Recast.AI" |
| 3 | +[logo]: https://github.com/RecastAI/SDK-PHP/blob/develop/misc/logo-inline.png "Recast.AI" |
4 | 4 |
|
5 | 5 | ![alt text][logo] |
6 | 6 |
|
7 | 7 | Recast.AI official SDK in PHP |
8 | 8 |
|
9 | 9 | ## Synospis |
10 | 10 |
|
11 | | -This module is a PHP interface to the [Recast.AI](https://recast.ai) API. It allows you to make request to your bots |
| 11 | +This module is a wrapper around the [Recast.AI](https://recast.ai) API, and allows you to: |
| 12 | +* [build a bot](https://github.com/RecastAI/SDK-PHP/wiki/Build-your-bot) |
| 13 | +* [analyze your text](https://github.com/RecastAI/SDK-PHP/wiki/Analyse-text) |
12 | 14 |
|
13 | 15 | ## Installation |
14 | 16 |
|
15 | 17 | ```bash |
16 | 18 | composer require recastai/sdk-php |
17 | 19 | ``` |
18 | 20 |
|
19 | | -## Usage |
| 21 | +## Documentation |
20 | 22 |
|
21 | | - |
22 | | -```php |
23 | | -<?php |
24 | | -use client\Client; |
25 | | - |
26 | | -require 'client.php'; |
27 | | - |
28 | | -$client = new Client(YOUR_TOKEN, YOUR_LANGUAGE); |
29 | | - |
30 | | -$res = $client->textRequest(YOUR_TEXT); |
31 | | -YOUR_INTENT = $res->intent(); |
32 | | -// Do your code... |
33 | | - |
34 | | -?> |
35 | | -``` |
| 23 | +You can find the full documentation [here](https://github.com/RecastAI/SDK-PHP/wiki). |
36 | 24 |
|
37 | 25 | ## Specs |
38 | 26 |
|
39 | | -### Classes |
40 | | - |
41 | | -This module contains 4 classes, as follows: |
42 | | - |
43 | | -* Client is the client allowing you to make requests. |
44 | | -* Response contains the response from [Recast.AI](https://recast.ai). |
45 | | -* Entity represents an entity found by Recast.AI in your user's input. |
46 | | -* RecastError is the error returned by the module. |
47 | | - |
48 | | -Don't hesitate to dive into the code, it's commented ;) |
49 | | - |
50 | | -## class Client |
51 | | - |
52 | | -The Client can be instanciated with a token and a language (both optional). |
53 | | - |
54 | | -```php |
55 | | -$client = new Client(YOUR_TOKEN, YOUR_LANGUAGE); |
56 | | -``` |
57 | | - |
58 | | -__Your tokens:__ |
59 | | - |
60 | | -[token]: https://github.com/RecastAI/SDK-NodeJs/blob/master/misc/recast-ai-tokens.png "Tokens" |
61 | | - |
62 | | -![alt text][token] |
63 | | - |
64 | | -*Copy paste your request access token from your bot's settings.* |
65 | | - |
66 | | -__Your language__ |
67 | | - |
68 | | -```php |
69 | | -$client = new Client(YOUR_TOKEN, 'en'); |
70 | | -``` |
71 | | -*The language is a lowercase 639-1 isocode.* |
72 | | - |
73 | | -## Text Request |
74 | | - |
75 | | -textRequest(text, options = { token: YOUR_TOKEN, language: YOUR_LANGUAGE, proxy: YOUR_URL_PROXY }) |
76 | | - |
77 | | -If your pass a token or a language in the options parameter, it will override your default client language or token. |
78 | | -You can pass a proxy url in the options if needed. |
79 | | - |
80 | | -```php |
81 | | -$res = $client->textRequest(YOUR_TEXT); |
82 | | -// Do your code...¯ |
83 | | - |
84 | | -}) |
85 | | -``` |
86 | | - |
87 | | -```php |
88 | | -// With optional parameters |
89 | | - |
90 | | -$options = array('language' => 'YOUR_LANGUAGE', 'token' => 'YOUR_TOKEN'); |
91 | | - |
92 | | -$res = $client->textRequest(YOUR_TEXT, $options); |
93 | | - |
94 | | -// Do your code... |
95 | | - |
96 | | -``` |
97 | | - |
98 | | -__If a language is provided:__ the language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used. |
99 | | - |
100 | | -__If no language is provided:__ the language of the text is detected and is used for processing if your bot has expressions for it, else your bot's primary language is used for processing. |
101 | | - |
102 | | -## File Request |
103 | | - |
104 | | -fileRequest(file, callback, options = { token: YOUR_TOKEN, language: YOUR_LANGUAGE, proxy: YOUR_PROXY_URL }) |
105 | | - |
106 | | -If your pass a token or a language in the options parameter, it will override your default client language or token. |
107 | | -You can pass a proxy url in the options if needed. |
108 | | - |
109 | | -__file format: .wav__ |
110 | | - |
111 | | -```php |
112 | | -$res = $client->fileRequest('myFile.wav'); |
113 | | - |
114 | | -// Do your code... |
115 | | - |
116 | | -}) |
117 | | -``` |
118 | | - |
119 | | -```php |
120 | | -$options = array('language' => 'en', 'token' => YOUR_TOKEN); |
121 | | - |
122 | | -$res = $client->fileRequest('myFile.wav', $options); |
123 | | - // Do your code... |
124 | | - |
125 | | -``` |
126 | | - |
127 | | -__If a language is provided:__ |
128 | | -Your bot's primary language is used for processing as we do not provide language detection for speech. |
129 | | - |
130 | | -__If no language is provided:__ |
131 | | -The language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used |
132 | | - |
133 | | -## class Response |
134 | | - |
135 | | -The Response is generated after a call to either fileRequest or textRequest. |
136 | | - |
137 | | -### Get the first detected intent |
138 | | - |
139 | | -| Method | Params | Return | |
140 | | -| ------------- |:------:| :-------------------------| |
141 | | -| intent() | | the first detected intent | |
142 | | - |
143 | | -```php |
144 | | -$res = $client->textRequest($text); |
145 | | -$lol = $res->intent(); |
146 | | - |
147 | | -if ($result->slug == 'weather') { |
148 | | - // Do your code... |
149 | | -} |
150 | | - |
151 | | -``` |
152 | | - |
153 | | -### Get one entity |
154 | | - |
155 | | -| Method | Params | Return | |
156 | | -| ------------- |:-------------:| :-------------------------| |
157 | | -| get(name) | name: String | the first Entity matched | |
158 | | - |
159 | | - |
160 | | -```php |
161 | | -$res = $client->textRequest($text); |
162 | | - |
163 | | -$result = $res->get('location'); |
164 | | - |
165 | | -``` |
166 | | - |
167 | | -### Get all entities matching name |
168 | | - |
169 | | -| Method | Params | Return | |
170 | | -| ------------- |:-------------:| :-------------------------| |
171 | | -| all(name) | name: String | all the Entities matched | |
172 | | - |
173 | | - |
174 | | -```php |
175 | | -$res = $client->textRequest($text); |
176 | | - |
177 | | -$lol = $res->all('location'); |
178 | | - |
179 | | -``` |
180 | | - |
181 | | -### Getters |
182 | | - |
183 | | -Each of the following methods corresponds to a Response attribute |
184 | | - |
185 | | -| Method | Params | Return | |
186 | | -| ----------- |:------:| :---------------------------------------------------| |
187 | | -| raw | | String: the raw unparsed json response | |
188 | | -| source | | String: the user input | |
189 | | -| intents | | Array[object]: all the matched intents | |
190 | | -| sentences | | Array[Sentence]: all the detected sentences | |
191 | | -| version | | String: the version of the json | |
192 | | -| timestamp | | String: the timestamp at the end of the processing | |
193 | | -| status | | String: the status of the response | |
194 | | -| type | | String: the type of the response | |
195 | | - |
196 | | - |
197 | | -## class Entity |
198 | | - |
199 | | -The Entity is generated by the Sentence constructor. |
200 | | - |
201 | | -### Getters |
202 | | - |
203 | | -Each of the following methods corresponds to a Response attribute |
204 | | - |
205 | | -| Attributes | Description | |
206 | | -| ----------- |:--------------------------------------------------------------| |
207 | | -| name | String: the name of the entity | |
208 | | -| raw | String: the unparsed json value of the entity | |
209 | | - |
210 | | -In addition to those methods, more attributes are generated depending of the nature of the entity. |
211 | | -The full list can be found there: [man.recast.ai](https://man.recast.ai/#list-of-entities) |
212 | | - |
213 | | -```php |
214 | | -$res = $client->textRequest($text); |
215 | | - |
216 | | -$result = $res->get('location'); |
217 | | - |
218 | | -var_dump($result->slug); |
219 | | -var_dump($result->raw); |
220 | | -``` |
221 | | - |
222 | | -## class RecastError |
223 | | - |
224 | | -The Recast.AI Error is thrown when receiving an non-200 response from Recast.AI. |
| 27 | +This module contains 5 classes, as follows: |
225 | 28 |
|
226 | | -As it inherits from Error, it implements the default Error methods. |
| 29 | +* [Client](https://github.com/RecastAI/SDK-PHP/wiki/Class-Client) is the client allowing you to make requests. |
| 30 | +* [Conversation](https://github.com/RecastAI/SDK-PHP/wiki/Class-Conversation) wraps the response from a call to [Recast.AI](https://recast.ai) API with the textConverse Client method. |
| 31 | +* [Response](https://github.com/RecastAI/SDK-PHP/wiki/Class-Response) wraps the response from a call to [Recast.AI](https://recast.ai) API with the textRequest or fileRequest Client methods. |
| 32 | +* [Entity](https://github.com/RecastAI/SDK-PHP/wiki/Class-Entity) represents an entity extracted from an input. |
227 | 33 |
|
228 | 34 | ## More |
229 | 35 |
|
|
0 commit comments