In just a few minutes, you can extend and modify your Twilio Flex call center instance using the JavaScript React framework.
During this Quickstart, you'll use React to customize your Flex instance by integrating a search engine into the Flex CRM container. This Quickstart only involves cutting/pasting some React code. If you want to learn more, check out the official React Docs.
At the end of this Quickstart, you'll know how to develop a Flex plugin, test it locally, and upload your changes to a Twilio-hosted Flex instance. Once you've seen basic changes you can make with React, you can start to make more extensive modifications to your contact center instance.
In this Quickstart, we will:
Prefer other styles of learning? See our collection of Flex video tutorials and demos.
Before you start working on plugins for Flex, you'll need a cloud call center instance to apply them on. Let's create a new Flex instance now.
If you already have a Twilio Flex instance you'd like to customize, feel free to skip ahead to the plugin prerequisites.
Before you can work with Flex, you'll need to sign up for a Twilio account or sign into your existing account.
Once in the console, navigate to the Flex product:
Now, select 'Create My Flex Account':
And that's all you need for now. Let it go through its setup, and you'll get a vanilla hosted Flex instance for us to modify.
Before you can start creating Flex plugins with React, you'll need a few things in place.
npm -v
in your terminal to check)
A Node.js long-term-support (LTS) version installed (type node -v
in your terminal to check):
In order to run the CLI commands, on your Flex application run the following command:
_10twilio login
You will be prompted for your Account SID and Auth Token, both of which you can find in the Twilio Console Dashboard.
Once you have logged in succesfully, all the subsequent CLI commands will use the Flex account you logged in with.
Learn more about using multiple accounts by visiting the Twilio CLI General Usage Guide.
Once you have NPM and Node of the proper version, you're ready to develop your Flex plugin. The Flex Plugins CLIis the easiest way to start building Flex plugins. It gives you a clean environment in which to develop your Flex plugin as well as tools to build and deploy your plugin. With the Flex Plugins CLI, you know that your Flex plugins will be modular - that is, Plugin A won't interfere with the behavior of Plugin B.
Follow the steps in Plugins CLI documentation for installation.
In your terminal, run the following commands to set up a sample Flex plugin:
_10# Now we can start with a template plugin for Flex 2.0 with the create command_10twilio flex:plugins:create plugin-sample --install_10_10# Or if you prefer a typescript project run_10twilio flex:plugins:create plugin-sample --install --typescript
Once you have created your plugin development environment, you can navigate into your plugin's code directory and start Flex:
_10cd plugin-sample_10twilio flex:plugins:start
A Flex instance should now be running on localhost:3000
. You might need to login to your Flex instance by clicking on the "Login with Twilio" link and logging in with your Twilio credentials.
Open your favorite text editor and change the directory to the plugin folder we just built. At the moment, our plugin just adds a black bar to the top of the task list - but we're going to configure the CRM to be an instance of the Bing search engine instead.
plugin-sample
(or the name you picked)
src/SamplePlugin.js
Replace the code in that file with the following
_26import React from "react"_26import { FlexPlugin } from "@twilio/flex-plugin"_26_26import CustomTaskList from "./components/CustomTaskList/CustomTaskList"_26_26const PLUGIN_NAME = "SamplePlugin"_26_26export default class SamplePlugin extends FlexPlugin {_26 constructor() {_26 super(PLUGIN_NAME)_26 }_26_26 /**_26 * This code is run when your plugin is being started_26 * Use this to modify any UI components or attach to the actions framework_26 *_26 * @param flex { typeof import('@twilio/flex-ui') }_26 */_26 async init(flex, manager) {_26 flex.CRMContainer.defaultProps.uriCallback = (task) => {_26 return task_26 ? `https://www.bing.com/search?q=${task.attributes.name}`_26 : "https://www.bing.com"_26 }_26 }_26}
Your browser will automatically reload. Now your instance should look like the following:
(Optional) Text in and see if there are any Bing results for your phone number!
You might notice that all we changed was a couple of lines of code:
_10const options = { sortOrder: -1 };_10flex.AgentDesktopView.Panel1.Content.add(<CustomTaskList key="SamplePlugin-component" />, options);
is replaced by
_10flex.CRMContainer.defaultProps.uriCallback = (task) => {_10 return task_10 ? `https://www.bing.com/search?q=${task.attributes.name}`_10 : "https://www.bing.com"_10}
This tells Flex to target the CRMContainer
(instead of the CutomTaskList
). Instead of adding a component to the CustomTaskList
, we update the URI that the CRMContainer
uses as a default prop to render its contents. In this case, we also add a bit of logic to make the container dynamic. We check to see if there's an active task. If there is an active task, we search for the task's name attribute, otherwise, we just show the https://bing.com
landing page.
Flex allows you to add, remove, and replace components so that you can tailor your contact center to your business needs. As you build more complex plugins, your workflow will remain similar. When you save files, your environment will reload and you can see the changes locally. To use the Twilio Paste UX library in your plugins, please see Use Twilio Paste with a Flex Plugin.
Next up, you'll build the plugin and deploy it to your hosted instance.
You need to deploy your plugin so that your plugin can be enabled on your live Flex Application. The Flex Plugins CLI uses the Functions & Assets API to upload your plugin directly from your CLI.
In your terminal, within the plugin-sample
directory we created, run
_10twilio flex:plugins:deploy --major --changelog "Adding Bing as search engine" --description "First Plugin on Flex"
Inorder to enable your plugin, run
_10twilio flex:plugins:release --name "First Plugin Release" --description "Enabling Plugin Sample" --plugin plugin-sample@1.0.0
Refer to our guide on how to deploy your plugins if you are deploying plugins to multiple accounts.
You now know how to build Flex Contact Center plugins using React, test them locally, then upload them to the cloud. You have the scaffolding to build whatever plugins you desire and see them reflected almost instantly in your call center instance.
Depending on your goals, we have a few paths you might want to follow next. Either explore more around plugin development with Flex and React or visit some of our other Flex Quickstarts.
We can't wait to call what you build!