Sid Gifari File Manager
🏠 Root
/
home
/
genremedia08
/
thepassage.overlookedtracks.com
/
wp-content9
/
plugins
/
echo-knowledge-base
/
js
/
ai
/
Editing: admin-help-chat.min.js
(function(){"use strict";if(!window.React||!window.ReactDOM){console.error("EPKB Admin Help Chat: React is not available");return}const{useState:e,useEffect:t,useRef:a,createElement:n}=window.React;const s=window.ReactDOM;const o=window.epkbAdminHelp||{};const{logError:i,showErrorMessage:l,createErrorReport:c,safeParseJSON:r}=window.EPKBChatUtils||{};const p=()=>n("div",{className:"epkb-help-typing"},n("span"),n("span"),n("span"));const d=({message:e})=>{if(e.isError){const t=window.EPKB_AI_Util_React.createAIErrorMessageElement({errorText:o.i18n?.error,persistText:o.i18n?.if_issue_persists,linkText:o.i18n?.contact_support,h:n});return n("div",{className:`epkb-help-chat-message epkb-help-chat-message--${e.role}`},n("div",{className:"epkb-message-bubble"},t))}const t=e.content.split("\n\n").filter((e=>e.trim()));const a=e=>{if(!e.includes("**")){return e}const t=e.split("**");const a=[];t.forEach(((e,t)=>{if(t%2===0){if(e)a.push(e)}else{a.push(n("strong",{key:`bold-${t}`},e))}}));return a};return n("div",{className:`epkb-help-chat-message epkb-help-chat-message--${e.role}`},n("div",{className:"epkb-message-bubble"},t.length>1?t.map(((e,t)=>{const s=e.includes("💡")&&e.includes("BETA");return n("p",{key:t,style:{margin:t===0?"0 0 0.5em 0":"0.5em 0",fontSize:s?"0.85em":"1em",fontStyle:s?"italic":"normal",opacity:s?"0.9":"1"}},a(e))})):a(e.content)))};const m=()=>"admin_"+Date.now()+"_"+Math.random().toString(36).substr(2,9);const u=()=>{const e=localStorage.getItem("epkb_admin_chat_conversation");if(e){try{const{conversationId:t,timestamp:a}=JSON.parse(e);const n=Date.now();const s=60*60*1e3;if(t&&a&&n-a<s){return t}}catch(e){}}const t=m();localStorage.setItem("epkb_admin_chat_conversation",JSON.stringify({conversationId:t,timestamp:Date.now()}));return t};const h=e=>{for(let t=e.length-1;t>=0;t--){if(e[t].role==="assistant"&&e[t].id){return e[t].id}}return null};const b=()=>{const e=m();localStorage.setItem("epkb_admin_chat_conversation",JSON.stringify({conversationId:e,timestamp:Date.now()}));return e};const k=()=>{const[s,l]=e(false);const[c,m]=e(false);const[k,g]=e(false);const[f,w]=e(false);const[_,v]=e(false);const[y,N]=e(false);const[S,C]=e({name:o.user?.name||"",email:o.user?.email||""});const E=document.getElementById("epkb-admin-help-chat-root");const I=E?.getAttribute("data-welcome-message")||o.i18n?.welcome;const A=E?.getAttribute("data-helper-question")||"";const T=E?.getAttribute("data-page-context")||"default";const D="💡 **Note:** I'm still learning and in BETA! I'll do my best to help, but for critical issues, you can always reach our human support team.";const O=A?`${I}\n\n${A}\n\n${D}`:`${I}\n\n${D}`;const[x,P]=e([{role:"assistant",content:O,id:"welcome_"+Date.now()}]);const[B,R]=e("");const[M,$]=e(false);const[H,K]=e((()=>u()));const J=a(null);const j=a(null);t((()=>{const e=localStorage.getItem("epkb_help_chat_intro_seen");if(!e){setTimeout((()=>{m(true);g(true)}),2e3)}}),[]);const q=()=>{J.current?.scrollIntoView({behavior:"smooth"})};t((()=>{q()}),[x,M]);t((()=>{if(s){if(j.current){j.current.focus()}m(false);g(false);localStorage.setItem("epkb_help_chat_intro_seen","true")}}),[s]);const U=()=>{m(false);g(false);localStorage.setItem("epkb_help_chat_intro_seen","true")};const Y=async()=>{if(!B.trim()||M)return;const e=B.trim();R("");const t=u();if(t!==H){K(t);P([{role:"assistant",content:O,id:"welcome_"+Date.now()}])}const a="user_"+Date.now();P((t=>[...t,{role:"user",content:e,id:a}]));$(true);const n=h(x);if(!f){w(true)}try{const a=await fetch(o.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:e,conversation_id:t||H,last_response_id:n,token:o.token,context:{plugin_version:o.plugin_version,wp_version:o.wp_version,ai_config:o.ai_config,page:window.location.pathname,page_context:T,welcome_shown:I}})});const s=await r(a);if(!a.ok){throw new Error(s.message||"API request failed")}const i=s.response_id||"assistant_"+Date.now();P((e=>[...e,{role:"assistant",content:s.response||s.message||"I received your message but couldn't generate a proper response.",id:i}]))}catch(t){i("Admin Help Chat","Message send failed",{message:t.message||"Unknown error",code:t.code,status:t.status,userMessage:e.substring(0,200),endpoint:o.endpoint,pageContext:T});P((e=>[...e,{role:"assistant",content:"",isError:true}]))}finally{$(false)}};const L=async()=>{if(!S.name.trim()||!S.email.trim()){alert(o.i18n?.fill_required||"Please provide your name and email.");return}N(true);try{const e=await fetch(o.ticket_endpoint||"https://www.echoknowledgebase.com/wp-json/epkb/v1/support/ticket",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:S.name,email:S.email,conversation_id:H,token:o.token,context:{site_url:window.location.hostname}})});const t=await r(e);if(!e.ok){throw new Error(t.message||"Ticket submission failed")}v(false);P((e=>[...e,{role:"assistant",content:o.i18n?.ticket_submitted||"Your support ticket has been submitted successfully! Our team will get back to you soon.",id:"ticket_success_"+Date.now()}]))}catch(e){i("Admin Help Chat","Ticket submission failed",{message:e.message||"Unknown error",code:e.code,status:e.status,conversationId:H,endpoint:o.ticket_endpoint||"https://www.echoknowledgebase.com/wp-json/epkb/v1/support/ticket"});alert(o.i18n?.ticket_error||"Failed to submit ticket. Please try again or contact support directly.")}finally{N(false)}};const z=()=>{if(M)return;const e=b();K(e);P([{role:"assistant",content:O,id:"welcome_"+Date.now()}]);R("");w(false)};const F=e=>{if(e.key==="Enter"&&!e.shiftKey){e.preventDefault();Y()}};if(!s){return n("div",{style:{position:"relative"}},c&&n("div",{className:"epkb-help-chat-intro"},n("div",{className:"epkb-help-chat-intro__text"},n("strong",null,"💡 New AI Help Available!"),n("br"),"Get instant help with KB configuration, settings, and features. Click below to chat with our AI assistant."),n("button",{className:"epkb-help-chat-intro__dismiss",onClick:U},"Dismiss")),n("button",{className:"epkb-help-chat-button"+(k?" epkb-help-chat-button--pulse":""),onClick:()=>l(true)},n("span",{className:"dashicons dashicons-editor-help"}),o.i18n?.help_button||"Need Help?"))}return n("div",{className:"epkb-help-chat-window"},n("div",{className:"epkb-help-chat-header"},n("div",{className:"epkb-help-chat-header-title"},n("span",null,"KB Plugin Help"),n("span",{className:"epkb-help-chat-beta-badge"},"BETA")),n("div",{className:"epkb-help-chat-header-actions"},x.length>1&&n("button",{className:"epkb-help-chat-clear",onClick:z,title:o.i18n?.new_conversation||"New Conversation",disabled:M},"🔄"),n("button",{className:"epkb-help-chat-close",onClick:()=>l(false)},"×"))),n("div",{className:"epkb-help-chat-messages"},x.map(((e,t)=>n(d,{key:t,message:e}))),M&&n("div",{className:"epkb-help-chat-message epkb-help-chat-message--assistant"},n(p)),n("div",{ref:J})),f&&n("div",{className:"epkb-help-chat-human-wrapper"},n("button",{className:"epkb-help-chat-human-button",onClick:()=>v(true)},o.i18n?.need_human||"Need a human?")),n("div",{className:"epkb-help-chat-input"},n("input",{ref:j,type:"text",value:B,onChange:e=>R(e.target.value),onKeyPress:F,placeholder:o.i18n?.placeholder||"Type your question...",disabled:M}),n("button",{onClick:Y,disabled:!B.trim()||M},o.i18n?.send||"Send")),_&&n("div",{className:"epkb-help-chat-dialog-overlay"},n("div",{className:"epkb-help-chat-dialog"},n("div",{className:"epkb-help-chat-dialog-header"},n("h3",null,o.i18n?.submit_ticket||"Submit Support Ticket"),n("button",{className:"epkb-help-chat-dialog-close",onClick:()=>v(false)},"×")),n("div",{className:"epkb-help-chat-dialog-body"},n("div",{className:"epkb-help-chat-dialog-intro"},o.i18n?.ticket_intro||"We'll create a support ticket for you and our team will review your conversation."),n("div",{className:"epkb-help-chat-field"},n("label",null,o.i18n?.your_name||"Your Name"),n("input",{type:"text",value:S.name,onChange:e=>C((t=>({...t,name:e.target.value}))),readOnly:o.user?.name?true:false})),n("div",{className:"epkb-help-chat-field"},n("label",null,o.i18n?.your_email||"Your Email"),n("input",{type:"email",value:S.email,onChange:e=>C((t=>({...t,email:e.target.value}))),readOnly:o.user?.email?true:false})),n("input",{type:"hidden",name:"conversation_id",value:H})),n("div",{className:"epkb-help-chat-dialog-footer"},n("button",{className:"epkb-help-chat-dialog-cancel",onClick:()=>v(false)},o.i18n?.cancel||"Cancel"),n("button",{className:"epkb-help-chat-dialog-submit",onClick:L,disabled:y},y?o.i18n?.submitting||"Submitting...":o.i18n?.submit||"Submit Ticket")))))};const g=()=>{const e=document.getElementById("epkb-admin-help-chat-root");if(e){if(typeof s.createRoot==="function"){const t=s.createRoot(e);t.render(n(k))}else{s.render(n(k),e)}}};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",g)}else{g()}})();
Save
Cancel