Mastering Twilio's One-Click Dialogflow CX Integration

March 14, 2024
Written by
Reviewed by

Revolutionizing Customer Engagement

Conversational AI has emerged as a transformative force in customer engagement, redefining the way businesses interact with their customers. This innovative technology streamlines communication, offering a seamless and intuitive experience that aligns with modern consumer expectations.

By integrating conversational AI, companies can significantly enhance their customer service and sales operations, providing instant, round-the-clock support. The automation of routine inquiries not only accelerates response times but also allows human agents to concentrate on more complex and high-value interactions.

Moreover, conversational AI's ability to understand and process natural language enables it to guide customers efficiently, reducing the friction associated with traditional communication methods like IVR trees. The result is a more efficient, personalized, and satisfying customer experience that drives loyalty and growth.

Twilio’s native integration with Google Dialogflow CX

In this blog post, we’ll dive into Twilio’s native integration with Google Dialogflow CX to craft an engaging virtual agent experience. We'll explore sophisticated features, including the seamless exchange of context between Twilio and Dialogflow, and delve into practical use cases that leverage these capabilities.

We will also explore strategies to amplify your existing communications platforms with Twilio's advanced features and demonstrate the transformative impact of adopting Twilio as your core platform.


This blog post is designed for readers with a general understanding of Twilio and Google Dialogflow CX . However, even those new to these platforms should find the walkthrough accessible. We will guide you through a typical Natural Language Understanding use case to facilitate a clearer comprehension.

  • If you don’t have a Twilio account you can sign up for a Twilio trial account here .
  • If you don’t have access to Dialogflow CX you can follow this guide to get started.
  • As of March 2024 the one-click integration is in Beta. You may need to contact support to enable some of these features.

Getting started

Integrating Twilio with Google Dialogflow CX is streamlined through Twilio Studio , a visual workflow designer that enables low-code or no-code development of communication applications. By following the Dialogflow CX Onboarding Guide , we can activate the Connect Virtual Agent Widget in Twilio Studio, which links to your Dialogflow CX virtual agent for advanced conversational AI capabilities.

After completing the integration, the pre-configured widget can be incorporated into our Studio Flow, seamlessly connecting Dialogflow with our voice and messaging services.

The Twilio one-click Dialogflow CX Integration Widget for Messaging is still in Beta and subject to change. Please ensure you review the official documentation in the event you come across any inconsistencies.

Passing context to Google Dialogflow CX

Passing contextual information from Twilio Studio to Dialogflow CX is essential for personalized customer interactions. This can include data such as customer identifiers, types, names, or other variables. The Connect Virtual Agent Widget in Twilio Studio facilitates this by allowing the inclusion of widget parameters.

For instance, in a Studio Flow, we might begin by retrieving customer details with an 'Execute Function' Widget named GetCRMDetails. Subsequently, we can use the Connect Virtual Agent Widget to engage the Virtual Agent with the call, armed with the fetched CRM data.

Build a studio flow for our virtual agent

To transfer customer record data from Twilio Studio to Dialogflow CX, we can set a new parameter within the Connect Virtual Agent Widget. For instance, we might create a parameter with the key customer_name. The value for this parameter would be a Liquid template variable that contains the firstname field extracted from the customer record obtained via the GetCRMDetails Widget. This ensures that the Dialogflow CX agent receives relevant customer information, enabling a more personalized interaction.

Extract a firstname for personalization

The configuration above is passing a key-value pair (KVP) to Dialogflow CX which can be used in our customer journeys. These values are stored as session parameters on Google Dialogflow CX.

As an example, to create a personalized Default Welcome Intent in Dialogflow CX that includes the customer's name, we can utilize the customer_name key-value pair (KVP) stored in the session parameters. If the customer_name KVP is set, we can access it within the intent to tailor the welcome message. Here's how to reference the session parameter in the intent response:

Reference a session parameter in an intent response.

We should also set a condition on the intent to ensure this Default Welcome Intent is only triggered when the parameter is set:

Only trigger a Default Welcome Intent if conditions are met.

Finally, we can make sure the new Default Welcome intent is triggered before the standard Default Welcome intent by moving it to the top of the route execution order. You can differentiate them by looking at the conditions:

Ordering the queue execution order.

In this test scenario, when we initiate a call to a number connected to the Studio flow, the system checks for an existing customer record in the CRM. If the record is found, it confirms that we're successfully passing the customer's information as a parameter to Dialogflow. Consequently, this triggers a personalized Welcome intent within Dialogflow. During an audio test, we would expect to hear the following output:

Personalized message when we find a user in the CRM.

On the other hand, if we place a call to the same number and there is no existing customer record in the CRM, the parameter passed to Dialogflow is null. As a result, the system triggers the generic Welcome intent instead of a personalized one. This ensures that all callers receive an appropriate greeting, whether or not their information is on file.

Didn't find the record in the CRM so send a generic message.

Receiving context from Dialogflow CX

Passing data from Google Dialogflow CX back to Twilio Studio is essential in various customer service scenarios. Dialogflow CX serves as the initial touchpoint, providing automated responses to common queries and integrating with systems like CRMs or ticketing platforms to streamline processes. It also enhances the customer experience by simplifying the IVR (Interactive Voice Response) system, allowing users to express their needs in natural language and be directed to the appropriate department without navigating complex menu options.

The Twilio Studio Connect Virtual Agent widget facilitates this interaction by enabling Dialogflow CX to send a Live Agent Handoff response back to Twilio Studio. This response can carry valuable data that Studio can use to route the customer to the correct queue, schedule a callback, initiate a CRM workflow, or generate a support ticket.

The following example shows how we could use Dialogflow and the Studio widget to flatten the IVR tree. Let’s assume your contact center has three departments: sales, service and complaints. In order to flatten the IVR tree, we can define 3 intents on the Dialogflow Agent with example phrases that would trigger these. Then, we would create 3 additional routes on the start page, each with one of these intents:

Selecting the sales queue intent

Each of these routes would then define the queue you want to use by setting a queue parameter. As an example, the sales queue route defined above would preset the parameter queue as per the image below.

Presetting the parameter "queue" with the "sales" value.

Additionally, we can set the preferred agent message and transition the route to a page called Live Agent Handoff.

Setting the preferred agent message when we hand off a call.

Each of the 3 intents we defined can have a different agent message and the same or a different transition. In this example we transition all of these intents to the same page. Our Live Agent Handoff page will then have an Agent Response dialog option Live Agent Handoff type, where we define what parameters go back to Twilio Studio as a JSON document.

Define what parameters go back to Twilio Studio as a JSON document in the Live Agent Handoff field.

Going back to the example where we want to flatten the IVR tree, once the Dialogflow Agent hands the interaction back to Twilio Studio, we can access this information within the Studio flow. The REST document we send from Dialogflow is accessible via the VirtualAgentProviderData.AgentHandoffParameters., where in this scenario the key is selected_queue. Assuming we want to enqueue the call to a Flex contact center, one way of routing the task based on the Dialogflow CX data would be to pass the queue parameter as a task attribute as per the example below:

Showing how to pass the queue parameter as a task attribute

In a scenario where we use Twilio TaskRouter to enqueue tasks to workers, we could achieve the same result by passing the selected_queue as an attribute and adjusting the TaskRouter workflow accordingly.

The example we’ve covered showed us how we can flatten the IVR tree by routing calls or conversations based on intents instead of IVR tree options. But the same capabilities could be used to pass other data. Let's assume we implemented a password reset process whereby the user needs to go through an Identification and Verification (ID&V) process on Dialogflow. In the event the user needs to speak to a human agent, we could pass the result of that process back to Studio, so that we could then inform the agent of the result of both the ID&V process and whether the reset was successful or not.

How can I bring these capabilities to my existing platform?

Twilio is a powerful and flexible Communications Platform as a Service (CPaaS), empowering users to implement comprehensive solutions or enhance their current communication systems. While we've explored the integration of these capabilities in combination with Twilio Flex or TaskRouter based solutions, it's important to note that these advancements can also revitalize existing 3rd party PBX or Contact Center infrastructures.

For those already leveraging Twilio for PSTN connectivity, Twilio Programmable Messaging or Twilio Programmable Voice , incorporating the functionalities we've discussed is a seamless process. Your Twilio Account Executive is ready to assist with any support you may need.

For organizations not currently utilizing Twilio, integration with your existing service provider is still within reach, or you can tap into Twilio's Programmable features through SIP. We invite you to get in touch with us —our team is eager to guide you through the integration process and help you unlock the full potential of Twilio's offerings.

Ricardo Bangueses is a Principal Solution Engineer at Twilio. He loves helping companies design great customer engagement solutions. He can be reached on LinkedIn .