Prerequisites
- Make sure that the Cloud Storage, Speech-to-Text and Insights APIs are enabled on your Google Cloud project.
Overview
Conversations can be viewed in Contact Center AI Insights after a corresponding Conversation object has been created and analyzed. This how-to guide walks you through the process of creating and analyzing a conversation using the REST API. If preferred, you can also perform these actions using the CCAI Insights console.
Stage on Cloud Storage
The following sections describe how to upload your own conversation data to a
Cloud Storage bucket in order to ingest it into CCAI Insights. If you
would like to try the API without using your own data, CCAI Insights
provides a publicly-available conversation dataset in the following location:
gs://cloud-samples-data/ccai/chat_sample.json
.
Chat Conversation
Upload the conversation's chat transcript as an object in your Cloud Storage bucket. Make a note of the object path, which is formatted as
gs://<bucket>/<object>
.The chat transcript file must be supplied as a JSON-formatted file that matches the CCAI conversation data format.
Voice Conversation
Upload the conversation's audio and transcript files as objects in your Cloud Storage bucket. Make a note of the two object paths, which are formatted as
gs://<bucket>/<object>
. The transcript files must be the returned result of a Cloud Speech-to-Text API transcription. Specifically, it must match the response returned from audio recognition. The response is identical for synchronous recognition and asynchronous recognition across all Speech-to-Text API versions. Other transcription formats are unsupported and will result in an error during conversation analysis.
Create a conversation
You have the option of creating a conversation using either transcripts of chat conversations or transcripts of phone call audio plus the audio data itself. Creating a conversation that includes the audio data lets you listen to samples of the audio when you use the CCAI Insights console.
REST
Refer to the
conversations:create
API endpoint for complete details. See the
Conversation
resource reference documentation for more information about configuring the
request body. If the
languageCode
field is not set, CCAI Insights will automatically infer it.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID.
- TRANSCRIPT_URI: the Cloud Storage URI that points to a file containing the conversation transcript.
- AUDIO_URI: the Cloud Storage URI that points to a file containing the conversation audio. Omit this field if you are transcribing transcript data only.
- MEDIUM: set to either
PHONE_CALL
orCHAT
depending on the data type. If unspecified the default value isPHONE_CALL
.
HTTP method and URL:
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations
Request JSON body:
{ "dataSource": { "gcsSource": { "transcriptUri": "TRANSCRIPT_URI", "audioUri": "AUDIO_URI" } }, "medium": "MEDIUM" }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/locations/us-central1/conversations/CONVERSATION_ID", "dataSource": { "gcsSource": { "transcriptUri": "gs://cloud-samples-data/ccai/chat_sample.json" } }, "createTime": "2021-01-20T10:10:10.123000Z", "transcript": { "transcriptSegments": [ ... { "text": "Thanks for confirming", "words": [ { "word": "Thanks" }, { "word": "for" }, { "word": "confirming" } ], "languageCode": "en-US", "channelTag": 2, "messageTime": "2021-01-10T10:10:15.123000Z", "segmentParticipant": { "role": "HUMAN_AGENT", "userId": "2" } }, ... ] }, "medium": "CHAT", "duration": "5.00s", "turnCount": 10, "startTime": "2021-01-10T10:10:10.123000Z" }
Python
To authenticate to CCAI Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to CCAI Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to CCAI Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Analyze a conversation
Once a Conversation
object is created in CCAI Insights, it must be
analyzed in order to produce useful results. A single conversation can be
analyzed many times, and each separate analysis creates a new Analysis
object.
An analysis runs a series of annotators against your conversation data and returns the results in the response. By default, the analysis will run all available annotators. Optionally, you can configure the analysis to run specified annotators only.
An analysis is a long-running operation. Calling the CreateAnalysis
method
creates an Operation
object that represents the long-running process. After
the operation is complete, the Operation
object contains the result. You can
poll the Operation
object to check for completion.
Create a new analysis
REST
Refer to the
conversations.analyses:create
API endpoint for complete details.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID.
- CONVERSATION_ID: the ID of the conversation you want to analyze. This value was returned in the `createConversation` response.
HTTP method and URL:
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations/CONVERSATION_ID/analyses
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID" }
Python
To authenticate to CCAI Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to CCAI Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to CCAI Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
(Optional) Configure an analysis
REST
Refer to the
conversations.analyses:create
API endpoint for complete details. Include any annotators that you want to run
in the annotatorSelector
object and set them to true
. Any annotators not
included will default to false
. If you don't specify any annotators in the
annotatorSelector
object all annotators will be run.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID.
- ANALYSIS_PERCENTAGE: Percentage of the conversations to randomly analyze.
- PHRASE_MATCHER(s): The fully qualified phrase matcher resource names of the phrase matchers you want to use for the phrase matcher annotator. If left empty, all active phrase matchers will run.
- ISSUE_MODEL(s): The fully qualified resource names of the issue models you want to use for the issue model annotator. Only works if run_issue_model_annotator is true. If left empty, all deployed issue models will run. Currently limited to 1 deployed model.
HTTP method and URL:
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations/CONVERSATION_ID/analyses
Request JSON body:
{ "annotatorSelector": { "run_interruption_annotator": {true/false}, "run_silence_annotator": {true/false}, "run_phrase_matcher_annotator": {true/false}, "phrase_matchers": PHRASE_MATCHER(s), "run_sentiment_annotator": {true/false}, "run_entity_annotator": {true/false}, "run_intent_annotator": {true/false}, "run_issue_model_annotator": {true/false} "issue_models": ISSUE_MODEL(s) } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID" }
Poll the operation
Creating an analysis returns a long-running operation. Long-running methods are asynchronous, and the operation might not be completed when the method returns a response. You can poll the operation to check on its status. See the long-running operations page for details and code samples.