Skip to content

Commit

Permalink
samples: create custom highlights (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrucHLe authored Sep 20, 2021
1 parent c417f8d commit 163873b
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 0 deletions.
90 changes: 90 additions & 0 deletions contact-center-insights/createPhraseMatcherAllOf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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_phrase_matcher_all_of]
/**
* 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 createPhraseMatcherAllOf() {
const [phraseMatcher] = await client.createPhraseMatcher({
parent: client.locationPath(projectId, 'us-central1'),
phraseMatcher: {
displayName: 'NON_SHIPPING_PHONE_SERVICE',
type: 'ALL_OF',
active: true,
phraseMatchRuleGroups: [
{
type: 'ANY_OF',
phraseMatchRules: [
{
query: 'PHONE',
config: {
exactMatchConfig: {},
},
},
{
query: 'CELLPHONE',
config: {
exactMatchConfig: {},
},
},
],
},
{
type: 'ALL_OF',
phraseMatchRules: [
{
query: 'SHIPPING',
negated: true,
config: {
exactMatchConfig: {},
},
},
{
query: 'DELIVERY',
negated: true,
config: {
exactMatchConfig: {},
},
},
],
},
],
},
});
console.info(`Created ${phraseMatcher.name}`);
}
createPhraseMatcherAllOf();
// [END contactcenterinsights_create_phrase_matcher_all_of]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
71 changes: 71 additions & 0 deletions contact-center-insights/createPhraseMatcherAnyOf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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_phrase_matcher_any_of]
/**
* 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 createPhraseMatcherAnyOf() {
const [phraseMatcher] = await client.createPhraseMatcher({
parent: client.locationPath(projectId, 'us-central1'),
phraseMatcher: {
displayName: 'PHONE_SERVICE',
type: 'ANY_OF',
active: true,
phraseMatchRuleGroups: [
{
type: 'ANY_OF',
phraseMatchRules: [
{
query: 'PHONE',
config: {
exactMatchConfig: {},
},
},
{
query: 'CELLPHONE',
config: {
exactMatchConfig: {},
},
},
],
},
],
},
});
console.info(`Created ${phraseMatcher.name}`);
}
createPhraseMatcherAnyOf();
// [END contactcenterinsights_create_phrase_matcher_any_of]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
52 changes: 52 additions & 0 deletions contact-center-insights/test/createPhraseMatcherAllOf.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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('CreatePhraseMatcherAllOf', () => {
let projectId;
let phraseMatcherName;

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

after(async () => {
client.deletePhraseMatcher({
name: phraseMatcherName,
});
});

it('should create a phrase matcher', async () => {
const stdout = execSync(`node ./createPhraseMatcherAllOf.js ${projectId}`);
phraseMatcherName = stdout.slice(8);
assert.match(
stdout,
new RegExp(
'Created projects/[0-9]+/locations/us-central1/phraseMatchers/[0-9]+'
)
);
});
});
52 changes: 52 additions & 0 deletions contact-center-insights/test/createPhraseMatcherAnyOf.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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('CreatePhraseMatcherAnyOf', () => {
let projectId;
let phraseMatcherName;

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

after(async () => {
client.deletePhraseMatcher({
name: phraseMatcherName,
});
});

it('should create a phrase matcher', async () => {
const stdout = execSync(`node ./createPhraseMatcherAnyOf.js ${projectId}`);
phraseMatcherName = stdout.slice(8);
assert.match(
stdout,
new RegExp(
'Created projects/[0-9]+/locations/us-central1/phraseMatchers/[0-9]+'
)
);
});
});

0 comments on commit 163873b

Please sign in to comment.