Contact center admins can add and edit the Script widget. The Script widget allows you to perform specific actions in the flow so that you don't need to rely on the UI to build flows. Keys, secrets, and other credentials are hidden by default in Script widgets.
Important:
This article covers:
Note: To better understand usage of the Script widget, see example configurations.
After configuring the Script widget and running it, you can map the script variable values to a flow variable.
You can also map variables in the Output variables section when customizing the Script widget.
See the account number example for details.
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)
// 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: At this time, the only external module available in the Javascript Script widget is Axios.
Add the dependency import by using this function:
const log = require('./utils/log');
Note: For the new version of the script engine, this is build-in so you don’t need to import it again
You can implement logging by using these functions:
log.debug("debugging enabled") log.error("error detected") log.info("info: yes") log.warn("WARNINGS: ")
You can implement HTTP requests using Axios. Refer to the Axios Support site for more information.
Add the dependency import by using this function:
const req = require('axios');
Note:
Example:
var {_get:var_get , _set:var_set, _setGlobalVariable:global_var_set} = require('./utils/variable');
Note: For the new version of the script engine, this is build-in so you don’t need to import it again
Use the var_get function to get the value of the variable. The var_get function can access the value of both local widget and global variables. System global variables are defined by default, but custom global variables must be defined first.
Example:
var_get()["global_system.Consumer.firstName"]
Note: While global variables are defined globally on the system, any value that you set in a global variable within a flow is limited in scope to the active engagement. In other words, if you set/change the value of a global variable within a flow, that value is only set for that specific engagement. If there are other consumers simultaneously or subsequently in the same flow, they will not have access to the updated global variable value set by another engagement.
var {_get:var_get , _set:var_set, _setGlobalVariable:global_var_set} = require('./utils/variable');
Note: For the new version of the script engine, this is build-in so you don’t need to import it again.
Use the var_set function to set the value for a local variable. The first parameter is the full name of the local variable; the second parameter is the value.
Example:var_set("account_number", “99999")The value of this variable can now be accessed within this flow as Script1.account_number
Add and configure the Script widget in your flow.
var {_get:var_get , _set:var_set, _setGlobalVariable:global_var_set} = require('./utils/variable');
Note: For the new version of the script engine, this is build-in so you don’t need to import it again
global_var_set("global_system.Consumer.firstName", "Your Name")
Note: While global variables are defined globally on the system, any value that you set in a global variable within a flow is limited in scope to the active engagement.