{"version":3,"file":"advisorystudio-webchat.min.js","mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,KAAK;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,SAAS;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gDAAgD,6BAA6B;AAC7E;AACA;AACA,YAAY,iBAAiB,wBAAwB,WAAW;AAChE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gCAAgC,iBAAiB,kCAAkC;AACnF;AACA,QAAQ,OAAO,WAAW;AAC1B,MAAM;AACN;AACA;AACA,2CAA2C,+BAA+B;AAC1E;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA,UAAU,QAAQ;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wHAAwH,qBAAqB,aAAa,iBAAiB,YAAY,aAAa;AACpM;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,iBAAiB;AACjC;AACA;AACA;AACA,kBAAkB,8BAA8B;AAChD;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,iBAAiB,2CAA2C,WAAW;AACvF;AACA;AACA;AACA,mBAAmB,iBAAiB,2CAA2C,WAAW;AAC1F,mCAAmC,eAAe;AAClD,YAAY,aAAa;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kFAAkF,WAAW;AAC7F;AACA;AACA;AACA;AACA;AACA;AACA,sFAAsF,WAAW;AACjG;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR,SAAS,UAAU;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB;AACnB,iBAAiB;AACjB,eAAe;AACf,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sDAAsD,OAAO;AAC7D;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA,oKAAoK,WAAW;AAC/K;AACA;AACA,2KAA2K,WAAW;AACtL;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA,qDAAqD,KAAK,UAAU;AACpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+BAA+B;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB;AACnB;AACA;AACA,WAAW;AACX;AACA;AACA;AACA;AACA;AACA,mBAAmB;AACnB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA,oBAAoB,iBAAiB;AACrC;AACA;AACA;AACA;AACA;AACA;AACA,mDAAmD,6BAA6B;AAChF;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA,WAAW,iBAAiB,kCAAkC;AAC9D;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAiD,IAAI;AACrD;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB,EAAE,kBAAkB,EAAE,cAAc,IAAI;AAC7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0DAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,EAAC;;;ACnkB4C;AAC9C;AACA;AACA;AACA;AACA;AACA,EAAE,iCAAgB;AAClB,EAAE,iCAAgB;AAClB;AACA,EAAE,kCAAiB;AACnB;AACA;AACA,iCAAiC,YAAY;AAC7C;AACA;AACA;AACA,gBAAgB,aAAa;AAC7B;AACA;AACA;AACA;AACA,QAAQ,yCAAwB;AAChC,QAAQ,yCAAwB;AAChC;AACA;AACA;AACA,QAAQ,6BAAY;AACpB,QAAQ,oCAAmB;AAC3B,QAAQ,mCAAkB;AAC1B,OAAO;AACP;AACA;AACA,QAAQ,mCAAkB;AAC1B,OAAO;AACP;AACA;AACA,QAAQ,mCAAkB;AAC1B,OAAO;AACP,MAAM;AACN,4FAA4F;AAC5F;AACA,GAAG;AACH,CAAC","sources":["webpack://advisory-stydio-chatbot-external/./shared/webchat-interaction.js","webpack://advisory-stydio-chatbot-external/./webchat-external.js"],"sourcesContent":["/* Private members */\r\nconst webChatScriptElement = document.getElementById('advbotscript');\r\nconst normalMode = webChatScriptElement.getAttribute('data-normal-mode')\r\n ? webChatScriptElement.getAttribute('data-normal-mode') === 'true'\r\n : false;\r\nconst customerId = webChatScriptElement.getAttribute('data-customer-id') ?? '';\r\n\r\nlet userIdleTime = 0;\r\nlet userIdleTimeIntervalId = null;\r\nlet advbotGuestEmail = null;\r\nlet advStuApiBaseUrl = null;\r\nlet advStuWebBaseUrl = null;\r\nlet encryptedDomainKey = null;\r\nlet isDomainRegistered = false;\r\n\r\n/* Setters */\r\n\r\n/**\r\n *\r\n * @param {string} baseUrl Base URL for the Advisory Studio API\r\n */\r\nfunction setApiBaseUrl(baseUrl) {\r\n advStuApiBaseUrl = baseUrl;\r\n}\r\n\r\n/**\r\n *\r\n * @param {string} baseUrl Base URL for the Advisory Studio Web UI\r\n */\r\nfunction setWebBaseUrl(baseUrl) {\r\n advStuWebBaseUrl = baseUrl;\r\n}\r\n\r\n/**\r\n *\r\n * @param {int} time User idle time\r\n */\r\nfunction setUserIdleTime(time) {\r\n userIdleTime = time;\r\n}\r\n\r\n/**\r\n *\r\n * @param {string} encryptedKey Encrypted value of the domain where chatbot is initiated from.\r\n */\r\nfunction setEncryptedDomainKey(encryptedKey) {\r\n encryptedDomainKey = encryptedKey;\r\n}\r\n\r\n/**\r\n *\r\n * @param {boolean} isRegistered Set the registration state of the client domain\r\n */\r\nfunction setIsDomainRegistered(isRegistered) {\r\n isDomainRegistered = isRegistered;\r\n}\r\n\r\nfunction isDesignerMode(callback) {\r\n const hostUrl = new URL(window.location.href);\r\n const designModeQueryValue = hostUrl.searchParams.get('designMode');\r\n const isDesignModeEnabledOnWebsite = designModeQueryValue === 'true';\r\n\r\n console.info(`isDesignModeEnabledOnWebsite: ${isDesignModeEnabledOnWebsite}`);\r\n\r\n const request = {\r\n url: `${advStuApiBaseUrl}/api/webchat/designer/${customerId}`,\r\n method: 'GET',\r\n };\r\n\r\n $.ajax(request).done((response) => {\r\n console.info(`response: `, response);\r\n\r\n const isFirstUse = response.IsFirstUse === 'true';\r\n if (isFirstUse) {\r\n setEncryptedDomainKey(response.Key);\r\n window.location.href = `${advStuWebBaseUrl}/WebSiteChat/NewRegistration?id=${encodeURIComponent(\r\n encryptedDomainKey\r\n )}&cid=${customerId}`;\r\n } else {\r\n const isDesignerModeEnabledOnBackend = response.IsDesignerMode === 'true';\r\n console.info(\r\n `isDesignerModeEnabledOnBackend: ${isDesignerModeEnabledOnBackend}`\r\n );\r\n\r\n isDesignModeEnabledOnWebsite === isDesignerModeEnabledOnBackend\r\n ? callback(true)\r\n : callback(false);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * @type {Object} Object containing the Chat UI Elements\r\n */\r\nconst ChatElements = {\r\n advbotChatGoesHere: null,\r\n advbotLeadForm: null,\r\n advbotLeadDetails: null,\r\n advbotChatOptionsModal: null,\r\n advbotLeadTitle: null,\r\n advbotChatMenuBtn: null,\r\n advbotMicrophoneBtn: null,\r\n};\r\n\r\n// Show the Advisory Studio chat UI\r\nfunction showChat() {\r\n ChatElements.advbotChatGoesHere.style.display = 'block';\r\n ChatElements.advbotLeadForm.style.display = 'none';\r\n ChatElements.advbotLeadDetails.style.height = '600px';\r\n ChatElements.advbotLeadDetails.style.display = 'block';\r\n ChatElements.advbotChatOptionsModal.style.display = 'none';\r\n ChatElements.advbotChatMenuBtn.style.display = 'block';\r\n ChatElements.advbotMicrophoneBtn.style.display = 'block';\r\n}\r\n\r\n// Show the Advisory Studio leads UI\r\nfunction showLead() {\r\n ChatElements.advbotLeadTitle.innerHTML =\r\n ChatElements.advbotLeadTitle.innerHTML || 'Sales Chat';\r\n ChatElements.advbotChatGoesHere.style.display = 'none';\r\n ChatElements.advbotLeadForm.style.display = 'block';\r\n ChatElements.advbotLeadDetails.style.height = '510px';\r\n ChatElements.advbotLeadDetails.style.display = 'block';\r\n ChatElements.advbotChatOptionsModal.style.display = 'none';\r\n}\r\n\r\n/**\r\n * Binds the theme color defined in the WebChat script element\r\n */\r\nfunction bindTheme() {\r\n let themeColor = null;\r\n\r\n if (webChatScriptElement) {\r\n themeColor = webChatScriptElement.getAttribute('data-theme-color');\r\n }\r\n\r\n if (!themeColor) {\r\n return;\r\n }\r\n\r\n const cssClass = ``;\r\n $('body').append(cssClass);\r\n}\r\n\r\n// Helper method to get the field within the form\r\nfunction getField(fieldName) {\r\n return ChatElements.advbotLeadForm.elements.namedItem(fieldName);\r\n}\r\n\r\n// Helper method to read the UI field value\r\nfunction getFieldValue(fieldName) {\r\n return getField(fieldName).value;\r\n}\r\n\r\n// Increments the user Idle time and executes an idle timeout if the user is away for too long\r\n//function timerIncrement() {\r\n// userIdleTime += 1;\r\n\r\n// if (userIdleTime > 3 * 60) {\r\n// // 5 secs\r\n// clearInterval(userIdleTimeIntervalId);\r\n\r\n// const settings = {\r\n// url: `${advStuApiBaseUrl}/api/bot/manager/idletimeout`,\r\n// method: 'POST',\r\n// 'Content-Type': 'application/json',\r\n// dataType: 'json',\r\n// data: { advbotGuestEmail, customerId },\r\n// };\r\n\r\n// $.ajax(settings).done(() => {});\r\n// }\r\n//}\r\n\r\n// Helper method to sanitize user attributes\r\n//function filterUserAttributes(str) {\r\n// if (!str) {\r\n// return '';\r\n// }\r\n\r\n// return str.replace(/|/gi, '');\r\n//}\r\n\r\n// Initializes the chat bot.\r\nfunction initiateChatBot(email, name, company, phone, callback) {\r\n //const settings = {\r\n // url: `${advStuApiBaseUrl}/api/bot/manager/GenerateDirectLineToken/${customerId}`,\r\n //method: 'GET',\r\n //};\r\n (async function () {\r\n const url = `${advStuApiBaseUrl}/api/bot/manager/GenerateDirectLineToken/${customerId}`;\r\n const res = await fetch(url, { method: 'GET' });\r\n const { token, key } = await res.json();\r\n console.log(token);\r\n console.log(key);\r\n const isGuest = email != null;\r\n\r\n const avatarOptions = {\r\n botAvatarImage: document\r\n .getElementById('advbotBtn')\r\n .getAttribute('data-is-icon')\r\n ? `https://ascoredevscusstorage.blob.core.windows.net/public/images/bot-${customerId}.png`\r\n : 'https://ascoredevscusstorage.blob.core.windows.net/public/images/bot-icon.png',\r\n botAvatarInitials: 'Bt',\r\n userAvatarInitials: 'US',\r\n userAvatarImage: document\r\n .getElementById('advbotBtn')\r\n .getAttribute('data-is-icon')\r\n ? `https://ascoredevscusstorage.blob.core.windows.net/public/images/botuser-${customerId}.png`\r\n : 'https://ascoredevscusstorage.blob.core.windows.net/public/images/bot-icon.png',\r\n };\r\n const selectedProject = callback ? callback() : null;\r\n console.log('Selected Project: ', selectedProject);\r\n\r\n const store = window.WebChat.createStore(\r\n {},\r\n ({ dispatch }) =>\r\n (next) =>\r\n (action) => {\r\n if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {\r\n console.log('Inside DIRECT_LINE/CONNECT_FULFILLED');\r\n dispatch({\r\n type: 'WEB_CHAT/SEND_EVENT',\r\n payload: {\r\n name: 'webchat/join',\r\n value: {\r\n guestData: {\r\n isGuest,\r\n email,\r\n name,\r\n company,\r\n phone,\r\n key: key,\r\n customerId: customerId,\r\n },\r\n projectData: {\r\n projectName: selectedProject\r\n ? selectedProject.selectedProject\r\n : null,\r\n projectGUID: selectedProject\r\n ? selectedProject.selectedTemplateGUID\r\n : null,\r\n isWebchat: selectedProject ? selectedProject.webChat : true,\r\n authToken: localStorage.getItem('ls.authorizationData')\r\n ? localStorage\r\n .getItem('ls.authorizationData')\r\n .replace(/^\"(.*)\"$/, '$1')\r\n : '',\r\n },\r\n },\r\n },\r\n });\r\n }\r\n return next(action);\r\n }\r\n );\r\n\r\n window.WebChat.renderWebChat(\r\n {\r\n directLine: window.WebChat.createDirectLine({ token }),\r\n store: store,\r\n userID: 'User',\r\n host: window.location.hostname,\r\n isGuest: email != null,\r\n locale: 'en-US',\r\n styleOptions: avatarOptions,\r\n },\r\n ChatElements.advbotChatGoesHere\r\n );\r\n showChat();\r\n $('.webchat__send-box-text-box__input')[0].placeholder =\r\n \"Type message or type 'help' to list commands\";\r\n if (isGuest || !normalMode) {\r\n //userIdleTimeIntervalId = setInterval(timerIncrement, 1 * 1000);\r\n advbotGuestEmail = email;\r\n }\r\n })();\r\n // $.ajax(settings).done((response) => {\r\n // // Create the styling options for the webchat.\r\n // const avatarOptions = {\r\n // botAvatarImage: document.getElementById('advbotBtn').getAttribute(\"data-is-icon\")?`https://ascoredevscusstorage.blob.core.windows.net/public/images/bot-${customerId}.png`:'https://ascoredevscusstorage.blob.core.windows.net/public/images/bot-icon.png',\r\n // botAvatarInitials: 'Bt',\r\n // userAvatarInitials: 'US',\r\n // userAvatarImage: document.getElementById('advbotBtn').getAttribute(\"data-is-icon\") ? `https://ascoredevscusstorage.blob.core.windows.net/public/images/botuser-${customerId}.png` : 'https://ascoredevscusstorage.blob.core.windows.net/public/images/bot-icon.png',\r\n // };\r\n\r\n // // Enable DirectLine Speech by creating the adaptors.\r\n // //const directline = window.WebChat.createDirectLine({\r\n // // token: response.token\r\n // //});\r\n\r\n // const selectedProject = callback ? callback() : null;\r\n // console.log('Selected Project: ', selectedProject);\r\n // console.log('authToken', \"\");\r\n\r\n // const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {\r\n // if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {\r\n // console.log('Inside DIRECT_LINE/CONNECT_FULFILLED')\r\n // dispatch({\r\n // type: 'WEB_CHAT/SEND_EVENT',\r\n // payload: {\r\n // name: 'webchat/join',\r\n // value: {\r\n // guestData: {\r\n // isGuest,\r\n // email,\r\n // name,\r\n // company,\r\n // phone,\r\n // key: response.key,\r\n // },\r\n // projectData: {\r\n // projectName: selectedProject ? selectedProject.selectedProject : null,\r\n // projectGUID: selectedProject ? selectedProject.selectedTemplateGUID : null,\r\n // isWebchat: selectedProject ? selectedProject.webChat : true,\r\n // authToken: localStorage.getItem('ls.authorizationData') ? localStorage.getItem('ls.authorizationData').replace(/^\"(.*)\"$/, '$1') : '',\r\n // }\r\n // }\r\n // }\r\n // });\r\n // }\r\n // return next(action);\r\n // });\r\n // // Render webchat with DirectLine speech adaptors\r\n // window.WebChat.renderWebChat(\r\n // {\r\n // directline: window.WebChat.createDirectLine({\r\n // token: response.token\r\n // }),\r\n // store: store,\r\n // userID: \"dl_\"+name,\r\n // host: window.location.hostname,\r\n // isGuest: email != null,\r\n // locale: 'en-US',\r\n // styleOptions: avatarOptions,\r\n // },\r\n // ChatElements.advbotChatGoesHere\r\n // );\r\n\r\n // showChat();\r\n // $('.webchat__send-box-text-box__input')[0].placeholder = 'Type message or type \\'help\\' to list commands';\r\n // //setupTokenRefresh(sourceDirectLine);\r\n\r\n // //if (userIdleTimeIntervalId) {\r\n // // clearInterval(userIdleTimeIntervalId);\r\n // //}\r\n\r\n // if (isGuest || !normalMode) {\r\n // //userIdleTimeIntervalId = setInterval(timerIncrement, 1 * 1000);\r\n // advbotGuestEmail = email;\r\n // }\r\n // });\r\n //}\r\n\r\n //function setupTokenRefresh(directLine) {\r\n // const settings = {\r\n // url: `${advStuApiBaseUrl}/api/bot/manager/GetDirectLineSpeechRefreshToken`,\r\n // method: 'GET',\r\n // };\r\n\r\n // setTimeout(() => {\r\n // $.ajax(settings).done(response => {\r\n // if (response) {\r\n // directLine.updateCredentials({ token: response.speechToken });\r\n // setupTokenRefresh();\r\n // }\r\n // });\r\n // }, 5 * 60 * 1000);\r\n //}\r\n}\r\n// Binds the lead generation form validation\r\nfunction bindLeadFormValidation() {\r\n const forms = document.getElementsByClassName('advbot-needs-validation');\r\n\r\n Array.prototype.filter.call(forms, (form) => {\r\n form.addEventListener(\r\n 'submit',\r\n (event) => {\r\n if (form.checkValidity() === false) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n } else {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n\r\n const email = getFieldValue('email');\r\n const name = getFieldValue('name');\r\n const company = getFieldValue('company');\r\n const phone = getFieldValue('phone');\r\n initiateChatBot(email, name, company, phone);\r\n }\r\n form.classList.add('was-validated');\r\n },\r\n false\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Binds the interaction logic for the web chat\r\n */\r\nfunction bindInteractions(callback) {\r\n ChatElements.advbotChatGoesHere =\r\n document.getElementById('advbotChatGoesHere');\r\n ChatElements.advbotLeadForm = document.getElementById('advbotLeadForm');\r\n ChatElements.advbotLeadDetails = document.getElementById('advbotLeadDetails');\r\n ChatElements.advbotChatOptionsModal = document.getElementById(\r\n 'advbotChatOptionsModal'\r\n );\r\n ChatElements.advbotLeadTitle = document.getElementById('advbotLeadTitle');\r\n //Button for mic\r\n ChatElements.advbotChatMenuBtn = document.getElementById('btnChatMenu');\r\n ChatElements.advbotMicrophoneBtn = document.getElementById('btnMicrophone');\r\n\r\n // Get the button that opens the modal\r\n // const btnSalesChat = advbotBtnSalesChat;\r\n // const btnSupportChat = advbotBtnSupportChat;\r\n const btnSalesChat = document.getElementById('advbotBtnSalesChat');\r\n const btnSupportChat = document.getElementById('advbotBtnSupportChat');\r\n\r\n // Get the element that closes the modal\r\n const spanClose = document.getElementsByClassName('advbot-close-form')[0];\r\n\r\n // Get the modal\r\n // const modal = advbotChatOptionsModal;\r\n\r\n // Get the button that opens the modal\r\n const btn = document.getElementById('advbotBtn');\r\n\r\n // Want to show popup\r\n const isOpenPopup = btn.getAttribute('data-opening-popup');\r\n\r\n // Bot avatar image\r\n //const isBotImage = btn.getAttribute(\"data-is-icon\");\r\n\r\n // Get the element that closes the modal\r\n const span = document.getElementsByClassName('advbot-close')[0];\r\n\r\n btn.onclick = () => {\r\n if (normalMode) {\r\n ChatElements.advbotLeadTitle.innerHTML = 'Advisory Studio';\r\n initiateChatBot('', '', '', '', callback);\r\n } else if (isDomainRegistered) {\r\n if (isOpenPopup == 'true')\r\n ChatElements.advbotChatOptionsModal.style.display = 'block';\r\n else {\r\n showLead();\r\n }\r\n bindLeadFormValidation();\r\n } else {\r\n const win = window.open(\r\n `${advStuWebBaseUrl}/WebSiteChat/NewRegistration?id=${encodeURIComponent(\r\n encryptedDomainKey\r\n )}`,\r\n '_blank'\r\n );\r\n win.focus();\r\n }\r\n };\r\n\r\n // When the user clicks on (x), close the modal\r\n span.onclick = () => {\r\n ChatElements.advbotChatOptionsModal.style.display = 'none';\r\n };\r\n\r\n // When the user clicks anywhere outside of the modal, close it\r\n window.onclick = (event) => {\r\n if (event.target === ChatElements.advbotChatOptionsModal) {\r\n ChatElements.advbotChatOptionsModal.style.display = 'none';\r\n }\r\n };\r\n\r\n // When the user clicks the button, open the modal\r\n btnSalesChat.onclick = showLead;\r\n btnSupportChat.onclick = () => {\r\n ChatElements.advbotLeadTitle.innerHTML = 'Support Chat';\r\n initiateChatBot();\r\n };\r\n\r\n spanClose.onclick = () => {\r\n ChatElements.advbotLeadDetails.style.display = 'none';\r\n };\r\n}\r\n\r\nfunction isValidEmail(email) {\r\n // eslint-disable-next-line no-useless-escape\r\n const emailRegex = /^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$/;\r\n return emailRegex.test(email);\r\n}\r\n\r\nfunction isValidPhoneNumber(phoneNumber) {\r\n // eslint-disable-next-line no-useless-escape\r\n const phoneRegex =\r\n /^[\\+]?[(]?[0-9]{3}[)]?[-\\s\\.]?[0-9]{3}[-\\s\\.]?[0-9]{4,6}$/im;\r\n return phoneRegex.test(phoneNumber);\r\n}\r\n\r\nfunction showErrorMessage(elementId) {\r\n document.getElementById(elementId).style.display = 'block';\r\n}\r\n\r\nfunction hideErrorMessage(elementId) {\r\n document.getElementById(elementId).style.display = 'none';\r\n}\r\n\r\nfunction showErrorHighlight(element) {\r\n element.classList.add('form-invalid');\r\n}\r\n\r\nfunction hideErrorHighlight(element) {\r\n element.classList.remove('form-invalid');\r\n}\r\n\r\nfunction enableSubmit() {\r\n document.getElementById('submit').disabled = false;\r\n}\r\n\r\nfunction disableSubmit() {\r\n document.getElementById('submit').disabled = true;\r\n}\r\n\r\nfunction validateEmail() {\r\n const emailField = getField('email');\r\n\r\n if (isValidEmail(emailField.value)) {\r\n hideErrorHighlight(emailField);\r\n hideErrorMessage('emailValidationMessage');\r\n enableSubmit();\r\n } else {\r\n showErrorHighlight(emailField);\r\n showErrorMessage('emailValidationMessage');\r\n disableSubmit();\r\n }\r\n}\r\n\r\nfunction validatePhoneNumber() {\r\n const phoneField = getField('phone');\r\n\r\n if (isValidPhoneNumber(phoneField.value)) {\r\n hideErrorHighlight(phoneField);\r\n hideErrorMessage('phoneValidationMessage');\r\n enableSubmit();\r\n } else {\r\n showErrorHighlight(phoneField);\r\n showErrorMessage('phoneValidationMessage');\r\n disableSubmit();\r\n }\r\n}\r\nfunction validateName() {\r\n const nameField = getField('name');\r\n\r\n if (nameField.value == '' || nameField.value == undefined) {\r\n showErrorHighlight(nameField);\r\n showErrorMessage('nameValidationMessage');\r\n disableSubmit();\r\n } else {\r\n hideErrorHighlight(nameField);\r\n hideErrorMessage('nameValidationMessage');\r\n enableSubmit();\r\n }\r\n}\r\n\r\nfunction bindValidations() {\r\n getField('email').addEventListener('blur', validateEmail);\r\n getField('phone').addEventListener('blur', validatePhoneNumber);\r\n getField('name').addEventListener('blur', validateName);\r\n}\r\n\r\nexport default {\r\n ChatElements,\r\n setApiBaseUrl,\r\n setWebBaseUrl,\r\n setUserIdleTime,\r\n setEncryptedDomainKey,\r\n setIsDomainRegistered,\r\n bindTheme,\r\n bindInteractions,\r\n bindValidations,\r\n isDesignerMode,\r\n};\r\n","import UI from './shared/webchat-interaction';\r\n\r\n$(document).ready(() => {\r\n const advStuApiUrl = 'https://apidev.advisorystudio.io';\r\n const advStuWebUrl = 'https://webdev.advisorystudio.io';\r\n\r\n UI.setApiBaseUrl(advStuApiUrl);\r\n UI.setWebBaseUrl(advStuWebUrl);\r\n\r\n UI.isDesignerMode((showWebchat) => {\r\n // Only render the webchat if showWebchat is true\r\n\r\n console.info(`showWebChat: ${showWebchat}`);\r\n\r\n if (showWebchat) {\r\n const settings = {\r\n url: `${advStuApiUrl}/api/bot/manager/script`,\r\n method: 'GET',\r\n };\r\n\r\n $.ajax(settings).done((response) => {\r\n UI.setIsDomainRegistered(response.isRegistered);\r\n UI.setEncryptedDomainKey(response.url);\r\n\r\n $('body').append(response.content);\r\n\r\n UI.bindTheme();\r\n UI.bindInteractions();\r\n UI.bindValidations();\r\n });\r\n\r\n $(document).mousemove(() => {\r\n UI.setUserIdleTime(0);\r\n });\r\n\r\n $(document).keypress(() => {\r\n UI.setUserIdleTime(0);\r\n });\r\n } else {\r\n console.log('%cAdvisory Studio WebChat is currently disabled.', 'background: #cff4fc; color: #0a58ca');\r\n }\r\n });\r\n});\r\n"],"names":[],"sourceRoot":""}