Skip to content

Commit e45b74e

Browse files
authored
docs: improved instructions for samples and tests (#41)
1 parent 030ac66 commit e45b74e

File tree

9 files changed

+142
-1
lines changed

9 files changed

+142
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ async function main(
3737

3838
// Imports the Google Cloud Some API library
3939
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
40+
/**
41+
* Example for regional endpoint:
42+
* const location = 'us-central1'
43+
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
44+
*/
4045
const client = new SessionsClient();
4146

4247
const fs = require('fs');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ async function main(
3737

3838
// Imports the Google Cloud Some API library
3939
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
40+
/**
41+
* Example for regional endpoint:
42+
* const location = 'us-central1'
43+
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
44+
*/
4045
const client = new SessionsClient();
4146

4247
const fs = require('fs');
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ async function main(projectId, location, agentId, query, languageCode) {
2222
// const projectId = 'my-project';
2323
// const location = 'global';
2424
// const agentId = 'my-agent';
25-
// const query = ['Hello'];
25+
// const query = 'Hello';
2626
// const languageCode = 'en'
2727

2828
// Imports the Google Cloud Some API library
2929
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
30+
/**
31+
* Example for regional endpoint:
32+
* const location = 'us-central1'
33+
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
34+
*/
3035
const client = new SessionsClient();
3136

3237
async function detectIntentText() {

dialogflow-cx/list-intents.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ async function main(projectId, location, agentId) {
2525

2626
// Imports the Google Cloud Some API library
2727
const {IntentsClient} = require('@google-cloud/dialogflow-cx');
28+
/**
29+
* Example for regional endpoint:
30+
* const location = 'us-central1'
31+
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
32+
*/
2833
const client = new IntentsClient();
2934

3035
async function listIntents() {

dialogflow-cx/quickstart.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ async function main(
3737

3838
// Imports the Google Cloud Some API library
3939
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
40+
/**
41+
* Example for regional endpoint:
42+
* const location = 'us-central1'
43+
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
44+
*/
4045
const client = new SessionsClient();
4146

4247
const fs = require('fs');
30.3 KB
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const execSync = require('child_process').execSync;
20+
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
21+
22+
describe('detect intent with text input', () => {
23+
const cmd = 'node detect-intent-audio.js';
24+
25+
const projectId = process.env.GCLOUD_PROJECT;
26+
const location = 'global';
27+
const agentId = '5d23f659-cd71-43e9-8fb2-b69cd9896370';
28+
const audioFileName = 'resources/book_a_room.wav';
29+
const encoding = 'AUDIO_ENCODING_LINEAR_16';
30+
const sampleRateHertz = 16000;
31+
const languageCode = 'en';
32+
33+
it('should response to "book a room"', async () => {
34+
const output = exec(
35+
`${cmd} ${projectId} ${location} ${agentId} ${audioFileName} ${encoding} ${sampleRateHertz} ${languageCode}`
36+
);
37+
assert.include(output, "Sorry, I didn't get that. Can you rephrase?");
38+
});
39+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const execSync = require('child_process').execSync;
20+
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
21+
22+
describe('detect intent with text input', () => {
23+
const cmd = 'node detect-intent-text.js';
24+
25+
const projectId = process.env.GCLOUD_PROJECT;
26+
const location = 'global';
27+
const agentId = '5d23f659-cd71-43e9-8fb2-b69cd9896370';
28+
const languageCode = 'en';
29+
30+
it('should response to "hello"', async () => {
31+
const output = exec(
32+
`${cmd} ${projectId} ${location} ${agentId} 'hello' ${languageCode}`
33+
);
34+
assert.include(output, 'How can I assist you today?');
35+
});
36+
37+
it('should response to "reserve a vent"', async () => {
38+
const output = exec(
39+
`${cmd} ${projectId} ${location} ${agentId} 'i need to reserve a van' ${languageCode}`
40+
);
41+
assert.include(output, 'Where would you like to pick it up?');
42+
});
43+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const execSync = require('child_process').execSync;
20+
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
21+
22+
describe('list intents', () => {
23+
const cmd = 'node list-intents.js';
24+
25+
const projectId = process.env.GCLOUD_PROJECT;
26+
const location = 'global';
27+
const agentId = '5d23f659-cd71-43e9-8fb2-b69cd9896370';
28+
29+
it('should List the Intents', async () => {
30+
const output = exec(`${cmd} ${projectId} ${location} ${agentId}`);
31+
assert.include(output, 'Default Welcome Intent');
32+
assert.include(output, 'Default Negative Intent');
33+
});
34+
});

0 commit comments

Comments
 (0)