Skip to content

Commit e9d4e92

Browse files
sirtorrybshaffer
authored andcommitted
Dialogflow samples (GoogleCloudPlatform#600)
1 parent d6e61a7 commit e9d4e92

36 files changed

+4242
-0
lines changed

dialogflow/README.md

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
# Dialogflow: PHP Samples
2+
3+
[![Open in Cloud Shell][shell_img]][shell_link]
4+
5+
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png
6+
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googlecloudplatform/php-docs-samples&page=editor&working_dir=dialogflow
7+
8+
## Description
9+
10+
This simple command-line application demonstrates how to invoke Dialogflow
11+
API from PHP.
12+
13+
## Before you begin
14+
1. Follow the first 2 steps of [this quickstart](https://cloud.google.com/dialogflow-enterprise/docs/quickstart).
15+
Feel free to stop after you've created an agent.
16+
17+
2. This sample comes with a [sample agent](https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/dialogflow/resources/RoomReservation.zip) which you can use to try the samples with. Follow the instructions on [this page](https://dialogflow.com/docs/best-practices/import-export-for-versions) to import the agent from the [console](https://console.dialogflow.com/api-client).
18+
> WARNING: Importing the sample agent will add intents and entities to your Dialogflow agent. You might want to use a different Google Cloud Platform Project, or export your Dialogflow agent before importing the sample agent to save a version of your agent before the sample agent was imported.
19+
20+
3. Clone the repo and cd into this directory
21+
```
22+
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
23+
$ cd php-docs-samples/dialogflow
24+
```
25+
26+
4. Follow [this guide](https://cloud.google.com/php/grpc) to install gRPC for PHP.
27+
28+
5. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
29+
Run `php composer.phar install` (if composer is installed locally) or `composer install`
30+
(if composer is installed globally).
31+
32+
## Samples
33+
34+
```
35+
usage: php dialogflow.php command [options] [arguments]
36+
```
37+
38+
### Detect intent (texts)
39+
```
40+
DialogFlow API detect intent PHP sample with text inputs.
41+
42+
Usage:
43+
php dialogflow.php detect-intent-texts [options] ()...
44+
45+
Examples:
46+
php dialogflow.php detect-intent-texts -h
47+
php dialogflow.php detect-intent-texts PROJECT_ID "hello" "book a meeting room" "Mountain View"
48+
php dialogflow.php detect-intent-texts -s SESSION_ID PROJECT_ID "tomorrow" "10 AM" "2 hours" "10 people" "A" "yes"
49+
50+
Command:
51+
detect-intent-texts
52+
53+
Arguments:
54+
PROJECT_ID project/agent id.
55+
texts array of text inputs separated by space.
56+
57+
Options:
58+
-s SESSION_ID identifier of DetectIntent session. defaults to random.
59+
-l LANGUAGE_CODE language code of the query. defaults to "en-US".
60+
61+
```
62+
63+
### Detect intent (audio)
64+
```
65+
DialogFlow API detect intent PHP sample with audio file.
66+
67+
Usage:
68+
php dialogflow.php detect-intent-audio [options]
69+
70+
Examples:
71+
php dialogflow.php detect-intent-audio -h
72+
php dialogflow.php detect-intent-audio PROJECT_ID resources/book_a_room.wav
73+
php dialogflow.php detect-intent-audio -s SESSION_ID PROJECT_ID resources/mountain_view.wav
74+
75+
Command:
76+
detect-intent-audio
77+
78+
Arguments:
79+
PROJECT_ID project/agent id.
80+
AUDIO_FILE_PATH path to audio file.
81+
82+
Options:
83+
-s SESSION_ID identifier of DetectIntent session. defaults to random.
84+
-l LANGUAGE_CODE language code of the query. defaults to "en-US".
85+
86+
```
87+
88+
### Detect intent (streaming)
89+
```
90+
DialogFlow API detect intent PHP sample with audio file processed as an audio stream.
91+
92+
Usage:
93+
php dialogflow.php detect-intent-stream [options]
94+
95+
Examples:
96+
php dialogflow.php detect-intent-stream -h
97+
php dialogflow.php detect-intent-stream PROJECT_ID resources/book_a_room.wav
98+
php dialogflow.php detect-intent-stream -s SESSION_ID PROJECT_ID resources/mountain_view.wav
99+
100+
Command:
101+
detect-intent-stream
102+
103+
Arguments:
104+
PROJECT_ID project/agent id.
105+
AUDIO_FILE_PATH path to audio file.
106+
107+
Options:
108+
-s SESSION_ID id of DetectIntent session. defaults to random.
109+
-l LANGUAGE_CODE language code of the query. defaults to "en-US".
110+
111+
```
112+
113+
### Context management
114+
```
115+
DialogFlow API PHP samples showing how to manage contexts.
116+
117+
Usage:
118+
php dialogflow.php context-list [options]
119+
php dialogflow.php context-create [options]
120+
php dialogflow.php context-delete [options]
121+
122+
Examples:
123+
php dialogflow.php context-create -h
124+
php dialogflow.php context-list -s SESSION_ID PROJECT_ID
125+
php dialogflow.php context-create -s SESSION_ID -l 2 PROJECT_ID test-context-id
126+
php dialogflow.php context-delete -s SESSION_ID PROJECT_ID test-context-id
127+
128+
Commands:
129+
session-entity-type-list
130+
session-entity-type-create
131+
session-entity-type-delete
132+
133+
Arguments:
134+
PROJECT_ID project/agent id.
135+
CONTEXT_ID id of context.
136+
137+
Options:
138+
-s SESSION_ID id of DetectIntent session. required.
139+
-l LIFESPAN_COUNT lifespan count of the context.
140+
141+
```
142+
143+
### Intent management
144+
```
145+
DialogFlow API PHP samples showing how to manage intents.
146+
147+
Usage:
148+
php dialogflow.php intent-list
149+
php dialogflow.php intent-create [options]
150+
php dialogflow.php intent-delete
151+
152+
Examples:
153+
php dialogflow.php intent-create -h
154+
php dialogflow.php intent-list PROJECT_ID
155+
php dialogflow.php intent-create PROJECT_ID "room.cancellation - yes" -t "cancel" -m "are you sure you want to cancel?"
156+
php dialogflow.php intent-delete PROJECT_ID 74892d81-7901-496a-bb0a-c769eda5180e
157+
158+
Commands:
159+
intent-list
160+
intent-create
161+
intent-delete
162+
163+
Arguments:
164+
PROJECT_ID project/agent id.
165+
DISPLAY_NAME display name of intent.
166+
INTENT_ID id of intent.
167+
168+
Options:
169+
-t training_phrase_part training phrase.
170+
-m message_texts message text for the agent's response when intent is detected.
171+
172+
```
173+
174+
### Entity type management
175+
```
176+
DialogFlow API PHP samples showing how to manage entity types.
177+
178+
Usage:
179+
php dialogflow.php entity-type-list
180+
php dialogflow.php entity-type-create [options]
181+
php dialogflow.php entity-type-delete
182+
183+
Examples:
184+
php dialogflow.php entity-type-create -h
185+
php dialogflow.php entity-type-list PROJECT_ID
186+
php dialogflow.php entity-type-create PROJECT_ID employee
187+
php dialogflow.php entity-type-delete PROJECT_ID e57238e2-e692-44ea-9216-6be1b2332e2a
188+
189+
Commands:
190+
entity-type-list
191+
entity-type-create
192+
entity-type-delete
193+
194+
Arguments:
195+
PROJECT_ID project/agent id.
196+
ENTITY_TYPE_DISPLAY_NAME display name of entity type.
197+
ENTITY_TYPE_ID id of entity type.
198+
199+
Option:
200+
-k KIND kind of entity. KIND_MAP (default) or KIND_LIST
201+
202+
```
203+
204+
### Entity management
205+
```
206+
DialogFlow API PHP samples showing how to manage entities.
207+
208+
Usage:
209+
php dialogflow.php entity-list
210+
php dialogflow.php entity-create []...
211+
php dialogflow.php entity-delete
212+
213+
Examples:
214+
php dialogflow.php entity-create -h
215+
php dialogflow.php entity-list PROJECT_ID e57238e2-e692-44ea-9216-6be1b2332e2a
216+
php dialogflow.php entity-create PROJECT_ID e57238e2-e692-44ea-9216-6be1b2332e2a new_room basement cellar
217+
php dialogflow.php entity-delete PROJECT_ID e57238e2-e692-44ea-9216-6be1b2332e2a new_room
218+
219+
Commands:
220+
entity-list
221+
entity-create
222+
entity-delete
223+
224+
Arguments:
225+
PROJECT_ID project/agent id.
226+
ENTITY_TYPE_ID id of entity type.
227+
ENTITY_VALUE value of the entity.
228+
synonyms array of synonyms that will map to provided entity value.
229+
230+
```
231+
232+
### Session entity type management
233+
```
234+
DialogFlow API PHP samples showing how to manage session entity types.
235+
236+
Usage:
237+
php dialogflow.php session-entity-type-list [options]
238+
php dialogflow.php session-entity-type-create [options] ()...
239+
php dialogflow.php session-entity-type-delete [options]
240+
241+
Examples:
242+
php dialogflow.php session-entity-type-create -h
243+
php dialogflow.php session-entity-type-list -s SESSION_ID PROJECT_ID
244+
php dialogflow.php session-entity-type-create -s SESSION_ID PROJECT_ID room c d e f
245+
php dialogflow.php session-entity-type-delete -s SESSION_ID PROJECT_ID room
246+
247+
Commands:
248+
session-entity-type-list
249+
session-entity-type-create
250+
session-entity-type-delete
251+
252+
Arguments:
253+
PROJECT_ID project/agent id.
254+
ENTITY_TYPE_DISPLAY_NAME display name of entity type.
255+
entity_value array of entity values separated by space.
256+
257+
Options:
258+
-s SESSION_ID id of DetectIntent session. required.
259+
260+
```
261+
262+
## The client library
263+
264+
This sample uses the [Google Cloud Client Library for PHP][google-cloud-php].
265+
You can read the documentation for more details on API usage and use GitHub
266+
to [browse the source][google-cloud-php-source] and [report issues][google-cloud-php-issues].
267+
268+
## Troubleshooting
269+
270+
If you get the following error, set the environment variable `GCLOUD_PROJECT` to your project ID:
271+
272+
```
273+
[Google\Cloud\Core\Exception\GoogleException]
274+
No project ID was provided, and we were unable to detect a default project ID.
275+
```
276+
277+
If you have not set a timezone you may get an error from php. This can be resolved by:
278+
279+
1. Finding where the php.ini is stored by running `php -i | grep 'Configuration File'`
280+
1. Finding out your timezone from the list on this page: http://php.net/manual/en/timezones.php
281+
1. Editing the php.ini file (or creating one if it doesn't exist)
282+
1. Adding the timezone to the php.ini file e.g., adding the following line: `date.timezone = "America/Los_Angeles"`
283+
284+
[google-cloud-php]: https://googlecloudplatform.github.io/google-cloud-php
285+
[google-cloud-php-source]: https://github.com/GoogleCloudPlatform/google-cloud-php
286+
[google-cloud-php-issues]: https://github.com/GoogleCloudPlatform/google-cloud-php/issues

dialogflow/composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"require": {
3+
"google/cloud-dialogflow": "^0.1",
4+
"symfony/console": "^3.1"
5+
},
6+
"autoload": {
7+
"psr-4": {
8+
"Google\\Cloud\\Samples\\Dialogflow\\": "src/"
9+
},
10+
"files": [
11+
"src/detect_intent_audio.php",
12+
"src/detect_intent_stream.php",
13+
"src/detect_intent_texts.php",
14+
"src/entity_create.php",
15+
"src/entity_delete.php",
16+
"src/entity_list.php",
17+
"src/entity_type_delete.php",
18+
"src/entity_type_create.php",
19+
"src/entity_type_list.php",
20+
"src/intent_create.php",
21+
"src/intent_delete.php",
22+
"src/intent_list.php",
23+
"src/context_create.php",
24+
"src/context_delete.php",
25+
"src/context_list.php",
26+
"src/session_entity_type_create.php",
27+
"src/session_entity_type_delete.php",
28+
"src/session_entity_type_list.php"
29+
]
30+
},
31+
"require-dev": {
32+
"phpunit/phpunit": "~4"
33+
}
34+
}

0 commit comments

Comments
 (0)