Skip to contentSkip to navigationSkip to topbar
On this page

Flex Manager


The Flex Manager is the access point for controlling your Flex instance and all of the underlying Twilio products used for communications and assigning tasks. This means that within your Flex project, you can access the TaskRouter or Chat client directly through the Flex manager.

Aside from Flex itself, Manager also gives you access to the Programmable Chat, Sync, Client, and TaskRouter SDKs.


Manager Class

manager-class page anchor

See the official Flex UI 1.x.x docs on the Manager class(link takes you to an external page) for a full list of attributes and methods.


How to obtain the Manager instance

how-to-obtain-the-manager-instance page anchor

You can access the manager as follows:

By calling the getInstance method

by-calling-the-getinstance-method page anchor
Flex.Manager.getInstance()

By calling the create method when initializing Flex

by-calling-the-create-method-when-initializing-flex page anchor
1
return Flex
2
.provideLoginInfo(configuration, "#container")
3
.then(() => Flex.Manager.create(configuration))
4
.then(manager => {
5
// use manager here
6
})
7
.catch(error => handleError(error));

You can check out the sample project(link takes you to an external page) on how to initialize Flex.

In the init method of your plugin

in-the-init-method-of-your-plugin page anchor
1
init(flex, manager) {
2
// use manager here
3
}

Subscribing to Manager events

subscribing-to-manager-events page anchor

You can use Flex Manager to subscribe to events that occur from Flex. See Flex Events(link takes you to an external page) for more details.

1
import { Manager } from "@twilio/flex-ui";
2
const manager = Manager.getInstance();
3
4
manager.events.addListener('eventName', (payload) => {
5
// implement logic here
6
});
7

For example, you can subscribe to the pluginsLoaded event to know when all Flex Plugins have loaded.

1
manager.events.addListener("pluginsLoaded", () => {
2
console.log("Plugins have been loaded!");
3
});
4

Common use cases and examples

common-use-cases-and-examples page anchor

This example logs connect in the browser's console whenever the agent connects to a call:

1
Flex.Manager.getInstance().voiceClient.on('connect', () => {
2
console.log('connect');
3
});
4

By mixing calls to the Manager with the Actions Framework, you can perform more complex tasks like this example that automatically accepts all inbound chats for agents:

1
Flex.Manager.getInstance().workerClient.on("reservationCreated", reservation => {
2
if (reservation.task.taskChannelUniqueName === 'chat' && reservation.task.direction === 'inbound') {
3
Flex.Actions.invokeAction("AcceptTask", {sid: reservation.sid});
4
Flex.Actions.invokeAction("SelectTask", {sid: reservation.sid});
5
}
6
});

The insightsClient provide access to the Twilio Sync SDK. For Flex accounts, this gives access to workers and tasks data through the use of two classes:

Both classes needs two arguments:

  • Index name: data set the query is executed against. Currently supported index names for Flex are: tr-task, tr-worker, tr-reservation, tr-queue.
  • Query: this is the query used to filter the data from the index. The syntax for the query is documented here. The query can be an empty string: in this case the whole data set is returned (e.g. all workers.)

In this example, the insightsClient is used to query the workers with activity_name set to Available and subscribe to changes. That means that every time a worker change its status to Available, an event itemUpdated is fired. If a worker changes its status from Available to any other status, the itemRemoved event is fired.

1
Flex.Manager.insightsClient
2
.liveQuery('tr-worker', 'data.activity_name == "Available"')
3
.then(function (args) {
4
console.log(
5
'Subscribed to live data updates for worker in "Available" activity'
6
);
7
args.on('itemRemoved', function (args) {
8
console.log('Worker ' + args.key + ' is no longer "Available"');
9
});
10
args.on('itemUpdated', function (args) {
11
console.log('Worker ' + args.key + ' is now "Available"');
12
});
13
})
14
.catch(function (err) {
15
console.log('Error when subscribing to live updates', err);
16
});
17

In this example, the insightsClient is used to query the workers with specific skills inside its attributes. This returns an array of workers that can be used to provide static data.

1
manager.insightsClient.instantQuery('tr-worker').then((q) => {
2
q.on('searchResult', (items) => {
3
// Do something with the results
4
});
5
q.search('data.attributes.languages contains "english"');
6
});

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.