Conditional Chat Waiting Behavior Change
by Andy Rowse
HTML
<script src="//cx.rightnow.com/euf/rightnow/RightNow.Client.js"></script>
<div id="myChatLinkContainer">
<div id="myChatLink" >
<div id="myChatLinkInfo"></div>
</div>
</div>
JavaScript
RightNow.Client.Controller.addComponent(
{
chat_login_page_height: 610,
chat_login_page_width: 460,
chat_login_page: "/app/chat/chat_launch",
container_element_id: "myChatLinkContainer",
label_available_immediately_template: "Agents are available with no wait time.",
label_unavailable_busy_template: "All agents are busy.",
label_unavailable_hours: "We're sorry, chat is currently unavailable.",
ignore_preroute: true,
min_sessions_avail: 0,
wait_threshold: 86400,
info_element_id: "myChatLinkInfo",
link_element_id: "myChatLink",
instance_id: "sccl_0",
module: "ConditionalChatLink",
type: 7
},
"//cx.rightnow.com/ci/ws/get" //<-- Change to your own server
);
//Widget loaded callback
RightNow.Client.Event.evt_widgetLoaded.subscribe(function (type, args) {
//Register event to watch for when avail is checked
RightNow.Client.Event.evt_conditionalChatLinkAvailabilityResponse.subscribe(function(type, args, instance)
{
var result = args[0].data;
var scope = args[1].scope;
var eventScope = args[1];
if (result.stats) //Only set if in Chat hours. Otherwise it won't be set
{
//Redefine how the OOTB behavior works. Trick it by setting the expectedWatiSeconds to 1
var availableSessionCount = result.stats.availableSessionCount;
var expectedWaitSeconds = parseInt(result.stats.expectedWaitSeconds, 10);
if(availableSessionCount == 0 && expectedWaitSeconds == 0)
{
result.stats.expectedWaitSeconds = "1";
}
}
});
//Reverse the subscribers so that ours fires first before the OOTB
RightNow.Client.Event.evt_conditionalChatLinkAvailabilityResponse.subscribers.reverse();
});