Customizing the Script widget in zoom app
The Script widget can be added and edited by contact center administrators. This Script widget allows you to create a flow by submitting the desired actions to the widget itself, eliminating the need for you to rely on the UI when building a flow. By default, Script widgets hide keys, secrets, and other credentials that are associated with them.
Important:
-
Zoom Contact Center announced that it will be launching a new script engine on September 17, 2022 which introduces a new syntax for scripts. There will be no impact on existing scripts as a result of this change. There are, however, a few rules that must be followed when developing new script widgets. This article includes examples of new script syntax in the New version section.
-
The following example configurations will help you to better understand how to utilize the Script widget.
Prerequisites for customizing the Script widget
-
Ownership or administrative privileges of the account
-
Whether you are a Business, Education, or Pro account holder
-
A license for Zoom Contact Center is required
-
Create voice, video, web, in-app, or SMS flows based on your preference
-
An advanced understanding of Javascript is required
How to add or edit the Script widget
-
Zoom’s web portal can be accessed by logging in.
-
Click Contact Center Management from the navigation menu and then click Flows from the drop-down list.
-
The display name of a flow can be edited by clicking on it.
-
Script can be dragged into the preferred location in the flow by clicking and dragging the widget in the left-side widgets panel.
-
You will need to select the widget called Script.
-
The widget can be renamed to make it more understandable to the end user. Click on Rename to make your change.
-
Adding a new script to a widget can be done by clicking the Add Script button, then specifying the following options:
-
Name: The script must be given a name that can be used internally to identify it.
-
Language: Scripting languages can be chosen from the dropdown menu.
-
-
Please click the Add button.
-
If you are using JavaScript, please enter the code below.
-
The Input Parameters panel can be used to input parameters for the script in JSON format on the right side of the screen. This is used to test the script locally. The key/value pairs need to be included according to the JavaScript code, so make sure to include them. The input parameter you will need to provide should contain all key/value pairs you expect to see when testing your code locally.
-
Click on the Run button.
In the Results section, you will be able to see the results. -
Close the window by clicking on it.
-
To save the script, click the Save button.
-
Click on the following options in the Settings tab (optional):
-
Pencil icon : Edit the script.
-
Trash bin icon : Delete the script.
-
-
You can customize your exit settings by clicking the Exits tab.
-
Success: In the event that the script has been successfully run, select the destination widget.
-
Fail: When the script fails to run, select the widget that should be the destination
-
Note: See example configurations of the script widget in order to get a better understanding of how it works.
Script variable mapping
It is possible to map a script variable value to a flow variable after configuring the Script widget and running it.
-
In the script var_set(), all variables are set into a flow variable named widget which is then associated with the script var_set(). It is possible to consider this variable to be a local variable.
-
There is a flow variable called value under the widget name which contains the value returned by the script when the widget is invoked.
-
Global custom variables should be defined for all variables which are set by global_var_set in order to be used in global variables. It is possible to reference the full name of the global variable in the Script widget as well as to modify it by using global_var_set in the Script widget.
Example of script mapping
For more information on account numbers, please refer to the example below.
How to program scripts
-
Your code should contain all the dependencies that you need. You can see the example code below in lines 2 to 4.
-
In order for the code engine to be able to extract your JS function, pass your function to module.exports. Async should only be used when await is required in your function. The function does not need to be called from the code panel, so there is no need to call it there.
Note: An automatic switch is turned on to enable strict mode.
Example of script programming
New version
async function main () { // your code starts here } Note: #### Supported built-in functions: (no need to import again) ## Variable Get/Set: var_get()[string]; var_set(string, string); global_var_set(string, string) ## Http Requests: req.get(url[, config]); req.delete(url[, config]); req.head(url[, config]); req.options(url[, config]) req.post(url[, data[, config]]); req.put(url[, data[, config]]); req.patch(url[, data[, config]]) ## Logging log.debug(string), log.info(string), log.warn(string), log.error(string)
Old version
// Using Lambda const log = require('./utils/log'); const req = require('axios'); // this is needed only if you plan to use Axios in your function var {_get:var_get , _set:var_set, _setGlobalVariable:global_var_set} = require('./utils/variable'); module.exports = async () => { // add your script logic. See two examples above. return }
Note: The Javascript Script widget currently only provides access to the Axios external module, which is the only one available at the moment.
How to use logging
By using the following function, you will be able to import the dependency:
const log = require(‘./utils/log’);
Note: There is a new version of the script engine that already includes this, so you do not need to import it again since it is built-in
Example of logging
The following functions can be used to implement logging in your application:
log.debug(“debugging enabled”) log.error(“error detected”) log.info(“info: yes”) log.warn(“WARNINGS: “)
How to implement HTTP requests
The HTTP requests can be implemented using Axios using the HTTP request library. You can find more information about Axios Support on the company’s website.
By using the following function, you will be able to import the dependency:
const req = require('axios');
Note:
-
You don’t have to import it again because this is already built-in to the new version of the script engine.
-
The HTTP Call widget is a standard widget that allows you to make HTTP requests with the help of JavaScript functions without having to write any JavaScript. For more advanced use cases, you may use the Axios module in conjunction with a script that executes HTTP requests, as well.
How to get variables within the Script widget
-
Your flow should include a script widget that you can add and configure.
-
The variable dependency import needs to be added to the JavaScript file.
Example:
var {_get:var_get , _set:var_set, _setGlobalVariable:global_var_set} = require('./utils/variable');
Note: You don’t have to import it again because this is already built-in to the new version of the script engine.
-
To find out what the value of a variable is, you can use the var_get function. Both local widget variables as well as global variables can be accessed using the var_get function. In addition to the globally defined system variables, you must define your own global variables before you can use them.
Example:
var_get()["global_system.Consumer.firstName"]
Note: Variables within flows are limited in scope to the active engagement even though global variables are defined globally on the system. A global variable’s value is specifically set for a specific engagement when it is set/changed within a flow. The updated global variable value set by another engagement will not be available to other consumers simultaneously or subsequently in the same flow.
How to set local variables within the Script widget
-
Add the Script widget to your flow and configure it. The Script widget should be renamed Script1 in this example.
-
The variable dependency should be imported into a JavaScript file. The dependency import needs to be added.
Example:
var {_get:var_get , _set:var_set, _setGlobalVariable:global_var_set} = require('./utils/variable');
Note:There is no need to import this again since it is built in to the new version of the script engine.
-
Set a local variable’s value using the var_set function. Local variables are named using their full names and their values are identified by their values.
Example:
var_set("account_number", “99999")
Within this flow, Script1.account_number can be accessed as the value of this variable
How to set global variables within the Script widget
-
Script widget should be added and configured in your flow.
-
The variable dependency import needs to be added to a JavaScript file.
Example:
var {_get:var_get , _set:var_set, _setGlobalVariable:global_var_set} = require('./utils/variable');
Note: You don’t need to import it again since it’s built into the new version of the script engine
-
Set a global variable’s value using the global_var_set function. A global variable’s full name is the first parameter, and the value is the second.
Example:
global_var_set("global_system.Consumer.firstName", "Your Name")
Note: Flows are limited in scope, while global variables can be defined globally on the system.