Changing Polling Intervals on Syndicated Conditional Chat

One item that is not exposed in Syndicated Conditional Chat's initialization parameters is the polling interval. The interval is unfortunately hard coded into the widget, but this doesn't mean that you can't control it. There is a widget initialization parameter named "enable_polling"; when this value is set to "false", the widget will not poll the server. This then gives you the chance to write your own polling logic using the syndicated widget frameworks Event system.

This works by subscribing to 2 events

  • evt_widgetLoaded
  • evt_conditionalChatLinkOffered

In your event handler for evt_widgetLoaded, you write your code to manually call the "Check Availability" method, then set that function to be recursively called on an interval of your choosing. Additionally you subscribe to the evt_conditionalChatLinkOffered event so that you can keep track of when there was sufficient availability and the chat link appeared. This then enables you to stop polling for availability.

I've constructed a working demo on JSFiddle: This example code pings the Oracle RightNow CX site for availability. It will almost always return "none". For your own purposes, replace the URL on line 17 with your own site. I've set up my code to ping on an ever increasing interval. Every check delays the next check by 2 seconds. Also be sure to turn on your Console so that you can see the logging messages.

Here's the code:

        container_element_id: "myChatLinkContainer", 
        info_element_id: "myChatLinkInfo", 
        link_element_id: "myChatLink", 
        instance_id: "sccl_0", 
        module: "ConditionalChatLink",	 
        wait_threshold: 300, 
        ignore_preroute: false, 
        min_sessions_avail: 0, 
        enable_availability_check: true, 
        enable_polling: false,  //Disabled polling
        label_default: "Chat directly with a member of our support team.", 
        type: 7
    "//" //<-- Change to your own server
//Widget loaded callback
RightNow.Client.Event.evt_widgetLoaded.subscribe(function (event_name, data) {
    if (data[0].id == "sccl_0") {           
        var chatOffered = false;
        var interval = 1000; //1 seconds
        //Register event to watch for when the chat link is offered
        RightNow.Client.Event.evt_conditionalChatLinkOffered.subscribe(function(event_name, data)
            if (data[0].id == "sccl_0") {
                console.log("chat offered");
                chatOffered = true; //Set flag. Used by resursive function.
        //Resursive function to check for chat availability
        var refreshChat = function()
            if(!chatOffered) //Check if chat was offered previously (i.e. The link is showing)
                //sccl_0.attrs.wait_threshold = 40000; //make this more to ensure
                interval += 2000; //Add 2 seconds per loop
                console.log("Checking availability: " + interval);
                //Initialize timer
                setTimeout(refreshChat, interval);
        //Kick off our recursive function

Zircon - This is a contributing Drupal Theme
Design by WeebPal.