问题描述
JavaScript 新手我正在使用 Watson 助手网络聊天框架 (https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-events#windowclose) 进行网络集成。我能够更新 CSS 变量和其他配置,但是当我删除用户会话时,最小化聊天机器人图标也会消失。
window.watsonAssistantChatOptions = {
carbonTheme: 'g10',enableFocusTrap: true,onLoad: function(instance) {
// Instance method to adjust specific CSS variables
instance.updateCSSVariables({
'BASE-font-family': '"Times New Roman",Times,serif','BASE-width':'460px','BASE-height':'500px','$interactive-01': '#5dd7ec','$interactive-03':'#002d9c','$interactive-04':'#002d9c'
});
instance.openWindow();
instance.writeableElements.headerBottomElement.innerHTML = ' Powered By <a href="https://teledental.com"><strong>TeleDental</strong></a>';
instance.render();
function handler(event)
{
instance.destroySession();
instance.destroy();
resolve();
}
instance.on({ type: "window:close",handler: handler });
}
};
setTimeout(function(){
const t=document.createElement('script');
t.src="https://web-chat.global.assistant.watson.appdomain.cloud/loadWatsonAssistantChat.js";
document.head.appendChild(t);
});
解决方法
你想完成什么?
instance.destroy()
将拆除整个网络聊天并删除启动器和与网络聊天相关的所有其他 UI 元素。这就是造成你所看到的。 (https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-instance-methods#destroy)。
instance.destroySession()
将删除与网络聊天相关的所有浏览器存储,因此,例如,如果您想将用户从您的网站注销,则不会留下任何识别数据。 (https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-instance-methods#destroySession)
当有人只是关闭聊天时,我认为您不想调用这些方法中的任何一个,他们可能只是在看屏幕上的其他内容并想回到聊天中,但也许我错过了您的最终目标就在这里。