|
| 1 | +# Copyright 2021 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# [START contactcenterinsights_create_conversation] |
| 16 | +from google.cloud import contact_center_insights_v1 |
| 17 | + |
| 18 | + |
| 19 | +def create_conversation( |
| 20 | + project_id: str, |
| 21 | + transcript_uri: str = "gs://cloud-samples-data/ccai/chat_sample.json", |
| 22 | + audio_uri: str = "gs://cloud-samples-data/ccai/voice_6912.txt", |
| 23 | +) -> contact_center_insights_v1.Conversation: |
| 24 | + # Construct a parent resource. |
| 25 | + parent = contact_center_insights_v1.ContactCenterInsightsClient.common_location_path( |
| 26 | + project_id, "us-central1" |
| 27 | + ) |
| 28 | + |
| 29 | + # Construct a conversation. |
| 30 | + conversation = contact_center_insights_v1.Conversation() |
| 31 | + conversation.data_source.gcs_source.transcript_uri = transcript_uri |
| 32 | + conversation.data_source.gcs_source.audio_uri = audio_uri |
| 33 | + conversation.medium = contact_center_insights_v1.Conversation.Medium.CHAT |
| 34 | + |
| 35 | + # Call the Insights client to create a conversation. |
| 36 | + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() |
| 37 | + conversation = insights_client.create_conversation( |
| 38 | + parent=parent, conversation=conversation |
| 39 | + ) |
| 40 | + |
| 41 | + print(f"Created {conversation.name}") |
| 42 | + return conversation |
| 43 | + |
| 44 | + |
| 45 | +# [END contactcenterinsights_create_conversation] |
0 commit comments