$(document).ready(function () { var template = `
`; $('body').append(template); //document.querySelector(".ad-area-mobile").addEventListener("click", function(event) { // event.preventDefault(); //}, false); try { var socket = io.connect( "https:" + socketEndpoint, { 'reconnection': true, 'reconnectionDelay': 500, 'reconnectionAttempts': 10 }); var name; getSessionId(); var status = true; var autoClose = false; $(".rufus-container").mouseover(function () { autoClose = false; }); socket.on('bot close', function (msg) { setTimeout(() => { if (autoClose && !rufuslanding) { $(".btn-open-rufus").addClass("active"); $(".rufus-container").removeClass("expand-rufus"); $(".rufus-container").addClass("close-rufus"); // $(".message-count").css("display", "flex"); } }, 3500); }); $(window).on('beforeunload', () => { socket.emit('user unload', { sessionid: Cookies.get('sessionID'), key: rufuskey }); }); // Receive Message From User and displays it socket.on('user send', function (msg) { console.log("user send") var random = Math.floor(Math.random() * (10000000 - 1)) + 1; var message = ` `; $('.chat-log').append(message); scrollChatBottom("fast"); $("#" + random).velocity( { opacity: 1 }, { duration: 500, begin: function (elements) { $("#" + random).find('.text').html("" + msg.msg + "
"); $("#" + random).find('.text p').velocity({ opacity: 1 }, { duration: 800, easing: "easeOutCubic", complete: function (elements) { if (status) { scrollChatBottom("fast"); socket.emit('bot send', msg); } } }) } }); }); socket.on('bot send', function (msg) { sendMessage(msg.payload, msg.delay); }); socket.on('bot send text', function (msg) { sendMessage(msg.payload, msg.delay); }); socket.on('bot send end', function (msg) { sendMessage(msg.payload, msg.delay); }); socket.on('bot send button', function (msg) { sendbutton(msg.payload); }); socket.on('bot send buttons', function (msg) { sendbutton(msg.payload); }); socket.on('bot send contact form', function (msg) { sendContactForm(); }); socket.on('bot send calendar', function (msg) { sendCalendar(); }); socket.on('bot send time', function (msg) { sendTime(); }); socket.on('bot send dropdown', function (msg) { sendDropdown(msg.payload); }); socket.on('bot send keyboard', function (msg) { setTimeout(function () { showTextInput() }, 600); }); socket.on('send redirect', function (msg) { setTimeout(function () { window.location = msg.payload }, 1500); }); function sendMessage(value, delayTime) { let msgWait = delayTime; var random = Math.floor(Math.random() * (10000000 - 1)) + 1; var message = ` `; $('.chat-log').append(message); scrollChatBottom("fast"); $("#" + random).velocity( { opacity: 1 }, { duration: msgWait / 2, complete: function (elements) { $(".message-loading").velocity("fadeOut", { duration: (msgWait / 2) - 300, easing: "easeInExpo", complete: function (elements) { scrollChatBottom("fast"); $("#" + random).find('.text').html("" + value + "
"); $("#" + random).find('.text p').velocity({ opacity: 1, display: "inline-block" }, { duration: 800, easing: "easeOutCubic", complete: function (elements) { $("#" + random).find('.text p').velocity({ opacity: 1 }, { duration: 500, easing: "easeOutCubic", }); scrollChatBottom("fast"); } }) } }); } }); scrollChatBottom("fast"); } function showTextInput() { $(".footer-ruf").velocity({ opacity: 0, }, { duration: 1, display: "flex", complete: function (elements) { scrollChatBottom("fast"); $(".footer-ruf").velocity({ opacity: 1, }, { duration: 500, complete: function (elements) { $(".input-box").focus(); } }); }, }); } function sendTextInput() { var random = Math.floor(Math.random() * (10000000 - 1)) + 1; var message = ` `; $('.chat-log').append(message); scrollChatBottom("fast"); let btnString = ``; btnString += `` $("#" + random).velocity( { opacity: 1 }, { duration: 500, complete: function (elements) { scrollChatBottom("fast"); $("#" + random).find('.text').html("" + btnString + "
"); $("#" + random).find('.text p').velocity({ opacity: 1 }, { duration: 800, easing: "easeOutCubic", complete: function (elements) { scrollChatBottom("fast"); } }) } }); } function sendbutton(buttonJson) { var random = Math.floor(Math.random() * (10000000 - 1)) + 1; var message = ` `; $('.chat-log').append(message); scrollChatBottom("fast"); let btnString = ``; JSON.parse(buttonJson).forEach(function (button) { btnString += ``; }); $("#" + random).velocity( { opacity: 1 }, { duration: 1000, complete: function (elements) { scrollChatBottom("fast"); $("#" + random).find('.text').html("" + btnString + "
"); $("#" + random).find('.text p').velocity({ opacity: 1 }, { duration: 800, easing: "easeOutCubic", complete: function (elements) { scrollChatBottom("fast"); } }) } }); } function sendDropdown(buttonJson) { var random = Math.floor(Math.random() * (10000000 - 1)) + 1; var message = ` `; $('.chat-log').append(message); scrollChatBottom("fast"); let selectString = `" + selectString + "
"); $("#" + random).find('select').formSelect(); $("#" + random).find('.text p').velocity({ opacity: 1 }, { duration: 800, easing: "easeOutCubic", complete: function (elements) { scrollChatBottom("fast"); } }) } }); } function sendCalendar() { var random = Math.floor(Math.random() * (10000000 - 1)) + 1; var message = ` `; $('.chat-log').append(message); scrollChatBottom("fast"); let btnString = ``; btnString += `` $("#" + random).velocity( { opacity: 1 }, { duration: 500, complete: function (elements) { scrollChatBottom("fast"); $("#" + random).find('.text').html("" + btnString + "
"); $("#" + random).find('.text p').velocity({ opacity: 1 }, { duration: 800, easing: "easeOutCubic", complete: function (elements) { scrollChatBottom("fast"); console.log($("#" + random).find('.datepicker')) $("#" + random + " .datepicker").datepicker({ defaultDate: new Date(), minDate: new Date(), }); } }) } }); } function sendTime() { var random = Math.floor(Math.random() * (10000000 - 1)) + 1; var message = ` `; $('.chat-log').append(message); scrollChatBottom("fast"); let btnString = ``; btnString += `` $("#" + random).velocity( { opacity: 1 }, { duration: 500, complete: function (elements) { scrollChatBottom("fast"); $("#" + random).find('.text').html("" + btnString + "
"); $("#" + random).find('.text p').velocity({ opacity: 1 }, { duration: 800, easing: "easeOutCubic", complete: function (elements) { scrollChatBottom("fast"); $("#" + random).find('.timepicker').timepicker({ }); } }) } }); } function sendContactForm() { var random = Math.floor(Math.random() * (10000000 - 1)) + 1; var message = ` `; $('.chat-log').append(message); scrollChatBottom("fast"); let btnString = ``; btnString += `