Loading of chat
Fetch agent availability on load
You can alter the behavior of chat by adding offline
function to cobrowse.create. This function is run when no agents are available at the team the call is made and returns name of the team.
<!-- Smilee service script start --><script type="text/javascript" charset="UTF-8">(function () {var x = document.createElement('script');x.src = 'https://saas.smilee.io/assets/javascripts/cobrowse.js';x.type = 'text/javascript';x.async = 'true';x.onload = x.onreadystatechange = function () {var rs = this.readyState;if (rs && rs != 'complete' && rs != 'loaded') return;try {Cobrowse.create({apiKey: "LQt/yocAfcWRAt...",offline: function(teamName) {console.info('Chat Client no online Agents for Team', teamName);};});} catch (e) {console.error('Failed loading Smilee script');}};var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(x, s);})();</script><!-- Smilee service script end -->
Launch chat and send message from another button
You can launch the smilee chat and send first message by adding getActionTrigger to cobrowse.create options and function like kickOpenFunc above the script. This script can use users email and name as options, these are optional. firstMessage is the only required property. If firstMessage is empty string "" the chat window will open, but if firstMessage is set the message will be send automatically when chat window is loaded. The example below launches a new chat from button with id open-chat, fetches name and email from fields with id:s and sends 'Interested about Smilee.io Chat!' message as initial message in chat.
<!-- Smilee service script start --><script type="text/javascript" charset="UTF-8">// Function to handle the opening of the chatvar kickOpenFunc = function(props) {console.log("Placeholder kickOpenFunc props:", props);};$("#open-chat").on("click", function() {kickOpenFunc({email: $("#e-mail").val(), // optionalname: $("#my-name").val(), // optionalfirstMessage: "Interested about Smilee.io Chat!"});});// End of function to handle opening(function () {var x = document.createElement('script');x.src = 'https://saas.smilee.io/assets/javascripts/cobrowse.js';x.type = 'text/javascript';x.async = 'true';x.onload = x.onreadystatechange = function () {var rs = this.readyState;if (rs && rs != 'complete' && rs != 'loaded') return;try {Cobrowse.create({apiKey: "LQt/yocAfcWRAt...",// New option to cobrowse.creategetActionTrigger = function(myCallback) {kickOpenFunc = myCallback;};// End of new option});} catch (e) {console.error('Failed loading Smilee script');}};var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(x, s);})();</script><!-- Smilee service script end -->
Change state of autopopup of chat
Smilee is exposing setAutoPopupDone and resetAutoPopupDone callbacks in success callback of the cobrowse.create. With these functions you can control the state of the autopopup of chat since in default case the autopopup is done only once.
<!-- Smilee service script start --><script type="text/javascript" charset="UTF-8">var mySetAutopopupDone // Create a variable where to store the callbackvar myResetAutopopupDone(function () {var x = document.createElement('script');x.src = 'https://saas.smilee.io/assets/javascripts/cobrowse.js';x.type = 'text/javascript';x.async = 'true';x.onload = x.onreadystatechange = function () {var rs = this.readyState;if (rs && rs != 'complete' && rs != 'loaded') return;try {Cobrowse.create({apiKey: "LQt/yocAfcWRAt...",success: function() {mySetAutopopupDone = setAutoPopupDone(), // Store the callback to the variablemyResetAutopopupDone = resetAutoPopupDone()};});} catch (e) {console.error('Failed loading Smilee script');}};var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(x, s);})();</script><!-- Smilee service script end -->