Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to retrive transcript of virtual agent and customer in dialogflowcx?

I have two questions?

1. How to retrieve transcript of virtual agent and customer in dialogflowcx? After the virtual agent has triggered the "live agent handoff" the call reaches our internal contact centre. I want to fetch the transcript of the conversation so far to show to the real agent. Using API/Client library/anything.

2. When live agent hand off happens, then there are certain parameters passed on. There is also an option to app a JSON in the dialogue option. Is there a way to retrieve this JSON/Parameters using an API call?

0 10 2,928
10 REPLIES 10

Hi,

There is no feature available as of the moment to extract the conversation using the API. But as a workaround you can get this information from the generated logs of Dialogflow. The logs are located in Cloud Logging as shown in this example. The provided example exports data manually, but you can use Cloud Logging API to programatically export the logs and automate this process. 

You can  create a feature request in GCPs public issue tracker regarding your request as this is a useful feature to have. Please keep in mind that when you create a feature request, it still needs to be analyzed and considered by the product team and a definite ETA is not guaranteed. 

Hi @ricconoel  and @amsrivastava  and @xavidop ,

Is this post still accurate? I see that it was posted in 2022 and now it is 6-28-2024. Wondering if there is still no conversation history for Dialogflow CX API? Note I'm needing conversation in Dialogflow CX and not Dialogflow ES. So only way to get history is in Cloud logging right?

Thanks,

Karl Gardner

Hi @ricconoel Thanks for your quick reply.

I was able to fetch the transcript using Conversations resource. This resource exists under the umbrella of Dialogflow ES v2beta1 and is not a part of Dialogflow CX. Is it a suggested way? I am asking as we are planning to use in a production app and want to avoid a situation where there this does not work, or stopped, etc.

I am attaching the code snippet for your better understanding

 

from google.cloud import dialogflow_v2beta1
from google.cloud.dialogflowcx_v3.services.agents.client import AgentsClient

# Set the project and location IDs for your Dialogflow CX project
project_id = "ccai-flex-aman"
location_id = "us-central1"
agent_id = "8bf5e181-f10f-4336-a831-c7936aa55585"
agent = f"projects/{project_id}/locations/{location_id}/agents/{agent_id}"
parent = f"projects/{project_id}/locations/{location_id}"

agent_components = AgentsClient.parse_agent_path(agent)

location_id = agent_components["location"]
if location_id != "global":
    api_endpoint = f"{location_id}-dialogflow.googleapis.com:443"
    print(f"API Endpoint: {api_endpoint}\n")
    client_options = {"api_endpoint": api_endpoint}

# Set up the Dialogflow CX client
client = dialogflow_v2beta1.ConversationsClient(client_options=client_options)

# Use the API to retrieve a list of all the conversations in the project
conversations = client.list_conversations(
    parent=f"projects/{project_id}/locations/{location_id}",
)

# Print the list of conversations
for conversation in conversations:
    print(conversation)

# Select the conversation for which you want to fetch the transcript
conversation_id = "081mM5l9Ry8Qeu_BFg8XjuZ8Q"

# Use the API to retrieve the full conversation history
messages = client.list_messages(
    parent=f"projects/{project_id}/locations/{location_id}/conversations/{conversation_id}"
)

# Format the conversation history into a transcript
transcript = ""
for message in messages:
    # Add the message text and timestamp to the transcript
    transcript += f"{message.content} ({message.create_time})\n"

# Print the transcript
print(transcript)

 

Output( 2nd part):

You have not provided a confirmation number yet. Let me transfer you to a live agent to further assist you. (2022-12-01 08:17:25.522847+00:00)
 (2022-12-01 08:17:25.483295+00:00)
 (2022-12-01 08:17:21.059599+00:00)
 (2022-12-01 08:17:21.021359+00:00)
What is your flight confirmation number? (2022-12-01 08:17:14.826351+00:00)
looking for my flight (2022-12-01 08:17:14.800063+00:00)
Hi! How are you doing? (2022-12-01 08:17:09.682911+00:00)


 

Dialogflow ES and Dialogflow CX have a huge difference in its architecture. So it really depends on your needs. For example Dialogflow CX implements flows and Dialogflow ES does not. If you won't be needing features of Dialoflow CX then you can go with Dialogflow ES. See reference for CX and ES comparison.

@ricconoel Please note that the above code snippet is fetching the conversation history of a Dialogflow CX agent using Dialogflow ES API. Is that an accepted approach?

from google.cloud import dialogflow_v2beta1

This directs to Dialogflow ES, but it can fetch conversations from CX 

I see. I never have thought of that. If you are able to fetch using this method I think you can continue using it.

Casually asking - Is this is a bug or a feature? Asking because we are planning to use it in a large scale application and if Google decides to remove this then there will be a huge impact on our customers.

Based on the Conversation History in CX, it is still in "preview" and is not recommended to use this yet in production environments. I suggest to wait for this feature to be in "general availability" before using it in production. 

Also it might be better to create an issue in GCP issue tracker to confirm to the engineering team if using Diagloflow ES Conversations with Dialogflow CX Conversations is an expected behavior.

Also, another question. How long does the conversation history remain in the Google systems? Is there a timeline before these conversations are purged?

It should be retained for 400 days as per document.