Embed Elastic App Search into Twilio Flex to help your Flex agents become more efficient

February 23, 2022
Written by
Reviewed by

Embed Elastic App Search into Twilio Flex to help your Flex agents become more efficient

Employees spend up to 20% of their time searching for information inside their company’s fragmented data systems (wiki, content management system, websites, CRMs, communication platform, etc.). This issue becomes more prominent in the contact center industry where agents have to respond quickly to customer queries. Contact Center agents are expected to provide timely and accurate information.

In this blog post, you will learn how to enable your agents to easily find the content they are looking for by integrating Elastic App Search with Twilio Flex.

Solution overview: Elastic App Search + Twilio Flex

Elastic App search is a product that provides powerful search, aggregation, and analytics capabilities as a Service, on top of Elasticsearch. Twilio Flex is a cloud-based contact center that is built on top of Twilio's cloud communications platform. By embedding search into Flex, your agents are able to find information more efficiently, without needing to juggle various browser tabs. With this solution, Agents can search and find content across multiple repositories and wikis to provide the best possible experience to your customers.

To develop this solution, you will create a Flex plugin, which is the recommended way to customize the Flex UI. You will also use Search-UI, a React library by Elastic that allows you to quickly implement search experiences without re-inventing the wheel. The end result is a search page within Flex that lets you quickly find information that is specific to your organizational needs.

Screenshot of an agent calling with a customer using Twilio Flex while searching for answers using the search feature you will build

Prerequisites

To follow along with this demo, you will need:

Project Setup

You can find all the source code for the Flex plugin in this GitHub repository. To quickly get started with this project, download the repository as a ZIP file and unzip it. Alternatively, you can run this Bash or PowerShell script to have it done for you:

Bash:

curl -L -o main.zip  https://github.com/apanagidis/flex-essearch/archive/refs/heads/main.zip
unzip main.zip
rm main.zip

PowerShell:

Invoke-WebRequest https://github.com/apanagidis/flex-essearch/archive/refs/heads/main.zip -OutFile main.zip
Expand-Archive main.zip
Move-Item main/flex-essearch-main/ flex-essearch-main
Remove-Item main.zip
Remove-Item main

Navigate to the flex-essearch-main folder in your preferred shell:

cd flex-essearch-main

There are multiple ways to get started with Elastic App Search, but the easiest way is to create an App Search cluster using docker and docker compose. Docker compose is a tool for defining and running multi-container Docker applications.

An example docker compose configuration file is provided with the source code. Use a text editor to open the docker-compose.yml file and change the default usernames and passwords. Run the containers using docker compose with the following command:

docker-compose up

Your docker host will need at least 4gb of free memory to run these containers.

Once your cluster is up and running, you can access from http://127.0.0.1:5601/app/enterprise_search/app_search/engines with the credentials specified in docker-compose.yml.

The next step is to create an engine to host your documents. Depending on your use case, you might want to index your own documents or use the built-in crawler to crawl a few websites. The end result is that you will have the information indexed in your engine for quick access. For this tutorial, you can click on "Try a sample engine" which will create an engine with USA's national parks.

The final step is to obtain your credentials from the credentials page of App Search. Click Credentials in the navigation on the left. You will find two keys on this page. Take note of the Public Search Key as you will need it later.

Leave the containers running and open a new shell for the upcoming commands.

Elastic App Search Flex Plugin

Flex plugins use the Twilio CLI for deployment and development. Make sure you have the latest version of the Twilio CLI installed. Next, make sure you are logged in using your Twilio Flex account. If you are not logged in, run the following command:

twilio login
twilio plugins:install @twilio-labs/plugin-flex@v4
twilio plugins:install @twilio-labs/plugin-serverless

Install the dependencies using npm:

npm install

In the /public directory, make a copy of the appConfig.examples.js file and rename it to appConfig.js.

In the root directory, make a copy of .env.sample, rename it to .env and update the ​​REACT_APP_SEARCH_KEY variable with your Public Search Key.

You can use the Twilio CLI to run and develop your Flex plugin locally. Run the following command from the root directory of the plugin.

twilio flex:plugins:start

This will automatically start up the Webpack Dev Server and open the app in the browser at http://localhost:3000.

Click on "Log in with Twilio" and log in using your Twilio profile. After logging in, you'll see the Flex UI with your plugin on the right side. Enter "Yos" in the search field and click Search. You should see one result for "Yosemite".

If you did not use the sample engine, you will need to update the code in src/components/ESSearch/ESSearch.jsx. Specifically, you'll need to at least update the config attribute of the SearchProvider node and the attributes of the Results node to match the schema of your App Search Engine.


When you make changes to your code, Webpack will automatically push the changes to the browser using Hot Module Replacement (HMR). HMR shortens the inner dev-loop and thus makes you much more productive when developing these plugins.

Plugin Deployment

Once you are happy with your plugin, you have to deploy it and then release the plugin for it to take effect on Twilio hosted Flex.

Run the following command to start the deployment:

twilio flex:plugins:deploy --major --changelog "Notes for this version" --description "Functionality of the plugin"

After your deployment runs, you will receive instructions for releasing your plugin from the bash prompt. You can use this or skip this step and release your plugin from the Flex plugin dashboard.

For more details on deploying your plugin, refer to the deploying your plugin guide.

You also have to refresh your browser for the new plugin deployment to take effect.

Twilio Flex user is typing into a search box to find documentation

Ideas to improve the solution

There are search products that can offer additional functionality to this solution:

  • You could use Elastic Workspace to easily ingest information from various data sources using connectors.
  • You could use Amazon Kendra to ingest data with ease using connectors and fine tune search results with continuous improvement and machine learning.

Adonis is a Twilio Solutions Architect working on the Professional Services team who advises and supports our customers with their Twilio builds. You can reach him at apanagidis [at] twilio.com.