Skip to content

Commit 9921de2

Browse files
galz10gcf-owl-bot[bot]
authored andcommitted
docs(samples): add LRO code snippets (#209)
* docs(samples): add LRO code snippets * lint fix * lint fix * lint fix * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 4992b1a commit 9921de2

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2021 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+
// https://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+
async function main(projectId, agentId, location) {
18+
/**
19+
* TODO(developer): Uncomment these variables before running the sample.
20+
*/
21+
// const projectId = 'my-project';
22+
// const agentId = 'my-agent';
23+
// const location = 'global';
24+
25+
// [START dialogflow_cx_log_running_operation]
26+
27+
const {AgentsClient, protos} = require('@google-cloud/dialogflow-cx');
28+
29+
const api_endpoint = `${location}-dialogflow.googleapis.com`;
30+
31+
const client = new AgentsClient({apiEndpoint: api_endpoint});
32+
33+
const exportAgentRequest =
34+
new protos.google.cloud.dialogflow.cx.v3.ExportAgentRequest();
35+
36+
exportAgentRequest.name = `projects/${projectId}/locations/${location}/agents/${agentId}`;
37+
38+
// exportAgent call returns a promise to a long running operation
39+
const [operation] = await client.exportAgent(exportAgentRequest);
40+
41+
// Waiting for the long running opporation to finish
42+
const [response] = await operation.promise();
43+
44+
// Prints the result of the operation when the operation is done
45+
console.log(response);
46+
47+
// [END dialogflow_cx_log_running_operation]
48+
}
49+
50+
process.on('unhandledRejection', err => {
51+
console.error(err.message);
52+
process.exitCode = 1;
53+
});
54+
main(...process.argv.slice(2));
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2021 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+
// https://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, before, it, after} = require('mocha');
19+
const execSync = require('child_process').execSync;
20+
const uuid = require('uuid');
21+
const dialogflow = require('@google-cloud/dialogflow-cx');
22+
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
23+
const location = 'global';
24+
let agentId = '';
25+
let agentPath = '';
26+
27+
describe('update intent', async () => {
28+
const agentClient = new dialogflow.AgentsClient();
29+
const projectId = await agentClient.getProjectId();
30+
const agentDisplayName = `temp_agent_${uuid.v4().split('-')[0]}`;
31+
const parent = 'projects/' + projectId + '/locations/' + location;
32+
const cmd = 'node long-running-operation.js';
33+
34+
before('create an agent and get agent id', async () => {
35+
// The path to identify the agent that owns the intents.
36+
37+
const agent = {
38+
displayName: agentDisplayName,
39+
defaultLanguageCode: 'en',
40+
timeZone: 'America/Los_Angeles',
41+
};
42+
43+
const request = {
44+
agent,
45+
parent,
46+
};
47+
48+
const [agentResponse] = await agentClient.createAgent(request);
49+
50+
agentPath = agentResponse.name;
51+
agentId = agentPath.split('/')[5];
52+
});
53+
54+
after('delete Agent', async () => {
55+
agentClient.deleteAgent({name: agentPath});
56+
});
57+
58+
it('should export agent', async () => {
59+
const output = exec(`${cmd} ${projectId} ${agentId} ${location}`);
60+
assert.include(output, 'agentContent');
61+
});
62+
});

0 commit comments

Comments
 (0)