-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: create conversation, create analysis, export data to BigQuery (
#34)
- Loading branch information
Showing
9 changed files
with
480 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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(conversationName) { | ||
// [START contactcenterinsights_create_analysis] | ||
/** | ||
* TODO(developer): Uncomment this variable before running the sample. | ||
*/ | ||
// const conversationName = 'projects/my_project_id/locations/us-central1/conversations/my_conversation_id'; | ||
|
||
// Imports the Contact Center Insights client. | ||
const { | ||
ContactCenterInsightsClient, | ||
} = require('@google-cloud/contact-center-insights'); | ||
|
||
// Instantiates a client. | ||
const client = new ContactCenterInsightsClient(); | ||
|
||
async function createAnalysis() { | ||
const [operation] = await client.createAnalysis({ | ||
parent: conversationName, | ||
}); | ||
|
||
// Wait for the operation to complete. | ||
const [analysis] = await operation.promise(); | ||
console.info(`Created ${analysis.name}`); | ||
} | ||
createAnalysis(); | ||
// [END contactcenterinsights_create_analysis] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// 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, | ||
transcriptUri = 'gs://cloud-samples-data/ccai/chat_sample.json', | ||
audioUri = 'gs://cloud-samples-data/ccai/voice_6912.txt' | ||
) { | ||
// [START contactcenterinsights_create_conversation] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'my_project_id'; | ||
// const transcriptUri = 'gs://cloud-samples-data/ccai/chat_sample.json'; | ||
// const audioUri = 'gs://cloud-samples-data/ccai/voice_6912.txt'; | ||
|
||
// Imports the Contact Center Insights client. | ||
const { | ||
ContactCenterInsightsClient, | ||
} = require('@google-cloud/contact-center-insights'); | ||
|
||
// Instantiates a client. | ||
const client = new ContactCenterInsightsClient(); | ||
|
||
async function createConversation() { | ||
const [conversation] = await client.createConversation({ | ||
parent: client.locationPath(projectId, 'us-central1'), | ||
conversation: { | ||
dataSource: { | ||
gcsSource: { | ||
transcriptUri: transcriptUri, | ||
audioUri: audioUri, | ||
}, | ||
}, | ||
medium: 'CHAT', | ||
}, | ||
}); | ||
console.info(`Created ${conversation.name}`); | ||
} | ||
createConversation(); | ||
// [END contactcenterinsights_create_conversation] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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, | ||
transcriptUri = 'gs://cloud-samples-data/ccai/chat_sample.json', | ||
audioUri = 'gs://cloud-samples-data/ccai/voice_6912.txt' | ||
) { | ||
// [START contactcenterinsights_create_conversation_with_ttl] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'my_project_id'; | ||
// const transcriptUri = 'gs://cloud-samples-data/ccai/chat_sample.json'; | ||
// const audioUri = 'gs://cloud-samples-data/ccai/voice_6912.txt'; | ||
|
||
// Imports the Contact Center Insights client. | ||
const { | ||
ContactCenterInsightsClient, | ||
} = require('@google-cloud/contact-center-insights'); | ||
|
||
// Instantiates a client. | ||
const client = new ContactCenterInsightsClient(); | ||
|
||
async function createConversationWithTtl() { | ||
const [conversation] = await client.createConversation({ | ||
parent: client.locationPath(projectId, 'us-central1'), | ||
conversation: { | ||
dataSource: { | ||
gcsSource: { | ||
transcriptUri: transcriptUri, | ||
audioUri: audioUri, | ||
}, | ||
}, | ||
medium: 'CHAT', | ||
ttl: { | ||
seconds: 600, | ||
}, | ||
}, | ||
}); | ||
console.info(`Created ${conversation.name}`); | ||
} | ||
createConversationWithTtl(); | ||
// [END contactcenterinsights_create_conversation_with_ttl] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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, bigqueryProjectId, bigqueryDataset, bigqueryTable) { | ||
// [START contactcenterinsights_export_to_bigquery] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'my_project_id'; | ||
// const bigqueryProjectId = 'my_bigquery_project_id'; | ||
// const bigqueryDataset = 'my_bigquery_dataset'; | ||
// const bigqueryTable = 'my_bigquery_table'; | ||
|
||
// Imports the Contact Center Insights client. | ||
const { | ||
ContactCenterInsightsClient, | ||
} = require('@google-cloud/contact-center-insights'); | ||
|
||
// Instantiates a client. | ||
const client = new ContactCenterInsightsClient(); | ||
|
||
async function exportToBigquery() { | ||
const [operation] = await client.exportInsightsData({ | ||
parent: client.locationPath(projectId, 'us-central1'), | ||
bigQueryDestination: { | ||
projectId: bigqueryProjectId, | ||
dataset: bigqueryDataset, | ||
table: bigqueryTable, | ||
}, | ||
filter: 'agent_id="007"', | ||
}); | ||
|
||
// Wait for the operation to complete. | ||
await operation.promise(); | ||
console.info('Exported data to BigQuery'); | ||
} | ||
exportToBigquery(); | ||
// [END contactcenterinsights_export_to_bigquery] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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('CreateAnalysis', () => { | ||
let projectId; | ||
let conversationName; | ||
|
||
before(async () => { | ||
projectId = await client.getProjectId(); | ||
}); | ||
|
||
after(() => { | ||
client.deleteConversation({ | ||
name: conversationName, | ||
force: true, | ||
}); | ||
}); | ||
|
||
it('should create a conversation and an analysis', async () => { | ||
const stdoutCreateConversation = execSync( | ||
`node ./createConversation.js ${projectId}` | ||
); | ||
conversationName = stdoutCreateConversation.slice(8); | ||
assert.match( | ||
stdoutCreateConversation, | ||
new RegExp( | ||
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+' | ||
) | ||
); | ||
|
||
const stdoutCreateAnalysis = execSync( | ||
`node ./createAnalysis.js ${conversationName}` | ||
); | ||
assert.match( | ||
stdoutCreateAnalysis, | ||
new RegExp( | ||
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+/analyses/[0-9]+' | ||
) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('CreateConversation', () => { | ||
let projectId; | ||
let conversationName; | ||
|
||
before(async () => { | ||
projectId = await client.getProjectId(); | ||
}); | ||
|
||
after(() => { | ||
client.deleteConversation({ | ||
name: conversationName, | ||
}); | ||
}); | ||
|
||
it('should create a conversation', async () => { | ||
const stdout = execSync(`node ./createConversation.js ${projectId}`); | ||
conversationName = stdout.slice(8); | ||
assert.match( | ||
stdout, | ||
new RegExp( | ||
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+' | ||
) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.