Skip to contentSkip to navigationSkip to topbar
On this page

Releasing Flex plugins with the Plugins API


This document guides you through using the Plugins API to release Flex Plugins to your contact center.


Prerequisites

prerequisites page anchor

You must already have a plugin available and hosted somewhere. You will need its destination URL when creating a PluginVersion. For retrieving the destination URL of a plugin version already hosted, run the following command in the folder of your plugin.

This command will list all the versions of the Plugin you have deployed along with its destination URL.

npm run list

Our guide on configuring your local environment will help you use the Plugin Builder to build a plugin and deploy it using Twilio Assets.


Create a Plugin Resource

create-a-plugin-resource page anchor

For a new plugin, you must first create a Plugin resource. We recommend using the same UniqueName that you used when creating your local plugin directory, such as plugin-sample. This Plugin entity will be used for all subsequent versions of the plugin that you plan to release.

Create a Plugin ResourceLink to code sample: Create a Plugin Resource
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createPlugin() {
11
const plugin = await client.flexApi.v1.plugins.create({
12
description: "My first plugin",
13
friendlyName: "Sample Plugin",
14
uniqueName: "plugin-sample",
15
});
16
17
console.log(plugin.sid);
18
}
19
20
createPlugin();

Output

1
{
2
"sid": "FPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"unique_name": "plugin-sample",
5
"friendly_name": "Sample Plugin",
6
"description": "My first plugin",
7
"archived": false,
8
"date_created": "2020-01-10T20:00:00Z",
9
"date_updated": "2020-01-10T20:00:00Z",
10
"url": "https://flex-api.twilio.com/v1/PluginService/Plugins/FPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
11
"links": {
12
"plugin_versions": "https://flex-api.twilio.com/v1/PluginService/Plugins/FPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Versions"
13
}
14
}

Now, you can create a Version resource to indicate which version of the Plugin that you want to use in Flex. Use version 0.0.1, since that's the version of the deployed Sample Plugin.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createPluginVersion() {
11
const pluginVersion = await client.flexApi.v1
12
.plugins("PluginSid")
13
.pluginVersions.create({
14
pluginUrl:
15
"https://default-3254-f021k.twil.io/plugins/plugin-sample/0.0.1/bundle.js",
16
private: true,
17
version: "0.0.1",
18
});
19
20
console.log(pluginVersion.sid);
21
}
22
23
createPluginVersion();

Output

1
{
2
"sid": "FVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"plugin_sid": "PluginSid",
5
"version": "0.0.1",
6
"plugin_url": "https://default-3254-f021k.twil.io/plugins/plugin-sample/0.0.1/bundle.js",
7
"changelog": "the changelog",
8
"private": true,
9
"archived": false,
10
"validated": false,
11
"date_created": "2020-01-10T20:00:00Z",
12
"url": "https://flex-api.twilio.com/v1/PluginService/Plugins/FPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Versions/FVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
13
}

Create a Plugin Configuration

create-a-plugin-configuration page anchor

You now have a Plugin with a Version. You can prepare to load it into Flex by including the returned Version SID in a Configuration. The Configuration describes all of the Plugins that we'll eventually want to release to Flex.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createPluginConfiguration() {
11
const pluginConfiguration =
12
await client.flexApi.v1.pluginConfigurations.create({
13
name: "Name",
14
plugins: [
15
{
16
plugin_version: "FV00000000000000000000000000000000",
17
},
18
],
19
});
20
21
console.log(pluginConfiguration.sid);
22
}
23
24
createPluginConfiguration();

Output

1
{
2
"sid": "FJaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"name": "Name",
5
"description": "description",
6
"archived": false,
7
"date_created": "2020-01-10T20:00:00Z",
8
"url": "https://flex-api.twilio.com/v1/PluginService/Configurations/FJaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"links": {
10
"plugins": "https://flex-api.twilio.com/v1/PluginService/Configurations/FJaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Plugins"
11
}
12
}

Release the Configuration

release-the-configuration page anchor

For our purposes we're only deploying one plugin, but you could include many plugins in a single configuration. Once your configuration includes all of your plugins at the correct version, you can create a new Release.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createPluginRelease() {
11
const pluginRelease = await client.flexApi.v1.pluginReleases.create({
12
configurationId: "FJ00000000000000000000000000000000",
13
});
14
15
console.log(pluginRelease.sid);
16
}
17
18
createPluginRelease();

Output

1
{
2
"sid": "FKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"configuration_sid": "FJaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"date_created": "2020-01-10T20:00:00Z",
6
"url": "https://flex-api.twilio.com/v1/PluginService/Releases/FKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
7
}

Congratulations - your Plugin(s) should now be deployed!

You can confirm whether your plugin is enabled by logging into your Flex instance, navigating to the Developer Setup Page(link takes you to an external page) and seeing it listed under the Installed Plugins section. Or, just start playing around with the new Configuration in the Flex UI to see all of the Plugins you configured at work!