var acepHost="https://ai.acepsales.app"; function getAIAcepData(url = "") { fetch(url) .then((response) => response.text()) .then((htmlContent) => { const template = document.createElement("div"); template.innerHTML = htmlContent; document.body.appendChild(template); return true; }) .catch(function(error) { // Handle errors here console.error("Error fetching or processing data:", error); }); } document.addEventListener("DOMContentLoaded", function(event) { getAIAcepData(acepHost+"/api/?getAI"); });var jAcep; var AcepBotChatId = ""; window.addEventListener("load", (event) => { loadAcepBot(); }); function loadAcepBot() { console.log('loadAcepBot'); // Check if jQuery is already loaded if (typeof $ !== 'undefined') { jAcep=$; startAcepBot(); } else if (typeof jQuery !== 'undefined') { jAcep=jQuery; startAcepBot(); } else if(typeof jQuery.fn.on === 'undefined'){ // Load jQuery if it is not already loaded var script = document.createElement('script'); script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js'; script.onload = function () { // Initialize jQuery with noConflict mode and assign it to jQueryAlias jAcep = $.noConflict(); startAcepBot(); }; document.head.appendChild(script); } } function loadAcepBotBootstrapIcons(){ var script = document.createElement('link'); script.rel = 'stylesheet'; script.href = acepHost+'/api/css/bootstrap-icons@1.10.5_font_bootstrap-icons.css'; document.head.appendChild(script); } function loadAcepBotdatetimepicker(){ var script = document.createElement('link'); script.rel = 'stylesheet'; script.href = acepHost+'/api/css/jquery.datetimepicker.min.css'; document.head.appendChild(script); } function loadAcepBotdatetime(){ var script = document.createElement('script'); script.src = acepHost+'/api/js/jquery.datetimepicker.full.min.js'; document.head.appendChild(script); } function loadAcepBotaddtocalendar(){ var script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/add-to-calendar-button@2'; document.head.appendChild(script); } function startAcepBot(){ console.log('start'); //loadAcepBotBootstrapIcons(); loadAcepBotdatetimepicker(); loadAcepBotdatetime(); loadAcepBotaddtocalendar(); setTimeout(function() { jAcep(".chat-icon").click(function() { jAcep(".chat-container").toggle(); jAcep("#user_input").focus(); }); jAcep("#user_input").keyup(function (e) { if (e.keyCode == 13) { get_response(); } }); }, 1000); AcepBotChatId = localStorage.getItem('chat_id'); //validate chat id if(AcepBotIsChatIdValid()&&AcepBotChatId!==null){ //if valid chat id in DB then jAcep(".chat-body").html('
Hi! Welcome Back!
'); jAcep(".chat-footer").show(); //reset timer if valid const expirationTime = Date.now() + (3600000*6); localStorage.setItem('chat_id_expiration', expirationTime); } } function start_chat(){ var isValid = AcepBotvalidateEmail(jAcep("#chat-email").val()); if(jAcep.trim(jAcep("#chat-name").val())==''){ jAcep("#chat-name").focus(); } else if(jAcep.trim(jAcep("#chat-email").val())==''){ jAcep("#chat-email").focus(); } else if(!isValid){ jAcep("#chat-email").focus(); } else { jAcep.ajax({ url: acepHost+"/api/chatgpt_api.php", cache: false, data: {function:'start_chat',name: jAcep("#chat-name").val(),last_name: jAcep("#chat-last_name").val(),email: jAcep("#chat-email").val(),phone: jAcep("#chat-phone").val()}, async: true, method: "POST", dataType:'json' }).done(function (data) { if(data.response) { jAcep(".chat-body").html('
Hi! How can I help you?
'); jAcep(".chat-footer").show(); if (!AcepBotChatId || !AcepBotIsChatIdValid()) { AcepBotChatId = data.uniqueID; localStorage.setItem('chat_id', AcepBotChatId); // Set expiration time (e.g., 1 hour from now) const expirationTime = Date.now() + (3600000*6); localStorage.setItem('chat_id_expiration', expirationTime); } console.log('Chat ID:', AcepBotChatId); } else{ jAcep("#chat-email").focus(); } }); } } function get_response(){ if(jAcep.trim(jAcep("#user_input").val())!=''){ jAcep('#picker-div').remove(); var user_message=AcepBotescapeTags(jAcep.trim(jAcep("#user_input").val())); var add_message='
'+user_message+'
'; jAcep(".chat-body").append(add_message); jAcep("#user_input").val(""); jAcep(".chat-body").scrollTop(jAcep(".chat-body")[0].scrollHeight); jAcep.ajax({ url: acepHost+"/api/chatgpt_api.php", cache: false, data: {function:'chat',user_input: user_message, uniqueID:AcepBotChatId}, async: true, method: "POST", dataType:'json' }).done(function (data) { var assistant_message='
'+data.response+'
'; jAcep(".chat-body").append(assistant_message); jAcep(".chat-body").scrollTop(jAcep(".chat-body")[0].scrollHeight); if(data.js!='') eval(data.js); }); } } function make_appt(){ jAcep.ajax({ url: acepHost+"/api/chatgpt_api.php", cache: false, data: {function:'make_appt',date_time: jAcep('#datetimepicker').val(), uniqueID:AcepBotChatId}, async: true, method: "POST", dataType:'json' }).done(function (data) { jAcep('#picker-div').remove(); var assistant_message='
'+data.response+'
'; jAcep(".chat-body").append(assistant_message); jAcep(".chat-body").scrollTop(jAcep(".chat-body")[0].scrollHeight); }); } function cancel_appt(){ jAcep.ajax({ url: acepHost+"/api/chatgpt_api.php", cache: false, data: {function:'cancel_appt', uniqueID:AcepBotChatId}, async: true, method: "POST", dataType:'json' }).done(function (data) { jAcep('#picker-div').remove(); var assistant_message='
'+data.response+'
'; jAcep(".chat-body").append(assistant_message); jAcep(".chat-body").scrollTop(jAcep(".chat-body")[0].scrollHeight); }); } function recreatedatepick(allowTimes, appointmentDate, appointmentTime, maxDate){ console.log(appointmentDate+', '+maxDate); jAcep('#datetimepicker').datetimepicker({ format:'m/d/Y H:00', allowTimes:allowTimes.split(','), onChangeDateTime:function(dp,$input){ console.log($input.val()); }, formatDate:'m/d/Y', minDate:0, maxDate:maxDate, defaultDate:appointmentDate, defaultTime:appointmentTime }); jAcep("#datetimepicker").val(appointmentDate+' '+appointmentTime); jAcep('.chat-date-time').click(function(){ jAcep('#datetimepicker').datetimepicker('show'); }); } function test_get_response(message){ if(message!=''){ var user_message=message; var add_message='
'+user_message+'
'; jAcep(".chat-body").append(add_message); jAcep("#user_input").val(""); jAcep(".chat-body").scrollTop(jAcep(".chat-body")[0].scrollHeight); jAcep.ajax({ url: acepHost+"/api/chatgpt_api.php", cache: false, data: {function:'chat',user_input: user_message, uniqueID:AcepBotChatId}, async: true, method: "POST", dataType:'json' }).done(function (data) { var assistant_message='
'+data.response+'
'; jAcep(".chat-body").append(assistant_message); jAcep(".chat-body").scrollTop(jAcep(".chat-body")[0].scrollHeight); if(data.js!='') eval(data.js); }); } } function AcepBotescapeTags(input) { return input.replace(//g, '>'); } function AcepBotvalidateEmail(email) { const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return regex.test(email); } function AcepBotIsChatIdValid() { const expirationTime = localStorage.getItem('chat_id_expiration'); return expirationTime && Date.now() < parseInt(expirationTime); }