diff --git a/dialogflow-cx/detect_intent_audio.js b/dialogflow-cx/detect-intent-audio.js similarity index 93% rename from dialogflow-cx/detect_intent_audio.js rename to dialogflow-cx/detect-intent-audio.js index f81f62fd2f..a389c00fc8 100644 --- a/dialogflow-cx/detect_intent_audio.js +++ b/dialogflow-cx/detect-intent-audio.js @@ -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'); diff --git a/dialogflow-cx/detect_intent_streaming.js b/dialogflow-cx/detect-intent-streaming.js similarity index 95% rename from dialogflow-cx/detect_intent_streaming.js rename to dialogflow-cx/detect-intent-streaming.js index ce0702c928..d8fd52e67b 100644 --- a/dialogflow-cx/detect_intent_streaming.js +++ b/dialogflow-cx/detect-intent-streaming.js @@ -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'); diff --git a/dialogflow-cx/detect_intent_text.js b/dialogflow-cx/detect-intent-text.js similarity index 91% rename from dialogflow-cx/detect_intent_text.js rename to dialogflow-cx/detect-intent-text.js index f571845d97..705cf56038 100644 --- a/dialogflow-cx/detect_intent_text.js +++ b/dialogflow-cx/detect-intent-text.js @@ -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() { diff --git a/dialogflow-cx/list-intents.js b/dialogflow-cx/list-intents.js index 29551a6301..f28ec20755 100644 --- a/dialogflow-cx/list-intents.js +++ b/dialogflow-cx/list-intents.js @@ -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() { diff --git a/dialogflow-cx/quickstart.js b/dialogflow-cx/quickstart.js index 20fb0df973..4e7efe3c31 100644 --- a/dialogflow-cx/quickstart.js +++ b/dialogflow-cx/quickstart.js @@ -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'); diff --git a/dialogflow-cx/resources/book_a_room.wav b/dialogflow-cx/resources/book_a_room.wav new file mode 100644 index 0000000000..9124e92794 Binary files /dev/null and b/dialogflow-cx/resources/book_a_room.wav differ diff --git a/dialogflow-cx/test/detect-intent-audio.test.js b/dialogflow-cx/test/detect-intent-audio.test.js new file mode 100644 index 0000000000..01157cc132 --- /dev/null +++ b/dialogflow-cx/test/detect-intent-audio.test.js @@ -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?"); + }); +}); diff --git a/dialogflow-cx/test/detect-intent-text.test.js b/dialogflow-cx/test/detect-intent-text.test.js new file mode 100644 index 0000000000..88b3db6101 --- /dev/null +++ b/dialogflow-cx/test/detect-intent-text.test.js @@ -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?'); + }); +}); diff --git a/dialogflow-cx/test/list-intents.test.js b/dialogflow-cx/test/list-intents.test.js new file mode 100644 index 0000000000..e8ede3d84a --- /dev/null +++ b/dialogflow-cx/test/list-intents.test.js @@ -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'); + }); +});