Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/nodejs-dialogflow-cx #2854

Merged
merged 57 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
21ab57e
feat!: initial full generation of library (#1)
bcoe Aug 25, 2020
bf31f97
chore: release 1.0.0 (#3)
release-please[bot] Aug 25, 2020
8b0a7b8
feat(samples): examples of dialogflow-cx in action
Aug 28, 2020
0760dd1
chore: release 1.1.0 (#9)
release-please[bot] Oct 16, 2020
7c6e7e6
chore: release 1.2.0 (#32)
release-please[bot] Nov 17, 2020
8325782
docs: update quickstart to reflect actual use case (#11)
bcoe Nov 19, 2020
d70dcd0
chore: release 2.0.0 (#36)
release-please[bot] Nov 19, 2020
3316e47
chore: release 2.1.0 (#40)
release-please[bot] Dec 2, 2020
810308a
docs: improved instructions for samples and tests (#41)
Jeremy-WEI Dec 4, 2020
1cd4e6e
chore: release 2.2.0 (#45)
release-please[bot] Jan 12, 2021
ef06af5
chore: release 2.3.0 (#55)
release-please[bot] Mar 1, 2021
fe27c52
chore: release 2.4.0 (#65)
release-please[bot] Mar 15, 2021
1653752
chore: release 2.5.0 (#84)
release-please[bot] Apr 28, 2021
ecf7fa8
chore: release 2.6.0 (#105)
release-please[bot] May 5, 2021
a90a4fa
chore: release 2.7.0 (#111)
release-please[bot] May 10, 2021
c50356f
chore: release 2.8.0 (#121)
release-please[bot] May 25, 2021
231e8ff
chore: release 2.8.1 (#128)
release-please[bot] Jun 10, 2021
d944687
chore: release 2.9.0 (#135)
release-please[bot] Jun 14, 2021
379f46e
chore: release 2.10.0 (#136)
release-please[bot] Jun 17, 2021
f0e30e5
chore: release 2.11.0 (#137)
release-please[bot] Jun 21, 2021
89bec4e
chore: release 2.12.0 (#143)
release-please[bot] Jun 30, 2021
73c63a0
chore: release 2.12.1 (#149)
release-please[bot] Jul 21, 2021
d9f659a
docs: add create agent code sample (#163)
galz10 Aug 16, 2021
6e5e6b6
chore: release 2.13.0 (#157)
release-please[bot] Aug 17, 2021
b773faa
docs: add update intent sample (#160)
galz10 Aug 20, 2021
2c98650
docs: add page management code samples (#174)
galz10 Sep 8, 2021
0cc9b0f
samples: fixed using wrong variable naming (#182)
galz10 Sep 21, 2021
f5f9c1a
chore: release 2.14.0 (#168)
release-please[bot] Sep 27, 2021
5e314b4
docs: add filter code sample (#179)
galz10 Oct 8, 2021
cbcc6c1
docs: added voice selection (#193)
galz10 Oct 12, 2021
5837a36
docs(samples): addes new training phrases sample (#195)
b-loved-dreamer Oct 19, 2021
2bd4213
docs: add webhook code sample (#177)
galz10 Oct 25, 2021
4992b1a
docs: added comment (#204)
galz10 Nov 12, 2021
9921de2
docs(samples): add LRO code snippets (#209)
galz10 Jan 6, 2022
f40f3b8
docs: `exports.` removed from the cloud function's entry point (#244)
Mar 29, 2022
7fc4083
feat: add Webhook samples (#259)
aribray Apr 29, 2022
ec65dff
docs(samples): Add detectIntent samples (#263)
aribray May 4, 2022
fe6cb09
docs(samples) - streamliine and clarify webhook samples (#264)
aribray May 5, 2022
7afa36f
docs(samples): hardcode parameter in webhook sample (#268)
aribray May 9, 2022
2e69bd0
docs(samples): replace agent ids (#271)
aribray May 11, 2022
061d3d2
build!: update library to use Node 12 (#288)
alexander-fenster May 17, 2022
652a6d5
docs(samples): refactor webhook samples (#270)
aribray Jun 16, 2022
070b065
docs (samples): add detect intent samples (#292)
aribray Jun 23, 2022
f2f1e90
chore(main): release 3.0.0 (#269)
release-please[bot] Jun 30, 2022
6b2cead
chore(main): release 3.1.0 (#299)
release-please[bot] Aug 2, 2022
3c9700a
fix(deps): update dependency uuid to v9 (#311)
renovate-bot Sep 9, 2022
6fa7847
chore(main): release 3.1.1 (#307)
release-please[bot] Sep 26, 2022
3a73445
chore(main): release 3.1.2 (#322)
release-please[bot] Nov 11, 2022
cd12477
Add workflows config
Nov 16, 2022
c1673bb
Delete test for unused sample
Nov 16, 2022
95f603a
Add secrets
Nov 18, 2022
eaa3628
Merge branch 'main' into nodejs-dialogflow-cx-migration
Nov 18, 2022
fd2300f
Allow specifying agent project ID via env var
Nov 18, 2022
14d5e36
Lint
Nov 18, 2022
f2aaee0
Merge branch 'main' into nodejs-dialogflow-cx-migration
Nov 19, 2022
5b17751
Merge branch 'main' into nodejs-dialogflow-cx-migration
Nov 19, 2022
9e05f20
Merge branch 'main' into nodejs-dialogflow-cx-migration
Nov 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/dialogflow-cx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: dialogflow-cx
on:
push:
branches:
- main
paths:
- 'dialogflow-cx/**'
pull_request:
paths:
- 'dialogflow-cx/**'
pull_request_target:
types: [labeled]
schedule:
- cron: '0 0 * * 0'
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
steps:
- uses: actions/checkout@v3
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- uses: google-github-actions/[email protected]
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: '[email protected]'
create_credentials_file: 'true'
access_token_lifetime: 600s
- id: secrets
uses: 'google-github-actions/get-secretmanager-secrets@v0'
with:
secrets: |-
agent_id:nodejs-docs-samples-tests/nodejs-docs-samples-dialogflow-cx-agent-id
test_id:nodejs-docs-samples-tests/nodejs-docs-samples-dialogflow-cx-test-id
- uses: actions/setup-node@v3
with:
node-version: 14
- run: npm install
working-directory: dialogflow-cx
- run: npm test
working-directory: dialogflow-cx
env:
AGENT_ID: ${{ steps.secrets.outputs.agent_id }}
TEST_ID: ${{ steps.secrets.outputs.test_id }}
AGENT_PROJECT_ID: nodejs-docs-samples-tests
MOCHA_REPORTER_SUITENAME: dialogflow-cx
MOCHA_REPORTER_OUTPUT: dialogflow_cx_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: ${{ github.event_name == 'schedule' && always() }}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"datastore/functions",
"datacatalog/quickstart",
"dialogflow",
"dialogflow-cx",
"document-ai",
"endpoints/getting-started",
"endpoints/getting-started-grpc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2022 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
//
// https://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.

/**
* Configures a webhook to set form parameters as optional/required
*/

// [START dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required]

exports.configureOptionalFormParam = (request, response) => {
// The value of the parameter that the webhook will set as optional or required.
// Note that the webhook cannot add or remove any form parameter

const jsonResponse = {
pageInfo: {
formInfo: {
parameterInfo: [
{
displayName: 'order-number',
// if required: false, the agent will not reprompt for this parameter, even if the state is 'INVALID'
required: true,
state: 'VALID',
},
],
},
},
};

// Info about form parameter that is sent in the webhook response:
console.log(
'Parameter Info: \n',
jsonResponse.pageInfo.formInfo.parameterInfo[0]
);

response.send(jsonResponse);
};
// [END dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required]
56 changes: 56 additions & 0 deletions dialogflow-cx/create-agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2021 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
//
// https://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';

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

async function main(projectId, displayName) {
// [START dialogflow_set_agent_sample]

const parent = 'projects/' + projectId + '/locations/global';

const api_endpoint = 'global-dialogflow.googleapis.com';

const agent = {
displayName: displayName,
defaultLanguageCode: 'en',
timeZone: 'America/Los_Angeles',
};

const {AgentsClient} = require('@google-cloud/dialogflow-cx');

const client = new AgentsClient({apiEndpoint: api_endpoint});

async function setAgentSample() {
const request = {
agent,
parent,
};

const [response] = await client.createAgent(request);
console.log(`response: ${JSON.stringify(response, null, 2)}`);

// Delete created agent resource
client.deleteAgent({name: response.name});
}
await setAgentSample();
// [END dialogflow_set_agent_sample]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
51 changes: 51 additions & 0 deletions dialogflow-cx/create-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2021 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
//
// https://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 {PagesClient} = require('@google-cloud/dialogflow-cx');

async function main(projectId, agentId, flowId, location, displayName) {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const agentId = 'my-agent';
// const flowId = 'my-flow';
// const displayName = 'my-display-name';
// const location = 'global';

// [START dialogflow_cx_create_page_sample]
async function createPage(projectId, agentId, flowId, location, displayName) {
const pagesClient = new PagesClient();

const createPageRequest = {
parent: `projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}`,
page: {
displayName: displayName,
},
};

const response = await pagesClient.createPage(createPageRequest);
console.log(response);
}
// [END dialogflow_cx_create_page_sample]

await createPage(projectId, agentId, flowId, location, displayName);
}

main(...process.argv.slice(2)).catch(err => {
console.error(err);
process.exitCode = 1;
});
48 changes: 48 additions & 0 deletions dialogflow-cx/delete-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2021 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
//
// https://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 {PagesClient} = require('@google-cloud/dialogflow-cx');

async function main(projectId, agentId, flowId, pageId, location) {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const agentId = 'my-agent';
// const flowId = 'my-flow';
// const pageId = 'my-page';
// const location = 'global';

// [START dialogflow_cx_delete_page_sample]
async function deletePage(projectId, agentId, flowId, pageId, location) {
const pagesClient = new PagesClient();

const req = {
name: `projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}/pages/${pageId}`,
};

const response = await pagesClient.deletePage(req);
console.log(response);
}
// [END dialogflow_cx_delete_page_sample]

await deletePage(projectId, agentId, flowId, pageId, location);
}

main(...process.argv.slice(2)).catch(err => {
console.error(err);
process.exitCode = 1;
});
102 changes: 102 additions & 0 deletions dialogflow-cx/detect-intent-audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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';

async function main(
projectId,
location,
agentId,
audioFileName,
encoding,
sampleRateHertz,
languageCode
) {
// [START dialogflow_cx_detect_intent_audio]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const location = 'global';
// const agentId = 'my-agent';
// const audioFileName = '/path/to/audio.raw';
// const encoding = 'AUDIO_ENCODING_LINEAR_16';
// const sampleRateHertz = 16000;
// 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();

const fs = require('fs');
const util = require('util');

async function detectIntentAudio() {
const sessionId = Math.random().toString(36).substring(7);
const sessionPath = client.projectLocationAgentSessionPath(
projectId,
location,
agentId,
sessionId
);
console.info(sessionPath);

// Read the content of the audio file and send it as part of the request.
const readFile = util.promisify(fs.readFile);
const inputAudio = await readFile(audioFileName);

const request = {
session: sessionPath,
queryInput: {
audio: {
config: {
audioEncoding: encoding,
sampleRateHertz: sampleRateHertz,
},
audio: inputAudio,
},
languageCode,
},
};
const [response] = await client.detectIntent(request);
console.log(`User Query: ${response.queryResult.transcript}`);
for (const message of response.queryResult.responseMessages) {
if (message.text) {
console.log(`Agent Response: ${message.text.text}`);
}
}
if (response.queryResult.match.intent) {
console.log(
`Matched Intent: ${response.queryResult.match.intent.displayName}`
);
}
console.log(
`Current Page: ${response.queryResult.currentPage.displayName}`
);
}

detectIntentAudio();
// [END dialogflow_cx_detect_intent_audio]
}

main(...process.argv.slice(2));
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
Loading