4ec529e860
- Implemented user token secret generation and retrieval in channel service. - Added ResetUserTokenSecret method to reset the user token secret for channels. - Updated channel configuration parsing to include user token secret. - Enhanced WebSocket service to utilize user token secret for external info retrieval. - Modified dashboard channel edit component to support user token secret display and reset functionality. - Introduced API endpoint for resetting user token secret. - Updated IM and SDK configurations to include user token. - Added tests for user token verification logic.
2 lines
8.4 KiB
JavaScript
2 lines
8.4 KiB
JavaScript
!function(){var e={position:"right",themeColor:"#0f6cbd",width:"380px",externalSource:"web_chat"},t=window.__CS_AGENT_WIDGET_STATE__;function n(t){var n,i={};for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n]);for(n in t=t||{})Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n]);return i.baseUrl=String(i.baseUrl||window.location.origin).replace(/\/$/,""),i.apiBaseUrl?i.apiBaseUrl=String(i.apiBaseUrl).replace(/\/$/,""):delete i.apiBaseUrl,i.channelId=String(i.channelId||""),i.externalSource=String(i.externalSource||"web_chat"),i.userToken&&(i.userToken=String(i.userToken)),i}function i(e){var t=document.currentScript;return t&&t.src?t.src.replace(/\/sdk\/cs-ai-agent-sdk\.min\.js(?:\?.*)?$/,""):String(e.widgetBaseUrl||e.baseUrl||window.location.origin).replace(/\/$/,"")}function r(){t.frameHideTimer&&(window.clearTimeout(t.frameHideTimer),t.frameHideTimer=null),t.frameDestroyTimer&&(window.clearTimeout(t.frameDestroyTimer),t.frameDestroyTimer=null)}function a(){var e=t.frame,n=t.config;if(e&&n){if(e.style.position="fixed",e.style.border="0",e.style.overflow="hidden",e.style.background="#fff",e.style.zIndex="2147483000",e.style.boxShadow="0 28px 80px rgba(15, 35, 65, 0.28)",e.style.willChange="top,right,bottom,left,width,height,opacity,transform,border-radius",e.style.transition="top 260ms cubic-bezier(0.22, 1, 0.36, 1), right 260ms cubic-bezier(0.22, 1, 0.36, 1), bottom 260ms cubic-bezier(0.22, 1, 0.36, 1), left 260ms cubic-bezier(0.22, 1, 0.36, 1), width 260ms cubic-bezier(0.22, 1, 0.36, 1), height 260ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease, transform 260ms cubic-bezier(0.22, 1, 0.36, 1), border-radius 260ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 260ms ease",e.style.transformOrigin="left"===n.position?"left bottom":"right bottom",t.isMaximized)return e.style.top="20px",e.style.right="20px",e.style.bottom="20px",e.style.left="20px",e.style.width="calc(100vw - 40px)",e.style.maxWidth="none",e.style.height="calc(100vh - 40px)",void(e.style.borderRadius="24px");e.style.top="",e.style.bottom="112px",e.style.right="left"===n.position?"":"24px",e.style.left="left"===n.position?"24px":"",e.style.width=n.width||"380px",e.style.maxWidth="calc(100vw - 24px)",e.style.height="min(760px, calc(100vh - 136px))",e.style.borderRadius="28px"}}function o(e){if(t.frame&&t.frame.contentWindow&&t.frameUrl)try{t.frame.contentWindow.postMessage(e,t.frameUrl.origin)}catch(e){console.error("[cs-agent-widget] postMessage failed",e)}}function s(){t.frame&&t.frameLoaded&&t.frameReady&&(t.initSent||(t.initSent=!0,o({type:"cs-agent:init",payload:t.config})),o({type:t.isOpen?"cs-agent:open":"cs-agent:minimize"}),o({type:"cs-agent:maximized",payload:{isMaximized:t.isMaximized}}))}function l(){var e=t.frame;if(e){if(r(),a(),e.style.display="block",t.isOpen)return e.style.visibility="visible",e.style.pointerEvents="auto",t.frameHideTimer=window.setTimeout(function(){t.frame&&(t.frame.style.opacity="1",t.frame.style.transform="translate3d(0, 0, 0) scale(1)")},16),void s();e.style.pointerEvents="none",e.style.opacity="0",e.style.transform=t.isMaximized?"translate3d(0, 10px, 0) scale(0.985)":"translate3d(0, 16px, 0) scale(0.96)",t.frameHideTimer=window.setTimeout(function(){t.frame&&!t.isOpen&&(t.frame.style.visibility="hidden")},t.animationDuration),s()}}function c(){return t.frame?t.frame:t.frameUrl&&t.config?(t.frame=document.createElement("iframe"),t.frame.dataset.csAgentWidget="frame",t.frame.title=t.config.title||"\u5728\u7ebf\u5ba2\u670d",t.frame.src=t.frameUrl.toString(),a(),t.frame.style.display="block",t.frame.style.visibility="hidden",t.frame.style.pointerEvents="none",t.frame.style.opacity="0",t.frame.style.transform="translate3d(0, 18px, 0) scale(0.96)",t.frame.addEventListener("load",function(){t.frameLoaded=!0,l()}),document.body.appendChild(t.frame),t.frame):null}function d(e){var r=e||window.CSAgentConfig||{};t.config=n(r);var a=i(t.config);r.baseUrl||(t.config.baseUrl=a),t.config.channelId?(t.configLoading=!0,function(e){var t=String(e.apiBaseUrl||e.baseUrl||"").replace(/\/$/,"");if(!t||!e.channelId||"function"!=typeof fetch)return Promise.resolve(e);var n=t+"/api/channel/config?channelId="+encodeURIComponent(e.channelId);return fetch(n,{method:"GET",cache:"no-store",headers:{"X-Channel-Id":e.channelId}}).then(function(e){return e.json()}).then(function(t){return t&&!1!==t.success?function(e,t){if(!t)return e;var n,i={};for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n]);for(var r=["title","subtitle","themeColor","position","width"],a=0;a<r.length;a+=1)n=r[a],Object.prototype.hasOwnProperty.call(t,n)&&void 0!==t[n]&&null!==t[n]&&(i[n]=t[n]);return i}(e,t.data||{}):e}).catch(function(){return e})}(t.config).then(function(e){t.configLoading=!1,t.config=n(e),t.frameUrl=function(e){var t=i(e),n=new URL(t+"/kefu/chat/");return n.searchParams.set("channelId",e.channelId),n.searchParams.set("baseUrl",e.baseUrl),e.apiBaseUrl&&n.searchParams.set("apiBaseUrl",e.apiBaseUrl),e.externalSource&&n.searchParams.set("externalSource",e.externalSource),e.externalName&&n.searchParams.set("externalName",e.externalName),e.userToken&&n.searchParams.set("userToken",e.userToken),n}(t.config),t.button&&t.button.parentNode&&(t.button.parentNode.removeChild(t.button),t.button=null),function(){if(t.button)return t.button;var e=t.config,n=document.createElement("button"),i=document.createElementNS("http://www.w3.org/2000/svg","svg"),r=document.createElement("span");n.type="button",n.dataset.csAgentWidget="launcher",n.setAttribute("aria-label",e.title||"\u5728\u7ebf\u5ba2\u670d"),i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("fill","none"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),i.setAttribute("aria-hidden","true"),i.style.width="24px",i.style.height="24px",i.style.flex="0 0 auto",["M3 11a9 9 0 1 1 18 0","M3 11h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z","M21 11h-3a2 2 0 0 0-2 2v3a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2z","M21 16v2a4 4 0 0 1-4 4h-5"].forEach(function(e){var t=document.createElementNS("http://www.w3.org/2000/svg","path");t.setAttribute("d",e),i.appendChild(t)}),r.textContent="\u5ba2\u670d",r.style.display="block",n.style.position="fixed",n.style.bottom="24px",n.style.right="left"===e.position?"":"24px",n.style.left="left"===e.position?"24px":"",n.style.zIndex="2147483000",n.style.display="inline-flex",n.style.flexDirection="column",n.style.alignItems="center",n.style.justifyContent="center",n.style.gap="4px",n.style.width="64px",n.style.height="64px",n.style.border="0",n.style.borderRadius="999px",n.style.padding="0",n.style.background=e.themeColor||"#0f6cbd",n.style.color="#fff",n.style.font="600 13px/1 sans-serif",n.style.boxShadow="0 18px 40px rgba(15, 35, 65, 0.24)",n.style.cursor="pointer",n.appendChild(i),n.appendChild(r),n.addEventListener("click",function(){t.frame||c(),t.isOpen=!t.isOpen,l()}),document.body.appendChild(n),t.button=n}()})):console.error("[cs-agent-widget] channelId is required")}t||(t={button:null,frame:null,frameLoaded:!1,frameReady:!1,initSent:!1,isOpen:!1,isMaximized:!1,configLoading:!1,frameHideTimer:null,frameDestroyTimer:null,config:null,frameUrl:null,animationDuration:260},window.__CS_AGENT_WIDGET_STATE__=t),window.CSAgentWidget={mount:d,destroy:function(){r(),t.frame&&t.frame.parentNode&&t.frame.parentNode.removeChild(t.frame),t.button&&t.button.parentNode&&t.button.parentNode.removeChild(t.button),t.button=null,t.frame=null,t.frameLoaded=!1,t.frameReady=!1,t.initSent=!1,t.isOpen=!1,t.isMaximized=!1,t.configLoading=!1},open:function(){t.frame||c(),t.frame&&(t.isOpen=!0,l())},close:function(){t.isOpen=!1,l()}},t.listenerBound||(window.addEventListener("message",function(e){if(t.frame&&e.source===t.frame.contentWindow){var n=e.data||{};return"cs-agent:ready"===n.type?(t.frameReady=!0,void s()):"cs-agent:request-minimize"===n.type?(t.isOpen=!1,void l()):void("cs-agent:request-close"!==n.type?"cs-agent:request-toggle-maximize"===n.type&&(t.isMaximized=!t.isMaximized,l()):t.frame&&(r(),t.frame.style.pointerEvents="none",t.frame.style.opacity="0",t.frame.style.transform="translate3d(0, 18px, 0) scale(0.94)",t.frame.style.visibility="hidden",t.frameDestroyTimer=window.setTimeout(function(){t.frame&&(t.frame.parentNode&&t.frame.parentNode.removeChild(t.frame),t.frame=null,t.frameLoaded=!1,t.frameReady=!1,t.initSent=!1,t.isOpen=!1,t.isMaximized=!1,r())},t.animationDuration)))}}),t.listenerBound=!0),window.CSAgentConfig&&d(window.CSAgentConfig)}();
|