|
| 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 | +# Set a project-level TTL for all incoming conversations. |
| 16 | +# [START contactcenterinsights_set_project_ttl] |
| 17 | +from google.api_core import protobuf_helpers |
| 18 | +from google.cloud import contact_center_insights_v1 |
| 19 | +from google.protobuf import duration_pb2 |
| 20 | + |
| 21 | + |
| 22 | +def set_project_ttl(project_id: str) -> None: |
| 23 | + # Construct a settings resource. |
| 24 | + settings = contact_center_insights_v1.Settings() |
| 25 | + settings.name = contact_center_insights_v1.ContactCenterInsightsClient.settings_path( |
| 26 | + project_id, "us-central1" |
| 27 | + ) |
| 28 | + |
| 29 | + conversation_ttl = duration_pb2.Duration() |
| 30 | + conversation_ttl.seconds = 86400 |
| 31 | + settings.conversation_ttl = conversation_ttl |
| 32 | + |
| 33 | + # Construct an update mask to only update the fields that are set on the settings resource. |
| 34 | + update_mask = protobuf_helpers.field_mask(None, type(settings).pb(settings)) |
| 35 | + |
| 36 | + # Construct an Insights client that will authenticate via Application Default Credentials. |
| 37 | + # See authentication details at https://cloud.google.com/docs/authentication/production. |
| 38 | + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() |
| 39 | + |
| 40 | + # Call the Insights client to set a project-level TTL. |
| 41 | + insights_client.update_settings(settings=settings, update_mask=update_mask) |
| 42 | + |
| 43 | + # Call the Insights client to get the project-level TTL to confirm that it was set. |
| 44 | + new_conversation_ttl = insights_client.get_settings( |
| 45 | + name=settings.name |
| 46 | + ).conversation_ttl |
| 47 | + print( |
| 48 | + "Set TTL for all incoming conversations to {} day".format( |
| 49 | + new_conversation_ttl.days |
| 50 | + ) |
| 51 | + ) |
| 52 | + |
| 53 | +# [END contactcenterinsights_set_project_ttl] |
0 commit comments