Skip to content

Commit

Permalink
docs: improved instructions for samples and tests (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy-WEI authored and Ace Nassri committed Nov 17, 2022
1 parent 3316e47 commit 810308a
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ async function main(

// Imports the Google Cloud Some API library
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
/**
* Example for regional endpoint:
* const location = 'us-central1'
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
*/
const client = new SessionsClient();

const fs = require('fs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ async function main(

// Imports the Google Cloud Some API library
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
/**
* Example for regional endpoint:
* const location = 'us-central1'
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
*/
const client = new SessionsClient();

const fs = require('fs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ async function main(projectId, location, agentId, query, languageCode) {
// const projectId = 'my-project';
// const location = 'global';
// const agentId = 'my-agent';
// const query = ['Hello'];
// const query = 'Hello';
// const languageCode = 'en'

// Imports the Google Cloud Some API library
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
/**
* Example for regional endpoint:
* const location = 'us-central1'
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
*/
const client = new SessionsClient();

async function detectIntentText() {
Expand Down
5 changes: 5 additions & 0 deletions dialogflow-cx/list-intents.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ async function main(projectId, location, agentId) {

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

async function listIntents() {
Expand Down
5 changes: 5 additions & 0 deletions dialogflow-cx/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ async function main(

// Imports the Google Cloud Some API library
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
/**
* Example for regional endpoint:
* const location = 'us-central1'
* const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
*/
const client = new SessionsClient();

const fs = require('fs');
Expand Down
Binary file added dialogflow-cx/resources/book_a_room.wav
Binary file not shown.
39 changes: 39 additions & 0 deletions dialogflow-cx/test/detect-intent-audio.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {assert} = require('chai');
const {describe, it} = require('mocha');
const execSync = require('child_process').execSync;
const exec = cmd => execSync(cmd, {encoding: 'utf8'});

describe('detect intent with text input', () => {
const cmd = 'node detect-intent-audio.js';

const projectId = process.env.GCLOUD_PROJECT;
const location = 'global';
const agentId = '5d23f659-cd71-43e9-8fb2-b69cd9896370';
const audioFileName = 'resources/book_a_room.wav';
const encoding = 'AUDIO_ENCODING_LINEAR_16';
const sampleRateHertz = 16000;
const languageCode = 'en';

it('should response to "book a room"', async () => {
const output = exec(
`${cmd} ${projectId} ${location} ${agentId} ${audioFileName} ${encoding} ${sampleRateHertz} ${languageCode}`
);
assert.include(output, "Sorry, I didn't get that. Can you rephrase?");
});
});
43 changes: 43 additions & 0 deletions dialogflow-cx/test/detect-intent-text.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {assert} = require('chai');
const {describe, it} = require('mocha');
const execSync = require('child_process').execSync;
const exec = cmd => execSync(cmd, {encoding: 'utf8'});

describe('detect intent with text input', () => {
const cmd = 'node detect-intent-text.js';

const projectId = process.env.GCLOUD_PROJECT;
const location = 'global';
const agentId = '5d23f659-cd71-43e9-8fb2-b69cd9896370';
const languageCode = 'en';

it('should response to "hello"', async () => {
const output = exec(
`${cmd} ${projectId} ${location} ${agentId} 'hello' ${languageCode}`
);
assert.include(output, 'How can I assist you today?');
});

it('should response to "reserve a vent"', async () => {
const output = exec(
`${cmd} ${projectId} ${location} ${agentId} 'i need to reserve a van' ${languageCode}`
);
assert.include(output, 'Where would you like to pick it up?');
});
});
34 changes: 34 additions & 0 deletions dialogflow-cx/test/list-intents.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {assert} = require('chai');
const {describe, it} = require('mocha');
const execSync = require('child_process').execSync;
const exec = cmd => execSync(cmd, {encoding: 'utf8'});

describe('list intents', () => {
const cmd = 'node list-intents.js';

const projectId = process.env.GCLOUD_PROJECT;
const location = 'global';
const agentId = '5d23f659-cd71-43e9-8fb2-b69cd9896370';

it('should List the Intents', async () => {
const output = exec(`${cmd} ${projectId} ${location} ${agentId}`);
assert.include(output, 'Default Welcome Intent');
assert.include(output, 'Default Negative Intent');
});
});

0 comments on commit 810308a

Please sign in to comment.