jQuery(document).ready(function(){
var chatstate = 1 ;
var start = 1;
var icon_option = 'only_icon' ;
jQuery('body').on('click','.chat_close_b',async function(){
if ( chatstate === 1 ) {
if ( icon_option != 'sidebar_icon') {
jQuery('.btntext').hide();
var src = 'https://timedtweeter.com/jams/wp-content/plugins/AppointBee/modules/inc/chatbot/images/cross-button.png';
jQuery(this).find('img').attr('src',src);
}
chatstate = 0;
jQuery('.insideChat').slideDown(500);
await delay(1300).then(function(){
jQuery('.chat_landing1').slideUp(1000);
jQuery('.chat_box').slideDown(1000);
});
}else{
if ( icon_option != 'sidebar_icon') {
var src = 'https://timedtweeter.com/jams/wp-content/plugins/AppointBee/modules/inc/chatbot/images/Appointbee-ChatIcon.png';
jQuery(this).find('img').attr('src',src);
}
chatstate = 1;
jQuery('.insideChat').slideUp();
await delay(300).then(function(){
jQuery('.chat_box').hide();
jQuery('.chat_landing1').show();
});
if ( icon_option != 'sidebar_icon') {
jQuery('.btntext').show();
}
}
if (start == 1) {
start = 0;
await delay(1300).then(async function(){
startBot();
// service_provider = 2;
// await get_month();
});
}
});
jQuery("body").on("click",".bot_close_btn",async function(event){
if ( icon_option != 'sidebar_icon') {
var src = 'https://timedtweeter.com/jams/wp-content/plugins/AppointBee/modules/inc/chatbot/images/Appointbee-ChatIcon.png';
jQuery('.chat_close_b').find('img').attr('src',src);
}
chatstate = 1;
jQuery('.insideChat').slideUp();
await delay(300).then(function(){
jQuery('.chat_box').hide();
jQuery('.chat_landing1').show();
});
if ( icon_option != 'sidebar_icon') {
jQuery('.btntext').show();
}
});
async function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
var current_event = 'select_service';
var name = '';
var contact = '';
var email = '';
var address = '';
var city = '';
var service = '';
var service_provider = '';
var requirements = '';
var notes = '';
var date_time = '';
var timezone = '';
var formattedTime = '';
var details_response = '';
var confirmDiv = '';
var confirmDiv1 = '';
var printElement = '';
myArray = [];
backEvent = [];
var lastbackEvent = '';
var ask_address = '';
var ask_city = '';
var all_services = '';
var services_by_worker_button = '[]';
var service_btn_array = JSON.parse(services_by_worker_button);
var workers_by_service_button = '[]';
var worker_btn_array = JSON.parse(workers_by_service_button);
var back_img = 'https://timedtweeter.com/jams/wp-content/plugins/AppointBee/modules/inc/chatbot/images/undo.png';
var back_btn_text = 'Back';
function startBot(){
printMsg('Hi there! Welcome to our appointment booking service.
What type of service are you interested in scheduling an appointment for?
'+all_services,'bot');
}
jQuery("body").on("click",".send_btn",async function(event){
run_input();
});
jQuery("body").on("keyup","#textbox",async function(event){
if (event.keyCode === 13) {
run_input();
}
});
async function run_input(){
var text = jQuery('#textbox').val();
if( current_event == 'name'){
name = text ;
await printMsg( text,'user');
if(!validation(text)){
await printMsg('Invalid Input: Please Enter a valid Name with a minimum of 4 characters and Special characters are not allowed."','bot');
return false;
}else{
current_event = 'contact';
await printMsg('What is your Contact Number ? We will need it to confirm your appointment','bot');
}
}else if( current_event == 'contact'){
contact = text ;
await printMsg( text,'user');
if(!validation(text)){
await printMsg('Invalid Input. Please Enter a valid Contact Number that contains only digits, has a minimum of 8 digits, and a maximum of 15 digits.','bot');
return false;
}else{
current_event = 'email';
await printMsg('What is your email address? ','bot');
}
}else if( current_event == 'email'){
email = text ;
await printMsg( text,'user');
if(!validation(text)){
await printMsg('Invalid Input. Please Enter a valid Email address','bot')
return false;
}
await printMsg('Thanks for sharing your contact information with us. We promise to keep it safe and secure.','bot');
if (ask_address == 1 ) {
current_event = 'ask_address';
await printMsg('Please Enter your Address :','bot');
}else if(ask_city == 1){
current_event = 'ask_city';
await printMsg('Please Enter your City Name :','bot');
}else{
current_event = 'req_qs';
await printMsg('Do you have any specific preferences or requirements for this appointment?
','bot');
}
}else if( current_event == 'ask_address'){
address = text ;
await printMsg( text,'user');
if ( ask_city == 1 ) {
current_event = 'ask_city';
await printMsg('Please Enter your City Name :','bot');
}else{
current_event = 'req_qs';
await printMsg('Do you have any specific preferences or requirements for this appointment?
','bot');
}
}else if( current_event == 'ask_city'){
city = text ;
await printMsg( text,'user');
current_event = 'req_qs';
await printMsg('Do you have any specific preferences or requirements for this appointment?
','bot');
}else if( current_event == 'requirements'){
requirements = text ;
await printMsg( text,'user');
if(!validation(text)){
await printMsg('Input exceeds the maximum limit of 250 characters. Please Enter Again :','bot');
return false;
}else{
current_event = 'confirm';
cfm_div();
}
}
//console.log(current_event +' | '+text);
}
function validation(text){
if( current_event == 'name'){
if (text.length >= 4 && text.length <= 50 && /^[a-zA-Z\s]+$/.test(text) ) {
return true;
}
}else if( current_event == 'contact'){
if (/^\+?\d{8,15}$/.test(text)) {
return true;
}
}else if( current_event == 'email'){
var emailRegex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
if (emailRegex.test(text)) {
return true;
}
}else if( current_event == 'requirements'){
if (text.length <= 250 ) {
return true;
}
}
return false;
}
async function cfm_div(){
confirmDiv = confirmDiv1;
confirmDiv += '
Name : '+name+'
'; confirmDiv += 'Contact : '+contact+'
'; confirmDiv += 'Email : '+email+'
'; if (ask_city == 1 ) { confirmDiv += 'City : '+city+'
'; } if (ask_address == 1 ) { confirmDiv += 'Address : '+address+'
'; } if( requirements != '' ){ confirmDiv += 'Notes : '+requirements+'
'; } confirmDiv += ''+response.service+'
'; confirmDiv1 += ''+response.worker+'
'; confirmDiv1 += ''+response.start+'
'; confirmDiv1 += ''+response.end+'
'; if (response.price != "0") { confirmDiv1 += ''+response.price+'
'; } }, "json"); } function addTo_stepBack(){ if (backEvent.length > 1) { //var lastbackEvent = backEvent[backEvent.length - 1]; }else{ //var lastbackEvent = backEvent[0]; } var draftHtml = jQuery('#msBox').html(); var state = { current_event, name, contact, email, address, city, service, service_provider, requirements, notes, date_time, timezone, formattedTime, details_response, confirmDiv, confirmDiv1, draftHtml }; myArray.push(state); console.log(backEvent); console.log(myArray); } jQuery('body').delegate('.backbtn','click',async function(){ if (myArray.length == 0 ) { return; } var lastState = myArray.pop(); var last_back_Event = backEvent.pop(); if (myArray.length == 0 ) { myArray.push(lastState); backEvent.push(last_back_Event); } jQuery('#msBox').html(lastState.draftHtml); current_event = lastState.current_event ; draftHtml = lastState.draftHtml; current_event = last_back_Event; lastbackEvent = ''; name = lastState.name; contact = lastState.contact; email = lastState.email; address = lastState.address; city = lastState.city; service = lastState.service; service_provider = lastState.service_provider; requirements = lastState.requirements; notes = lastState.notes; date_time = lastState.date_time; timezone = lastState.timezone; formattedTime = lastState.formattedTime; details_response = lastState.details_response; confirmDiv = lastState.confirmDiv; //confirmDiv1 = lastState.confirmDiv1; if(jQuery('.backbtn').length > 1 ){ jQuery('.backbtn').last().show(); } jQuery('#textbox').prop('disabled', false); console.log(backEvent); console.log(myArray); }); }); jQuery(document).ready(function () { var words = ['Book an Appointment'], part, i = 0, offset = 0, len = words.length, forwards = true, skip_count = 0, skip_delay = 15, speed = 100; var wordflick = function () { setInterval(function () { if (forwards) { if (offset >= words[i].length) { ++skip_count; if (skip_count == skip_delay) { forwards = false; skip_count = 0; } } } else { if (offset == 0) { forwards = true; i++; offset = 0; if (i >= len) { i = 0; } } } part = words[i].substr(0, offset); if (skip_count == 0) { if (forwards) { offset++; } else { offset--; } } jQuery('.btntext').text(part); },speed); }; wordflick(); }); function printDiv(divId,title) { let mywindow = window.open('', 'PRINT', 'height=650,width=900,top=100,left=150'); mywindow.document.write(`