Dialogflow CX Integration
Integrate Google Dialogflow CX with BuilderBot for advanced conversational AI with visual flow builders, version control, and enterprise features.Dialogflow CX is the advanced version of Dialogflow with visual flow builders, better state management, and enterprise capabilities. Use Dialogflow ES for simpler use cases.
Installation
Install Google Cloud dependencies
The package requires Google Cloud Dialogflow CX SDK:
This dependency is included automatically when you install
@builderbot/contexts-dialogflow-cxGet Google Cloud credentials
- Go to Google Cloud Console
- Create or select a project
- Enable the Dialogflow CX API
- Create a service account with Dialogflow API Admin role
- Download the JSON key file
- Save it as
google-key.jsonin your project root
Configuration
Setup Google Credentials
Place yourgoogle-key.json file in your project root directory:
google-key.json
Initialize Dialogflow CX Context
Configuration Options
Language code for Dialogflow CX agent (e.g., ‘en’, ‘es’, ‘fr’, ‘pt’)
Google Cloud region where your CX agent is deployedCommon locations:
us-central1- Iowa, USAus-east1- South Carolina, USAeurope-west1- Belgiumasia-northeast1- Tokyo, Japan
Your Dialogflow CX agent ID (found in agent settings)
Usage
Handle Messages with Dialogflow CX
Process incoming messages through Dialogflow CX:Complete Example with Flows
Response Types
Dialogflow CX can send different types of responses:Text Responses
Simple text messages from pages and flows:Rich Media Responses (Custom Payloads)
Send images, buttons, and interactive content using custom payloads:Dialogflow CX Custom Payload
Advanced Features
Session Parameters
Dialogflow CX maintains session parameters across the conversation flow:Multi-turn Conversations
CX excels at complex, multi-turn conversations with state management:Page Transitions
Dialogflow CX uses pages to manage conversation states. The context automatically handles page transitions and state changes.Session Management
Dialogflow CX Context automatically manages user sessions:- Each user gets a unique session based on their phone number (
fromfield) - Sessions maintain full conversation state
- Page context and parameters are preserved
- Flow transitions are handled automatically
TypeScript Support
Full TypeScript definitions included:Best Practices
Agent Configuration
Agent Configuration
- Design your CX flows in the visual builder first
- Test flows thoroughly in the Dialogflow CX simulator
- Use pages to organize complex conversation logic
- Set appropriate session timeouts
Location Selection
Location Selection
- Choose a location close to your users for better latency
- Ensure data residency requirements are met
- Note:
locationmust match where your CX agent is deployed
Security
Security
- Never commit
google-key.jsonto version control - Use environment variables for production
- Restrict service account to minimum required permissions
- Rotate service account keys regularly
Error Handling
Error Handling
- Implement fallback responses in CX
- Monitor API quotas and usage
- Add logging for debugging
- Handle network errors gracefully
Performance
Performance
- Cache frequently accessed data
- Monitor response times
- Use webhooks for external data when needed
- Optimize flow complexity
Troubleshooting
Error: “No se encontró google-key.json”
Ensure your credentials file exists in the project root:API Endpoint Errors
Verify yourlocation matches your agent deployment:
Agent ID Issues
Get your agent ID from Dialogflow CX Console:- Open your agent
- Go to Agent Settings
- Copy the Agent ID (long UUID format)
Session Path Errors
The session path format for CX is:project_idfrom credentialslocationfrom optionsagentIdfrom optionsfromfield as session ID
Dialogflow ES vs CX
| Feature | Dialogflow ES | Dialogflow CX |
|---|---|---|
| Visual Flow Builder | Limited | Advanced |
| State Management | Basic contexts | Pages & flows |
| Version Control | Basic | Built-in |
| Pricing | Lower | Higher |
| Complexity | Simple bots | Enterprise apps |
| Package | @builderbot/contexts-dialogflow | @builderbot/contexts-dialogflow-cx |