Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit 1ea76e6

Browse files
author
Bruno
committed
[ADD] add sdk php on github recast
0 parents  commit 1ea76e6

File tree

16 files changed

+1013
-0
lines changed

16 files changed

+1013
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vendor/
2+
composer.lock
3+
composer.phar
4+
.DS_Store
5+
node_modules
6+
file.wav

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Gantelmi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
# Recast.AI - SDK PHP
2+
3+
[logo]: https://github.com/RecastAI/SDK-NodeJs/blob/master/misc/logo-inline.png "Recast.AI"
4+
5+
![alt text][logo]
6+
7+
Recast.AI official SDK in PHP
8+
9+
## Synospis
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
12+
13+
## Installation
14+
15+
```bash
16+
composer require recastai/sdk-php
17+
```
18+
19+
## Usage
20+
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+
```
36+
37+
## Specs
38+
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.
225+
226+
As it inherits from Error, it implements the default Error methods.
227+
228+
## More
229+
230+
You can view the whole API reference at [man.recast.ai](https://man.recast.ai).
231+
232+
## Author
233+
234+
Bruno Gantelmi, bruno.gantelmi@recast.ai
235+
236+
You can follow us on Twitter at [@recastai](https://twitter.com/recastai) for updates and releases.
237+
238+
## License
239+
240+
Copyright (c) [2016] [Recast.AI](https://recast.ai)
241+
242+
Permission is hereby granted, free of charge, to any person obtaining a copy
243+
of this software and associated documentation files (the "Software"), to deal
244+
in the Software without restriction, including without limitation the rights
245+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
246+
copies of the Software, and to permit persons to whom the Software is
247+
furnished to do so, subject to the following conditions:
248+
249+
The above copyright notice and this permission notice shall be included in all
250+
copies or substantial portions of the Software.
251+
252+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
253+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
254+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
255+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
256+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
257+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
258+
SOFTWARE.

composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "recastai/sdk-php",
3+
"description": "The official PHP SDK Recast.ai",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Bruno",
8+
"email": "bruno.gantelmi@recast.ai"
9+
}
10+
],
11+
"minimum-stability": "dev",
12+
"require": {
13+
"php": "^5.3.3 || ^7.0",
14+
"rmccue/requests": "dev-master",
15+
"guzzlehttp/guzzle": "^6.2@dev"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "3.7.*"
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"SDK-PHP\\": "src/",
23+
"client\\": "tests/"
24+
}
25+
}
26+
}

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "sdkphp",
3+
"version": "1.0.0",
4+
"description": "[logo]: https://github.com/RecastAI/SDK-NodeJs/blob/master/misc/logo-inline.png \"Recast.AI\"",
5+
"main": "index.js",
6+
"directories": {
7+
"test": "tests"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1",
11+
"doc": "./node_modules/apidoc/bin/apidoc -i src/ -o doc/"
12+
},
13+
"apidoc": {
14+
"name": "php sdk API doc",
15+
"version": "0.1.0",
16+
"description": "apiDoc php sdk recast",
17+
"apidoc": {
18+
"title": "php sdk recast"
19+
}
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/bgantelm/SDK-PHP.git"
24+
},
25+
"author": "",
26+
"license": "ISC",
27+
"bugs": {
28+
"url": "https://github.com/bgantelm/SDK-PHP/issues"
29+
},
30+
"homepage": "https://github.com/bgantelm/SDK-PHP#readme"
31+
}

phpunit.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit colors="true">
3+
<testsuites>
4+
<testsuite name="Recast PHP SDK Test Suite">
5+
<directory>./tests/</directory>
6+
</testsuite>
7+
</testsuites>
8+
</phpunit>

0 commit comments

Comments
 (0)