-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed-chatbot.js
67 lines (63 loc) · 3.14 KB
/
embed-chatbot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(function () {
const fontAwesome = document.createElement("link");
fontAwesome.rel = "stylesheet";
fontAwesome.href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css";
document.head.appendChild(fontAwesome);
const scriptTag = document.currentScript || document.querySelector('script[data-assistant-name][data-assistant-id]');
const assistantName = scriptTag.getAttribute('data-assistant-name');
const assistantId = scriptTag.getAttribute('data-assistant-id');
const container = document.createElement("div");
container.innerHTML = `
<div id="assistant-embed-container">
<div id="chatbot-icon" style="position:fixed;bottom:40px;right:50px;width:120px;height:120px;display:flex;align-items:center;justify-content:center;cursor:pointer;animation:bounce 2s infinite;z-index:9999;">
<img src="https://github.com/afshansji/embeded-chatbot/blob/main/Bot%201.png?raw=true" alt="Chatbot" style="width:150px;height:120px;object-fit:contain;" />
</div>
<div id="assistant-embed" style="position:fixed;bottom:20px;right:20px;width:510px;height:580px;border:1px solid #ccc;border-radius:10px;display:none;z-index:9999;">
<div style="display:flex;justify-content:space-between;align-items:center;padding:10px;background: linear-gradient(90deg, #1969E9 0%, #05B8FB 100%);border-top-left-radius:10px;border-top-right-radius:10px;">
<h4 style="margin:0;color:white;font-size:16px;">${assistantName} Assistant</h4>
<button id="minimize-button" style="border:none;background:transparent;cursor:pointer;font-size:20px;">
<i class="fas fa-chevron-down" style="color:#ffffff;"></i>
</button>
</div>
<iframe id="chatbot-iframe" width="100%" height="100%"
style="border: none; border-radius: 0 0 10px 10px;" title="Custom Chatbot"></iframe>
</div>
</div>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {transform:translateY(0);}
40% {transform:translateY(-10px);}
60% {transform:translateY(-5px);}
}
#chatbot-icon {
width: 150px;
height: 150px;
}
#chatbot-icon img {
width: 130px;
height: 130px;
object-fit: cover;
border-radius: 0;
}
</style>
`;
document.body.appendChild(container);
if (assistantName && assistantId) {
document.getElementById("chatbot-iframe").src = `https://tutorgpt.managedcoder.com/assistants/${assistantName}/${assistantId}`;
} else {
console.error("Assistant name or ID not provided.");
}
document.getElementById("chatbot-icon").onclick = function () {
document.getElementById("assistant-embed").style.display = "block";
document.getElementById("chatbot-icon").style.display = "none";
};
document.getElementById("minimize-button").onclick = function () {
document.getElementById("assistant-embed").style.display = "none";
document.getElementById("chatbot-icon").style.display = "flex";
};
})();