PageSourceSearch

https://access.com/app/plugins/access-chatbot/resources/js/scripts.js?ver=1790953098

js access.com collected 2026-10-02 16:20:00 UTC 5,110 bytes, 24 lines download raw bytes

1class f{constructor(){this.apiBaseUrl="/wp-json/custom/v1/chatbot",this.isOpen=!1,this.userInteraction=!1,this.initializeElements(),this.bindEvents(),this.startConversation()}initializeElements(){this.chatToggle=document.getElementById("chat-toggle"),this.chatContainer=document.getElementById("chat-container"),this.chatClose=document.getElementById("chat-close"),this.chatMessages=document.getElementById("chat-messages"),this.chatInput=document.getElementById("chat-input"),this.chatSend=document.getElementById("chat-send")}bindEvents(){this.chatToggle.addEventListener("click",()=>this.toggleChat()),this.chatClose.addEventListener("click",()=>this.closeChat()),this.chatSend.addEventListener("click",n=>this.sendMessage(n)),this.chatInput.addEventListener("keypress",n=>{n.altKey||n.ctrlKey||n.shiftKey||n.key==="Enter"&&this.sendMessage(n)})}toggleChat(){this.isOpen?this.closeChat():this.openChat()}openChat(){this.chatContainer.classList.remove("hidden"),this.isOpen=!0,this.chatInput.focus()}closeChat(){this.chatContainer.classList.add("hidden"),this.isOpen=!1}scrollToBottom(){this.chatClose&&!this.chatClose.classList.contains("scroll-initiated")&&(this.chatMessages.scrollTop=this.chatMessages.scrollHeight,this.chatClose.classList.add("scroll-initiated"))}addMessage(n,e=!1){const t=document.createElement("div");t.className=`message ${e?"user":"bot"}`;const s=document.createElement("div");s.className="message-content",s.innerHTML=this.convertJSONToText(n),t.appendChild(s),this.chatMessages.appendChild(t),t.scrollIntoView({behavior:"smooth",block:"start"})}convertJSONToText(n){const e=n.split(`
2`).map(i=>i.trim()).filter(Boolean);let t="",s=0;const r=i=>/^\d+\.\s+/.test(i),c=i=>/^-\s+/.test(i),d=i=>!r(i)&&!c(i),p=i=>/^#{1,6}\s+/.test(i);let a=!1;for(;s<e.length;){const i=e[s],g=/^<[^>]+>.*<\/[^>]+>$/.test(i);if(i==="---")s++;else if(p(i)){a&&(t+=`</ol>
3`,a=!1);const h=i.match(/^(#{1,6})\s+(.*)/),o=h[1].length,l=h[2];t+=`<h${o}>${l}</h${o}>
4`,s++}else if(d(i))a&&(t+=`</ol>
5`,a=!1),t+=`<p>${i}</p>
6`,s++;else if(r(i)){for(a||(t+=`<ol>
7`,a=!0);s<e.length&&r(e[s]);){const h=e[s].replace(/^\d+\.\s+/,"");t+=`<li>${h}`;const o=[];for(s++;s<e.length&&c(e[s]);)o.push(e[s].replace(/^- /,"")),s++;o.length&&(t+=`
8<ul>
9`,o.forEach(l=>{t+=`<li>${l}</li>
10`}),t+="</ul>"),t+=`</li>
11`}t+=`</ol>
12`,a=!1}else if(c(i)){for(t+=`<ul>
13`;s<e.length&&c(e[s]);)t+=`<li>${e[s].replace(/^- /,"")}</li>
14`,s++;t+=`</ul>
15`}else g?t+=i+`
16`:t+=`<p>${i}</p>
17`,s++}return a&&(t+=`</ol>
18`),t+="",t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank">$1</a>'),t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>")}showTypingIndicator(){const n=document.createElement("div");n.className="typing-indicator",n.id="typing-indicator",n.innerHTML=`
19			<div class="typing-dots">
20				<span></span>
21				<span></span>
22				<span></span>
23			</div>
24		`,this.chatMessages.appendChild(n),this.chatMessages.scrollTop=this.chatMessages.scrollHeight}hideTypingIndicator(){const n=document.getElementById("typing-indicator");n&&n.remove()}async refreshNonce(){const n=await fetch(smartflow.api_refresh_nonce,{method:"GET",credentials:"same-origin"});if(n.ok){const e=await n.json();e.nonce&&(smartflow.nonce=e.nonce)}}async sendMessage(n){n.preventDefault();const e=this.chatInput.value.trim();if(e){this.addMessage(e,!0),setTimeout(()=>{this.chatInput.value=""},30),this.showTypingIndicator();try{await this.sendToAPI(e)}catch(t){this.hideTypingIndicator(),this.handleAPIError(t)}}}async sendToAPI(n){const e={message:n},t=await fetch(accesschatbot.api_chatbot,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":accesschatbot.nonce},body:JSON.stringify(e)});if(t.status===403&&(await this.refreshNonce(),t=await fetch(accesschatbot.api_chatbot,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":accesschatbot.nonce},body:JSON.stringify(e)})),!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const s=await t.json();if(this.hideTypingIndicator(),s.output&&s.output.includes("Error in workflow"))throw new Error("Error in workflow detected in API response.");return s.output&&this.addMessage(s.output),s}async fetchHistory(){var n;this.showTypingIndicator();
24try{const e=await fetch(accesschatbot.api_history,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":accesschatbot.nonce}});if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);const t=await e.json();(n=t==null?void 0:t.messages)==null||n.map(s=>{s.message!==""&&this.addMessage(s.message,s.from==="Client")}),this.hideTypingIndicator(),this.chatInput.disabled=!1,this.chatSend.disabled=!1,setTimeout(()=>{this.scrollToBottom()},100)}catch(e){this.hideTypingIndicator(),this.handleAPIError(e),this.chatInput.disabled=!1,this.chatSend.disabled=!1}}handleAPIError(n){console.error("Chat error:",n);let e="We are experiencing high traffic. Please try again in a few moments.";errorText.includes("cookie")&&(e="Your session has expired. Please refresh the page and try again."),this.addMessage(e)}startConversation(){this.fetchHistory()}}document.addEventListener("DOMContentLoaded",()=>{new f});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.