Overview
There are two ways to set a conversation's expiration time in
Insights: using the expire_time
field, or using the ttl
field. You can use the expire_time
field set a timestamp indicating when
the conversation will expire, or the ttl
field to set a time duration (in
seconds) until the conversation will expire. If a conversation has both an
expire_time
and ttl
value, Insights uses the expire_time
value.
Conversations set to expire using either the expire_time
or ttl
field
will be deleted 24 hours after the specified expiration time is reached. See
the Conversation resource documentation
for complete details. This page demonstrates how to set a TTL, both for
individual conversations and for all conversations in a given project.
If a conversation is not set to expire, it will remain in Insights indefinitely, though conversations can always be manually deleted.
Create a conversation with a TTL value
The following sample illustrates how to set a TTL value for a single,
newly-created conversation using the ttl
field in a
Conversation resource.
Permissions required for this task
To perform this task, you must have the following permissions:
contactcenterinsights.conversations.create
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.
- MEDIUM: set to either
PHONE_CALL
orCHAT
depending on the data type. If unspecified the default value isPHONE_CALL
. - SECONDS: the time-to-live (time until the conversation expires) in seconds and fractions of a second.
HTTP method and URL:
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID /locations/us-central1/conversations
Request JSON body:
{ "data_source": { "gcs_source": { "transcript_uri": "TRANSCRIPT_URI " } }, "medium": "MEDIUM ", "ttl": { "seconds": "SECONDS " } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID /locations/us-central1/conversations"
PowerShell (Windows)
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID /locations/us-central1/conversations" | Select-Object -Expand Content
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": "555" } }, ... ] }, "medium": "CHAT", "duration": "5.00s", "turnCount": 10, "startTime": "2021-01-10T10:10:10.123000Z" "expireTime":"2021-01-21T10:10:10.123000Z", }
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Set a project-level TTL for all incoming conversations
The following code sample demonstrates how to set a project-level TTL
using the conversation_ttl
field in a
Settings resource.
This TTL will be applied to all incoming conversations that don't specify a
separate expiration time or a different TTL value.
Permissions required for this task
To perform this task, you must have the following permissions:
contactcenterinsights.settings.update
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID.
- SECONDS: the time-to-live (time until the conversation expires) in seconds and fractions of a second.
HTTP method and URL:
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID /locations/us-central1/settings?updateMask=conversation_ttl
Request JSON body:
{ "conversation_ttl": { "seconds": "SECONDS " } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID /locations/us-central1/settings?updateMask=conversation_ttl"
PowerShell (Windows)
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID /locations/us-central1/settings?updateMask=conversation_ttl" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "name": "projects/$PROJECT/locations/us-central1/settings", "createTime": "2021-01-20T10:10:10.123000Z", "updateTime": "2021-01-20T11:11:11.456000Z", "conversationTtl": "86400s" }
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.