|
| 1 | +/* |
| 2 | + * Copyright 2021 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example.contactcenterinsights; |
| 18 | + |
| 19 | +// [START contactcenterinsights_create_conversation] |
| 20 | + |
| 21 | +import com.google.cloud.contactcenterinsights.v1.ContactCenterInsightsClient; |
| 22 | +import com.google.cloud.contactcenterinsights.v1.Conversation; |
| 23 | +import com.google.cloud.contactcenterinsights.v1.ConversationDataSource; |
| 24 | +import com.google.cloud.contactcenterinsights.v1.CreateConversationRequest; |
| 25 | +import com.google.cloud.contactcenterinsights.v1.GcsSource; |
| 26 | +import com.google.cloud.contactcenterinsights.v1.LocationName; |
| 27 | +import java.io.IOException; |
| 28 | + |
| 29 | +public class CreateConversation { |
| 30 | + |
| 31 | + public static void main(String[] args) throws IOException { |
| 32 | + // TODO(developer): Replace these variables before running the sample. |
| 33 | + String projectId = "my_project_id"; |
| 34 | + String transcriptUri = "gs://cloud-samples-data/ccai/chat_sample.json"; |
| 35 | + String audioUri = "gs://cloud-samples-data/ccai/voice_6912.txt"; |
| 36 | + |
| 37 | + createConversation(projectId, transcriptUri, audioUri); |
| 38 | + } |
| 39 | + |
| 40 | + public static Conversation createConversation( |
| 41 | + String projectId, String transcriptUri, String audioUri) throws IOException { |
| 42 | + // Initialize client that will be used to send requests. This client only needs to be created |
| 43 | + // once, and can be reused for multiple requests. After completing all of your requests, call |
| 44 | + // the "close" method on the client to safely clean up any remaining background resources. |
| 45 | + try (ContactCenterInsightsClient client = ContactCenterInsightsClient.create()) { |
| 46 | + // Construct a parent resource. |
| 47 | + LocationName parent = LocationName.of(projectId, "us-central1"); |
| 48 | + |
| 49 | + // Construct a conversation. |
| 50 | + Conversation conversation = |
| 51 | + Conversation.newBuilder() |
| 52 | + .setDataSource( |
| 53 | + ConversationDataSource.newBuilder() |
| 54 | + .setGcsSource( |
| 55 | + GcsSource.newBuilder() |
| 56 | + .setTranscriptUri(transcriptUri) |
| 57 | + .setAudioUri(audioUri) |
| 58 | + .build()) |
| 59 | + .build()) |
| 60 | + .setMedium(Conversation.Medium.CHAT) |
| 61 | + .build(); |
| 62 | + |
| 63 | + // Construct a request. |
| 64 | + CreateConversationRequest request = |
| 65 | + CreateConversationRequest.newBuilder() |
| 66 | + .setParent(parent.toString()) |
| 67 | + .setConversation(conversation) |
| 68 | + .build(); |
| 69 | + |
| 70 | + // Call the Insights client to create a conversation. |
| 71 | + Conversation response = client.createConversation(request); |
| 72 | + System.out.printf("Created %s%n", response.getName()); |
| 73 | + return response; |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +// [END contactcenterinsights_create_conversation] |
0 commit comments