OpenAI Meets Twilio Flex: Creating Powerful Customer Engagement with GPT-4 and the AI Tools Flex Plugin

Engineers discussing AI automation of contact center operations at a table
April 11, 2023
Written by
Reviewed by
Paul Kamp
Twilion

Ready to streamline your workflows with out-of-the-box AI? With Agent Copilot (Public Beta), Flex can automatically generate summaries, analyze sentiment, and help agents during wrap-up.

Are you looking for a way to integrate Artificial Intelligence into your Twilio Flex contact center? You aren’t alone, and I’ve got you covered.

More and more businesses are looking to enhance their customer service experience, and we are being asked by our customers if they can use OpenAI’s services with Twilio Flex.

The answer, of course, is yes! In this blog post, I'll explore how Twilio Flex and OpenAI's AI products can work together to create a seamless customer service experience. I’ll show you how to integrate OpenAI’s GPT-4 or ChatGPT with Twilio Flex using a plugin we created. Then, I’ll show you three use cases – AI-suggested responses, AI summaries, and AI sentiment analysis – to demonstrate the integration value. Let’s get started!

Solution Overview

We will demonstrate the Flex-OpenAI plugin I created  with three powerful use cases that enable businesses to leverage OpenAI’s capabilities and enhance their own customer service.

  1. AI Responses – provide the ability for agents to generate AI-powered responses to customer inquiries in real-time. This tool leverages OpenAI's natural language processing capabilities to generate helpful responses to customer queries.
  2. AI Summaries – provides the ability to summarize text that exceeds a user-defined character limit. This can be helpful for agents who must read through a lengthy and occasionally complicated message, and should enable them to understand the message's main points before responding.
  3. AI Sentiment Analysis : This function analyzes a message's sentiment, enabling agents to estimate the emotional state of a client from their messages. It enables agents to react accordingly in circumstances where the client is upset or frustrated.  Each feature within the plugin can be enabled or disabled accordingly

Diagram

Flex OpenAI architecture overview

 

Prerequisites

Twilio account

You will require a Twilio account before beginning the Twilio Flex and OpenAI integration.

  • You can create a free Twilio account here and receive credits, if you don't already have an account.
  • You will also need to build a Flex instance because this integration is a Flex plugin.
  • After signing up for the account, you'll be asked “Which Twilio product are you here to use?”. In the dropdown, select Twilio Flex – this will set up the Flex instance.

If you missed that step or you already have an account, please go to your Twilio Console and select Products to locate Flex. You can then create the Flex instance from there.

Software

You’ll also need a few things installed before you can begin work with the plugin.

OpenAI

If you don't already have an account, you must make one in order to use OpenAI.

Please be aware that while this plugin has been tried with a number of OpenAI models, GPT-4 is the recommended platform.

If you'd like to use GPT-4, which is currently in restricted beta, you can sign up for the waitlist here. However, you can still use the plugin with GPT-3 or any other compatible model in the meantime.

Flex-OpenAI integration plugin setup and build.

Awesome – you’ve now got all of the accounts and the prerequisite software and tools you’ll need. Now I’m going to walk through how to get the plugin installed.

Environment setup and install

First, we need to clone the Flex plugin and do some work with the CLI.

Clone the OpenAI tools Flex plugin from the Github repository using the command:

git clone https://github.com/Panosdevstuff/flex-plugin-openai-tools

Navigate to the plugin directory using the command line:

cd flex-plugin-openai-tools

Use npm to load the required dependencies by typing npm install.

Next, use the command twilio plugins:install @twilio-labs/plugin-flex to add the Flex Plugin extension to the Twilio CLI.

Create a Twilio Function

In your Twilio Console, create a new Twilio Service and Function on the Services pane. This Function will host the API request to GPT-4 (or the model you chose),

Copy and paste the code from src/function/gpt4.js to your newly created function. Add the dependencies and environment variables as described on the comments of the file to the appropriate panes in the Functions console.

Back in the plugin directory change the name of the file from .env.local to .env, and then follow the instructions in the file.

Log into Twilio from the CLI and deploy

Now, use the command twilio login to sign in to the Twilio CLI from your shell.

Choose a profile using the command twilio profiles:use yourprofilename

Next, test the plugin runs locally using the command twilio flex:plugins:start  

Always execute from within your plugin directory.

If your Flex install is currently live, this step requires consideration. Please read the disclaimer in git.

To deploy the plugin to your Flex instance, use the following command:

twilio flex:plugins:deploy --major --changelog "Adding initial version" --description "Twilio OpenAI tools plugin"

to build, deploy, and create a new major version of the plugin.

Finally, create a configuration and a release with the new version of the plugin using the command twilio flex:plugins:release (copy the message that appears on the screen).

Awesome – you’re now ready to move onto testing! But first, a quick demo.

Demonstrating the OpenAI-Flex integration

Below, you'll see an overview of the features in the plugin. I'll explain how to test each of them in the next section.

OpenAI Flex Plugin Integration Demo

 

Testing the OpenAI-Flex integration

To test the summary function as a user, type a long message (longer than the defined threshold in the conf file) to the conversation window, then click on the AI Summary button. A summary of the message will be displayed using OpenaAI’s GPT model:

AI summary button

 

To test the sentiment analysis: when a discussion is ongoing between an agent and a customer, click on the Analyze Sentiment button. A textbox will appear with the sentiment and an emoji:

AI sentiment analysis button

 


Test the suggestion function: upon receiving a message from the user, click on the Suggest Response button:

AI response button

 

For more personalized responses, you can provide OpenAI with additional context about your business. This is configurable under the context property in the .env file.


Integrating OpenAI’s GPT-4 with Twilio Flex

The integration of AI and Customer Engagement Platforms will change the industry... and now you’ve seen how you can do it with OpenAI and Twilio Flex. With the power of AI, the functions that we demonstrated – sentiment analysis, automatic summaries, and suggested responses – can enhance your users’ experience, improve your agents’ productivity, and ultimately lead to higher customer satisfaction.

As AI technology develops, we can anticipate seeing even more sophisticated capabilities, including completely autonomous virtual agents with decision-making abilities.

Twilio Flex is a great platform which can help you take advantage of AI as it progresses. It allows you to customize and tailor your customer experience to your specific business needs while taking advantage of the latest AI technologies. So, how will your business use AI?

Looking for more? Here are some more ideas using OpenAI and Twilio Flex:

Panos Ioannou works as a Principal Flex Solutions Engineer at Twilio, where he assists companies in EMEA with the transformation and implementation of their next generation contact centers using Twilio Flex, a customer engagement solution. For inquiries or assistance, Panos can be reached on LinkedIn