Jump to Content
AI & Machine Learning

How to integrate a Virtual Agent using Google Dialogflow ES into a Twilio Conversation

May 26, 2023
Carolina Hernandez

Cloud Solution Architect, Google

Stenal Jolly

Strategic Cloud Engineer

Twilio Flex is an omni-channel CCaaS (Contact Center as a Service) that makes it easy to build personalized support that’s unique to your business. In this post, we will show you how to integrate Flex’s asynchronous channels with Google DialogFlow.

Flex uses Twilio Conversations to natively support conversational messaging use cases such as customer support and conversational commerce via SMS, MMS, WhatsApp, Chat, GBM and FBM.

To integrate Flex with Dialogflow, we will leverage Flex’ Conversations API and SDKs to connect customers to virtual agents so you can use state-of-the-art Agent Assist and Dialogflow CX to handle customer inquiries. If you are looking for a natural language understanding platform to power your Flex asynchronous channels, these are great options; they are easy to implement, flexible, scalable, secure, and cost-effective.

This Dialogflow integration will enable you to easily create rich, natural language conversations using AI over your Twilio digital channels. 

Google Dialogflow with Twilio Conversations Differentiator  

Integrating Twilio’s Conversations API with Google Virtual Agent using Dialogflow allows you to get features that you can tweak and tune to each individual customer’s experience and you can use the power of programmability to drive deep personalization into your conversations. A virtual agent integration can help your organization to improve customer satisfaction while also reducing labor costs and increasing operational efficiency.   

Virtual agents can handle a high volume of simple, repetitive tasks, such as answering frequently asked questions, freeing up human agents to focus on more complex interactions. Additionally, virtual agents can offer 24/7 availability, quick response times, and personalized experiences through the use of data and can interact with customers through multiple channels.

Furthermore, in case a Virtual Agent is not able to resolve an issue for the customer, you can easily hand the conversation over to a human agent to continue the conversation.

Introducing a Google Open-Source middleware to integrate Dialogflow with Twilio Conversation 

At Google our mission is to build for everyone, everywhere. With this commitment in mind, the Google Cloud team has developed and open-sourced the solution for a middleware that is easily accessible and can be used as a foundational building block that integrates conversational messaging over text-based channels from Twilio with Google Virtual Agents. 

How it works

The provided open-source middleware processes the messages from a conversation by invoking Dialogflow API and returns the response from the virtual agent back to the conversation. Therefore,  two layers of communication will be handled by this solution, with Twilio and with Dialogflow. The following diagram describes a high level architecture to be presented.

https://storage.googleapis.com/gweb-cloudblog-publish/images/Blog_Twilio.max-2200x2200.jpeg

After going through Twilio onboarding process the middleware can be built and deployed on a fully managed platform such as Cloud Run  

The middleware responsibilities are

  1. Receiving callbacks for incoming messages from conversations connected with a virtual agent participant. 

  2. Managing virtual agent lifecycle while connected with the participant.

  3. Managing the conversation lifecycle between Twilio Conversations and Dialogflow Conversations

  4. Mapping between Twilio Conversations and Dialogflow Conversations with Memorystore.

  5. Processing conversation natural language understanding events from a participant and issuing responses, status and action callbacks to the conversations service.

You can find an examples of the implementation on Github:

Continue Exploring

In this blog post we described how to integrate Twilio Conversations and Dialogflow CX to deflect customer interactions to a Virtual agent. But this is just the tip of the iceberg. Here are some more ideas you can explore:

  • Extract the intents detected by the virtual agent to build a snapshot of what the customers are asking for

  • Enable sentiment analysis and the Virtual Agent will include a score of the customer's sentiment

  • Explore handing the conversation to a Twilio Flex Agent if the customer asks to talk to an agent and power with Google Agent Assist features.

  • Explore using Twilio Studio SendToFlex widget

  • Check how you can integrate Voice channel here

Conclusion

In this post,  Google has open-sourced a solution for a middleware that can be used to integrate text-based channels conversations from Twilio with Google Virtual Agents powered by Google Dialogflow. Your organization can easily and rapidly build and deploy this middleware on a fully managed platform such as Cloud Run. This can help your organization improve customer satisfaction while also reducing labor costs and increasing operational efficiency in a contact center.  If you want to learn more, review our Agent Assist basics and Dialogflow Virtual Agents pages, and the Twilio Dialogflow CX Onboarding guide to get you started.


Thanks to Aymen Naim at Twilio and Ankita Sharda at Google for their support providing feedback on our content.  We could not have done this without you.

Posted in