function embedChatbot() {
const t = window.maxkbChatConfig
if (t && t.token) {
icon = ``;
chat_button = document.createElement("div");
chat_button.style =
"position: fixed;bottom: 40px;right: 20px;cursor: pointer;";
chat_button.innerHTML = icon;
chat_container = document.createElement("div");
chat_container.id = "chat_container";
chat_container.style.cssText = `z-index:10000;position: relative;
width: 420px;
height: 600px;
border: none;
border-radius: 7px 7px 7px 7px;
position: fixed;bottom: 40px;right: 20px`;
chat_container.style["display"] = "none";
chat = document.createElement("iframe");
chat.src = `http://${window.maxkbChatConfig.host}/ui/chat/${window.maxkbChatConfig.token}`;
chat.id = "chat";
chat_container.append(chat);
chat.style.cssText = `border: none;height:100%;width:100%`;
close_button = document.createElement("div");
close_button.innerHTML = ``;
close_button.style.cssText = `position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
`;
close_button.onclick = () => {
chat_container.style["display"] = "none";
chat_button.style["display"] = "block";
};
chat_container.append(close_button);
document.body.append(chat_container);
chat_button.onclick = ($event) => {
chat_container.style["display"] = "block";
chat_button.style["display"] = "none";
};
sty=document.createElement("style")
sty.innerText=` #chat_container {
animation: appear .4s ease-in-out;
}
@keyframes appear {
from {
height: 0;;
}
to {
height: 600px;
}
}`
document.head.append(sty)
document.body.append(chat_button);
} else console.error('difyChatbotConfig is empty or token is not provided')
}
document.body.onload = embedChatbot