@mobil80-dev/chatbot-widget 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +94 -23
- package/package.json +5 -2
package/index.js
CHANGED
|
@@ -1,7 +1,63 @@
|
|
|
1
1
|
const VaultChat = {
|
|
2
2
|
init (config = {}) {
|
|
3
|
+
/* ============================
|
|
4
|
+
THEME RESOLUTION
|
|
5
|
+
============================ */
|
|
6
|
+
const theme =
|
|
7
|
+
config.theme === 'dark'
|
|
8
|
+
? 'dark'
|
|
9
|
+
: config.theme === 'light'
|
|
10
|
+
? 'light'
|
|
11
|
+
: window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
12
|
+
? 'dark'
|
|
13
|
+
: 'light'
|
|
14
|
+
|
|
15
|
+
const colors =
|
|
16
|
+
theme === 'dark'
|
|
17
|
+
? {
|
|
18
|
+
cardBg: '#0f172a',
|
|
19
|
+
headerBorder: '#1e293b',
|
|
20
|
+
text: '#e5e7eb',
|
|
21
|
+
mutedText: '#94a3b8',
|
|
22
|
+
inputBg: '#020617',
|
|
23
|
+
inputBorder: '#334155',
|
|
24
|
+
botBubble: '#1e293b',
|
|
25
|
+
userText: '#ffffff',
|
|
26
|
+
messagesBg: '#020617'
|
|
27
|
+
}
|
|
28
|
+
: {
|
|
29
|
+
cardBg: '#ffffff',
|
|
30
|
+
headerBorder: '#e5e7eb',
|
|
31
|
+
text: '#0f172a',
|
|
32
|
+
mutedText: '#64748b',
|
|
33
|
+
inputBg: '#ffffff',
|
|
34
|
+
inputBorder: '#cbd5f5',
|
|
35
|
+
botBubble: '#e5e7eb',
|
|
36
|
+
userText: '#ffffff',
|
|
37
|
+
messagesBg: '#f8fafc'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const primaryColor = config.primaryColor || '#2563eb'
|
|
41
|
+
|
|
42
|
+
/* ============================
|
|
43
|
+
FLOATING BUTTON
|
|
44
|
+
============================ */
|
|
3
45
|
const button = document.createElement('div')
|
|
4
|
-
|
|
46
|
+
|
|
47
|
+
if (config.buttonHtml) {
|
|
48
|
+
button.innerHTML = config.buttonHtml
|
|
49
|
+
} else if (config.buttonIconUrl) {
|
|
50
|
+
const img = document.createElement('img')
|
|
51
|
+
img.src = config.buttonIconUrl
|
|
52
|
+
img.style.width = '26px'
|
|
53
|
+
img.style.height = '26px'
|
|
54
|
+
img.style.objectFit = 'contain'
|
|
55
|
+
button.appendChild(img)
|
|
56
|
+
} else if (config.buttonText) {
|
|
57
|
+
button.textContent = config.buttonText
|
|
58
|
+
} else {
|
|
59
|
+
button.textContent = '💬'
|
|
60
|
+
}
|
|
5
61
|
|
|
6
62
|
Object.assign(button.style, {
|
|
7
63
|
position: 'fixed',
|
|
@@ -10,37 +66,44 @@ const VaultChat = {
|
|
|
10
66
|
width: '56px',
|
|
11
67
|
height: '56px',
|
|
12
68
|
borderRadius: '50%',
|
|
13
|
-
background:
|
|
69
|
+
background: primaryColor,
|
|
14
70
|
color: '#fff',
|
|
15
71
|
display: 'flex',
|
|
16
72
|
alignItems: 'center',
|
|
17
73
|
justifyContent: 'center',
|
|
18
74
|
cursor: 'pointer',
|
|
19
75
|
fontSize: '24px',
|
|
20
|
-
zIndex:
|
|
76
|
+
zIndex: 999999
|
|
21
77
|
})
|
|
22
78
|
|
|
79
|
+
/* ============================
|
|
80
|
+
CHAT CARD
|
|
81
|
+
============================ */
|
|
23
82
|
const card = document.createElement('div')
|
|
83
|
+
|
|
24
84
|
card.innerHTML = `
|
|
25
|
-
<div style="
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Powered by <strong>VaultChat</strong>
|
|
33
|
-
</div>
|
|
85
|
+
<div style="
|
|
86
|
+
padding:12px;
|
|
87
|
+
border-bottom:1px solid ${colors.headerBorder};
|
|
88
|
+
color:${colors.mutedText};
|
|
89
|
+
font-size:14px;
|
|
90
|
+
user-select:none">
|
|
91
|
+
Powered by <strong>VaultChat</strong>
|
|
34
92
|
</div>
|
|
35
93
|
|
|
36
94
|
<div id="vc-messages" style="
|
|
37
95
|
flex:1;
|
|
38
96
|
padding:12px;
|
|
39
97
|
overflow-y:auto;
|
|
40
|
-
background
|
|
98
|
+
background:${colors.messagesBg};
|
|
99
|
+
color:${colors.text}">
|
|
41
100
|
</div>
|
|
42
101
|
|
|
43
|
-
<div style="
|
|
102
|
+
<div style="
|
|
103
|
+
display:flex;
|
|
104
|
+
padding:10px;
|
|
105
|
+
border-top:1px solid ${colors.headerBorder};
|
|
106
|
+
background:${colors.cardBg}">
|
|
44
107
|
<input
|
|
45
108
|
id="vc-input"
|
|
46
109
|
placeholder="Type your message..."
|
|
@@ -48,7 +111,9 @@ const VaultChat = {
|
|
|
48
111
|
flex:1;
|
|
49
112
|
padding:10px;
|
|
50
113
|
border-radius:8px;
|
|
51
|
-
border:1px solid
|
|
114
|
+
border:1px solid ${colors.inputBorder};
|
|
115
|
+
background:${colors.inputBg};
|
|
116
|
+
color:${colors.text};
|
|
52
117
|
outline:none"
|
|
53
118
|
/>
|
|
54
119
|
<button id="vc-send" style="
|
|
@@ -56,7 +121,7 @@ const VaultChat = {
|
|
|
56
121
|
padding:0 14px;
|
|
57
122
|
border:none;
|
|
58
123
|
border-radius:8px;
|
|
59
|
-
background:${
|
|
124
|
+
background:${primaryColor};
|
|
60
125
|
color:white;
|
|
61
126
|
cursor:pointer">
|
|
62
127
|
➤
|
|
@@ -70,10 +135,10 @@ const VaultChat = {
|
|
|
70
135
|
right: '20px',
|
|
71
136
|
width: '400px',
|
|
72
137
|
height: '420px',
|
|
73
|
-
background:
|
|
138
|
+
background: colors.cardBg,
|
|
74
139
|
borderRadius: '12px',
|
|
75
140
|
boxShadow: '0 10px 30px rgba(0,0,0,.3)',
|
|
76
|
-
zIndex:
|
|
141
|
+
zIndex: 999999,
|
|
77
142
|
display: 'none',
|
|
78
143
|
flexDirection: 'column'
|
|
79
144
|
})
|
|
@@ -87,6 +152,9 @@ const VaultChat = {
|
|
|
87
152
|
document.body.appendChild(button)
|
|
88
153
|
document.body.appendChild(card)
|
|
89
154
|
|
|
155
|
+
/* ============================
|
|
156
|
+
CHAT LOGIC
|
|
157
|
+
============================ */
|
|
90
158
|
const messages = card.querySelector('#vc-messages')
|
|
91
159
|
const input = card.querySelector('#vc-input')
|
|
92
160
|
const sendBtn = card.querySelector('#vc-send')
|
|
@@ -94,8 +162,8 @@ const VaultChat = {
|
|
|
94
162
|
function addUserMessage (text) {
|
|
95
163
|
const div = document.createElement('div')
|
|
96
164
|
div.style.cssText = `
|
|
97
|
-
background:${
|
|
98
|
-
color
|
|
165
|
+
background:${primaryColor};
|
|
166
|
+
color:${colors.userText};
|
|
99
167
|
padding:8px 12px;
|
|
100
168
|
border-radius:12px;
|
|
101
169
|
max-width:80%;
|
|
@@ -108,7 +176,8 @@ const VaultChat = {
|
|
|
108
176
|
function addBotMessage (text) {
|
|
109
177
|
const div = document.createElement('div')
|
|
110
178
|
div.style.cssText = `
|
|
111
|
-
background
|
|
179
|
+
background:${colors.botBubble};
|
|
180
|
+
color:${colors.text};
|
|
112
181
|
padding:8px 12px;
|
|
113
182
|
border-radius:12px;
|
|
114
183
|
max-width:80%;
|
|
@@ -125,9 +194,11 @@ const VaultChat = {
|
|
|
125
194
|
addUserMessage(text)
|
|
126
195
|
input.value = ''
|
|
127
196
|
|
|
128
|
-
//
|
|
197
|
+
// 🔐 API key missing → internal response only
|
|
129
198
|
if (!config.apiKey) {
|
|
130
|
-
addBotMessage(
|
|
199
|
+
addBotMessage(
|
|
200
|
+
'⚠️ API key not configured. Please add apiKey in VaultChat.init().'
|
|
201
|
+
)
|
|
131
202
|
return
|
|
132
203
|
}
|
|
133
204
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobil80-dev/chatbot-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Drop-in JavaScript chat widget for websites (no iframe, no framework)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,5 +12,8 @@
|
|
|
12
12
|
"vaultchat"
|
|
13
13
|
],
|
|
14
14
|
"author": "Nantha Gopal",
|
|
15
|
-
"license": "MIT"
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@mobil80-dev/chatbot-widget": "^1.0.8"
|
|
18
|
+
}
|
|
16
19
|
}
|