Revision as of 19:36, July 22, 2016 by Bfriend (talk | contribs)
Jump to: navigation, search

Widget Bus API Overview

The Widget Bus API comprises two components:

The Widget Bus API events and commands are executed asynchronously using deferred methods.

The Widget Bus allows you to invoke commands and subscribe to events.

The Bus is accessible via two methods:

Global Access (Available at runtime after Genesys Widgets have initialized. See onReady below)

window._genesys.cxwidget.bus

Very useful for manually triggering commands on the bus using the JavaScript console in your browser. Also accessible by your own custom programs at runtime for easy integration with Genesys Widgets.

Genesys Widgets onReady callback

window._genesys.cxwidget.onReady = function(CXBus){
    
    // Use the CXBus object provided here to interface with the bus
    // CXBus here is analogous to window._genesys.cxwidget.bus
};

For the following examples let us assume we are working within the onReady callback function.

Example 1: Subscribing to an Event

Format: CXBus.subscribe("event name and path", function(e){})

Example:

CXBus.subscribe("WebChat.ready", function(e){

    // interact with the WebChat widget now that it is initialized (ready)
});

Example 2: Invoking a Command

Format: widgetBus.command("command name and path", options).done(function(e){}).fail(function(e){})

Example:

CXBus.command("WebChat.open").done(function(e){

    // success scenario
    // the value of e depends on the command being called
    // Review the API reference for the particular command you are calling

}).fail(function(e){
    
    // failure scenario: error, exception, improper arguments
    // the value of e is typically an error string or an AJAX response object
    // Review the API reference for the particular command you are calling
})
Comments or questions about this documentation? Contact us for support!