Skip to content

Commit

Permalink
docs: add set agent code sample (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
galz10 authored and NimJay committed Nov 18, 2022
1 parent a94d241 commit fba5434
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
48 changes: 48 additions & 0 deletions dialogflow/set-agent.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';

async function main(parentId, displayName) {
// [START dialogflow_set_agent_sample]
const {AgentsClient} = require('@google-cloud/dialogflow');

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

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

const client = new AgentsClient();

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

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

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
27 changes: 27 additions & 0 deletions dialogflow/system-test/set-agent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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
//
// 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');

// We cannot test setAgent because Dialogflow ES can only have one agent
// and if we create a agent it will delete the exisitng testing agent and
// would cause all tests to fail
describe('create agent', () => {
it('should create an intent', async () => {
assert.isTrue(true);
});
});

0 comments on commit fba5434

Please sign in to comment.