We have recently introduced webchat to our solution and wanted to add offline scheduling to not display the start chat button, however, the code provided doesn't appear to work, we have set offline Mon-Fri but chat still get passed to agents.
has anyone got a working example they can share please?
Yes, the current example in the documentation is misleading because schedules will not work if you just drop them into the existing web chat example.
The problem is that the original web chat example only creates web chat when the customer clicks a button. For schedules to work, ININ.webchat.create() must be called on page load.
Sorry about that! We are working on updating the documentation, but in the mean time, here is a full example:
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Web chat schedules example</title>
<style type="text/css">
#chatButton {
display: none;
}
#chatButton.purecloud-chat-available {
display: inline;
}
</style>
</head>
<body>
<h1>Web chat schedules example</h1>
<form>
<button type="button" id="chat-button">Start Chat</button>
</form>
<div id="chat-container" style="height:600px"></div>
<script src="https://apps.mypurecloud.com/webchat/jsapi-v1.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function initializeChat () {
var chatConfig = {
// Web chat application URL
webchatAppUrl: 'https://apps.mypurecloud.com/webchat',
// Web chat service URL
webchatServiceUrl: 'https://realtime.mypurecloud.com:443',
// Numeric organization ID
orgId: 1234,
// Organization name. Replace with your org name.
orgName: 'yourorgname',
// Target agent email (OPTIONAL)
agentEmail: 'alex.agent@example.com',
// Log level
logLevel: 'DEBUG',
// Locale code
locale: 'en',
// Logo used within the chat window
companyLogoSmall: {
width: 149,
height: 149,
url: 'https://dhqbrvplips7x.cloudfront.net/webchat/1.0.23/company-logo-small-9c9fe09b.png'
},
// Text displayed with chat window is displayed
welcomeMessage: 'Thanks for chatting.',
// CSS class applied to the chat window
cssClass: 'webchat-frame',
// Custom style applied to the chat window
css: {
width: '100%',
height: '100%'
},
onlineSchedules: [{
day: 'Monday-Friday',
time: '0800-1800',
city: 'America/Chicago'
}],
// Element that will have 'purecloud-chat-available' class added to it when
// intersection of online and not offline schedules
chatNowElement: chatButton,
};
var chatButton = document.getElementById('chat-button');
ININ.webchat.create(chatConfig)
.then(function (webchat) {
chatButton.onclick = function () {
webchat.renderFrame({
containerEl: 'chat-container'
});
};
})
.catch(function (err){
console.log(err);
});
});
</script>
</body>
</html>