Tutorial: Hello World!

Hello World!

This example assumes that you've loaded the VisitorAPI library with one of the methods discussed here.

First it is checked if the support agent of department "C" is available. If so the initially deactivated chat button will be enabled and a click handler which opens a chat popup window will be registered.

You should insert the appropriate values for the location of your yalst server directory as well as your 'site id' and the 'department id'.

////// Example use of the API //////

// IMPORTANT: Always associate the API to a particular yalst live support product first,
// BEFORE calling any other method!
function onYalstVisitorAPILoaded(api)
{
    api.associateWithLiveSupportProduct(
        "https://YALST_PRODUCT_SERVER/YALST_DIRECTORY", // e.g. https://example.com/yalst
        "YALST_SITE_I_E_LICENSE_KEY" // e.g. "1-1"
    );

    api.getOperatorAvailability(onAvailabilityDetected, "C");


    function onAvailabilityDetected(status){
        if (status instanceof Error){
            alert("An error has occurred:" + status.toString());
        }
        else if (status == api.Availability.AVAILABLE){
            var chatButton = document.getElementById('assist_me_button');

            chatButton.removeAttribute("disabled");

            $(chatButton).click(function(){
                api.startLiveChat();
            });
        }
    }

}