如何存储检索Dialogflow对话历史及转接人工时获取用户对话记录
Great question! Handling conversation history is critical for smooth handoffs to human support, so let’s break this down clearly.
Yes, both Dialogflow ES (Essentials) and Dialogflow CX (Contact Center Edition) offer built-in conversation history features, though the exact workflows differ slightly:
For Dialogflow ES:
- Enable it first: Head to your Agent’s settings (left menu > Settings > General), scroll to the "Conversation History" section, check the box to enable it, and set a retention period (how long you want records stored).
- Access via Console: Use the left menu’s Conversation History tab to browse, filter (by date, user, intent, etc.), and export records as CSV or JSON for offline use.
- Access via API: Use the Dialogflow API’s
projects.locations.agents.conversationsendpoints. For example:projects.locations.agents.conversations.listto fetch all conversations in a time rangeprojects.locations.agents.conversations.getto retrieve details for a specific conversation (using its unique conversation ID)
You’ll need a service account with thedialogflow.conversations.getpermission to make these calls.
For Dialogflow CX:
- Access via Console: Go to Analytics > Conversations in the left menu. Here you can view full conversation transcripts, filter by agent, user, or intent, and export data.
- Access via API: Use the CX API’s
projects.locations.agents.conversationsendpoints, similar to ES, to programmatically pull conversation history.
If the built-in storage doesn’t meet your needs (e.g., you need to integrate with your own CRM or custom support tool), you can set up custom storage using webhooks:
Custom Storage Workflow:
- Set up a Fulfillment Webhook: In Dialogflow, configure a webhook to trigger on every user interaction (you can set this globally or per intent).
- Capture Conversation Data: In your webhook service, extract key data from the incoming request body:
- Conversation ID (unique identifier for the user’s chat session)
- User input text/audio transcript
- Agent’s response
- Detected intent and parameters
- Timestamp of the interaction
- Store in Your Database: Save this data to a database of your choice (Firestore, MySQL, MongoDB, etc.), using the conversation ID as a foreign key to group all messages from the same session.
- Retrieve When Needed: When you need to pull the history (e.g., for a support handoff), query your database using the conversation ID to fetch all related messages, sorted by timestamp.
Whether you use built-in or custom storage, the goal is to pass the full conversation context to your human support team seamlessly:
Using Built-in History:
When your Dialogflow agent detects a "handoff to human" intent (e.g., user says "I need to talk to someone"), trigger a fulfillment that:
- Grabs the current conversation ID from the request.
- Calls the Dialogflow API to fetch the full transcript for that conversation.
- Formats the transcript into a readable format (e.g., a timestamped list of "User: ..." and "Agent: ..." messages).
- Passes this formatted history, along with user details (if available), to your support platform (Zendesk, Freshdesk, or your custom tool).
Using Custom Storage:
For custom setups, the handoff workflow is simpler:
- In the handoff intent’s fulfillment, use the conversation ID to query your database for all messages in the session.
- Format the history into a user-friendly transcript.
- Push this data to your support system so the human agent can see exactly what the user discussed with the bot before the handoff.
Key Notes:
- Data Privacy: Always comply with regulations like GDPR or CCPA. Ensure you have user consent to store conversation data, encrypt sensitive information, and delete records when they’re no longer needed.
- Conversation ID Consistency: The conversation ID is your anchor for grouping messages—make sure you use the same ID across all interactions in a single user session, whether you’re using built-in or custom storage.
内容的提问来源于stack exchange,提问作者Rakhi Mittal

