Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
samples: create topic model (#49)
Browse files Browse the repository at this point in the history
* samples: create topic model

* 馃 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* use async

* 馃 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* use filter

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
TrucHLe and gcf-owl-bot[bot] committed Sep 20, 2021
1 parent 08f13b4 commit 18d497a
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-contact-cen
| Create Analysis | [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createAnalysis.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-contact-center-insights&page=editor&open_in_editor=samples/createAnalysis.js,samples/README.md) |
| Create Conversation | [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createConversation.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-contact-center-insights&page=editor&open_in_editor=samples/createConversation.js,samples/README.md) |
| Create Conversation With Ttl | [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createConversationWithTtl.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-contact-center-insights&page=editor&open_in_editor=samples/createConversationWithTtl.js,samples/README.md) |
| Create Issue Model | [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createIssueModel.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-contact-center-insights&page=editor&open_in_editor=samples/createIssueModel.js,samples/README.md) |
| Enable Pub Sub Notifications | [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/enablePubSubNotifications.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-contact-center-insights&page=editor&open_in_editor=samples/enablePubSubNotifications.js,samples/README.md) |
| Export To Bigquery | [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/exportToBigquery.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-contact-center-insights&page=editor&open_in_editor=samples/exportToBigquery.js,samples/README.md) |
| Get Operation | [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/getOperation.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-contact-center-insights&page=editor&open_in_editor=samples/getOperation.js,samples/README.md) |
Expand Down
7 changes: 7 additions & 0 deletions linkinator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"recurse": true,
"skip": [
"https://codecov.io/gh/googleapis/",
"https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createAnalysis.js",
"https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createConversation.js",
"https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createConversationWithTtl.js",
"https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createIssueModel.js",
"https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/enablePubSubNotifications.js",
"https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/exportToBigquery.js",
"https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/getOperation.js",
"www.googleapis.com",
"img.shields.io"
],
Expand Down
18 changes: 18 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [Create Analysis](#create-analysis)
* [Create Conversation](#create-conversation)
* [Create Conversation With Ttl](#create-conversation-with-ttl)
* [Create Issue Model](#create-issue-model)
* [Enable Pub Sub Notifications](#enable-pub-sub-notifications)
* [Export To Bigquery](#export-to-bigquery)
* [Get Operation](#get-operation)
Expand Down Expand Up @@ -86,6 +87,23 @@ __Usage:__



### Create Issue Model

View the [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/createIssueModel.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-contact-center-insights&page=editor&open_in_editor=samples/createIssueModel.js,samples/README.md)

__Usage:__


`node samples/createIssueModel.js`


-----




### Enable Pub Sub Notifications

View the [source code](https://github.com/googleapis/nodejs-contact-center-insights/blob/main/samples/enablePubSubNotifications.js).
Expand Down
56 changes: 56 additions & 0 deletions samples/createIssueModel.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';

function main(projectId) {
// [START contactcenterinsights_create_issue_model]
/**
* TODO(developer): Uncomment this variable before running the sample.
*/
// const projectId = 'my_project_id';

// Imports the Contact Center Insights client.
const {
ContactCenterInsightsClient,
} = require('@google-cloud/contact-center-insights');

// Instantiates a client.
const client = new ContactCenterInsightsClient();

async function createIssueModel() {
const [operation] = await client.createIssueModel({
parent: client.locationPath(projectId, 'us-central1'),
issueModel: {
displayName: 'my-model',
inputDataConfig: {
filter: 'medium="CHAT"',
},
},
});

// Wait for the operation to complete.
const [issueModel] = await operation.promise();
console.info(`Created ${issueModel.name}`);
}
createIssueModel();
// [END contactcenterinsights_create_issue_model]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
89 changes: 89 additions & 0 deletions samples/test/createIssueModel.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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 {assert} = require('chai');
const {after, before, describe, it} = require('mocha');
const cp = require('child_process');
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const {
ContactCenterInsightsClient,
} = require('@google-cloud/contact-center-insights');
const client = new ContactCenterInsightsClient();

describe('CreateIssueModel', () => {
const minConversationCount = 10000;
const pageSize = 1000;
let projectId;
let conversationCount;
let issueModelName;

before(async () => {
projectId = await client.getProjectId();

// Check if the project has the minimum number of conversations required to create an issue model.
// See https://cloud.google.com/contact-center/insights/docs/topic-model.
conversationCount = 0;
let pageToken = '';
let listResponse;
while (conversationCount < minConversationCount) {
if (pageToken) {
[listResponse] = await client.listConversations({
parent: client.locationPath(projectId, 'us-central1'),
pageSize: pageSize,
pageToken: pageToken,
});
} else {
[listResponse] = await client.listConversations({
parent: client.locationPath(projectId, 'us-central1'),
pageSize: pageSize,
});
}

if (!listResponse.conversations) {
break;
}
conversationCount += listResponse.conversations.length;

if (!listResponse.nextPageToken) {
break;
}
pageToken = listResponse.nextPageToken;
}
});

after(async () => {
if (conversationCount >= minConversationCount) {
client.deleteIssueModel({
name: issueModelName,
});
}
});

it('should create an issue model', async () => {
if (conversationCount >= minConversationCount) {
const stdout = execSync(`node ./createIssueModel.js ${projectId}`);
issueModelName = stdout.slice(8);
assert.match(
stdout,
new RegExp(
'Created projects/[0-9]+/locations/us-central1/issueModels/[0-9]+'
)
);
}
});
});

0 comments on commit 18d497a

Please sign in to comment.