Customizing the Script widget for Zoom Virtual Agent


 

Zoom Virtual Agent admins can add and edit the Script widget. The Script widget allows the bot to build actions using Javascript so that you don't need to rely on the UI to build flows. You can look for IDs, names, details on the site, or in an API. The results can be set in variables that can be stated back to the user.

Prerequisites for customizing the Script widget

How to edit the Script widget

  1. Sign in to the Zoom web portal.
  2. In the navigation menu, click AI Management then Virtual Agent.
  3. Click the display name of an existing chatbot.
  4. Click the Bot Flows tab.
  5. Click the display name of an existing bot flow.
  6. In the left-side widgets panel, click and drag Script onto the preferred location in the flow.
  7. Select the Script widget.
  8. (Optional) In the right-side panel, click Rename to change the display name of the widget.
  9. In the Setup tab, click Add Script to add a new script to the widget, then specify these options:
    • Name: Enter an internal display name to help identify the script.
    • Language: Select the scripting language.
  10. Click Add.
  11. Enter your JavaScript code.
    To test your code locally, on the right side, use the Input Parameters panel to input parameters for the script in JSON format. Make sure to include the appropriate key/value pairs as required by your JavaScript code. When testing your code locally, you will need to provide all expected key/value pairs as Input Parameters.
  12. Click Run.
    The result will appear in the Results section.
  13. Click Close.
  14. Below Map output to, select a variable in the drop-down menu.
  15. (Optional) Click Add Variable to add more script variable.
  16. Click the Exits tab to customize exit settings.
    • Success: Select the destination widget if the script is able to run successfully.
    • Fail: Select the destination widget if the script failed to run.

Sample script code

 async function main() {

    var input = var_get()["order_email"];

    //var input="alpha.adam@example.com";

    log.info(input);

    //replace with your url

    var baseurl = 'https://zoomineer-hues.myshopify.com/admin/api/2023-01/customers/';

    var url = baseurl + "search.json?query=email:" + input

    var config = {

        url: url,

        headers: {

            'X-Shopify-Access-Token': 'replace this with your token'

        }

    };

    const resp = await req.get(url, config);

    // log.info(JSON.stringify(resp.data.customers[0]))

    const customer = resp.data.customers[0];

    var cust_info = {

        "id": customer.id,

        "first_name": customer.first_name,

        "last_name": customer.last_name,

        "email": customer.email,

        "last_order_id": customer.last_order_id

    }

    const order_id = cust_info.last_order_id;


    log.info(JSON.stringify(cust_info));

    // lookup orders by cust id

    const cust_id = cust_info.id;

    url = baseurl + cust_id + "/orders.json";


    const resp1 = await req.get(url, config);

    const orders = resp1.data.orders;

    const order_ids = orders.map(getOrders);


    function getOrders(order) {

        return order.id;

    };


    var_set("order1", order_ids[0]);

    var_set("order2", order_ids[1]);


    // log.info(JSON.stringify(order_ids[1]))


    return order_id;

}